如何在设备树中禁用和开启设备

在Linux内核中,设备树节点中的status属性的值决定了是否开启设备,当status属性没有在设备节点中定义时,默认设备是开启的。

关于设备树节点中status属性的处理的代码位于drivers/of/base.c文件中,有两个函数,如下所示:

/**
 *  __of_device_is_available - check if a device is available for use
 *
 *  @device: Node to check for availability, with locks already held
 *
 *  Returns true if the status property is absent or set to "okay" or "ok",
 *  false otherwise
 */
static bool __of_device_is_available(const struct device_node *device)
{
    const char *status;
    int statlen;

    if (!device)
        return false;

    status = __of_get_property(device, "status", &statlen);
    if (status == NULL)
        return true;

    if (statlen > 0) {
        if (!strcmp(status, "okay") || !strcmp(status, "ok"))
            return true;
    }

    return false;
}

/**
 *  of_device_is_available - check if a device is available for use
 *
 *  @device: Node to check for availability
 *
 *  Returns true if the status property is absent or set to "okay" or "ok",
 *  false otherwise
 */
bool of_device_is_available(const struct device_node *device)
{
    unsigned long flags;
    bool res;

    raw_spin_lock_irqsave(&devtree_lock, flags);
    res = __of_device_is_available(device);
    raw_spin_unlock_irqrestore(&devtree_lock, flags);
    return res;

}
EXPORT_SYMBOL(of_device_is_available);

从代码中,可以知道,当默认没有定义status属性时,函数将返回true,也就是默认是开启设备的,另外,想要在设备节点中开启设备,可以将status属性的值定义为"ok"或者"okay"。

原文地址:https://www.cnblogs.com/Cqlismy/p/11821581.html