property.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #ifndef _LINUX_PROPERTY_H_
  13. #define _LINUX_PROPERTY_H_
  14. #include <linux/fwnode.h>
  15. #include <linux/types.h>
  16. struct device;
  17. enum dev_prop_type {
  18. DEV_PROP_U8,
  19. DEV_PROP_U16,
  20. DEV_PROP_U32,
  21. DEV_PROP_U64,
  22. DEV_PROP_STRING,
  23. DEV_PROP_MAX,
  24. };
  25. enum dev_dma_attr {
  26. DEV_DMA_NOT_SUPPORTED,
  27. DEV_DMA_NON_COHERENT,
  28. DEV_DMA_COHERENT,
  29. };
  30. bool device_property_present(struct device *dev, const char *propname);
  31. int device_property_read_u8_array(struct device *dev, const char *propname,
  32. u8 *val, size_t nval);
  33. int device_property_read_u16_array(struct device *dev, const char *propname,
  34. u16 *val, size_t nval);
  35. int device_property_read_u32_array(struct device *dev, const char *propname,
  36. u32 *val, size_t nval);
  37. int device_property_read_u64_array(struct device *dev, const char *propname,
  38. u64 *val, size_t nval);
  39. int device_property_read_string_array(struct device *dev, const char *propname,
  40. const char **val, size_t nval);
  41. int device_property_read_string(struct device *dev, const char *propname,
  42. const char **val);
  43. int device_property_match_string(struct device *dev,
  44. const char *propname, const char *string);
  45. bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname);
  46. int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
  47. const char *propname, u8 *val,
  48. size_t nval);
  49. int fwnode_property_read_u16_array(struct fwnode_handle *fwnode,
  50. const char *propname, u16 *val,
  51. size_t nval);
  52. int fwnode_property_read_u32_array(struct fwnode_handle *fwnode,
  53. const char *propname, u32 *val,
  54. size_t nval);
  55. int fwnode_property_read_u64_array(struct fwnode_handle *fwnode,
  56. const char *propname, u64 *val,
  57. size_t nval);
  58. int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
  59. const char *propname, const char **val,
  60. size_t nval);
  61. int fwnode_property_read_string(struct fwnode_handle *fwnode,
  62. const char *propname, const char **val);
  63. int fwnode_property_match_string(struct fwnode_handle *fwnode,
  64. const char *propname, const char *string);
  65. struct fwnode_handle *device_get_next_child_node(struct device *dev,
  66. struct fwnode_handle *child);
  67. #define device_for_each_child_node(dev, child) \
  68. for (child = device_get_next_child_node(dev, NULL); child; \
  69. child = device_get_next_child_node(dev, child))
  70. void fwnode_handle_put(struct fwnode_handle *fwnode);
  71. unsigned int device_get_child_node_count(struct device *dev);
  72. static inline bool device_property_read_bool(struct device *dev,
  73. const char *propname)
  74. {
  75. return device_property_present(dev, propname);
  76. }
  77. static inline int device_property_read_u8(struct device *dev,
  78. const char *propname, u8 *val)
  79. {
  80. return device_property_read_u8_array(dev, propname, val, 1);
  81. }
  82. static inline int device_property_read_u16(struct device *dev,
  83. const char *propname, u16 *val)
  84. {
  85. return device_property_read_u16_array(dev, propname, val, 1);
  86. }
  87. static inline int device_property_read_u32(struct device *dev,
  88. const char *propname, u32 *val)
  89. {
  90. return device_property_read_u32_array(dev, propname, val, 1);
  91. }
  92. static inline int device_property_read_u64(struct device *dev,
  93. const char *propname, u64 *val)
  94. {
  95. return device_property_read_u64_array(dev, propname, val, 1);
  96. }
  97. static inline bool fwnode_property_read_bool(struct fwnode_handle *fwnode,
  98. const char *propname)
  99. {
  100. return fwnode_property_present(fwnode, propname);
  101. }
  102. static inline int fwnode_property_read_u8(struct fwnode_handle *fwnode,
  103. const char *propname, u8 *val)
  104. {
  105. return fwnode_property_read_u8_array(fwnode, propname, val, 1);
  106. }
  107. static inline int fwnode_property_read_u16(struct fwnode_handle *fwnode,
  108. const char *propname, u16 *val)
  109. {
  110. return fwnode_property_read_u16_array(fwnode, propname, val, 1);
  111. }
  112. static inline int fwnode_property_read_u32(struct fwnode_handle *fwnode,
  113. const char *propname, u32 *val)
  114. {
  115. return fwnode_property_read_u32_array(fwnode, propname, val, 1);
  116. }
  117. static inline int fwnode_property_read_u64(struct fwnode_handle *fwnode,
  118. const char *propname, u64 *val)
  119. {
  120. return fwnode_property_read_u64_array(fwnode, propname, val, 1);
  121. }
  122. /**
  123. * struct property_entry - "Built-in" device property representation.
  124. * @name: Name of the property.
  125. * @type: Type of the property.
  126. * @nval: Number of items of type @type making up the value.
  127. * @value: Value of the property (an array of @nval items of type @type).
  128. */
  129. struct property_entry {
  130. const char *name;
  131. enum dev_prop_type type;
  132. size_t nval;
  133. union {
  134. void *raw_data;
  135. u8 *u8_data;
  136. u16 *u16_data;
  137. u32 *u32_data;
  138. u64 *u64_data;
  139. const char **str;
  140. } value;
  141. };
  142. /**
  143. * struct property_set - Collection of "built-in" device properties.
  144. * @fwnode: Handle to be pointed to by the fwnode field of struct device.
  145. * @properties: Array of properties terminated with a null entry.
  146. */
  147. struct property_set {
  148. struct fwnode_handle fwnode;
  149. struct property_entry *properties;
  150. };
  151. void device_add_property_set(struct device *dev, struct property_set *pset);
  152. bool device_dma_supported(struct device *dev);
  153. enum dev_dma_attr device_get_dma_attr(struct device *dev);
  154. int device_get_phy_mode(struct device *dev);
  155. void *device_get_mac_address(struct device *dev, char *addr, int alen);
  156. #endif /* _LINUX_PROPERTY_H_ */