checkpatch.pl: Request a test when a new command is added
[oweals/u-boot.git] / drivers / block / blk-uclass.c
index facf52711ccfd735171ba7c0235aa275ad089af1..b19375cbc8da3466eef5e22a3d27952b2140500d 100644 (file)
@@ -7,9 +7,13 @@
 #include <common.h>
 #include <blk.h>
 #include <dm.h>
+#include <log.h>
+#include <malloc.h>
+#include <part.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
 #include <dm/uclass-internal.h>
+#include <linux/err.h>
 
 static const char *if_typename_str[IF_TYPE_COUNT] = {
        [IF_TYPE_IDE]           = "ide",
@@ -23,6 +27,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
        [IF_TYPE_HOST]          = "host",
        [IF_TYPE_NVME]          = "nvme",
        [IF_TYPE_EFI]           = "efi",
+       [IF_TYPE_VIRTIO]        = "virtio",
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
@@ -37,6 +42,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
        [IF_TYPE_HOST]          = UCLASS_ROOT,
        [IF_TYPE_NVME]          = UCLASS_NVME,
        [IF_TYPE_EFI]           = UCLASS_EFI,
+       [IF_TYPE_VIRTIO]        = UCLASS_VIRTIO,
 };
 
 static enum if_type if_typename_to_iftype(const char *if_typename)
@@ -140,9 +146,9 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
  */
 struct blk_desc *blk_get_by_device(struct udevice *dev)
 {
-       struct udevice *child_dev, *next;
+       struct udevice *child_dev;
 
-       device_foreach_child_safe(child_dev, next, dev) {
+       device_foreach_child(child_dev, dev) {
                if (device_get_uclass_id(child_dev) != UCLASS_BLK)
                        continue;
 
@@ -471,15 +477,6 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
        return ops->erase(dev, start, blkcnt);
 }
 
-int blk_prepare_device(struct udevice *dev)
-{
-       struct blk_desc *desc = dev_get_uclass_platdata(dev);
-
-       part_init(desc);
-
-       return 0;
-}
-
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
 {
        struct udevice *dev;
@@ -526,7 +523,7 @@ int blk_find_max_devnum(enum if_type if_type)
        return max_devnum;
 }
 
-static int blk_next_free_devnum(enum if_type if_type)
+int blk_next_free_devnum(enum if_type if_type)
 {
        int ret;
 
@@ -587,6 +584,7 @@ int blk_create_device(struct udevice *parent, const char *drv_name,
        desc = dev_get_uclass_platdata(dev);
        desc->if_type = if_type;
        desc->blksz = blksz;
+       desc->log2blksz = LOG2(desc->blksz);
        desc->lba = lba;
        desc->part_type = PART_TYPE_UNKNOWN;
        desc->bdev = dev;
@@ -644,8 +642,20 @@ int blk_unbind_all(int if_type)
        return 0;
 }
 
+static int blk_post_probe(struct udevice *dev)
+{
+#if defined(CONFIG_PARTITIONS) && defined(CONFIG_HAVE_BLOCK_DEVICE)
+       struct blk_desc *desc = dev_get_uclass_platdata(dev);
+
+       part_init(desc);
+#endif
+
+       return 0;
+}
+
 UCLASS_DRIVER(blk) = {
        .id             = UCLASS_BLK,
        .name           = "blk",
+       .post_probe     = blk_post_probe,
        .per_device_platdata_auto_alloc_size = sizeof(struct blk_desc),
 };