ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / zalon.c
1 /*
2  * Zalon 53c7xx device driver.
3  * By Richard Hirst (rhirst@linuxcare.com)
4  */
5
6 #include <linux/init.h>
7 #include <linux/types.h>
8 #include <linux/stat.h>
9 #include <linux/mm.h>
10 #include <linux/blkdev.h>
11 #include <linux/sched.h>
12 #include <linux/version.h>
13 #include <linux/config.h>
14 #include <linux/module.h>
15
16 #include <scsi/scsicam.h>
17
18 #include <asm/page.h>
19 #include <asm/pgtable.h>
20 #include <asm/irq.h>
21 #include <asm/hardware.h>
22 #include <asm/delay.h>
23 #include <asm/io.h>
24
25 #include "../parisc/gsc.h"
26 #include "scsi.h"
27 #include "hosts.h"
28
29 #include "ncr53c8xx.h"
30
31 MODULE_AUTHOR("Richard Hirst");
32 MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
33 MODULE_LICENSE("GPL");
34
35 #define GSC_SCSI_ZALON_OFFSET 0x800
36
37 #define IO_MODULE_EIM           (1*4)
38 #define IO_MODULE_DC_ADATA      (2*4)
39 #define IO_MODULE_II_CDATA      (3*4)
40 #define IO_MODULE_IO_COMMAND    (12*4)
41 #define IO_MODULE_IO_STATUS     (13*4)
42
43 #define IOSTATUS_RY             0x40
44 #define IOSTATUS_FE             0x80
45 #define IOIIDATA_SMINT5L        0x40000000
46 #define IOIIDATA_MINT5EN        0x20000000
47 #define IOIIDATA_PACKEN         0x10000000
48 #define IOIIDATA_PREFETCHEN     0x08000000
49 #define IOIIDATA_IOII           0x00000020
50
51 #define CMD_RESET               5
52
53 static ncr_chip zalon720_chip __initdata = {
54         .device_id =    PSEUDO_720_ID,
55         .revision_id =  0x0f,
56         .name =         "720",
57         .burst_max =    3,
58         .offset_max =   8,
59         .nr_divisor =   4,
60         .features =     FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
61 };
62
63
64
65 #if 0
66 /* FIXME:
67  * Is this function dead code? or is someone planning on using it in the
68  * future.  The clock = (int) pdc_result[16] does not look correct to
69  * me ... I think it should be iodc_data[16].  Since this cause a compile
70  * error with the new encapsulated PDC, I'm not compiling in this function.
71  * - RB
72  */
73 /* poke SCSI clock out of iodc data */
74
75 static u8 iodc_data[32] __attribute__ ((aligned (64)));
76 static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
77
78 static int 
79 lasi_scsi_clock(void * hpa, int defaultclock)
80 {
81         int clock, status;
82
83         status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
84         if (status == PDC_RET_OK) {
85                 clock = (int) pdc_result[16];
86         } else {
87                 printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __FUNCTION__, status);
88                 clock = defaultclock; 
89         }
90
91         printk(KERN_DEBUG "%s: SCSI clock %d\n", __FUNCTION__, clock);
92         return clock;
93 }
94 #endif
95
96 static Scsi_Host_Template zalon7xx_template = {
97         .module         = THIS_MODULE,
98         .proc_name      = "zalon7xx",
99 };
100
101 static int __init
102 zalon_probe(struct parisc_device *dev)
103 {
104         struct gsc_irq gsc_irq;
105         u32 zalon_vers;
106         int irq, error = -ENODEV;
107         unsigned long zalon = dev->hpa;
108         unsigned long io_port = zalon + GSC_SCSI_ZALON_OFFSET;
109         static int unit = 0;
110         struct Scsi_Host *host;
111         struct ncr_device device;
112
113         __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
114         while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
115                 ;
116         __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
117                 zalon + IO_MODULE_II_CDATA);
118
119         /* XXX: Save the Zalon version for bug workarounds? */
120         zalon_vers = __raw_readl(dev->hpa + IO_MODULE_II_CDATA) & 0x07000000;
121         zalon_vers >>= 24;
122
123         /* Setup the interrupts first.
124         ** Later on request_irq() will register the handler.
125         */
126         irq = gsc_alloc_irq(&gsc_irq);
127
128         printk("%s: Zalon vers field is 0x%x, IRQ %d\n", __FUNCTION__,
129                 zalon_vers, irq);
130
131         __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, dev->hpa + IO_MODULE_EIM);
132
133         if (zalon_vers == 0)
134                 printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __FUNCTION__);
135
136         memset(&device, 0, sizeof(struct ncr_device));
137
138         /* The following three are needed before any other access. */
139         writeb(0x20, io_port + 0x38); /* DCNTL_REG,  EA  */
140         writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
141         writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
142
143         /* Initialise ncr_device structure with items required by ncr_attach. */
144         device.chip             = zalon720_chip;
145         device.host_id          = 7;
146         device.dev              = &dev->dev;
147         device.slot.base        = (u_long)io_port;
148         device.slot.base_c      = (u_long)io_port;
149         device.slot.irq         = irq;
150         device.differential     = 2;
151
152         host = ncr_attach(&zalon7xx_template, unit, &device);
153         if (!host)
154                 goto fail;
155
156         if (request_irq(irq, ncr53c8xx_intr, SA_SHIRQ, dev->dev.bus_id, host)) {
157                 printk(KERN_ERR "%s: irq problem with %d, detaching\n ",
158                        dev->dev.bus_id, irq);
159                 goto fail;
160         }
161
162         unit++;
163
164         dev_set_drvdata(&dev->dev, host);
165
166         error = scsi_add_host(host, &dev->dev);
167         if (error)
168                 goto fail_free_irq;
169
170         scsi_scan_host(host);
171         return 0;
172
173  fail_free_irq:
174         free_irq(irq, host);
175  fail:
176         ncr53c8xx_release(host);
177         return error;
178 }
179
180 static struct parisc_device_id zalon_tbl[] = {
181         { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 
182         { 0, }
183 };
184
185 MODULE_DEVICE_TABLE(parisc, zalon_tbl);
186
187 static int __exit zalon_remove(struct parisc_device *dev)
188 {
189         struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
190         int irq = host->irq;
191
192         scsi_remove_host(host);
193         ncr53c8xx_release(host);
194         free_irq(irq, host);
195
196         return 0;
197 }
198         
199
200 static struct parisc_driver zalon_driver = {
201         .name =         "GSC SCSI (Zalon)",
202         .id_table =     zalon_tbl,
203         .probe =        zalon_probe,
204         .remove =       __devexit_p(zalon_remove),
205 };
206
207 static int __init zalon7xx_init(void)
208 {
209         return register_parisc_driver(&zalon_driver);
210 }
211
212 static void __exit zalon7xx_exit(void)
213 {
214         unregister_parisc_driver(&zalon_driver);
215 }
216
217 module_init(zalon7xx_init);
218 module_exit(zalon7xx_exit);