blob: 5e2bce22f37ca6146ee46c7abf3eca84628ff2f0 [file] [log] [blame]
Thomas Gleixner69f34c92005-11-07 11:15:40 +00001/* linux/drivers/mtd/maps/scx200_docflash.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4
Thomas Gleixner69f34c92005-11-07 11:15:40 +00005 $Id: scx200_docflash.c,v 1.12 2005/11/07 11:14:28 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
7 National Semiconductor SCx200 flash mapped with DOCCS
8*/
9
10#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <asm/io.h>
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/map.h>
17#include <linux/mtd/partitions.h>
18
19#include <linux/pci.h>
20#include <linux/scx200.h>
21
22#define NAME "scx200_docflash"
23
24MODULE_AUTHOR("Christer Weinigel <wingel@hack.org>");
25MODULE_DESCRIPTION("NatSemi SCx200 DOCCS Flash Driver");
26MODULE_LICENSE("GPL");
27
28static int probe = 0; /* Don't autoprobe */
29static unsigned size = 0x1000000; /* 16 MiB the whole ISA address space */
30static unsigned width = 8; /* Default to 8 bits wide */
31static char *flashtype = "cfi_probe";
32
33module_param(probe, int, 0);
34MODULE_PARM_DESC(probe, "Probe for a BIOS mapping");
35module_param(size, int, 0);
36MODULE_PARM_DESC(size, "Size of the flash mapping");
37module_param(width, int, 0);
38MODULE_PARM_DESC(width, "Data width of the flash mapping (8/16)");
39module_param(flashtype, charp, 0);
40MODULE_PARM_DESC(flashtype, "Type of MTD probe to do");
41
42static struct resource docmem = {
43 .flags = IORESOURCE_MEM,
44 .name = "NatSemi SCx200 DOCCS Flash",
45};
46
47static struct mtd_info *mymtd;
48
49#ifdef CONFIG_MTD_PARTITIONS
50static struct mtd_partition partition_info[] = {
Thomas Gleixner69f34c92005-11-07 11:15:40 +000051 {
52 .name = "DOCCS Boot kernel",
53 .offset = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .size = 0xc0000
55 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000056 {
57 .name = "DOCCS Low BIOS",
58 .offset = 0xc0000,
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 .size = 0x40000
60 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000061 {
62 .name = "DOCCS File system",
63 .offset = 0x100000,
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 .size = ~0 /* calculate from flash size */
65 },
Thomas Gleixner69f34c92005-11-07 11:15:40 +000066 {
67 .name = "DOCCS High BIOS",
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 .offset = ~0, /* calculate from flash size */
69 .size = 0x80000
70 },
71};
Tobias Klauser87d10f32006-03-31 02:29:45 -080072#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#endif
74
75
76static struct map_info scx200_docflash_map = {
77 .name = "NatSemi SCx200 DOCCS Flash",
78};
79
80static int __init init_scx200_docflash(void)
81{
82 unsigned u;
83 unsigned base;
84 unsigned ctrl;
85 unsigned pmr;
86 struct pci_dev *bridge;
87
88 printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n");
89
Alan Coxdd8e9ed2006-09-22 10:19:20 +010090 if ((bridge = pci_get_device(PCI_VENDOR_ID_NS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
92 NULL)) == NULL)
93 return -ENODEV;
94
95 /* check that we have found the configuration block */
Alan Coxdd8e9ed2006-09-22 10:19:20 +010096 if (!scx200_cb_present()) {
97 pci_dev_put(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return -ENODEV;
Alan Coxdd8e9ed2006-09-22 10:19:20 +010099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 if (probe) {
102 /* Try to use the present flash mapping if any */
103 pci_read_config_dword(bridge, SCx200_DOCCS_BASE, &base);
104 pci_read_config_dword(bridge, SCx200_DOCCS_CTRL, &ctrl);
Alan Coxdd8e9ed2006-09-22 10:19:20 +0100105 pci_dev_put(bridge);
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 pmr = inl(scx200_cb_base + SCx200_PMR);
108
109 if (base == 0
110 || (ctrl & 0x07000000) != 0x07000000
111 || (ctrl & 0x0007ffff) == 0)
112 return -ENODEV;
113
114 size = ((ctrl&0x1fff)<<13) + (1<<13);
115
116 for (u = size; u > 1; u >>= 1)
117 ;
118 if (u != 1)
119 return -ENODEV;
120
121 if (pmr & (1<<6))
122 width = 16;
123 else
124 width = 8;
125
126 docmem.start = base;
127 docmem.end = base + size;
128
129 if (request_resource(&iomem_resource, &docmem)) {
130 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
131 return -ENOMEM;
132 }
133 } else {
Alan Coxdd8e9ed2006-09-22 10:19:20 +0100134 pci_dev_put(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 for (u = size; u > 1; u >>= 1)
136 ;
137 if (u != 1) {
138 printk(KERN_ERR NAME ": invalid size for flash mapping\n");
139 return -EINVAL;
140 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (width != 8 && width != 16) {
143 printk(KERN_ERR NAME ": invalid bus width for flash mapping\n");
144 return -EINVAL;
145 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000146
147 if (allocate_resource(&iomem_resource, &docmem,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 size,
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000149 0xc0000000, 0xffffffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 size, NULL, NULL)) {
151 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
152 return -ENOMEM;
153 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 ctrl = 0x07000000 | ((size-1) >> 13);
156
157 printk(KERN_INFO "DOCCS BASE=0x%08lx, CTRL=0x%08lx\n", (long)docmem.start, (long)ctrl);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 pci_write_config_dword(bridge, SCx200_DOCCS_BASE, docmem.start);
160 pci_write_config_dword(bridge, SCx200_DOCCS_CTRL, ctrl);
161 pmr = inl(scx200_cb_base + SCx200_PMR);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (width == 8) {
164 pmr &= ~(1<<6);
165 } else {
166 pmr |= (1<<6);
167 }
168 outl(pmr, scx200_cb_base + SCx200_PMR);
169 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000170
Greg Kroah-Hartman176dfc62006-06-12 15:15:17 -0700171 printk(KERN_INFO NAME ": DOCCS mapped at 0x%llx-0x%llx, width %d\n",
172 (unsigned long long)docmem.start,
173 (unsigned long long)docmem.end, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 scx200_docflash_map.size = size;
176 if (width == 8)
177 scx200_docflash_map.bankwidth = 1;
178 else
179 scx200_docflash_map.bankwidth = 2;
180
181 simple_map_init(&scx200_docflash_map);
182
183 scx200_docflash_map.phys = docmem.start;
184 scx200_docflash_map.virt = ioremap(docmem.start, scx200_docflash_map.size);
185 if (!scx200_docflash_map.virt) {
186 printk(KERN_ERR NAME ": failed to ioremap the flash\n");
187 release_resource(&docmem);
188 return -EIO;
189 }
190
191 mymtd = do_map_probe(flashtype, &scx200_docflash_map);
192 if (!mymtd) {
193 printk(KERN_ERR NAME ": unable to detect flash\n");
194 iounmap(scx200_docflash_map.virt);
195 release_resource(&docmem);
196 return -ENXIO;
197 }
198
199 if (size < mymtd->size)
200 printk(KERN_WARNING NAME ": warning, flash mapping is smaller than flash size\n");
201
202 mymtd->owner = THIS_MODULE;
203
204#ifdef CONFIG_MTD_PARTITIONS
205 partition_info[3].offset = mymtd->size-partition_info[3].size;
206 partition_info[2].size = partition_info[3].offset-partition_info[2].offset;
207 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
208#else
209 add_mtd_device(mymtd);
210#endif
211 return 0;
212}
213
214static void __exit cleanup_scx200_docflash(void)
215{
216 if (mymtd) {
217#ifdef CONFIG_MTD_PARTITIONS
218 del_mtd_partitions(mymtd);
219#else
220 del_mtd_device(mymtd);
221#endif
222 map_destroy(mymtd);
223 }
224 if (scx200_docflash_map.virt) {
225 iounmap(scx200_docflash_map.virt);
226 release_resource(&docmem);
227 }
228}
229
230module_init(init_scx200_docflash);
231module_exit(cleanup_scx200_docflash);
232
233/*
234 Local variables:
235 compile-command: "make -k -C ../../.. SUBDIRS=drivers/mtd/maps modules"
236 c-basic-offset: 8
237 End:
238*/