of_property_read_u32(node, "post-pwm-on-delay-ms",&data->post_pwm_on_delay);
/*根据"post-pwm-on-delay-ms",从属性中查找并读取一个32位整数*/
/*读到一个32位整数,保存到data->post_pwm_on_delay中*/
of_property_read_u32(node, "pwm-off-delay-ms", &data->pwm_off_delay);
/*根据"pwm-off-delay-ms",从属性中查找并读取一个32位整数*/
/*读到一个32位整数,保存到data->pwm_off_delay中*/
文件路径;
/home/zgq/linux/atk-mp1/linux/my_linux/linux-5.4.31/include/linux/of.h
static inline int of_property_read_u32(const struct device_node *np,
const char *propname,
u32 *out_value)
{
return of_property_read_u32_array(np, propname, out_value, 1);
}
static inline int of_property_read_u32_array(const struct device_node *np,
const char *propname,
u32 *out_values, size_t sz)
{
int ret = of_property_read_variable_u32_array(np, propname, out_values,
sz, 0);
if (ret >= 0) return 0;
else return ret;//读取ret个32位整数
}
文件路径:
/home/zgq/linux/atk-mp1/linux/my_linux/linux-5.4.31/drivers/of/property.c
int of_property_read_variable_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz_min, size_t sz_max)
{
size_t sz, count;
const __be32 *val = of_find_property_value_of_size(np, propname,
(sz_min * sizeof(*out_values)),
(sz_max * sizeof(*out_values)),
&sz);
if (IS_ERR(val)) return PTR_ERR(val);
if (!sz_max) sz = sz_min;
else sz /= sizeof(*out_values);
count = sz;//读取sz个32位整数
while (count--)
*out_values++ = be32_to_cpup(val++);
//相当于“*out_values=*val;out_values++;val++;”
return sz;
}
static void *of_find_property_value_of_size(const struct device_node *np,
const char *propname, u32 min, u32 max, size_t *len)
{
struct property *prop = of_find_property(np, propname, NULL);
if (!prop) return ERR_PTR(-EINVAL);
if (!prop->value)return ERR_PTR(-ENODATA);
if (prop->length < min)return ERR_PTR(-EOVERFLOW);
if (max && prop->length > max)return ERR_PTR(-EOVERFLOW);
if (len) *len = prop->length;//读取一个32位整数
return prop->value;
}
文件路径:
/home/zgq/linux/atk-mp1/linux/my_linux/linux-5.4.31/drivers/of/base.c
struct property *of_find_property(const struct device_node *np,const char *name,int *lenp)
{
struct property *pp;
unsigned long flags;
raw_spin_lock_irqsave(&devtree_lock, flags);
pp = __of_find_property(np, name, lenp);
raw_spin_unlock_irqrestore(&devtree_lock, flags);
return pp;
}
static struct property *__of_find_property(const struct device_node *np,const char *name, int *lenp)
{
struct property *pp;
if (!np)
return NULL;
for (pp = np->properties; pp; pp = pp->next)
{
if (of_prop_cmp(pp->name, name) == 0)
{
if (lenp) *lenp = pp->length;
break;
}
}
return pp;
}
#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
文件路径:
/home/zgq/linux/atk-mp1/linux/my_linux/linux-5.4.31/include/linux/byteorder/generic.h
#define be32_to_cpup __be32_to_cpup
文件路径:
/home/zgq/linux/atk-mp1/linux/my_linux/linux-5.4.31/include/uapi/linux/byteorder/big_endian.h
static __always_inline __u32 __be32_to_cpup(const __be32 *p)
{
return (__force __u32)*p;
}
typedef uint32_t __u32;