Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

driver core: Implement device property accessors through fwnode ones

Now that the ACPI companions of devices are pointed to by the fwnode
field in struct device, the device_property_*() accessor functions
can be modified to use their fwnode_property_*() counterparts
internally with minimum extra overhead in the IS_ENABLED(CONFIG_OF)
case, so make those changes.

This allows us to get rid of the rather ugly DEV_PROP_READ_ARRAY()
macro among other things.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+17 -28
+17 -28
drivers/base/property.c
··· 15 15 #include <linux/acpi.h> 16 16 #include <linux/of.h> 17 17 18 + static inline struct fwnode_handle *dev_fwnode(struct device *dev) 19 + { 20 + return IS_ENABLED(CONFIG_OF) && dev->of_node ? 21 + &dev->of_node->fwnode : dev->fwnode; 22 + } 23 + 18 24 /** 19 25 * device_property_present - check if a property of a device is present 20 26 * @dev: Device whose property is being checked ··· 30 24 */ 31 25 bool device_property_present(struct device *dev, const char *propname) 32 26 { 33 - if (IS_ENABLED(CONFIG_OF) && dev->of_node) 34 - return of_property_read_bool(dev->of_node, propname); 35 - 36 - return !acpi_dev_prop_get(ACPI_COMPANION(dev), propname, NULL); 27 + return fwnode_property_present(dev_fwnode(dev), propname); 37 28 } 38 29 EXPORT_SYMBOL_GPL(device_property_present); 39 30 ··· 49 46 return false; 50 47 } 51 48 EXPORT_SYMBOL_GPL(fwnode_property_present); 52 - 53 - #define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \ 54 - (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \ 55 - : of_property_count_elems_of_size((node), (propname), sizeof(type)) 56 - 57 - #define DEV_PROP_READ_ARRAY(_dev_, _propname_, _type_, _proptype_, _val_, _nval_) \ 58 - IS_ENABLED(CONFIG_OF) && _dev_->of_node ? \ 59 - (OF_DEV_PROP_READ_ARRAY(_dev_->of_node, _propname_, _type_, \ 60 - _val_, _nval_)) : \ 61 - acpi_dev_prop_read(ACPI_COMPANION(_dev_), _propname_, \ 62 - _proptype_, _val_, _nval_) 63 49 64 50 /** 65 51 * device_property_read_u8_array - return a u8 array property of a device ··· 70 78 int device_property_read_u8_array(struct device *dev, const char *propname, 71 79 u8 *val, size_t nval) 72 80 { 73 - return DEV_PROP_READ_ARRAY(dev, propname, u8, DEV_PROP_U8, val, nval); 81 + return fwnode_property_read_u8_array(dev_fwnode(dev), propname, val, nval); 74 82 } 75 83 EXPORT_SYMBOL_GPL(device_property_read_u8_array); 76 84 ··· 94 102 int device_property_read_u16_array(struct device *dev, const char *propname, 95 103 u16 *val, size_t nval) 96 104 { 97 - return DEV_PROP_READ_ARRAY(dev, propname, u16, DEV_PROP_U16, val, nval); 105 + return fwnode_property_read_u16_array(dev_fwnode(dev), propname, val, nval); 98 106 } 99 107 EXPORT_SYMBOL_GPL(device_property_read_u16_array); 100 108 ··· 118 126 int device_property_read_u32_array(struct device *dev, const char *propname, 119 127 u32 *val, size_t nval) 120 128 { 121 - return DEV_PROP_READ_ARRAY(dev, propname, u32, DEV_PROP_U32, val, nval); 129 + return fwnode_property_read_u32_array(dev_fwnode(dev), propname, val, nval); 122 130 } 123 131 EXPORT_SYMBOL_GPL(device_property_read_u32_array); 124 132 ··· 142 150 int device_property_read_u64_array(struct device *dev, const char *propname, 143 151 u64 *val, size_t nval) 144 152 { 145 - return DEV_PROP_READ_ARRAY(dev, propname, u64, DEV_PROP_U64, val, nval); 153 + return fwnode_property_read_u64_array(dev_fwnode(dev), propname, val, nval); 146 154 } 147 155 EXPORT_SYMBOL_GPL(device_property_read_u64_array); 148 156 ··· 166 174 int device_property_read_string_array(struct device *dev, const char *propname, 167 175 const char **val, size_t nval) 168 176 { 169 - return IS_ENABLED(CONFIG_OF) && dev->of_node ? 170 - (val ? of_property_read_string_array(dev->of_node, propname, val, nval) 171 - : of_property_count_strings(dev->of_node, propname)) : 172 - acpi_dev_prop_read(ACPI_COMPANION(dev), propname, 173 - DEV_PROP_STRING, val, nval); 177 + return fwnode_property_read_string_array(dev_fwnode(dev), propname, val, nval); 174 178 } 175 179 EXPORT_SYMBOL_GPL(device_property_read_string_array); 176 180 ··· 187 199 int device_property_read_string(struct device *dev, const char *propname, 188 200 const char **val) 189 201 { 190 - return IS_ENABLED(CONFIG_OF) && dev->of_node ? 191 - of_property_read_string(dev->of_node, propname, val) : 192 - acpi_dev_prop_read(ACPI_COMPANION(dev), propname, 193 - DEV_PROP_STRING, val, 1); 202 + return fwnode_property_read_string(dev_fwnode(dev), propname, val); 194 203 } 195 204 EXPORT_SYMBOL_GPL(device_property_read_string); 205 + 206 + #define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \ 207 + (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \ 208 + : of_property_count_elems_of_size((node), (propname), sizeof(type)) 196 209 197 210 #define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \ 198 211 ({ \