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.23 2005/11/07 11:14:30 gleixner 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 address support
24 * added support for read device ready/busy line
27 * 10-06-2002 TG 128K card support added
30 #include <linux/slab.h>
31 #include <linux/init.h>
32 #include <linux/module.h>
33 #include <linux/mtd/mtd.h>
34 #include <linux/mtd/nand.h>
35 #include <linux/mtd/partitions.h>
37 #include <asm/arch/hardware.h>
38 #include <asm/sizes.h>
39 #include <asm/arch/autcpu12.h>
42 * MTD structure for AUTCPU12 board
44 static struct mtd_info
*autcpu12_mtd
= NULL
;
45 static void __iomem
*autcpu12_fio_base
;
48 * Define partitions for flash devices
50 static struct mtd_partition partition_info16k
[] = {
51 { .name
= "AUTCPU12 flash partition 1",
54 { .name
= "AUTCPU12 flash partition 2",
59 static struct mtd_partition partition_info32k
[] = {
60 { .name
= "AUTCPU12 flash partition 1",
63 { .name
= "AUTCPU12 flash partition 2",
68 static struct mtd_partition partition_info64k
[] = {
69 { .name
= "AUTCPU12 flash partition 1",
72 { .name
= "AUTCPU12 flash partition 2",
77 static struct mtd_partition partition_info128k
[] = {
78 { .name
= "AUTCPU12 flash partition 1",
81 { .name
= "AUTCPU12 flash partition 2",
83 .size
= 112 * SZ_1M
},
86 #define NUM_PARTITIONS16K 2
87 #define NUM_PARTITIONS32K 2
88 #define NUM_PARTITIONS64K 2
89 #define NUM_PARTITIONS128K 2
91 * hardware specific access to control-lines
93 * ALE bit 4 autcpu12_pedr
94 * CLE bit 5 autcpu12_pedr
98 static void autcpu12_hwcontrol(struct mtd_info
*mtd
, int cmd
,
101 struct nand_chip
*chip
= mtd
->priv
;
103 if (ctrl
& NAND_CTRL_CHANGE
) {
107 addr
= CS89712_VIRT_BASE
+ AUTCPU12_SMC_PORT_OFFSET
;
108 bits
= (ctrl
& NAND_CLE
) << 4;
109 bits
|= (ctrl
& NAND_ALE
) << 2;
110 writeb((readb(addr
) & ~0x30) | bits
, addr
);
112 addr
= autcpu12_fio_base
+ AUTCPU12_SMC_SELECT_OFFSET
;
113 writeb((readb(addr
) & ~0x1) | (ctrl
& NAND_NCE
), addr
);
116 if (cmd
!= NAND_CMD_NONE
)
117 writeb(cmd
, chip
->IO_ADDR_W
);
121 * read device ready pin
123 int autcpu12_device_ready(struct mtd_info
*mtd
)
125 void __iomem
*addr
= CS89712_VIRT_BASE
+ AUTCPU12_SMC_PORT_OFFSET
;
127 return readb(addr
) & AUTCPU12_SMC_RDY
;
131 * Main initialization routine
133 static int __init
autcpu12_init(void)
135 struct nand_chip
*this;
138 /* Allocate memory for MTD device structure and private data */
139 autcpu12_mtd
= kmalloc(sizeof(struct mtd_info
) + sizeof(struct nand_chip
),
142 printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
147 /* map physical address */
148 autcpu12_fio_base
= ioremap(AUTCPU12_PHYS_SMC
, SZ_1K
);
149 if (!autcpu12_fio_base
) {
150 printk("Ioremap autcpu12 SmartMedia Card failed\n");
155 /* Get pointer to private data */
156 this = (struct nand_chip
*)(&autcpu12_mtd
[1]);
158 /* Initialize structures */
159 memset(autcpu12_mtd
, 0, sizeof(struct mtd_info
));
160 memset(this, 0, sizeof(struct nand_chip
));
162 /* Link the private data with the MTD structure */
163 autcpu12_mtd
->priv
= this;
164 autcpu12_mtd
->owner
= THIS_MODULE
;
166 /* Set address of NAND IO lines */
167 this->IO_ADDR_R
= autcpu12_fio_base
;
168 this->IO_ADDR_W
= autcpu12_fio_base
;
169 this->cmd_ctrl
= autcpu12_hwcontrol
;
170 this->dev_ready
= autcpu12_device_ready
;
171 /* 20 us command delay time */
172 this->chip_delay
= 20;
173 this->ecc
.mode
= NAND_ECC_SOFT
;
175 /* Enable the following for a flash based bad block table */
177 this->options = NAND_USE_FLASH_BBT;
179 this->options
= NAND_USE_FLASH_BBT
;
181 /* Scan to find existance of the device */
182 if (nand_scan(autcpu12_mtd
, 1)) {
187 /* Register the partitions */
188 switch (autcpu12_mtd
->size
) {
190 add_mtd_partitions(autcpu12_mtd
, partition_info16k
,
194 add_mtd_partitions(autcpu12_mtd
, partition_info32k
,
198 add_mtd_partitions(autcpu12_mtd
, partition_info64k
,
202 add_mtd_partitions(autcpu12_mtd
, partition_info128k
,
206 printk("Unsupported SmartMedia device\n");
213 iounmap(autcpu12_fio_base
);
220 module_init(autcpu12_init
);
225 static void __exit
autcpu12_cleanup(void)
227 /* Release resources, unregister device */
228 nand_release(autcpu12_mtd
);
230 /* unmap physical address */
231 iounmap(autcpu12_fio_base
);
233 /* Free the MTD device structure */
237 module_exit(autcpu12_cleanup
);
239 MODULE_LICENSE("GPL");
240 MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
241 MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");