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 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 * This is a device driver for the NAND flash device found on the
15 * autronix autcpu12 board, which is a SmartMediaCard. It supports
16 * 16MiB, 32MiB and 64MiB cards.
19 * 02-12-2002 TG Cleanup of module params
21 * 02-20-2002 TG adjusted for different rd/wr address support
22 * added support for read device ready/busy line
25 * 10-06-2002 TG 128K card support added
28 #include <linux/slab.h>
29 #include <linux/init.h>
30 #include <linux/module.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/nand.h>
33 #include <linux/mtd/partitions.h>
35 #include <mach/hardware.h>
36 #include <asm/sizes.h>
37 #include <mach/autcpu12.h>
40 * MTD structure for AUTCPU12 board
42 static struct mtd_info
*autcpu12_mtd
= NULL
;
43 static void __iomem
*autcpu12_fio_base
;
46 * Define partitions for flash devices
48 static struct mtd_partition partition_info16k
[] = {
49 { .name
= "AUTCPU12 flash partition 1",
52 { .name
= "AUTCPU12 flash partition 2",
57 static struct mtd_partition partition_info32k
[] = {
58 { .name
= "AUTCPU12 flash partition 1",
61 { .name
= "AUTCPU12 flash partition 2",
66 static struct mtd_partition partition_info64k
[] = {
67 { .name
= "AUTCPU12 flash partition 1",
70 { .name
= "AUTCPU12 flash partition 2",
75 static struct mtd_partition partition_info128k
[] = {
76 { .name
= "AUTCPU12 flash partition 1",
79 { .name
= "AUTCPU12 flash partition 2",
81 .size
= 112 * SZ_1M
},
84 #define NUM_PARTITIONS16K 2
85 #define NUM_PARTITIONS32K 2
86 #define NUM_PARTITIONS64K 2
87 #define NUM_PARTITIONS128K 2
89 * hardware specific access to control-lines
91 * ALE bit 4 autcpu12_pedr
92 * CLE bit 5 autcpu12_pedr
96 static void autcpu12_hwcontrol(struct mtd_info
*mtd
, int cmd
,
99 struct nand_chip
*chip
= mtd
->priv
;
101 if (ctrl
& NAND_CTRL_CHANGE
) {
105 bits
= clps_readb(AUTCPU12_SMC_PORT_OFFSET
) & ~0x30;
106 bits
|= (ctrl
& NAND_CLE
) << 4;
107 bits
|= (ctrl
& NAND_ALE
) << 2;
108 clps_writeb(bits
, AUTCPU12_SMC_PORT_OFFSET
);
110 addr
= autcpu12_fio_base
+ AUTCPU12_SMC_SELECT_OFFSET
;
111 writeb((readb(addr
) & ~0x1) | (ctrl
& NAND_NCE
), addr
);
114 if (cmd
!= NAND_CMD_NONE
)
115 writeb(cmd
, chip
->IO_ADDR_W
);
119 * read device ready pin
121 int autcpu12_device_ready(struct mtd_info
*mtd
)
123 return clps_readb(AUTCPU12_SMC_PORT_OFFSET
) & AUTCPU12_SMC_RDY
;
127 * Main initialization routine
129 static int __init
autcpu12_init(void)
131 struct nand_chip
*this;
134 /* Allocate memory for MTD device structure and private data */
135 autcpu12_mtd
= kmalloc(sizeof(struct mtd_info
) + sizeof(struct nand_chip
),
138 printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
143 /* map physical address */
144 autcpu12_fio_base
= ioremap(AUTCPU12_PHYS_SMC
, SZ_1K
);
145 if (!autcpu12_fio_base
) {
146 printk("Ioremap autcpu12 SmartMedia Card failed\n");
151 /* Get pointer to private data */
152 this = (struct nand_chip
*)(&autcpu12_mtd
[1]);
154 /* Initialize structures */
155 memset(autcpu12_mtd
, 0, sizeof(struct mtd_info
));
156 memset(this, 0, sizeof(struct nand_chip
));
158 /* Link the private data with the MTD structure */
159 autcpu12_mtd
->priv
= this;
160 autcpu12_mtd
->owner
= THIS_MODULE
;
162 /* Set address of NAND IO lines */
163 this->IO_ADDR_R
= autcpu12_fio_base
;
164 this->IO_ADDR_W
= autcpu12_fio_base
;
165 this->cmd_ctrl
= autcpu12_hwcontrol
;
166 this->dev_ready
= autcpu12_device_ready
;
167 /* 20 us command delay time */
168 this->chip_delay
= 20;
169 this->ecc
.mode
= NAND_ECC_SOFT
;
171 /* Enable the following for a flash based bad block table */
173 this->bbt_options = NAND_BBT_USE_FLASH;
175 this->bbt_options
= NAND_BBT_USE_FLASH
;
177 /* Scan to find existence of the device */
178 if (nand_scan(autcpu12_mtd
, 1)) {
183 /* Register the partitions */
184 switch (autcpu12_mtd
->size
) {
186 mtd_device_register(autcpu12_mtd
, partition_info16k
,
190 mtd_device_register(autcpu12_mtd
, partition_info32k
,
194 mtd_device_register(autcpu12_mtd
, partition_info64k
,
198 mtd_device_register(autcpu12_mtd
, partition_info128k
,
202 printk("Unsupported SmartMedia device\n");
209 iounmap(autcpu12_fio_base
);
216 module_init(autcpu12_init
);
221 static void __exit
autcpu12_cleanup(void)
223 /* Release resources, unregister device */
224 nand_release(autcpu12_mtd
);
226 /* unmap physical address */
227 iounmap(autcpu12_fio_base
);
229 /* Free the MTD device structure */
233 module_exit(autcpu12_cleanup
);
235 MODULE_LICENSE("GPL");
236 MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
237 MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");