[MTD] NAND modularize ECC
[deliverable/linux.git] / drivers / mtd / nand / ts7250.c
CommitLineData
7d532dd5
LB
1/*
2 * drivers/mtd/nand/ts7250.c
3 *
4 * Copyright (C) 2004 Technologic Systems (support@embeddedARM.com)
5 *
6 * Derived from drivers/mtd/nand/edb7312.c
151e7659 7 * Copyright (C) 2004 Marius Gröger (mag@sysgo.de)
7d532dd5
LB
8 *
9 * Derived from drivers/mtd/nand/autcpu12.c
10 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
11 *
12 * $Id: ts7250.c,v 1.4 2004/12/30 22:02:07 joff Exp $
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 *
18 * Overview:
19 * This is a device driver for the NAND flash device found on the
20 * TS-7250 board which utilizes a Samsung 32 Mbyte part.
21 */
22
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/mtd/mtd.h>
27#include <linux/mtd/nand.h>
28#include <linux/mtd/partitions.h>
29#include <asm/io.h>
30#include <asm/arch/hardware.h>
31#include <asm/sizes.h>
32#include <asm/mach-types.h>
33
34/*
35 * MTD structure for TS7250 board
36 */
37static struct mtd_info *ts7250_mtd = NULL;
38
39#ifdef CONFIG_MTD_PARTITIONS
40static const char *part_probes[] = { "cmdlinepart", NULL };
41
42#define NUM_PARTITIONS 3
43
44/*
45 * Define static partitions for flash device
46 */
47static struct mtd_partition partition_info32[] = {
48 {
49 .name = "TS-BOOTROM",
50 .offset = 0x00000000,
51 .size = 0x00004000,
52 }, {
53 .name = "Linux",
54 .offset = 0x00004000,
55 .size = 0x01d00000,
56 }, {
57 .name = "RedBoot",
58 .offset = 0x01d04000,
59 .size = 0x002fc000,
60 },
61};
62
63/*
64 * Define static partitions for flash device
65 */
66static struct mtd_partition partition_info128[] = {
67 {
68 .name = "TS-BOOTROM",
69 .offset = 0x00000000,
70 .size = 0x00004000,
71 }, {
72 .name = "Linux",
73 .offset = 0x00004000,
74 .size = 0x07d00000,
75 }, {
76 .name = "RedBoot",
77 .offset = 0x07d04000,
78 .size = 0x002fc000,
79 },
80};
81#endif
82
83
84/*
85 * hardware specific access to control-lines
86 */
87static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd)
88{
89 unsigned long ctrl = TS72XX_NAND_CONTROL_VIRT_BASE;
90
e0c7d767 91 switch (cmd) {
7d532dd5
LB
92 case NAND_CTL_SETCLE:
93 __raw_writeb(__raw_readb(ctrl) | 0x2, ctrl);
94 break;
95 case NAND_CTL_CLRCLE:
96 __raw_writeb(__raw_readb(ctrl) & ~0x2, ctrl);
97 break;
98 case NAND_CTL_SETALE:
99 __raw_writeb(__raw_readb(ctrl) | 0x1, ctrl);
100 break;
101 case NAND_CTL_CLRALE:
102 __raw_writeb(__raw_readb(ctrl) & ~0x1, ctrl);
103 break;
104 case NAND_CTL_SETNCE:
105 __raw_writeb(__raw_readb(ctrl) | 0x4, ctrl);
106 break;
107 case NAND_CTL_CLRNCE:
108 __raw_writeb(__raw_readb(ctrl) & ~0x4, ctrl);
109 break;
110 }
111}
112
113/*
114 * read device ready pin
115 */
116static int ts7250_device_ready(struct mtd_info *mtd)
117{
118 return __raw_readb(TS72XX_NAND_BUSY_VIRT_BASE) & 0x20;
119}
120
121/*
122 * Main initialization routine
123 */
124static int __init ts7250_init(void)
125{
126 struct nand_chip *this;
127 const char *part_type = 0;
128 int mtd_parts_nb = 0;
129 struct mtd_partition *mtd_parts = 0;
130
131 if (!machine_is_ts72xx() || board_is_ts7200())
132 return -ENXIO;
133
134 /* Allocate memory for MTD device structure and private data */
e0c7d767 135 ts7250_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
7d532dd5
LB
136 if (!ts7250_mtd) {
137 printk("Unable to allocate TS7250 NAND MTD device structure.\n");
138 return -ENOMEM;
139 }
140
141 /* Get pointer to private data */
142 this = (struct nand_chip *)(&ts7250_mtd[1]);
143
144 /* Initialize structures */
145 memset(ts7250_mtd, 0, sizeof(struct mtd_info));
146 memset(this, 0, sizeof(struct nand_chip));
147
148 /* Link the private data with the MTD structure */
149 ts7250_mtd->priv = this;
552d9205 150 ts7250_mtd->owner = THIS_MODULE;
7d532dd5
LB
151
152 /* insert callbacks */
153 this->IO_ADDR_R = (void *)TS72XX_NAND_DATA_VIRT_BASE;
154 this->IO_ADDR_W = (void *)TS72XX_NAND_DATA_VIRT_BASE;
155 this->hwcontrol = ts7250_hwcontrol;
156 this->dev_ready = ts7250_device_ready;
157 this->chip_delay = 15;
6dfc6d25 158 this->ecc.mode = NAND_ECC_SOFT;
7d532dd5
LB
159
160 printk("Searching for NAND flash...\n");
161 /* Scan to find existence of the device */
162 if (nand_scan(ts7250_mtd, 1)) {
163 kfree(ts7250_mtd);
164 return -ENXIO;
165 }
7d532dd5
LB
166#ifdef CONFIG_MTD_PARTITIONS
167 ts7250_mtd->name = "ts7250-nand";
e0c7d767 168 mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, &mtd_parts, 0);
7d532dd5
LB
169 if (mtd_parts_nb > 0)
170 part_type = "command line";
171 else
172 mtd_parts_nb = 0;
173#endif
174 if (mtd_parts_nb == 0) {
175 mtd_parts = partition_info32;
176 if (ts7250_mtd->size >= (128 * 0x100000))
177 mtd_parts = partition_info128;
178 mtd_parts_nb = NUM_PARTITIONS;
179 part_type = "static";
180 }
181
182 /* Register the partitions */
183 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
184 add_mtd_partitions(ts7250_mtd, mtd_parts, mtd_parts_nb);
185
186 /* Return happy */
187 return 0;
188}
e0c7d767 189
7d532dd5
LB
190module_init(ts7250_init);
191
192/*
193 * Clean up routine
194 */
195static void __exit ts7250_cleanup(void)
196{
197 /* Unregister the device */
198 del_mtd_device(ts7250_mtd);
199
200 /* Free the MTD device structure */
201 kfree(ts7250_mtd);
202}
e0c7d767 203
7d532dd5
LB
204module_exit(ts7250_cleanup);
205
206MODULE_LICENSE("GPL");
207MODULE_AUTHOR("Jesse Off <joff@embeddedARM.com>");
208MODULE_DESCRIPTION("MTD map driver for Technologic Systems TS-7250 board");
This page took 0.03585 seconds and 5 git commands to generate.