summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-04-24 02:02:05 (GMT)
committerSimon Glass <sjg@chromium.org>2017-06-01 13:03:04 (GMT)
commit6139281a6473334351c8776643478c0b0e208342 (patch)
tree501de9018b4716ecc19bfcff404b4ea10f65e0ee
parente7017a3c7d2f9ff845516675205c99df4ad6eacc (diff)
downloadu-boot-fsl-qoriq-6139281a6473334351c8776643478c0b0e208342.tar.xz
dm: blk: Allow finding block devices without probing
Sometimes it is useful to be able to find a block device without also probing it. Add a function for this as well as the associated test. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/block/blk-uclass.c15
-rw-r--r--include/blk.h15
-rw-r--r--test/dm/blk.c21
3 files changed, 48 insertions, 3 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index af3c35f..8b6b28d 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -363,7 +363,7 @@ int blk_next_device(struct udevice **devp)
} while (1);
}
-int blk_get_device(int if_type, int devnum, struct udevice **devp)
+int blk_find_device(int if_type, int devnum, struct udevice **devp)
{
struct uclass *uc;
struct udevice *dev;
@@ -379,13 +379,24 @@ int blk_get_device(int if_type, int devnum, struct udevice **devp)
if_type, devnum, dev->name, desc->if_type, desc->devnum);
if (desc->if_type == if_type && desc->devnum == devnum) {
*devp = dev;
- return device_probe(dev);
+ return 0;
}
}
return -ENODEV;
}
+int blk_get_device(int if_type, int devnum, struct udevice **devp)
+{
+ int ret;
+
+ ret = blk_find_device(if_type, devnum, devp);
+ if (ret)
+ return ret;
+
+ return device_probe(*devp);
+}
+
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer)
{
diff --git a/include/blk.h b/include/blk.h
index 66a1c55..a128ee4 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -253,12 +253,25 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
/**
+ * blk_find_device() - Find a block device
+ *
+ * This function does not activate the device. The device will be returned
+ * whether or not it is activated.
+ *
+ * @if_type: Interface type (enum if_type_t)
+ * @devnum: Device number (specific to each interface type)
+ * @devp: the device, if found
+ * @return 0 if found, -ENODEV if no device found, or other -ve error value
+ */
+int blk_find_device(int if_type, int devnum, struct udevice **devp);
+
+/**
* blk_get_device() - Find and probe a block device ready for use
*
* @if_type: Interface type (enum if_type_t)
* @devnum: Device number (specific to each interface type)
* @devp: the device, if found
- * @return - if found, -ENODEV if no device found, or other -ve error value
+ * @return 0 if found, -ENODEV if no device found, or other -ve error value
*/
int blk_get_device(int if_type, int devnum, struct udevice **devp);
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 012bf4c..3e34336 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -94,3 +94,24 @@ static int dm_test_blk_usb(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_blk_usb, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we can find block devices without probing them */
+static int dm_test_blk_find(struct unit_test_state *uts)
+{
+ struct udevice *blk, *dev;
+
+ ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
+ IF_TYPE_HOST, 1, 512, 1024, &blk));
+ ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev));
+ ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev));
+ ut_asserteq_ptr(blk, dev);
+ ut_asserteq(false, device_active(dev));
+
+ /* Now activate it */
+ ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
+ ut_asserteq_ptr(blk, dev);
+ ut_asserteq(true, device_active(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_blk_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);