1 /* linux/drivers/mtd/maps/scx200_docflash.c
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
5 $Id: scx200_docflash.c,v 1.1 2003/01/24 13:20:40 dwmw2 Exp $
7 National Semiconductor SCx200 flash mapped with DOCCS
10 #include <linux/module.h>
11 #include <linux/config.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/map.h>
17 #include <linux/mtd/partitions.h>
19 #include <linux/pci.h>
20 #include <linux/scx200.h>
22 #define NAME "scx200_docflash"
24 MODULE_AUTHOR("Christer Weinigel <wingel@hack.org>");
25 MODULE_DESCRIPTION("NatSemi SCx200 DOCCS Flash Driver");
26 MODULE_LICENSE("GPL");
28 /* Set this to one if you want to partition the flash */
31 MODULE_PARM(probe, "i");
32 MODULE_PARM_DESC(probe, "Probe for a BIOS mapping");
33 MODULE_PARM(size, "i");
34 MODULE_PARM_DESC(size, "Size of the flash mapping");
35 MODULE_PARM(width, "i");
36 MODULE_PARM_DESC(width, "Data width of the flash mapping (8/16)");
37 MODULE_PARM(flashtype, "s");
38 MODULE_PARM_DESC(flashtype, "Type of MTD probe to do");
40 static int probe = 0; /* Don't autoprobe */
41 static unsigned size = 0x1000000; /* 16 MiB the whole ISA address space */
42 static unsigned width = 8; /* Default to 8 bits wide */
43 static char *flashtype = "cfi_probe";
45 static struct resource docmem = {
46 .flags = IORESOURCE_MEM,
47 .name = "NatSemi SCx200 DOCCS Flash",
50 static struct mtd_info *mymtd;
53 static struct mtd_partition partition_info[] = {
55 .name = "DOCCS Boot kernel",
60 .name = "DOCCS Low BIOS",
65 .name = "DOCCS File system",
67 .size = ~0 /* calculate from flash size */
70 .name = "DOCCS High BIOS",
71 .offset = ~0, /* calculate from flash size */
75 #define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
78 static __u8 scx200_docflash_read8(struct map_info *map, unsigned long ofs)
80 return __raw_readb(map->map_priv_1 + ofs);
83 static __u16 scx200_docflash_read16(struct map_info *map, unsigned long ofs)
85 return __raw_readw(map->map_priv_1 + ofs);
88 static void scx200_docflash_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
90 memcpy_fromio(to, map->map_priv_1 + from, len);
93 static void scx200_docflash_write8(struct map_info *map, __u8 d, unsigned long adr)
95 __raw_writeb(d, map->map_priv_1 + adr);
99 static void scx200_docflash_write16(struct map_info *map, __u16 d, unsigned long adr)
101 __raw_writew(d, map->map_priv_1 + adr);
105 static void scx200_docflash_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
107 memcpy_toio(map->map_priv_1 + to, from, len);
110 static struct map_info scx200_docflash_map = {
111 .name = "NatSemi SCx200 DOCCS Flash",
112 .read8 = scx200_docflash_read8,
113 .read16 = scx200_docflash_read16,
114 .copy_from = scx200_docflash_copy_from,
115 .write8 = scx200_docflash_write8,
116 .write16 = scx200_docflash_write16,
117 .copy_to = scx200_docflash_copy_to
120 int __init init_scx200_docflash(void)
126 struct pci_dev *bridge;
128 printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n");
130 if ((bridge = pci_find_device(PCI_VENDOR_ID_NS,
131 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
135 if (!scx200_cb_probe(SCx200_CB_BASE)) {
136 printk(KERN_WARNING NAME ": no configuration block found\n");
141 /* Try to use the present flash mapping if any */
142 pci_read_config_dword(bridge, SCx200_DOCCS_BASE, &base);
143 pci_read_config_dword(bridge, SCx200_DOCCS_CTRL, &ctrl);
144 pmr = inl(SCx200_CB_BASE + SCx200_PMR);
147 || (ctrl & 0x07000000) != 0x07000000
148 || (ctrl & 0x0007ffff) == 0)
151 size = ((ctrl&0x1fff)<<13) + (1<<13);
153 for (u = size; u > 1; u >>= 1)
164 docmem.end = base + size;
166 if (request_resource(&iomem_resource, &docmem)) {
167 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
171 for (u = size; u > 1; u >>= 1)
174 printk(KERN_ERR NAME ": invalid size for flash mapping\n");
178 if (width != 8 && width != 16) {
179 printk(KERN_ERR NAME ": invalid bus width for flash mapping\n");
183 if (allocate_resource(&iomem_resource, &docmem,
185 0xc0000000, 0xffffffff,
187 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
191 ctrl = 0x07000000 | ((size-1) >> 13);
193 printk(KERN_INFO "DOCCS BASE=0x%08lx, CTRL=0x%08lx\n", (long)docmem.start, (long)ctrl);
195 pci_write_config_dword(bridge, SCx200_DOCCS_BASE, docmem.start);
196 pci_write_config_dword(bridge, SCx200_DOCCS_CTRL, ctrl);
197 pmr = inl(SCx200_CB_BASE + SCx200_PMR);
204 outl(pmr, SCx200_CB_BASE + SCx200_PMR);
207 printk(KERN_INFO NAME ": DOCCS mapped at 0x%lx-0x%lx, width %d\n",
208 docmem.start, docmem.end, width);
210 scx200_docflash_map.size = size;
212 scx200_docflash_map.buswidth = 1;
214 scx200_docflash_map.buswidth = 2;
216 scx200_docflash_map.map_priv_1 = (unsigned long)ioremap(docmem.start, scx200_docflash_map.size);
217 if (!scx200_docflash_map.map_priv_1) {
218 printk(KERN_ERR NAME ": failed to ioremap the flash\n");
219 release_resource(&docmem);
223 mymtd = do_map_probe(flashtype, &scx200_docflash_map);
225 printk(KERN_ERR NAME ": unable to detect flash\n");
226 iounmap((void *)scx200_docflash_map.map_priv_1);
227 release_resource(&docmem);
231 if (size < mymtd->size)
232 printk(KERN_WARNING NAME ": warning, flash mapping is smaller than flash size\n");
234 mymtd->module = THIS_MODULE;
237 partition_info[3].offset = mymtd->size-partition_info[3].size;
238 partition_info[2].size = partition_info[3].offset-partition_info[2].offset;
239 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
241 add_mtd_device(mymtd);
246 static void __exit cleanup_scx200_docflash(void)
250 del_mtd_partitions(mymtd);
252 del_mtd_device(mymtd);
256 if (scx200_docflash_map.map_priv_1) {
257 iounmap((void *)scx200_docflash_map.map_priv_1);
258 release_resource(&docmem);
262 module_init(init_scx200_docflash);
263 module_exit(cleanup_scx200_docflash);
267 compile-command: "make -k -C ../../.. SUBDIRS=drivers/mtd/maps modules"