2019-06-04 11:11:33 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2014-11-04 03:28:56 +03:00
|
|
|
/*
|
|
|
|
* property.h - Unified device property interface.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014, Intel Corporation
|
|
|
|
* Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
|
|
|
|
* Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_PROPERTY_H_
|
|
|
|
#define _LINUX_PROPERTY_H_
|
|
|
|
|
2019-04-02 13:30:37 +03:00
|
|
|
#include <linux/bits.h>
|
2015-03-17 01:49:03 +03:00
|
|
|
#include <linux/fwnode.h>
|
2014-11-04 03:28:56 +03:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
struct device;
|
|
|
|
|
|
|
|
enum dev_prop_type {
|
|
|
|
DEV_PROP_U8,
|
|
|
|
DEV_PROP_U16,
|
|
|
|
DEV_PROP_U32,
|
|
|
|
DEV_PROP_U64,
|
|
|
|
DEV_PROP_STRING,
|
|
|
|
DEV_PROP_MAX,
|
|
|
|
};
|
|
|
|
|
2015-10-29 01:50:47 +03:00
|
|
|
enum dev_dma_attr {
|
|
|
|
DEV_DMA_NOT_SUPPORTED,
|
|
|
|
DEV_DMA_NON_COHERENT,
|
|
|
|
DEV_DMA_COHERENT,
|
|
|
|
};
|
|
|
|
|
2017-03-28 10:52:24 +03:00
|
|
|
struct fwnode_handle *dev_fwnode(struct device *dev);
|
|
|
|
|
2014-11-04 03:28:56 +03:00
|
|
|
bool device_property_present(struct device *dev, const char *propname);
|
|
|
|
int device_property_read_u8_array(struct device *dev, const char *propname,
|
|
|
|
u8 *val, size_t nval);
|
|
|
|
int device_property_read_u16_array(struct device *dev, const char *propname,
|
|
|
|
u16 *val, size_t nval);
|
|
|
|
int device_property_read_u32_array(struct device *dev, const char *propname,
|
|
|
|
u32 *val, size_t nval);
|
|
|
|
int device_property_read_u64_array(struct device *dev, const char *propname,
|
|
|
|
u64 *val, size_t nval);
|
|
|
|
int device_property_read_string_array(struct device *dev, const char *propname,
|
|
|
|
const char **val, size_t nval);
|
|
|
|
int device_property_read_string(struct device *dev, const char *propname,
|
|
|
|
const char **val);
|
2015-09-14 17:37:35 +03:00
|
|
|
int device_property_match_string(struct device *dev,
|
|
|
|
const char *propname, const char *string);
|
2014-11-04 03:28:56 +03:00
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
|
|
|
|
bool fwnode_property_present(const struct fwnode_handle *fwnode,
|
|
|
|
const char *propname);
|
|
|
|
int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u8 *val,
|
|
|
|
size_t nval);
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u16 *val,
|
|
|
|
size_t nval);
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u32 *val,
|
|
|
|
size_t nval);
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u64 *val,
|
|
|
|
size_t nval);
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, const char **val,
|
|
|
|
size_t nval);
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_property_read_string(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, const char **val);
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_property_match_string(const struct fwnode_handle *fwnode,
|
2015-09-14 17:37:35 +03:00
|
|
|
const char *propname, const char *string);
|
2017-07-21 15:11:49 +03:00
|
|
|
int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
|
|
|
|
const char *prop, const char *nargs_prop,
|
|
|
|
unsigned int nargs, unsigned int index,
|
|
|
|
struct fwnode_reference_args *args);
|
2014-11-04 16:03:59 +03:00
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
|
|
|
|
struct fwnode_handle *fwnode_get_next_parent(
|
|
|
|
struct fwnode_handle *fwnode);
|
|
|
|
struct fwnode_handle *fwnode_get_next_child_node(
|
|
|
|
const struct fwnode_handle *fwnode, struct fwnode_handle *child);
|
2018-01-18 15:31:41 +03:00
|
|
|
struct fwnode_handle *fwnode_get_next_available_child_node(
|
|
|
|
const struct fwnode_handle *fwnode, struct fwnode_handle *child);
|
2017-03-28 10:52:18 +03:00
|
|
|
|
|
|
|
#define fwnode_for_each_child_node(fwnode, child) \
|
|
|
|
for (child = fwnode_get_next_child_node(fwnode, NULL); child; \
|
|
|
|
child = fwnode_get_next_child_node(fwnode, child))
|
2017-03-28 10:52:17 +03:00
|
|
|
|
2018-01-18 15:31:41 +03:00
|
|
|
#define fwnode_for_each_available_child_node(fwnode, child) \
|
|
|
|
for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
|
|
|
|
child = fwnode_get_next_available_child_node(fwnode, child))
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
struct fwnode_handle *device_get_next_child_node(
|
|
|
|
struct device *dev, struct fwnode_handle *child);
|
2014-11-04 16:03:59 +03:00
|
|
|
|
2015-11-30 18:11:34 +03:00
|
|
|
#define device_for_each_child_node(dev, child) \
|
|
|
|
for (child = device_get_next_child_node(dev, NULL); child; \
|
2014-11-04 16:03:59 +03:00
|
|
|
child = device_get_next_child_node(dev, child))
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
struct fwnode_handle *fwnode_get_named_child_node(
|
|
|
|
const struct fwnode_handle *fwnode, const char *childname);
|
2016-06-21 20:50:20 +03:00
|
|
|
struct fwnode_handle *device_get_named_child_node(struct device *dev,
|
|
|
|
const char *childname);
|
|
|
|
|
2017-09-19 12:39:11 +03:00
|
|
|
struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
|
2014-11-04 16:03:59 +03:00
|
|
|
void fwnode_handle_put(struct fwnode_handle *fwnode);
|
|
|
|
|
2018-01-18 15:31:40 +03:00
|
|
|
int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
|
|
|
|
|
2014-11-04 16:03:59 +03:00
|
|
|
unsigned int device_get_child_node_count(struct device *dev);
|
|
|
|
|
2014-11-04 03:28:56 +03:00
|
|
|
static inline bool device_property_read_bool(struct device *dev,
|
|
|
|
const char *propname)
|
|
|
|
{
|
|
|
|
return device_property_present(dev, propname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int device_property_read_u8(struct device *dev,
|
|
|
|
const char *propname, u8 *val)
|
|
|
|
{
|
|
|
|
return device_property_read_u8_array(dev, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int device_property_read_u16(struct device *dev,
|
|
|
|
const char *propname, u16 *val)
|
|
|
|
{
|
|
|
|
return device_property_read_u16_array(dev, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int device_property_read_u32(struct device *dev,
|
|
|
|
const char *propname, u32 *val)
|
|
|
|
{
|
|
|
|
return device_property_read_u32_array(dev, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int device_property_read_u64(struct device *dev,
|
|
|
|
const char *propname, u64 *val)
|
|
|
|
{
|
|
|
|
return device_property_read_u64_array(dev, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname)
|
|
|
|
{
|
|
|
|
return fwnode_property_present(fwnode, propname);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u8 *val)
|
|
|
|
{
|
|
|
|
return fwnode_property_read_u8_array(fwnode, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u16 *val)
|
|
|
|
{
|
|
|
|
return fwnode_property_read_u16_array(fwnode, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u32 *val)
|
|
|
|
{
|
|
|
|
return fwnode_property_read_u32_array(fwnode, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
|
2014-11-04 16:03:59 +03:00
|
|
|
const char *propname, u64 *val)
|
|
|
|
{
|
|
|
|
return fwnode_property_read_u64_array(fwnode, propname, val, 1);
|
|
|
|
}
|
|
|
|
|
2015-04-03 17:05:11 +03:00
|
|
|
/**
|
|
|
|
* struct property_entry - "Built-in" device property representation.
|
|
|
|
* @name: Name of the property.
|
2015-11-30 18:11:31 +03:00
|
|
|
* @length: Length of data making up the value.
|
2015-11-30 18:11:32 +03:00
|
|
|
* @is_array: True when the property is an array.
|
2018-05-15 20:32:02 +03:00
|
|
|
* @type: Type of the data in unions.
|
2015-11-30 18:11:32 +03:00
|
|
|
* @pointer: Pointer to the property (an array of items of the given type).
|
|
|
|
* @value: Value of the property (when it is a single item of the given type).
|
2015-04-03 17:05:11 +03:00
|
|
|
*/
|
|
|
|
struct property_entry {
|
|
|
|
const char *name;
|
2015-11-30 18:11:31 +03:00
|
|
|
size_t length;
|
2015-11-30 18:11:32 +03:00
|
|
|
bool is_array;
|
2018-05-15 20:32:02 +03:00
|
|
|
enum dev_prop_type type;
|
2015-04-03 17:05:11 +03:00
|
|
|
union {
|
2015-11-30 18:11:32 +03:00
|
|
|
union {
|
2017-02-03 04:41:26 +03:00
|
|
|
const u8 *u8_data;
|
|
|
|
const u16 *u16_data;
|
|
|
|
const u32 *u32_data;
|
|
|
|
const u64 *u64_data;
|
|
|
|
const char * const *str;
|
2015-11-30 18:11:32 +03:00
|
|
|
} pointer;
|
|
|
|
union {
|
|
|
|
u8 u8_data;
|
|
|
|
u16 u16_data;
|
|
|
|
u32 u32_data;
|
|
|
|
u64 u64_data;
|
|
|
|
const char *str;
|
|
|
|
} value;
|
|
|
|
};
|
2015-04-03 17:05:11 +03:00
|
|
|
};
|
|
|
|
|
2016-01-01 04:07:09 +03:00
|
|
|
/*
|
|
|
|
* Note: the below four initializers for the anonymous union are carefully
|
|
|
|
* crafted to avoid gcc-4.4.4's problems with initialization of anon unions
|
|
|
|
* and structs.
|
|
|
|
*/
|
|
|
|
|
2018-05-15 20:32:02 +03:00
|
|
|
#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _Type_, _val_) \
|
|
|
|
(struct property_entry) { \
|
|
|
|
.name = _name_, \
|
|
|
|
.length = ARRAY_SIZE(_val_) * sizeof(_type_), \
|
|
|
|
.is_array = true, \
|
|
|
|
.type = DEV_PROP_##_Type_, \
|
|
|
|
{ .pointer = { ._type_##_data = _val_ } }, \
|
2015-11-30 18:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u8, U8, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u16, U16, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u32, U32, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u64, U64, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
|
|
|
|
#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \
|
2018-01-22 19:01:42 +03:00
|
|
|
(struct property_entry) { \
|
2015-11-30 18:11:33 +03:00
|
|
|
.name = _name_, \
|
|
|
|
.length = ARRAY_SIZE(_val_) * sizeof(const char *), \
|
|
|
|
.is_array = true, \
|
2018-05-15 20:32:02 +03:00
|
|
|
.type = DEV_PROP_STRING, \
|
2016-01-01 04:07:09 +03:00
|
|
|
{ .pointer = { .str = _val_ } }, \
|
2015-11-30 18:11:33 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:32:02 +03:00
|
|
|
#define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \
|
|
|
|
(struct property_entry) { \
|
|
|
|
.name = _name_, \
|
|
|
|
.length = sizeof(_type_), \
|
|
|
|
.type = DEV_PROP_##_Type_, \
|
|
|
|
{ .value = { ._type_##_data = _val_ } }, \
|
2015-11-30 18:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PROPERTY_ENTRY_U8(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
#define PROPERTY_ENTRY_U16(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
#define PROPERTY_ENTRY_U32(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
#define PROPERTY_ENTRY_U64(_name_, _val_) \
|
2018-05-15 20:32:02 +03:00
|
|
|
PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_)
|
2015-11-30 18:11:33 +03:00
|
|
|
|
|
|
|
#define PROPERTY_ENTRY_STRING(_name_, _val_) \
|
2018-01-22 19:01:42 +03:00
|
|
|
(struct property_entry) { \
|
2015-11-30 18:11:33 +03:00
|
|
|
.name = _name_, \
|
2019-01-23 17:44:16 +03:00
|
|
|
.length = sizeof(const char *), \
|
2018-05-15 20:32:02 +03:00
|
|
|
.type = DEV_PROP_STRING, \
|
2015-12-29 14:07:48 +03:00
|
|
|
{ .value = { .str = _val_ } }, \
|
2015-11-30 18:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PROPERTY_ENTRY_BOOL(_name_) \
|
2018-01-22 19:01:42 +03:00
|
|
|
(struct property_entry) { \
|
2015-11-30 18:11:33 +03:00
|
|
|
.name = _name_, \
|
|
|
|
}
|
|
|
|
|
2017-02-03 04:41:27 +03:00
|
|
|
struct property_entry *
|
|
|
|
property_entries_dup(const struct property_entry *properties);
|
|
|
|
|
|
|
|
void property_entries_free(const struct property_entry *properties);
|
|
|
|
|
2016-03-29 14:52:23 +03:00
|
|
|
int device_add_properties(struct device *dev,
|
2017-02-03 04:41:25 +03:00
|
|
|
const struct property_entry *properties);
|
2016-03-29 14:52:23 +03:00
|
|
|
void device_remove_properties(struct device *dev);
|
2015-04-03 17:05:11 +03:00
|
|
|
|
2015-10-29 01:50:49 +03:00
|
|
|
bool device_dma_supported(struct device *dev);
|
|
|
|
|
|
|
|
enum dev_dma_attr device_get_dma_attr(struct device *dev);
|
2017-12-13 10:20:49 +03:00
|
|
|
|
2018-02-09 18:38:36 +03:00
|
|
|
const void *device_get_match_data(struct device *dev);
|
2015-10-29 01:50:49 +03:00
|
|
|
|
2015-08-13 01:06:26 +03:00
|
|
|
int device_get_phy_mode(struct device *dev);
|
|
|
|
|
|
|
|
void *device_get_mac_address(struct device *dev, char *addr, int alen);
|
|
|
|
|
2018-01-18 15:31:39 +03:00
|
|
|
int fwnode_get_phy_mode(struct fwnode_handle *fwnode);
|
2018-01-18 15:31:38 +03:00
|
|
|
void *fwnode_get_mac_address(struct fwnode_handle *fwnode,
|
|
|
|
char *addr, int alen);
|
2017-03-28 10:52:21 +03:00
|
|
|
struct fwnode_handle *fwnode_graph_get_next_endpoint(
|
2017-07-21 14:39:36 +03:00
|
|
|
const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
|
2017-06-06 12:37:41 +03:00
|
|
|
struct fwnode_handle *
|
2017-07-21 14:39:36 +03:00
|
|
|
fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
|
2017-03-28 10:52:21 +03:00
|
|
|
struct fwnode_handle *fwnode_graph_get_remote_port_parent(
|
2017-07-21 14:39:36 +03:00
|
|
|
const struct fwnode_handle *fwnode);
|
2017-03-28 10:52:21 +03:00
|
|
|
struct fwnode_handle *fwnode_graph_get_remote_port(
|
2017-07-21 14:39:36 +03:00
|
|
|
const struct fwnode_handle *fwnode);
|
2017-03-28 10:52:21 +03:00
|
|
|
struct fwnode_handle *fwnode_graph_get_remote_endpoint(
|
2017-07-21 14:39:36 +03:00
|
|
|
const struct fwnode_handle *fwnode);
|
|
|
|
struct fwnode_handle *
|
|
|
|
fwnode_graph_get_remote_node(const struct fwnode_handle *fwnode, u32 port,
|
|
|
|
u32 endpoint);
|
2017-03-28 10:52:21 +03:00
|
|
|
|
2019-04-02 13:30:37 +03:00
|
|
|
/*
|
|
|
|
* Fwnode lookup flags
|
|
|
|
*
|
|
|
|
* @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the
|
|
|
|
* closest endpoint ID greater than the specified
|
|
|
|
* one.
|
|
|
|
* @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote
|
|
|
|
* endpoint of the given endpoint belongs to,
|
|
|
|
* may be disabled.
|
|
|
|
*/
|
|
|
|
#define FWNODE_GRAPH_ENDPOINT_NEXT BIT(0)
|
|
|
|
#define FWNODE_GRAPH_DEVICE_DISABLED BIT(1)
|
|
|
|
|
|
|
|
struct fwnode_handle *
|
|
|
|
fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
|
|
|
|
u32 port, u32 endpoint, unsigned long flags);
|
|
|
|
|
2017-09-19 12:39:12 +03:00
|
|
|
#define fwnode_graph_for_each_endpoint(fwnode, child) \
|
|
|
|
for (child = NULL; \
|
|
|
|
(child = fwnode_graph_get_next_endpoint(fwnode, child)); )
|
|
|
|
|
2017-07-21 14:39:36 +03:00
|
|
|
int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
|
2017-03-28 10:52:25 +03:00
|
|
|
struct fwnode_endpoint *endpoint);
|
|
|
|
|
2018-11-09 17:21:36 +03:00
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
/* Software fwnode support - when HW description is incomplete or missing */
|
|
|
|
|
|
|
|
bool is_software_node(const struct fwnode_handle *fwnode);
|
|
|
|
|
|
|
|
int software_node_notify(struct device *dev, unsigned long action);
|
|
|
|
|
|
|
|
struct fwnode_handle *
|
|
|
|
fwnode_create_software_node(const struct property_entry *properties,
|
|
|
|
const struct fwnode_handle *parent);
|
|
|
|
void fwnode_remove_software_node(struct fwnode_handle *fwnode);
|
|
|
|
|
2014-11-04 03:28:56 +03:00
|
|
|
#endif /* _LINUX_PROPERTY_H_ */
|