2 * PMC551 PCI Mezzanine Ram Device
5 * Mark Ferrell <mferrell@mvista.com>
6 * Copyright 1999,2000 Nortel Networks
9 * As part of this driver was derived from the slram.c driver it
10 * falls under the same license, which is GNU General Public
14 * This driver is intended to support the PMC551 PCI Ram device
15 * from Ramix Inc. The PMC551 is a PMC Mezzanine module for
16 * cPCI embedded systems. The device contains a single SROM
17 * that initially programs the V370PDC chipset onboard the
18 * device, and various banks of DRAM/SDRAM onboard. This driver
19 * implements this PCI Ram device as an MTD (Memory Technology
20 * Device) so that it can be used to hold a file system, or for
21 * added swap space in embedded systems. Since the memory on
22 * this board isn't as fast as main memory we do not try to hook
23 * it into main memory as that would simply reduce performance
24 * on the system. Using it as a block device allows us to use
25 * it as high speed swap or for a high speed disk device of some
26 * sort. Which becomes very useful on diskless systems in the
27 * embedded market I might add.
30 * Due to what I assume is more buggy SROM, the 64M PMC551 I
31 * have available claims that all 4 of its DRAM banks have 64MiB
32 * of ram configured (making a grand total of 256MiB onboard).
33 * This is slightly annoying since the BAR0 size reflects the
34 * aperture size, not the dram size, and the V370PDC supplies no
35 * other method for memory size discovery. This problem is
36 * mostly only relevant when compiled as a module, as the
37 * unloading of the module with an aperture size smaller than
38 * the ram will cause the driver to detect the onboard memory
39 * size to be equal to the aperture size when the module is
40 * reloaded. Soooo, to help, the module supports an msize
41 * option to allow the specification of the onboard memory, and
42 * an asize option, to allow the specification of the aperture
43 * size. The aperture must be equal to or less then the memory
44 * size, the driver will correct this if you screw it up. This
45 * problem is not relevant for compiled in drivers as compiled
46 * in drivers only init once.
49 * Saeed Karamooz <saeed@ramix.com> of Ramix INC. for the
50 * initial example code of how to initialize this device and for
51 * help with questions I had concerning operation of the device.
53 * Most of the MTD code for this driver was originally written
54 * for the slram.o module in the MTD drivers package which
55 * allows the mapping of system memory into an MTD device.
56 * Since the PMC551 memory module is accessed in the same
57 * fashion as system memory, the slram.c code became a very nice
58 * fit to the needs of this driver. All we added was PCI
59 * detection/initialization to the driver and automatically figure
60 * out the size via the PCI detection.o, later changes by Corey
61 * Minyard set up the card to utilize a 1M sliding apature.
63 * Corey Minyard <minyard@nortelnetworks.com>
64 * * Modified driver to utilize a sliding aperture instead of
65 * mapping all memory into kernel space which turned out to
67 * * Located a bug in the SROM's initialization sequence that
68 * made the memory unusable, added a fix to code to touch up
72 * * MUST fix the init function to not spin on a register
73 * waiting for it to set .. this does not safely handle busted
74 * devices that never reset the register correctly which will
75 * cause the system to hang w/ a reboot being the only chance at
76 * recover. [sort of fixed, could be better]
77 * * Add I2C handling of the SROM so we can read the SROM's information
78 * about the aperture size. This should always accurately reflect the
79 * onboard memory size.
80 * * Comb the init routine. It's still a bit cludgy on a few things.
83 #include <linux/kernel.h>
84 #include <linux/module.h>
85 #include <asm/uaccess.h>
86 #include <linux/types.h>
87 #include <linux/init.h>
88 #include <linux/ptrace.h>
89 #include <linux/slab.h>
90 #include <linux/string.h>
91 #include <linux/timer.h>
92 #include <linux/major.h>
94 #include <linux/ioctl.h>
96 #include <linux/pci.h>
98 #include <linux/mtd/mtd.h>
99 #include <linux/mtd/pmc551.h>
101 static struct mtd_info *pmc551list;
103 static int pmc551_erase(struct mtd_info *mtd, struct erase_info *instr)
105 struct mypriv *priv = mtd->priv;
106 u32 soff_hi, soff_lo; /* start address offset hi/lo */
107 u32 eoff_hi, eoff_lo; /* end address offset hi/lo */
112 #ifdef CONFIG_MTD_PMC551_DEBUG
113 printk(KERN_DEBUG "pmc551_erase(pos:%ld, len:%ld)\n", (long)instr->addr,
117 end = instr->addr + instr->len - 1;
119 /* Is it past the end? */
120 if (end > mtd->size) {
121 #ifdef CONFIG_MTD_PMC551_DEBUG
122 printk(KERN_DEBUG "pmc551_erase() out of bounds (%ld > %ld)\n",
123 (long)end, (long)mtd->size);
128 eoff_hi = end & ~(priv->asize - 1);
129 soff_hi = instr->addr & ~(priv->asize - 1);
130 eoff_lo = end & (priv->asize - 1);
131 soff_lo = instr->addr & (priv->asize - 1);
133 pmc551_point(mtd, instr->addr, instr->len, &retlen,
134 (void **)&ptr, NULL);
136 if (soff_hi == eoff_hi || mtd->size == priv->asize) {
137 /* The whole thing fits within one access, so just one shot
139 memset(ptr, 0xff, instr->len);
141 /* We have to do multiple writes to get all the data
143 while (soff_hi != eoff_hi) {
144 #ifdef CONFIG_MTD_PMC551_DEBUG
145 printk(KERN_DEBUG "pmc551_erase() soff_hi: %ld, "
146 "eoff_hi: %ld\n", (long)soff_hi, (long)eoff_hi);
148 memset(ptr, 0xff, priv->asize);
149 if (soff_hi + priv->asize >= mtd->size) {
152 soff_hi += priv->asize;
153 pmc551_point(mtd, (priv->base_map0 | soff_hi),
154 priv->asize, &retlen,
155 (void **)&ptr, NULL);
157 memset(ptr, 0xff, eoff_lo);
161 instr->state = MTD_ERASE_DONE;
162 #ifdef CONFIG_MTD_PMC551_DEBUG
163 printk(KERN_DEBUG "pmc551_erase() done\n");
166 mtd_erase_callback(instr);
170 static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
171 size_t *retlen, void **virt, resource_size_t *phys)
173 struct mypriv *priv = mtd->priv;
177 #ifdef CONFIG_MTD_PMC551_DEBUG
178 printk(KERN_DEBUG "pmc551_point(%ld, %ld)\n", (long)from, (long)len);
181 if (from + len > mtd->size) {
182 #ifdef CONFIG_MTD_PMC551_DEBUG
183 printk(KERN_DEBUG "pmc551_point() out of bounds (%ld > %ld)\n",
184 (long)from + len, (long)mtd->size);
189 /* can we return a physical address with this driver? */
193 soff_hi = from & ~(priv->asize - 1);
194 soff_lo = from & (priv->asize - 1);
196 /* Cheap hack optimization */
197 if (priv->curr_map0 != from) {
198 pci_write_config_dword(priv->dev, PMC551_PCI_MEM_MAP0,
199 (priv->base_map0 | soff_hi));
200 priv->curr_map0 = soff_hi;
203 *virt = priv->start + soff_lo;
208 static void pmc551_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
210 #ifdef CONFIG_MTD_PMC551_DEBUG
211 printk(KERN_DEBUG "pmc551_unpoint()\n");
215 static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
216 size_t * retlen, u_char * buf)
218 struct mypriv *priv = mtd->priv;
219 u32 soff_hi, soff_lo; /* start address offset hi/lo */
220 u32 eoff_hi, eoff_lo; /* end address offset hi/lo */
223 u_char *copyto = buf;
225 #ifdef CONFIG_MTD_PMC551_DEBUG
226 printk(KERN_DEBUG "pmc551_read(pos:%ld, len:%ld) asize: %ld\n",
227 (long)from, (long)len, (long)priv->asize);
230 end = from + len - 1;
232 /* Is it past the end? */
233 if (end > mtd->size) {
234 #ifdef CONFIG_MTD_PMC551_DEBUG
235 printk(KERN_DEBUG "pmc551_read() out of bounds (%ld > %ld)\n",
236 (long)end, (long)mtd->size);
241 soff_hi = from & ~(priv->asize - 1);
242 eoff_hi = end & ~(priv->asize - 1);
243 soff_lo = from & (priv->asize - 1);
244 eoff_lo = end & (priv->asize - 1);
246 pmc551_point(mtd, from, len, retlen, (void **)&ptr, NULL);
248 if (soff_hi == eoff_hi) {
249 /* The whole thing fits within one access, so just one shot
251 memcpy(copyto, ptr, len);
254 /* We have to do multiple writes to get all the data
256 while (soff_hi != eoff_hi) {
257 #ifdef CONFIG_MTD_PMC551_DEBUG
258 printk(KERN_DEBUG "pmc551_read() soff_hi: %ld, "
259 "eoff_hi: %ld\n", (long)soff_hi, (long)eoff_hi);
261 memcpy(copyto, ptr, priv->asize);
262 copyto += priv->asize;
263 if (soff_hi + priv->asize >= mtd->size) {
266 soff_hi += priv->asize;
267 pmc551_point(mtd, soff_hi, priv->asize, retlen,
268 (void **)&ptr, NULL);
270 memcpy(copyto, ptr, eoff_lo);
275 #ifdef CONFIG_MTD_PMC551_DEBUG
276 printk(KERN_DEBUG "pmc551_read() done\n");
278 *retlen = copyto - buf;
282 static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
283 size_t * retlen, const u_char * buf)
285 struct mypriv *priv = mtd->priv;
286 u32 soff_hi, soff_lo; /* start address offset hi/lo */
287 u32 eoff_hi, eoff_lo; /* end address offset hi/lo */
290 const u_char *copyfrom = buf;
292 #ifdef CONFIG_MTD_PMC551_DEBUG
293 printk(KERN_DEBUG "pmc551_write(pos:%ld, len:%ld) asize:%ld\n",
294 (long)to, (long)len, (long)priv->asize);
298 /* Is it past the end? or did the u32 wrap? */
299 if (end > mtd->size) {
300 #ifdef CONFIG_MTD_PMC551_DEBUG
301 printk(KERN_DEBUG "pmc551_write() out of bounds (end: %ld, "
302 "size: %ld, to: %ld)\n", (long)end, (long)mtd->size,
308 soff_hi = to & ~(priv->asize - 1);
309 eoff_hi = end & ~(priv->asize - 1);
310 soff_lo = to & (priv->asize - 1);
311 eoff_lo = end & (priv->asize - 1);
313 pmc551_point(mtd, to, len, retlen, (void **)&ptr, NULL);
315 if (soff_hi == eoff_hi) {
316 /* The whole thing fits within one access, so just one shot
318 memcpy(ptr, copyfrom, len);
321 /* We have to do multiple writes to get all the data
323 while (soff_hi != eoff_hi) {
324 #ifdef CONFIG_MTD_PMC551_DEBUG
325 printk(KERN_DEBUG "pmc551_write() soff_hi: %ld, "
326 "eoff_hi: %ld\n", (long)soff_hi, (long)eoff_hi);
328 memcpy(ptr, copyfrom, priv->asize);
329 copyfrom += priv->asize;
330 if (soff_hi >= mtd->size) {
333 soff_hi += priv->asize;
334 pmc551_point(mtd, soff_hi, priv->asize, retlen,
335 (void **)&ptr, NULL);
337 memcpy(ptr, copyfrom, eoff_lo);
342 #ifdef CONFIG_MTD_PMC551_DEBUG
343 printk(KERN_DEBUG "pmc551_write() done\n");
345 *retlen = copyfrom - buf;
350 * Fixup routines for the V370PDC
351 * PCI device ID 0x020011b0
353 * This function basically kick starts the DRAM oboard the card and gets it
354 * ready to be used. Before this is done the device reads VERY erratic, so
355 * much that it can crash the Linux 2.2.x series kernels when a user cat's
356 * /proc/pci .. though that is mainly a kernel bug in handling the PCI DEVSEL
357 * register. FIXME: stop spinning on registers .. must implement a timeout
359 * returns the size of the memory region found.
361 static u32 fixup_pmc551(struct pci_dev *dev)
363 #ifdef CONFIG_MTD_PMC551_BUGFIX
366 u32 size, dcmd, cfg, dtmp;
376 * Attempt to reset the card
377 * FIXME: Stop Spinning registers
380 /* unlock registers */
381 pci_write_config_byte(dev, PMC551_SYS_CTRL_REG, 0xA5);
382 /* read in old data */
383 pci_read_config_byte(dev, PMC551_SYS_CTRL_REG, &bcmd);
384 /* bang the reset line up and down for a few */
385 for (i = 0; i < 10; i++) {
388 while (counter++ < 100) {
389 pci_write_config_byte(dev, PMC551_SYS_CTRL_REG, bcmd);
393 while (counter++ < 100) {
394 pci_write_config_byte(dev, PMC551_SYS_CTRL_REG, bcmd);
397 bcmd |= (0x40 | 0x20);
398 pci_write_config_byte(dev, PMC551_SYS_CTRL_REG, bcmd);
401 * Take care and turn off the memory on the device while we
402 * tweak the configurations
404 pci_read_config_word(dev, PCI_COMMAND, &cmd);
405 tmp = cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
406 pci_write_config_word(dev, PCI_COMMAND, tmp);
409 * Disable existing aperture before probing memory size
411 pci_read_config_dword(dev, PMC551_PCI_MEM_MAP0, &dcmd);
412 dtmp = (dcmd | PMC551_PCI_MEM_MAP_ENABLE | PMC551_PCI_MEM_MAP_REG_EN);
413 pci_write_config_dword(dev, PMC551_PCI_MEM_MAP0, dtmp);
415 * Grab old BAR0 config so that we can figure out memory size
416 * This is another bit of kludge going on. The reason for the
417 * redundancy is I am hoping to retain the original configuration
418 * previously assigned to the card by the BIOS or some previous
419 * fixup routine in the kernel. So we read the old config into cfg,
420 * then write all 1's to the memory space, read back the result into
421 * "size", and then write back all the old config.
423 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &cfg);
424 #ifndef CONFIG_MTD_PMC551_BUGFIX
425 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, ~0);
426 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &size);
427 size = (size & PCI_BASE_ADDRESS_MEM_MASK);
429 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, cfg);
432 * Get the size of the memory by reading all the DRAM size values
433 * and adding them up.
435 * KLUDGE ALERT: the boards we are using have invalid column and
436 * row mux values. We fix them here, but this will break other
437 * memory configurations.
439 pci_read_config_dword(dev, PMC551_DRAM_BLK0, &dram_data);
440 size = PMC551_DRAM_BLK_GET_SIZE(dram_data);
441 dram_data = PMC551_DRAM_BLK_SET_COL_MUX(dram_data, 0x5);
442 dram_data = PMC551_DRAM_BLK_SET_ROW_MUX(dram_data, 0x9);
443 pci_write_config_dword(dev, PMC551_DRAM_BLK0, dram_data);
445 pci_read_config_dword(dev, PMC551_DRAM_BLK1, &dram_data);
446 size += PMC551_DRAM_BLK_GET_SIZE(dram_data);
447 dram_data = PMC551_DRAM_BLK_SET_COL_MUX(dram_data, 0x5);
448 dram_data = PMC551_DRAM_BLK_SET_ROW_MUX(dram_data, 0x9);
449 pci_write_config_dword(dev, PMC551_DRAM_BLK1, dram_data);
451 pci_read_config_dword(dev, PMC551_DRAM_BLK2, &dram_data);
452 size += PMC551_DRAM_BLK_GET_SIZE(dram_data);
453 dram_data = PMC551_DRAM_BLK_SET_COL_MUX(dram_data, 0x5);
454 dram_data = PMC551_DRAM_BLK_SET_ROW_MUX(dram_data, 0x9);
455 pci_write_config_dword(dev, PMC551_DRAM_BLK2, dram_data);
457 pci_read_config_dword(dev, PMC551_DRAM_BLK3, &dram_data);
458 size += PMC551_DRAM_BLK_GET_SIZE(dram_data);
459 dram_data = PMC551_DRAM_BLK_SET_COL_MUX(dram_data, 0x5);
460 dram_data = PMC551_DRAM_BLK_SET_ROW_MUX(dram_data, 0x9);
461 pci_write_config_dword(dev, PMC551_DRAM_BLK3, dram_data);
464 * Oops .. something went wrong
466 if ((size &= PCI_BASE_ADDRESS_MEM_MASK) == 0) {
469 #endif /* CONFIG_MTD_PMC551_BUGFIX */
471 if ((cfg & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_MEMORY) {
478 pci_write_config_word(dev, PMC551_SDRAM_MA, 0x0400);
479 pci_write_config_word(dev, PMC551_SDRAM_CMD, 0x00bf);
482 * Wait until command has gone through
483 * FIXME: register spinning issue
486 pci_read_config_word(dev, PMC551_SDRAM_CMD, &cmd);
489 } while ((PCI_COMMAND_IO) & cmd);
492 * Turn on auto refresh
493 * The loop is taken directly from Ramix's example code. I assume that
494 * this must be held high for some duration of time, but I can find no
495 * documentation refrencing the reasons why.
497 for (i = 1; i <= 8; i++) {
498 pci_write_config_word(dev, PMC551_SDRAM_CMD, 0x0df);
501 * Make certain command has gone through
502 * FIXME: register spinning issue
506 pci_read_config_word(dev, PMC551_SDRAM_CMD, &cmd);
509 } while ((PCI_COMMAND_IO) & cmd);
512 pci_write_config_word(dev, PMC551_SDRAM_MA, 0x0020);
513 pci_write_config_word(dev, PMC551_SDRAM_CMD, 0x0ff);
516 * Wait until command completes
517 * FIXME: register spinning issue
521 pci_read_config_word(dev, PMC551_SDRAM_CMD, &cmd);
524 } while ((PCI_COMMAND_IO) & cmd);
526 pci_read_config_dword(dev, PMC551_DRAM_CFG, &dcmd);
528 pci_write_config_dword(dev, PMC551_DRAM_CFG, dcmd);
531 * Check to make certain fast back-to-back, if not
534 pci_read_config_word(dev, PCI_STATUS, &cmd);
535 if ((cmd & PCI_COMMAND_FAST_BACK) == 0) {
536 cmd |= PCI_COMMAND_FAST_BACK;
537 pci_write_config_word(dev, PCI_STATUS, cmd);
541 * Check to make certain the DEVSEL is set correctly, this device
542 * has a tendency to assert DEVSEL and TRDY when a write is performed
543 * to the memory when memory is read-only
545 if ((cmd & PCI_STATUS_DEVSEL_MASK) != 0x0) {
546 cmd &= ~PCI_STATUS_DEVSEL_MASK;
547 pci_write_config_word(dev, PCI_STATUS, cmd);
550 * Set to be prefetchable and put everything back based on old cfg.
551 * it's possible that the reset of the V370PDC nuked the original
555 cfg |= PCI_BASE_ADDRESS_MEM_PREFETCH;
556 pci_write_config_dword( dev, PCI_BASE_ADDRESS_0, cfg );
560 * Turn PCI memory and I/O bus access back on
562 pci_write_config_word(dev, PCI_COMMAND,
563 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
564 #ifdef CONFIG_MTD_PMC551_DEBUG
568 printk(KERN_DEBUG "pmc551: %d%sB (0x%x) of %sprefetchable memory at "
569 "0x%llx\n", (size < 1024) ? size : (size < 1048576) ?
570 size >> 10 : size >> 20,
571 (size < 1024) ? "" : (size < 1048576) ? "Ki" : "Mi", size,
572 ((dcmd & (0x1 << 3)) == 0) ? "non-" : "",
573 (unsigned long long)pci_resource_start(dev, 0));
576 * Check to see the state of the memory
578 pci_read_config_dword(dev, PMC551_DRAM_BLK0, &dcmd);
579 printk(KERN_DEBUG "pmc551: DRAM_BLK0 Flags: %s,%s\n"
580 "pmc551: DRAM_BLK0 Size: %d at %d\n"
581 "pmc551: DRAM_BLK0 Row MUX: %d, Col MUX: %d\n",
582 (((0x1 << 1) & dcmd) == 0) ? "RW" : "RO",
583 (((0x1 << 0) & dcmd) == 0) ? "Off" : "On",
584 PMC551_DRAM_BLK_GET_SIZE(dcmd),
585 ((dcmd >> 20) & 0x7FF), ((dcmd >> 13) & 0x7),
586 ((dcmd >> 9) & 0xF));
588 pci_read_config_dword(dev, PMC551_DRAM_BLK1, &dcmd);
589 printk(KERN_DEBUG "pmc551: DRAM_BLK1 Flags: %s,%s\n"
590 "pmc551: DRAM_BLK1 Size: %d at %d\n"
591 "pmc551: DRAM_BLK1 Row MUX: %d, Col MUX: %d\n",
592 (((0x1 << 1) & dcmd) == 0) ? "RW" : "RO",
593 (((0x1 << 0) & dcmd) == 0) ? "Off" : "On",
594 PMC551_DRAM_BLK_GET_SIZE(dcmd),
595 ((dcmd >> 20) & 0x7FF), ((dcmd >> 13) & 0x7),
596 ((dcmd >> 9) & 0xF));
598 pci_read_config_dword(dev, PMC551_DRAM_BLK2, &dcmd);
599 printk(KERN_DEBUG "pmc551: DRAM_BLK2 Flags: %s,%s\n"
600 "pmc551: DRAM_BLK2 Size: %d at %d\n"
601 "pmc551: DRAM_BLK2 Row MUX: %d, Col MUX: %d\n",
602 (((0x1 << 1) & dcmd) == 0) ? "RW" : "RO",
603 (((0x1 << 0) & dcmd) == 0) ? "Off" : "On",
604 PMC551_DRAM_BLK_GET_SIZE(dcmd),
605 ((dcmd >> 20) & 0x7FF), ((dcmd >> 13) & 0x7),
606 ((dcmd >> 9) & 0xF));
608 pci_read_config_dword(dev, PMC551_DRAM_BLK3, &dcmd);
609 printk(KERN_DEBUG "pmc551: DRAM_BLK3 Flags: %s,%s\n"
610 "pmc551: DRAM_BLK3 Size: %d at %d\n"
611 "pmc551: DRAM_BLK3 Row MUX: %d, Col MUX: %d\n",
612 (((0x1 << 1) & dcmd) == 0) ? "RW" : "RO",
613 (((0x1 << 0) & dcmd) == 0) ? "Off" : "On",
614 PMC551_DRAM_BLK_GET_SIZE(dcmd),
615 ((dcmd >> 20) & 0x7FF), ((dcmd >> 13) & 0x7),
616 ((dcmd >> 9) & 0xF));
618 pci_read_config_word(dev, PCI_COMMAND, &cmd);
619 printk(KERN_DEBUG "pmc551: Memory Access %s\n",
620 (((0x1 << 1) & cmd) == 0) ? "off" : "on");
621 printk(KERN_DEBUG "pmc551: I/O Access %s\n",
622 (((0x1 << 0) & cmd) == 0) ? "off" : "on");
624 pci_read_config_word(dev, PCI_STATUS, &cmd);
625 printk(KERN_DEBUG "pmc551: Devsel %s\n",
626 ((PCI_STATUS_DEVSEL_MASK & cmd) == 0x000) ? "Fast" :
627 ((PCI_STATUS_DEVSEL_MASK & cmd) == 0x200) ? "Medium" :
628 ((PCI_STATUS_DEVSEL_MASK & cmd) == 0x400) ? "Slow" : "Invalid");
630 printk(KERN_DEBUG "pmc551: %sFast Back-to-Back\n",
631 ((PCI_COMMAND_FAST_BACK & cmd) == 0) ? "Not " : "");
633 pci_read_config_byte(dev, PMC551_SYS_CTRL_REG, &bcmd);
634 printk(KERN_DEBUG "pmc551: EEPROM is under %s control\n"
635 "pmc551: System Control Register is %slocked to PCI access\n"
636 "pmc551: System Control Register is %slocked to EEPROM access\n",
637 (bcmd & 0x1) ? "software" : "hardware",
638 (bcmd & 0x20) ? "" : "un", (bcmd & 0x40) ? "" : "un");
644 * Kernel version specific module stuffages
647 MODULE_LICENSE("GPL");
648 MODULE_AUTHOR("Mark Ferrell <mferrell@mvista.com>");
649 MODULE_DESCRIPTION(PMC551_VERSION);
652 * Stuff these outside the ifdef so as to not bust compiled in driver support
654 static int msize = 0;
655 static int asize = 0;
657 module_param(msize, int, 0);
658 MODULE_PARM_DESC(msize, "memory size in MiB [1 - 1024]");
659 module_param(asize, int, 0);
660 MODULE_PARM_DESC(asize, "aperture size, must be <= memsize [1-1024]");
663 * PMC551 Card Initialization
665 static int __init init_pmc551(void)
667 struct pci_dev *PCI_Device = NULL;
670 struct mtd_info *mtd;
674 msize = (1 << (ffs(msize) - 1)) << 20;
675 if (msize > (1 << 30)) {
676 printk(KERN_NOTICE "pmc551: Invalid memory size [%d]\n",
683 asize = (1 << (ffs(asize) - 1)) << 20;
684 if (asize > (1 << 30)) {
685 printk(KERN_NOTICE "pmc551: Invalid aperture size "
691 printk(KERN_INFO PMC551_VERSION);
694 * PCU-bus chipset probe.
698 if ((PCI_Device = pci_get_device(PCI_VENDOR_ID_V3_SEMI,
699 PCI_DEVICE_ID_V3_SEMI_V370PDC,
700 PCI_Device)) == NULL) {
704 printk(KERN_NOTICE "pmc551: Found PCI V370PDC at 0x%llx\n",
705 (unsigned long long)pci_resource_start(PCI_Device, 0));
708 * The PMC551 device acts VERY weird if you don't init it
709 * first. i.e. it will not correctly report devsel. If for
710 * some reason the sdram is in a wrote-protected state the
711 * device will DEVSEL when it is written to causing problems
712 * with the oldproc.c driver in
713 * some kernels (2.2.*)
715 if ((length = fixup_pmc551(PCI_Device)) <= 0) {
716 printk(KERN_NOTICE "pmc551: Cannot init SDRAM\n");
721 * This is needed until the driver is capable of reading the
722 * onboard I2C SROM to discover the "real" memory size.
726 printk(KERN_NOTICE "pmc551: Using specified memory "
727 "size 0x%x\n", length);
732 mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
734 printk(KERN_NOTICE "pmc551: Cannot allocate new MTD "
739 priv = kzalloc(sizeof(struct mypriv), GFP_KERNEL);
741 printk(KERN_NOTICE "pmc551: Cannot allocate new MTD "
747 priv->dev = PCI_Device;
749 if (asize > length) {
750 printk(KERN_NOTICE "pmc551: reducing aperture size to "
751 "fit %dM\n", length >> 20);
752 priv->asize = asize = length;
753 } else if (asize == 0 || asize == length) {
754 printk(KERN_NOTICE "pmc551: Using existing aperture "
755 "size %dM\n", length >> 20);
756 priv->asize = asize = length;
758 printk(KERN_NOTICE "pmc551: Using specified aperture "
759 "size %dM\n", asize >> 20);
762 priv->start = pci_iomap(PCI_Device, 0, priv->asize);
765 printk(KERN_NOTICE "pmc551: Unable to map IO space\n");
770 #ifdef CONFIG_MTD_PMC551_DEBUG
771 printk(KERN_DEBUG "pmc551: setting aperture to %d\n",
772 ffs(priv->asize >> 20) - 1);
775 priv->base_map0 = (PMC551_PCI_MEM_MAP_REG_EN
776 | PMC551_PCI_MEM_MAP_ENABLE
777 | (ffs(priv->asize >> 20) - 1) << 4);
778 priv->curr_map0 = priv->base_map0;
779 pci_write_config_dword(priv->dev, PMC551_PCI_MEM_MAP0,
782 #ifdef CONFIG_MTD_PMC551_DEBUG
783 printk(KERN_DEBUG "pmc551: aperture set to %d\n",
784 (priv->base_map0 & 0xF0) >> 4);
788 mtd->flags = MTD_CAP_RAM;
789 mtd->erase = pmc551_erase;
790 mtd->read = pmc551_read;
791 mtd->write = pmc551_write;
792 mtd->point = pmc551_point;
793 mtd->unpoint = pmc551_unpoint;
795 mtd->name = "PMC551 RAM board";
796 mtd->erasesize = 0x10000;
798 mtd->owner = THIS_MODULE;
800 if (mtd_device_register(mtd, NULL, 0)) {
801 printk(KERN_NOTICE "pmc551: Failed to register new device\n");
802 pci_iounmap(PCI_Device, priv->start);
808 /* Keep a reference as the mtd_device_register worked */
809 pci_dev_get(PCI_Device);
811 printk(KERN_NOTICE "Registered pmc551 memory device.\n");
812 printk(KERN_NOTICE "Mapped %dMiB of memory from 0x%p to 0x%p\n",
814 priv->start, priv->start + priv->asize);
815 printk(KERN_NOTICE "Total memory is %d%sB\n",
816 (length < 1024) ? length :
817 (length < 1048576) ? length >> 10 : length >> 20,
818 (length < 1024) ? "" : (length < 1048576) ? "Ki" : "Mi");
819 priv->nextpmc551 = pmc551list;
824 /* Exited early, reference left over */
826 pci_dev_put(PCI_Device);
829 printk(KERN_NOTICE "pmc551: not detected\n");
832 printk(KERN_NOTICE "pmc551: %d pmc551 devices loaded\n", found);
838 * PMC551 Card Cleanup
840 static void __exit cleanup_pmc551(void)
843 struct mtd_info *mtd;
846 while ((mtd = pmc551list)) {
848 pmc551list = priv->nextpmc551;
851 printk(KERN_DEBUG "pmc551: unmapping %dMiB starting at "
852 "0x%p\n", priv->asize >> 20, priv->start);
853 pci_iounmap(priv->dev, priv->start);
855 pci_dev_put(priv->dev);
858 mtd_device_unregister(mtd);
863 printk(KERN_NOTICE "pmc551: %d pmc551 devices unloaded\n", found);
866 module_init(init_pmc551);
867 module_exit(cleanup_pmc551);