Skip to content

Commit 18223ee

Browse files
Srinivas Kandagatlavinodkoul
authored andcommitted
of: base: Add of_property_read_u8_index
Add support for of_property_read_u8_index(), simillar to others u16 and u32 variants. Having this helper makes the code more tidy in isome cases, specially when we are parsing multiple of these into data structures. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> Tested-by: Alexey Klimov <alexey.klimov@linaro.org> # sm8550 Link: https://patch.msgid.link/20250912083225.228778-2-srinivas.kandagatla@oss.qualcomm.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 3a86608 commit 18223ee

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

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_u8_index - Find and read a u8 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 u8 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 8-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 u8 value can be decoded.
166+
*/
167+
int of_property_read_u8_index(const struct device_node *np,
168+
const char *propname,
169+
u32 index, u8 *out_value)
170+
{
171+
const u8 *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 = val[index];
179+
return 0;
180+
}
181+
EXPORT_SYMBOL_GPL(of_property_read_u8_index);
182+
150183
/**
151184
* of_property_read_u16_index - Find and read a u16 from a multi-value property.
152185
*

include/linux/of.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ extern struct property *of_find_property(const struct device_node *np,
316316
extern bool of_property_read_bool(const struct device_node *np, const char *propname);
317317
extern int of_property_count_elems_of_size(const struct device_node *np,
318318
const char *propname, int elem_size);
319+
extern int of_property_read_u8_index(const struct device_node *np,
320+
const char *propname,
321+
u32 index, u8 *out_value);
319322
extern int of_property_read_u16_index(const struct device_node *np,
320323
const char *propname,
321324
u32 index, u16 *out_value);
@@ -646,6 +649,12 @@ static inline int of_property_count_elems_of_size(const struct device_node *np,
646649
return -ENOSYS;
647650
}
648651

652+
static inline int of_property_read_u8_index(const struct device_node *np,
653+
const char *propname, u32 index, u8 *out_value)
654+
{
655+
return -ENOSYS;
656+
}
657+
649658
static inline int of_property_read_u16_index(const struct device_node *np,
650659
const char *propname, u32 index, u16 *out_value)
651660
{

0 commit comments

Comments
 (0)