diff options
Diffstat (limited to 'drivers/mtd/nand/sharpsl.c')
-rw-r--r-- | drivers/mtd/nand/sharpsl.c | 247 |
1 files changed, 125 insertions, 122 deletions
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c index 54ec7542a7b7..30a518e211bd 100644 --- a/drivers/mtd/nand/sharpsl.c +++ b/drivers/mtd/nand/sharpsl.c @@ -2,7 +2,6 @@ * drivers/mtd/nand/sharpsl.c * * Copyright (C) 2004 Richard Purdie - * Copyright (C) 2008 Dmitry Baryshkov * * Based on Sharp's NAND driver sharp_sl.c * @@ -20,31 +19,22 @@ #include <linux/mtd/nand.h> #include <linux/mtd/nand_ecc.h> #include <linux/mtd/partitions.h> -#include <linux/mtd/sharpsl.h> #include <linux/interrupt.h> -#include <linux/platform_device.h> - #include <asm/io.h> #include <mach/hardware.h> #include <asm/mach-types.h> -struct sharpsl_nand { - struct mtd_info mtd; - struct nand_chip chip; - - void __iomem *io; -}; - -#define mtd_to_sharpsl(_mtd) container_of(_mtd, struct sharpsl_nand, mtd) +static void __iomem *sharpsl_io_base; +static int sharpsl_phys_base = 0x0C000000; /* register offset */ -#define ECCLPLB 0x00 /* line parity 7 - 0 bit */ -#define ECCLPUB 0x04 /* line parity 15 - 8 bit */ -#define ECCCP 0x08 /* column parity 5 - 0 bit */ -#define ECCCNTR 0x0C /* ECC byte counter */ -#define ECCCLRR 0x10 /* cleare ECC */ -#define FLASHIO 0x14 /* Flash I/O */ -#define FLASHCTL 0x18 /* Flash Control */ +#define ECCLPLB sharpsl_io_base+0x00 /* line parity 7 - 0 bit */ +#define ECCLPUB sharpsl_io_base+0x04 /* line parity 15 - 8 bit */ +#define ECCCP sharpsl_io_base+0x08 /* column parity 5 - 0 bit */ +#define ECCCNTR sharpsl_io_base+0x0C /* ECC byte counter */ +#define ECCCLRR sharpsl_io_base+0x10 /* cleare ECC */ +#define FLASHIO sharpsl_io_base+0x14 /* Flash I/O */ +#define FLASHCTL sharpsl_io_base+0x18 /* Flash Control */ /* Flash control bit */ #define FLRYBY (1 << 5) @@ -55,6 +45,35 @@ struct sharpsl_nand { #define FLCE0 (1 << 0) /* + * MTD structure for SharpSL + */ +static struct mtd_info *sharpsl_mtd = NULL; + +/* + * Define partitions for flash device + */ +#define DEFAULT_NUM_PARTITIONS 3 + +static int nr_partitions; +static struct mtd_partition sharpsl_nand_default_partition_info[] = { + { + .name = "System Area", + .offset = 0, + .size = 7 * 1024 * 1024, + }, + { + .name = "Root Filesystem", + .offset = 7 * 1024 * 1024, + .size = 30 * 1024 * 1024, + }, + { + .name = "Home Filesystem", + .offset = MTDPART_OFS_APPEND, + .size = MTDPART_SIZ_FULL, + }, +}; + +/* * hardware specific access to control-lines * ctrl: * NAND_CNE: bit 0 -> ! bit 0 & 4 @@ -65,7 +84,6 @@ struct sharpsl_nand { static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) { - struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); struct nand_chip *chip = mtd->priv; if (ctrl & NAND_CTRL_CHANGE) { @@ -75,97 +93,103 @@ static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, bits ^= 0x11; - writeb((readb(sharpsl->io + FLASHCTL) & ~0x17) | bits, sharpsl->io + FLASHCTL); + writeb((readb(FLASHCTL) & ~0x17) | bits, FLASHCTL); } if (cmd != NAND_CMD_NONE) writeb(cmd, chip->IO_ADDR_W); } +static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; + +static struct nand_bbt_descr sharpsl_bbt = { + .options = 0, + .offs = 4, + .len = 2, + .pattern = scan_ff_pattern +}; + +static struct nand_bbt_descr sharpsl_akita_bbt = { + .options = 0, + .offs = 4, + .len = 1, + .pattern = scan_ff_pattern +}; + +static struct nand_ecclayout akita_oobinfo = { + .eccbytes = 24, + .eccpos = { + 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, + 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, + 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, + .oobfree = {{0x08, 0x09}} +}; + static int sharpsl_nand_dev_ready(struct mtd_info *mtd) { - struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); - return !((readb(sharpsl->io + FLASHCTL) & FLRYBY) == 0); + return !((readb(FLASHCTL) & FLRYBY) == 0); } static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode) { - struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); - writeb(0, sharpsl->io + ECCCLRR); + writeb(0, ECCCLRR); } static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code) { - struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); - ecc_code[0] = ~readb(sharpsl->io + ECCLPUB); - ecc_code[1] = ~readb(sharpsl->io + ECCLPLB); - ecc_code[2] = (~readb(sharpsl->io + ECCCP) << 2) | 0x03; - return readb(sharpsl->io + ECCCNTR) != 0; + ecc_code[0] = ~readb(ECCLPUB); + ecc_code[1] = ~readb(ECCLPLB); + ecc_code[2] = (~readb(ECCCP) << 2) | 0x03; + return readb(ECCCNTR) != 0; } #ifdef CONFIG_MTD_PARTITIONS -static const char *part_probes[] = { "cmdlinepart", NULL }; +const char *part_probes[] = { "cmdlinepart", NULL }; #endif /* * Main initialization routine */ -static int __devinit sharpsl_nand_probe(struct platform_device *pdev) +static int __init sharpsl_nand_init(void) { struct nand_chip *this; -#ifdef CONFIG_MTD_PARTITIONS struct mtd_partition *sharpsl_partition_info; - int nr_partitions; -#endif - struct resource *r; int err = 0; - struct sharpsl_nand *sharpsl; - struct sharpsl_nand_platform_data *data = pdev->dev.platform_data; - - if (!data) { - dev_err(&pdev->dev, "no platform data!\n"); - return -EINVAL; - } /* Allocate memory for MTD device structure and private data */ - sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL); - if (!sharpsl) { + sharpsl_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); + if (!sharpsl_mtd) { printk("Unable to allocate SharpSL NAND MTD device structure.\n"); return -ENOMEM; } - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!r) { - dev_err(&pdev->dev, "no io memory resource defined!\n"); - err = -ENODEV; - goto err_get_res; - } - /* map physical address */ - sharpsl->io = ioremap(r->start, resource_size(r)); - if (!sharpsl->io) { + sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000); + if (!sharpsl_io_base) { printk("ioremap to access Sharp SL NAND chip failed\n"); - err = -EIO; - goto err_ioremap; + kfree(sharpsl_mtd); + return -EIO; } /* Get pointer to private data */ - this = (struct nand_chip *)(&sharpsl->chip); + this = (struct nand_chip *)(&sharpsl_mtd[1]); - /* Link the private data with the MTD structure */ - sharpsl->mtd.priv = this; - sharpsl->mtd.owner = THIS_MODULE; + /* Initialize structures */ + memset(sharpsl_mtd, 0, sizeof(struct mtd_info)); + memset(this, 0, sizeof(struct nand_chip)); - platform_set_drvdata(pdev, sharpsl); + /* Link the private data with the MTD structure */ + sharpsl_mtd->priv = this; + sharpsl_mtd->owner = THIS_MODULE; /* * PXA initialize */ - writeb(readb(sharpsl->io + FLASHCTL) | FLWP, sharpsl->io + FLASHCTL); + writeb(readb(FLASHCTL) | FLWP, FLASHCTL); /* Set address of NAND IO lines */ - this->IO_ADDR_R = sharpsl->io + FLASHIO; - this->IO_ADDR_W = sharpsl->io + FLASHIO; + this->IO_ADDR_R = FLASHIO; + this->IO_ADDR_W = FLASHIO; /* Set address of hardware control function */ this->cmd_ctrl = sharpsl_nand_hwcontrol; this->dev_ready = sharpsl_nand_dev_ready; @@ -175,89 +199,68 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev) this->ecc.mode = NAND_ECC_HW; this->ecc.size = 256; this->ecc.bytes = 3; - this->badblock_pattern = data->badblock_pattern; - this->ecc.layout = data->ecc_layout; + this->badblock_pattern = &sharpsl_bbt; + if (machine_is_akita() || machine_is_borzoi()) { + this->badblock_pattern = &sharpsl_akita_bbt; + this->ecc.layout = &akita_oobinfo; + } this->ecc.hwctl = sharpsl_nand_enable_hwecc; this->ecc.calculate = sharpsl_nand_calculate_ecc; this->ecc.correct = nand_correct_data; /* Scan to find existence of the device */ - err = nand_scan(&sharpsl->mtd, 1); - if (err) - goto err_scan; + err = nand_scan(sharpsl_mtd, 1); + if (err) { + iounmap(sharpsl_io_base); + kfree(sharpsl_mtd); + return err; + } /* Register the partitions */ - sharpsl->mtd.name = "sharpsl-nand"; -#ifdef CONFIG_MTD_PARTITIONS - nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0); + sharpsl_mtd->name = "sharpsl-nand"; + nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, &sharpsl_partition_info, 0); + if (nr_partitions <= 0) { - nr_partitions = data->nr_partitions; - sharpsl_partition_info = data->partitions; + nr_partitions = DEFAULT_NUM_PARTITIONS; + sharpsl_partition_info = sharpsl_nand_default_partition_info; + if (machine_is_poodle()) { + sharpsl_partition_info[1].size = 22 * 1024 * 1024; + } else if (machine_is_corgi() || machine_is_shepherd()) { + sharpsl_partition_info[1].size = 25 * 1024 * 1024; + } else if (machine_is_husky()) { + sharpsl_partition_info[1].size = 53 * 1024 * 1024; + } else if (machine_is_spitz()) { + sharpsl_partition_info[1].size = 5 * 1024 * 1024; + } else if (machine_is_akita()) { + sharpsl_partition_info[1].size = 58 * 1024 * 1024; + } else if (machine_is_borzoi()) { + sharpsl_partition_info[1].size = 32 * 1024 * 1024; + } } - if (nr_partitions > 0) - err = add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions); - else -#endif - err = add_mtd_device(&sharpsl->mtd); - if (err) - goto err_add; + add_mtd_partitions(sharpsl_mtd, sharpsl_partition_info, nr_partitions); /* Return happy */ return 0; - -err_add: - nand_release(&sharpsl->mtd); - -err_scan: - platform_set_drvdata(pdev, NULL); - iounmap(sharpsl->io); -err_ioremap: -err_get_res: - kfree(sharpsl); - return err; } +module_init(sharpsl_nand_init); + /* * Clean up routine */ -static int __devexit sharpsl_nand_remove(struct platform_device *pdev) +static void __exit sharpsl_nand_cleanup(void) { - struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev); - /* Release resources, unregister device */ - nand_release(&sharpsl->mtd); + nand_release(sharpsl_mtd); - platform_set_drvdata(pdev, NULL); - - iounmap(sharpsl->io); + iounmap(sharpsl_io_base); /* Free the MTD device structure */ - kfree(sharpsl); - - return 0; -} - -static struct platform_driver sharpsl_nand_driver = { - .driver = { - .name = "sharpsl-nand", - .owner = THIS_MODULE, - }, - .probe = sharpsl_nand_probe, - .remove = __devexit_p(sharpsl_nand_remove), -}; - -static int __init sharpsl_nand_init(void) -{ - return platform_driver_register(&sharpsl_nand_driver); + kfree(sharpsl_mtd); } -module_init(sharpsl_nand_init); -static void __exit sharpsl_nand_exit(void) -{ - platform_driver_unregister(&sharpsl_nand_driver); -} -module_exit(sharpsl_nand_exit); +module_exit(sharpsl_nand_cleanup); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |