MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / mtd / nand / m5329.c
blob4717c96df3010e7a328e34ceba3097f7628d0e46
1 /*
2 * drivers/mtd/nand/m5329.c
4 * Yaroslav Vinogradov (Yaroslav.Vinogradov@freescale.com)
5 *
6 * Copyright Freescale Semiconductor, Inc 2006
8 * Using as template code from:
9 * drivers/mtd/nand/spia.c Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 or any later
13 * version (at your option) as published by the Free Software Foundation.
15 * Overview:
16 * This is a device driver for the NAND flash device found on the
17 * M5329EVB board which utilizes the Toshiba part. This is
18 * a 16MB NAND Flash device
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
28 #include <asm/io.h>
29 #include <asm/mcfsim.h>
32 * MTD structure for M5329EVB board
34 static struct mtd_info *m5329_mtd = NULL;
37 * Values specific to the SPIA board (used with EP7212 processor)
39 #define NAND_FLASH_ADDRESS 0xd0000000 /* Fash address mapping */
41 #define CLE_ADDR_BIT 4
42 #define ALE_ADDR_BIT 3
43 #define NCE_ADDR_BIT 19
46 * Module stuff
49 static unsigned int m5329_fio_base = NAND_FLASH_ADDRESS;
51 module_param(m5329_fio_base, int, 0);
54 * Define partitions for flash device
56 const static struct mtd_partition partition_info[] = {
58 .name = "M5329 flash partition 1",
59 .offset = 0,
60 .size = 16*1024*1024
63 #define NUM_PARTITIONS 1
66 /*
67 * hardware specific access to control-lines
69 static void m5329_hwcontrol(struct mtd_info *mtd, int cmd){
70 struct nand_chip *this;
71 unsigned int base;
74 /* Get pointer to private data */
75 this = (struct nand_chip *) (&m5329_mtd[1]);
76 m5329_fio_base = (unsigned int)this->IO_ADDR_R;
77 base = m5329_fio_base;
79 switch(cmd){
80 case NAND_CTL_SETCLE:
81 m5329_fio_base |= 1<<CLE_ADDR_BIT;
82 break;
83 case NAND_CTL_CLRCLE:
84 m5329_fio_base &= ~(1<<CLE_ADDR_BIT);
85 break;
86 case NAND_CTL_SETALE:
87 m5329_fio_base |= 1<<ALE_ADDR_BIT;
88 break;
89 case NAND_CTL_CLRALE:
90 m5329_fio_base &= ~(1<<ALE_ADDR_BIT);
91 break;
92 case NAND_CTL_SETNCE:
93 m5329_fio_base &= ~(1<<NCE_ADDR_BIT);
94 break;
95 case NAND_CTL_CLRNCE:
96 m5329_fio_base |= 1<NCE_ADDR_BIT;
97 break;
99 /* Set address of NAND IO lines */
100 this->IO_ADDR_R = (void __iomem *) m5329_fio_base;
101 this->IO_ADDR_W = (void __iomem *) m5329_fio_base;
105 * Main initialization routine
107 int __init m5329_init (void)
109 struct nand_chip *this;
111 /* Setup NAND flash chip select signals */
112 MCF_FBCS2_CSAR = NAND_FLASH_ADDRESS;
113 MCF_FBCS2_CSCR = (MCF_FBCS_CSCR_PS_8
114 | MCF_FBCS_CSCR_BEM
115 | MCF_FBCS_CSCR_AA
116 | MCF_FBCS_CSCR_SBM
117 | MCF_FBCS_CSCR_WS(7));
118 MCF_FBCS2_CSMR = (MCF_FBCS_CSMR_BAM_16M
119 | MCF_FBCS_CSMR_V);
121 /* Allocate memory for MTD device structure and private data */
122 m5329_mtd = kmalloc (sizeof(struct mtd_info)+sizeof (struct nand_chip),
123 GFP_KERNEL);
124 if (!m5329_mtd) {
125 printk ("Unable to allocate M5329 NAND MTD device structure\n");
126 return -ENOMEM;
129 /* Get pointer to private data */
130 this = (struct nand_chip *) (&m5329_mtd[1]);
132 /* Initialize structures */
133 memset((char *) m5329_mtd, 0, sizeof(struct mtd_info));
134 memset((char *) this, 0, sizeof(struct nand_chip));
136 /* Link the private data with the MTD structure */
137 m5329_mtd->priv = this;
139 /* Set address of NAND IO lines */
140 this->IO_ADDR_R = (void __iomem *) m5329_fio_base;
141 this->IO_ADDR_W = (void __iomem *) m5329_fio_base;
142 /* Set address of hardware control function */
143 this->hwcontrol = m5329_hwcontrol;
144 /* 50 us command delay time */
145 this->chip_delay = 50;
146 this->eccmode = NAND_ECC_SOFT;
148 /* Scan to find existence of the device */
149 if (nand_scan (m5329_mtd, 1)) {
150 kfree (m5329_mtd);
151 return -ENXIO;
154 /* Register the partitions */
155 add_mtd_partitions(m5329_mtd, partition_info, NUM_PARTITIONS);
157 /* Return happy */
158 return 0;
160 module_init(m5329_init);
163 * Clean up routine
165 #ifdef MODULE
166 static void __exit m5329_cleanup (void)
168 /* Release resources, unregister device */
169 nand_release (m5329_mtd);
171 /* Free the MTD device structure */
172 kfree (m5329_mtd);
174 module_exit(m5329_cleanup);
175 #endif
177 MODULE_LICENSE("GPL");
178 MODULE_AUTHOR("Yaroslav Vinogradov <Yaroslav.Vinogradov@freescale.com>");
179 MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on M5329 board");