diff options
author | Tom Rini <trini@konsulko.com> | 2016-03-14 19:21:44 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-03-14 19:21:44 -0400 |
commit | 88033d737d9f46e7eebda6a8f9770957eb9aae9c (patch) | |
tree | 0b7c3bc6caa5ab4b7f8e88f05ce51ace87f25890 /common | |
parent | 9f0f432c0aea1e70959a0c06938459d3175a36b0 (diff) | |
parent | 608e399fdef82e983db44c5cb8f5e772bba870e2 (diff) | |
download | u-boot-imx-88033d737d9f46e7eebda6a8f9770957eb9aae9c.zip u-boot-imx-88033d737d9f46e7eebda6a8f9770957eb9aae9c.tar.gz u-boot-imx-88033d737d9f46e7eebda6a8f9770957eb9aae9c.tar.bz2 |
Merge git://git.denx.de/u-boot-dm
Diffstat (limited to 'common')
-rw-r--r-- | common/env_fat.c | 12 | ||||
-rw-r--r-- | common/fb_mmc.c | 33 | ||||
-rw-r--r-- | common/spl/spl_ext.c | 12 | ||||
-rw-r--r-- | common/spl/spl_fat.c | 8 | ||||
-rw-r--r-- | common/spl/spl_mmc.c | 2 | ||||
-rw-r--r-- | common/spl/spl_sata.c | 2 | ||||
-rw-r--r-- | common/spl/spl_usb.c | 2 | ||||
-rw-r--r-- | common/usb_storage.c | 276 |
8 files changed, 240 insertions, 107 deletions
diff --git a/common/env_fat.c b/common/env_fat.c index d79d864..75616d4 100644 --- a/common/env_fat.c +++ b/common/env_fat.c @@ -38,7 +38,7 @@ int env_init(void) int saveenv(void) { env_t env_new; - block_dev_desc_t *dev_desc = NULL; + struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; @@ -48,13 +48,13 @@ int saveenv(void) if (err) return err; - part = get_device_and_partition(FAT_ENV_INTERFACE, + part = blk_get_device_part_str(FAT_ENV_INTERFACE, FAT_ENV_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) return 1; - dev = dev_desc->dev; + dev = dev_desc->devnum; if (fat_set_blk_dev(dev_desc, &info) != 0) { printf("\n** Unable to use %s %d:%d for saveenv **\n", FAT_ENV_INTERFACE, dev, part); @@ -77,18 +77,18 @@ int saveenv(void) void env_relocate_spec(void) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); - block_dev_desc_t *dev_desc = NULL; + struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; - part = get_device_and_partition(FAT_ENV_INTERFACE, + part = blk_get_device_part_str(FAT_ENV_INTERFACE, FAT_ENV_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; - dev = dev_desc->dev; + dev = dev_desc->devnum; if (fat_set_blk_dev(dev_desc, &info) != 0) { printf("\n** Unable to use %s %d:%d for loading the env **\n", FAT_ENV_INTERFACE, dev, part); diff --git a/common/fb_mmc.c b/common/fb_mmc.c index 6e742da..e3abcc8 100644 --- a/common/fb_mmc.c +++ b/common/fb_mmc.c @@ -6,6 +6,7 @@ #include <config.h> #include <common.h> +#include <blk.h> #include <errno.h> #include <fastboot.h> #include <fb_mmc.h> @@ -22,15 +23,15 @@ static char *response_str; struct fb_mmc_sparse { - block_dev_desc_t *dev_desc; + struct blk_desc *dev_desc; }; -static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc, +static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc, const char *name, disk_partition_t *info) { int ret; - ret = get_partition_info_efi_by_name(dev_desc, name, info); + ret = part_get_info_efi_by_name(dev_desc, name, info); if (ret) { /* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */ char env_alias_name[25 + 32 + 1]; @@ -41,7 +42,7 @@ static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc, strncat(env_alias_name, name, 32); aliased_part_name = getenv(env_alias_name); if (aliased_part_name != NULL) - ret = get_partition_info_efi_by_name(dev_desc, + ret = part_get_info_efi_by_name(dev_desc, aliased_part_name, info); } return ret; @@ -55,17 +56,17 @@ static int fb_mmc_sparse_write(struct sparse_storage *storage, char *data) { struct fb_mmc_sparse *sparse = priv; - block_dev_desc_t *dev_desc = sparse->dev_desc; + struct blk_desc *dev_desc = sparse->dev_desc; int ret; - ret = dev_desc->block_write(dev_desc, offset, size, data); + ret = blk_dwrite(dev_desc, offset, size, data); if (!ret) return -EIO; return ret; } -static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info, +static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info, const char *part_name, void *buffer, unsigned int download_bytes) { @@ -84,9 +85,9 @@ static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info, puts("Flashing Raw Image\n"); - blks = dev_desc->block_write(dev_desc, info->start, blkcnt, buffer); + blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer); if (blks != blkcnt) { - error("failed writing to device %d\n", dev_desc->dev); + error("failed writing to device %d\n", dev_desc->devnum); fastboot_fail(response_str, "failed writing to device"); return; } @@ -100,13 +101,13 @@ void fb_mmc_flash_write(const char *cmd, unsigned int session_id, void *download_buffer, unsigned int download_bytes, char *response) { - block_dev_desc_t *dev_desc; + struct blk_desc *dev_desc; disk_partition_t info; /* initialize the response buffer */ response_str = response; - dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { error("invalid mmc device\n"); fastboot_fail(response_str, "invalid mmc device"); @@ -131,7 +132,7 @@ void fb_mmc_flash_write(const char *cmd, unsigned int session_id, printf("........ success\n"); fastboot_okay(response_str, ""); return; - } else if (get_partition_info_efi_by_name_or_alias(dev_desc, cmd, &info)) { + } else if (part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info)) { error("cannot find partition: '%s'\n", cmd); fastboot_fail(response_str, "cannot find partition"); return; @@ -165,7 +166,7 @@ void fb_mmc_flash_write(const char *cmd, unsigned int session_id, void fb_mmc_erase(const char *cmd, char *response) { int ret; - block_dev_desc_t *dev_desc; + struct blk_desc *dev_desc; disk_partition_t info; lbaint_t blks, blks_start, blks_size, grp_size; struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV); @@ -179,14 +180,14 @@ void fb_mmc_erase(const char *cmd, char *response) /* initialize the response buffer */ response_str = response; - dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { error("invalid mmc device"); fastboot_fail(response_str, "invalid mmc device"); return; } - ret = get_partition_info_efi_by_name_or_alias(dev_desc, cmd, &info); + ret = part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info); if (ret) { error("cannot find partition: '%s'", cmd); fastboot_fail(response_str, "cannot find partition"); @@ -207,7 +208,7 @@ void fb_mmc_erase(const char *cmd, char *response) blks = dev_desc->block_erase(dev_desc, blks_start, blks_size); if (blks != blks_size) { - error("failed erasing from device %d", dev_desc->dev); + error("failed erasing from device %d", dev_desc->devnum); fastboot_fail(response_str, "failed erasing from device"); return; } diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index a42fbd0..b77dbf4 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -10,7 +10,7 @@ #include <image.h> #ifdef CONFIG_SPL_EXT_SUPPORT -int spl_load_image_ext(block_dev_desc_t *block_dev, +int spl_load_image_ext(struct blk_desc *block_dev, int partition, const char *filename) { @@ -22,8 +22,7 @@ int spl_load_image_ext(block_dev_desc_t *block_dev, header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - sizeof(struct image_header)); - if (get_partition_info(block_dev, - partition, &part_info)) { + if (part_get_info(block_dev, partition, &part_info)) { printf("spl: no partition table found\n"); return -1; } @@ -64,15 +63,14 @@ end: } #ifdef CONFIG_SPL_OS_BOOT -int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition) +int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) { int err; __maybe_unused loff_t filelen, actlen; disk_partition_t part_info = {}; __maybe_unused char *file; - if (get_partition_info(block_dev, - partition, &part_info)) { + if (part_get_info(block_dev, partition, &part_info)) { printf("spl: no partition table found\n"); return -1; } @@ -137,7 +135,7 @@ defaults: CONFIG_SPL_FS_LOAD_KERNEL_NAME); } #else -int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition) +int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) { return -ENOSYS; } diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 0daadbe..d761b26 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -19,7 +19,7 @@ static int fat_registered; #ifdef CONFIG_SPL_FAT_SUPPORT -static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) +static int spl_register_fat_device(struct blk_desc *block_dev, int partition) { int err = 0; @@ -39,7 +39,7 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) return err; } -int spl_load_image_fat(block_dev_desc_t *block_dev, +int spl_load_image_fat(struct blk_desc *block_dev, int partition, const char *filename) { @@ -72,7 +72,7 @@ end: } #ifdef CONFIG_SPL_OS_BOOT -int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition) +int spl_load_image_fat_os(struct blk_desc *block_dev, int partition) { int err; __maybe_unused char *file; @@ -121,7 +121,7 @@ defaults: CONFIG_SPL_FS_LOAD_KERNEL_NAME); } #else -int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition) +int spl_load_image_fat_os(struct blk_desc *block_dev, int partition) { return -ENOSYS; } diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 9482142..c0e76be 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -161,7 +161,7 @@ static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) disk_partition_t info; int err; - err = get_partition_info(&mmc->block_dev, partition, &info); + err = part_get_info(&mmc->block_dev, partition, &info); if (err) { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT puts("spl: partition error\n"); diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 3ba4c24..1719946 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR; int spl_sata_load_image(void) { int err; - block_dev_desc_t *stor_dev; + struct blk_desc *stor_dev; err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE); if (err) { diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index 588b85c..c42848e 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -25,7 +25,7 @@ static int usb_stor_curr_dev = -1; /* current device */ int spl_usb_load_image(void) { int err; - block_dev_desc_t *stor_dev; + struct blk_desc *stor_dev; usb_stop(); err = usb_init(); diff --git a/common/usb_storage.c b/common/usb_storage.c index 8737cf7..1472824 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -43,6 +43,7 @@ #include <asm/byteorder.h> #include <asm/processor.h> #include <dm/device-internal.h> +#include <dm/lists.h> #include <part.h> #include <usb.h> @@ -67,7 +68,9 @@ static __u32 CBWTag; static int usb_max_devs; /* number of highest available usb device */ -static block_dev_desc_t usb_dev_desc[USB_MAX_STOR_DEV]; +#ifndef CONFIG_BLK +static struct blk_desc usb_dev_desc[USB_MAX_STOR_DEV]; +#endif struct us_data; typedef int (*trans_cmnd)(ccb *cb, struct us_data *data); @@ -108,26 +111,45 @@ struct us_data { #define USB_MAX_XFER_BLK 20 #endif +#ifndef CONFIG_BLK static struct us_data usb_stor[USB_MAX_STOR_DEV]; +#endif #define USB_STOR_TRANSPORT_GOOD 0 #define USB_STOR_TRANSPORT_FAILED -1 #define USB_STOR_TRANSPORT_ERROR -2 int usb_stor_get_info(struct usb_device *dev, struct us_data *us, - block_dev_desc_t *dev_desc); + struct blk_desc *dev_desc); int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, struct us_data *ss); -static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr, +#ifdef CONFIG_BLK +static unsigned long usb_stor_read(struct udevice *dev, lbaint_t blknr, + lbaint_t blkcnt, void *buffer); +static unsigned long usb_stor_write(struct udevice *dev, lbaint_t blknr, + lbaint_t blkcnt, const void *buffer); +#else +static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer); -static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr, +static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer); +#endif void uhci_show_temp_int_td(void); #ifdef CONFIG_PARTITIONS -block_dev_desc_t *usb_stor_get_dev(int index) +struct blk_desc *usb_stor_get_dev(int index) { +#ifdef CONFIG_BLK + struct udevice *dev; + int ret; + + ret = blk_get_device(IF_TYPE_USB, index, &dev); + if (ret) + return NULL; + return dev_get_uclass_platdata(dev); +#else return (index < usb_max_devs) ? &usb_dev_desc[index] : NULL; +#endif } #endif @@ -142,6 +164,20 @@ static void usb_show_progress(void) */ int usb_stor_info(void) { + int count = 0; +#ifdef CONFIG_BLK + struct udevice *dev; + + for (blk_first_device(IF_TYPE_USB, &dev); + dev; + blk_next_device(&dev)) { + struct blk_desc *desc = dev_get_uclass_platdata(dev); + + printf(" Device %d: ", desc->devnum); + dev_print(desc); + count++; + } +#else int i; if (usb_max_devs > 0) { @@ -151,8 +187,12 @@ int usb_stor_info(void) } return 0; } +#endif + if (!count) { + printf("No storage devices, perhaps not 'usb start'ed..?\n"); + return 1; + } - printf("No storage devices, perhaps not 'usb start'ed..?\n"); return 1; } @@ -171,52 +211,110 @@ static unsigned int usb_get_max_lun(struct us_data *us) return (len > 0) ? *result : 0; } -static int usb_stor_probe_device(struct usb_device *dev) +static int usb_stor_probe_device(struct usb_device *udev) { - if (dev == NULL) + int lun, max_lun; + +#ifdef CONFIG_BLK + struct us_data *data; + char dev_name[30], *str; + int ret; +#else + int start; + + if (udev == NULL) return -ENOENT; /* no more devices available */ +#endif debug("\n\nProbing for storage\n"); - if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) { - /* OK, it's a storage device. Iterate over its LUNs - * and populate `usb_dev_desc'. - */ - int lun, max_lun, start = usb_max_devs; - - max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]); - for (lun = 0; - lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV; - lun++) { - struct block_dev_desc *blkdev; - - blkdev = &usb_dev_desc[usb_max_devs]; - memset(blkdev, '\0', sizeof(block_dev_desc_t)); - blkdev->if_type = IF_TYPE_USB; - blkdev->dev = usb_max_devs; - blkdev->part_type = PART_TYPE_UNKNOWN; - blkdev->target = 0xff; - blkdev->type = DEV_TYPE_UNKNOWN; - blkdev->block_read = usb_stor_read; - blkdev->block_write = usb_stor_write; - blkdev->lun = lun; - blkdev->priv = dev; - - if (usb_stor_get_info(dev, &usb_stor[start], - &usb_dev_desc[usb_max_devs]) == - 1) { - usb_max_devs++; - debug("%s: Found device %p\n", __func__, dev); - } +#ifdef CONFIG_BLK + /* + * We store the us_data in the mass storage device's platdata. It + * is shared by all LUNs (block devices) attached to this mass storage + * device. + */ + data = dev_get_platdata(udev->dev); + if (!usb_storage_probe(udev, 0, data)) + return 0; + max_lun = usb_get_max_lun(data); + for (lun = 0; lun <= max_lun; lun++) { + struct blk_desc *blkdev; + struct udevice *dev; + + snprintf(dev_name, sizeof(dev_name), "%s.lun%d", + udev->dev->name, lun); + str = strdup(dev_name); + if (!str) + return -ENOMEM; + ret = blk_create_device(udev->dev, "usb_storage_blk", str, + IF_TYPE_USB, usb_max_devs, 512, 0, &dev); + if (ret) { + debug("Cannot bind driver\n"); + return ret; } - } - /* if storage device */ + blkdev = dev_get_uclass_platdata(dev); + blkdev->target = 0xff; + blkdev->lun = lun; + + ret = usb_stor_get_info(udev, data, blkdev); + if (ret == 1) + ret = blk_prepare_device(dev); + if (!ret) { + usb_max_devs++; + debug("%s: Found device %p\n", __func__, udev); + } else { + debug("usb_stor_get_info: Invalid device\n"); + ret = device_unbind(dev); + if (ret) + return ret; + } + } +#else + /* We don't have space to even probe if we hit the maximum */ if (usb_max_devs == USB_MAX_STOR_DEV) { printf("max USB Storage Device reached: %d stopping\n", usb_max_devs); return -ENOSPC; } + if (!usb_storage_probe(udev, 0, &usb_stor[usb_max_devs])) + return 0; + + /* + * OK, it's a storage device. Iterate over its LUNs and populate + * usb_dev_desc' + */ + start = usb_max_devs; + + max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]); + for (lun = 0; lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV; + lun++) { + struct blk_desc *blkdev; + + blkdev = &usb_dev_desc[usb_max_devs]; + memset(blkdev, '\0', sizeof(struct blk_desc)); + blkdev->if_type = IF_TYPE_USB; + blkdev->devnum = usb_max_devs; + blkdev->part_type = PART_TYPE_UNKNOWN; + blkdev->target = 0xff; + blkdev->type = DEV_TYPE_UNKNOWN; + blkdev->block_read = usb_stor_read; + blkdev->block_write = usb_stor_write; + blkdev->lun = lun; + blkdev->priv = udev; + + if (usb_stor_get_info(udev, &usb_stor[start], + &usb_dev_desc[usb_max_devs]) == 1) { + debug("partype: %d\n", blkdev->part_type); + part_init(blkdev); + debug("partype: %d\n", blkdev->part_type); + usb_max_devs++; + debug("%s: Found device %p\n", __func__, udev); + } + } +#endif + return 0; } @@ -1011,7 +1109,7 @@ static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start, * device with proper values (as reported by 'usb info'). * * Vendor and product length limits are taken from the definition of - * block_dev_desc_t in include/part.h. + * struct blk_desc in include/part.h. */ static void usb_bin_fixup(struct usb_device_descriptor descriptor, unsigned char vendor[], @@ -1026,39 +1124,50 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor, } #endif /* CONFIG_USB_BIN_FIXUP */ -static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr, +#ifdef CONFIG_BLK +static unsigned long usb_stor_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer) +#else +static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr, + lbaint_t blkcnt, void *buffer) +#endif { - int device = block_dev->dev; lbaint_t start, blks; uintptr_t buf_addr; unsigned short smallblks; - struct usb_device *dev; + struct usb_device *udev; struct us_data *ss; int retry; ccb *srb = &usb_ccb; +#ifdef CONFIG_BLK + struct blk_desc *block_dev; +#endif if (blkcnt == 0) return 0; - - device &= 0xff; /* Setup device */ - debug("\nusb_read: dev %d\n", device); - dev = usb_dev_desc[device].priv; - if (!dev) { +#ifdef CONFIG_BLK + block_dev = dev_get_uclass_platdata(dev); + udev = dev_get_parent_priv(dev_get_parent(dev)); + debug("\nusb_read: udev %d\n", block_dev->devnum); +#else + debug("\nusb_read: udev %d\n", block_dev->devnum); + udev = usb_dev_desc[block_dev->devnum].priv; + if (!udev) { debug("%s: No device\n", __func__); return 0; } - ss = (struct us_data *)dev->privptr; +#endif + ss = (struct us_data *)udev->privptr; usb_disable_asynch(1); /* asynch transfer not allowed */ - srb->lun = usb_dev_desc[device].lun; + srb->lun = block_dev->lun; buf_addr = (uintptr_t)buffer; start = blknr; blks = blkcnt; - debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF - " buffer %" PRIxPTR "\n", device, start, blks, buf_addr); + debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %" + PRIxPTR "\n", block_dev->devnum, start, blks, buf_addr); do { /* XXX need some comment here */ @@ -1071,7 +1180,7 @@ static unsigned long usb_stor_read(block_dev_desc_t *block_dev, lbaint_t blknr, retry_it: if (smallblks == USB_MAX_XFER_BLK) usb_show_progress(); - srb->datalen = usb_dev_desc[device].blksz * smallblks; + srb->datalen = block_dev->blksz * smallblks; srb->pdata = (unsigned char *)buf_addr; if (usb_read_10(srb, ss, start, smallblks)) { debug("Read ERROR\n"); @@ -1097,38 +1206,52 @@ retry_it: return blkcnt; } -static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr, +#ifdef CONFIG_BLK +static unsigned long usb_stor_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer) +#else +static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr, + lbaint_t blkcnt, const void *buffer) +#endif { - int device = block_dev->dev; lbaint_t start, blks; uintptr_t buf_addr; unsigned short smallblks; - struct usb_device *dev; + struct usb_device *udev; struct us_data *ss; int retry; ccb *srb = &usb_ccb; +#ifdef CONFIG_BLK + struct blk_desc *block_dev; +#endif if (blkcnt == 0) return 0; - device &= 0xff; /* Setup device */ - debug("\nusb_write: dev %d\n", device); - dev = usb_dev_desc[device].priv; - if (!dev) +#ifdef CONFIG_BLK + block_dev = dev_get_uclass_platdata(dev); + udev = dev_get_parent_priv(dev_get_parent(dev)); + debug("\nusb_read: udev %d\n", block_dev->devnum); +#else + debug("\nusb_read: udev %d\n", block_dev->devnum); + udev = usb_dev_desc[block_dev->devnum].priv; + if (!udev) { + debug("%s: No device\n", __func__); return 0; - ss = (struct us_data *)dev->privptr; + } +#endif + ss = (struct us_data *)udev->privptr; usb_disable_asynch(1); /* asynch transfer not allowed */ - srb->lun = usb_dev_desc[device].lun; + srb->lun = block_dev->lun; buf_addr = (uintptr_t)buffer; start = blknr; blks = blkcnt; - debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF - " buffer %" PRIxPTR "\n", device, start, blks, buf_addr); + debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF " buffer %" + PRIxPTR "\n", block_dev->devnum, start, blks, buf_addr); do { /* If write fails retry for max retry count else @@ -1143,7 +1266,7 @@ static unsigned long usb_stor_write(block_dev_desc_t *block_dev, lbaint_t blknr, retry_it: if (smallblks == USB_MAX_XFER_BLK) usb_show_progress(); - srb->datalen = usb_dev_desc[device].blksz * smallblks; + srb->datalen = block_dev->blksz * smallblks; srb->pdata = (unsigned char *)buf_addr; if (usb_write_10(srb, ss, start, smallblks)) { debug("Write ERROR\n"); @@ -1289,7 +1412,7 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, } int usb_stor_get_info(struct usb_device *dev, struct us_data *ss, - block_dev_desc_t *dev_desc) + struct blk_desc *dev_desc) { unsigned char perq, modi; ALLOC_CACHE_ALIGN_BUFFER(u32, cap, 2); @@ -1372,11 +1495,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss, dev_desc->log2blksz = LOG2(dev_desc->blksz); dev_desc->type = perq; debug(" address %d\n", dev_desc->target); - debug("partype: %d\n", dev_desc->part_type); - - init_part(dev_desc); - debug("partype: %d\n", dev_desc->part_type); return 1; } @@ -1404,6 +1523,9 @@ U_BOOT_DRIVER(usb_mass_storage) = { .id = UCLASS_MASS_STORAGE, .of_match = usb_mass_storage_ids, .probe = usb_mass_storage_probe, +#ifdef CONFIG_BLK + .platdata_auto_alloc_size = sizeof(struct us_data), +#endif }; UCLASS_DRIVER(usb_mass_storage) = { @@ -1420,5 +1542,17 @@ static const struct usb_device_id mass_storage_id_table[] = { }; U_BOOT_USB_DEVICE(usb_mass_storage, mass_storage_id_table); +#endif +#ifdef CONFIG_BLK +static const struct blk_ops usb_storage_ops = { + .read = usb_stor_read, + .write = usb_stor_write, +}; + +U_BOOT_DRIVER(usb_storage_blk) = { + .name = "usb_storage_blk", + .id = UCLASS_BLK, + .ops = &usb_storage_ops, +}; #endif |