diff options
author | Simon Glass <sjg@chromium.org> | 2016-05-01 11:36:28 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2016-05-17 09:54:43 -0600 |
commit | 52138fd4072b64448855eac4c2c9815b46f5b43c (patch) | |
tree | fd5dead396df725150d71861e69d656d22e73dd9 /drivers | |
parent | 199a1201ab901413a80c64a9eee72f82977ba8d3 (diff) | |
download | u-boot-imx-52138fd4072b64448855eac4c2c9815b46f5b43c.zip u-boot-imx-52138fd4072b64448855eac4c2c9815b46f5b43c.tar.gz u-boot-imx-52138fd4072b64448855eac4c2c9815b46f5b43c.tar.bz2 |
dm: blk: Allow blk_create_device() to allocate the device number
Allow a devnum parameter of -1 to indicate that the device number should be
alocated automatically. The next highest available device number for that
interface type is used.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/blk-uclass.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 3687b9a..c947d95 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -411,6 +411,26 @@ int blk_prepare_device(struct udevice *dev) return 0; } +int blk_find_max_devnum(enum if_type if_type) +{ + struct udevice *dev; + int max_devnum = -ENODEV; + struct uclass *uc; + int ret; + + ret = uclass_get(UCLASS_BLK, &uc); + if (ret) + return ret; + uclass_foreach_dev(dev, uc) { + struct blk_desc *desc = dev_get_uclass_platdata(dev); + + if (desc->if_type == if_type && desc->devnum > max_devnum) + max_devnum = desc->devnum; + } + + return max_devnum; +} + int blk_create_device(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, lbaint_t size, struct udevice **devp) @@ -428,6 +448,15 @@ int blk_create_device(struct udevice *parent, const char *drv_name, desc->lba = size / blksz; desc->part_type = PART_TYPE_UNKNOWN; desc->bdev = dev; + if (devnum == -1) { + ret = blk_find_max_devnum(if_type); + if (ret == -ENODEV) + devnum = 0; + else if (ret < 0) + return ret; + else + devnum = ret + 1; + } desc->devnum = devnum; *devp = dev; |