blob: 556a2dfe94c586e03b363f5c2056992346df72b1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX,
2 SBC-GXm and SBC-GX1 series boards.
Thomas Gleixner69f34c92005-11-07 11:15:40 +00003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 Copyright (C) 2001 Arcom Control System Ltd
Thomas Gleixner69f34c92005-11-07 11:15:40 +00005
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
Thomas Gleixner69f34c92005-11-07 11:15:40 +000010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
Thomas Gleixner69f34c92005-11-07 11:15:40 +000015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
Thomas Gleixner69f34c92005-11-07 11:15:40 +000020The SBC-MediaGX / SBC-GXx has up to 16 MiB of
21Intel StrataFlash (28F320/28F640) in x8 mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23This driver uses the CFI probe and Intel Extended Command Set drivers.
24
25The flash is accessed as follows:
26
27 16 KiB memory window at 0xdc000-0xdffff
Thomas Gleixner69f34c92005-11-07 11:15:40 +000028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 Two IO address locations for paging
Thomas Gleixner69f34c92005-11-07 11:15:40 +000030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 0x258
32 bit 0-7: address bit 14-21
33 0x259
34 bit 0-1: address bit 22-23
35 bit 7: 0 - reset/powered down
36 1 - device enabled
37
Thomas Gleixner69f34c92005-11-07 11:15:40 +000038The single flash device is divided into 3 partition which appear as
Linus Torvalds1da177e2005-04-16 15:20:36 -070039separate MTD devices.
40
4125/04/2001 AJL (Arcom) Modified signon strings and partition sizes
42 (to support bzImages up to 638KiB-ish)
43*/
44
45// Includes
46
47#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/ioport.h>
49#include <linux/init.h>
50#include <asm/io.h>
51
52#include <linux/mtd/mtd.h>
53#include <linux/mtd/map.h>
54#include <linux/mtd/partitions.h>
55
56// Defines
57
58// - Hardware specific
59
60#define WINDOW_START 0xdc000
61
62/* Number of bits in offset. */
63#define WINDOW_SHIFT 14
64#define WINDOW_LENGTH (1 << WINDOW_SHIFT)
65
66/* The bits for the offset into the window. */
67#define WINDOW_MASK (WINDOW_LENGTH-1)
68#define PAGE_IO 0x258
69#define PAGE_IO_SIZE 2
70
71/* bit 7 of 0x259 must be 1 to enable device. */
72#define DEVICE_ENABLE 0x8000
73
74// - Flash / Partition sizing
75
76#define MAX_SIZE_KiB 16384
77#define BOOT_PARTITION_SIZE_KiB 768
78#define DATA_PARTITION_SIZE_KiB 1280
79#define APP_PARTITION_SIZE_KiB 6144
80
81// Globals
82
83static volatile int page_in_window = -1; // Current page in window.
84static void __iomem *iomapadr;
85static DEFINE_SPINLOCK(sbc_gxx_spin);
86
Thomas Gleixner69f34c92005-11-07 11:15:40 +000087/* partition_info gives details on the logical partitions that the split the
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 * single flash device into. If the size if zero we use up to the end of the
89 * device. */
90static struct mtd_partition partition_info[]={
Thomas Gleixner69f34c92005-11-07 11:15:40 +000091 { .name = "SBC-GXx flash boot partition",
92 .offset = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .size = BOOT_PARTITION_SIZE_KiB*1024 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000094 { .name = "SBC-GXx flash data partition",
95 .offset = BOOT_PARTITION_SIZE_KiB*1024,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 .size = (DATA_PARTITION_SIZE_KiB)*1024 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000097 { .name = "SBC-GXx flash application partition",
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
99};
100
101#define NUM_PARTITIONS 3
102
103static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs)
104{
105 unsigned long page = ofs >> WINDOW_SHIFT;
106
107 if( page!=page_in_window ) {
108 outw( page | DEVICE_ENABLE, PAGE_IO );
109 page_in_window = page;
110 }
111}
112
113
114static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs)
115{
116 map_word ret;
117 spin_lock(&sbc_gxx_spin);
118 sbc_gxx_page(map, ofs);
119 ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
120 spin_unlock(&sbc_gxx_spin);
121 return ret;
122}
123
124static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
125{
126 while(len) {
127 unsigned long thislen = len;
128 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
129 thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 spin_lock(&sbc_gxx_spin);
132 sbc_gxx_page(map, from);
133 memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
134 spin_unlock(&sbc_gxx_spin);
135 to += thislen;
136 from += thislen;
137 len -= thislen;
138 }
139}
140
141static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
142{
143 spin_lock(&sbc_gxx_spin);
144 sbc_gxx_page(map, adr);
145 writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
146 spin_unlock(&sbc_gxx_spin);
147}
148
149static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000150{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 while(len) {
152 unsigned long thislen = len;
153 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
154 thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 spin_lock(&sbc_gxx_spin);
157 sbc_gxx_page(map, to);
158 memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
159 spin_unlock(&sbc_gxx_spin);
160 to += thislen;
161 from += thislen;
162 len -= thislen;
163 }
164}
165
166static struct map_info sbc_gxx_map = {
167 .name = "SBC-GXx flash",
168 .phys = NO_XIP,
169 .size = MAX_SIZE_KiB*1024, /* this must be set to a maximum possible amount
170 of flash so the cfi probe routines find all
171 the chips */
172 .bankwidth = 1,
173 .read = sbc_gxx_read8,
174 .copy_from = sbc_gxx_copy_from,
175 .write = sbc_gxx_write8,
176 .copy_to = sbc_gxx_copy_to
177};
178
179/* MTD device for all of the flash. */
180static struct mtd_info *all_mtd;
181
182static void cleanup_sbc_gxx(void)
183{
184 if( all_mtd ) {
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100185 mtd_device_unregister(all_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 map_destroy( all_mtd );
187 }
188
189 iounmap(iomapadr);
190 release_region(PAGE_IO,PAGE_IO_SIZE);
191}
192
193static int __init init_sbc_gxx(void)
194{
195 iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
196 if (!iomapadr) {
197 printk( KERN_ERR"%s: failed to ioremap memory region\n",
198 sbc_gxx_map.name );
199 return -EIO;
200 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
203 printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
204 sbc_gxx_map.name,
205 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 );
206 iounmap(iomapadr);
207 return -EAGAIN;
208 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000209
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
212 sbc_gxx_map.name,
213 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
214 WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
215
216 /* Probe for chip. */
217 all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map );
218 if( !all_mtd ) {
219 cleanup_sbc_gxx();
220 return -ENXIO;
221 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 all_mtd->owner = THIS_MODULE;
224
225 /* Create MTD devices for each partition. */
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100226 mtd_device_register(all_mtd, partition_info, NUM_PARTITIONS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 return 0;
229}
230
231module_init(init_sbc_gxx);
232module_exit(cleanup_sbc_gxx);
233
234MODULE_LICENSE("GPL");
235MODULE_AUTHOR("Arcom Control Systems Ltd.");
236MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards");