aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorHuang Shijie <shijie8@gmail.com>2013-12-20 11:02:28 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-01-11 15:20:15 -0500
commite07caa3687317e1c5a9efa0d315a2d7ca57f3df5 (patch)
treec2460d146e2c51386da11a5cfe1d5e7a354fc89f /drivers/mtd
parenta5900554a8b5fbc4fb731c6f9896ed265683f94e (diff)
mtd: denali: kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE
This patch kills the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE by the following way: 1.) change the @buf field of nand_buf{} from an array to a pointer. also remove the DENALI_BUF_SIZE macro. 2.) Before we call the nand_scan_ident, we allocate a temporary buffer whose size is PAGE_SIZE. 3.) After we finish the nand_scan_ident, we have already getten the page size and oob size. We will allocate the right buffer size again. Signed-off-by: Huang Shijie <shijie8@gmail.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/denali.c51
-rw-r--r--drivers/mtd/nand/denali.h4
2 files changed, 31 insertions, 24 deletions
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 3a3a47f60d28..c07cd573ad3a 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -125,7 +125,6 @@ static void reset_buf(struct denali_nand_info *denali)
125 125
126static void write_byte_to_buf(struct denali_nand_info *denali, uint8_t byte) 126static void write_byte_to_buf(struct denali_nand_info *denali, uint8_t byte)
127{ 127{
128 BUG_ON(denali->buf.tail >= sizeof(denali->buf.buf));
129 denali->buf.buf[denali->buf.tail++] = byte; 128 denali->buf.buf[denali->buf.tail++] = byte;
130} 129}
131 130
@@ -1429,20 +1428,12 @@ int denali_init(struct denali_nand_info *denali)
1429 } 1428 }
1430 } 1429 }
1431 1430
1432 /* Is 32-bit DMA supported? */ 1431 /* allocate a temporary buffer for nand_scan_ident() */
1433 ret = dma_set_mask(denali->dev, DMA_BIT_MASK(32)); 1432 denali->buf.buf = devm_kzalloc(denali->dev, PAGE_SIZE,
1434 if (ret) { 1433 GFP_DMA | GFP_KERNEL);
1435 pr_err("Spectra: no usable DMA configuration\n"); 1434 if (!denali->buf.buf)
1436 return ret; 1435 return -ENOMEM;
1437 }
1438 denali->buf.dma_buf = dma_map_single(denali->dev, denali->buf.buf,
1439 DENALI_BUF_SIZE,
1440 DMA_BIDIRECTIONAL);
1441 1436
1442 if (dma_mapping_error(denali->dev, denali->buf.dma_buf)) {
1443 dev_err(denali->dev, "Spectra: failed to map DMA buffer\n");
1444 return -EIO;
1445 }
1446 denali->mtd.dev.parent = denali->dev; 1437 denali->mtd.dev.parent = denali->dev;
1447 denali_hw_init(denali); 1438 denali_hw_init(denali);
1448 denali_drv_init(denali); 1439 denali_drv_init(denali);
@@ -1475,12 +1466,29 @@ int denali_init(struct denali_nand_info *denali)
1475 goto failed_req_irq; 1466 goto failed_req_irq;
1476 } 1467 }
1477 1468
1478 /* MTD supported page sizes vary by kernel. We validate our 1469 /* allocate the right size buffer now */
1479 * kernel supports the device here. 1470 devm_kfree(denali->dev, denali->buf.buf);
1480 */ 1471 denali->buf.buf = devm_kzalloc(denali->dev,
1481 if (denali->mtd.writesize > NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE) { 1472 denali->mtd.writesize + denali->mtd.oobsize,
1482 ret = -ENODEV; 1473 GFP_KERNEL);
1483 pr_err("Spectra: device size not supported by this version of MTD."); 1474 if (!denali->buf.buf) {
1475 ret = -ENOMEM;
1476 goto failed_req_irq;
1477 }
1478
1479 /* Is 32-bit DMA supported? */
1480 ret = dma_set_mask(denali->dev, DMA_BIT_MASK(32));
1481 if (ret) {
1482 pr_err("Spectra: no usable DMA configuration\n");
1483 goto failed_req_irq;
1484 }
1485
1486 denali->buf.dma_buf = dma_map_single(denali->dev, denali->buf.buf,
1487 denali->mtd.writesize + denali->mtd.oobsize,
1488 DMA_BIDIRECTIONAL);
1489 if (dma_mapping_error(denali->dev, denali->buf.dma_buf)) {
1490 dev_err(denali->dev, "Spectra: failed to map DMA buffer\n");
1491 ret = -EIO;
1484 goto failed_req_irq; 1492 goto failed_req_irq;
1485 } 1493 }
1486 1494
@@ -1602,7 +1610,8 @@ EXPORT_SYMBOL(denali_init);
1602void denali_remove(struct denali_nand_info *denali) 1610void denali_remove(struct denali_nand_info *denali)
1603{ 1611{
1604 denali_irq_cleanup(denali->irq, denali); 1612 denali_irq_cleanup(denali->irq, denali);
1605 dma_unmap_single(denali->dev, denali->buf.dma_buf, DENALI_BUF_SIZE, 1613 dma_unmap_single(denali->dev, denali->buf.dma_buf,
1614 denali->mtd.writesize + denali->mtd.oobsize,
1606 DMA_BIDIRECTIONAL); 1615 DMA_BIDIRECTIONAL);
1607} 1616}
1608EXPORT_SYMBOL(denali_remove); 1617EXPORT_SYMBOL(denali_remove);
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index cec5712862c9..966817462421 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -455,12 +455,10 @@
455 455
456#define ECC_SECTOR_SIZE 512 456#define ECC_SECTOR_SIZE 512
457 457
458#define DENALI_BUF_SIZE (NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE)
459
460struct nand_buf { 458struct nand_buf {
461 int head; 459 int head;
462 int tail; 460 int tail;
463 uint8_t buf[DENALI_BUF_SIZE]; 461 uint8_t *buf;
464 dma_addr_t dma_buf; 462 dma_addr_t dma_buf;
465}; 463};
466 464