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