0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include <linux/module.h>
0036 #include <linux/ioport.h>
0037 #include <linux/init.h>
0038 #include <asm/io.h>
0039
0040 #include <linux/mtd/mtd.h>
0041 #include <linux/mtd/map.h>
0042 #include <linux/mtd/partitions.h>
0043
0044
0045
0046
0047
0048 #define WINDOW_START 0xdc000
0049
0050
0051 #define WINDOW_SHIFT 14
0052 #define WINDOW_LENGTH (1 << WINDOW_SHIFT)
0053
0054
0055 #define WINDOW_MASK (WINDOW_LENGTH-1)
0056 #define PAGE_IO 0x258
0057 #define PAGE_IO_SIZE 2
0058
0059
0060 #define DEVICE_ENABLE 0x8000
0061
0062
0063
0064 #define MAX_SIZE_KiB 16384
0065 #define BOOT_PARTITION_SIZE_KiB 768
0066 #define DATA_PARTITION_SIZE_KiB 1280
0067 #define APP_PARTITION_SIZE_KiB 6144
0068
0069
0070
0071 static volatile int page_in_window = -1;
0072 static void __iomem *iomapadr;
0073 static DEFINE_SPINLOCK(sbc_gxx_spin);
0074
0075
0076
0077
0078 static const struct mtd_partition partition_info[] = {
0079 { .name = "SBC-GXx flash boot partition",
0080 .offset = 0,
0081 .size = BOOT_PARTITION_SIZE_KiB*1024 },
0082 { .name = "SBC-GXx flash data partition",
0083 .offset = BOOT_PARTITION_SIZE_KiB*1024,
0084 .size = (DATA_PARTITION_SIZE_KiB)*1024 },
0085 { .name = "SBC-GXx flash application partition",
0086 .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
0087 };
0088
0089 #define NUM_PARTITIONS 3
0090
0091 static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs)
0092 {
0093 unsigned long page = ofs >> WINDOW_SHIFT;
0094
0095 if( page!=page_in_window ) {
0096 outw( page | DEVICE_ENABLE, PAGE_IO );
0097 page_in_window = page;
0098 }
0099 }
0100
0101
0102 static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs)
0103 {
0104 map_word ret;
0105 spin_lock(&sbc_gxx_spin);
0106 sbc_gxx_page(map, ofs);
0107 ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
0108 spin_unlock(&sbc_gxx_spin);
0109 return ret;
0110 }
0111
0112 static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
0113 {
0114 while(len) {
0115 unsigned long thislen = len;
0116 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
0117 thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
0118
0119 spin_lock(&sbc_gxx_spin);
0120 sbc_gxx_page(map, from);
0121 memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
0122 spin_unlock(&sbc_gxx_spin);
0123 to += thislen;
0124 from += thislen;
0125 len -= thislen;
0126 }
0127 }
0128
0129 static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
0130 {
0131 spin_lock(&sbc_gxx_spin);
0132 sbc_gxx_page(map, adr);
0133 writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
0134 spin_unlock(&sbc_gxx_spin);
0135 }
0136
0137 static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
0138 {
0139 while(len) {
0140 unsigned long thislen = len;
0141 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
0142 thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
0143
0144 spin_lock(&sbc_gxx_spin);
0145 sbc_gxx_page(map, to);
0146 memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
0147 spin_unlock(&sbc_gxx_spin);
0148 to += thislen;
0149 from += thislen;
0150 len -= thislen;
0151 }
0152 }
0153
0154 static struct map_info sbc_gxx_map = {
0155 .name = "SBC-GXx flash",
0156 .phys = NO_XIP,
0157 .size = MAX_SIZE_KiB*1024,
0158
0159
0160 .bankwidth = 1,
0161 .read = sbc_gxx_read8,
0162 .copy_from = sbc_gxx_copy_from,
0163 .write = sbc_gxx_write8,
0164 .copy_to = sbc_gxx_copy_to
0165 };
0166
0167
0168 static struct mtd_info *all_mtd;
0169
0170 static void cleanup_sbc_gxx(void)
0171 {
0172 if( all_mtd ) {
0173 mtd_device_unregister(all_mtd);
0174 map_destroy( all_mtd );
0175 }
0176
0177 iounmap(iomapadr);
0178 release_region(PAGE_IO,PAGE_IO_SIZE);
0179 }
0180
0181 static int __init init_sbc_gxx(void)
0182 {
0183 iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
0184 if (!iomapadr) {
0185 printk( KERN_ERR"%s: failed to ioremap memory region\n",
0186 sbc_gxx_map.name );
0187 return -EIO;
0188 }
0189
0190 if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
0191 printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
0192 sbc_gxx_map.name,
0193 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 );
0194 iounmap(iomapadr);
0195 return -EAGAIN;
0196 }
0197
0198
0199 printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
0200 sbc_gxx_map.name,
0201 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
0202 WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
0203
0204
0205 all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map );
0206 if( !all_mtd ) {
0207 cleanup_sbc_gxx();
0208 return -ENXIO;
0209 }
0210
0211 all_mtd->owner = THIS_MODULE;
0212
0213
0214 mtd_device_register(all_mtd, partition_info, NUM_PARTITIONS);
0215
0216 return 0;
0217 }
0218
0219 module_init(init_sbc_gxx);
0220 module_exit(cleanup_sbc_gxx);
0221
0222 MODULE_LICENSE("GPL");
0223 MODULE_AUTHOR("Arcom Control Systems Ltd.");
0224 MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards");