dm: core: Add a function to get a device's uclass ID
authorSimon Glass <sjg@chromium.org>
Sun, 25 Jan 2015 15:27:04 +0000 (08:27 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 30 Jan 2015 00:09:55 +0000 (17:09 -0700)
This is useful to check which uclass a device is in.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
drivers/core/device.c
include/dm/device.h
test/dm/core.c

index 365676b9121941afb9982013296422ee8b5b77af..2606d18717782be09f0116bfe5fb624bde84cd5d 100644 (file)
@@ -438,3 +438,8 @@ ulong dev_get_of_data(struct udevice *dev)
 {
        return dev->of_id->data;
 }
+
+enum uclass_id device_get_uclass_id(struct udevice *dev)
+{
+       return dev->uclass->uc_drv->id;
+}
index 50f1b4f5087c76eab23df880201396fe6e4ab153..81afa8c6281f8f9c55dbd968bfd4b344f8cf872a 100644 (file)
@@ -245,6 +245,14 @@ struct udevice *dev_get_parent(struct udevice *child);
  */
 ulong dev_get_of_data(struct udevice *dev);
 
+/*
+ * device_get_uclass_id() - return the uclass ID of a device
+ *
+ * @dev:       Device to check
+ * @return uclass ID for the device
+ */
+enum uclass_id device_get_uclass_id(struct udevice *dev);
+
 /**
  * device_get_child() - Get the child of a device by index
  *
index ff5c2a749c5e37dbbcca5340dabdf18374a8e5c2..eccda0974da6d6effbdd931c75dff71f36bdaaf6 100644 (file)
@@ -598,3 +598,14 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms)
 }
 
 DM_TEST(dm_test_uclass_before_ready, 0);
+
+static int dm_test_device_get_uclass_id(struct dm_test_state *dms)
+{
+       struct udevice *dev;
+
+       ut_assertok(uclass_get_device(UCLASS_TEST, 0, &dev));
+       ut_asserteq(UCLASS_TEST, device_get_uclass_id(dev));
+
+       return 0;
+}
+DM_TEST(dm_test_device_get_uclass_id, DM_TESTF_SCAN_PDATA);