1 /* elan-104nc.c -- MTD map driver for Arcom Control Systems ELAN-104NC
3 Copyright (C) 2000 Arcom Control System Ltd
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 $Id: elan-104nc.c,v 1.25 2004/11/28 09:40:39 dwmw2 Exp $
21 The ELAN-104NC has up to 8 Mibyte of Intel StrataFlash (28F320/28F640) in x16
22 mode. This drivers uses the CFI probe and Intel Extended Command Set drivers.
24 The flash is accessed as follows:
26 32 kbyte memory window at 0xb0000-0xb7fff
28 16 bit I/O port (0x22) for some sort of paging.
30 The single flash device is divided into 3 partition which appear as separate
33 Linux thinks that the I/O port is used by the PIC and hence check_region() will
34 always fail. So we don't do it. I just hope it doesn't break anything.
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/ioport.h>
39 #include <linux/init.h>
42 #include <linux/mtd/map.h>
43 #include <linux/mtd/mtd.h>
44 #include <linux/mtd/partitions.h>
46 #define WINDOW_START 0xb0000
47 /* Number of bits in offset. */
48 #define WINDOW_SHIFT 15
49 #define WINDOW_LENGTH (1 << WINDOW_SHIFT)
50 /* The bits for the offset into the window. */
51 #define WINDOW_MASK (WINDOW_LENGTH-1)
53 #define PAGE_IO_SIZE 2
55 static volatile int page_in_window
= -1; // Current page in window.
56 static void __iomem
*iomapadr
;
57 static DEFINE_SPINLOCK(elan_104nc_spin
);
59 /* partition_info gives details on the logical partitions that the split the
60 * single flash device into. If the size if zero we use up to the end of the
62 static struct mtd_partition partition_info
[]={
63 { .name
= "ELAN-104NC flash boot partition",
66 { .name
= "ELAN-104NC flash partition 1",
69 { .name
= "ELAN-104NC flash partition 2",
70 .offset
= (640+896)*1024 }
72 #define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
75 * If no idea what is going on here. This is taken from the FlashFX stuff.
79 static inline void elan_104nc_setup(void)
83 outw( 0x0023 + ROMCS
*2, PAGE_IO
);
88 outw( ((0x0023 + ROMCS
*2) | (t
<< 8)), PAGE_IO
);
91 static inline void elan_104nc_page(struct map_info
*map
, unsigned long ofs
)
93 unsigned long page
= ofs
>> WINDOW_SHIFT
;
95 if( page
!=page_in_window
) {
99 cmd1
=(page
& 0x700) + 0x0833 + ROMCS
*0x4000;
100 cmd2
=((page
& 0xff) << 8) + 0x0032;
102 outw( cmd1
, PAGE_IO
);
103 outw( cmd2
, PAGE_IO
);
105 page_in_window
= page
;
110 static map_word
elan_104nc_read16(struct map_info
*map
, unsigned long ofs
)
113 spin_lock(&elan_104nc_spin
);
114 elan_104nc_page(map
, ofs
);
115 ret
.x
[0] = readw(iomapadr
+ (ofs
& WINDOW_MASK
));
116 spin_unlock(&elan_104nc_spin
);
120 static void elan_104nc_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
123 unsigned long thislen
= len
;
124 if (len
> (WINDOW_LENGTH
- (from
& WINDOW_MASK
)))
125 thislen
= WINDOW_LENGTH
-(from
& WINDOW_MASK
);
127 spin_lock(&elan_104nc_spin
);
128 elan_104nc_page(map
, from
);
129 memcpy_fromio(to
, iomapadr
+ (from
& WINDOW_MASK
), thislen
);
130 spin_unlock(&elan_104nc_spin
);
137 static void elan_104nc_write16(struct map_info
*map
, map_word d
, unsigned long adr
)
139 spin_lock(&elan_104nc_spin
);
140 elan_104nc_page(map
, adr
);
141 writew(d
.x
[0], iomapadr
+ (adr
& WINDOW_MASK
));
142 spin_unlock(&elan_104nc_spin
);
145 static void elan_104nc_copy_to(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
148 unsigned long thislen
= len
;
149 if (len
> (WINDOW_LENGTH
- (to
& WINDOW_MASK
)))
150 thislen
= WINDOW_LENGTH
-(to
& WINDOW_MASK
);
152 spin_lock(&elan_104nc_spin
);
153 elan_104nc_page(map
, to
);
154 memcpy_toio(iomapadr
+ (to
& WINDOW_MASK
), from
, thislen
);
155 spin_unlock(&elan_104nc_spin
);
162 static struct map_info elan_104nc_map
= {
163 .name
= "ELAN-104NC flash",
165 .size
= 8*1024*1024, /* this must be set to a maximum possible amount
166 of flash so the cfi probe routines find all
169 .read
= elan_104nc_read16
,
170 .copy_from
= elan_104nc_copy_from
,
171 .write
= elan_104nc_write16
,
172 .copy_to
= elan_104nc_copy_to
175 /* MTD device for all of the flash. */
176 static struct mtd_info
*all_mtd
;
178 static void cleanup_elan_104nc(void)
181 del_mtd_partitions( all_mtd
);
182 map_destroy( all_mtd
);
188 static int __init
init_elan_104nc(void)
190 /* Urg! We use I/O port 0x22 without request_region()ing it,
191 because it's already allocated to the PIC. */
193 iomapadr
= ioremap(WINDOW_START
, WINDOW_LENGTH
);
195 printk( KERN_ERR
"%s: failed to ioremap memory region\n",
196 elan_104nc_map
.name
);
200 printk( KERN_INFO
"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
202 PAGE_IO
, PAGE_IO
+PAGE_IO_SIZE
-1,
203 WINDOW_START
, WINDOW_START
+WINDOW_LENGTH
-1 );
207 /* Probe for chip. */
208 all_mtd
= do_map_probe("cfi_probe", &elan_104nc_map
);
210 cleanup_elan_104nc();
214 all_mtd
->owner
= THIS_MODULE
;
216 /* Create MTD devices for each partition. */
217 add_mtd_partitions( all_mtd
, partition_info
, NUM_PARTITIONS
);
222 module_init(init_elan_104nc
);
223 module_exit(cleanup_elan_104nc
);
226 MODULE_LICENSE("GPL");
227 MODULE_AUTHOR("Arcom Control Systems Ltd.");
228 MODULE_DESCRIPTION("MTD map driver for Arcom Control Systems ELAN-104NC");