[MTD] partitioning utility predicates
[pandora-kernel.git] / drivers / mtd / devices / mtd_dataflash.c
index 6dd9aff..d95f74a 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/device.h>
 #include <linux/mutex.h>
 #include <linux/err.h>
+#include <linux/math64.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
@@ -97,12 +98,6 @@ struct dataflash {
        struct mtd_info         mtd;
 };
 
-#ifdef CONFIG_MTD_PARTITIONS
-#define        mtd_has_partitions()    (1)
-#else
-#define        mtd_has_partitions()    (0)
-#endif
-
 /* ......................................................................... */
 
 /*
@@ -128,7 +123,7 @@ static int dataflash_waitready(struct spi_device *spi)
                status = dataflash_status(spi);
                if (status < 0) {
                        DEBUG(MTD_DEBUG_LEVEL1, "%s: status %d?\n",
-                                       spi->dev.bus_id, status);
+                                       dev_name(&spi->dev), status);
                        status = 0;
                }
 
@@ -152,15 +147,20 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
        struct spi_message      msg;
        unsigned                blocksize = priv->page_size << 3;
        uint8_t                 *command;
+       uint32_t                rem;
 
-       DEBUG(MTD_DEBUG_LEVEL2, "%s: erase addr=0x%x len 0x%x\n",
-                       spi->dev.bus_id,
-                       instr->addr, instr->len);
+       DEBUG(MTD_DEBUG_LEVEL2, "%s: erase addr=0x%llx len 0x%llx\n",
+             dev_name(&spi->dev), (long long)instr->addr,
+             (long long)instr->len);
 
        /* Sanity checks */
-       if ((instr->addr + instr->len) > mtd->size
-                       || (instr->len % priv->page_size) != 0
-                       || (instr->addr % priv->page_size) != 0)
+       if (instr->addr + instr->len > mtd->size)
+               return -EINVAL;
+       div_u64_rem(instr->len, priv->page_size, &rem);
+       if (rem)
+               return -EINVAL;
+       div_u64_rem(instr->addr, priv->page_size, &rem);
+       if (rem)
                return -EINVAL;
 
        spi_message_init(&msg);
@@ -178,7 +178,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
                /* Calculate flash page address; use block erase (for speed) if
                 * we're at a block boundary and need to erase the whole block.
                 */
-               pageaddr = instr->addr / priv->page_size;
+               pageaddr = div_u64(instr->len, priv->page_size);
                do_block = (pageaddr & 0x7) == 0 && instr->len >= blocksize;
                pageaddr = pageaddr << priv->page_offset;
 
@@ -197,7 +197,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
 
                if (status < 0) {
                        printk(KERN_ERR "%s: erase %x, err %d\n",
-                               spi->dev.bus_id, pageaddr, status);
+                               dev_name(&spi->dev), pageaddr, status);
                        /* REVISIT:  can retry instr->retries times; or
                         * giveup and instr->fail_addr = instr->addr;
                         */
@@ -239,7 +239,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
        int                     status;
 
        DEBUG(MTD_DEBUG_LEVEL2, "%s: read 0x%x..0x%x\n",
-               priv->spi->dev.bus_id, (unsigned)from, (unsigned)(from + len));
+               dev_name(&priv->spi->dev), (unsigned)from, (unsigned)(from + len));
 
        *retlen = 0;
 
@@ -288,7 +288,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
                status = 0;
        } else
                DEBUG(MTD_DEBUG_LEVEL1, "%s: read %x..%x --> %d\n",
-                       priv->spi->dev.bus_id,
+                       dev_name(&priv->spi->dev),
                        (unsigned)from, (unsigned)(from + len),
                        status);
        return status;
@@ -315,7 +315,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
        uint8_t                 *command;
 
        DEBUG(MTD_DEBUG_LEVEL2, "%s: write 0x%x..0x%x\n",
-               spi->dev.bus_id, (unsigned)to, (unsigned)(to + len));
+               dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len));
 
        *retlen = 0;
 
@@ -374,7 +374,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
                        status = spi_sync(spi, &msg);
                        if (status < 0)
                                DEBUG(MTD_DEBUG_LEVEL1, "%s: xfer %u -> %d \n",
-                                       spi->dev.bus_id, addr, status);
+                                       dev_name(&spi->dev), addr, status);
 
                        (void) dataflash_waitready(priv->spi);
                }
@@ -396,7 +396,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
                spi_transfer_del(x + 1);
                if (status < 0)
                        DEBUG(MTD_DEBUG_LEVEL1, "%s: pgm %u/%u -> %d \n",
-                               spi->dev.bus_id, addr, writelen, status);
+                               dev_name(&spi->dev), addr, writelen, status);
 
                (void) dataflash_waitready(priv->spi);
 
@@ -416,14 +416,14 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
                status = spi_sync(spi, &msg);
                if (status < 0)
                        DEBUG(MTD_DEBUG_LEVEL1, "%s: compare %u -> %d \n",
-                               spi->dev.bus_id, addr, status);
+                               dev_name(&spi->dev), addr, status);
 
                status = dataflash_waitready(priv->spi);
 
                /* Check result of the compare operation */
                if (status & (1 << 6)) {
                        printk(KERN_ERR "%s: compare page %u, err %d\n",
-                               spi->dev.bus_id, pageaddr, status);
+                               dev_name(&spi->dev), pageaddr, status);
                        remaining = 0;
                        status = -EIO;
                        break;
@@ -667,8 +667,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
        if (revision >= 'c')
                otp_tag = otp_setup(device, revision);
 
-       dev_info(&spi->dev, "%s (%d KBytes) pagesize %d bytes%s\n",
-                       name, DIV_ROUND_UP(device->size, 1024),
+       dev_info(&spi->dev, "%s (%lld KBytes) pagesize %d bytes%s\n",
+                       name, (long long)((device->size + 1023) >> 10),
                        pagesize, otp_tag);
        dev_set_drvdata(&spi->dev, priv);
 
@@ -676,11 +676,13 @@ add_dataflash_otp(struct spi_device *spi, char *name,
                struct mtd_partition    *parts;
                int                     nr_parts = 0;
 
-#ifdef CONFIG_MTD_CMDLINE_PARTS
-               static const char *part_probes[] = { "cmdlinepart", NULL, };
+               if (mtd_has_cmdlinepart()) {
+                       static const char *part_probes[]
+                                       = { "cmdlinepart", NULL, };
 
-               nr_parts = parse_mtd_partitions(device, part_probes, &parts, 0);
-#endif
+                       nr_parts = parse_mtd_partitions(device,
+                                       part_probes, &parts, 0);
+               }
 
                if (nr_parts <= 0 && pdata && pdata->parts) {
                        parts = pdata->parts;
@@ -779,7 +781,7 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi)
        tmp = spi_write_then_read(spi, &code, 1, id, 3);
        if (tmp < 0) {
                DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n",
-                       spi->dev.bus_id, tmp);
+                       dev_name(&spi->dev), tmp);
                return ERR_PTR(tmp);
        }
        if (id[0] != 0x1f)
@@ -815,7 +817,8 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi)
                                        if (!(info->flags & IS_POW2PS))
                                                return info;
                                }
-                       }
+                       } else
+                               return info;
                }
        }
 
@@ -869,7 +872,7 @@ static int __devinit dataflash_probe(struct spi_device *spi)
        status = dataflash_status(spi);
        if (status <= 0 || status == 0xff) {
                DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n",
-                               spi->dev.bus_id, status);
+                               dev_name(&spi->dev), status);
                if (status == 0 || status == 0xff)
                        status = -ENODEV;
                return status;
@@ -905,13 +908,13 @@ static int __devinit dataflash_probe(struct spi_device *spi)
        /* obsolete AT45DB1282 not (yet?) supported */
        default:
                DEBUG(MTD_DEBUG_LEVEL1, "%s: unsupported device (%x)\n",
-                               spi->dev.bus_id, status & 0x3c);
+                               dev_name(&spi->dev), status & 0x3c);
                status = -ENODEV;
        }
 
        if (status < 0)
                DEBUG(MTD_DEBUG_LEVEL1, "%s: add_dataflash --> %d\n",
-                               spi->dev.bus_id, status);
+                               dev_name(&spi->dev), status);
 
        return status;
 }
@@ -921,7 +924,7 @@ static int __devexit dataflash_remove(struct spi_device *spi)
        struct dataflash        *flash = dev_get_drvdata(&spi->dev);
        int                     status;
 
-       DEBUG(MTD_DEBUG_LEVEL1, "%s: remove\n", spi->dev.bus_id);
+       DEBUG(MTD_DEBUG_LEVEL1, "%s: remove\n", dev_name(&spi->dev));
 
        if (mtd_has_partitions() && flash->partitioned)
                status = del_mtd_partitions(&flash->mtd);