// SPDX-License-Identifier: GPL-2.0+
/*
* drivers/of/property.c - Procedures for accessing and interpreting
* Devicetree properties and graphs.
*
* Initially created by copying procedures from drivers/of/base.c. This
* file contains the OF property as well as the OF graph interface
* functions.
*
* Paul Mackerras August 1996.
* Copyright (C) 1996-2005 Paul Mackerras.
*
* Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
* {engebret|bergner}@us.ibm.com
*
* Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
*
* Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
* Grant Likely.
*/
#define pr_fmt(fmt) "OF: " fmt
#include <linux/ctype.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/of_graph.h>
#include <linux/of_irq.h>
#include <linux/string.h>
#include <linux/moduleparam.h>
#include "of_private.h"
/**
* of_property_read_bool - Find a property
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
*
* Search for a boolean property in a device node. Usage on non-boolean
* property types is deprecated.
*
* Return: true if the property exists false otherwise.
*/
bool of_property_read_bool(const struct device_node *np, const char *propname)
{
struct property *prop = of_find_property(np, propname, NULL);
/*
* Boolean properties should not have a value. Testing for property
* presence should either use of_property_present() or just read the
* property value and check the returned error code.
*/
if (prop && prop->length)
pr_warn("%pOF: Read of boolean property '%s' with a value.\n", np, propname);
return prop ? true : false;
}
EXPORT_SYMBOL(of_property_read_bool);
/**
* of_graph_is_present() - check graph's presence
* @node: pointer to device_node containing graph port
*
* Return: True if @node has a port or ports (with a port) sub-node,
* false otherwise.
*/
bool of_graph_is_present(const struct device_node *node)
{
struct device_node *ports __free(device_node) = of_get_child_by_name(node, "ports");
if (ports)
node = ports;
struct device_node *port __free(device_node) = of_get_child_by_name(node, "port");
return !!port;
}
EXPORT_SYMBOL(of_graph_is_present);
/**
* of_property_count_elems_of_size - Count the number of elements in a property
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @elem_size: size of the individual element
*
* Search for a property in a d
|