2 * drivers/mtd/autcpu12.c
4 * Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de>
6 * Derived from drivers/mtd/spia.c
7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
9 * $Id: autcpu12.c,v 1.19 2004/07/12 15:02:15 dwmw2 Exp $
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 as
13 * published by the Free Software Foundation.
16 * This is a device driver for the NAND flash device found on the
17 * autronix autcpu12 board, which is a SmartMediaCard. It supports
18 * 16MiB, 32MiB and 64MiB cards.
21 * 02-12-2002 TG Cleanup of module params
23 * 02-20-2002 TG adjusted for different rd/wr adress support
24 * added support for read device ready/busy line
27 * 10-06-2002 TG 128K card support added
30 #include <linux/version.h>
31 #include <linux/slab.h>
32 #include <linux/init.h>
33 #include <linux/module.h>
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/nand.h>
36 #include <linux/mtd/partitions.h>
38 #include <asm/arch/hardware.h>
39 #include <asm/sizes.h>
40 #include <asm/arch/autcpu12.h>
43 * MTD structure for AUTCPU12 board
45 static struct mtd_info *autcpu12_mtd = NULL;
50 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
51 #define autcpu12_init init_module
52 #define autcpu12_cleanup cleanup_module
55 static int autcpu12_io_base = CS89712_VIRT_BASE;
56 static int autcpu12_fio_pbase = AUTCPU12_PHYS_SMC;
57 static int autcpu12_fio_ctrl = AUTCPU12_SMC_SELECT_OFFSET;
58 static int autcpu12_pedr = AUTCPU12_SMC_PORT_OFFSET;
59 static int autcpu12_fio_base;
62 MODULE_PARM(autcpu12_fio_pbase, "i");
63 MODULE_PARM(autcpu12_fio_ctrl, "i");
64 MODULE_PARM(autcpu12_pedr, "i");
66 __setup("autcpu12_fio_pbase=",autcpu12_fio_pbase);
67 __setup("autcpu12_fio_ctrl=",autcpu12_fio_ctrl);
68 __setup("autcpu12_pedr=",autcpu12_pedr);
72 * Define partitions for flash devices
74 static struct mtd_partition partition_info16k[] = {
75 { .name = "AUTCPU12 flash partition 1",
78 { .name = "AUTCPU12 flash partition 2",
83 static struct mtd_partition partition_info32k[] = {
84 { .name = "AUTCPU12 flash partition 1",
87 { .name = "AUTCPU12 flash partition 2",
92 static struct mtd_partition partition_info64k[] = {
93 { .name = "AUTCPU12 flash partition 1",
96 { .name = "AUTCPU12 flash partition 2",
101 static struct mtd_partition partition_info128k[] = {
102 { .name = "AUTCPU12 flash partition 1",
104 .size = 16 * SZ_1M },
105 { .name = "AUTCPU12 flash partition 2",
106 .offset = 16 * SZ_1M,
107 .size = 112 * SZ_1M },
110 #define NUM_PARTITIONS16K 2
111 #define NUM_PARTITIONS32K 2
112 #define NUM_PARTITIONS64K 2
113 #define NUM_PARTITIONS128K 2
115 * hardware specific access to control-lines
117 static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd)
122 case NAND_CTL_SETCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |= AUTCPU12_SMC_CLE; break;
123 case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_CLE; break;
125 case NAND_CTL_SETALE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |= AUTCPU12_SMC_ALE; break;
126 case NAND_CTL_CLRALE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_ALE; break;
128 case NAND_CTL_SETNCE: (*(volatile unsigned char *) (autcpu12_fio_base + autcpu12_fio_ctrl)) = 0x01; break;
129 case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (autcpu12_fio_base + autcpu12_fio_ctrl)) = 0x00; break;
134 * read device ready pin
136 int autcpu12_device_ready(struct mtd_info *mtd)
139 return ( (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) & AUTCPU12_SMC_RDY) ? 1 : 0;
144 * Main initialization routine
146 int __init autcpu12_init (void)
148 struct nand_chip *this;
151 /* Allocate memory for MTD device structure and private data */
152 autcpu12_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
155 printk ("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
160 /* map physical adress */
161 autcpu12_fio_base=(unsigned long)ioremap(autcpu12_fio_pbase,SZ_1K);
162 if(!autcpu12_fio_base){
163 printk("Ioremap autcpu12 SmartMedia Card failed\n");
168 /* Get pointer to private data */
169 this = (struct nand_chip *) (&autcpu12_mtd[1]);
171 /* Initialize structures */
172 memset((char *) autcpu12_mtd, 0, sizeof(struct mtd_info));
173 memset((char *) this, 0, sizeof(struct nand_chip));
175 /* Link the private data with the MTD structure */
176 autcpu12_mtd->priv = this;
178 /* Set address of NAND IO lines */
179 this->IO_ADDR_R = autcpu12_fio_base;
180 this->IO_ADDR_W = autcpu12_fio_base;
181 this->hwcontrol = autcpu12_hwcontrol;
182 this->dev_ready = autcpu12_device_ready;
183 /* 20 us command delay time */
184 this->chip_delay = 20;
185 this->eccmode = NAND_ECC_SOFT;
187 /* Enable the following for a flash based bad block table */
189 this->options = NAND_USE_FLASH_BBT;
191 this->options = NAND_USE_FLASH_BBT;
193 /* Scan to find existance of the device */
194 if (nand_scan (autcpu12_mtd, 1)) {
199 /* Register the partitions */
200 switch(autcpu12_mtd->size){
201 case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break;
202 case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break;
203 case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break;
204 case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break;
206 printk ("Unsupported SmartMedia device\n");
214 iounmap((void *)autcpu12_fio_base);
216 kfree (autcpu12_mtd);
221 module_init(autcpu12_init);
227 static void __exit autcpu12_cleanup (void)
229 /* Release resources, unregister device */
230 nand_release (autcpu12_mtd);
232 /* unmap physical adress */
233 iounmap((void *)autcpu12_fio_base);
235 /* Free the MTD device structure */
236 kfree (autcpu12_mtd);
238 module_exit(autcpu12_cleanup);
241 MODULE_LICENSE("GPL");
242 MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
243 MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");