mxc_nand: use DRIVER_NAME where appropriate
[safe/jmp/linux-2.6] / drivers / mtd / nand / bf5xx_nand.c
index fc58afe..8506e7e 100644 (file)
@@ -91,6 +91,41 @@ static const unsigned short bfin_nfc_pin_req[] =
         P_NAND_ALE,
         0};
 
+#ifdef CONFIG_MTD_NAND_BF5XX_BOOTROM_ECC
+static uint8_t bbt_pattern[] = { 0xff };
+
+static struct nand_bbt_descr bootrom_bbt = {
+       .options = 0,
+       .offs = 63,
+       .len = 1,
+       .pattern = bbt_pattern,
+};
+
+static struct nand_ecclayout bootrom_ecclayout = {
+       .eccbytes = 24,
+       .eccpos = {
+               0x8 * 0, 0x8 * 0 + 1, 0x8 * 0 + 2,
+               0x8 * 1, 0x8 * 1 + 1, 0x8 * 1 + 2,
+               0x8 * 2, 0x8 * 2 + 1, 0x8 * 2 + 2,
+               0x8 * 3, 0x8 * 3 + 1, 0x8 * 3 + 2,
+               0x8 * 4, 0x8 * 4 + 1, 0x8 * 4 + 2,
+               0x8 * 5, 0x8 * 5 + 1, 0x8 * 5 + 2,
+               0x8 * 6, 0x8 * 6 + 1, 0x8 * 6 + 2,
+               0x8 * 7, 0x8 * 7 + 1, 0x8 * 7 + 2
+       },
+       .oobfree = {
+               { 0x8 * 0 + 3, 5 },
+               { 0x8 * 1 + 3, 5 },
+               { 0x8 * 2 + 3, 5 },
+               { 0x8 * 3 + 3, 5 },
+               { 0x8 * 4 + 3, 5 },
+               { 0x8 * 5 + 3, 5 },
+               { 0x8 * 6 + 3, 5 },
+               { 0x8 * 7 + 3, 5 },
+       }
+};
+#endif
+
 /*
  * Data structures for bf5xx nand flash controller driver
  */
@@ -423,7 +458,7 @@ static irqreturn_t bf5xx_nand_dma_irq(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-static int bf5xx_nand_dma_rw(struct mtd_info *mtd,
+static void bf5xx_nand_dma_rw(struct mtd_info *mtd,
                                uint8_t *buf, int is_read)
 {
        struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
@@ -461,11 +496,20 @@ static int bf5xx_nand_dma_rw(struct mtd_info *mtd,
        /* setup DMA register with Blackfin DMA API */
        set_dma_config(CH_NFC, 0x0);
        set_dma_start_addr(CH_NFC, (unsigned long) buf);
+
+/* The DMAs have different size on BF52x and BF54x */
+#ifdef CONFIG_BF52x
+       set_dma_x_count(CH_NFC, (page_size >> 1));
+       set_dma_x_modify(CH_NFC, 2);
+       val = DI_EN | WDSIZE_16;
+#endif
+
+#ifdef CONFIG_BF54x
        set_dma_x_count(CH_NFC, (page_size >> 2));
        set_dma_x_modify(CH_NFC, 4);
-
-       /* setup write or read operation */
        val = DI_EN | WDSIZE_32;
+#endif
+       /* setup write or read operation */
        if (is_read)
                val |= WNR;
        set_dma_config(CH_NFC, val);
@@ -477,8 +521,6 @@ static int bf5xx_nand_dma_rw(struct mtd_info *mtd,
        else
                bfin_write_NFC_PGCTL(0x2);
        wait_for_completion(&info->dma_completion);
-
-       return 0;
 }
 
 static void bf5xx_nand_dma_read_buf(struct mtd_info *mtd,
@@ -514,11 +556,9 @@ static void bf5xx_nand_dma_write_buf(struct mtd_info *mtd,
 /*
  * System initialization functions
  */
-
 static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info)
 {
        int ret;
-       unsigned short val;
 
        /* Do not use dma */
        if (!hardware_ecc)
@@ -526,13 +566,6 @@ static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info)
 
        init_completion(&info->dma_completion);
 
-#ifdef CONFIG_BF54x
-       /* Setup DMAC1 channel mux for NFC which shared with SDH */
-       val = bfin_read_DMAC1_PERIMUX();
-       val &= 0xFFFE;
-       bfin_write_DMAC1_PERIMUX(val);
-       SSYNC();
-#endif
        /* Request NFC DMA channel */
        ret = request_dma(CH_NFC, "BF5XX NFC driver");
        if (ret < 0) {
@@ -540,13 +573,26 @@ static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info)
                return ret;
        }
 
-       set_dma_callback(CH_NFC, (void *) bf5xx_nand_dma_irq, (void *) info);
+#ifdef CONFIG_BF54x
+       /* Setup DMAC1 channel mux for NFC which shared with SDH */
+       bfin_write_DMAC1_PERIMUX(bfin_read_DMAC1_PERIMUX() & ~1);
+       SSYNC();
+#endif
+
+       set_dma_callback(CH_NFC, bf5xx_nand_dma_irq, info);
 
        /* Turn off the DMA channel first */
        disable_dma(CH_NFC);
        return 0;
 }
 
+static void bf5xx_nand_dma_remove(struct bf5xx_nand_info *info)
+{
+       /* Free NFC DMA channel */
+       if (hardware_ecc)
+               free_dma(CH_NFC);
+}
+
 /*
  * BF5XX NFC hardware initialization
  *  - pin mux setup
@@ -591,7 +637,7 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
 /*
  * Device management interface
  */
-static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
+static int __devinit bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
 {
        struct mtd_info *mtd = &info->mtd;
 
@@ -605,7 +651,7 @@ static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
 #endif
 }
 
-static int bf5xx_nand_remove(struct platform_device *pdev)
+static int __devexit bf5xx_nand_remove(struct platform_device *pdev)
 {
        struct bf5xx_nand_info *info = to_nand_info(pdev);
        struct mtd_info *mtd = NULL;
@@ -623,6 +669,7 @@ static int bf5xx_nand_remove(struct platform_device *pdev)
        }
 
        peripheral_free_list(bfin_nfc_pin_req);
+       bf5xx_nand_dma_remove(info);
 
        /* free the common resources */
        kfree(info);
@@ -638,7 +685,7 @@ static int bf5xx_nand_remove(struct platform_device *pdev)
  * it can allocate all necessary resources then calls the
  * nand layer to look for devices
  */
-static int bf5xx_nand_probe(struct platform_device *pdev)
+static int __devinit bf5xx_nand_probe(struct platform_device *pdev)
 {
        struct bf5xx_nand_platform *plat = to_nand_plat(pdev);
        struct bf5xx_nand_info *info = NULL;
@@ -648,22 +695,21 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
 
        dev_dbg(&pdev->dev, "(%p)\n", pdev);
 
-       if (peripheral_request_list(bfin_nfc_pin_req, DRV_NAME)) {
-               printk(KERN_ERR DRV_NAME
-               ": Requesting Peripherals failed\n");
-               return -EFAULT;
-       }
-
        if (!plat) {
                dev_err(&pdev->dev, "no platform specific information\n");
-               goto exit_error;
+               return -EINVAL;
+       }
+
+       if (peripheral_request_list(bfin_nfc_pin_req, DRV_NAME)) {
+               dev_err(&pdev->dev, "requesting Peripherals failed\n");
+               return -EFAULT;
        }
 
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (info == NULL) {
                dev_err(&pdev->dev, "no memory for flash info\n");
                err = -ENOMEM;
-               goto exit_error;
+               goto out_err_kzalloc;
        }
 
        platform_set_drvdata(pdev, info);
@@ -707,11 +753,16 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
 
        /* initialise the hardware */
        err = bf5xx_nand_hw_init(info);
-       if (err != 0)
-               goto exit_error;
+       if (err)
+               goto out_err_hw_init;
 
        /* setup hardware ECC data struct */
        if (hardware_ecc) {
+#ifdef CONFIG_MTD_NAND_BF5XX_BOOTROM_ECC
+               chip->badblock_pattern = &bootrom_bbt;
+               chip->ecc.layout = &bootrom_ecclayout;
+#endif
+
                if (plat->page_size == NFC_PG_SIZE_256) {
                        chip->ecc.bytes = 3;
                        chip->ecc.size = 256;
@@ -733,7 +784,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
        /* scan hardware nand chip and setup mtd info data struct */
        if (nand_scan(mtd, 1)) {
                err = -ENXIO;
-               goto exit_error;
+               goto out_err_nand_scan;
        }
 
        /* add NAND partition */
@@ -742,11 +793,14 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
        dev_dbg(&pdev->dev, "initialised ok\n");
        return 0;
 
-exit_error:
-       bf5xx_nand_remove(pdev);
+out_err_nand_scan:
+       bf5xx_nand_dma_remove(info);
+out_err_hw_init:
+       platform_set_drvdata(pdev, NULL);
+       kfree(info);
+out_err_kzalloc:
+       peripheral_free_list(bfin_nfc_pin_req);
 
-       if (err == 0)
-               err = -EINVAL;
        return err;
 }
 
@@ -775,7 +829,7 @@ static int bf5xx_nand_resume(struct platform_device *dev)
 /* driver device registration */
 static struct platform_driver bf5xx_nand_driver = {
        .probe          = bf5xx_nand_probe,
-       .remove         = bf5xx_nand_remove,
+       .remove         = __devexit_p(bf5xx_nand_remove),
        .suspend        = bf5xx_nand_suspend,
        .resume         = bf5xx_nand_resume,
        .driver         = {