summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c
index 1079e2c38f..beba062952 100644
--- a/src/device.c
+++ b/src/device.c
@@ -457,4 +457,87 @@ rt_err_t rt_device_set_tx_complete(rt_device_t dev,
}
RTM_EXPORT(rt_device_set_tx_complete);
+#ifdef RT_USING_DM
+/**
+ * This function bind drvier and device
+ *
+ * @param driver the pointer of driver structure
+ * @param device the pointer of device structure
+ * @param node the pointer of fdt node structure
+ *
+ * @return the error code, RT_EOK on successfully.
+ */
+rt_err_t rt_device_bind_driver(rt_device_t device, rt_driver_t driver, void *node)
+{
+ if((!driver) || (!device))
+ {
+ return -RT_EINVAL;
+ }
+
+ device->drv = driver;
+#ifdef RT_USING_DEVICE_OPS
+ device->ops = driver->dev_ops;
+#endif
+ device->dtb_node = node;
+
+ return RT_EOK;
+}
+RTM_EXPORT(rt_device_bind_driver);
+
+/**
+ * This function create rt_device according to driver infomation
+ *
+ * @param drv the pointer of driver structure
+ * @param device_id specify the ID of the rt_device
+ *
+ * @return the error code, RT_EOK on successfully.
+ */
+rt_device_t rt_device_create_since_driver(rt_driver_t drv,int device_id)
+{
+ rt_device_t device;
+ if (!drv)
+ {
+ return RT_NULL;
+ }
+
+ device = (rt_device_t)rt_calloc(1,drv->device_size);
+ if(device == RT_NULL)
+ {
+ return RT_NULL;
+ }
+ device->device_id = device_id;
+ rt_snprintf(device->parent.name, sizeof(device->parent.name), "%s%d", drv->name, device_id);
+ return device;
+}
+RTM_EXPORT(rt_device_create_since_driver);
+
+/**
+ * This function rt_device probe and init
+ *
+ * @param device the pointer of rt_device structure
+ * @return the error code, RT_EOK on successfully.
+ */
+rt_err_t rt_device_probe_and_init(rt_device_t device)
+{
+ int ret = -RT_ERROR;
+ if (!device)
+ {
+ return -RT_EINVAL;
+ }
+ if(!device->drv)
+ {
+ return -RT_ERROR;
+ }
+ if(device->drv->probe)
+ {
+ ret = device->drv->probe((rt_device_t)device);
+ }
+ if(device->drv->probe_init)
+ {
+ ret = device->drv->probe_init((rt_device_t)device);
+ }
+ return ret;
+}
+RTM_EXPORT(rt_device_probe_and_init);
+#endif /* RT_USING_DM */
#endif /* RT_USING_DEVICE */