[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / mtd / nand / h1910.c
blob3825a7a0900ced0707182f1e39c4547e85a7ea05
1 /*
2 * drivers/mtd/nand/h1910.c
4 * Copyright (C) 2003 Joshua Wise (joshua@joshuawise.com)
6 * Derived from drivers/mtd/nand/edb7312.c
7 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
8 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
10 * $Id: h1910.c,v 1.5 2004/11/04 12:53:10 gleixner Exp $
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.
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.
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>
29 #include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
30 #include <asm/sizes.h>
31 #include <asm/arch/h1900-gpio.h>
32 #include <asm/arch/ipaq.h>
35 * MTD structure for EDB7312 board
37 static struct mtd_info *h1910_nand_mtd = NULL;
40 * Module stuff
43 #ifdef CONFIG_MTD_PARTITIONS
45 * Define static partitions for flash device
47 static struct mtd_partition partition_info[] = {
48 { name: "h1910 NAND Flash",
49 offset: 0,
50 size: 16*1024*1024 }
52 #define NUM_PARTITIONS 1
54 #endif
57 /*
58 * hardware specific access to control-lines
60 static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
62 struct nand_chip* this = (struct nand_chip *) (mtd->priv);
64 switch(cmd) {
66 case NAND_CTL_SETCLE:
67 this->IO_ADDR_R |= (1 << 2);
68 this->IO_ADDR_W |= (1 << 2);
69 break;
70 case NAND_CTL_CLRCLE:
71 this->IO_ADDR_R &= ~(1 << 2);
72 this->IO_ADDR_W &= ~(1 << 2);
73 break;
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;
84 case NAND_CTL_SETNCE:
85 break;
86 case NAND_CTL_CLRNCE:
87 break;
92 * read device ready pin
94 #if 0
95 static int h1910_device_ready(struct mtd_info *mtd)
97 return (GPLR(55) & GPIO_bit(55));
99 #endif
102 * Main initialization routine
104 static int __init h1910_init (void)
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;
112 if (!machine_is_h1900())
113 return -ENODEV;
115 nandaddr = __ioremap(0x08000000, 0x1000, 0, 1);
116 if (!nandaddr) {
117 printk("Failed to ioremap nand flash.\n");
118 return -ENOMEM;
121 /* Allocate memory for MTD device structure and private data */
122 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) +
123 sizeof(struct nand_chip),
124 GFP_KERNEL);
125 if (!h1910_nand_mtd) {
126 printk("Unable to allocate h1910 NAND MTD device structure.\n");
127 iounmap ((void *) nandaddr);
128 return -ENOMEM;
131 /* Get pointer to private data */
132 this = (struct nand_chip *) (&h1910_nand_mtd[1]);
134 /* Initialize structures */
135 memset((char *) h1910_nand_mtd, 0, sizeof(struct mtd_info));
136 memset((char *) this, 0, sizeof(struct nand_chip));
138 /* Link the private data with the MTD structure */
139 h1910_nand_mtd->priv = this;
142 * Enable VPEN
144 GPSR(37) = GPIO_bit(37);
146 /* insert callbacks */
147 this->IO_ADDR_R = nandaddr;
148 this->IO_ADDR_W = nandaddr;
149 this->hwcontrol = h1910_hwcontrol;
150 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
151 /* 15 us command delay time */
152 this->chip_delay = 50;
153 this->eccmode = NAND_ECC_SOFT;
154 this->options = NAND_NO_AUTOINCR;
156 /* Scan to find existence of the device */
157 if (nand_scan (h1910_nand_mtd, 1)) {
158 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
159 kfree (h1910_nand_mtd);
160 iounmap ((void *) nandaddr);
161 return -ENXIO;
164 #ifdef CONFIG_MTD_CMDLINE_PARTS
165 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts,
166 "h1910-nand");
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)
174 mtd_parts = partition_info;
175 mtd_parts_nb = NUM_PARTITIONS;
176 part_type = "static";
179 /* Register the partitions */
180 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
181 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
183 /* Return happy */
184 return 0;
186 module_init(h1910_init);
189 * Clean up routine
191 static void __exit h1910_cleanup (void)
193 struct nand_chip *this = (struct nand_chip *) &h1910_nand_mtd[1];
195 /* Release resources, unregister device */
196 nand_release (h1910_nand_mtd);
198 /* Release io resource */
199 iounmap ((void *) this->IO_ADDR_W);
201 /* Free the MTD device structure */
202 kfree (h1910_nand_mtd);
204 module_exit(h1910_cleanup);
206 MODULE_LICENSE("GPL");
207 MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
208 MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");