Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[deliverable/linux.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 *
1da177e4
LT
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.
13 *
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.
18 */
19
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>
304b2c68 27#include <mach/hardware.h>
1da177e4 28#include <asm/sizes.h>
a09e64fb
RK
29#include <mach/h1900-gpio.h>
30#include <mach/ipaq.h>
1da177e4
LT
31
32/*
33 * MTD structure for EDB7312 board
34 */
35static struct mtd_info *h1910_nand_mtd = NULL;
36
37/*
38 * Module stuff
39 */
40
1da177e4
LT
41/*
42 * Define static partitions for flash device
43 */
44static struct mtd_partition partition_info[] = {
e0c7d767
DW
45 {name:"h1910 NAND Flash",
46 offset:0,
47 size:16 * 1024 * 1024}
1da177e4 48};
e0c7d767 49
1da177e4
LT
50#define NUM_PARTITIONS 1
51
61b03bd7 52/*
1da177e4 53 * hardware specific access to control-lines
7abd3ef9
TG
54 *
55 * NAND_NCE: bit 0 - don't care
56 * NAND_CLE: bit 1 - address bit 2
57 * NAND_ALE: bit 2 - address bit 3
1da177e4 58 */
7abd3ef9
TG
59static void h1910_hwcontrol(struct mtd_info *mtd, int cmd,
60 unsigned int ctrl)
1da177e4 61{
7abd3ef9
TG
62 struct nand_chip *chip = mtd->priv;
63
64 if (cmd != NAND_CMD_NONE)
65 writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1));
1da177e4
LT
66}
67
68/*
69 * read device ready pin
70 */
71#if 0
72static int h1910_device_ready(struct mtd_info *mtd)
73{
74 return (GPLR(55) & GPIO_bit(55));
75}
76#endif
77
78/*
79 * Main initialization routine
80 */
e0c7d767 81static int __init h1910_init(void)
1da177e4
LT
82{
83 struct nand_chip *this;
1da177e4 84 void __iomem *nandaddr;
61b03bd7 85
1da177e4
LT
86 if (!machine_is_h1900())
87 return -ENODEV;
61b03bd7 88
0c2e4b4f 89 nandaddr = ioremap(0x08000000, 0x1000);
1da177e4
LT
90 if (!nandaddr) {
91 printk("Failed to ioremap nand flash.\n");
92 return -ENOMEM;
93 }
61b03bd7 94
1da177e4 95 /* Allocate memory for MTD device structure and private data */
e0c7d767 96 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
1da177e4
LT
97 if (!h1910_nand_mtd) {
98 printk("Unable to allocate h1910 NAND MTD device structure.\n");
e0c7d767 99 iounmap((void *)nandaddr);
1da177e4
LT
100 return -ENOMEM;
101 }
61b03bd7 102
1da177e4 103 /* Get pointer to private data */
e0c7d767 104 this = (struct nand_chip *)(&h1910_nand_mtd[1]);
61b03bd7 105
1da177e4 106 /* Initialize structures */
e0c7d767
DW
107 memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
108 memset(this, 0, sizeof(struct nand_chip));
61b03bd7 109
1da177e4
LT
110 /* Link the private data with the MTD structure */
111 h1910_nand_mtd->priv = this;
552d9205 112 h1910_nand_mtd->owner = THIS_MODULE;
61b03bd7 113
1da177e4
LT
114 /*
115 * Enable VPEN
116 */
117 GPSR(37) = GPIO_bit(37);
61b03bd7 118
1da177e4
LT
119 /* insert callbacks */
120 this->IO_ADDR_R = nandaddr;
121 this->IO_ADDR_W = nandaddr;
7abd3ef9 122 this->cmd_ctrl = h1910_hwcontrol;
1da177e4
LT
123 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
124 /* 15 us command delay time */
125 this->chip_delay = 50;
6dfc6d25 126 this->ecc.mode = NAND_ECC_SOFT;
61b03bd7 127
1da177e4 128 /* Scan to find existence of the device */
e0c7d767 129 if (nand_scan(h1910_nand_mtd, 1)) {
1da177e4 130 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
e0c7d767
DW
131 kfree(h1910_nand_mtd);
132 iounmap((void *)nandaddr);
1da177e4
LT
133 return -ENXIO;
134 }
61b03bd7 135
1da177e4 136 /* Register the partitions */
42d7fbe2
AB
137 mtd_device_parse_register(h1910_nand_mtd, NULL, NULL, partition_info,
138 NUM_PARTITIONS);
61b03bd7 139
1da177e4
LT
140 /* Return happy */
141 return 0;
142}
e0c7d767 143
1da177e4
LT
144module_init(h1910_init);
145
146/*
147 * Clean up routine
148 */
e0c7d767 149static void __exit h1910_cleanup(void)
1da177e4 150{
e0c7d767 151 struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
61b03bd7 152
1da177e4 153 /* Release resources, unregister device */
e0c7d767 154 nand_release(h1910_nand_mtd);
1da177e4
LT
155
156 /* Release io resource */
e0c7d767 157 iounmap((void *)this->IO_ADDR_W);
1da177e4
LT
158
159 /* Free the MTD device structure */
e0c7d767 160 kfree(h1910_nand_mtd);
1da177e4 161}
e0c7d767 162
1da177e4
LT
163module_exit(h1910_cleanup);
164
165MODULE_LICENSE("GPL");
166MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
167MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");
This page took 0.609081 seconds and 5 git commands to generate.