[MTD] NAND modularize ECC
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / mtd / nand / h1910.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/mtd/nand/h1910.c
3 *
4 * Copyright (C) 2003 Joshua Wise (joshua@joshuawise.com)
5 *
6 * Derived from drivers/mtd/nand/edb7312.c
151e7659 7 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
1da177e4
LT
8 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
9 *
61b03bd7 10 * $Id: h1910.c,v 1.6 2005/11/07 11:14:30 gleixner Exp $
1da177e4
LT
11 *
12 * 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 * iPAQ h1910 board which utilizes the Samsung K9F2808 part. This is
19 * a 128Mibit (16MiB x 8 bits) NAND flash device.
20 */
21
22#include <linux/slab.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/mtd/mtd.h>
26#include <linux/mtd/nand.h>
27#include <linux/mtd/partitions.h>
28#include <asm/io.h>
e0c7d767 29#include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
1da177e4
LT
30#include <asm/sizes.h>
31#include <asm/arch/h1900-gpio.h>
32#include <asm/arch/ipaq.h>
33
34/*
35 * MTD structure for EDB7312 board
36 */
37static struct mtd_info *h1910_nand_mtd = NULL;
38
39/*
40 * Module stuff
41 */
42
43#ifdef CONFIG_MTD_PARTITIONS
44/*
45 * Define static partitions for flash device
46 */
47static struct mtd_partition partition_info[] = {
e0c7d767
DW
48 {name:"h1910 NAND Flash",
49 offset:0,
50 size:16 * 1024 * 1024}
1da177e4 51};
e0c7d767 52
1da177e4
LT
53#define NUM_PARTITIONS 1
54
55#endif
56
61b03bd7 57/*
1da177e4
LT
58 * hardware specific access to control-lines
59 */
61b03bd7 60static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
1da177e4 61{
e0c7d767 62 struct nand_chip *this = (struct nand_chip *)(mtd->priv);
61b03bd7 63
e0c7d767 64 switch (cmd) {
61b03bd7
TG
65
66 case NAND_CTL_SETCLE:
1da177e4
LT
67 this->IO_ADDR_R |= (1 << 2);
68 this->IO_ADDR_W |= (1 << 2);
69 break;
61b03bd7 70 case NAND_CTL_CLRCLE:
1da177e4
LT
71 this->IO_ADDR_R &= ~(1 << 2);
72 this->IO_ADDR_W &= ~(1 << 2);
73 break;
61b03bd7 74
1da177e4
LT
75 case NAND_CTL_SETALE:
76 this->IO_ADDR_R |= (1 << 3);
77 this->IO_ADDR_W |= (1 << 3);
78 break;
79 case NAND_CTL_CLRALE:
80 this->IO_ADDR_R &= ~(1 << 3);
81 this->IO_ADDR_W &= ~(1 << 3);
82 break;
61b03bd7 83
1da177e4
LT
84 case NAND_CTL_SETNCE:
85 break;
86 case NAND_CTL_CLRNCE:
87 break;
88 }
89}
90
91/*
92 * read device ready pin
93 */
94#if 0
95static int h1910_device_ready(struct mtd_info *mtd)
96{
97 return (GPLR(55) & GPIO_bit(55));
98}
99#endif
100
101/*
102 * Main initialization routine
103 */
e0c7d767 104static int __init h1910_init(void)
1da177e4
LT
105{
106 struct nand_chip *this;
107 const char *part_type = 0;
108 int mtd_parts_nb = 0;
109 struct mtd_partition *mtd_parts = 0;
110 void __iomem *nandaddr;
61b03bd7 111
1da177e4
LT
112 if (!machine_is_h1900())
113 return -ENODEV;
61b03bd7 114
0c2e4b4f 115 nandaddr = ioremap(0x08000000, 0x1000);
1da177e4
LT
116 if (!nandaddr) {
117 printk("Failed to ioremap nand flash.\n");
118 return -ENOMEM;
119 }
61b03bd7 120
1da177e4 121 /* Allocate memory for MTD device structure and private data */
e0c7d767 122 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
1da177e4
LT
123 if (!h1910_nand_mtd) {
124 printk("Unable to allocate h1910 NAND MTD device structure.\n");
e0c7d767 125 iounmap((void *)nandaddr);
1da177e4
LT
126 return -ENOMEM;
127 }
61b03bd7 128
1da177e4 129 /* Get pointer to private data */
e0c7d767 130 this = (struct nand_chip *)(&h1910_nand_mtd[1]);
61b03bd7 131
1da177e4 132 /* Initialize structures */
e0c7d767
DW
133 memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
134 memset(this, 0, sizeof(struct nand_chip));
61b03bd7 135
1da177e4
LT
136 /* Link the private data with the MTD structure */
137 h1910_nand_mtd->priv = this;
552d9205 138 h1910_nand_mtd->owner = THIS_MODULE;
61b03bd7 139
1da177e4
LT
140 /*
141 * Enable VPEN
142 */
143 GPSR(37) = GPIO_bit(37);
61b03bd7 144
1da177e4
LT
145 /* insert callbacks */
146 this->IO_ADDR_R = nandaddr;
147 this->IO_ADDR_W = nandaddr;
148 this->hwcontrol = h1910_hwcontrol;
149 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
150 /* 15 us command delay time */
151 this->chip_delay = 50;
6dfc6d25 152 this->ecc.mode = NAND_ECC_SOFT;
1da177e4 153 this->options = NAND_NO_AUTOINCR;
61b03bd7 154
1da177e4 155 /* Scan to find existence of the device */
e0c7d767 156 if (nand_scan(h1910_nand_mtd, 1)) {
1da177e4 157 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
e0c7d767
DW
158 kfree(h1910_nand_mtd);
159 iounmap((void *)nandaddr);
1da177e4
LT
160 return -ENXIO;
161 }
1da177e4 162#ifdef CONFIG_MTD_CMDLINE_PARTS
e0c7d767 163 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
1da177e4 164 if (mtd_parts_nb > 0)
e0c7d767 165 part_type = "command line";
1da177e4 166 else
e0c7d767 167 mtd_parts_nb = 0;
1da177e4 168#endif
e0c7d767 169 if (mtd_parts_nb == 0) {
1da177e4
LT
170 mtd_parts = partition_info;
171 mtd_parts_nb = NUM_PARTITIONS;
172 part_type = "static";
173 }
61b03bd7 174
1da177e4
LT
175 /* Register the partitions */
176 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
177 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
61b03bd7 178
1da177e4
LT
179 /* Return happy */
180 return 0;
181}
e0c7d767 182
1da177e4
LT
183module_init(h1910_init);
184
185/*
186 * Clean up routine
187 */
e0c7d767 188static void __exit h1910_cleanup(void)
1da177e4 189{
e0c7d767 190 struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
61b03bd7 191
1da177e4 192 /* Release resources, unregister device */
e0c7d767 193 nand_release(h1910_nand_mtd);
1da177e4
LT
194
195 /* Release io resource */
e0c7d767 196 iounmap((void *)this->IO_ADDR_W);
1da177e4
LT
197
198 /* Free the MTD device structure */
e0c7d767 199 kfree(h1910_nand_mtd);
1da177e4 200}
e0c7d767 201
1da177e4
LT
202module_exit(h1910_cleanup);
203
204MODULE_LICENSE("GPL");
205MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
206MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");