Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/ppchameleonevb.c |
| 3 | * |
| 4 | * Copyright (C) 2003 DAVE Srl (info@wawnet.biz) |
| 5 | * |
| 6 | * Derived from drivers/mtd/nand/edb7312.c |
| 7 | * |
| 8 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 9 | * $Id: ppchameleonevb.c,v 1.7 2005/11/07 11:14:31 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * Overview: |
| 16 | * This is a device driver for the NAND flash devices found on the |
| 17 | * PPChameleon/PPChameleonEVB system. |
| 18 | * PPChameleon options (autodetected): |
| 19 | * - BA model: no NAND |
| 20 | * - ME model: 32MB (Samsung K9F5608U0B) |
| 21 | * - HI model: 128MB (Samsung K9F1G08UOM) |
| 22 | * PPChameleonEVB options: |
| 23 | * - 32MB (Samsung K9F5608U0B) |
| 24 | */ |
| 25 | |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/mtd/mtd.h> |
| 30 | #include <linux/mtd/nand.h> |
| 31 | #include <linux/mtd/partitions.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <platforms/PPChameleonEVB.h> |
| 34 | |
| 35 | #undef USE_READY_BUSY_PIN |
| 36 | #define USE_READY_BUSY_PIN |
| 37 | /* see datasheets (tR) */ |
| 38 | #define NAND_BIG_DELAY_US 25 |
| 39 | #define NAND_SMALL_DELAY_US 10 |
| 40 | |
| 41 | /* handy sizes */ |
| 42 | #define SZ_4M 0x00400000 |
| 43 | #define NAND_SMALL_SIZE 0x02000000 |
| 44 | #define NAND_MTD_NAME "ppchameleon-nand" |
| 45 | #define NAND_EVB_MTD_NAME "ppchameleonevb-nand" |
| 46 | |
| 47 | /* GPIO pins used to drive NAND chip mounted on processor module */ |
| 48 | #define NAND_nCE_GPIO_PIN (0x80000000 >> 1) |
| 49 | #define NAND_CLE_GPIO_PIN (0x80000000 >> 2) |
| 50 | #define NAND_ALE_GPIO_PIN (0x80000000 >> 3) |
| 51 | #define NAND_RB_GPIO_PIN (0x80000000 >> 4) |
| 52 | /* GPIO pins used to drive NAND chip mounted on EVB */ |
| 53 | #define NAND_EVB_nCE_GPIO_PIN (0x80000000 >> 14) |
| 54 | #define NAND_EVB_CLE_GPIO_PIN (0x80000000 >> 15) |
| 55 | #define NAND_EVB_ALE_GPIO_PIN (0x80000000 >> 16) |
| 56 | #define NAND_EVB_RB_GPIO_PIN (0x80000000 >> 31) |
| 57 | |
| 58 | /* |
| 59 | * MTD structure for PPChameleonEVB board |
| 60 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 61 | static struct mtd_info *ppchameleon_mtd = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static struct mtd_info *ppchameleonevb_mtd = NULL; |
| 63 | |
| 64 | /* |
| 65 | * Module stuff |
| 66 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 67 | static unsigned long ppchameleon_fio_pbase = CFG_NAND0_PADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | static unsigned long ppchameleonevb_fio_pbase = CFG_NAND1_PADDR; |
| 69 | |
| 70 | #ifdef MODULE |
| 71 | module_param(ppchameleon_fio_pbase, ulong, 0); |
| 72 | module_param(ppchameleonevb_fio_pbase, ulong, 0); |
| 73 | #else |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 74 | __setup("ppchameleon_fio_pbase=", ppchameleon_fio_pbase); |
| 75 | __setup("ppchameleonevb_fio_pbase=", ppchameleonevb_fio_pbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #endif |
| 77 | |
| 78 | #ifdef CONFIG_MTD_PARTITIONS |
| 79 | /* |
| 80 | * Define static partitions for flash devices |
| 81 | */ |
| 82 | static struct mtd_partition partition_info_hi[] = { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 83 | { .name = "PPChameleon HI Nand Flash", |
| 84 | offset = 0, |
| 85 | .size = 128 * 1024 * 1024 |
| 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static struct mtd_partition partition_info_me[] = { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 90 | { .name = "PPChameleon ME Nand Flash", |
| 91 | .offset = 0, |
| 92 | .size = 32 * 1024 * 1024 |
| 93 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | static struct mtd_partition partition_info_evb[] = { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 97 | { .name = "PPChameleonEVB Nand Flash", |
| 98 | .offset = 0, |
| 99 | .size = 32 * 1024 * 1024 |
| 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | #define NUM_PARTITIONS 1 |
| 104 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 105 | extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #endif |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /* |
| 109 | * hardware specific access to control-lines |
| 110 | */ |
| 111 | static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd) |
| 112 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 113 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | case NAND_CTL_SETCLE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 116 | MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND0_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | break; |
| 118 | case NAND_CTL_CLRCLE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 119 | MACRO_NAND_CTL_CLRCLE((unsigned long)CFG_NAND0_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | break; |
| 121 | case NAND_CTL_SETALE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 122 | MACRO_NAND_CTL_SETALE((unsigned long)CFG_NAND0_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | break; |
| 124 | case NAND_CTL_CLRALE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 125 | MACRO_NAND_CTL_CLRALE((unsigned long)CFG_NAND0_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | break; |
| 127 | case NAND_CTL_SETNCE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 128 | MACRO_NAND_ENABLE_CE((unsigned long)CFG_NAND0_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | break; |
| 130 | case NAND_CTL_CLRNCE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 131 | MACRO_NAND_DISABLE_CE((unsigned long)CFG_NAND0_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | break; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd) |
| 137 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 138 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | case NAND_CTL_SETCLE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 141 | MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND1_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | break; |
| 143 | case NAND_CTL_CLRCLE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 144 | MACRO_NAND_CTL_CLRCLE((unsigned long)CFG_NAND1_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | break; |
| 146 | case NAND_CTL_SETALE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 147 | MACRO_NAND_CTL_SETALE((unsigned long)CFG_NAND1_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | break; |
| 149 | case NAND_CTL_CLRALE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 150 | MACRO_NAND_CTL_CLRALE((unsigned long)CFG_NAND1_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | break; |
| 152 | case NAND_CTL_SETNCE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 153 | MACRO_NAND_ENABLE_CE((unsigned long)CFG_NAND1_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | break; |
| 155 | case NAND_CTL_CLRNCE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 156 | MACRO_NAND_DISABLE_CE((unsigned long)CFG_NAND1_PADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | #ifdef USE_READY_BUSY_PIN |
| 162 | /* |
| 163 | * read device ready pin |
| 164 | */ |
| 165 | static int ppchameleon_device_ready(struct mtd_info *minfo) |
| 166 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 167 | if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_RB_GPIO_PIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return 1; |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int ppchameleonevb_device_ready(struct mtd_info *minfo) |
| 173 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 174 | if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_EVB_RB_GPIO_PIN) |
| 175 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | #endif |
| 179 | |
| 180 | #ifdef CONFIG_MTD_PARTITIONS |
| 181 | const char *part_probes[] = { "cmdlinepart", NULL }; |
| 182 | const char *part_probes_evb[] = { "cmdlinepart", NULL }; |
| 183 | #endif |
| 184 | |
| 185 | /* |
| 186 | * Main initialization routine |
| 187 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 188 | static int __init ppchameleonevb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | struct nand_chip *this; |
| 191 | const char *part_type = 0; |
| 192 | int mtd_parts_nb = 0; |
| 193 | struct mtd_partition *mtd_parts = 0; |
| 194 | void __iomem *ppchameleon_fio_base; |
| 195 | void __iomem *ppchameleonevb_fio_base; |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /********************************* |
| 198 | * Processor module NAND (if any) * |
| 199 | *********************************/ |
| 200 | /* Allocate memory for MTD device structure and private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 201 | ppchameleon_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | if (!ppchameleon_mtd) { |
| 203 | printk("Unable to allocate PPChameleon NAND MTD device structure.\n"); |
| 204 | return -ENOMEM; |
| 205 | } |
| 206 | |
| 207 | /* map physical address */ |
| 208 | ppchameleon_fio_base = ioremap(ppchameleon_fio_pbase, SZ_4M); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 209 | if (!ppchameleon_fio_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | printk("ioremap PPChameleon NAND flash failed\n"); |
| 211 | kfree(ppchameleon_mtd); |
| 212 | return -EIO; |
| 213 | } |
| 214 | |
| 215 | /* Get pointer to private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 216 | this = (struct nand_chip *)(&ppchameleon_mtd[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | /* Initialize structures */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 219 | memset(ppchameleon_mtd, 0, sizeof(struct mtd_info)); |
| 220 | memset(this, 0, sizeof(struct nand_chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* Link the private data with the MTD structure */ |
| 223 | ppchameleon_mtd->priv = this; |
| 224 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 225 | /* Initialize GPIOs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | /* Pin mapping for NAND chip */ |
| 227 | /* |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 228 | CE GPIO_01 |
| 229 | CLE GPIO_02 |
| 230 | ALE GPIO_03 |
| 231 | R/B GPIO_04 |
| 232 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* output select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 234 | out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xC0FFFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* three-state select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 236 | out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xC0FFFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* enable output driver */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 238 | out_be32((volatile unsigned *)GPIO0_TCR, |
| 239 | in_be32((volatile unsigned *)GPIO0_TCR) | NAND_nCE_GPIO_PIN | NAND_CLE_GPIO_PIN | NAND_ALE_GPIO_PIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | #ifdef USE_READY_BUSY_PIN |
| 241 | /* three-state select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 242 | out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFF3FFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* high-impedecence */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 244 | out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_RB_GPIO_PIN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /* input select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 246 | out_be32((volatile unsigned *)GPIO0_ISR1H, |
| 247 | (in_be32((volatile unsigned *)GPIO0_ISR1H) & 0xFF3FFFFF) | 0x00400000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | #endif |
| 249 | |
| 250 | /* insert callbacks */ |
| 251 | this->IO_ADDR_R = ppchameleon_fio_base; |
| 252 | this->IO_ADDR_W = ppchameleon_fio_base; |
| 253 | this->hwcontrol = ppchameleon_hwcontrol; |
| 254 | #ifdef USE_READY_BUSY_PIN |
| 255 | this->dev_ready = ppchameleon_device_ready; |
| 256 | #endif |
| 257 | this->chip_delay = NAND_BIG_DELAY_US; |
| 258 | /* ECC mode */ |
| 259 | this->eccmode = NAND_ECC_SOFT; |
| 260 | |
| 261 | /* Scan to find existence of the device (it could not be mounted) */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 262 | if (nand_scan(ppchameleon_mtd, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | iounmap((void *)ppchameleon_fio_base); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 264 | kfree(ppchameleon_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | goto nand_evb_init; |
| 266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | #ifndef USE_READY_BUSY_PIN |
| 268 | /* Adjust delay if necessary */ |
| 269 | if (ppchameleon_mtd->size == NAND_SMALL_SIZE) |
| 270 | this->chip_delay = NAND_SMALL_DELAY_US; |
| 271 | #endif |
| 272 | |
| 273 | #ifdef CONFIG_MTD_PARTITIONS |
| 274 | ppchameleon_mtd->name = "ppchameleon-nand"; |
| 275 | mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0); |
| 276 | if (mtd_parts_nb > 0) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 277 | part_type = "command line"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | else |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 279 | mtd_parts_nb = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | #endif |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 281 | if (mtd_parts_nb == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (ppchameleon_mtd->size == NAND_SMALL_SIZE) |
| 283 | mtd_parts = partition_info_me; |
| 284 | else |
| 285 | mtd_parts = partition_info_hi; |
| 286 | mtd_parts_nb = NUM_PARTITIONS; |
| 287 | part_type = "static"; |
| 288 | } |
| 289 | |
| 290 | /* Register the partitions */ |
| 291 | printk(KERN_NOTICE "Using %s partition definition\n", part_type); |
| 292 | add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb); |
| 293 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 294 | nand_evb_init: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | /**************************** |
| 296 | * EVB NAND (always present) * |
| 297 | ****************************/ |
| 298 | /* Allocate memory for MTD device structure and private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 299 | ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | if (!ppchameleonevb_mtd) { |
| 301 | printk("Unable to allocate PPChameleonEVB NAND MTD device structure.\n"); |
| 302 | return -ENOMEM; |
| 303 | } |
| 304 | |
| 305 | /* map physical address */ |
| 306 | ppchameleonevb_fio_base = ioremap(ppchameleonevb_fio_pbase, SZ_4M); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 307 | if (!ppchameleonevb_fio_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | printk("ioremap PPChameleonEVB NAND flash failed\n"); |
| 309 | kfree(ppchameleonevb_mtd); |
| 310 | return -EIO; |
| 311 | } |
| 312 | |
| 313 | /* Get pointer to private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 314 | this = (struct nand_chip *)(&ppchameleonevb_mtd[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | /* Initialize structures */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 317 | memset(ppchameleonevb_mtd, 0, sizeof(struct mtd_info)); |
| 318 | memset(this, 0, sizeof(struct nand_chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /* Link the private data with the MTD structure */ |
| 321 | ppchameleonevb_mtd->priv = this; |
| 322 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 323 | /* Initialize GPIOs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* Pin mapping for NAND chip */ |
| 325 | /* |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 326 | CE GPIO_14 |
| 327 | CLE GPIO_15 |
| 328 | ALE GPIO_16 |
| 329 | R/B GPIO_31 |
| 330 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* output select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 332 | out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xFFFFFFF0); |
| 333 | out_be32((volatile unsigned *)GPIO0_OSRL, in_be32((volatile unsigned *)GPIO0_OSRL) & 0x3FFFFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* three-state select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 335 | out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFFFFFFF0); |
| 336 | out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0x3FFFFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* enable output driver */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 338 | out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN); |
| 340 | #ifdef USE_READY_BUSY_PIN |
| 341 | /* three-state select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 342 | out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0xFFFFFFFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* high-impedecence */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 344 | out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_EVB_RB_GPIO_PIN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | /* input select */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 346 | out_be32((volatile unsigned *)GPIO0_ISR1L, |
| 347 | (in_be32((volatile unsigned *)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | #endif |
| 349 | |
| 350 | /* insert callbacks */ |
| 351 | this->IO_ADDR_R = ppchameleonevb_fio_base; |
| 352 | this->IO_ADDR_W = ppchameleonevb_fio_base; |
| 353 | this->hwcontrol = ppchameleonevb_hwcontrol; |
| 354 | #ifdef USE_READY_BUSY_PIN |
| 355 | this->dev_ready = ppchameleonevb_device_ready; |
| 356 | #endif |
| 357 | this->chip_delay = NAND_SMALL_DELAY_US; |
| 358 | |
| 359 | /* ECC mode */ |
| 360 | this->eccmode = NAND_ECC_SOFT; |
| 361 | |
| 362 | /* Scan to find existence of the device */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 363 | if (nand_scan(ppchameleonevb_mtd, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | iounmap((void *)ppchameleonevb_fio_base); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 365 | kfree(ppchameleonevb_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return -ENXIO; |
| 367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | #ifdef CONFIG_MTD_PARTITIONS |
| 369 | ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME; |
| 370 | mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0); |
| 371 | if (mtd_parts_nb > 0) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 372 | part_type = "command line"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | else |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 374 | mtd_parts_nb = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | #endif |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 376 | if (mtd_parts_nb == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | mtd_parts = partition_info_evb; |
| 378 | mtd_parts_nb = NUM_PARTITIONS; |
| 379 | part_type = "static"; |
| 380 | } |
| 381 | |
| 382 | /* Register the partitions */ |
| 383 | printk(KERN_NOTICE "Using %s partition definition\n", part_type); |
| 384 | add_mtd_partitions(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb); |
| 385 | |
| 386 | /* Return happy */ |
| 387 | return 0; |
| 388 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | module_init(ppchameleonevb_init); |
| 391 | |
| 392 | /* |
| 393 | * Clean up routine |
| 394 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 395 | static void __exit ppchameleonevb_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
| 397 | struct nand_chip *this; |
| 398 | |
| 399 | /* Release resources, unregister device(s) */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame^] | 400 | nand_release(ppchameleon_mtd); |
| 401 | nand_release(ppchameleonevb_mtd); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | /* Release iomaps */ |
| 404 | this = (struct nand_chip *) &ppchameleon_mtd[1]; |
| 405 | iounmap((void *) this->IO_ADDR_R; |
| 406 | this = (struct nand_chip *) &ppchameleonevb_mtd[1]; |
| 407 | iounmap((void *) this->IO_ADDR_R; |
| 408 | |
| 409 | /* Free the MTD device structure */ |
| 410 | kfree (ppchameleon_mtd); |
| 411 | kfree (ppchameleonevb_mtd); |
| 412 | } |
| 413 | module_exit(ppchameleonevb_cleanup); |
| 414 | |
| 415 | MODULE_LICENSE("GPL"); |
| 416 | MODULE_AUTHOR("DAVE Srl <support-ppchameleon@dave-tech.it>"); |
| 417 | MODULE_DESCRIPTION("MTD map driver for DAVE Srl PPChameleonEVB board"); |