Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mtd / maps / sbc_gxx.c
blob9d48a261c2b21824a9e90f009aaeda2b2c8d30b6
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX,
3 SBC-GXm and SBC-GX1 series boards.
5 Copyright (C) 2001 Arcom Control System Ltd
8 The SBC-MediaGX / SBC-GXx has up to 16 MiB of
9 Intel StrataFlash (28F320/28F640) in x8 mode.
11 This driver uses the CFI probe and Intel Extended Command Set drivers.
13 The flash is accessed as follows:
15 16 KiB memory window at 0xdc000-0xdffff
17 Two IO address locations for paging
19 0x258
20 bit 0-7: address bit 14-21
21 0x259
22 bit 0-1: address bit 22-23
23 bit 7: 0 - reset/powered down
24 1 - device enabled
26 The single flash device is divided into 3 partition which appear as
27 separate MTD devices.
29 25/04/2001 AJL (Arcom) Modified signon strings and partition sizes
30 (to support bzImages up to 638KiB-ish)
33 // Includes
35 #include <linux/module.h>
36 #include <linux/ioport.h>
37 #include <linux/init.h>
38 #include <asm/io.h>
40 #include <linux/mtd/mtd.h>
41 #include <linux/mtd/map.h>
42 #include <linux/mtd/partitions.h>
44 // Defines
46 // - Hardware specific
48 #define WINDOW_START 0xdc000
50 /* Number of bits in offset. */
51 #define WINDOW_SHIFT 14
52 #define WINDOW_LENGTH (1 << WINDOW_SHIFT)
54 /* The bits for the offset into the window. */
55 #define WINDOW_MASK (WINDOW_LENGTH-1)
56 #define PAGE_IO 0x258
57 #define PAGE_IO_SIZE 2
59 /* bit 7 of 0x259 must be 1 to enable device. */
60 #define DEVICE_ENABLE 0x8000
62 // - Flash / Partition sizing
64 #define MAX_SIZE_KiB 16384
65 #define BOOT_PARTITION_SIZE_KiB 768
66 #define DATA_PARTITION_SIZE_KiB 1280
67 #define APP_PARTITION_SIZE_KiB 6144
69 // Globals
71 static volatile int page_in_window = -1; // Current page in window.
72 static void __iomem *iomapadr;
73 static DEFINE_SPINLOCK(sbc_gxx_spin);
75 /* partition_info gives details on the logical partitions that the split the
76 * single flash device into. If the size if zero we use up to the end of the
77 * device. */
78 static const struct mtd_partition partition_info[] = {
79 { .name = "SBC-GXx flash boot partition",
80 .offset = 0,
81 .size = BOOT_PARTITION_SIZE_KiB*1024 },
82 { .name = "SBC-GXx flash data partition",
83 .offset = BOOT_PARTITION_SIZE_KiB*1024,
84 .size = (DATA_PARTITION_SIZE_KiB)*1024 },
85 { .name = "SBC-GXx flash application partition",
86 .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
89 #define NUM_PARTITIONS 3
91 static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs)
93 unsigned long page = ofs >> WINDOW_SHIFT;
95 if( page!=page_in_window ) {
96 outw( page | DEVICE_ENABLE, PAGE_IO );
97 page_in_window = page;
102 static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs)
104 map_word ret;
105 spin_lock(&sbc_gxx_spin);
106 sbc_gxx_page(map, ofs);
107 ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
108 spin_unlock(&sbc_gxx_spin);
109 return ret;
112 static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
114 while(len) {
115 unsigned long thislen = len;
116 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
117 thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
119 spin_lock(&sbc_gxx_spin);
120 sbc_gxx_page(map, from);
121 memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
122 spin_unlock(&sbc_gxx_spin);
123 to += thislen;
124 from += thislen;
125 len -= thislen;
129 static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
131 spin_lock(&sbc_gxx_spin);
132 sbc_gxx_page(map, adr);
133 writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
134 spin_unlock(&sbc_gxx_spin);
137 static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
139 while(len) {
140 unsigned long thislen = len;
141 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
142 thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
144 spin_lock(&sbc_gxx_spin);
145 sbc_gxx_page(map, to);
146 memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
147 spin_unlock(&sbc_gxx_spin);
148 to += thislen;
149 from += thislen;
150 len -= thislen;
154 static struct map_info sbc_gxx_map = {
155 .name = "SBC-GXx flash",
156 .phys = NO_XIP,
157 .size = MAX_SIZE_KiB*1024, /* this must be set to a maximum possible amount
158 of flash so the cfi probe routines find all
159 the chips */
160 .bankwidth = 1,
161 .read = sbc_gxx_read8,
162 .copy_from = sbc_gxx_copy_from,
163 .write = sbc_gxx_write8,
164 .copy_to = sbc_gxx_copy_to
167 /* MTD device for all of the flash. */
168 static struct mtd_info *all_mtd;
170 static void cleanup_sbc_gxx(void)
172 if( all_mtd ) {
173 mtd_device_unregister(all_mtd);
174 map_destroy( all_mtd );
177 iounmap(iomapadr);
178 release_region(PAGE_IO,PAGE_IO_SIZE);
181 static int __init init_sbc_gxx(void)
183 iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
184 if (!iomapadr) {
185 printk( KERN_ERR"%s: failed to ioremap memory region\n",
186 sbc_gxx_map.name );
187 return -EIO;
190 if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
191 printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
192 sbc_gxx_map.name,
193 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 );
194 iounmap(iomapadr);
195 return -EAGAIN;
199 printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
200 sbc_gxx_map.name,
201 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
202 WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
204 /* Probe for chip. */
205 all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map );
206 if( !all_mtd ) {
207 cleanup_sbc_gxx();
208 return -ENXIO;
211 all_mtd->owner = THIS_MODULE;
213 /* Create MTD devices for each partition. */
214 mtd_device_register(all_mtd, partition_info, NUM_PARTITIONS);
216 return 0;
219 module_init(init_sbc_gxx);
220 module_exit(cleanup_sbc_gxx);
222 MODULE_LICENSE("GPL");
223 MODULE_AUTHOR("Arcom Control Systems Ltd.");
224 MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards");