Merge git://git.denx.de/u-boot-dm

This commit is contained in:
Tom Rini 2018-04-01 20:36:39 -04:00
commit 0e5d3e3111
15 changed files with 172 additions and 34 deletions

View File

@ -27,6 +27,10 @@
testfdt3 = "/b-test";
testfdt5 = "/some-bus/c-test@5";
testfdt8 = "/a-test";
fdt_dummy0 = "/translation-test@8000/dev@0,0";
fdt_dummy1 = "/translation-test@8000/dev@1,100";
fdt_dummy2 = "/translation-test@8000/dev@2,200";
fdt_dummy3 = "/translation-test@8000/noxlatebus@3,300/dev@42";
usb0 = &usb_0;
usb1 = &usb_1;
usb2 = &usb_2;
@ -487,6 +491,50 @@
reg = <9 1>;
};
};
translation-test@8000 {
compatible = "simple-bus";
reg = <0x8000 0x4000>;
#address-cells = <0x2>;
#size-cells = <0x1>;
ranges = <0 0x0 0x8000 0x1000
1 0x100 0x9000 0x1000
2 0x200 0xA000 0x1000
3 0x300 0xB000 0x1000
>;
dev@0,0 {
compatible = "denx,u-boot-fdt-dummy";
reg = <0 0x0 0x1000>;
};
dev@1,100 {
compatible = "denx,u-boot-fdt-dummy";
reg = <1 0x100 0x1000>;
};
dev@2,200 {
compatible = "denx,u-boot-fdt-dummy";
reg = <2 0x200 0x1000>;
};
noxlatebus@3,300 {
compatible = "simple-bus";
reg = <3 0x300 0x1000>;
#address-cells = <0x1>;
#size-cells = <0x0>;
dev@42 {
compatible = "denx,u-boot-fdt-dummy";
reg = <0x42>;
};
};
};
};
#include "sandbox_pmic.dtsi"

View File

@ -22,7 +22,7 @@ static int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc,
return 0;
}
if (argc == 2) {
end_of_rom = (int)simple_strtoul(argv[1], &ep, 16);
end_of_rom = simple_strtoul(argv[1], &ep, 16);
if (*ep) {
puts("\n** Invalid end of ROM **\n");
return 1;

View File

@ -21,6 +21,9 @@
#define CONFIG_SYS_FDT_PAD 0x3000
#endif
/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
#define FDT_RAMDISK_OVERHEAD 0x80
DECLARE_GLOBAL_DATA_PTR;
static void fdt_error(const char *msg)

View File

@ -49,12 +49,17 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index)
reg += index * (na + ns);
/*
* Use the full-fledged translate function for complex
* bus setups.
*/
addr = fdt_translate_address((void *)gd->fdt_blob,
dev_of_offset(dev), reg);
if (ns) {
/*
* Use the full-fledged translate function for complex
* bus setups.
*/
addr = fdt_translate_address((void *)gd->fdt_blob,
dev_of_offset(dev), reg);
} else {
/* Non translatable if #size-cells == 0 */
addr = fdt_read_number(reg, na);
}
} else {
/*
* Use the "simple" translate function for less complex

View File

@ -227,13 +227,16 @@ fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
uint flags;
u64 size;
int na;
int ns;
prop_val = of_get_address(ofnode_to_np(node), index, &size,
&flags);
if (!prop_val)
return FDT_ADDR_T_NONE;
if (IS_ENABLED(CONFIG_OF_TRANSLATE)) {
ns = of_n_size_cells(ofnode_to_np(node));
if (IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
return of_translate_address(ofnode_to_np(node), prop_val);
} else {
na = of_n_addr_cells(ofnode_to_np(node));

View File

@ -333,7 +333,8 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob,
int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only)
{
int node, ret;
int ret;
ofnode node;
ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only);
if (ret) {
@ -342,13 +343,18 @@ int dm_extended_scan_fdt(const void *blob, bool pre_reloc_only)
}
/* bind fixed-clock */
node = ofnode_to_offset(ofnode_path("/clocks"));
node = ofnode_path("/clocks");
/* if no DT "clocks" node, no need to go further */
if (node < 0)
if (!ofnode_valid(node))
return ret;
ret = dm_scan_fdt_node(gd->dm_root, gd->fdt_blob, node,
pre_reloc_only);
#if CONFIG_IS_ENABLED(OF_LIVE)
if (of_live_active())
ret = dm_scan_fdt_live(gd->dm_root, node.np, pre_reloc_only);
else
#endif
ret = dm_scan_fdt_node(gd->dm_root, gd->fdt_blob, node.of_offset,
pre_reloc_only);
if (ret)
debug("dm_scan_fdt_node() failed: %d\n", ret);

View File

@ -457,6 +457,32 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
}
#if CONFIG_IS_ENABLED(OF_CONTROL)
int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id,
struct udevice **devp)
{
struct udevice *dev;
struct uclass *uc;
int ret;
*devp = NULL;
ret = uclass_get(id, &uc);
if (ret)
return ret;
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
uint phandle;
phandle = dev_read_phandle(dev);
if (phandle == phandle_id) {
*devp = dev;
return uclass_get_device_tail(dev, ret, devp);
}
}
return -ENODEV;
}
int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
const char *name, struct udevice **devp)
{

View File

@ -12,6 +12,7 @@
#include <dm/lists.h>
#include <dm/pinctrl.h>
#include <dm/util.h>
#include <dm/of_access.h>
DECLARE_GLOBAL_DATA_PTR;
@ -63,16 +64,13 @@ static int pinctrl_config_one(struct udevice *config)
*/
static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
{
const void *fdt = gd->fdt_blob;
int node = dev_of_offset(dev);
char propname[32]; /* long enough */
const fdt32_t *list;
uint32_t phandle;
int config_node;
struct udevice *config;
int state, size, i, ret;
state = fdt_stringlist_search(fdt, node, "pinctrl-names", statename);
state = dev_read_stringlist_search(dev, "pinctrl-names", statename);
if (state < 0) {
char *end;
/*
@ -85,22 +83,15 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
}
snprintf(propname, sizeof(propname), "pinctrl-%d", state);
list = fdt_getprop(fdt, node, propname, &size);
list = dev_read_prop(dev, propname, &size);
if (!list)
return -EINVAL;
size /= sizeof(*list);
for (i = 0; i < size; i++) {
phandle = fdt32_to_cpu(*list++);
config_node = fdt_node_offset_by_phandle(fdt, phandle);
if (config_node < 0) {
dev_err(dev, "prop %s index %d invalid phandle\n",
propname, i);
return -EINVAL;
}
ret = uclass_get_device_by_of_offset(UCLASS_PINCONFIG,
config_node, &config);
ret = uclass_get_device_by_phandle_id(UCLASS_PINCONFIG, phandle,
&config);
if (ret)
return ret;

View File

@ -168,9 +168,9 @@ static int file_cbfs_load_header(uintptr_t end_of_rom,
struct cbfs_header *header)
{
struct cbfs_header *header_in_rom;
int32_t offset = *(u32 *)(end_of_rom - 3);
header_in_rom = (struct cbfs_header *)(uintptr_t)
*(u32 *)(end_of_rom - 3);
header_in_rom = (struct cbfs_header *)(end_of_rom + offset + 1);
swap_header(header, header_in_rom);
if (header->magic != good_magic || header->offset >

View File

@ -19,6 +19,7 @@ enum uclass_id {
UCLASS_TEST_FDT,
UCLASS_TEST_BUS,
UCLASS_TEST_PROBE,
UCLASS_TEST_DUMMY,
UCLASS_SPI_EMUL, /* sandbox SPI device emulator */
UCLASS_I2C_EMUL, /* sandbox I2C device emulator */
UCLASS_PCI_EMUL, /* sandbox PCI device emulator */

View File

@ -210,6 +210,22 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node,
int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
struct udevice **devp);
/**
* uclass_get_device_by_phandle_id() - Get a uclass device by phandle id
*
* This searches the devices in the uclass for one with the given phandle id.
*
* The device is probed to activate it ready for use.
*
* @id: uclass ID to look up
* @phandle_id: the phandle id to look up
* @devp: Returns pointer to device (there is only one for each node)
* @return 0 if OK, -ENODEV if there is no device match the phandle, other
* -ve on error
*/
int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id,
struct udevice **devp);
/**
* uclass_get_device_by_phandle() - Get a uclass device by phandle
*

View File

@ -21,6 +21,7 @@
/* Define this to avoid #ifdefs later on */
struct lmb;
struct fdt_region;
#ifdef USE_HOSTCC
#include <sys/types.h>

View File

@ -309,7 +309,4 @@ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count,
extern struct fdt_header *working_fdt; /* Pointer to the working fdt */
/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
#define FDT_RAMDISK_OVERHEAD 0x80
#endif /* _INCLUDE_LIBFDT_H_ */

View File

@ -14,8 +14,6 @@
#include "fdt_host.h"
#endif
#include "libfdt_internal.h"
#define FDT_MAX_DEPTH 32
static int str_in_list(const char *str, char * const list[], int count)

View File

@ -419,3 +419,46 @@ static int dm_test_first_next_ok_device(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_first_next_ok_device, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
static const struct udevice_id fdt_dummy_ids[] = {
{ .compatible = "denx,u-boot-fdt-dummy", },
{ }
};
UCLASS_DRIVER(fdt_dummy) = {
.name = "fdt_dummy",
.id = UCLASS_TEST_DUMMY,
.flags = DM_UC_FLAG_SEQ_ALIAS,
};
U_BOOT_DRIVER(fdt_dummy_drv) = {
.name = "fdt_dummy_drv",
.of_match = fdt_dummy_ids,
.id = UCLASS_TEST_DUMMY,
};
static int dm_test_fdt_translation(struct unit_test_state *uts)
{
struct udevice *dev;
/* Some simple translations */
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
ut_asserteq_str("dev@0,0", dev->name);
ut_asserteq(0x8000, dev_read_addr(dev));
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
ut_asserteq_str("dev@1,100", dev->name);
ut_asserteq(0x9000, dev_read_addr(dev));
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, true, &dev));
ut_asserteq_str("dev@2,200", dev->name);
ut_asserteq(0xA000, dev_read_addr(dev));
/* No translation for busses with #size-cells == 0 */
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, true, &dev));
ut_asserteq_str("dev@42", dev->name);
ut_asserteq(0x42, dev_read_addr(dev));
return 0;
}
DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);