Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX,
0003                 SBC-GXm and SBC-GX1 series boards.
0004 
0005    Copyright (C) 2001 Arcom Control System Ltd
0006 
0007 
0008 The SBC-MediaGX / SBC-GXx has up to 16 MiB of
0009 Intel StrataFlash (28F320/28F640) in x8 mode.
0010 
0011 This driver uses the CFI probe and Intel Extended Command Set drivers.
0012 
0013 The flash is accessed as follows:
0014 
0015    16 KiB memory window at 0xdc000-0xdffff
0016 
0017    Two IO address locations for paging
0018 
0019    0x258
0020        bit 0-7: address bit 14-21
0021    0x259
0022        bit 0-1: address bit 22-23
0023        bit 7:   0 - reset/powered down
0024                 1 - device enabled
0025 
0026 The single flash device is divided into 3 partition which appear as
0027 separate MTD devices.
0028 
0029 25/04/2001 AJL (Arcom)  Modified signon strings and partition sizes
0030                         (to support bzImages up to 638KiB-ish)
0031 */
0032 
0033 // Includes
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 // Defines
0045 
0046 // - Hardware specific
0047 
0048 #define WINDOW_START 0xdc000
0049 
0050 /* Number of bits in offset. */
0051 #define WINDOW_SHIFT 14
0052 #define WINDOW_LENGTH (1 << WINDOW_SHIFT)
0053 
0054 /* The bits for the offset into the window. */
0055 #define WINDOW_MASK (WINDOW_LENGTH-1)
0056 #define PAGE_IO 0x258
0057 #define PAGE_IO_SIZE 2
0058 
0059 /* bit 7 of 0x259 must be 1 to enable device. */
0060 #define DEVICE_ENABLE 0x8000
0061 
0062 // - Flash / Partition sizing
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 // Globals
0070 
0071 static volatile int page_in_window = -1; // Current page in window.
0072 static void __iomem *iomapadr;
0073 static DEFINE_SPINLOCK(sbc_gxx_spin);
0074 
0075 /* partition_info gives details on the logical partitions that the split the
0076  * single flash device into. If the size if zero we use up to the end of the
0077  * device. */
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, /* this must be set to a maximum possible amount
0158              of flash so the cfi probe routines find all
0159              the chips */
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 /* MTD device for all of the flash. */
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     /* Probe for chip. */
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     /* Create MTD devices for each partition. */
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");