1 #include <linux/types.h>
4 #include <linux/sched.h>
5 #include <linux/version.h>
6 #include <linux/init.h>
10 #include <asm/pgtable.h>
11 #include <asm/amigaints.h>
12 #include <asm/amigahw.h>
13 #include <linux/zorro.h>
15 #include <linux/spinlock.h>
22 #include<linux/stat.h>
24 #define DMA(ptr) ((gvp11_scsiregs *)((ptr)->base))
25 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
27 static struct Scsi_Host
*first_instance
= NULL
;
28 static Scsi_Host_Template
*gvp11_template
;
30 static void gvp11_intr (int irq
, void *dummy
, struct pt_regs
*fp
)
34 struct Scsi_Host
*instance
;
36 for (instance
= first_instance
; instance
&&
37 instance
->hostt
== gvp11_template
; instance
= instance
->next
)
39 status
= DMA(instance
)->CNTR
;
40 if (!(status
& GVP11_DMAC_INT_PENDING
))
43 spin_lock_irqsave(&io_request_lock
, flags
);
44 wd33c93_intr (instance
);
45 spin_unlock_irqrestore(&io_request_lock
, flags
);
49 static int gvp11_xfer_mask
= 0;
51 void gvp11_setup (char *str
, int *ints
)
53 gvp11_xfer_mask
= ints
[1];
56 static int dma_setup (Scsi_Cmnd
*cmd
, int dir_in
)
58 unsigned short cntr
= GVP11_DMAC_INT_ENABLE
;
59 unsigned long addr
= virt_to_bus(cmd
->SCp
.ptr
);
61 static int scsi_alloc_out_of_range
= 0;
63 /* use bounce buffer if the physical address is bad */
64 if (addr
& HDATA(cmd
->host
)->dma_xfer_mask
||
65 (!dir_in
&& mm_end_of_chunk (addr
, cmd
->SCp
.this_residual
)))
67 HDATA(cmd
->host
)->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511)
70 if( !scsi_alloc_out_of_range
) {
71 HDATA(cmd
->host
)->dma_bounce_buffer
=
72 scsi_malloc (HDATA(cmd
->host
)->dma_bounce_len
);
73 HDATA(cmd
->host
)->dma_buffer_pool
= BUF_SCSI_ALLOCED
;
76 if ( scsi_alloc_out_of_range
|| !HDATA(cmd
->host
)->dma_bounce_buffer
) {
77 HDATA(cmd
->host
)->dma_bounce_buffer
=
78 amiga_chip_alloc(HDATA(cmd
->host
)->dma_bounce_len
,
79 "GVP II SCSI Bounce Buffer");
81 if(!HDATA(cmd
->host
)->dma_bounce_buffer
)
83 HDATA(cmd
->host
)->dma_bounce_len
= 0;
87 HDATA(cmd
->host
)->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
90 /* check if the address of the bounce buffer is OK */
91 addr
= virt_to_bus(HDATA(cmd
->host
)->dma_bounce_buffer
);
93 if (addr
& HDATA(cmd
->host
)->dma_xfer_mask
) {
94 /* fall back to Chip RAM if address out of range */
95 if( HDATA(cmd
->host
)->dma_buffer_pool
== BUF_SCSI_ALLOCED
) {
96 scsi_free (HDATA(cmd
->host
)->dma_bounce_buffer
,
97 HDATA(cmd
->host
)->dma_bounce_len
);
98 scsi_alloc_out_of_range
= 1;
100 amiga_chip_free (HDATA(cmd
->host
)->dma_bounce_buffer
);
103 HDATA(cmd
->host
)->dma_bounce_buffer
=
104 amiga_chip_alloc(HDATA(cmd
->host
)->dma_bounce_len
,
105 "GVP II SCSI Bounce Buffer");
107 if(!HDATA(cmd
->host
)->dma_bounce_buffer
)
109 HDATA(cmd
->host
)->dma_bounce_len
= 0;
113 addr
= virt_to_bus(HDATA(cmd
->host
)->dma_bounce_buffer
);
114 HDATA(cmd
->host
)->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
118 /* copy to bounce buffer for a write */
119 memcpy (HDATA(cmd
->host
)->dma_bounce_buffer
,
120 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
124 /* setup dma direction */
126 cntr
|= GVP11_DMAC_DIR_WRITE
;
128 HDATA(cmd
->host
)->dma_dir
= dir_in
;
129 DMA(cmd
->host
)->CNTR
= cntr
;
131 /* setup DMA *physical* address */
132 DMA(cmd
->host
)->ACR
= addr
;
135 /* invalidate any cache */
136 cache_clear (addr
, cmd
->SCp
.this_residual
);
138 /* push any dirty cache */
139 cache_push (addr
, cmd
->SCp
.this_residual
);
141 if ((bank_mask
= (~HDATA(cmd
->host
)->dma_xfer_mask
>> 18) & 0x01c0))
142 DMA(cmd
->host
)->BANK
= bank_mask
& (addr
>> 18);
145 DMA(cmd
->host
)->ST_DMA
= 1;
151 static void dma_stop (struct Scsi_Host
*instance
, Scsi_Cmnd
*SCpnt
,
155 DMA(instance
)->SP_DMA
= 1;
156 /* remove write bit from CONTROL bits */
157 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
159 /* copy from a bounce buffer, if necessary */
160 if (status
&& HDATA(instance
)->dma_bounce_buffer
) {
161 if (HDATA(instance
)->dma_dir
&& SCpnt
)
162 memcpy (SCpnt
->SCp
.ptr
,
163 HDATA(instance
)->dma_bounce_buffer
,
164 SCpnt
->SCp
.this_residual
);
166 if (HDATA(instance
)->dma_buffer_pool
== BUF_SCSI_ALLOCED
)
167 scsi_free (HDATA(instance
)->dma_bounce_buffer
,
168 HDATA(instance
)->dma_bounce_len
);
170 amiga_chip_free(HDATA(instance
)->dma_bounce_buffer
);
172 HDATA(instance
)->dma_bounce_buffer
= NULL
;
173 HDATA(instance
)->dma_bounce_len
= 0;
177 static int num_gvp11
= 0;
179 #define CHECK_WD33C93
181 int __init
gvp11_detect(Scsi_Host_Template
*tpnt
)
183 static unsigned char called
= 0;
184 struct Scsi_Host
*instance
;
185 unsigned long address
;
187 struct zorro_dev
*z
= NULL
;
188 unsigned int default_dma_xfer_mask
;
190 volatile unsigned char *sasr_3393
, *scmd_3393
;
191 unsigned char save_sasr
;
195 if (!MACH_IS_AMIGA
|| called
)
199 tpnt
->proc_name
= "GVP11";
200 tpnt
->proc_info
= &wd33c93_proc_info
;
202 while ((z
= zorro_find_device(ZORRO_WILDCARD
, z
))) {
204 * This should (hopefully) be the correct way to identify
205 * all the different GVP SCSI controllers (except for the
209 if (z
->id
== ZORRO_PROD_GVP_COMBO_030_R3_SCSI
||
210 z
->id
== ZORRO_PROD_GVP_SERIES_II
)
211 default_dma_xfer_mask
= ~0x00ffffff;
212 else if (z
->id
== ZORRO_PROD_GVP_GFORCE_030_SCSI
||
213 z
->id
== ZORRO_PROD_GVP_A530_SCSI
||
214 z
->id
== ZORRO_PROD_GVP_COMBO_030_R4_SCSI
)
215 default_dma_xfer_mask
= ~0x01ffffff;
216 else if (z
->id
== ZORRO_PROD_GVP_A1291
||
217 z
->id
== ZORRO_PROD_GVP_GFORCE_040_SCSI_1
)
218 default_dma_xfer_mask
= ~0x07ffffff;
223 * Rumors state that some GVP ram boards use the same product
224 * code as the SCSI controllers. Therefore if the board-size
225 * is not 64KB we asume it is a ram board and bail out.
227 if (z
->resource
.end
-z
->resource
.start
!= 0xffff)
230 address
= z
->resource
.start
;
231 if (!request_mem_region(address
, 256, "wd33c93"))
237 * These darn GVP boards are a problem - it can be tough to tell
238 * whether or not they include a SCSI controller. This is the
239 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
240 * probes for a WD33c93 chip: If we find one, it's extremely
241 * likely that this card supports SCSI, regardless of Product_
242 * Code, Board_Size, etc.
245 /* Get pointers to the presumed register locations and save contents */
247 sasr_3393
= &(((gvp11_scsiregs
*)(ZTWO_VADDR(address
)))->SASR
);
248 scmd_3393
= &(((gvp11_scsiregs
*)(ZTWO_VADDR(address
)))->SCMD
);
249 save_sasr
= *sasr_3393
;
251 /* First test the AuxStatus Reg */
253 q
= *sasr_3393
; /* read it */
254 if (q
& 0x08) /* bit 3 should always be clear */
256 *sasr_3393
= WD_AUXILIARY_STATUS
; /* setup indirect address */
257 if (*sasr_3393
== WD_AUXILIARY_STATUS
) { /* shouldn't retain the write */
258 *sasr_3393
= save_sasr
; /* Oops - restore this byte */
261 if (*sasr_3393
!= q
) { /* should still read the same */
262 *sasr_3393
= save_sasr
; /* Oops - restore this byte */
265 if (*scmd_3393
!= q
) /* and so should the image at 0x1f */
269 /* Ok, we probably have a wd33c93, but let's check a few other places
270 * for good measure. Make sure that this works for both 'A and 'B
274 *sasr_3393
= WD_SCSI_STATUS
;
276 *sasr_3393
= WD_SCSI_STATUS
;
278 *sasr_3393
= WD_SCSI_STATUS
;
280 *sasr_3393
= WD_SCSI_STATUS
;
282 if (qq
!= q
) /* should be read only */
284 *sasr_3393
= 0x1e; /* this register is unimplemented */
292 if (qq
!= q
|| qq
!= 0xff) /* should be read only, all 1's */
294 *sasr_3393
= WD_TIMEOUT_PERIOD
;
296 *sasr_3393
= WD_TIMEOUT_PERIOD
;
298 *sasr_3393
= WD_TIMEOUT_PERIOD
;
300 *sasr_3393
= WD_TIMEOUT_PERIOD
;
302 if (qq
!= (~q
& 0xff)) /* should be read/write */
306 instance
= scsi_register (tpnt
, sizeof (struct WD33C93_hostdata
));
309 instance
->base
= ZTWO_VADDR(address
);
310 instance
->irq
= IRQ_AMIGA_PORTS
;
311 instance
->unique_id
= z
->slotaddr
;
314 HDATA(instance
)->dma_xfer_mask
= gvp11_xfer_mask
;
316 HDATA(instance
)->dma_xfer_mask
= default_dma_xfer_mask
;
319 DMA(instance
)->secret2
= 1;
320 DMA(instance
)->secret1
= 0;
321 DMA(instance
)->secret3
= 15;
322 while (DMA(instance
)->CNTR
& GVP11_DMAC_BUSY
) ;
323 DMA(instance
)->CNTR
= 0;
325 DMA(instance
)->BANK
= 0;
327 epc
= *(unsigned short *)(ZTWO_VADDR(address
) + 0x8000);
330 * Check for 14MHz SCSI clock
332 if (epc
& GVP_SCSICLKMASK
)
333 wd33c93_init(instance
, (wd33c93_regs
*)&(DMA(instance
)->SASR
),
334 dma_setup
, dma_stop
, WD33C93_FS_8_10
);
336 wd33c93_init(instance
, (wd33c93_regs
*)&(DMA(instance
)->SASR
),
337 dma_setup
, dma_stop
, WD33C93_FS_12_15
);
339 if (num_gvp11
++ == 0) {
340 first_instance
= instance
;
341 gvp11_template
= instance
->hostt
;
342 request_irq(IRQ_AMIGA_PORTS
, gvp11_intr
, SA_SHIRQ
,
343 "GVP11 SCSI", gvp11_intr
);
345 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
349 release_mem_region(address
, 256);
360 static Scsi_Host_Template driver_template
= GVP11_SCSI
;
362 #include "scsi_module.c"
364 int gvp11_release(struct Scsi_Host
*instance
)
367 DMA(instance
)->CNTR
= 0;
368 release_mem_region(ZTWO_PADDR(instance
->base
), 256);
369 if (--num_gvp11
== 0)
370 free_irq(IRQ_AMIGA_PORTS
, gvp11_intr
);