aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/property.h
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 /include/linux/property.h
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 'include/linux/property.h')
-rw-r--r--include/linux/property.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/include/linux/property.h b/include/linux/property.h
new file mode 100644
index 000000000000..9242fb0221ba
--- /dev/null
+++ b/include/linux/property.h
@@ -0,0 +1,73 @@
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/types.h>
17
18struct device;
19
20enum dev_prop_type {
21 DEV_PROP_U8,
22 DEV_PROP_U16,
23 DEV_PROP_U32,
24 DEV_PROP_U64,
25 DEV_PROP_STRING,
26 DEV_PROP_MAX,
27};
28
29bool device_property_present(struct device *dev, const char *propname);
30int device_property_read_u8_array(struct device *dev, const char *propname,
31 u8 *val, size_t nval);
32int device_property_read_u16_array(struct device *dev, const char *propname,
33 u16 *val, size_t nval);
34int device_property_read_u32_array(struct device *dev, const char *propname,
35 u32 *val, size_t nval);
36int device_property_read_u64_array(struct device *dev, const char *propname,
37 u64 *val, size_t nval);
38int device_property_read_string_array(struct device *dev, const char *propname,
39 const char **val, size_t nval);
40int device_property_read_string(struct device *dev, const char *propname,
41 const char **val);
42
43static inline bool device_property_read_bool(struct device *dev,
44 const char *propname)
45{
46 return device_property_present(dev, propname);
47}
48
49static inline int device_property_read_u8(struct device *dev,
50 const char *propname, u8 *val)
51{
52 return device_property_read_u8_array(dev, propname, val, 1);
53}
54
55static inline int device_property_read_u16(struct device *dev,
56 const char *propname, u16 *val)
57{
58 return device_property_read_u16_array(dev, propname, val, 1);
59}
60
61static inline int device_property_read_u32(struct device *dev,
62 const char *propname, u32 *val)
63{
64 return device_property_read_u32_array(dev, propname, val, 1);
65}
66
67static inline int device_property_read_u64(struct device *dev,
68 const char *propname, u64 *val)
69{
70 return device_property_read_u64_array(dev, propname, val, 1);
71}
72
73#endif /* _LINUX_PROPERTY_H_ */