Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / hdaudio / hdaudiovar.h
blob312cc8e187238f7a5ae6fb3bf95e93137cec1ad0
1 /* $NetBSD: hdaudiovar.h,v 1.4 2009/09/07 16:21:08 jmcneill Exp $ */
3 /*
4 * Copyright (c) 2009 Precedence Technologies Ltd <support@precedence.co.uk>
5 * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
6 * All rights reserved.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Precedence Technologies Ltd
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #ifndef _HDAUDIOVAR_H
33 #define _HDAUDIOVAR_H
35 #include <dev/auconv.h>
37 #define HDAUDIO_MAX_CODECS 15
39 #define hda_read1(sc, off) \
40 bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (off))
41 #define hda_read2(sc, off) \
42 bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (off))
43 #define hda_read4(sc, off) \
44 bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (off))
45 #define hda_write1(sc, off, val) \
46 bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (off), (val))
47 #define hda_write2(sc, off, val) \
48 bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (off), (val))
49 #define hda_write4(sc, off, val) \
50 bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (off), (val))
51 #define hda_print(sc, ...) \
52 aprint_normal_dev((sc)->sc_dev, __VA_ARGS__)
53 #define hda_print1(sc, ...) \
54 aprint_normal(__VA_ARGS__)
55 #define hda_error(sc, ...) \
56 aprint_error_dev((sc)->sc_dev, __VA_ARGS__)
57 #define hda_trace(sc, ...) \
58 aprint_debug_dev((sc)->sc_dev, __VA_ARGS__)
59 #define hda_delay(us) \
60 delay((us))
62 struct hdaudio_softc;
64 enum function_group_type {
65 HDAUDIO_GROUP_TYPE_UNKNOWN = 0,
66 HDAUDIO_GROUP_TYPE_AFG,
67 HDAUDIO_GROUP_TYPE_VSM_FG,
70 struct hdaudio_function_group {
71 device_t fg_device;
72 struct hdaudio_codec *fg_codec;
73 enum function_group_type fg_type;
74 int fg_nid;
75 uint16_t fg_vendor;
76 uint16_t fg_product;
79 struct hdaudio_codec {
80 bool co_valid;
81 u_int co_addr;
82 u_int co_nfg;
83 struct hdaudio_function_group *co_fg;
84 struct hdaudio_softc *co_host;
87 #define DMA_KERNADDR(dma) ((dma)->dma_addr)
88 #define DMA_DMAADDR(dma) ((dma)->dma_map->dm_segs[0].ds_addr)
90 struct hdaudio_dma {
91 bus_dmamap_t dma_map;
92 void *dma_addr;
93 bus_dma_segment_t dma_segs[1];
94 int dma_nsegs;
95 bus_size_t dma_size;
96 bool dma_valid;
97 uint8_t dma_sizereg;
100 #define HDAUDIO_MAX_STREAMS 30
102 struct hdaudio_dma_position {
103 uint32_t position;
104 uint32_t reserved;
105 } __packed;
107 struct hdaudio_bdl_entry {
108 uint32_t address_lo;
109 uint32_t address_hi;
110 uint32_t length;
111 uint32_t flags;
112 #define HDAUDIO_BDL_ENTRY_IOC 0x00000001
113 } __packed;
115 #define HDAUDIO_BDL_MAX 256
117 enum hdaudio_stream_type {
118 HDAUDIO_STREAM_ISS = 0,
119 HDAUDIO_STREAM_OSS = 1,
120 HDAUDIO_STREAM_BSS = 2
123 struct hdaudio_stream {
124 struct hdaudio_softc *st_host;
125 bool st_enable;
126 enum hdaudio_stream_type st_type;
127 int st_shift;
128 int st_num;
130 int (*st_intr)(struct hdaudio_stream *);
131 void *st_cookie;
133 struct hdaudio_dma st_data;
134 struct hdaudio_dma st_bdl;
137 struct hdaudio_softc {
138 device_t sc_dev;
140 bus_dma_tag_t sc_dmat;
141 bus_space_tag_t sc_memt;
142 bus_space_handle_t sc_memh;
143 bus_addr_t sc_membase;
144 bus_size_t sc_memsize;
145 bool sc_memvalid;
147 uint32_t sc_subsystem;
149 kmutex_t sc_corb_mtx;
150 struct hdaudio_dma sc_corb;
151 struct hdaudio_dma sc_rirb;
152 uint16_t sc_rirbrp;
154 struct hdaudio_codec sc_codec[HDAUDIO_MAX_CODECS];
156 struct hdaudio_stream sc_stream[HDAUDIO_MAX_STREAMS];
157 uint32_t sc_stream_mask;
158 kmutex_t sc_stream_mtx;
161 int hdaudio_attach(device_t, struct hdaudio_softc *);
162 int hdaudio_detach(struct hdaudio_softc *, int);
163 bool hdaudio_resume(struct hdaudio_softc *);
164 uint32_t hdaudio_command(struct hdaudio_codec *, int, uint32_t, uint32_t);
165 int hdaudio_intr(struct hdaudio_softc *);
167 int hdaudio_dma_alloc(struct hdaudio_softc *, struct hdaudio_dma *, int);
168 void hdaudio_dma_free(struct hdaudio_softc *, struct hdaudio_dma *);
170 struct hdaudio_stream * hdaudio_stream_establish(struct hdaudio_softc *,
171 enum hdaudio_stream_type,
172 int (*)(struct hdaudio_stream *), void *);
173 void hdaudio_stream_disestablish(struct hdaudio_stream *);
174 void hdaudio_stream_start(struct hdaudio_stream *, int, bus_size_t,
175 const audio_params_t *);
176 void hdaudio_stream_stop(struct hdaudio_stream *);
177 void hdaudio_stream_reset(struct hdaudio_stream *);
178 int hdaudio_stream_tag(struct hdaudio_stream *);
179 uint16_t hdaudio_stream_param(struct hdaudio_stream *, const audio_params_t *);
181 int hdaudio_afg_widget_info(void *, prop_dictionary_t, prop_dictionary_t);
182 int hdaudio_afg_codec_info(void *, prop_dictionary_t, prop_dictionary_t);
184 #endif /* !_HDAUDIOVAR_H */