Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX, |
| 2 | SBC-GXm and SBC-GX1 series boards. |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | Copyright (C) 2001 Arcom Control System Ltd |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | 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 Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | 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 Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | 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 Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 20 | The SBC-MediaGX / SBC-GXx has up to 16 MiB of |
| 21 | Intel StrataFlash (28F320/28F640) in x8 mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | This driver uses the CFI probe and Intel Extended Command Set drivers. |
| 24 | |
| 25 | The flash is accessed as follows: |
| 26 | |
| 27 | 16 KiB memory window at 0xdc000-0xdffff |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | Two IO address locations for paging |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | 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 Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 38 | The single flash device is divided into 3 partition which appear as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | separate MTD devices. |
| 40 | |
| 41 | 25/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> |
| 48 | #include <linux/slab.h> |
| 49 | #include <linux/ioport.h> |
| 50 | #include <linux/init.h> |
| 51 | #include <asm/io.h> |
| 52 | |
| 53 | #include <linux/mtd/mtd.h> |
| 54 | #include <linux/mtd/map.h> |
| 55 | #include <linux/mtd/partitions.h> |
| 56 | |
| 57 | // Defines |
| 58 | |
| 59 | // - Hardware specific |
| 60 | |
| 61 | #define WINDOW_START 0xdc000 |
| 62 | |
| 63 | /* Number of bits in offset. */ |
| 64 | #define WINDOW_SHIFT 14 |
| 65 | #define WINDOW_LENGTH (1 << WINDOW_SHIFT) |
| 66 | |
| 67 | /* The bits for the offset into the window. */ |
| 68 | #define WINDOW_MASK (WINDOW_LENGTH-1) |
| 69 | #define PAGE_IO 0x258 |
| 70 | #define PAGE_IO_SIZE 2 |
| 71 | |
| 72 | /* bit 7 of 0x259 must be 1 to enable device. */ |
| 73 | #define DEVICE_ENABLE 0x8000 |
| 74 | |
| 75 | // - Flash / Partition sizing |
| 76 | |
| 77 | #define MAX_SIZE_KiB 16384 |
| 78 | #define BOOT_PARTITION_SIZE_KiB 768 |
| 79 | #define DATA_PARTITION_SIZE_KiB 1280 |
| 80 | #define APP_PARTITION_SIZE_KiB 6144 |
| 81 | |
| 82 | // Globals |
| 83 | |
| 84 | static volatile int page_in_window = -1; // Current page in window. |
| 85 | static void __iomem *iomapadr; |
| 86 | static DEFINE_SPINLOCK(sbc_gxx_spin); |
| 87 | |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 88 | /* partition_info gives details on the logical partitions that the split the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | * single flash device into. If the size if zero we use up to the end of the |
| 90 | * device. */ |
| 91 | static struct mtd_partition partition_info[]={ |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 92 | { .name = "SBC-GXx flash boot partition", |
| 93 | .offset = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | .size = BOOT_PARTITION_SIZE_KiB*1024 }, |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 95 | { .name = "SBC-GXx flash data partition", |
| 96 | .offset = BOOT_PARTITION_SIZE_KiB*1024, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | .size = (DATA_PARTITION_SIZE_KiB)*1024 }, |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 98 | { .name = "SBC-GXx flash application partition", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 } |
| 100 | }; |
| 101 | |
| 102 | #define NUM_PARTITIONS 3 |
| 103 | |
| 104 | static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs) |
| 105 | { |
| 106 | unsigned long page = ofs >> WINDOW_SHIFT; |
| 107 | |
| 108 | if( page!=page_in_window ) { |
| 109 | outw( page | DEVICE_ENABLE, PAGE_IO ); |
| 110 | page_in_window = page; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs) |
| 116 | { |
| 117 | map_word ret; |
| 118 | spin_lock(&sbc_gxx_spin); |
| 119 | sbc_gxx_page(map, ofs); |
| 120 | ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK)); |
| 121 | spin_unlock(&sbc_gxx_spin); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) |
| 126 | { |
| 127 | while(len) { |
| 128 | unsigned long thislen = len; |
| 129 | if (len > (WINDOW_LENGTH - (from & WINDOW_MASK))) |
| 130 | thislen = WINDOW_LENGTH-(from & WINDOW_MASK); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | spin_lock(&sbc_gxx_spin); |
| 133 | sbc_gxx_page(map, from); |
| 134 | memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen); |
| 135 | spin_unlock(&sbc_gxx_spin); |
| 136 | to += thislen; |
| 137 | from += thislen; |
| 138 | len -= thislen; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr) |
| 143 | { |
| 144 | spin_lock(&sbc_gxx_spin); |
| 145 | sbc_gxx_page(map, adr); |
| 146 | writeb(d.x[0], iomapadr + (adr & WINDOW_MASK)); |
| 147 | spin_unlock(&sbc_gxx_spin); |
| 148 | } |
| 149 | |
| 150 | static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 151 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | while(len) { |
| 153 | unsigned long thislen = len; |
| 154 | if (len > (WINDOW_LENGTH - (to & WINDOW_MASK))) |
| 155 | thislen = WINDOW_LENGTH-(to & WINDOW_MASK); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | spin_lock(&sbc_gxx_spin); |
| 158 | sbc_gxx_page(map, to); |
| 159 | memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen); |
| 160 | spin_unlock(&sbc_gxx_spin); |
| 161 | to += thislen; |
| 162 | from += thislen; |
| 163 | len -= thislen; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | static struct map_info sbc_gxx_map = { |
| 168 | .name = "SBC-GXx flash", |
| 169 | .phys = NO_XIP, |
| 170 | .size = MAX_SIZE_KiB*1024, /* this must be set to a maximum possible amount |
| 171 | of flash so the cfi probe routines find all |
| 172 | the chips */ |
| 173 | .bankwidth = 1, |
| 174 | .read = sbc_gxx_read8, |
| 175 | .copy_from = sbc_gxx_copy_from, |
| 176 | .write = sbc_gxx_write8, |
| 177 | .copy_to = sbc_gxx_copy_to |
| 178 | }; |
| 179 | |
| 180 | /* MTD device for all of the flash. */ |
| 181 | static struct mtd_info *all_mtd; |
| 182 | |
| 183 | static void cleanup_sbc_gxx(void) |
| 184 | { |
| 185 | if( all_mtd ) { |
| 186 | del_mtd_partitions( all_mtd ); |
| 187 | map_destroy( all_mtd ); |
| 188 | } |
| 189 | |
| 190 | iounmap(iomapadr); |
| 191 | release_region(PAGE_IO,PAGE_IO_SIZE); |
| 192 | } |
| 193 | |
| 194 | static int __init init_sbc_gxx(void) |
| 195 | { |
| 196 | iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH); |
| 197 | if (!iomapadr) { |
| 198 | printk( KERN_ERR"%s: failed to ioremap memory region\n", |
| 199 | sbc_gxx_map.name ); |
| 200 | return -EIO; |
| 201 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) { |
| 204 | printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n", |
| 205 | sbc_gxx_map.name, |
| 206 | PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 ); |
| 207 | iounmap(iomapadr); |
| 208 | return -EAGAIN; |
| 209 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 210 | |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n", |
| 213 | sbc_gxx_map.name, |
| 214 | PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1, |
| 215 | WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 ); |
| 216 | |
| 217 | /* Probe for chip. */ |
| 218 | all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map ); |
| 219 | if( !all_mtd ) { |
| 220 | cleanup_sbc_gxx(); |
| 221 | return -ENXIO; |
| 222 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | all_mtd->owner = THIS_MODULE; |
| 225 | |
| 226 | /* Create MTD devices for each partition. */ |
| 227 | add_mtd_partitions(all_mtd, partition_info, NUM_PARTITIONS ); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | module_init(init_sbc_gxx); |
| 233 | module_exit(cleanup_sbc_gxx); |
| 234 | |
| 235 | MODULE_LICENSE("GPL"); |
| 236 | MODULE_AUTHOR("Arcom Control Systems Ltd."); |
| 237 | MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards"); |