Home | History | Annotate | Line # | Download | only in sbus
dbrivar.h revision 1.9
      1  1.9  macallan /*	$NetBSD: dbrivar.h,v 1.9 2008/05/09 03:12:49 macallan Exp $	*/
      2  1.1  macallan 
      3  1.1  macallan /*
      4  1.2  macallan  * Copyright (C) 1997 Rudolf Koenig (rfkoenig (at) immd4.informatik.uni-erlangen.de)
      5  1.2  macallan  * Copyright (c) 1998, 1999 Brent Baccala (baccala (at) freesoft.org)
      6  1.2  macallan  * Copyright (c) 2001, 2002 Jared D. McNeill <jmcneill (at) netbsd.org>
      7  1.2  macallan  * Copyright (c) 2005 Michael Lorenz <macallan (at) netbsd.org>
      8  1.1  macallan  * All rights reserved.
      9  1.1  macallan  *
     10  1.2  macallan  * This driver is losely based on a Linux driver written by Rudolf Koenig and
     11  1.2  macallan  * Brent Baccala who kindly gave their permission to use their code in a
     12  1.2  macallan  * BSD-licensed driver.
     13  1.2  macallan  *
     14  1.1  macallan  * Redistribution and use in source and binary forms, with or without
     15  1.1  macallan  * modification, are permitted provided that the following conditions
     16  1.1  macallan  * are met:
     17  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     18  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     19  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     20  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     21  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     22  1.1  macallan  *
     23  1.9  macallan  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     24  1.9  macallan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  1.9  macallan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  1.9  macallan  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  1.9  macallan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     28  1.9  macallan  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     29  1.9  macallan  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  1.9  macallan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  1.9  macallan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  1.9  macallan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  1.1  macallan  *
     34  1.1  macallan  */
     35  1.1  macallan 
     36  1.4  macallan #ifndef DBRI_VAR_H
     37  1.4  macallan #define DBRI_VAR_H
     38  1.2  macallan 
     39  1.1  macallan #define	DBRI_NUM_COMMANDS	64
     40  1.7  macallan #define	DBRI_NUM_DESCRIPTORS	32
     41  1.1  macallan #define	DBRI_INT_BLOCKS		64
     42  1.1  macallan 
     43  1.1  macallan #define DBRI_PIPE_MAX		32
     44  1.1  macallan 
     45  1.1  macallan enum direction {
     46  1.1  macallan 	in,
     47  1.1  macallan 	out
     48  1.1  macallan };
     49  1.1  macallan 
     50  1.1  macallan /* DBRI DMA transmit descriptor */
     51  1.7  macallan struct dbri_xmit {
     52  1.4  macallan 	volatile uint32_t	flags;
     53  1.1  macallan 		#define TX_EOF	0x80000000	/* End of frame marker */
     54  1.1  macallan 		#define TX_BCNT(x)	((x&0x3fff)<<16)
     55  1.1  macallan 		#define TX_BINT	0x00008000	/* interrupt when EOF */
     56  1.1  macallan 		#define TX_MINT 0x00004000	/* marker interrupt */
     57  1.1  macallan 		#define TX_IDLE	0x00002000	/* send idles after data */
     58  1.1  macallan 		#define TX_FCNT(x)	(x&0x1fff)
     59  1.1  macallan 
     60  1.4  macallan 	volatile uint32_t	ba;		/* tx/rx buffer address */
     61  1.4  macallan 	volatile uint32_t	nda;		/* next descriptor address */
     62  1.4  macallan 	volatile uint32_t	status;
     63  1.1  macallan 		#define TS_OK		0x0001	/* transmission completed */
     64  1.1  macallan 		#define TS_ABORT	0x0004	/* transmission aborted */
     65  1.1  macallan 		#define TS_UNDERRUN	0x0008	/* DMA underrun */
     66  1.1  macallan };
     67  1.1  macallan 
     68  1.7  macallan struct dbri_recv {
     69  1.7  macallan 	volatile uint32_t	status;
     70  1.7  macallan 		#define RX_EOF		0x80000000
     71  1.7  macallan 		#define RX_COMPLETED	0x40000000
     72  1.7  macallan 		#define RX_BCNT(x)	((x & 0x3fff) << 16)
     73  1.7  macallan 		#define RX_CRCERROR	0x00000080
     74  1.7  macallan 		#define RX_BBC		0x00000040	/* bad byte count */
     75  1.7  macallan 		#define RX_ABORT	0x00000020
     76  1.7  macallan 		#define RX_OVERRUN	0x00000008
     77  1.7  macallan 	volatile uint32_t	ba;
     78  1.7  macallan 	volatile uint32_t	nda;
     79  1.7  macallan 	volatile uint32_t	flags;
     80  1.7  macallan 		#define RX_BSIZE(x)	(x & 0x3fff)
     81  1.7  macallan 		#define RX_FINAL	0x00008000
     82  1.7  macallan 		#define RX_MARKER	0x00004000
     83  1.7  macallan };
     84  1.7  macallan 
     85  1.1  macallan struct dbri_pipe {
     86  1.4  macallan 	uint32_t	sdp;		/* SDP command word */
     87  1.1  macallan 	enum direction	direction;
     88  1.1  macallan 	int		next;		/* next pipe in linked list */
     89  1.1  macallan 	int		prev;		/* previous pipe in linked list */
     90  1.1  macallan 	int		cycle;		/* offset of timeslot (bits) */
     91  1.1  macallan 	int		length;		/* length of timeslot (bits) */
     92  1.1  macallan 	int		desc;		/* index of active descriptor */
     93  1.4  macallan 	volatile uint32_t	*prec;	/* pointer to received fixed data */
     94  1.1  macallan };
     95  1.1  macallan 
     96  1.1  macallan struct dbri_desc {
     97  1.1  macallan 	int		busy;
     98  1.5  christos 	void *		buf;		/* cpu view of buffer */
     99  1.5  christos 	void *		buf_dvma;	/* device view */
    100  1.1  macallan 	bus_addr_t	dmabase;
    101  1.1  macallan 	bus_dma_segment_t dmaseg;
    102  1.1  macallan 	bus_dmamap_t	dmamap;
    103  1.1  macallan 	size_t		len;
    104  1.1  macallan 	void		(*callback)(void *);
    105  1.1  macallan 	void		*callback_args;
    106  1.8        ad 	void		*softint;
    107  1.1  macallan };
    108  1.1  macallan 
    109  1.1  macallan struct dbri_dma {
    110  1.4  macallan 	volatile uint32_t	command[DBRI_NUM_COMMANDS];
    111  1.1  macallan 	volatile int32_t	intr[DBRI_INT_BLOCKS];
    112  1.7  macallan 	struct dbri_xmit	xmit[DBRI_NUM_DESCRIPTORS];
    113  1.7  macallan 	struct dbri_recv	recv[DBRI_NUM_DESCRIPTORS];
    114  1.1  macallan };
    115  1.1  macallan 
    116  1.1  macallan struct dbri_softc {
    117  1.1  macallan 	struct device	sc_dev;		/* base device */
    118  1.1  macallan 
    119  1.1  macallan 	struct sbusdev	sc_sd;		/* sbus device */
    120  1.1  macallan 	bus_space_handle_t sc_ioh;
    121  1.1  macallan 	bus_space_tag_t	sc_iot;
    122  1.7  macallan 	/* DMA buffer for sending commands to the chip */
    123  1.1  macallan 	bus_dma_tag_t	sc_dmat;
    124  1.1  macallan 	bus_dmamap_t	sc_dmamap;
    125  1.1  macallan 	bus_dma_segment_t sc_dmaseg;
    126  1.4  macallan 
    127  1.4  macallan 	int		sc_have_powerctl;
    128  1.6  macallan 	int		sc_powerstate;	/* DBRI's powered up or not */
    129  1.6  macallan 	int		sc_pmgrstate;	/* PWR_RESUME etc. */
    130  1.1  macallan 	int		sc_burst;	/* DVMA burst size in effect */
    131  1.1  macallan 
    132  1.1  macallan 	bus_addr_t	sc_dmabase;	/* VA of buffer we provide */
    133  1.5  christos 	void *		sc_membase;
    134  1.1  macallan 	int		sc_bufsiz;	/* size of the buffer */
    135  1.1  macallan 	int		sc_locked;
    136  1.1  macallan 	int		sc_irqp;
    137  1.1  macallan 
    138  1.1  macallan 	int		sc_waitseen;
    139  1.1  macallan 
    140  1.7  macallan 	int		sc_refcount;
    141  1.6  macallan 	int		sc_playing;
    142  1.7  macallan 	int		sc_recording;
    143  1.1  macallan 
    144  1.1  macallan 	int		sc_liu_state;
    145  1.1  macallan 	void		(*sc_liu)(void *);
    146  1.1  macallan 	void		*sc_liu_args;
    147  1.1  macallan 
    148  1.1  macallan 	struct dbri_pipe sc_pipe[DBRI_PIPE_MAX];
    149  1.1  macallan 	struct dbri_desc sc_desc[DBRI_NUM_DESCRIPTORS];
    150  1.1  macallan 
    151  1.1  macallan 	struct cs4215_state	sc_mm;
    152  1.6  macallan 	int		sc_latt, sc_ratt;	/* output attenuation */
    153  1.6  macallan 	int		sc_linp, sc_rinp;	/* input volume */
    154  1.6  macallan 	int		sc_monitor;		/* monitor volume */
    155  1.6  macallan 	int		sc_input;		/* 0 - line, 1 - mic */
    156  1.6  macallan 
    157  1.1  macallan 	int		sc_ctl_mode;
    158  1.1  macallan 
    159  1.4  macallan 	uint32_t	sc_version;
    160  1.1  macallan 	int		sc_chi_pipe_in;
    161  1.1  macallan 	int		sc_chi_pipe_out;
    162  1.1  macallan 	int		sc_chi_bpf;
    163  1.1  macallan 
    164  1.1  macallan 	int		sc_desc_used;
    165  1.1  macallan 
    166  1.1  macallan 	struct audio_params sc_params;
    167  1.1  macallan 
    168  1.1  macallan 	struct dbri_dma	*sc_dma;
    169  1.1  macallan };
    170  1.1  macallan 
    171  1.1  macallan #define dbri_dma_off(member, elem)	\
    172  1.4  macallan 	((uint32_t)(unsigned long)	\
    173  1.1  macallan 	 (&(((struct dbri_dma *)0)->member[elem])))
    174  1.1  macallan 
    175  1.1  macallan #if 1
    176  1.1  macallan #define DBRI_CMD(cmd, intr, value)	((cmd << 28) | (intr << 27) | value)
    177  1.1  macallan #else
    178  1.1  macallan #define	DBRI_CMD(cmd, intr, value)	((cmd << 28) | (1 << 27) | value)
    179  1.1  macallan #endif
    180  1.1  macallan #define DBRI_INTR_GETCHAN(v)		(((v) >> 24) & 0x3f)
    181  1.1  macallan #define DBRI_INTR_GETCODE(v)		(((v) >> 20) & 0xf)
    182  1.1  macallan #define DBRI_INTR_GETCMD(v)		(((v) >> 16) & 0xf)
    183  1.1  macallan #define DBRI_INTR_GETVAL(v)		((v) & 0xffff)
    184  1.1  macallan #define DBRI_INTR_GETRVAL(v)		((v) & 0xfffff)
    185  1.1  macallan 
    186  1.1  macallan #define	DBRI_SDP_MODE(v)		((v) & (7 << 13))
    187  1.1  macallan #define DBRI_PIPE(v)			((v) << 0)
    188  1.4  macallan 
    189  1.4  macallan #endif /* DBRI_VAR_H */
    190