blob: 2c410a011317a8ba3c9ec6a178835c4ad24fe39d [file] [log] [blame]
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +02001/*
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
David Woodhouse151e7652006-05-14 01:51:54 +01007 * Copyright (C) 2004 Marius Gröger (mag@sysgo.de)
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +02008 *
9 * Derived from drivers/mtd/nand/autcpu12.c
10 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
11 *
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +020012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * Overview:
17 * This is a device driver for the NAND flash device found on the
18 * TS-7250 board which utilizes a Samsung 32 Mbyte part.
19 */
20
21#include <linux/slab.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/mtd/mtd.h>
25#include <linux/mtd/nand.h>
26#include <linux/mtd/partitions.h>
27#include <asm/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +020029#include <asm/sizes.h>
30#include <asm/mach-types.h>
31
32/*
33 * MTD structure for TS7250 board
34 */
35static struct mtd_info *ts7250_mtd = NULL;
36
37#ifdef CONFIG_MTD_PARTITIONS
38static const char *part_probes[] = { "cmdlinepart", NULL };
39
40#define NUM_PARTITIONS 3
41
42/*
43 * Define static partitions for flash device
44 */
45static struct mtd_partition partition_info32[] = {
46 {
47 .name = "TS-BOOTROM",
48 .offset = 0x00000000,
49 .size = 0x00004000,
50 }, {
51 .name = "Linux",
52 .offset = 0x00004000,
53 .size = 0x01d00000,
54 }, {
55 .name = "RedBoot",
56 .offset = 0x01d04000,
57 .size = 0x002fc000,
58 },
59};
60
61/*
62 * Define static partitions for flash device
63 */
64static struct mtd_partition partition_info128[] = {
65 {
66 .name = "TS-BOOTROM",
67 .offset = 0x00000000,
68 .size = 0x00004000,
69 }, {
70 .name = "Linux",
71 .offset = 0x00004000,
72 .size = 0x07d00000,
73 }, {
74 .name = "RedBoot",
75 .offset = 0x07d04000,
76 .size = 0x002fc000,
77 },
78};
79#endif
80
81
82/*
83 * hardware specific access to control-lines
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020084 *
85 * ctrl:
86 * NAND_NCE: bit 0 -> bit 2
87 * NAND_CLE: bit 1 -> bit 1
88 * NAND_ALE: bit 2 -> bit 0
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +020089 */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020090static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +020091{
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020092 struct nand_chip *chip = mtd->priv;
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +020093
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020094 if (ctrl & NAND_CTRL_CHANGE) {
95 unsigned long addr = TS72XX_NAND_CONTROL_VIRT_BASE;
96 unsigned char bits;
97
Petr Stetiar0e4ced52006-06-23 19:17:03 +020098 bits = (ctrl & NAND_NCE) << 2;
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020099 bits |= ctrl & NAND_CLE;
100 bits |= (ctrl & NAND_ALE) >> 2;
101
102 __raw_writeb((__raw_readb(addr) & ~0x7) | bits, addr);
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200103 }
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200104
105 if (cmd != NAND_CMD_NONE)
106 writeb(cmd, chip->IO_ADDR_W);
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200107}
108
109/*
110 * read device ready pin
111 */
112static int ts7250_device_ready(struct mtd_info *mtd)
113{
114 return __raw_readb(TS72XX_NAND_BUSY_VIRT_BASE) & 0x20;
115}
116
117/*
118 * Main initialization routine
119 */
120static int __init ts7250_init(void)
121{
122 struct nand_chip *this;
123 const char *part_type = 0;
124 int mtd_parts_nb = 0;
125 struct mtd_partition *mtd_parts = 0;
126
127 if (!machine_is_ts72xx() || board_is_ts7200())
128 return -ENXIO;
129
130 /* Allocate memory for MTD device structure and private data */
David Woodhousee0c7d762006-05-13 18:07:53 +0100131 ts7250_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200132 if (!ts7250_mtd) {
133 printk("Unable to allocate TS7250 NAND MTD device structure.\n");
134 return -ENOMEM;
135 }
136
137 /* Get pointer to private data */
138 this = (struct nand_chip *)(&ts7250_mtd[1]);
139
140 /* Initialize structures */
141 memset(ts7250_mtd, 0, sizeof(struct mtd_info));
142 memset(this, 0, sizeof(struct nand_chip));
143
144 /* Link the private data with the MTD structure */
145 ts7250_mtd->priv = this;
David Woodhouse552d9202006-05-14 01:20:46 +0100146 ts7250_mtd->owner = THIS_MODULE;
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200147
148 /* insert callbacks */
149 this->IO_ADDR_R = (void *)TS72XX_NAND_DATA_VIRT_BASE;
150 this->IO_ADDR_W = (void *)TS72XX_NAND_DATA_VIRT_BASE;
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200151 this->cmd_ctrl = ts7250_hwcontrol;
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200152 this->dev_ready = ts7250_device_ready;
153 this->chip_delay = 15;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200154 this->ecc.mode = NAND_ECC_SOFT;
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200155
156 printk("Searching for NAND flash...\n");
157 /* Scan to find existence of the device */
158 if (nand_scan(ts7250_mtd, 1)) {
159 kfree(ts7250_mtd);
160 return -ENXIO;
161 }
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200162#ifdef CONFIG_MTD_PARTITIONS
163 ts7250_mtd->name = "ts7250-nand";
David Woodhousee0c7d762006-05-13 18:07:53 +0100164 mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, &mtd_parts, 0);
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200165 if (mtd_parts_nb > 0)
166 part_type = "command line";
167 else
168 mtd_parts_nb = 0;
169#endif
170 if (mtd_parts_nb == 0) {
171 mtd_parts = partition_info32;
172 if (ts7250_mtd->size >= (128 * 0x100000))
173 mtd_parts = partition_info128;
174 mtd_parts_nb = NUM_PARTITIONS;
175 part_type = "static";
176 }
177
178 /* Register the partitions */
179 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
180 add_mtd_partitions(ts7250_mtd, mtd_parts, mtd_parts_nb);
181
182 /* Return happy */
183 return 0;
184}
David Woodhousee0c7d762006-05-13 18:07:53 +0100185
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200186module_init(ts7250_init);
187
188/*
189 * Clean up routine
190 */
191static void __exit ts7250_cleanup(void)
192{
193 /* Unregister the device */
194 del_mtd_device(ts7250_mtd);
195
196 /* Free the MTD device structure */
197 kfree(ts7250_mtd);
198}
David Woodhousee0c7d762006-05-13 18:07:53 +0100199
Lennert Buytenhek7d532dd2006-04-30 10:36:38 +0200200module_exit(ts7250_cleanup);
201
202MODULE_LICENSE("GPL");
203MODULE_AUTHOR("Jesse Off <joff@embeddedARM.com>");
204MODULE_DESCRIPTION("MTD map driver for Technologic Systems TS-7250 board");