diff options
author | Christophe Leroy <christophe.leroy@csgroup.eu> | 2023-04-04 12:42:15 +0200 |
---|---|---|
committer | Christophe Leroy <christophe.leroy@csgroup.eu> | 2023-04-28 17:52:23 +0200 |
commit | 3155b0af4eab045b145681a53ebec04bd836b17c (patch) | |
tree | db4f2a7a4e88918ed9195a3a73a8aa7610b6cff1 /board/cssi/common/common.c | |
parent | 71e94640fb9b57fd1109898a7f2cb5de4a116620 (diff) |
board: cssi: Create dedicated file for common sources
In preparation of the new cssi board called cmpcpro which
we be introduce in a future patch, move common
functions into a dedicated file in a common directory.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Diffstat (limited to 'board/cssi/common/common.c')
-rw-r--r-- | board/cssi/common/common.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/board/cssi/common/common.c b/board/cssi/common/common.c new file mode 100644 index 00000000000..71b35cc692f --- /dev/null +++ b/board/cssi/common/common.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2010-2020 CS Group + * Charles Frey <charles.frey@c-s.fr> + * Florent Trinh Thai <florent.trinh-thai@c-s.fr> + * Christophe Leroy <christophe.leroy@c-s.fr> + * + * Common specific routines for the CS Group boards + */ + +#include <fdt_support.h> + +static int fdt_set_node_and_value(void *blob, char *node, const char *prop, + void *var, int size) +{ + int ret, off; + + off = fdt_path_offset(blob, node); + + if (off < 0) { + printf("Cannot find %s node err:%s\n", node, fdt_strerror(off)); + + return off; + } + + ret = fdt_setprop(blob, off, prop, var, size); + + if (ret < 0) + printf("Cannot set %s/%s prop err: %s\n", node, prop, fdt_strerror(ret)); + + return ret; +} + +/* Checks front/rear id and remove unneeded nodes from the blob */ +void ft_cleanup(void *blob, unsigned long id, const char *prop, const char *compatible) +{ + int off; + + off = fdt_node_offset_by_compatible(blob, -1, compatible); + + while (off != -FDT_ERR_NOTFOUND) { + const struct fdt_property *ids; + int nb_ids, idx; + int tmp = -1; + + ids = fdt_get_property(blob, off, prop, &nb_ids); + + for (idx = 0; idx < nb_ids; idx += 4) { + if (*((uint32_t *)&ids->data[idx]) == id) + break; + } + + if (idx >= nb_ids) + fdt_del_node(blob, off); + else + tmp = off; + + off = fdt_node_offset_by_compatible(blob, tmp, compatible); + } + + fdt_set_node_and_value(blob, "/", prop, &id, sizeof(uint32_t)); +} |