harmonyvar.h revision 1.2 1 /* $NetBSD: harmonyvar.h,v 1.2 2019/05/08 13:40:15 isaki Exp $ */
2
3 /* $OpenBSD: harmonyvar.h,v 1.8 2003/08/15 13:25:53 mickey Exp $ */
4
5 /*
6 * Copyright (c) 2003 Jason L. Wright (jason (at) thought.net)
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #define HARMONY_PORT_INPUT_LVL 0
32 #define HARMONY_PORT_INPUT_OV 1
33 #define HARMONY_PORT_OUTPUT_LVL 2
34 #define HARMONY_PORT_OUTPUT_GAIN 3
35 #define HARMONY_PORT_MONITOR_LVL 4
36 #define HARMONY_PORT_RECORD_SOURCE 5
37 #define HARMONY_PORT_OUTPUT_SOURCE 6
38 #define HARMONY_PORT_INPUT_CLASS 7
39 #define HARMONY_PORT_OUTPUT_CLASS 8
40 #define HARMONY_PORT_MONITOR_CLASS 9
41 #define HARMONY_PORT_RECORD_CLASS 10
42
43 #define HARMONY_IN_MIC 0
44 #define HARMONY_IN_LINE 1
45
46 #define HARMONY_OUT_LINE 0
47 #define HARMONY_OUT_SPEAKER 1
48 #define HARMONY_OUT_HEADPHONE 2
49
50 #define PLAYBACK_EMPTYS 3 /* playback empty buffers */
51 #define CAPTURE_EMPTYS 3 /* capture empty buffers */
52
53 struct harmony_volume {
54 u_char left, right;
55 };
56
57 struct harmony_empty {
58 uint8_t playback[PLAYBACK_EMPTYS][HARMONY_BUFSIZE];
59 uint8_t capture[CAPTURE_EMPTYS][HARMONY_BUFSIZE];
60 };
61
62 struct harmony_dma {
63 struct harmony_dma *d_next;
64 bus_dmamap_t d_map;
65 bus_dma_segment_t d_seg;
66 void *d_kva;
67 size_t d_size;
68 };
69
70 struct harmony_channel {
71 struct harmony_dma *c_current;
72 bus_size_t c_segsz;
73 bus_size_t c_cnt;
74 bus_size_t c_blksz;
75 bus_addr_t c_lastaddr;
76 void (*c_intr)(void *);
77 void *c_intrarg;
78 bus_addr_t c_theaddr;
79 };
80
81 struct harmony_softc {
82 device_t sc_dv;
83 kmutex_t sc_lock;
84 kmutex_t sc_intr_lock;
85 struct audio_device sc_audev;
86
87 bus_dma_tag_t sc_dmat;
88 bus_space_tag_t sc_bt;
89 bus_space_handle_t sc_bh;
90 uint32_t sc_cntlbits;
91 int sc_need_commit;
92 int sc_playback_empty;
93 bus_addr_t sc_playback_paddrs[PLAYBACK_EMPTYS];
94 int sc_capture_empty;
95 bus_addr_t sc_capture_paddrs[CAPTURE_EMPTYS];
96 bus_dmamap_t sc_empty_map;
97 bus_dma_segment_t sc_empty_seg;
98 int sc_empty_rseg;
99 struct harmony_empty *sc_empty_kva;
100 struct harmony_dma *sc_dmas;
101 int sc_playing, sc_capturing;
102 struct harmony_channel sc_playback, sc_capture;
103 struct harmony_volume sc_monitor_lvl, sc_input_lvl, sc_output_lvl;
104 int sc_in_port, sc_out_port;
105 int sc_micpreamp, sc_ov, sc_outputgain;
106 int sc_teleshare;
107
108 krndsource_t sc_rnd_source;
109 struct callout sc_acc_tmo;
110 uint32_t sc_acc, sc_acc_num, sc_acc_cnt;
111 };
112
113 #define READ_REG(sc, reg) \
114 bus_space_read_4((sc)->sc_bt, (sc)->sc_bh, (reg))
115 #define WRITE_REG(sc, reg, val) \
116 bus_space_write_4((sc)->sc_bt, (sc)->sc_bh, (reg), (val))
117 #define SYNC_REG(sc, reg, flags) \
118 bus_space_barrier((sc)->sc_bt, (sc)->sc_bh, (reg), sizeof(uint32_t), \
119 (flags))
120