2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-05-19 02:09:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2017-05-19 02:09:02 +00:00
|
|
|
#include <dm/of_access.h>
|
|
|
|
#include <dm/of_extra.h>
|
|
|
|
#include <dm/ofnode.h>
|
|
|
|
|
2018-06-11 19:07:17 +00:00
|
|
|
int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry)
|
2017-05-19 02:09:02 +00:00
|
|
|
{
|
|
|
|
const char *prop;
|
2021-01-21 20:57:14 +00:00
|
|
|
ofnode subnode;
|
2017-05-19 02:09:02 +00:00
|
|
|
|
2018-10-01 18:22:08 +00:00
|
|
|
if (ofnode_read_u32(node, "image-pos", &entry->offset)) {
|
|
|
|
debug("Node '%s' has bad/missing 'image-pos' property\n",
|
2018-06-11 19:07:17 +00:00
|
|
|
ofnode_get_name(node));
|
2021-01-21 20:57:14 +00:00
|
|
|
return log_msg_ret("image-pos", -ENOENT);
|
2018-10-01 18:22:08 +00:00
|
|
|
}
|
|
|
|
if (ofnode_read_u32(node, "size", &entry->length)) {
|
|
|
|
debug("Node '%s' has bad/missing 'size' property\n",
|
|
|
|
ofnode_get_name(node));
|
2021-01-21 20:57:14 +00:00
|
|
|
return log_msg_ret("size", -ENOENT);
|
2017-05-19 02:09:02 +00:00
|
|
|
}
|
|
|
|
entry->used = ofnode_read_s32_default(node, "used", entry->length);
|
|
|
|
prop = ofnode_read_string(node, "compress");
|
2018-10-01 18:22:08 +00:00
|
|
|
if (prop) {
|
|
|
|
if (!strcmp(prop, "lz4"))
|
|
|
|
entry->compress_algo = FMAP_COMPRESS_LZ4;
|
2021-07-05 22:32:40 +00:00
|
|
|
else if (!strcmp(prop, "lzma"))
|
|
|
|
entry->compress_algo = FMAP_COMPRESS_LZMA;
|
2018-10-01 18:22:08 +00:00
|
|
|
else
|
2021-01-21 20:57:14 +00:00
|
|
|
return log_msg_ret("compression algo", -EINVAL);
|
2018-10-01 18:22:08 +00:00
|
|
|
} else {
|
|
|
|
entry->compress_algo = FMAP_COMPRESS_NONE;
|
|
|
|
}
|
|
|
|
entry->unc_length = ofnode_read_s32_default(node, "uncomp-size",
|
|
|
|
entry->length);
|
2021-01-21 20:57:14 +00:00
|
|
|
subnode = ofnode_find_subnode(node, "hash");
|
|
|
|
if (ofnode_valid(subnode)) {
|
|
|
|
prop = ofnode_read_prop(subnode, "value", &entry->hash_size);
|
|
|
|
|
|
|
|
/* Assume it is sha256 */
|
|
|
|
entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
|
|
|
|
entry->hash = (uint8_t *)prop;
|
|
|
|
}
|
2017-05-19 02:09:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-11 19:07:18 +00:00
|
|
|
|
|
|
|
int ofnode_decode_region(ofnode node, const char *prop_name, fdt_addr_t *basep,
|
|
|
|
fdt_size_t *sizep)
|
|
|
|
{
|
|
|
|
const fdt_addr_t *cell;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
debug("%s: %s: %s\n", __func__, ofnode_get_name(node), prop_name);
|
|
|
|
cell = ofnode_get_property(node, prop_name, &len);
|
|
|
|
if (!cell || (len < sizeof(fdt_addr_t) * 2)) {
|
|
|
|
debug("cell=%p, len=%d\n", cell, len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*basep = fdt_addr_to_cpu(*cell);
|
|
|
|
*sizep = fdt_size_to_cpu(cell[1]);
|
|
|
|
debug("%s: base=%08lx, size=%lx\n", __func__, (ulong)*basep,
|
|
|
|
(ulong)*sizep);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
|
|
|
|
const char *suffix, fdt_addr_t *basep,
|
|
|
|
fdt_size_t *sizep)
|
|
|
|
{
|
|
|
|
char prop_name[50];
|
|
|
|
const char *mem;
|
|
|
|
fdt_size_t size, offset_size;
|
|
|
|
fdt_addr_t base, offset;
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
if (!ofnode_valid(config_node)) {
|
|
|
|
config_node = ofnode_path("/config");
|
|
|
|
if (!ofnode_valid(config_node)) {
|
|
|
|
debug("%s: Cannot find /config node\n", __func__);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!suffix)
|
|
|
|
suffix = "";
|
|
|
|
|
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s-memory%s", mem_type,
|
|
|
|
suffix);
|
|
|
|
mem = ofnode_read_string(config_node, prop_name);
|
|
|
|
if (!mem) {
|
|
|
|
debug("%s: No memory type for '%s', using /memory\n", __func__,
|
|
|
|
prop_name);
|
|
|
|
mem = "/memory";
|
|
|
|
}
|
|
|
|
|
|
|
|
node = ofnode_path(mem);
|
|
|
|
if (!ofnode_valid(node)) {
|
|
|
|
debug("%s: Failed to find node '%s'\n", __func__, mem);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not strictly correct - the memory may have multiple banks. We just
|
|
|
|
* use the first
|
|
|
|
*/
|
|
|
|
if (ofnode_decode_region(node, "reg", &base, &size)) {
|
|
|
|
debug("%s: Failed to decode memory region %s\n", __func__,
|
|
|
|
mem);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s-offset%s", mem_type,
|
|
|
|
suffix);
|
|
|
|
if (ofnode_decode_region(config_node, prop_name, &offset,
|
|
|
|
&offset_size)) {
|
|
|
|
debug("%s: Failed to decode memory region '%s'\n", __func__,
|
|
|
|
prop_name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*basep = base + offset;
|
|
|
|
*sizep = offset_size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-03-14 12:14:46 +00:00
|
|
|
|
|
|
|
bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node)
|
|
|
|
{
|
|
|
|
ofnode node, subnode;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
subnode = ofnode_find_subnode(eth_node, "fixed-link");
|
|
|
|
if (ofnode_valid(subnode)) {
|
|
|
|
/* new binding */
|
|
|
|
node = subnode;
|
|
|
|
} else if (ofnode_get_property(eth_node, "fixed-link", &len) &&
|
|
|
|
len == (5 * sizeof(__be32))) {
|
|
|
|
/* old binding */
|
|
|
|
node = eth_node;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phy_node)
|
|
|
|
*phy_node = node;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
net: introduce a helper to determine whether to use in-band autoneg
Certain serial SERDES protocols like 1000base-x, 2500base-x, SGMII,
USXGMII can operate either in a mode where the PHY (be it on-board or
inside an SFP module) passes the link parameters (speed, duplex, pause)
to the MAC through in-band through control words standardized by IEEE
802.3 clause 37, or in a mode where the MAC must configure (force) its
link parameters based on information obtained out-of-band (MDIO reads,
guesswork etc).
In Linux, the OF node property named "managed" is parsed by the phylink
framework, and the convention is that if a driver uses phylink, then the
presence of this property means that in-band autoneg should be enabled,
otherwise it shouldn't.
To be compatible with the OF node bindings of drivers that use phylink
in Linux, introduce parsing support for this property in U-Boot too.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
2021-09-29 15:04:39 +00:00
|
|
|
|
|
|
|
bool ofnode_eth_uses_inband_aneg(ofnode eth_node)
|
|
|
|
{
|
|
|
|
bool inband_aneg = false;
|
|
|
|
const char *managed;
|
|
|
|
|
|
|
|
managed = ofnode_read_string(eth_node, "managed");
|
|
|
|
if (managed && !strcmp(managed, "in-band-status"))
|
|
|
|
inband_aneg = true;
|
|
|
|
|
|
|
|
return inband_aneg;
|
|
|
|
}
|