Home | History | Annotate | Line # | Download | only in dev
otgsc.c revision 1.1
      1  1.1  chopps /*
      2  1.1  chopps  * Copyright (c) 1982, 1990 The Regents of the University of California.
      3  1.1  chopps  * All rights reserved.
      4  1.1  chopps  *
      5  1.1  chopps  * Redistribution and use in source and binary forms, with or without
      6  1.1  chopps  * modification, are permitted provided that the following conditions
      7  1.1  chopps  * are met:
      8  1.1  chopps  * 1. Redistributions of source code must retain the above copyright
      9  1.1  chopps  *    notice, this list of conditions and the following disclaimer.
     10  1.1  chopps  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  chopps  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  chopps  *    documentation and/or other materials provided with the distribution.
     13  1.1  chopps  * 3. All advertising materials mentioning features or use of this software
     14  1.1  chopps  *    must display the following acknowledgement:
     15  1.1  chopps  *	This product includes software developed by the University of
     16  1.1  chopps  *	California, Berkeley and its contributors.
     17  1.1  chopps  * 4. Neither the name of the University nor the names of its contributors
     18  1.1  chopps  *    may be used to endorse or promote products derived from this software
     19  1.1  chopps  *    without specific prior written permission.
     20  1.1  chopps  *
     21  1.1  chopps  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  chopps  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  chopps  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  chopps  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1  chopps  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  chopps  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  chopps  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  chopps  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  chopps  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  chopps  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  chopps  * SUCH DAMAGE.
     32  1.1  chopps  *
     33  1.1  chopps  *	@(#)csa12gdma.c
     34  1.1  chopps  *	$Id: otgsc.c,v 1.1 1994/05/08 05:53:30 chopps Exp $
     35  1.1  chopps  */
     36  1.1  chopps 
     37  1.1  chopps /*
     38  1.1  chopps  * dummy CSA 12 Gauge 5380 DMA driver
     39  1.1  chopps  */
     40  1.1  chopps 
     41  1.1  chopps #include "csa12gscsi.h"
     42  1.1  chopps 
     43  1.1  chopps #if NCSA12GSCSI > 0
     44  1.1  chopps 
     45  1.1  chopps #include <sys/param.h>
     46  1.1  chopps 
     47  1.1  chopps #include <amiga/dev/device.h>
     48  1.1  chopps #include <amiga/dev/scivar.h>
     49  1.1  chopps #include <amiga/dev/scireg.h>
     50  1.1  chopps 
     51  1.1  chopps #define QPRINTF
     52  1.1  chopps #ifdef DEBUG
     53  1.1  chopps extern int sci_debug;
     54  1.1  chopps #endif
     55  1.1  chopps #define	HIST(h,w)
     56  1.1  chopps 
     57  1.1  chopps extern int sci_data_wait;
     58  1.1  chopps 
     59  1.1  chopps static int dma_xfer_in __P((struct sci_softc *dev, int len,
     60  1.1  chopps     register u_char *buf, int phase));
     61  1.1  chopps static int dma_xfer_out __P((struct sci_softc *dev, int len,
     62  1.1  chopps     register u_char *buf, int phase));
     63  1.1  chopps 
     64  1.1  chopps void
     65  1.1  chopps csa12gdmainit (dev)
     66  1.1  chopps 	struct sci_softc *dev;
     67  1.1  chopps {
     68  1.1  chopps 	dev->dma_xfer_in = dma_xfer_in;
     69  1.1  chopps 	dev->dma_xfer_out = dma_xfer_out;
     70  1.1  chopps }
     71  1.1  chopps 
     72  1.1  chopps static int
     73  1.1  chopps dma_xfer_in (dev, len, buf, phase)
     74  1.1  chopps 	struct sci_softc *dev;
     75  1.1  chopps 	int len;
     76  1.1  chopps 	register u_char *buf;
     77  1.1  chopps 	int phase;
     78  1.1  chopps {
     79  1.1  chopps 	int wait = sci_data_wait;
     80  1.1  chopps 	u_char csr;
     81  1.1  chopps 	u_char *obp = buf;
     82  1.1  chopps 	volatile register u_char *sci_dma = dev->sci_data + 0x80;
     83  1.1  chopps 	volatile register u_char *sci_csr = dev->sci_csr;
     84  1.1  chopps 	volatile register u_char *sci_icmd = dev->sci_icmd;
     85  1.1  chopps 
     86  1.1  chopps 	QPRINTF(("csa12gdma_in %d, csr=%02x\n", len, *dev->sci_bus_csr));
     87  1.1  chopps 
     88  1.1  chopps 	*dev->sci_tcmd = phase;
     89  1.1  chopps 	*dev->sci_mode |= SCI_MODE_DMA;
     90  1.1  chopps 	*dev->sci_icmd = 0;
     91  1.1  chopps 	*dev->sci_irecv = 0;
     92  1.1  chopps 	while (len > 0) {
     93  1.1  chopps 		wait = sci_data_wait;
     94  1.1  chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
     95  1.1  chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
     96  1.1  chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
     97  1.1  chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
     98  1.1  chopps 			  || --wait < 0) {
     99  1.1  chopps #ifdef DEBUG
    100  1.1  chopps 				if (sci_debug)
    101  1.1  chopps 					printf("csa12g_in fail: l%d i%x w%d\n",
    102  1.1  chopps 					len, csr, wait);
    103  1.1  chopps #endif
    104  1.1  chopps 				HIST(ixin_wait, wait)
    105  1.1  chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    106  1.1  chopps 				return 0;
    107  1.1  chopps 			}
    108  1.1  chopps 		}
    109  1.1  chopps 
    110  1.1  chopps 		*buf++ = *sci_dma;
    111  1.1  chopps 		len--;
    112  1.1  chopps 	}
    113  1.1  chopps 
    114  1.1  chopps 	QPRINTF(("csa12gdma_in {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    115  1.1  chopps 	  len, obp[0], obp[1], obp[2], obp[3], obp[4], obp[5],
    116  1.1  chopps 	  obp[6], obp[7], obp[8], obp[9]));
    117  1.1  chopps 
    118  1.1  chopps 	/* this leaves with one csr to be read */
    119  1.1  chopps 	HIST(ixin_wait, wait)
    120  1.1  chopps 	*dev->sci_mode &= ~SCI_MODE_DMA;
    121  1.1  chopps 	return 0;
    122  1.1  chopps }
    123  1.1  chopps 
    124  1.1  chopps static int
    125  1.1  chopps dma_xfer_out (dev, len, buf, phase)
    126  1.1  chopps 	struct sci_softc *dev;
    127  1.1  chopps 	int len;
    128  1.1  chopps 	register u_char *buf;
    129  1.1  chopps 	int phase;
    130  1.1  chopps {
    131  1.1  chopps 	int wait = sci_data_wait;
    132  1.1  chopps 	u_char csr;
    133  1.1  chopps 	u_char *obp = buf;
    134  1.1  chopps 	volatile register u_char *sci_dma = dev->sci_data + 0x80;
    135  1.1  chopps 	volatile register u_char *sci_csr = dev->sci_csr;
    136  1.1  chopps 	volatile register u_char *sci_icmd = dev->sci_icmd;
    137  1.1  chopps 
    138  1.1  chopps 	QPRINTF(("csa12gdma_out %d, csr=%02x\n", len, *dev->sci_bus_csr));
    139  1.1  chopps 
    140  1.1  chopps 	QPRINTF(("csa12gdma_out {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    141  1.1  chopps   	 len, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
    142  1.1  chopps 	 buf[6], buf[7], buf[8], buf[9]));
    143  1.1  chopps 
    144  1.1  chopps 	*dev->sci_tcmd = phase;
    145  1.1  chopps 	*dev->sci_mode |= SCI_MODE_DMA;
    146  1.1  chopps 	*dev->sci_icmd = SCI_ICMD_DATA;
    147  1.1  chopps 	*dev->sci_dma_send = 0;
    148  1.1  chopps 	while (len > 0) {
    149  1.1  chopps 		wait = sci_data_wait;
    150  1.1  chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    151  1.1  chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    152  1.1  chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    153  1.1  chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    154  1.1  chopps 			  || --wait < 0) {
    155  1.1  chopps #ifdef DEBUG
    156  1.1  chopps 				if (sci_debug)
    157  1.1  chopps 					printf("csa12gdma_out fail: l%d i%x w%d\n",
    158  1.1  chopps 					len, csr, wait);
    159  1.1  chopps #endif
    160  1.1  chopps 				HIST(ixin_wait, wait)
    161  1.1  chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    162  1.1  chopps 				return 0;
    163  1.1  chopps 			}
    164  1.1  chopps 		}
    165  1.1  chopps 
    166  1.1  chopps 		*sci_dma = *buf++;
    167  1.1  chopps 		len--;
    168  1.1  chopps 	}
    169  1.1  chopps 
    170  1.1  chopps 	wait = sci_data_wait;
    171  1.1  chopps 	while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) ==
    172  1.1  chopps 	  SCI_CSR_PHASE_MATCH && --wait);
    173  1.1  chopps 
    174  1.1  chopps 
    175  1.1  chopps 	HIST(ixin_wait, wait)
    176  1.1  chopps 	*dev->sci_mode &= ~SCI_MODE_DMA;
    177  1.1  chopps 	return 0;
    178  1.1  chopps }
    179  1.1  chopps #endif
    180