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/blk.h>
11 #include <linux/sched.h>
12 #include <linux/version.h>
13 #include <linux/config.h>
14 #include <linux/module.h>
15
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/gsc.h>
22
23 #include "scsi.h"
24 #include "hosts.h"
25
26 /*
27 * ** Define the BSD style u_int32 and u_int64 type.
28 * ** Are in fact u_int32_t and u_int64_t :-)
29 * */
30 typedef u32 u_int32;
31 typedef u64 u_int64;
32 typedef u_long vm_offset_t;
33
34 #include "zalon7xx.h"
35
36
37 /* hosts_* are kluges to pass info between the zalon7xx_detected()
38 ** and the register_parisc_driver() callbacks.
39 */
40 static Scsi_Host_Template *hosts_tptr;
41 static int hosts_used=0;
42 static int zalon_id = 0;
43
44 extern int zalon_attach(Scsi_Host_Template *tpnt,
45 unsigned long base_addr,
46 struct parisc_device *dev,
47 int irq_vector,
48 int unit
49 );
50
51
52 #if 0
53 /* FIXME:
54 * Is this function dead code? or is someone planning on using it in the
55 * future. The clock = (int) pdc_result[16] does not look correct to
56 * me ... I think it should be iodc_data[16]. Since this cause a compile
57 * error with the new encapsulated PDC, I'm not compiling in this function.
58 * - RB
59 */
60 /* poke SCSI clock out of iodc data */
61
62 static u8 iodc_data[32] __attribute__ ((aligned (64)));
63 static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
64
65 static int
66 lasi_scsi_clock(void * hpa, int defaultclock)
67 {
68 int clock, status;
69
70 status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
71 if (status == PDC_RET_OK) {
72 clock = (int) pdc_result[16];
73 } else {
74 printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __FUNCTION__, status);
75 clock = defaultclock;
76 }
77
78 printk(KERN_DEBUG "%s: SCSI clock %d\n", __FUNCTION__, clock);
79 return clock;
80 }
81 #endif
82
83 static int __init
zalon_scsi_callback(struct parisc_device * dev)84 zalon_scsi_callback(struct parisc_device *dev)
85 {
86 struct gsc_irq gsc_irq;
87 u32 zalon_vers;
88 int irq;
89 unsigned long zalon = dev->hpa;
90
91 __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
92 while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
93 ;
94 __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
95 zalon + IO_MODULE_II_CDATA);
96
97 /* XXX: Save the Zalon version for bug workarounds? */
98 zalon_vers = __raw_readl(dev->hpa + IO_MODULE_II_CDATA) & 0x07000000;
99 zalon_vers >>= 24;
100
101 /* Setup the interrupts first.
102 ** Later on request_irq() will register the handler.
103 */
104 irq = gsc_alloc_irq(&gsc_irq);
105
106 printk("%s: Zalon vers field is 0x%x, IRQ %d\n", __FUNCTION__,
107 zalon_vers, irq);
108
109 __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, dev->hpa + IO_MODULE_EIM);
110
111 if ( zalon_vers == 0)
112 printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __FUNCTION__);
113
114 /*
115 ** zalon_attach: returns -1 on failure, 0 on success
116 */
117 hosts_used = zalon_attach(hosts_tptr, dev->hpa + GSC_SCSI_ZALON_OFFSET,
118 dev, irq, zalon_id);
119
120 if (hosts_used == 0)
121 zalon_id++;
122
123 hosts_used = (hosts_used == 0);
124 return (hosts_used == 0);
125 }
126
127 static struct parisc_device_id zalon_tbl[] = {
128 { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 },
129 { 0, }
130 };
131
132 MODULE_DEVICE_TABLE(parisc, zalon_tbl);
133
134 static struct parisc_driver zalon_driver = {
135 name: "GSC SCSI (Zalon)",
136 id_table: zalon_tbl,
137 probe: zalon_scsi_callback,
138 };
139
zalon7xx_detect(Scsi_Host_Template * tpnt)140 int zalon7xx_detect(Scsi_Host_Template *tpnt)
141 {
142 /* "pass" the parameter to the callback functions */
143 hosts_tptr = tpnt;
144 hosts_used = 0;
145
146 /* claim all zalon cards. */
147 register_parisc_driver(&zalon_driver);
148
149 /* Check if any callbacks actually found/claimed anything. */
150 return (hosts_used != 0);
151 }
152
153 #ifdef MODULE
154 extern int ncr53c8xx_release(struct Scsi_Host *host);
155
zalon7xx_release(struct Scsi_Host * host)156 int zalon7xx_release(struct Scsi_Host *host)
157 {
158 ncr53c8xx_release(host);
159 unregister_parisc_driver(&zalon_driver);
160 return 1;
161 }
162 #endif
163