1/*	$OpenBSD: envyvar.h,v 1.20 2019/04/30 20:29:46 ratchov Exp $	*/
2/*
3 * Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef SYS_DEV_PCI_ENVYVAR_H
19#define SYS_DEV_PCI_ENVYVAR_H
20
21#include <sys/types.h>
22#include <sys/device.h>
23#include <sys/time.h>
24#include <dev/audio_if.h>
25#include <dev/midi_if.h>
26
27struct envy_softc;
28
29struct envy_buf {
30	bus_dma_segment_t	seg;
31	bus_dmamap_t		map;
32	caddr_t			addr;
33	size_t			size;
34	unsigned int		swpos;
35	unsigned int		bufsz;
36	unsigned int		blksz;
37};
38
39struct envy_codec {
40	char *name;
41	int (*ndev)(struct envy_softc *);
42	void (*devinfo)(struct envy_softc *, struct mixer_devinfo *, int);
43	void (*get)(struct envy_softc *, struct mixer_ctrl *, int);
44	int (*set)(struct envy_softc *, struct mixer_ctrl *, int);
45};
46
47struct envy_card {
48	int subid;
49	char *name;
50	int nich;
51	struct envy_codec *adc;
52	int noch;
53	struct envy_codec *dac;
54	int nmidi;
55	void (*init)(struct envy_softc *);
56	void (*codec_write)(struct envy_softc *, int, int, int);
57 	void (*set_rate)(struct envy_softc *, int);
58	unsigned char *eeprom;
59};
60
61struct envy_softc {
62	struct device		dev;
63	struct device	       *audio;
64	int			isht;		/* is a Envy24HT ? */
65	int			isac97;		/* is a Envy24HT AC97 ? */
66	struct envy_buf		ibuf, obuf;
67	pcitag_t		pci_tag;
68	pci_chipset_tag_t	pci_pc;
69	pci_intr_handle_t      *pci_ih;
70	bus_dma_tag_t		pci_dmat;
71	bus_space_tag_t		ccs_iot;
72	bus_space_handle_t	ccs_ioh;
73	bus_size_t		ccs_iosz;
74	bus_space_tag_t		mt_iot;
75	bus_space_handle_t	mt_ioh;
76	bus_size_t		mt_iosz;
77	int			iactive;	/* trigger_input called */
78	int			oactive;	/* trigger_output called */
79	int			ibusy;		/* input DMA started */
80	int			obusy;		/* output DMA started */
81#ifdef ENVY_DEBUG
82	unsigned 		spurious;
83	struct timespec		start_ts;
84#define ENVY_NINTR		16
85	unsigned 		nintr;
86	struct envy_intr {
87		int ipos, opos, st, mask, ctl, iactive, oactive;
88		struct timespec ts;
89	} intrs[ENVY_NINTR];
90#endif
91	struct envy_card       *card;
92	unsigned char 		shadow[4][16];
93#define ENVY_EEPROM_MAXSZ 32
94	unsigned char		eeprom[ENVY_EEPROM_MAXSZ];
95	struct ac97_codec_if   *codec_if;
96	struct ac97_host_if	host_if;
97	enum ac97_host_flags	codec_flags;
98	void (*iintr)(void *);
99	void *iarg;
100	void (*ointr)(void *);
101	void *oarg;
102#if NMIDI > 0
103	void (*midi_in)(void *, int);
104	void (*midi_out)(void *);
105	void *midi_arg;
106	struct device *midi;
107	int midi_isopen;
108#endif
109};
110
111#define ENVY_MIX_CLASSIN	0
112#define ENVY_MIX_CLASSOUT	1
113#define ENVY_MIX_CLASSMON	2
114
115#define ENVY_MIX_NCLASS		3
116#define ENVY_MIX_NOUTSRC	10
117#define ENVY_MIX_NMONITOR	20
118
119#define ENVY_MIX_OUTSRC_LINEIN	0
120#define ENVY_MIX_OUTSRC_SPDIN	8
121#define ENVY_MIX_OUTSRC_DMA	10
122#define ENVY_MIX_OUTSRC_MON	11
123
124#endif /* !defined(SYS_DEV_PCI_ENVYVAR_H) */
125