aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-11-03 19:28:56 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-11-04 15:58:21 -0500
commitb31384fa5de37a100507751dfb5c0a49d06cee67 (patch)
treefa0084d464b8cb3873c5e169d61ee3c7e8e5b3e6 /drivers/of/base.c
parentffdcd955c3078af3ce117edcfce80fde1a512bed (diff)
Driver core: Unified device properties interface for platform firmware
Add a uniform interface by which device drivers can request device properties from the platform firmware by providing a property name and the corresponding data type. The purpose of it is to help to write portable code that won't depend on any particular platform firmware interface. The following general helper functions are added: device_property_present() device_property_read_u8() device_property_read_u16() device_property_read_u32() device_property_read_u64() device_property_read_string() device_property_read_u8_array() device_property_read_u16_array() device_property_read_u32_array() device_property_read_u64_array() device_property_read_string_array() The first one allows the caller to check if the given property is present. The next 5 of them allow single-valued properties of various types to be retrieved in a uniform way. The remaining 5 are for reading properties with multiple values (arrays of either numbers or strings). The interface covers both ACPI and Device Trees. This change set includes material from Mika Westerberg and Aaron Lu. Signed-off-by: Aaron Lu <aaron.lu@intel.com> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Grant Likely <grant.likely@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3823edf2d012..4c2ccde42427 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1250,6 +1250,39 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
1250EXPORT_SYMBOL_GPL(of_property_read_u64); 1250EXPORT_SYMBOL_GPL(of_property_read_u64);
1251 1251
1252/** 1252/**
1253 * of_property_read_u64_array - Find and read an array of 64 bit integers
1254 * from a property.
1255 *
1256 * @np: device node from which the property value is to be read.
1257 * @propname: name of the property to be searched.
1258 * @out_values: pointer to return value, modified only if return value is 0.
1259 * @sz: number of array elements to read
1260 *
1261 * Search for a property in a device node and read 64-bit value(s) from
1262 * it. Returns 0 on success, -EINVAL if the property does not exist,
1263 * -ENODATA if property does not have a value, and -EOVERFLOW if the
1264 * property data isn't large enough.
1265 *
1266 * The out_values is modified only if a valid u64 value can be decoded.
1267 */
1268int of_property_read_u64_array(const struct device_node *np,
1269 const char *propname, u64 *out_values,
1270 size_t sz)
1271{
1272 const __be32 *val = of_find_property_value_of_size(np, propname,
1273 (sz * sizeof(*out_values)));
1274
1275 if (IS_ERR(val))
1276 return PTR_ERR(val);
1277
1278 while (sz--) {
1279 *out_values++ = of_read_number(val, 2);
1280 val += 2;
1281 }
1282 return 0;
1283}
1284
1285/**
1253 * of_property_read_string - Find and read a string from a property 1286 * of_property_read_string - Find and read a string from a property
1254 * @np: device node from which the property value is to be read. 1287 * @np: device node from which the property value is to be read.
1255 * @propname: name of the property to be searched. 1288 * @propname: name of the property to be searched.