mmc: block: fixed NULL pointer dereference
[linux-2.6.git] / drivers / mtd / nand / h1910.c
blob02a03e67109c90ce2534757b4053ada8e8469956
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 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * Overview:
15 * This is a device driver for the NAND flash device found on the
16 * iPAQ h1910 board which utilizes the Samsung K9F2808 part. This is
17 * a 128Mibit (16MiB x 8 bits) NAND flash device.
20 #include <linux/slab.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/nand.h>
25 #include <linux/mtd/partitions.h>
26 #include <asm/io.h>
27 #include <mach/hardware.h> /* for CLPS7111_VIRT_BASE */
28 #include <asm/sizes.h>
29 #include <mach/h1900-gpio.h>
30 #include <mach/ipaq.h>
33 * MTD structure for EDB7312 board
35 static struct mtd_info *h1910_nand_mtd = NULL;
38 * Module stuff
42 * Define static partitions for flash device
44 static struct mtd_partition partition_info[] = {
45 {name:"h1910 NAND Flash",
46 offset:0,
47 size:16 * 1024 * 1024}
50 #define NUM_PARTITIONS 1
53 * hardware specific access to control-lines
55 * NAND_NCE: bit 0 - don't care
56 * NAND_CLE: bit 1 - address bit 2
57 * NAND_ALE: bit 2 - address bit 3
59 static void h1910_hwcontrol(struct mtd_info *mtd, int cmd,
60 unsigned int ctrl)
62 struct nand_chip *chip = mtd->priv;
64 if (cmd != NAND_CMD_NONE)
65 writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1));
69 * read device ready pin
71 #if 0
72 static int h1910_device_ready(struct mtd_info *mtd)
74 return (GPLR(55) & GPIO_bit(55));
76 #endif
79 * Main initialization routine
81 static int __init h1910_init(void)
83 struct nand_chip *this;
84 const char *part_type = 0;
85 int mtd_parts_nb = 0;
86 struct mtd_partition *mtd_parts = 0;
87 void __iomem *nandaddr;
89 if (!machine_is_h1900())
90 return -ENODEV;
92 nandaddr = ioremap(0x08000000, 0x1000);
93 if (!nandaddr) {
94 printk("Failed to ioremap nand flash.\n");
95 return -ENOMEM;
98 /* Allocate memory for MTD device structure and private data */
99 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
100 if (!h1910_nand_mtd) {
101 printk("Unable to allocate h1910 NAND MTD device structure.\n");
102 iounmap((void *)nandaddr);
103 return -ENOMEM;
106 /* Get pointer to private data */
107 this = (struct nand_chip *)(&h1910_nand_mtd[1]);
109 /* Initialize structures */
110 memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
111 memset(this, 0, sizeof(struct nand_chip));
113 /* Link the private data with the MTD structure */
114 h1910_nand_mtd->priv = this;
115 h1910_nand_mtd->owner = THIS_MODULE;
118 * Enable VPEN
120 GPSR(37) = GPIO_bit(37);
122 /* insert callbacks */
123 this->IO_ADDR_R = nandaddr;
124 this->IO_ADDR_W = nandaddr;
125 this->cmd_ctrl = h1910_hwcontrol;
126 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
127 /* 15 us command delay time */
128 this->chip_delay = 50;
129 this->ecc.mode = NAND_ECC_SOFT;
130 this->options = NAND_NO_AUTOINCR;
132 /* Scan to find existence of the device */
133 if (nand_scan(h1910_nand_mtd, 1)) {
134 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
135 kfree(h1910_nand_mtd);
136 iounmap((void *)nandaddr);
137 return -ENXIO;
139 #ifdef CONFIG_MTD_CMDLINE_PARTS
140 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
141 if (mtd_parts_nb > 0)
142 part_type = "command line";
143 else
144 mtd_parts_nb = 0;
145 #endif
146 if (mtd_parts_nb == 0) {
147 mtd_parts = partition_info;
148 mtd_parts_nb = NUM_PARTITIONS;
149 part_type = "static";
152 /* Register the partitions */
153 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
154 mtd_device_register(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
156 /* Return happy */
157 return 0;
160 module_init(h1910_init);
163 * Clean up routine
165 static void __exit h1910_cleanup(void)
167 struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
169 /* Release resources, unregister device */
170 nand_release(h1910_nand_mtd);
172 /* Release io resource */
173 iounmap((void *)this->IO_ADDR_W);
175 /* Free the MTD device structure */
176 kfree(h1910_nand_mtd);
179 module_exit(h1910_cleanup);
181 MODULE_LICENSE("GPL");
182 MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
183 MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");