在devicetree的节点下面可以方便的通过status这个变量来使能或者disable driver的probe
例如如果要使能driver的话,可以将status设为okay反之就是disable
dts/mediatek/mt8173-evb.dts:405: status = "okay";
dts/mediatek/mt8173.dtsi:306: status = "disabled";
这样在driver的probe函数中可以通过of_device_is_available 来判断probe函数是否要继续下去
if (!of_device_is_available(mii_np)) {
ret = -ENODEV;
goto err_put_node;
}
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;
}
可见设置ok或者okay 都行,反之只要不是这两个字串,of_device_is_available就返回false,这样probe函数就停止了
因此可以在devicetree节点中通过加status来方便的使能或者disable driver
例如如果要使能driver的话,可以将status设为okay反之就是disable
dts/mediatek/mt8173-evb.dts:405: status = "okay";
dts/mediatek/mt8173.dtsi:306: status = "disabled";
这样在driver的probe函数中可以通过of_device_is_available 来判断probe函数是否要继续下去
if (!of_device_is_available(mii_np)) {
ret = -ENODEV;
goto err_put_node;
}
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;
}
可见设置ok或者okay 都行,反之只要不是这两个字串,of_device_is_available就返回false,这样probe函数就停止了
因此可以在devicetree节点中通过加status来方便的使能或者disable driver