Skip to content

Commit fd95829

Browse files
Ernest Van Hoeckebroonie
authored andcommitted
of: Add of_property_read_u16_index
There is an of_property_read_u32_index and of_property_read_u64_index. This patch adds a similar helper for u16. Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20250319142059.46692-2-francesco@dolcini.it Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 4701f33 commit fd95829

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

drivers/of/property.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,39 @@ static void *of_find_property_value_of_size(const struct device_node *np,
147147
return prop->value;
148148
}
149149

150+
/**
151+
* of_property_read_u16_index - Find and read a u16 from a multi-value property.
152+
*
153+
* @np: device node from which the property value is to be read.
154+
* @propname: name of the property to be searched.
155+
* @index: index of the u16 in the list of values
156+
* @out_value: pointer to return value, modified only if no error.
157+
*
158+
* Search for a property in a device node and read nth 16-bit value from
159+
* it.
160+
*
161+
* Return: 0 on success, -EINVAL if the property does not exist,
162+
* -ENODATA if property does not have a value, and -EOVERFLOW if the
163+
* property data isn't large enough.
164+
*
165+
* The out_value is modified only if a valid u16 value can be decoded.
166+
*/
167+
int of_property_read_u16_index(const struct device_node *np,
168+
const char *propname,
169+
u32 index, u16 *out_value)
170+
{
171+
const u16 *val = of_find_property_value_of_size(np, propname,
172+
((index + 1) * sizeof(*out_value)),
173+
0, NULL);
174+
175+
if (IS_ERR(val))
176+
return PTR_ERR(val);
177+
178+
*out_value = be16_to_cpup(((__be16 *)val) + index);
179+
return 0;
180+
}
181+
EXPORT_SYMBOL_GPL(of_property_read_u16_index);
182+
150183
/**
151184
* of_property_read_u32_index - Find and read a u32 from a multi-value property.
152185
*

include/linux/of.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ extern struct property *of_find_property(const struct device_node *np,
314314
extern bool of_property_read_bool(const struct device_node *np, const char *propname);
315315
extern int of_property_count_elems_of_size(const struct device_node *np,
316316
const char *propname, int elem_size);
317+
extern int of_property_read_u16_index(const struct device_node *np,
318+
const char *propname,
319+
u32 index, u16 *out_value);
317320
extern int of_property_read_u32_index(const struct device_node *np,
318321
const char *propname,
319322
u32 index, u32 *out_value);
@@ -627,6 +630,12 @@ static inline int of_property_count_elems_of_size(const struct device_node *np,
627630
return -ENOSYS;
628631
}
629632

633+
static inline int of_property_read_u16_index(const struct device_node *np,
634+
const char *propname, u32 index, u16 *out_value)
635+
{
636+
return -ENOSYS;
637+
}
638+
630639
static inline int of_property_read_u32_index(const struct device_node *np,
631640
const char *propname, u32 index, u32 *out_value)
632641
{

0 commit comments

Comments
 (0)