2 * drivers/mtd/nand/m5329.c
4 * Yaroslav Vinogradov (Yaroslav.Vinogradov@freescale.com)
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.
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>
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
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",
63 #define NUM_PARTITIONS 1
67 * hardware specific access to control-lines
69 static void m5329_hwcontrol(struct mtd_info
*mtd
, int cmd
){
70 struct nand_chip
*this;
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
;
81 m5329_fio_base
|= 1<<CLE_ADDR_BIT
;
84 m5329_fio_base
&= ~(1<<CLE_ADDR_BIT
);
87 m5329_fio_base
|= 1<<ALE_ADDR_BIT
;
90 m5329_fio_base
&= ~(1<<ALE_ADDR_BIT
);
93 m5329_fio_base
&= ~(1<<NCE_ADDR_BIT
);
96 m5329_fio_base
|= 1<NCE_ADDR_BIT
;
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
117 | MCF_FBCS_CSCR_WS(7));
118 MCF_FBCS2_CSMR
= (MCF_FBCS_CSMR_BAM_16M
121 /* Allocate memory for MTD device structure and private data */
122 m5329_mtd
= kmalloc (sizeof(struct mtd_info
)+sizeof (struct nand_chip
),
125 printk ("Unable to allocate M5329 NAND MTD device structure\n");
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)) {
154 /* Register the partitions */
155 add_mtd_partitions(m5329_mtd
, partition_info
, NUM_PARTITIONS
);
160 module_init(m5329_init
);
166 static void __exit
m5329_cleanup (void)
168 /* Release resources, unregister device */
169 nand_release (m5329_mtd
);
171 /* Free the MTD device structure */
174 module_exit(m5329_cleanup
);
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");