]> git.sur5r.net Git - u-boot/commitdiff
dm: systemace: Add driver-mode block-device support
authorSimon Glass <sjg@chromium.org>
Sun, 1 May 2016 17:36:31 +0000 (11:36 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 17 May 2016 15:54:43 +0000 (09:54 -0600)
Add support for CONFIG_BLK to the systemace driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/block/systemace.c

index eeba7f08900385a32c7eeefde208833961160bc8..9392beaf052eb419ffb9f106018fd0746032c80d 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <part.h>
 #include <asm/io.h>
 
@@ -68,7 +69,9 @@ static u16 ace_readw(unsigned off)
        return in16(base + off);
 }
 
+#ifndef CONFIG_BLK
 static struct blk_desc systemace_dev = { 0 };
+#endif
 
 static int get_cf_lock(void)
 {
@@ -104,9 +107,14 @@ static void release_cf_lock(void)
  * the dev_desc) to read blocks of data. The return value is the
  * number of blocks read. A zero return indicates an error.
  */
+#ifdef CONFIG_BLK
+static unsigned long systemace_read(struct udevice *dev, unsigned long start,
+                                   lbaint_t blkcnt, void *buffer)
+#else
 static unsigned long systemace_read(struct blk_desc *block_dev,
                                    unsigned long start, lbaint_t blkcnt,
                                    void *buffer)
+#endif
 {
        int retry;
        unsigned blk_countdown;
@@ -225,6 +233,41 @@ static unsigned long systemace_read(struct blk_desc *block_dev,
        return blkcnt;
 }
 
+#ifdef CONFIG_BLK
+static int systemace_bind(struct udevice *dev)
+{
+       struct blk_desc *bdesc;
+       struct udevice *bdev;
+       int ret;
+
+       ret = blk_create_devicef(dev, "systemace_blk", "blk", IF_TYPE_SYSTEMACE,
+                                -1, 512, 0, &bdev);
+       if (ret) {
+               debug("Cannot create block device\n");
+               return ret;
+       }
+       bdesc = dev_get_uclass_platdata(bdev);
+       bdesc->removable = 1;
+       bdesc->part_type = PART_TYPE_UNKNOWN;
+       bdesc->log2blksz = LOG2(bdesc->blksz);
+
+       /* Ensure the correct bus mode (8/16 bits) gets enabled */
+       ace_writew(width == 8 ? 0 : 0x0001, 0);
+
+       return 0;
+}
+
+static const struct blk_ops systemace_blk_ops = {
+       .read   = systemace_read,
+};
+
+U_BOOT_DRIVER(systemace_blk) = {
+       .name           = "systemace_blk",
+       .id             = UCLASS_BLK,
+       .ops            = &systemace_blk_ops,
+       .bind           = systemace_bind,
+};
+#else
 static int systemace_get_dev(int dev, struct blk_desc **descp)
 {
        /* The first time through this, the systemace_dev object is
@@ -257,3 +300,4 @@ U_BOOT_LEGACY_BLK(systemace) = {
        .max_devs       = 1,
        .get_dev        = systemace_get_dev,
 };
+#endif