Merge with Linux 2.5.74.
[linux-2.6/linux-mips.git] / drivers / scsi / zalon.c
blob81aa5551fcb3a805713fce0180842cb9367d0a0d
1 /*
2 * Zalon 53c7xx device driver.
3 * By Richard Hirst (rhirst@linuxcare.com)
4 */
6 #include <linux/init.h>
7 #include <linux/types.h>
8 #include <linux/stat.h>
9 #include <linux/mm.h>
10 #include <linux/blk.h>
11 #include <linux/sched.h>
12 #include <linux/version.h>
13 #include <linux/config.h>
14 #include <linux/module.h>
16 #include <asm/page.h>
17 #include <asm/pgtable.h>
18 #include <asm/irq.h>
19 #include <asm/hardware.h>
20 #include <asm/delay.h>
21 #include <asm/io.h>
23 #include "../parisc/gsc.h"
24 #include "scsi.h"
25 #include "hosts.h"
27 #include "ncr53c8xx.h"
29 #include "zalon.h"
31 MODULE_AUTHOR("Richard Hirst");
32 MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
33 MODULE_LICENSE("GPL");
35 static ncr_chip zalon720_chip __initdata = {
36 .device_id = PSEUDO_720_ID,
37 .revision_id = 0x0f,
38 .name = "720",
39 .burst_max = 3,
40 .offset_max = 8,
41 .nr_divisor = 4,
42 .features = FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
47 #if 0
48 /* FIXME:
49 * Is this function dead code? or is someone planning on using it in the
50 * future. The clock = (int) pdc_result[16] does not look correct to
51 * me ... I think it should be iodc_data[16]. Since this cause a compile
52 * error with the new encapsulated PDC, I'm not compiling in this function.
53 * - RB
55 /* poke SCSI clock out of iodc data */
57 static u8 iodc_data[32] __attribute__ ((aligned (64)));
58 static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
60 static int
61 lasi_scsi_clock(void * hpa, int defaultclock)
63 int clock, status;
65 status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
66 if (status == PDC_RET_OK) {
67 clock = (int) pdc_result[16];
68 } else {
69 printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __FUNCTION__, status);
70 clock = defaultclock;
73 printk(KERN_DEBUG "%s: SCSI clock %d\n", __FUNCTION__, clock);
74 return clock;
76 #endif
78 static Scsi_Host_Template zalon7xx_template = {
79 .module = THIS_MODULE,
80 .proc_name = "zalon7xx",
83 static int __init
84 zalon_scsi_callback(struct parisc_device *dev)
86 struct gsc_irq gsc_irq;
87 u32 zalon_vers;
88 int irq;
89 unsigned long zalon = dev->hpa;
90 unsigned long io_port = zalon + GSC_SCSI_ZALON_OFFSET;
91 static int unit = 0;
92 struct Scsi_Host *host;
93 ncr_device device;
95 __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
96 while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
98 __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
99 zalon + IO_MODULE_II_CDATA);
101 /* XXX: Save the Zalon version for bug workarounds? */
102 zalon_vers = __raw_readl(dev->hpa + IO_MODULE_II_CDATA) & 0x07000000;
103 zalon_vers >>= 24;
105 /* Setup the interrupts first.
106 ** Later on request_irq() will register the handler.
108 irq = gsc_alloc_irq(&gsc_irq);
110 printk("%s: Zalon vers field is 0x%x, IRQ %d\n", __FUNCTION__,
111 zalon_vers, irq);
113 __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, dev->hpa + IO_MODULE_EIM);
115 if ( zalon_vers == 0)
116 printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __FUNCTION__);
118 memset(&device, 0, sizeof(ncr_device));
120 /* The following three are needed before any other access. */
121 writeb(0x20, io_port + 0x38); /* DCNTL_REG, EA */
122 writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
123 writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
125 /* Initialise ncr_device structure with items required by ncr_attach. */
126 device.chip = zalon720_chip;
127 device.host_id = 7;
128 device.dev = &dev->dev;
129 device.slot.base = (u_long)io_port;
130 device.slot.base_c = (u_long)io_port;
131 device.slot.irq = irq;
132 device.differential = 2;
134 host = ncr_attach(&zalon7xx_template, unit, &device);
135 if(!host)
136 goto fail;
138 strlcpy(dev->dev.name, "zalon7xx", sizeof(dev->dev.name));
140 if(request_irq(irq, ncr53c8xx_intr, SA_SHIRQ, dev->dev.name, host)) {
141 printk(KERN_ERR "%s: irq problem with %d, detaching\n ",
142 dev->dev.name, irq);
143 goto fail;
146 unit++;
148 dev_set_drvdata(&dev->dev, host);
150 scsi_add_host(host, &dev->dev);
152 return 0;
153 fail:
154 return -ENODEV;
157 static struct parisc_device_id zalon_tbl[] = {
158 { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 },
159 { 0, }
162 MODULE_DEVICE_TABLE(parisc, zalon_tbl);
164 static int __exit zalon_remove(struct parisc_device *dev)
166 struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
167 int irq = host->irq;
169 scsi_remove_host(host);
170 ncr53c8xx_release(host);
171 free_irq(irq, host);
173 return 0;
177 static struct parisc_driver zalon_driver = {
178 .name = "GSC SCSI (Zalon)",
179 .id_table = zalon_tbl,
180 .probe = zalon_scsi_callback,
181 .remove = __devexit_p(zalon_remove),
184 static int __init zalon7xx_init(void)
186 return register_parisc_driver(&zalon_driver);
189 static void __exit zalon7xx_exit(void)
191 unregister_parisc_driver(&zalon_driver);
194 module_init(zalon7xx_init);
195 module_exit(zalon7xx_exit);