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>
This commit is contained in:
Simon Glass
2016-05-01 11:36:28 -06:00
parent 199a1201ab
commit 52138fd407
2 changed files with 43 additions and 1 deletions

View File

@@ -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;