1/* 2 * property.h - Unified device property interface. 3 * 4 * Copyright (C) 2014, Intel Corporation 5 * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> 6 * Mika Westerberg <mika.westerberg@linux.intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 */ 12 13#ifndef _LINUX_PROPERTY_H_ 14#define _LINUX_PROPERTY_H_ 15 16#include <linux/fwnode.h> 17#include <linux/types.h> 18 19struct device; 20 21enum dev_prop_type { 22 DEV_PROP_U8, 23 DEV_PROP_U16, 24 DEV_PROP_U32, 25 DEV_PROP_U64, 26 DEV_PROP_STRING, 27 DEV_PROP_MAX, 28}; 29 30bool device_property_present(struct device *dev, const char *propname); 31int device_property_read_u8_array(struct device *dev, const char *propname, 32 u8 *val, size_t nval); 33int device_property_read_u16_array(struct device *dev, const char *propname, 34 u16 *val, size_t nval); 35int device_property_read_u32_array(struct device *dev, const char *propname, 36 u32 *val, size_t nval); 37int device_property_read_u64_array(struct device *dev, const char *propname, 38 u64 *val, size_t nval); 39int device_property_read_string_array(struct device *dev, const char *propname, 40 const char **val, size_t nval); 41int device_property_read_string(struct device *dev, const char *propname, 42 const char **val); 43 44bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname); 45int fwnode_property_read_u8_array(struct fwnode_handle *fwnode, 46 const char *propname, u8 *val, 47 size_t nval); 48int fwnode_property_read_u16_array(struct fwnode_handle *fwnode, 49 const char *propname, u16 *val, 50 size_t nval); 51int fwnode_property_read_u32_array(struct fwnode_handle *fwnode, 52 const char *propname, u32 *val, 53 size_t nval); 54int fwnode_property_read_u64_array(struct fwnode_handle *fwnode, 55 const char *propname, u64 *val, 56 size_t nval); 57int fwnode_property_read_string_array(struct fwnode_handle *fwnode, 58 const char *propname, const char **val, 59 size_t nval); 60int fwnode_property_read_string(struct fwnode_handle *fwnode, 61 const char *propname, const char **val); 62 63struct fwnode_handle *device_get_next_child_node(struct device *dev, 64 struct fwnode_handle *child); 65 66#define device_for_each_child_node(dev, child) \ 67 for (child = device_get_next_child_node(dev, NULL); child; \ 68 child = device_get_next_child_node(dev, child)) 69 70void fwnode_handle_put(struct fwnode_handle *fwnode); 71 72unsigned int device_get_child_node_count(struct device *dev); 73 74static inline bool device_property_read_bool(struct device *dev, 75 const char *propname) 76{ 77 return device_property_present(dev, propname); 78} 79 80static inline int device_property_read_u8(struct device *dev, 81 const char *propname, u8 *val) 82{ 83 return device_property_read_u8_array(dev, propname, val, 1); 84} 85 86static inline int device_property_read_u16(struct device *dev, 87 const char *propname, u16 *val) 88{ 89 return device_property_read_u16_array(dev, propname, val, 1); 90} 91 92static inline int device_property_read_u32(struct device *dev, 93 const char *propname, u32 *val) 94{ 95 return device_property_read_u32_array(dev, propname, val, 1); 96} 97 98static inline int device_property_read_u64(struct device *dev, 99 const char *propname, u64 *val) 100{ 101 return device_property_read_u64_array(dev, propname, val, 1); 102} 103 104static inline bool fwnode_property_read_bool(struct fwnode_handle *fwnode, 105 const char *propname) 106{ 107 return fwnode_property_present(fwnode, propname); 108} 109 110static inline int fwnode_property_read_u8(struct fwnode_handle *fwnode, 111 const char *propname, u8 *val) 112{ 113 return fwnode_property_read_u8_array(fwnode, propname, val, 1); 114} 115 116static inline int fwnode_property_read_u16(struct fwnode_handle *fwnode, 117 const char *propname, u16 *val) 118{ 119 return fwnode_property_read_u16_array(fwnode, propname, val, 1); 120} 121 122static inline int fwnode_property_read_u32(struct fwnode_handle *fwnode, 123 const char *propname, u32 *val) 124{ 125 return fwnode_property_read_u32_array(fwnode, propname, val, 1); 126} 127 128static inline int fwnode_property_read_u64(struct fwnode_handle *fwnode, 129 const char *propname, u64 *val) 130{ 131 return fwnode_property_read_u64_array(fwnode, propname, val, 1); 132} 133 134/** 135 * struct property_entry - "Built-in" device property representation. 136 * @name: Name of the property. 137 * @type: Type of the property. 138 * @nval: Number of items of type @type making up the value. 139 * @value: Value of the property (an array of @nval items of type @type). 140 */ 141struct property_entry { 142 const char *name; 143 enum dev_prop_type type; 144 size_t nval; 145 union { 146 void *raw_data; 147 u8 *u8_data; 148 u16 *u16_data; 149 u32 *u32_data; 150 u64 *u64_data; 151 const char **str; 152 } value; 153}; 154 155/** 156 * struct property_set - Collection of "built-in" device properties. 157 * @fwnode: Handle to be pointed to by the fwnode field of struct device. 158 * @properties: Array of properties terminated with a null entry. 159 */ 160struct property_set { 161 struct fwnode_handle fwnode; 162 struct property_entry *properties; 163}; 164 165void device_add_property_set(struct device *dev, struct property_set *pset); 166 167#endif /* _LINUX_PROPERTY_H_ */ 168