Merge branch 'org.openembedded.dev' of git://git.openembedded.net/openembedded into...
[vuplus_openembedded] / packages / linux / linux-dm8000 / linux-2.6.12-dm8000-nand.patch
1 Index: stblinux-2.6.12/drivers/mtd/nand/Kconfig
2 ===================================================================
3 --- stblinux-2.6.12.orig/drivers/mtd/nand/Kconfig       2006-10-10 20:27:00.000000000 +0200
4 +++ stblinux-2.6.12/drivers/mtd/nand/Kconfig    2007-04-25 02:36:25.000000000 +0200
5 @@ -199,6 +199,10 @@
6         help
7           Enables access to the Smart Media card interface on the AT91RM9200.
8  
9 +config MTD_NAND_DM8000
10 +       bool "DM8000 NAND support"
11 +       depends on MTD_NAND
12 +
13  config MTD_NAND_NANDSIM
14         tristate "Support for NAND Flash Simulator"
15         depends on m && MTD_NAND && MTD_PARTITIONS
16 Index: stblinux-2.6.12/drivers/mtd/nand/Makefile
17 ===================================================================
18 --- stblinux-2.6.12.orig/drivers/mtd/nand/Makefile      2006-10-10 20:27:00.000000000 +0200
19 +++ stblinux-2.6.12/drivers/mtd/nand/Makefile   2007-04-25 02:36:25.000000000 +0200
20 @@ -16,6 +16,7 @@
21  obj-$(CONFIG_MTD_NAND_AU1550)          += au1550nd.o
22  obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB)  += ppchameleonevb.o
23  obj-$(CONFIG_MTD_NAND_S3C2410)         += s3c2410.o
24 +obj-$(CONFIG_MTD_NAND_DM8000)     += dm8000.o
25  obj-$(CONFIG_MTD_NAND_DISKONCHIP)      += diskonchip.o
26  obj-$(CONFIG_MTD_NAND_H1900)           += h1910.o
27  obj-$(CONFIG_MTD_NAND_RTC_FROM4)       += rtc_from4.o
28 Index: stblinux-2.6.12/drivers/mtd/nand/dm8000.c
29 ===================================================================
30 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
31 +++ stblinux-2.6.12/drivers/mtd/nand/dm8000.c   2007-04-25 16:09:12.000000000 +0200
32 @@ -0,0 +1,217 @@
33 +/*
34 + *  drivers/mtd/nand/dm8000.c
35 + *
36 + *  Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
37 + *
38 + *  Modified for Dreambox DM8000 by Felix Domke <tmbinc@elitedvb.net>
39 + *
40 + *
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License version 2 as
43 + * published by the Free Software Foundation.
44 + *
45 + *  Overview:
46 + *   This is a device driver for the NAND flash device found on the
47 + *   DM8000 board.
48 + *
49 + */
50 +
51 +#include <linux/slab.h>
52 +#include <linux/module.h>
53 +#include <linux/mtd/mtd.h>
54 +#include <linux/mtd/nand.h>
55 +#include <linux/mtd/partitions.h>
56 +#include <asm/io.h>
57 +
58 +static struct mtd_info *dm8000_mtd = NULL;
59 +/*
60 + * Define partitions for flash device
61 + */
62 +const static struct mtd_partition partition_info[] = {
63 +       {
64 +               .name   = "complete",
65 +               .offset = 0,
66 +               .size   = 256*1024*1024
67 +       },
68 +       {
69 +               .name   = "loader",
70 +               .offset = 0,
71 +               .size   = 1024*1024
72 +       },
73 +       {
74 +               .name   = "boot partition",
75 +               .offset = 1024*1024,
76 +               .size   = 3*1024*1024
77 +       },
78 +       {
79 +               .name   = "root partition",
80 +               .offset = 4*1024*1024,
81 +               .size   = 60*1024*1024
82 +       },
83 +       {
84 +               .name   = "home partition",
85 +               .offset = 64*1024*1024,
86 +               .size   = 64*1024*1024
87 +       },
88 +       {
89 +               .name   = "unused partition",
90 +               .offset = 128*1024*1024,
91 +               .size   = 120*1024*1024
92 +       },
93 +       {
94 +               .name   = "preset partition",
95 +               .offset = 248*1024*1024,
96 +               .size   = 8*1024*1024
97 +       }
98 +};
99 +#define NUM_PARTITIONS 7
100 +
101 +/*
102 + *     hardware specific access to control-lines
103 + *  our hardware logic handles the line according to the addresses.
104 + */
105 +static void dm8000_hwcontrol(struct mtd_info *mtd, int cmd)
106 +{
107 +       struct nand_chip *this = mtd->priv;
108 +
109 +       switch(cmd){
110 +
111 +       case NAND_CTL_SETCLE: this->IO_ADDR_W = (void*)0xBF030000; break; // COMMAND
112 +       case NAND_CTL_CLRCLE: this->IO_ADDR_W = (void*)0xBF030004; break; // DATA
113 +
114 +       case NAND_CTL_SETALE: this->IO_ADDR_W = (void*)0xBF030002; break; // ADDRESS
115 +       case NAND_CTL_CLRALE: this->IO_ADDR_W = (void*)0xBF030004; break; // DATA
116 +
117 +       case NAND_CTL_SETNCE: break; // CE will automatically set on command
118 +       case NAND_CTL_CLRNCE: *(volatile unsigned char*)0xBF030003 = 0; break; // TERM
119 +       default:
120 +               BUG();
121 +       }
122 +}
123 +
124 +static void dm8000_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
125 +{
126 +//     struct nand_chip *this = mtd->priv;
127 +
128 +       *(volatile unsigned char*)0xBF030002;
129 +
130 +       while (len > 16)
131 +       {
132 +               *(long*)buf = *(volatile long*)(0xBF030004);
133 +               *(long*)(buf+4) = *(volatile long*)(0xBF030004);
134 +               *(long*)(buf+8) = *(volatile long*)(0xBF030004);
135 +               *(long*)(buf+12) = *(volatile long*)(0xBF030004);
136 +               buf += 16;
137 +               len -= 16;
138 +       }
139 +
140 +       while (len--)
141 +               *buf++ = *(volatile unsigned char*)(0xBF030004);
142 +}
143 +
144 +static int dm8000_dev_ready(struct mtd_info *mtd)
145 +{
146 +       *(volatile unsigned char*)0xBF030002;
147 +       return 1;
148 +}
149 +
150 +/*
151 + * Main initialization routine
152 + */
153 +int __init dm8000_init (void)
154 +{
155 +       struct nand_chip *this;
156 +       unsigned char probe[4];
157 +       int i, j;
158 +
159 +       /* Allocate memory for MTD device structure and private data */
160 +       dm8000_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
161 +                               GFP_KERNEL);
162 +       if (!dm8000_mtd) {
163 +               printk ("Unable to allocate DM8000 NAND MTD device structure.\n");
164 +               return -ENOMEM;
165 +       }
166 +
167 +       /* Get pointer to private data */
168 +       this = (struct nand_chip *) (&dm8000_mtd[1]);
169 +
170 +       *(volatile unsigned char*)(0xBF030000) = 0x90;
171 +       *(volatile unsigned char*)(0xBF030002) = 0;
172 +       probe[0] = *(volatile unsigned char*)(0xBF030004);
173 +       probe[1] = *(volatile unsigned char*)(0xBF030004);
174 +       probe[2] = *(volatile unsigned char*)(0xBF030004);
175 +       probe[3] = *(volatile unsigned char*)(0xBF030004);
176 +       *(volatile unsigned char*)(0xBF030003) = 0; // term
177 +
178 +       j = jiffies;
179 +       for (i=0; i<1000*1000/4; ++i)
180 +               *(volatile unsigned long*)(0xBF030004);
181 +       printk("%ld kb/s\n", 1000 * HZ / (jiffies-j));
182 +
183 +       printk(" - NAND PROBE: %02x %02x %02x %02x\n",
184 +                       probe[0], probe[1], probe[2], probe[3]);
185 +
186 +       /* Initialize structures */
187 +       memset((char *) dm8000_mtd, 0, sizeof(struct mtd_info));
188 +       memset((char *) this, 0, sizeof(struct nand_chip));
189 +
190 +       /* Link the private data with the MTD structure */
191 +       dm8000_mtd->priv = this;
192 +
193 +       /* Set address of NAND IO lines */
194 +       this->IO_ADDR_R = (void*)0xBF030004;
195 +       this->IO_ADDR_W = (void*)0xBF030004;
196 +
197 +       /* Set address of hardware control function */
198 +       this->hwcontrol = dm8000_hwcontrol;
199 +       this->read_buf = dm8000_nand_read_buf;
200 +       this->dev_ready = 0; // don't use dm8000_dev_ready
201 +       /* 15 us command delay time */
202 +       this->chip_delay = 15;
203 +       this->eccmode = NAND_ECC_SOFT;
204 +
205 +       /* Scan to find existence of the device */
206 +       if (nand_scan (dm8000_mtd, 1)) {
207 +               kfree (dm8000_mtd);
208 +               return -ENXIO;
209 +       }
210 +
211 +       /* Allocate memory for internal data buffer */
212 +       this->data_buf = kmalloc (sizeof(u_char) * (dm8000_mtd->oobblock + dm8000_mtd->oobsize), GFP_KERNEL);
213 +       if (!this->data_buf) {
214 +               printk ("Unable to allocate NAND data buffer for Dreambox.\n");
215 +               kfree (dm8000_mtd);
216 +               return -ENOMEM;
217 +       }
218 +
219 +       /* Register the partitions */
220 +       add_mtd_partitions(dm8000_mtd, partition_info, NUM_PARTITIONS);
221 +
222 +       /* Return happy */
223 +       return 0;
224 +}
225 +module_init(dm8000_init);
226 +
227 +/*
228 + * Clean up routine
229 + */
230 +#ifdef MODULE
231 +static void __exit dm8000_cleanup (void)
232 +{
233 +       struct nand_chip *this = (struct nand_chip *) &dm8000_mtd[1];
234 +
235 +       /* Unregister the device */
236 +       del_mtd_device (dm8000_mtd);
237 +
238 +       /* Free internal data buffer */
239 +       kfree (this->data_buf);
240 +
241 +       /* Free the MTD device structure */
242 +       kfree (dm8000_mtd);
243 +}
244 +module_exit(dm8000_cleanup);
245 +#endif
246 +
247 +MODULE_LICENSE("GPL");
248 +MODULE_AUTHOR("Felix Domke <tmbinc@elitedvb.net>");
249 +MODULE_DESCRIPTION("Dream-Multimedia DM8000 NAND flash board glue");