blob: 9848eb09b8846651ba794833f6de48592c635ae2 [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
59 */
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000060static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
David Woodhousee0c7d762006-05-13 18:07:53 +010062 struct nand_chip *this = (struct nand_chip *)(mtd->priv);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000063
David Woodhousee0c7d762006-05-13 18:07:53 +010064 switch (cmd) {
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000065
66 case NAND_CTL_SETCLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 this->IO_ADDR_R |= (1 << 2);
68 this->IO_ADDR_W |= (1 << 2);
69 break;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000070 case NAND_CTL_CLRCLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 this->IO_ADDR_R &= ~(1 << 2);
72 this->IO_ADDR_W &= ~(1 << 2);
73 break;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 case NAND_CTL_SETALE:
76 this->IO_ADDR_R |= (1 << 3);
77 this->IO_ADDR_W |= (1 << 3);
78 break;
79 case NAND_CTL_CLRALE:
80 this->IO_ADDR_R &= ~(1 << 3);
81 this->IO_ADDR_W &= ~(1 << 3);
82 break;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +000083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 case NAND_CTL_SETNCE:
85 break;
86 case NAND_CTL_CLRNCE:
87 break;
88 }
89}
90
91/*
92 * read device ready pin
93 */
94#if 0
95static int h1910_device_ready(struct mtd_info *mtd)
96{
97 return (GPLR(55) & GPIO_bit(55));
98}
99#endif
100
101/*
102 * Main initialization routine
103 */
David Woodhousee0c7d762006-05-13 18:07:53 +0100104static int __init h1910_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106 struct nand_chip *this;
107 const char *part_type = 0;
108 int mtd_parts_nb = 0;
109 struct mtd_partition *mtd_parts = 0;
110 void __iomem *nandaddr;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 if (!machine_is_h1900())
113 return -ENODEV;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000114
Russell King0c2e4b42005-11-17 16:46:41 +0000115 nandaddr = ioremap(0x08000000, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (!nandaddr) {
117 printk("Failed to ioremap nand flash.\n");
118 return -ENOMEM;
119 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 /* Allocate memory for MTD device structure and private data */
David Woodhousee0c7d762006-05-13 18:07:53 +0100122 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (!h1910_nand_mtd) {
124 printk("Unable to allocate h1910 NAND MTD device structure.\n");
David Woodhousee0c7d762006-05-13 18:07:53 +0100125 iounmap((void *)nandaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return -ENOMEM;
127 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* Get pointer to private data */
David Woodhousee0c7d762006-05-13 18:07:53 +0100130 this = (struct nand_chip *)(&h1910_nand_mtd[1]);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 /* Initialize structures */
David Woodhousee0c7d762006-05-13 18:07:53 +0100133 memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
134 memset(this, 0, sizeof(struct nand_chip));
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* Link the private data with the MTD structure */
137 h1910_nand_mtd->priv = this;
David Woodhouse552d9202006-05-14 01:20:46 +0100138 h1910_nand_mtd->owner = THIS_MODULE;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /*
141 * Enable VPEN
142 */
143 GPSR(37) = GPIO_bit(37);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /* insert callbacks */
146 this->IO_ADDR_R = nandaddr;
147 this->IO_ADDR_W = nandaddr;
148 this->hwcontrol = h1910_hwcontrol;
149 this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
150 /* 15 us command delay time */
151 this->chip_delay = 50;
152 this->eccmode = NAND_ECC_SOFT;
153 this->options = NAND_NO_AUTOINCR;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* Scan to find existence of the device */
David Woodhousee0c7d762006-05-13 18:07:53 +0100156 if (nand_scan(h1910_nand_mtd, 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
David Woodhousee0c7d762006-05-13 18:07:53 +0100158 kfree(h1910_nand_mtd);
159 iounmap((void *)nandaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return -ENXIO;
161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#ifdef CONFIG_MTD_CMDLINE_PARTS
David Woodhousee0c7d762006-05-13 18:07:53 +0100163 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 if (mtd_parts_nb > 0)
David Woodhousee0c7d762006-05-13 18:07:53 +0100165 part_type = "command line";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 else
David Woodhousee0c7d762006-05-13 18:07:53 +0100167 mtd_parts_nb = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#endif
David Woodhousee0c7d762006-05-13 18:07:53 +0100169 if (mtd_parts_nb == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 mtd_parts = partition_info;
171 mtd_parts_nb = NUM_PARTITIONS;
172 part_type = "static";
173 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 /* Register the partitions */
176 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
177 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 /* Return happy */
180 return 0;
181}
David Woodhousee0c7d762006-05-13 18:07:53 +0100182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183module_init(h1910_init);
184
185/*
186 * Clean up routine
187 */
David Woodhousee0c7d762006-05-13 18:07:53 +0100188static void __exit h1910_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
David Woodhousee0c7d762006-05-13 18:07:53 +0100190 struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* Release resources, unregister device */
David Woodhousee0c7d762006-05-13 18:07:53 +0100193 nand_release(h1910_nand_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 /* Release io resource */
David Woodhousee0c7d762006-05-13 18:07:53 +0100196 iounmap((void *)this->IO_ADDR_W);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 /* Free the MTD device structure */
David Woodhousee0c7d762006-05-13 18:07:53 +0100199 kfree(h1910_nand_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
David Woodhousee0c7d762006-05-13 18:07:53 +0100201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202module_exit(h1910_cleanup);
203
204MODULE_LICENSE("GPL");
205MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
206MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");