]>
Commit | Line | Data |
---|---|---|
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 | */ | |
37 | static struct mtd_info *ts7250_mtd = NULL; | |
38 | ||
39 | #ifdef CONFIG_MTD_PARTITIONS | |
40 | static const char *part_probes[] = { "cmdlinepart", NULL }; | |
41 | ||
42 | #define NUM_PARTITIONS 3 | |
43 | ||
44 | /* | |
45 | * Define static partitions for flash device | |
46 | */ | |
47 | static 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 | */ | |
66 | static 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 | |
7abd3ef9 TG |
86 | * |
87 | * ctrl: | |
88 | * NAND_NCE: bit 0 -> bit 2 | |
89 | * NAND_CLE: bit 1 -> bit 1 | |
90 | * NAND_ALE: bit 2 -> bit 0 | |
7d532dd5 | 91 | */ |
7abd3ef9 | 92 | static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
7d532dd5 | 93 | { |
7abd3ef9 TG |
94 | struct nand_chip *chip = mtd->priv; |
95 | ||
96 | if (ctrl & NAND_CTRL_CHANGE) { | |
97 | unsigned long addr = TS72XX_NAND_CONTROL_VIRT_BASE; | |
98 | unsigned char bits; | |
99 | ||
0e4ced59 | 100 | bits = (ctrl & NAND_NCE) << 2; |
7abd3ef9 TG |
101 | bits |= ctrl & NAND_CLE; |
102 | bits |= (ctrl & NAND_ALE) >> 2; | |
103 | ||
104 | __raw_writeb((__raw_readb(addr) & ~0x7) | bits, addr); | |
7d532dd5 | 105 | } |
7abd3ef9 TG |
106 | |
107 | if (cmd != NAND_CMD_NONE) | |
108 | writeb(cmd, chip->IO_ADDR_W); | |
7d532dd5 LB |
109 | } |
110 | ||
111 | /* | |
112 | * read device ready pin | |
113 | */ | |
114 | static int ts7250_device_ready(struct mtd_info *mtd) | |
115 | { | |
116 | return __raw_readb(TS72XX_NAND_BUSY_VIRT_BASE) & 0x20; | |
117 | } | |
118 | ||
119 | /* | |
120 | * Main initialization routine | |
121 | */ | |
122 | static int __init ts7250_init(void) | |
123 | { | |
124 | struct nand_chip *this; | |
125 | const char *part_type = 0; | |
126 | int mtd_parts_nb = 0; | |
127 | struct mtd_partition *mtd_parts = 0; | |
128 | ||
129 | if (!machine_is_ts72xx() || board_is_ts7200()) | |
130 | return -ENXIO; | |
131 | ||
132 | /* Allocate memory for MTD device structure and private data */ | |
e0c7d767 | 133 | ts7250_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
7d532dd5 LB |
134 | if (!ts7250_mtd) { |
135 | printk("Unable to allocate TS7250 NAND MTD device structure.\n"); | |
136 | return -ENOMEM; | |
137 | } | |
138 | ||
139 | /* Get pointer to private data */ | |
140 | this = (struct nand_chip *)(&ts7250_mtd[1]); | |
141 | ||
142 | /* Initialize structures */ | |
143 | memset(ts7250_mtd, 0, sizeof(struct mtd_info)); | |
144 | memset(this, 0, sizeof(struct nand_chip)); | |
145 | ||
146 | /* Link the private data with the MTD structure */ | |
147 | ts7250_mtd->priv = this; | |
552d9205 | 148 | ts7250_mtd->owner = THIS_MODULE; |
7d532dd5 LB |
149 | |
150 | /* insert callbacks */ | |
151 | this->IO_ADDR_R = (void *)TS72XX_NAND_DATA_VIRT_BASE; | |
152 | this->IO_ADDR_W = (void *)TS72XX_NAND_DATA_VIRT_BASE; | |
7abd3ef9 | 153 | this->cmd_ctrl = ts7250_hwcontrol; |
7d532dd5 LB |
154 | this->dev_ready = ts7250_device_ready; |
155 | this->chip_delay = 15; | |
6dfc6d25 | 156 | this->ecc.mode = NAND_ECC_SOFT; |
7d532dd5 LB |
157 | |
158 | printk("Searching for NAND flash...\n"); | |
159 | /* Scan to find existence of the device */ | |
160 | if (nand_scan(ts7250_mtd, 1)) { | |
161 | kfree(ts7250_mtd); | |
162 | return -ENXIO; | |
163 | } | |
7d532dd5 LB |
164 | #ifdef CONFIG_MTD_PARTITIONS |
165 | ts7250_mtd->name = "ts7250-nand"; | |
e0c7d767 | 166 | mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, &mtd_parts, 0); |
7d532dd5 LB |
167 | if (mtd_parts_nb > 0) |
168 | part_type = "command line"; | |
169 | else | |
170 | mtd_parts_nb = 0; | |
171 | #endif | |
172 | if (mtd_parts_nb == 0) { | |
173 | mtd_parts = partition_info32; | |
174 | if (ts7250_mtd->size >= (128 * 0x100000)) | |
175 | mtd_parts = partition_info128; | |
176 | mtd_parts_nb = NUM_PARTITIONS; | |
177 | part_type = "static"; | |
178 | } | |
179 | ||
180 | /* Register the partitions */ | |
181 | printk(KERN_NOTICE "Using %s partition definition\n", part_type); | |
182 | add_mtd_partitions(ts7250_mtd, mtd_parts, mtd_parts_nb); | |
183 | ||
184 | /* Return happy */ | |
185 | return 0; | |
186 | } | |
e0c7d767 | 187 | |
7d532dd5 LB |
188 | module_init(ts7250_init); |
189 | ||
190 | /* | |
191 | * Clean up routine | |
192 | */ | |
193 | static void __exit ts7250_cleanup(void) | |
194 | { | |
195 | /* Unregister the device */ | |
196 | del_mtd_device(ts7250_mtd); | |
197 | ||
198 | /* Free the MTD device structure */ | |
199 | kfree(ts7250_mtd); | |
200 | } | |
e0c7d767 | 201 | |
7d532dd5 LB |
202 | module_exit(ts7250_cleanup); |
203 | ||
204 | MODULE_LICENSE("GPL"); | |
205 | MODULE_AUTHOR("Jesse Off <joff@embeddedARM.com>"); | |
206 | MODULE_DESCRIPTION("MTD map driver for Technologic Systems TS-7250 board"); |