blob: 02a03e67109c90ce2534757b4053ada8e8469956 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
David Woodhouse151e7652006-05-14 01:51:54 +01007 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/hardware.h> /* for CLPS7111_VIRT_BASE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/sizes.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/h1900-gpio.h>
30#include <mach/ipaq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*
33 * MTD structure for EDB7312 board
34 */
35static struct mtd_info *h1910_nand_mtd = NULL;
36
37/*
38 * Module stuff
39 */
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/*
42 * Define static partitions for flash device
43 */
44static struct mtd_partition partition_info[] = {
David Woodhousee0c7d762006-05-13 18:07:53 +010045 {name:"h1910 NAND Flash",
46 offset:0,
47 size:16 * 1024 * 1024}
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
David Woodhousee0c7d762006-05-13 18:07:53 +010049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define NUM_PARTITIONS 1
51
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000052/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * hardware specific access to control-lines
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020054 *
55 * NAND_NCE: bit 0 - don't care
56 * NAND_CLE: bit 1 - address bit 2
57 * NAND_ALE: bit 2 - address bit 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020059static void h1910_hwcontrol(struct mtd_info *mtd, int cmd,
60 unsigned int ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020062 struct nand_chip *chip = mtd->priv;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000063
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020064 if (cmd != NAND_CMD_NONE)
65 writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
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 */
David Woodhousee0c7d762006-05-13 18:07:53 +010081static int __init h1910_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 struct nand_chip *this;
84 const char *part_type = 0;
85 int mtd_parts_nb = 0;
86 struct mtd_partition *mtd_parts = 0;
87 void __iomem *nandaddr;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if (!machine_is_h1900())
90 return -ENODEV;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000091
Russell King0c2e4b42005-11-17 16:46:41 +000092 nandaddr = ioremap(0x08000000, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (!nandaddr) {
94 printk("Failed to ioremap nand flash.\n");
95 return -ENOMEM;
96 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 /* Allocate memory for MTD device structure and private data */
David Woodhousee0c7d762006-05-13 18:07:53 +010099 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (!h1910_nand_mtd) {
101 printk("Unable to allocate h1910 NAND MTD device structure.\n");
David Woodhousee0c7d762006-05-13 18:07:53 +0100102 iounmap((void *)nandaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return -ENOMEM;
104 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* Get pointer to private data */
David Woodhousee0c7d762006-05-13 18:07:53 +0100107 this = (struct nand_chip *)(&h1910_nand_mtd[1]);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* Initialize structures */
David Woodhousee0c7d762006-05-13 18:07:53 +0100110 memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
111 memset(this, 0, sizeof(struct nand_chip));
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 /* Link the private data with the MTD structure */
114 h1910_nand_mtd->priv = this;
David Woodhouse552d9202006-05-14 01:20:46 +0100115 h1910_nand_mtd->owner = THIS_MODULE;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /*
118 * Enable VPEN
119 */
120 GPSR(37) = GPIO_bit(37);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /* insert callbacks */
123 this->IO_ADDR_R = nandaddr;
124 this->IO_ADDR_W = nandaddr;
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200125 this->cmd_ctrl = h1910_hwcontrol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
127 /* 15 us command delay time */
128 this->chip_delay = 50;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200129 this->ecc.mode = NAND_ECC_SOFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 this->options = NAND_NO_AUTOINCR;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 /* Scan to find existence of the device */
David Woodhousee0c7d762006-05-13 18:07:53 +0100133 if (nand_scan(h1910_nand_mtd, 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
David Woodhousee0c7d762006-05-13 18:07:53 +0100135 kfree(h1910_nand_mtd);
136 iounmap((void *)nandaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return -ENXIO;
138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef CONFIG_MTD_CMDLINE_PARTS
David Woodhousee0c7d762006-05-13 18:07:53 +0100140 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (mtd_parts_nb > 0)
David Woodhousee0c7d762006-05-13 18:07:53 +0100142 part_type = "command line";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 else
David Woodhousee0c7d762006-05-13 18:07:53 +0100144 mtd_parts_nb = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif
David Woodhousee0c7d762006-05-13 18:07:53 +0100146 if (mtd_parts_nb == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 mtd_parts = partition_info;
148 mtd_parts_nb = NUM_PARTITIONS;
149 part_type = "static";
150 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /* Register the partitions */
153 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
Jamie Ilesc4a55222011-05-23 10:23:24 +0100154 mtd_device_register(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /* Return happy */
157 return 0;
158}
David Woodhousee0c7d762006-05-13 18:07:53 +0100159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160module_init(h1910_init);
161
162/*
163 * Clean up routine
164 */
David Woodhousee0c7d762006-05-13 18:07:53 +0100165static void __exit h1910_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
David Woodhousee0c7d762006-05-13 18:07:53 +0100167 struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /* Release resources, unregister device */
David Woodhousee0c7d762006-05-13 18:07:53 +0100170 nand_release(h1910_nand_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /* Release io resource */
David Woodhousee0c7d762006-05-13 18:07:53 +0100173 iounmap((void *)this->IO_ADDR_W);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* Free the MTD device structure */
David Woodhousee0c7d762006-05-13 18:07:53 +0100176 kfree(h1910_nand_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
David Woodhousee0c7d762006-05-13 18:07:53 +0100178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179module_exit(h1910_cleanup);
180
181MODULE_LICENSE("GPL");
182MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
183MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");