aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-03-23 19:24:16 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-03-25 16:00:09 -0400
commit9017f25254e474f2cc05df489e4f83b972d3d6fd (patch)
treea1f0adcf2b1674e581333de2dc5d011d8d5be091
parentfe0a20a3eff282efae9f891fd10081a9e2b45c96 (diff)
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>
-rw-r--r--drivers/base/property.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/drivers/base/property.c b/drivers/base/property.c
index cf3b2160e34e..62787bc89a1d 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -15,6 +15,12 @@
15#include <linux/acpi.h> 15#include <linux/acpi.h>
16#include <linux/of.h> 16#include <linux/of.h>
17 17
18static 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 * device_property_present - check if a property of a device is present 25 * device_property_present - check if a property of a device is present
20 * @dev: Device whose property is being checked 26 * @dev: Device whose property is being checked
@@ -24,10 +30,7 @@
24 */ 30 */
25bool device_property_present(struct device *dev, const char *propname) 31bool device_property_present(struct device *dev, const char *propname)
26{ 32{
27 if (IS_ENABLED(CONFIG_OF) && dev->of_node) 33 return fwnode_property_present(dev_fwnode(dev), propname);
28 return of_property_read_bool(dev->of_node, propname);
29
30 return !acpi_dev_prop_get(ACPI_COMPANION(dev), propname, NULL);
31} 34}
32EXPORT_SYMBOL_GPL(device_property_present); 35EXPORT_SYMBOL_GPL(device_property_present);
33 36
@@ -47,17 +50,6 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname)
47} 50}
48EXPORT_SYMBOL_GPL(fwnode_property_present); 51EXPORT_SYMBOL_GPL(fwnode_property_present);
49 52
50#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
51 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \
52 : of_property_count_elems_of_size((node), (propname), sizeof(type))
53
54#define DEV_PROP_READ_ARRAY(_dev_, _propname_, _type_, _proptype_, _val_, _nval_) \
55 IS_ENABLED(CONFIG_OF) && _dev_->of_node ? \
56 (OF_DEV_PROP_READ_ARRAY(_dev_->of_node, _propname_, _type_, \
57 _val_, _nval_)) : \
58 acpi_dev_prop_read(ACPI_COMPANION(_dev_), _propname_, \
59 _proptype_, _val_, _nval_)
60
61/** 53/**
62 * device_property_read_u8_array - return a u8 array property of a device 54 * device_property_read_u8_array - return a u8 array property of a device
63 * @dev: Device to get the property of 55 * @dev: Device to get the property of
@@ -78,7 +70,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_present);
78int device_property_read_u8_array(struct device *dev, const char *propname, 70int device_property_read_u8_array(struct device *dev, const char *propname,
79 u8 *val, size_t nval) 71 u8 *val, size_t nval)
80{ 72{
81 return DEV_PROP_READ_ARRAY(dev, propname, u8, DEV_PROP_U8, val, nval); 73 return fwnode_property_read_u8_array(dev_fwnode(dev), propname, val, nval);
82} 74}
83EXPORT_SYMBOL_GPL(device_property_read_u8_array); 75EXPORT_SYMBOL_GPL(device_property_read_u8_array);
84 76
@@ -102,7 +94,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u8_array);
102int device_property_read_u16_array(struct device *dev, const char *propname, 94int device_property_read_u16_array(struct device *dev, const char *propname,
103 u16 *val, size_t nval) 95 u16 *val, size_t nval)
104{ 96{
105 return DEV_PROP_READ_ARRAY(dev, propname, u16, DEV_PROP_U16, val, nval); 97 return fwnode_property_read_u16_array(dev_fwnode(dev), propname, val, nval);
106} 98}
107EXPORT_SYMBOL_GPL(device_property_read_u16_array); 99EXPORT_SYMBOL_GPL(device_property_read_u16_array);
108 100
@@ -126,7 +118,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u16_array);
126int device_property_read_u32_array(struct device *dev, const char *propname, 118int device_property_read_u32_array(struct device *dev, const char *propname,
127 u32 *val, size_t nval) 119 u32 *val, size_t nval)
128{ 120{
129 return DEV_PROP_READ_ARRAY(dev, propname, u32, DEV_PROP_U32, val, nval); 121 return fwnode_property_read_u32_array(dev_fwnode(dev), propname, val, nval);
130} 122}
131EXPORT_SYMBOL_GPL(device_property_read_u32_array); 123EXPORT_SYMBOL_GPL(device_property_read_u32_array);
132 124
@@ -150,7 +142,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u32_array);
150int device_property_read_u64_array(struct device *dev, const char *propname, 142int device_property_read_u64_array(struct device *dev, const char *propname,
151 u64 *val, size_t nval) 143 u64 *val, size_t nval)
152{ 144{
153 return DEV_PROP_READ_ARRAY(dev, propname, u64, DEV_PROP_U64, val, nval); 145 return fwnode_property_read_u64_array(dev_fwnode(dev), propname, val, nval);
154} 146}
155EXPORT_SYMBOL_GPL(device_property_read_u64_array); 147EXPORT_SYMBOL_GPL(device_property_read_u64_array);
156 148
@@ -174,11 +166,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array);
174int device_property_read_string_array(struct device *dev, const char *propname, 166int device_property_read_string_array(struct device *dev, const char *propname,
175 const char **val, size_t nval) 167 const char **val, size_t nval)
176{ 168{
177 return IS_ENABLED(CONFIG_OF) && dev->of_node ? 169 return fwnode_property_read_string_array(dev_fwnode(dev), propname, val, nval);
178 (val ? of_property_read_string_array(dev->of_node, propname, val, nval)
179 : of_property_count_strings(dev->of_node, propname)) :
180 acpi_dev_prop_read(ACPI_COMPANION(dev), propname,
181 DEV_PROP_STRING, val, nval);
182} 170}
183EXPORT_SYMBOL_GPL(device_property_read_string_array); 171EXPORT_SYMBOL_GPL(device_property_read_string_array);
184 172
@@ -199,13 +187,14 @@ EXPORT_SYMBOL_GPL(device_property_read_string_array);
199int device_property_read_string(struct device *dev, const char *propname, 187int device_property_read_string(struct device *dev, const char *propname,
200 const char **val) 188 const char **val)
201{ 189{
202 return IS_ENABLED(CONFIG_OF) && dev->of_node ? 190 return fwnode_property_read_string(dev_fwnode(dev), propname, val);
203 of_property_read_string(dev->of_node, propname, val) :
204 acpi_dev_prop_read(ACPI_COMPANION(dev), propname,
205 DEV_PROP_STRING, val, 1);
206} 191}
207EXPORT_SYMBOL_GPL(device_property_read_string); 192EXPORT_SYMBOL_GPL(device_property_read_string);
208 193
194#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
195 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \
196 : of_property_count_elems_of_size((node), (propname), sizeof(type))
197
209#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \ 198#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \
210({ \ 199({ \
211 int _ret_; \ 200 int _ret_; \