OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [mtd/] [nand/] [spia.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  drivers/mtd/nand/spia.c
3
 *
4
 *  Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
5
 *
6
 *
7
 *      10-29-2001 TG   change to support hardwarespecific access
8
 *                      to controllines (due to change in nand.c)
9
 *                      page_cache added
10
 *
11
 * $Id: spia.c,v 1.1.1.1 2004-04-15 01:51:58 phoenix Exp $
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License version 2 as
15
 * published by the Free Software Foundation.
16
 *
17
 *  Overview:
18
 *   This is a device driver for the NAND flash device found on the
19
 *   SPIA board which utilizes the Toshiba TC58V64AFT part. This is
20
 *   a 64Mibit (8MiB x 8 bits) NAND flash device.
21
 */
22
 
23
#include <linux/slab.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>
29
 
30
/*
31
 * MTD structure for SPIA board
32
 */
33
static struct mtd_info *spia_mtd = NULL;
34
 
35
/*
36
 * Values specific to the SPIA board (used with EP7212 processor)
37
 */
38
#define SPIA_IO_ADDR    = 0xd0000000    /* Start of EP7212 IO address space */
39
#define SPIA_FIO_ADDR   = 0xf0000000    /* Address where flash is mapped */
40
#define SPIA_PEDR       = 0x0080        /*
41
                                         * IO offset to Port E data register
42
                                         * where the CLE, ALE and NCE pins
43
                                         * are wired to.
44
                                         */
45
#define SPIA_PEDDR      = 0x00c0        /*
46
                                         * IO offset to Port E data direction
47
                                         * register so we can control the IO
48
                                         * lines.
49
                                         */
50
 
51
/*
52
 * Module stuff
53
 */
54
 
55
static int spia_io_base = SPIA_IO_BASE;
56
static int spia_fio_base = SPIA_FIO_BASE;
57
static int spia_pedr = SPIA_PEDR;
58
static int spia_peddr = SPIA_PEDDR;
59
 
60
MODULE_PARM(spia_io_base, "i");
61
MODULE_PARM(spia_fio_base, "i");
62
MODULE_PARM(spia_pedr, "i");
63
MODULE_PARM(spia_peddr, "i");
64
 
65
__setup("spia_io_base=",spia_io_base);
66
__setup("spia_fio_base=",spia_fio_base);
67
__setup("spia_pedr=",spia_pedr);
68
__setup("spia_peddr=",spia_peddr);
69
 
70
/*
71
 * Define partitions for flash device
72
 */
73
const static struct mtd_partition partition_info[] = {
74
        { name: "SPIA flash partition 1",
75
          offset: 0,
76
          size: 2*1024*1024 },
77
        { name: "SPIA flash partition 2",
78
          offset: 2*1024*1024,
79
          size: 6*1024*1024 }
80
};
81
#define NUM_PARTITIONS 2
82
 
83
 
84
/*
85
 *      hardware specific access to control-lines
86
*/
87
void spia_hwcontrol(int cmd){
88
 
89
    switch(cmd){
90
 
91
        case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |=  0x01; break;
92
        case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break;
93
 
94
        case NAND_CTL_SETALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |=  0x02; break;
95
        case NAND_CTL_CLRALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x02; break;
96
 
97
        case NAND_CTL_SETNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x04; break;
98
        case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |=  0x04; break;
99
    }
100
}
101
 
102
/*
103
 * Main initialization routine
104
 */
105
int __init spia_init (void)
106
{
107
        struct nand_chip *this;
108
 
109
        /* Allocate memory for MTD device structure and private data */
110
        spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
111
                                GFP_KERNEL);
112
        if (!spia_mtd) {
113
                printk ("Unable to allocate SPIA NAND MTD device structure.\n");
114
                return -ENOMEM;
115
        }
116
 
117
        /* Get pointer to private data */
118
        this = (struct nand_chip *) (&spia_mtd[1]);
119
 
120
        /* Initialize structures */
121
        memset((char *) spia_mtd, 0, sizeof(struct mtd_info));
122
        memset((char *) this, 0, sizeof(struct nand_chip));
123
 
124
        /* Link the private data with the MTD structure */
125
        spia_mtd->priv = this;
126
 
127
        /*
128
         * Set GPIO Port E control register so that the pins are configured
129
         * to be outputs for controlling the NAND flash.
130
         */
131
        (*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07;
132
 
133
        /* Set address of NAND IO lines */
134
        this->IO_ADDR_R = spia_fio_base;
135
        this->IO_ADDR_W = spia_fio_base;
136
        /* Set address of hardware control function */
137
        this->hwcontrol = spia_hwcontrol;
138
        /* 15 us command delay time */
139
        this->chip_delay = 15;
140
 
141
        /* Scan to find existence of the device */
142
        if (nand_scan (spia_mtd)) {
143
                kfree (spia_mtd);
144
                return -ENXIO;
145
        }
146
 
147
        /* Allocate memory for internal data buffer */
148
        this->data_buf = kmalloc (sizeof(u_char) * (spia_mtd->oobblock + spia_mtd->oobsize), GFP_KERNEL);
149
        if (!this->data_buf) {
150
                printk ("Unable to allocate NAND data buffer for SPIA.\n");
151
                kfree (spia_mtd);
152
                return -ENOMEM;
153
        }
154
 
155
        /* Allocate memory for internal data buffer */
156
        this->data_cache = kmalloc (sizeof(u_char) * (spia_mtd->oobblock + spia_mtd->oobsize), GFP_KERNEL);
157
        if (!this->data_cache) {
158
                printk ("Unable to allocate NAND data cache for SPIA.\n");
159
                kfree (this->data_buf);
160
                kfree (spia_mtd);
161
                return = -ENOMEM;
162
        }
163
        this->cache_page = -1;
164
 
165
        /* Register the partitions */
166
        add_mtd_partitions(spia_mtd, partition_info, NUM_PARTITIONS);
167
 
168
        /* Return happy */
169
        return 0;
170
}
171
module_init(spia_init);
172
 
173
/*
174
 * Clean up routine
175
 */
176
#ifdef MODULE
177
static void __exit spia_cleanup (void)
178
{
179
        struct nand_chip *this = (struct nand_chip *) &spia_mtd[1];
180
 
181
        /* Unregister the device */
182
        del_mtd_device (spia_mtd);
183
 
184
        /* Free internal data buffer */
185
        kfree (this->data_buf);
186
        kfree (this->page_cache);
187
 
188
        /* Free the MTD device structure */
189
        kfree (spia_mtd);
190
}
191
module_exit(spia_cleanup);
192
#endif
193
 
194
MODULE_LICENSE("GPL");
195
MODULE_AUTHOR("Steven J. Hill <sjhill@cotw.com");
196
MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on SPIA board");

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.