Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/sharpsl.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Richard Purdie |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 5 | * Copyright (C) 2008 Dmitry Baryshkov |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Based on Sharp's NAND driver sharp_sl.c |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/genhd.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/mtd/mtd.h> |
| 20 | #include <linux/mtd/nand.h> |
| 21 | #include <linux/mtd/nand_ecc.h> |
| 22 | #include <linux/mtd/partitions.h> |
| 23 | #include <linux/interrupt.h> |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/io.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
| 29 | |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 30 | struct sharpsl_nand { |
| 31 | struct mtd_info mtd; |
| 32 | struct nand_chip chip; |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 33 | |
| 34 | void __iomem *io; |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 35 | }; |
| 36 | |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 37 | #define mtd_to_sharpsl(_mtd) container_of(_mtd, struct sharpsl_nand, mtd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* register offset */ |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 40 | #define ECCLPLB 0x00 /* line parity 7 - 0 bit */ |
| 41 | #define ECCLPUB 0x04 /* line parity 15 - 8 bit */ |
| 42 | #define ECCCP 0x08 /* column parity 5 - 0 bit */ |
| 43 | #define ECCCNTR 0x0C /* ECC byte counter */ |
| 44 | #define ECCCLRR 0x10 /* cleare ECC */ |
| 45 | #define FLASHIO 0x14 /* Flash I/O */ |
| 46 | #define FLASHCTL 0x18 /* Flash Control */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | /* Flash control bit */ |
| 49 | #define FLRYBY (1 << 5) |
| 50 | #define FLCE1 (1 << 4) |
| 51 | #define FLWP (1 << 3) |
| 52 | #define FLALE (1 << 2) |
| 53 | #define FLCLE (1 << 1) |
| 54 | #define FLCE0 (1 << 0) |
| 55 | |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 56 | #ifdef CONFIG_MTD_PARTITIONS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | * Define partitions for flash device |
| 59 | */ |
| 60 | #define DEFAULT_NUM_PARTITIONS 3 |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static struct mtd_partition sharpsl_nand_default_partition_info[] = { |
| 63 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 64 | .name = "System Area", |
| 65 | .offset = 0, |
| 66 | .size = 7 * 1024 * 1024, |
| 67 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 69 | .name = "Root Filesystem", |
| 70 | .offset = 7 * 1024 * 1024, |
| 71 | .size = 30 * 1024 * 1024, |
| 72 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 74 | .name = "Home Filesystem", |
| 75 | .offset = MTDPART_OFS_APPEND, |
| 76 | .size = MTDPART_SIZ_FULL, |
| 77 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }; |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 79 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 81 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * hardware specific access to control-lines |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 83 | * ctrl: |
Richard Purdie | 6a5a297c | 2006-07-15 13:05:24 +0100 | [diff] [blame] | 84 | * NAND_CNE: bit 0 -> ! bit 0 & 4 |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 85 | * NAND_CLE: bit 1 -> bit 1 |
| 86 | * NAND_ALE: bit 2 -> bit 2 |
| 87 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | */ |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 89 | static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, |
| 90 | unsigned int ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 92 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 93 | struct nand_chip *chip = mtd->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 95 | if (ctrl & NAND_CTRL_CHANGE) { |
| 96 | unsigned char bits = ctrl & 0x07; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 98 | bits |= (ctrl & 0x01) << 4; |
Richard Purdie | 6a5a297c | 2006-07-15 13:05:24 +0100 | [diff] [blame] | 99 | |
| 100 | bits ^= 0x11; |
| 101 | |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 102 | writeb((readb(sharpsl->io + FLASHCTL) & ~0x17) | bits, sharpsl->io + FLASHCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 104 | |
| 105 | if (cmd != NAND_CMD_NONE) |
| 106 | writeb(cmd, chip->IO_ADDR_W); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; |
| 110 | |
| 111 | static struct nand_bbt_descr sharpsl_bbt = { |
| 112 | .options = 0, |
| 113 | .offs = 4, |
| 114 | .len = 2, |
| 115 | .pattern = scan_ff_pattern |
| 116 | }; |
| 117 | |
Richard Purdie | 87c146d | 2005-11-03 11:36:45 +0000 | [diff] [blame] | 118 | static struct nand_bbt_descr sharpsl_akita_bbt = { |
| 119 | .options = 0, |
| 120 | .offs = 4, |
| 121 | .len = 1, |
| 122 | .pattern = scan_ff_pattern |
| 123 | }; |
| 124 | |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 125 | static struct nand_ecclayout akita_oobinfo = { |
Richard Purdie | 87c146d | 2005-11-03 11:36:45 +0000 | [diff] [blame] | 126 | .eccbytes = 24, |
| 127 | .eccpos = { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 128 | 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, |
| 129 | 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, |
| 130 | 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, |
| 131 | .oobfree = {{0x08, 0x09}} |
Richard Purdie | 87c146d | 2005-11-03 11:36:45 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 134 | static int sharpsl_nand_dev_ready(struct mtd_info *mtd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 136 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
| 137 | return !((readb(sharpsl->io + FLASHCTL) & FLRYBY) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 140 | static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 142 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
| 143 | writeb(0, sharpsl->io + ECCCLRR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 146 | static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 148 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
| 149 | ecc_code[0] = ~readb(sharpsl->io + ECCLPUB); |
| 150 | ecc_code[1] = ~readb(sharpsl->io + ECCLPLB); |
| 151 | ecc_code[2] = (~readb(sharpsl->io + ECCCP) << 2) | 0x03; |
| 152 | return readb(sharpsl->io + ECCCNTR) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | #ifdef CONFIG_MTD_PARTITIONS |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 156 | static const char *part_probes[] = { "cmdlinepart", NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #endif |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* |
| 160 | * Main initialization routine |
| 161 | */ |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 162 | static int __devinit sharpsl_nand_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
| 164 | struct nand_chip *this; |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 165 | #ifdef CONFIG_MTD_PARTITIONS |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 166 | struct mtd_partition *sharpsl_partition_info; |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 167 | int nr_partitions; |
| 168 | #endif |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 169 | struct resource *r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | int err = 0; |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 171 | struct sharpsl_nand *sharpsl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* Allocate memory for MTD device structure and private data */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 174 | sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL); |
| 175 | if (!sharpsl) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 176 | printk("Unable to allocate SharpSL NAND MTD device structure.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return -ENOMEM; |
| 178 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 179 | |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 180 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 181 | if (!r) { |
| 182 | dev_err(&pdev->dev, "no io memory resource defined!\n"); |
| 183 | err = -ENODEV; |
| 184 | goto err_get_res; |
| 185 | } |
| 186 | |
Joe Perches | 8e87d78 | 2008-02-03 17:22:34 +0200 | [diff] [blame] | 187 | /* map physical address */ |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 188 | sharpsl->io = ioremap(r->start, resource_size(r)); |
| 189 | if (!sharpsl->io) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | printk("ioremap to access Sharp SL NAND chip failed\n"); |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 191 | err = -EIO; |
| 192 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | /* Get pointer to private data */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 196 | this = (struct nand_chip *)(&sharpsl->chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | /* Link the private data with the MTD structure */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 199 | sharpsl->mtd.priv = this; |
| 200 | sharpsl->mtd.owner = THIS_MODULE; |
| 201 | |
| 202 | platform_set_drvdata(pdev, sharpsl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * PXA initialize |
| 206 | */ |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 207 | writeb(readb(sharpsl->io + FLASHCTL) | FLWP, sharpsl->io + FLASHCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* Set address of NAND IO lines */ |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 210 | this->IO_ADDR_R = sharpsl->io + FLASHIO; |
| 211 | this->IO_ADDR_W = sharpsl->io + FLASHIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* Set address of hardware control function */ |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 213 | this->cmd_ctrl = sharpsl_nand_hwcontrol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | this->dev_ready = sharpsl_nand_dev_ready; |
| 215 | /* 15 us command delay time */ |
| 216 | this->chip_delay = 15; |
| 217 | /* set eccmode using hardware ECC */ |
Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame] | 218 | this->ecc.mode = NAND_ECC_HW; |
| 219 | this->ecc.size = 256; |
| 220 | this->ecc.bytes = 3; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 221 | this->badblock_pattern = &sharpsl_bbt; |
Richard Purdie | 87c146d | 2005-11-03 11:36:45 +0000 | [diff] [blame] | 222 | if (machine_is_akita() || machine_is_borzoi()) { |
| 223 | this->badblock_pattern = &sharpsl_akita_bbt; |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 224 | this->ecc.layout = &akita_oobinfo; |
Richard Purdie | 87c146d | 2005-11-03 11:36:45 +0000 | [diff] [blame] | 225 | } |
Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame] | 226 | this->ecc.hwctl = sharpsl_nand_enable_hwecc; |
| 227 | this->ecc.calculate = sharpsl_nand_calculate_ecc; |
| 228 | this->ecc.correct = nand_correct_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | /* Scan to find existence of the device */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 231 | err = nand_scan(&sharpsl->mtd, 1); |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 232 | if (err) |
| 233 | goto err_scan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | /* Register the partitions */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 236 | sharpsl->mtd.name = "sharpsl-nand"; |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 237 | #ifdef CONFIG_MTD_PARTITIONS |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 238 | nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | if (nr_partitions <= 0) { |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 241 | nr_partitions = ARRAY_SIZE(sharpsl_nand_default_partition_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | sharpsl_partition_info = sharpsl_nand_default_partition_info; |
| 243 | if (machine_is_poodle()) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 244 | sharpsl_partition_info[1].size = 22 * 1024 * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } else if (machine_is_corgi() || machine_is_shepherd()) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 246 | sharpsl_partition_info[1].size = 25 * 1024 * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } else if (machine_is_husky()) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 248 | sharpsl_partition_info[1].size = 53 * 1024 * 1024; |
Richard Purdie | 62052d4 | 2005-09-16 19:27:31 -0700 | [diff] [blame] | 249 | } else if (machine_is_spitz()) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 250 | sharpsl_partition_info[1].size = 5 * 1024 * 1024; |
Richard Purdie | 62052d4 | 2005-09-16 19:27:31 -0700 | [diff] [blame] | 251 | } else if (machine_is_akita()) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 252 | sharpsl_partition_info[1].size = 58 * 1024 * 1024; |
Richard Purdie | 62052d4 | 2005-09-16 19:27:31 -0700 | [diff] [blame] | 253 | } else if (machine_is_borzoi()) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 254 | sharpsl_partition_info[1].size = 32 * 1024 * 1024; |
Richard Purdie | 62052d4 | 2005-09-16 19:27:31 -0700 | [diff] [blame] | 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 258 | err = add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions); |
| 259 | #else |
| 260 | err = add_mtd_device(&sharpsl->mtd); |
| 261 | #endif |
| 262 | if (err) |
| 263 | goto err_add; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
| 265 | /* Return happy */ |
| 266 | return 0; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 267 | |
Dmitry Baryshkov | c176d0c | 2008-10-16 18:22:28 +0400 | [diff] [blame^] | 268 | err_add: |
| 269 | nand_release(&sharpsl->mtd); |
| 270 | |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 271 | err_scan: |
| 272 | platform_set_drvdata(pdev, NULL); |
| 273 | iounmap(sharpsl->io); |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 274 | err_ioremap: |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 275 | err_get_res: |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 276 | kfree(sharpsl); |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 277 | return err; |
| 278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * Clean up routine |
| 282 | */ |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 283 | static int __devexit sharpsl_nand_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 285 | struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev); |
| 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | /* Release resources, unregister device */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 288 | nand_release(&sharpsl->mtd); |
| 289 | |
| 290 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Dmitry Baryshkov | a4e4f29 | 2008-10-16 17:58:18 +0400 | [diff] [blame] | 292 | iounmap(sharpsl->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
| 294 | /* Free the MTD device structure */ |
Dmitry Baryshkov | 2206ef1 | 2008-10-16 17:49:06 +0400 | [diff] [blame] | 295 | kfree(sharpsl); |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 296 | |
| 297 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 299 | |
Dmitry Baryshkov | 2661524 | 2008-10-16 12:08:14 +0400 | [diff] [blame] | 300 | static struct platform_driver sharpsl_nand_driver = { |
| 301 | .driver = { |
| 302 | .name = "sharpsl-nand", |
| 303 | .owner = THIS_MODULE, |
| 304 | }, |
| 305 | .probe = sharpsl_nand_probe, |
| 306 | .remove = __devexit_p(sharpsl_nand_remove), |
| 307 | }; |
| 308 | |
| 309 | static struct resource sharpsl_nand_resources[] = { |
| 310 | { |
| 311 | .start = 0x0C000000, |
| 312 | .end = 0x0C000FFF, |
| 313 | .flags = IORESOURCE_MEM, |
| 314 | }, |
| 315 | }; |
| 316 | |
| 317 | static struct platform_device sharpsl_nand_device = { |
| 318 | .name = "sharpsl-nand", |
| 319 | .id = -1, |
| 320 | .resource = sharpsl_nand_resources, |
| 321 | .num_resources = ARRAY_SIZE(sharpsl_nand_resources), |
| 322 | }; |
| 323 | |
| 324 | static int __init sharpsl_nand_init(void) |
| 325 | { |
| 326 | platform_device_register(&sharpsl_nand_device); |
| 327 | return platform_driver_register(&sharpsl_nand_driver); |
| 328 | } |
| 329 | module_init(sharpsl_nand_init); |
| 330 | |
| 331 | static void __exit sharpsl_nand_exit(void) |
| 332 | { |
| 333 | platform_driver_unregister(&sharpsl_nand_driver); |
| 334 | platform_device_unregister(&sharpsl_nand_device); |
| 335 | } |
| 336 | module_exit(sharpsl_nand_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | MODULE_LICENSE("GPL"); |
| 339 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |
| 340 | MODULE_DESCRIPTION("Device specific logic for NAND flash on Sharp SL-C7xx Series"); |