xref: /dflybsd-src/sys/dev/sound/pci/hdspe.h (revision 67931cc46b2c63adf26460fc9f0e333e55b5ccbe)
12a1ad637SFrançois Tigeot /*-
22a1ad637SFrançois Tigeot  * Copyright (c) 2012 Ruslan Bukin <br@bsdpad.com>
32a1ad637SFrançois Tigeot  * All rights reserved.
42a1ad637SFrançois Tigeot  *
52a1ad637SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
62a1ad637SFrançois Tigeot  * modification, are permitted provided that the following conditions
72a1ad637SFrançois Tigeot  * are met:
82a1ad637SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
92a1ad637SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer.
102a1ad637SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
112a1ad637SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
122a1ad637SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
132a1ad637SFrançois Tigeot  *
142a1ad637SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
152a1ad637SFrançois Tigeot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162a1ad637SFrançois Tigeot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172a1ad637SFrançois Tigeot  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
182a1ad637SFrançois Tigeot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
192a1ad637SFrançois Tigeot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
202a1ad637SFrançois Tigeot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
212a1ad637SFrançois Tigeot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
222a1ad637SFrançois Tigeot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
232a1ad637SFrançois Tigeot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
242a1ad637SFrançois Tigeot  * SUCH DAMAGE.
252a1ad637SFrançois Tigeot  *
262a1ad637SFrançois Tigeot  * $FreeBSD: head/sys/dev/sound/pci/hdspe.h 232337 2012-03-01 13:10:18Z mav $
272a1ad637SFrançois Tigeot  */
282a1ad637SFrançois Tigeot 
292a1ad637SFrançois Tigeot #define PCI_VENDOR_XILINX		0x10ee
302a1ad637SFrançois Tigeot #define PCI_DEVICE_XILINX_HDSPE		0x3fc6 /* AIO, MADI, AES, RayDAT */
312a1ad637SFrançois Tigeot #define PCI_CLASS_REVISION		0x08
322a1ad637SFrançois Tigeot #define PCI_REVISION_AIO		212
332a1ad637SFrançois Tigeot #define PCI_REVISION_RAYDAT		211
342a1ad637SFrançois Tigeot 
352a1ad637SFrançois Tigeot #define AIO				0
362a1ad637SFrançois Tigeot #define RAYDAT				1
372a1ad637SFrançois Tigeot 
382a1ad637SFrançois Tigeot /* Hardware mixer */
392a1ad637SFrançois Tigeot #define HDSPE_OUT_ENABLE_BASE		512
402a1ad637SFrançois Tigeot #define HDSPE_IN_ENABLE_BASE		768
412a1ad637SFrançois Tigeot #define HDSPE_MIXER_BASE		32768
422a1ad637SFrançois Tigeot #define HDSPE_MAX_GAIN			32768
432a1ad637SFrançois Tigeot 
442a1ad637SFrançois Tigeot /* Buffer */
452a1ad637SFrançois Tigeot #define HDSPE_PAGE_ADDR_BUF_OUT		8192
462a1ad637SFrançois Tigeot #define HDSPE_PAGE_ADDR_BUF_IN		(HDSPE_PAGE_ADDR_BUF_OUT + 64 * 16 * 4)
472a1ad637SFrançois Tigeot #define HDSPE_BUF_POSITION_MASK		0x000FFC0
482a1ad637SFrançois Tigeot 
492a1ad637SFrançois Tigeot /* Frequency */
502a1ad637SFrançois Tigeot #define HDSPE_FREQ_0			(1<<6)
512a1ad637SFrançois Tigeot #define HDSPE_FREQ_1			(1<<7)
522a1ad637SFrançois Tigeot #define HDSPE_FREQ_DOUBLE		(1<<8)
532a1ad637SFrançois Tigeot #define HDSPE_FREQ_QUAD			(1<<31)
542a1ad637SFrançois Tigeot 
552a1ad637SFrançois Tigeot #define HDSPE_FREQ_32000		HDSPE_FREQ_0
562a1ad637SFrançois Tigeot #define HDSPE_FREQ_44100		HDSPE_FREQ_1
572a1ad637SFrançois Tigeot #define HDSPE_FREQ_48000		(HDSPE_FREQ_0 | HDSPE_FREQ_1)
582a1ad637SFrançois Tigeot #define HDSPE_FREQ_MASK			(HDSPE_FREQ_0 | HDSPE_FREQ_1 |	\
592a1ad637SFrançois Tigeot 					HDSPE_FREQ_DOUBLE | HDSPE_FREQ_QUAD)
602a1ad637SFrançois Tigeot #define HDSPE_FREQ_MASK_DEFAULT		HDSPE_FREQ_48000
612a1ad637SFrançois Tigeot #define HDSPE_FREQ_REG			256
622a1ad637SFrançois Tigeot #define HDSPE_FREQ_AIO			104857600000000ULL
632a1ad637SFrançois Tigeot 
642a1ad637SFrançois Tigeot #define HDSPE_SPEED_DEFAULT		48000
652a1ad637SFrançois Tigeot 
662a1ad637SFrançois Tigeot /* Latency */
672a1ad637SFrançois Tigeot #define HDSPE_LAT_0			(1<<1)
682a1ad637SFrançois Tigeot #define HDSPE_LAT_1			(1<<2)
692a1ad637SFrançois Tigeot #define HDSPE_LAT_2			(1<<3)
702a1ad637SFrançois Tigeot #define HDSPE_LAT_MASK			(HDSPE_LAT_0 | HDSPE_LAT_1 | HDSPE_LAT_2)
712a1ad637SFrançois Tigeot #define HDSPE_LAT_BYTES_MAX		(4096 * 4)
722a1ad637SFrançois Tigeot #define HDSPE_LAT_BYTES_MIN		(32 * 4)
732a1ad637SFrançois Tigeot #define hdspe_encode_latency(x)		(((x)<<1) & HDSPE_LAT_MASK)
742a1ad637SFrançois Tigeot 
752a1ad637SFrançois Tigeot /* Settings */
762a1ad637SFrançois Tigeot #define HDSPE_SETTINGS_REG		0
772a1ad637SFrançois Tigeot #define HDSPE_CONTROL_REG		64
782a1ad637SFrançois Tigeot #define HDSPE_STATUS_REG		0
792a1ad637SFrançois Tigeot #define HDSPE_ENABLE			(1<<0)
802a1ad637SFrançois Tigeot #define HDSPM_CLOCK_MODE_MASTER		(1<<4)
812a1ad637SFrançois Tigeot 
822a1ad637SFrançois Tigeot /* Interrupts */
832a1ad637SFrançois Tigeot #define HDSPE_AUDIO_IRQ_PENDING		(1<<0)
842a1ad637SFrançois Tigeot #define HDSPE_AUDIO_INT_ENABLE		(1<<5)
852a1ad637SFrançois Tigeot #define HDSPE_INTERRUPT_ACK		96
862a1ad637SFrançois Tigeot 
872a1ad637SFrançois Tigeot /* Channels */
882a1ad637SFrançois Tigeot #define HDSPE_MAX_SLOTS			64 /* Mono channels */
892a1ad637SFrançois Tigeot #define HDSPE_MAX_CHANS			(HDSPE_MAX_SLOTS / 2) /* Stereo pairs */
902a1ad637SFrançois Tigeot 
912a1ad637SFrançois Tigeot #define HDSPE_CHANBUF_SAMPLES		(16 * 1024)
922a1ad637SFrançois Tigeot #define HDSPE_CHANBUF_SIZE		(4 * HDSPE_CHANBUF_SAMPLES)
932a1ad637SFrançois Tigeot #define HDSPE_DMASEGSIZE		(HDSPE_CHANBUF_SIZE * HDSPE_MAX_SLOTS)
942a1ad637SFrançois Tigeot 
952a1ad637SFrançois Tigeot struct hdspe_channel {
962a1ad637SFrançois Tigeot 	uint32_t	left;
972a1ad637SFrançois Tigeot 	uint32_t	right;
982a1ad637SFrançois Tigeot 	char		*descr;
992a1ad637SFrançois Tigeot 	uint32_t	play;
1002a1ad637SFrançois Tigeot 	uint32_t	rec;
1012a1ad637SFrançois Tigeot };
1022a1ad637SFrançois Tigeot 
1032a1ad637SFrançois Tigeot static MALLOC_DEFINE(M_HDSPE, "hdspe", "hdspe audio");
1042a1ad637SFrançois Tigeot 
1052a1ad637SFrançois Tigeot /* Channel registers */
1062a1ad637SFrançois Tigeot struct sc_chinfo {
1072a1ad637SFrançois Tigeot 	struct snd_dbuf		*buffer;
1082a1ad637SFrançois Tigeot 	struct pcm_channel	*channel;
1092a1ad637SFrançois Tigeot 	struct sc_pcminfo	*parent;
1102a1ad637SFrançois Tigeot 
1112a1ad637SFrançois Tigeot 	/* Channel information */
1122a1ad637SFrançois Tigeot 	uint32_t	dir;
1132a1ad637SFrançois Tigeot 	uint32_t	format;
1142a1ad637SFrançois Tigeot 	uint32_t	lslot;
1152a1ad637SFrançois Tigeot 	uint32_t	rslot;
1162a1ad637SFrançois Tigeot 	uint32_t	lvol;
1172a1ad637SFrançois Tigeot 	uint32_t	rvol;
1182a1ad637SFrançois Tigeot 
1192a1ad637SFrançois Tigeot 	/* Buffer */
1202a1ad637SFrançois Tigeot 	uint32_t	*data;
1212a1ad637SFrançois Tigeot 	uint32_t	size;
1222a1ad637SFrançois Tigeot 
1232a1ad637SFrançois Tigeot 	/* Flags */
1242a1ad637SFrançois Tigeot 	uint32_t	run;
1252a1ad637SFrançois Tigeot };
1262a1ad637SFrançois Tigeot 
1272a1ad637SFrançois Tigeot /* PCM device private data */
1282a1ad637SFrançois Tigeot struct sc_pcminfo {
1292a1ad637SFrançois Tigeot 	device_t		dev;
1302a1ad637SFrançois Tigeot 	uint32_t		(*ih) (struct sc_pcminfo *scp);
1312a1ad637SFrançois Tigeot 	uint32_t		chnum;
1322a1ad637SFrançois Tigeot 	struct sc_chinfo	chan[HDSPE_MAX_CHANS];
1332a1ad637SFrançois Tigeot 	struct sc_info		*sc;
1342a1ad637SFrançois Tigeot 	struct hdspe_channel	*hc;
1352a1ad637SFrançois Tigeot };
1362a1ad637SFrançois Tigeot 
1372a1ad637SFrançois Tigeot /* HDSPe device private data */
1382a1ad637SFrançois Tigeot struct sc_info {
1392a1ad637SFrançois Tigeot 	device_t		dev;
140*67931cc4SFrançois Tigeot 	struct lock		*lock;
1412a1ad637SFrançois Tigeot 
1422a1ad637SFrançois Tigeot 	uint32_t		ctrl_register;
1432a1ad637SFrançois Tigeot 	uint32_t		settings_register;
1442a1ad637SFrançois Tigeot 	uint32_t		type;
1452a1ad637SFrançois Tigeot 
1462a1ad637SFrançois Tigeot 	/* Control/Status register */
1472a1ad637SFrançois Tigeot 	struct resource		*cs;
1482a1ad637SFrançois Tigeot 	int			csid;
1492a1ad637SFrançois Tigeot 	bus_space_tag_t		cst;
1502a1ad637SFrançois Tigeot 	bus_space_handle_t	csh;
1512a1ad637SFrançois Tigeot 
1522a1ad637SFrançois Tigeot 	struct resource		*irq;
1532a1ad637SFrançois Tigeot 	int			irqid;
1542a1ad637SFrançois Tigeot 	void			*ih;
1552a1ad637SFrançois Tigeot 	bus_dma_tag_t		dmat;
1562a1ad637SFrançois Tigeot 
1572a1ad637SFrançois Tigeot 	/* Play/Record DMA buffers */
1582a1ad637SFrançois Tigeot 	uint32_t		*pbuf;
1592a1ad637SFrançois Tigeot 	uint32_t		*rbuf;
1602a1ad637SFrançois Tigeot 	uint32_t		bufsize;
1612a1ad637SFrançois Tigeot 	bus_dmamap_t		pmap;
1622a1ad637SFrançois Tigeot 	bus_dmamap_t		rmap;
1632a1ad637SFrançois Tigeot 	uint32_t		period;
1642a1ad637SFrançois Tigeot 	uint32_t		speed;
1652a1ad637SFrançois Tigeot };
1662a1ad637SFrançois Tigeot 
1672a1ad637SFrançois Tigeot #define hdspe_read_1(sc, regno)						\
1682a1ad637SFrançois Tigeot 	bus_space_read_1((sc)->cst, (sc)->csh, (regno))
1692a1ad637SFrançois Tigeot #define hdspe_read_2(sc, regno)						\
1702a1ad637SFrançois Tigeot 	bus_space_read_2((sc)->cst, (sc)->csh, (regno))
1712a1ad637SFrançois Tigeot #define hdspe_read_4(sc, regno)						\
1722a1ad637SFrançois Tigeot 	bus_space_read_4((sc)->cst, (sc)->csh, (regno))
1732a1ad637SFrançois Tigeot 
1742a1ad637SFrançois Tigeot #define hdspe_write_1(sc, regno, data)					\
1752a1ad637SFrançois Tigeot 	bus_space_write_1((sc)->cst, (sc)->csh, (regno), (data))
1762a1ad637SFrançois Tigeot #define hdspe_write_2(sc, regno, data)					\
1772a1ad637SFrançois Tigeot 	bus_space_write_2((sc)->cst, (sc)->csh, (regno), (data))
1782a1ad637SFrançois Tigeot #define hdspe_write_4(sc, regno, data)					\
1792a1ad637SFrançois Tigeot 	bus_space_write_4((sc)->cst, (sc)->csh, (regno), (data))
180