Skip to content

Commit bb39141

Browse files
committed
device property: Split property reading bool and presence test ops
The fwnode/device property API currently implement (fwnode|device)_property_read_bool() with (fwnode|device)_property_present(). That does not allow having different behavior depending on the backend. Specifically, the usage of (fwnode|device)_property_read_bool() on non-boolean properties is deprecated on DT. In order to add a warning on this deprecated use, these 2 APIs need separate ops for the backend. Acked-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent de7323f commit bb39141

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

drivers/acpi/property.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ static int acpi_fwnode_irq_get(const struct fwnode_handle *fwnode,
16561656
acpi_fwnode_device_dma_supported, \
16571657
.device_get_dma_attr = acpi_fwnode_device_get_dma_attr, \
16581658
.property_present = acpi_fwnode_property_present, \
1659+
.property_read_bool = acpi_fwnode_property_present, \
16591660
.property_read_int_array = \
16601661
acpi_fwnode_property_read_int_array, \
16611662
.property_read_string_array = \

drivers/base/property.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,44 @@ bool fwnode_property_present(const struct fwnode_handle *fwnode,
7070
}
7171
EXPORT_SYMBOL_GPL(fwnode_property_present);
7272

73+
/**
74+
* device_property_read_bool - Return the value for a boolean property of a device
75+
* @dev: Device whose property is being checked
76+
* @propname: Name of the property
77+
*
78+
* Return if property @propname is true or false in the device firmware description.
79+
*
80+
* Return: true if property @propname is present. Otherwise, returns false.
81+
*/
82+
bool device_property_read_bool(const struct device *dev, const char *propname)
83+
{
84+
return fwnode_property_read_bool(dev_fwnode(dev), propname);
85+
}
86+
EXPORT_SYMBOL_GPL(device_property_read_bool);
87+
88+
/**
89+
* fwnode_property_read_bool - Return the value for a boolean property of a firmware node
90+
* @fwnode: Firmware node whose property to check
91+
* @propname: Name of the property
92+
*
93+
* Return if property @propname is true or false in the firmware description.
94+
*/
95+
bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
96+
const char *propname)
97+
{
98+
bool ret;
99+
100+
if (IS_ERR_OR_NULL(fwnode))
101+
return false;
102+
103+
ret = fwnode_call_bool_op(fwnode, property_read_bool, propname);
104+
if (ret)
105+
return ret;
106+
107+
return fwnode_call_bool_op(fwnode->secondary, property_read_bool, propname);
108+
}
109+
EXPORT_SYMBOL_GPL(fwnode_property_read_bool);
110+
73111
/**
74112
* device_property_read_u8_array - return a u8 array property of a device
75113
* @dev: Device to get the property of

drivers/base/swnode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ static const struct fwnode_operations software_node_ops = {
677677
.get = software_node_get,
678678
.put = software_node_put,
679679
.property_present = software_node_property_present,
680+
.property_read_bool = software_node_property_present,
680681
.property_read_int_array = software_node_read_int_array,
681682
.property_read_string_array = software_node_read_string_array,
682683
.get_name = software_node_get_name,

drivers/of/property.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,12 @@ of_fwnode_device_get_dma_attr(const struct fwnode_handle *fwnode)
965965

966966
static bool of_fwnode_property_present(const struct fwnode_handle *fwnode,
967967
const char *propname)
968+
{
969+
return of_property_present(to_of_node(fwnode), propname);
970+
}
971+
972+
static bool of_fwnode_property_read_bool(const struct fwnode_handle *fwnode,
973+
const char *propname)
968974
{
969975
return of_property_read_bool(to_of_node(fwnode), propname);
970976
}
@@ -1562,6 +1568,7 @@ const struct fwnode_operations of_fwnode_ops = {
15621568
.device_dma_supported = of_fwnode_device_dma_supported,
15631569
.device_get_dma_attr = of_fwnode_device_get_dma_attr,
15641570
.property_present = of_fwnode_property_present,
1571+
.property_read_bool = of_fwnode_property_read_bool,
15651572
.property_read_int_array = of_fwnode_property_read_int_array,
15661573
.property_read_string_array = of_fwnode_property_read_string_array,
15671574
.get_name = of_fwnode_get_name,

include/linux/fwnode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct fwnode_reference_args {
112112
* @device_is_available: Return true if the device is available.
113113
* @device_get_match_data: Return the device driver match data.
114114
* @property_present: Return true if a property is present.
115+
* @property_read_bool: Return a boolean property value.
115116
* @property_read_int_array: Read an array of integer properties. Return zero on
116117
* success, a negative error code otherwise.
117118
* @property_read_string_array: Read an array of string properties. Return zero
@@ -141,6 +142,8 @@ struct fwnode_operations {
141142
(*device_get_dma_attr)(const struct fwnode_handle *fwnode);
142143
bool (*property_present)(const struct fwnode_handle *fwnode,
143144
const char *propname);
145+
bool (*property_read_bool)(const struct fwnode_handle *fwnode,
146+
const char *propname);
144147
int (*property_read_int_array)(const struct fwnode_handle *fwnode,
145148
const char *propname,
146149
unsigned int elem_size, void *val,

include/linux/of.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ static inline bool of_property_read_bool(const struct device_node *np,
12711271
*/
12721272
static inline bool of_property_present(const struct device_node *np, const char *propname)
12731273
{
1274-
return of_property_read_bool(np, propname);
1274+
struct property *prop = of_find_property(np, propname, NULL);
1275+
1276+
return prop ? true : false;
12751277
}
12761278

12771279
/**

include/linux/property.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct fwnode_handle *__dev_fwnode(struct device *dev);
3737
struct device *: __dev_fwnode)(dev)
3838

3939
bool device_property_present(const struct device *dev, const char *propname);
40+
bool device_property_read_bool(const struct device *dev, const char *propname);
4041
int device_property_read_u8_array(const struct device *dev, const char *propname,
4142
u8 *val, size_t nval);
4243
int device_property_read_u16_array(const struct device *dev, const char *propname,
@@ -54,6 +55,8 @@ int device_property_match_string(const struct device *dev,
5455

5556
bool fwnode_property_present(const struct fwnode_handle *fwnode,
5657
const char *propname);
58+
bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
59+
const char *propname);
5760
int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
5861
const char *propname, u8 *val,
5962
size_t nval);
@@ -207,12 +210,6 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);
207210

208211
unsigned int device_get_child_node_count(const struct device *dev);
209212

210-
static inline bool device_property_read_bool(const struct device *dev,
211-
const char *propname)
212-
{
213-
return device_property_present(dev, propname);
214-
}
215-
216213
static inline int device_property_read_u8(const struct device *dev,
217214
const char *propname, u8 *val)
218215
{
@@ -263,12 +260,6 @@ static inline int device_property_string_array_count(const struct device *dev,
263260
return device_property_read_string_array(dev, propname, NULL, 0);
264261
}
265262

266-
static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
267-
const char *propname)
268-
{
269-
return fwnode_property_present(fwnode, propname);
270-
}
271-
272263
static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
273264
const char *propname, u8 *val)
274265
{

0 commit comments

Comments
 (0)