1 /* $NetBSD: esmvar.h,v 1.5 2001/12/31 22:06:47 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2000, 2001 Rene Hexel <rh@netbsd.org> 5 * All rights reserved. 6 * 7 * Copyright (c) 2000 Taku YAMAMOTO <taku@cent.saitama-u.ac.jp> 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, 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. 30 * 31 * Taku Id: maestro.c,v 1.12 2000/09/06 03:32:34 taku Exp 32 * FreeBSD: /c/ncvs/src/sys/dev/sound/pci/maestro.c,v 1.4 2000/12/18 01:36:35 cg Exp 33 * 34 */ 35 36 /* 37 * Credits: 38 * 39 * This code is based on the FreeBSD driver written by Taku YAMAMOTO 40 * 41 * 42 * Original credits from the FreeBSD driver: 43 * 44 * Part of this code (especially in many magic numbers) was heavily inspired 45 * by the Linux driver originally written by 46 * Alan Cox <alan.cox@linux.org>, modified heavily by 47 * Zach Brown <zab@zabbo.net>. 48 * 49 * busdma()-ize and buffer size reduction were suggested by 50 * Cameron Grant <gandalf@vilnya.demon.co.uk>. 51 * Also he showed me the way to use busdma() suite. 52 * 53 * Internal speaker problems on NEC VersaPro's and Dell Inspiron 7500 54 * were looked at by 55 * Munehiro Matsuda <haro@tk.kubota.co.jp>, 56 * who brought patches based on the Linux driver with some simplification. 57 */ 58 59 /* IRQ timer fequency limits */ 60 #define MAESTRO_MINFREQ 24 61 #define MAESTRO_MAXFREQ 48000 62 63 struct esm_dma { 64 bus_dmamap_t map; 65 caddr_t addr; 66 bus_dma_segment_t segs[1]; 67 int nsegs; 68 size_t size; 69 struct esm_dma *next; 70 }; 71 72 #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr) 73 #define KERNADDR(p) ((void *)((p)->addr)) 74 75 struct esm_chinfo { 76 u_int32_t base; /* DMA base */ 77 u_int32_t blocksize; /* block size in bytes */ 78 unsigned num; /* logical channel number */ 79 u_int16_t aputype; /* APU channel type */ 80 u_int16_t apublk; /* blk size in samples per ch */ 81 u_int16_t apubuf; /* buf size in samples per ch */ 82 u_int16_t nextirq; /* pos to trigger next IRQ at */ 83 u_int16_t wcreg_tpl; /* wavecache tag and format */ 84 u_int16_t sample_rate; 85 }; 86 87 struct esm_softc { 88 struct device sc_dev; 89 90 bus_space_tag_t st; 91 bus_space_handle_t sh; 92 93 pcitag_t tag; 94 pci_chipset_tag_t pc; 95 bus_dma_tag_t dmat; 96 pcireg_t subid; 97 98 void *ih; 99 100 struct ac97_codec_if *codec_if; 101 struct ac97_host_if host_if; 102 enum ac97_host_flags codec_flags; 103 104 struct esm_dma *sc_dmas; 105 106 int pactive, ractive; 107 struct esm_chinfo pch; 108 struct esm_chinfo rch; 109 110 void (*sc_pintr)(void *); 111 void *sc_parg; 112 113 void (*sc_rintr)(void *); 114 void *sc_rarg; 115 116 /* Power Management */ 117 char esm_suspend; 118 void *esm_powerhook; 119 }; 120 121 enum esm_quirk_flags { 122 ESM_QUIRKF_GPIO = 0x1, /* needs GPIO operation */ 123 ESM_QUIRKF_SWAPPEDCH = 0x2, /* left/right is reversed */ 124 }; 125 126 struct esm_quirks { 127 pci_vendor_id_t eq_vendor; /* subsystem vendor */ 128 pci_product_id_t eq_product; /* and product */ 129 130 enum esm_quirk_flags eq_quirks; /* needed quirks */ 131 }; 132 133 int esm_read_codec(void *, u_int8_t, u_int16_t *); 134 int esm_write_codec(void *, u_int8_t, u_int16_t); 135 int esm_attach_codec(void *, struct ac97_codec_if *); 136 void esm_reset_codec(void *); 137 enum ac97_host_flags esm_flags_codec(void *); 138 139 void esm_power(struct esm_softc *, int); 140 void esm_init(struct esm_softc *); 141 void esm_initcodec(struct esm_softc *); 142 143 int esm_init_output(void *, void *, int); 144 int esm_trigger_output(void *, void *, void *, int, void (*)(void *), 145 void *, struct audio_params *); 146 int esm_trigger_input(void *, void *, void *, int, void (*)(void *), 147 void *, struct audio_params *); 148 int esm_halt_output(void *); 149 int esm_halt_input(void *); 150 int esm_open(void *, int); 151 void esm_close(void *); 152 int esm_getdev(void *, struct audio_device *); 153 int esm_round_blocksize(void *, int); 154 int esm_query_encoding(void *, struct audio_encoding *); 155 int esm_set_params(void *, int, int, struct audio_params *, 156 struct audio_params *); 157 int esm_set_port(void *, mixer_ctrl_t *); 158 int esm_get_port(void *, mixer_ctrl_t *); 159 int esm_query_devinfo(void *, mixer_devinfo_t *); 160 void *esm_malloc(void *, int, size_t, int, int); 161 void esm_free(void *, void *, int); 162 size_t esm_round_buffersize(void *, int, size_t); 163 paddr_t esm_mappage(void *, void *, off_t, int); 164 int esm_get_props(void *); 165 166 int esm_match(struct device *, struct cfdata *, void *); 167 void esm_attach(struct device *, struct device *, void *); 168 int esm_intr(void *); 169 170 int esm_allocmem(struct esm_softc *, size_t, size_t, 171 struct esm_dma *); 172 int esm_freemem(struct esm_softc *, struct esm_dma *); 173 174 int esm_suspend(struct esm_softc *); 175 int esm_resume(struct esm_softc *); 176 int esm_shutdown(struct esm_softc *); 177 178 enum esm_quirk_flags esm_get_quirks(pcireg_t); 179