File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff 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 *
Original file line number Diff line number Diff line change @@ -314,6 +314,9 @@ extern struct property *of_find_property(const struct device_node *np,
314314extern bool of_property_read_bool (const struct device_node * np , const char * propname );
315315extern 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 );
317320extern 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+
630639static inline int of_property_read_u32_index (const struct device_node * np ,
631640 const char * propname , u32 index , u32 * out_value )
632641{
You can’t perform that action at this time.
0 commit comments