FRV: Use generic show_interrupts()
[cris-mirror.git] / drivers / mtd / maps / scx200_docflash.c
blob027e628a4f1d912791668f21d2e1787e6a4523f5
1 /* linux/drivers/mtd/maps/scx200_docflash.c
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
5 National Semiconductor SCx200 flash mapped with DOCCS
6 */
8 #include <linux/module.h>
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <asm/io.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/map.h>
15 #include <linux/mtd/partitions.h>
17 #include <linux/pci.h>
18 #include <linux/scx200.h>
20 #define NAME "scx200_docflash"
22 MODULE_AUTHOR("Christer Weinigel <wingel@hack.org>");
23 MODULE_DESCRIPTION("NatSemi SCx200 DOCCS Flash Driver");
24 MODULE_LICENSE("GPL");
26 static int probe = 0; /* Don't autoprobe */
27 static unsigned size = 0x1000000; /* 16 MiB the whole ISA address space */
28 static unsigned width = 8; /* Default to 8 bits wide */
29 static char *flashtype = "cfi_probe";
31 module_param(probe, int, 0);
32 MODULE_PARM_DESC(probe, "Probe for a BIOS mapping");
33 module_param(size, int, 0);
34 MODULE_PARM_DESC(size, "Size of the flash mapping");
35 module_param(width, int, 0);
36 MODULE_PARM_DESC(width, "Data width of the flash mapping (8/16)");
37 module_param(flashtype, charp, 0);
38 MODULE_PARM_DESC(flashtype, "Type of MTD probe to do");
40 static struct resource docmem = {
41 .flags = IORESOURCE_MEM,
42 .name = "NatSemi SCx200 DOCCS Flash",
45 static struct mtd_info *mymtd;
47 #ifdef CONFIG_MTD_PARTITIONS
48 static struct mtd_partition partition_info[] = {
50 .name = "DOCCS Boot kernel",
51 .offset = 0,
52 .size = 0xc0000
55 .name = "DOCCS Low BIOS",
56 .offset = 0xc0000,
57 .size = 0x40000
60 .name = "DOCCS File system",
61 .offset = 0x100000,
62 .size = ~0 /* calculate from flash size */
65 .name = "DOCCS High BIOS",
66 .offset = ~0, /* calculate from flash size */
67 .size = 0x80000
70 #define NUM_PARTITIONS ARRAY_SIZE(partition_info)
71 #endif
74 static struct map_info scx200_docflash_map = {
75 .name = "NatSemi SCx200 DOCCS Flash",
78 static int __init init_scx200_docflash(void)
80 unsigned u;
81 unsigned base;
82 unsigned ctrl;
83 unsigned pmr;
84 struct pci_dev *bridge;
86 printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n");
88 if ((bridge = pci_get_device(PCI_VENDOR_ID_NS,
89 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
90 NULL)) == NULL)
91 return -ENODEV;
93 /* check that we have found the configuration block */
94 if (!scx200_cb_present()) {
95 pci_dev_put(bridge);
96 return -ENODEV;
99 if (probe) {
100 /* Try to use the present flash mapping if any */
101 pci_read_config_dword(bridge, SCx200_DOCCS_BASE, &base);
102 pci_read_config_dword(bridge, SCx200_DOCCS_CTRL, &ctrl);
103 pci_dev_put(bridge);
105 pmr = inl(scx200_cb_base + SCx200_PMR);
107 if (base == 0
108 || (ctrl & 0x07000000) != 0x07000000
109 || (ctrl & 0x0007ffff) == 0)
110 return -ENODEV;
112 size = ((ctrl&0x1fff)<<13) + (1<<13);
114 for (u = size; u > 1; u >>= 1)
116 if (u != 1)
117 return -ENODEV;
119 if (pmr & (1<<6))
120 width = 16;
121 else
122 width = 8;
124 docmem.start = base;
125 docmem.end = base + size;
127 if (request_resource(&iomem_resource, &docmem)) {
128 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
129 return -ENOMEM;
131 } else {
132 pci_dev_put(bridge);
133 for (u = size; u > 1; u >>= 1)
135 if (u != 1) {
136 printk(KERN_ERR NAME ": invalid size for flash mapping\n");
137 return -EINVAL;
140 if (width != 8 && width != 16) {
141 printk(KERN_ERR NAME ": invalid bus width for flash mapping\n");
142 return -EINVAL;
145 if (allocate_resource(&iomem_resource, &docmem,
146 size,
147 0xc0000000, 0xffffffff,
148 size, NULL, NULL)) {
149 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
150 return -ENOMEM;
153 ctrl = 0x07000000 | ((size-1) >> 13);
155 printk(KERN_INFO "DOCCS BASE=0x%08lx, CTRL=0x%08lx\n", (long)docmem.start, (long)ctrl);
157 pci_write_config_dword(bridge, SCx200_DOCCS_BASE, docmem.start);
158 pci_write_config_dword(bridge, SCx200_DOCCS_CTRL, ctrl);
159 pmr = inl(scx200_cb_base + SCx200_PMR);
161 if (width == 8) {
162 pmr &= ~(1<<6);
163 } else {
164 pmr |= (1<<6);
166 outl(pmr, scx200_cb_base + SCx200_PMR);
169 printk(KERN_INFO NAME ": DOCCS mapped at %pR, width %d\n",
170 &docmem, width);
172 scx200_docflash_map.size = size;
173 if (width == 8)
174 scx200_docflash_map.bankwidth = 1;
175 else
176 scx200_docflash_map.bankwidth = 2;
178 simple_map_init(&scx200_docflash_map);
180 scx200_docflash_map.phys = docmem.start;
181 scx200_docflash_map.virt = ioremap(docmem.start, scx200_docflash_map.size);
182 if (!scx200_docflash_map.virt) {
183 printk(KERN_ERR NAME ": failed to ioremap the flash\n");
184 release_resource(&docmem);
185 return -EIO;
188 mymtd = do_map_probe(flashtype, &scx200_docflash_map);
189 if (!mymtd) {
190 printk(KERN_ERR NAME ": unable to detect flash\n");
191 iounmap(scx200_docflash_map.virt);
192 release_resource(&docmem);
193 return -ENXIO;
196 if (size < mymtd->size)
197 printk(KERN_WARNING NAME ": warning, flash mapping is smaller than flash size\n");
199 mymtd->owner = THIS_MODULE;
201 #ifdef CONFIG_MTD_PARTITIONS
202 partition_info[3].offset = mymtd->size-partition_info[3].size;
203 partition_info[2].size = partition_info[3].offset-partition_info[2].offset;
204 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
205 #else
206 add_mtd_device(mymtd);
207 #endif
208 return 0;
211 static void __exit cleanup_scx200_docflash(void)
213 if (mymtd) {
214 #ifdef CONFIG_MTD_PARTITIONS
215 del_mtd_partitions(mymtd);
216 #else
217 del_mtd_device(mymtd);
218 #endif
219 map_destroy(mymtd);
221 if (scx200_docflash_map.virt) {
222 iounmap(scx200_docflash_map.virt);
223 release_resource(&docmem);
227 module_init(init_scx200_docflash);
228 module_exit(cleanup_scx200_docflash);
231 Local variables:
232 compile-command: "make -k -C ../../.. SUBDIRS=drivers/mtd/maps modules"
233 c-basic-offset: 8
234 End: