1 1.18 isaki /* $NetBSD: cs428x.h,v 1.18 2021/02/03 14:44:32 isaki Exp $ */ 2 1.1 augustss 3 1.1 augustss /* 4 1.1 augustss * Copyright (c) 2000 Tatoku Ogaito. All rights reserved. 5 1.1 augustss * 6 1.1 augustss * Redistribution and use in source and binary forms, with or without 7 1.1 augustss * modification, are permitted provided that the following conditions 8 1.1 augustss * are met: 9 1.1 augustss * 1. Redistributions of source code must retain the above copyright 10 1.1 augustss * notice, this list of conditions and the following disclaimer. 11 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 augustss * notice, this list of conditions and the following disclaimer in the 13 1.1 augustss * documentation and/or other materials provided with the distribution. 14 1.1 augustss * 3. All advertising materials mentioning features or use of this software 15 1.1 augustss * must display the following acknowledgement: 16 1.1 augustss * This product includes software developed by Tatoku Ogaito 17 1.1 augustss * for the NetBSD Project. 18 1.1 augustss * 4. The name of the author may not be used to endorse or promote products 19 1.1 augustss * derived from this software without specific prior written permission 20 1.1 augustss * 21 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 1.1 augustss * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 1.1 augustss * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 1.1 augustss * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 1.1 augustss * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 1.1 augustss * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 1.1 augustss * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 1.1 augustss * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 1.1 augustss * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 1.1 augustss * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 1.1 augustss */ 32 1.1 augustss 33 1.1 augustss /* Common functions and variables for CS4280 and CS4281 */ 34 1.1 augustss 35 1.1 augustss #ifndef _CS428X_H_ 36 1.1 augustss #define _CS428X_H_ 37 1.1 augustss 38 1.8 kent #define PCI_BA0 (0x10) 39 1.8 kent #define PCI_BA1 (0x14) 40 1.1 augustss 41 1.1 augustss #define CS428X_SAVE_REG_MAX (0x10) 42 1.8 kent #define TYPE_CS4280 (0x4280) 43 1.8 kent #define TYPE_CS4281 (0x4281) 44 1.1 augustss 45 1.1 augustss #define BA0READ4(sc, r) bus_space_read_4((sc)->ba0t, (sc)->ba0h, (r)) 46 1.1 augustss #define BA0WRITE4(sc, r, x) bus_space_write_4((sc)->ba0t, (sc)->ba0h, (r), (x)) 47 1.1 augustss 48 1.1 augustss /* DMA */ 49 1.1 augustss struct cs428x_dma { 50 1.1 augustss bus_dmamap_t map; 51 1.12 christos void *addr; /* real DMA buffer */ 52 1.12 christos void *dum; /* dummy buffer for audio driver */ 53 1.1 augustss bus_dma_segment_t segs[1]; 54 1.1 augustss int nsegs; 55 1.1 augustss size_t size; 56 1.1 augustss struct cs428x_dma *next; 57 1.1 augustss }; 58 1.1 augustss #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr) 59 1.6 wiz #define KERNADDR(p) ((void *)((p)->addr)) /* buffer for real DMA */ 60 1.1 augustss #define BUFADDR(p) ((void *)((p)->dum)) /* buffer for audio driver */ 61 1.1 augustss 62 1.1 augustss /* 63 1.10 jmcneill * Flags (currently used only for CS4280) 64 1.10 jmcneill */ 65 1.10 jmcneill enum cs428x_flags { 66 1.10 jmcneill CS428X_FLAG_NONE = 0x0, 67 1.10 jmcneill CS428X_FLAG_INVAC97EAMP = 0x1, /* inverted AC97 external amp */ 68 1.11 jmcneill CS428X_FLAG_CLKRUNHACK = 0x2 /* needs CLKRUN hack */ 69 1.10 jmcneill }; 70 1.10 jmcneill 71 1.10 jmcneill /* 72 1.1 augustss * Software state 73 1.1 augustss */ 74 1.1 augustss struct cs428x_softc { 75 1.16 chs device_t sc_dev; 76 1.15 jmcneill kmutex_t sc_lock; 77 1.15 jmcneill kmutex_t sc_intr_lock; 78 1.1 augustss 79 1.13 joerg pci_chipset_tag_t sc_pc; 80 1.13 joerg pcitag_t sc_pt; 81 1.1 augustss pci_intr_handle_t * sc_ih; 82 1.13 joerg pci_intr_handle_t intrh; 83 1.1 augustss 84 1.1 augustss /* I/O (BA0) */ 85 1.1 augustss bus_space_tag_t ba0t; 86 1.1 augustss bus_space_handle_t ba0h; 87 1.8 kent 88 1.1 augustss /* BA1 */ 89 1.1 augustss bus_space_tag_t ba1t; 90 1.1 augustss bus_space_handle_t ba1h; 91 1.8 kent 92 1.1 augustss /* DMA */ 93 1.1 augustss bus_dma_tag_t sc_dmatag; 94 1.1 augustss struct cs428x_dma *sc_dmas; 95 1.1 augustss size_t dma_size; 96 1.1 augustss size_t dma_align; 97 1.1 augustss 98 1.8 kent int hw_blocksize; 99 1.8 kent int type; 100 1.1 augustss 101 1.1 augustss /* playback */ 102 1.6 wiz void (*sc_pintr)(void *); /* DMA completion intr handler */ 103 1.1 augustss void *sc_parg; /* arg for sc_intr() */ 104 1.1 augustss char *sc_ps, *sc_pe, *sc_pn; 105 1.1 augustss int sc_pcount; 106 1.1 augustss int sc_pi; 107 1.1 augustss struct cs428x_dma *sc_pdma; 108 1.1 augustss char *sc_pbuf; 109 1.8 kent char sc_prun; /* playback status */ 110 1.8 kent int sc_prate; /* playback sample rate */ 111 1.1 augustss 112 1.1 augustss /* capturing */ 113 1.6 wiz void (*sc_rintr)(void *); /* DMA completion intr handler */ 114 1.1 augustss void *sc_rarg; /* arg for sc_intr() */ 115 1.1 augustss char *sc_rs, *sc_re, *sc_rn; 116 1.1 augustss int sc_rcount; 117 1.1 augustss int sc_ri; 118 1.1 augustss struct cs428x_dma *sc_rdma; 119 1.1 augustss char *sc_rbuf; 120 1.8 kent char sc_rrun; /* recording status */ 121 1.8 kent int sc_rrate; /* recording sample rate */ 122 1.1 augustss 123 1.3 tacha /* Although cs4281 does not support midi (yet), 124 1.3 tacha * don't remove these definition. 125 1.3 tacha */ 126 1.1 augustss void (*sc_iintr)(void *, int); /* midi input ready handler */ 127 1.1 augustss void (*sc_ointr)(void *); /* midi output ready handler */ 128 1.1 augustss void *sc_arg; 129 1.1 augustss 130 1.1 augustss /* 131 1.1 augustss * XXX 132 1.10 jmcneill * Actually these 3 variables are needed only for CS4280. 133 1.1 augustss */ 134 1.10 jmcneill enum cs428x_flags sc_flags; 135 1.8 kent uint32_t pctl; 136 1.8 kent uint32_t cctl; 137 1.1 augustss 138 1.1 augustss /* AC97 CODEC */ 139 1.1 augustss struct ac97_codec_if *codec_if; 140 1.8 kent struct ac97_host_if host_if; 141 1.1 augustss 142 1.1 augustss /* Power Management */ 143 1.14 jmcneill union { 144 1.14 jmcneill struct { 145 1.14 jmcneill uint32_t pctl; 146 1.14 jmcneill uint32_t pba; 147 1.14 jmcneill uint32_t pfie; 148 1.14 jmcneill uint32_t pdtc; 149 1.14 jmcneill uint32_t cctl; 150 1.14 jmcneill uint32_t cba; 151 1.14 jmcneill uint32_t cie; 152 1.14 jmcneill } cs4280; 153 1.14 jmcneill struct { 154 1.14 jmcneill uint32_t dba0; 155 1.14 jmcneill uint32_t dbc0; 156 1.14 jmcneill uint32_t dmr0; 157 1.14 jmcneill uint32_t dcr0; 158 1.14 jmcneill uint32_t dba1; 159 1.14 jmcneill uint32_t dbc1; 160 1.14 jmcneill uint32_t dmr1; 161 1.14 jmcneill uint32_t dcr1; 162 1.14 jmcneill } cs4281; 163 1.14 jmcneill } sc_suspend_state; 164 1.11 jmcneill 165 1.11 jmcneill /* CLKRUN hack (CS428X_FLAG_CLKRUN), only for CS4280 */ 166 1.11 jmcneill int sc_active; 167 1.11 jmcneill bus_space_tag_t sc_pm_iot; 168 1.11 jmcneill bus_space_handle_t sc_pm_ioh; 169 1.1 augustss }; 170 1.1 augustss 171 1.1 augustss 172 1.7 kent int cs428x_round_blocksize(void *, int, int, const audio_params_t *); 173 1.1 augustss int cs428x_get_props(void *); 174 1.1 augustss int cs428x_attach_codec(void *, struct ac97_codec_if *); 175 1.3 tacha int cs428x_read_codec(void *, u_int8_t, u_int16_t *); 176 1.1 augustss int cs428x_write_codec(void *, u_int8_t, u_int16_t); 177 1.1 augustss 178 1.1 augustss int cs428x_mixer_set_port(void *, mixer_ctrl_t *); 179 1.1 augustss int cs428x_mixer_get_port(void *, mixer_ctrl_t *); 180 1.1 augustss int cs428x_query_devinfo(void *, mixer_devinfo_t *); 181 1.15 jmcneill void *cs428x_malloc(void *, int, size_t); 182 1.1 augustss size_t cs428x_round_buffersize(void *, int, size_t); 183 1.15 jmcneill void cs428x_free(void *, void *, size_t); 184 1.15 jmcneill void cs428x_get_locks(void *, kmutex_t **, kmutex_t **); 185 1.1 augustss 186 1.1 augustss /* internal functions */ 187 1.15 jmcneill int cs428x_allocmem(struct cs428x_softc *, size_t, struct cs428x_dma *); 188 1.1 augustss int cs428x_src_wait(struct cs428x_softc *); 189 1.1 augustss 190 1.1 augustss 191 1.1 augustss /* DEBUG */ 192 1.3 tacha /* #define CS4280_DEBUG */ 193 1.3 tacha /* #define CS4281_DEBUG */ 194 1.1 augustss 195 1.1 augustss #if defined(CS4280_DEBUG) || defined(CS4281_DEBUG) 196 1.1 augustss #define DPRINTF(x) if (cs428x_debug) printf x 197 1.1 augustss #define DPRINTFN(n,x) if (cs428x_debug>(n)) printf x 198 1.1 augustss extern int cs428x_debug; 199 1.1 augustss #if CS4280_DEBUG + 0 == 0 200 1.1 augustss #undef CS4280_DEBUG 201 1.1 augustss #define CS4280_DEBUG 0 202 1.1 augustss #endif 203 1.1 augustss #else 204 1.1 augustss #define DPRINTF(x) 205 1.1 augustss #define DPRINTFN(n,x) 206 1.1 augustss #endif 207 1.1 augustss 208 1.1 augustss #endif /* _CS428X_H_ */ 209