blob: 2d585d2d090c97e58efc831ec988159ee1a3fb22 [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 *
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000010 * $Id: h1910.c,v 1.6 2005/11/07 11:14:30 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * Overview:
17 * This is a device driver for the NAND flash device found on the
18 * iPAQ h1910 board which utilizes the Samsung K9F2808 part. This is
19 * a 128Mibit (16MiB x 8 bits) NAND flash device.
20 */
21
22#include <linux/slab.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/mtd/mtd.h>
26#include <linux/mtd/nand.h>
27#include <linux/mtd/partitions.h>
28#include <asm/io.h>
David Woodhousee0c7d762006-05-13 18:07:53 +010029#include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/sizes.h>
31#include <asm/arch/h1900-gpio.h>
32#include <asm/arch/ipaq.h>
33
34/*
35 * MTD structure for EDB7312 board
36 */
37static struct mtd_info *h1910_nand_mtd = NULL;
38
39/*
40 * Module stuff
41 */
42
43#ifdef CONFIG_MTD_PARTITIONS
44/*
45 * Define static partitions for flash device
46 */
47static struct mtd_partition partition_info[] = {
David Woodhousee0c7d762006-05-13 18:07:53 +010048 {name:"h1910 NAND Flash",
49 offset:0,
50 size:16 * 1024 * 1024}
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
David Woodhousee0c7d762006-05-13 18:07:53 +010052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define NUM_PARTITIONS 1
54
55#endif
56
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000057/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 * hardware specific access to control-lines
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020059 *
60 * NAND_NCE: bit 0 - don't care
61 * NAND_CLE: bit 1 - address bit 2
62 * NAND_ALE: bit 2 - address bit 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020064static void h1910_hwcontrol(struct mtd_info *mtd, int cmd,
65 unsigned int ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020067 struct nand_chip *chip = mtd->priv;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000068
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +020069 if (cmd != NAND_CMD_NONE)
70 writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73/*
74 * read device ready pin
75 */
76#if 0
77static int h1910_device_ready(struct mtd_info *mtd)
78{
79 return (GPLR(55) & GPIO_bit(55));
80}
81#endif
82
83/*
84 * Main initialization routine
85 */
David Woodhousee0c7d762006-05-13 18:07:53 +010086static int __init h1910_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 struct nand_chip *this;
89 const char *part_type = 0;
90 int mtd_parts_nb = 0;
91 struct mtd_partition *mtd_parts = 0;
92 void __iomem *nandaddr;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 if (!machine_is_h1900())
95 return -ENODEV;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000096
Russell King0c2e4b42005-11-17 16:46:41 +000097 nandaddr = ioremap(0x08000000, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (!nandaddr) {
99 printk("Failed to ioremap nand flash.\n");
100 return -ENOMEM;
101 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* Allocate memory for MTD device structure and private data */
David Woodhousee0c7d762006-05-13 18:07:53 +0100104 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 if (!h1910_nand_mtd) {
106 printk("Unable to allocate h1910 NAND MTD device structure.\n");
David Woodhousee0c7d762006-05-13 18:07:53 +0100107 iounmap((void *)nandaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return -ENOMEM;
109 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 /* Get pointer to private data */
David Woodhousee0c7d762006-05-13 18:07:53 +0100112 this = (struct nand_chip *)(&h1910_nand_mtd[1]);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* Initialize structures */
David Woodhousee0c7d762006-05-13 18:07:53 +0100115 memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
116 memset(this, 0, sizeof(struct nand_chip));
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 /* Link the private data with the MTD structure */
119 h1910_nand_mtd->priv = this;
David Woodhouse552d9202006-05-14 01:20:46 +0100120 h1910_nand_mtd->owner = THIS_MODULE;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /*
123 * Enable VPEN
124 */
125 GPSR(37) = GPIO_bit(37);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* insert callbacks */
128 this->IO_ADDR_R = nandaddr;
129 this->IO_ADDR_W = nandaddr;
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200130 this->cmd_ctrl = h1910_hwcontrol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
132 /* 15 us command delay time */
133 this->chip_delay = 50;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200134 this->ecc.mode = NAND_ECC_SOFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 this->options = NAND_NO_AUTOINCR;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 /* Scan to find existence of the device */
David Woodhousee0c7d762006-05-13 18:07:53 +0100138 if (nand_scan(h1910_nand_mtd, 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
David Woodhousee0c7d762006-05-13 18:07:53 +0100140 kfree(h1910_nand_mtd);
141 iounmap((void *)nandaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return -ENXIO;
143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_MTD_CMDLINE_PARTS
David Woodhousee0c7d762006-05-13 18:07:53 +0100145 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (mtd_parts_nb > 0)
David Woodhousee0c7d762006-05-13 18:07:53 +0100147 part_type = "command line";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 else
David Woodhousee0c7d762006-05-13 18:07:53 +0100149 mtd_parts_nb = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif
David Woodhousee0c7d762006-05-13 18:07:53 +0100151 if (mtd_parts_nb == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 mtd_parts = partition_info;
153 mtd_parts_nb = NUM_PARTITIONS;
154 part_type = "static";
155 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /* Register the partitions */
158 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
159 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /* Return happy */
162 return 0;
163}
David Woodhousee0c7d762006-05-13 18:07:53 +0100164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165module_init(h1910_init);
166
167/*
168 * Clean up routine
169 */
David Woodhousee0c7d762006-05-13 18:07:53 +0100170static void __exit h1910_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
David Woodhousee0c7d762006-05-13 18:07:53 +0100172 struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 /* Release resources, unregister device */
David Woodhousee0c7d762006-05-13 18:07:53 +0100175 nand_release(h1910_nand_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 /* Release io resource */
David Woodhousee0c7d762006-05-13 18:07:53 +0100178 iounmap((void *)this->IO_ADDR_W);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* Free the MTD device structure */
David Woodhousee0c7d762006-05-13 18:07:53 +0100181 kfree(h1910_nand_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
David Woodhousee0c7d762006-05-13 18:07:53 +0100183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184module_exit(h1910_cleanup);
185
186MODULE_LICENSE("GPL");
187MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
188MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");