1 /*-7 2 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca> 3 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org> 4 * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 /* 32 * Intel High Definition Audio (Audio function quirks) driver for FreeBSD. 33 */ 34 35 #ifndef _HDAA_QUIRKS_H_ 36 #define _HDAA_QUIRKS_H_ 37 38 #define HDAA_GPIO_SHIFT(n) (n * 3) 39 #define HDAA_GPIO_MASK(n) (0x7 << (n * 3)) 40 #define HDAA_GPIO_KEEP(n) (0x0 << (n * 3)) 41 #define HDAA_GPIO_SET(n) (0x1 << (n * 3)) 42 #define HDAA_GPIO_CLEAR(n) (0x2 << (n * 3)) 43 #define HDAA_GPIO_DISABLE(n) (0x3 << (n * 3)) 44 #define HDAA_GPIO_INPUT(n) (0x4 << (n * 3)) 45 46 /* 9 - 25 = anything else */ 47 #define HDAA_QUIRK_SOFTPCMVOL (1 << 9) 48 #define HDAA_QUIRK_FIXEDRATE (1 << 10) 49 #define HDAA_QUIRK_FORCESTEREO (1 << 11) 50 #define HDAA_QUIRK_EAPDINV (1 << 12) 51 #define HDAA_QUIRK_SENSEINV (1 << 14) 52 53 /* 26 - 31 = vrefs */ 54 #define HDAA_QUIRK_IVREF50 (1 << 26) 55 #define HDAA_QUIRK_IVREF80 (1 << 27) 56 #define HDAA_QUIRK_IVREF100 (1 << 28) 57 #define HDAA_QUIRK_OVREF50 (1 << 29) 58 #define HDAA_QUIRK_OVREF80 (1 << 30) 59 #define HDAA_QUIRK_OVREF100 (1 << 31) 60 61 #define HDAA_QUIRK_IVREF (HDAA_QUIRK_IVREF50 | HDAA_QUIRK_IVREF80 | \ 62 HDAA_QUIRK_IVREF100) 63 #define HDAA_QUIRK_OVREF (HDAA_QUIRK_OVREF50 | HDAA_QUIRK_OVREF80 | \ 64 HDAA_QUIRK_OVREF100) 65 #define HDAA_QUIRK_VREF (HDAA_QUIRK_IVREF | HDAA_QUIRK_OVREF) 66 67 #define HDAA_AMP_VOL_DEFAULT (-1) 68 #define HDAA_AMP_MUTE_DEFAULT (0xffffffff) 69 #define HDAA_AMP_MUTE_NONE (0) 70 #define HDAA_AMP_MUTE_LEFT (1 << 0) 71 #define HDAA_AMP_MUTE_RIGHT (1 << 1) 72 #define HDAA_AMP_MUTE_ALL (HDAA_AMP_MUTE_LEFT | HDAA_AMP_MUTE_RIGHT) 73 74 #define HDAA_AMP_LEFT_MUTED(v) ((v) & (HDAA_AMP_MUTE_LEFT)) 75 #define HDAA_AMP_RIGHT_MUTED(v) (((v) & HDAA_AMP_MUTE_RIGHT) >> 1) 76 77 #define HDAA_ADC_MONITOR (1 << 0) 78 79 #define HDAA_CTL_OUT 1 80 #define HDAA_CTL_IN 2 81 82 #define HDA_MAX_CONNS 32 83 #define HDA_MAX_NAMELEN 32 84 85 struct hdaa_widget { 86 nid_t nid; 87 int type; 88 int enable; 89 int nconns, selconn; 90 int waspin; 91 uint32_t pflags; 92 int bindas; 93 int bindseqmask; 94 int ossdev; 95 uint32_t ossmask; 96 nid_t conns[HDA_MAX_CONNS]; 97 u_char connsenable[HDA_MAX_CONNS]; 98 char name[HDA_MAX_NAMELEN]; 99 struct hdaa_devinfo *devinfo; 100 struct { 101 uint32_t widget_cap; 102 uint32_t outamp_cap; 103 uint32_t inamp_cap; 104 uint32_t supp_stream_formats; 105 uint32_t supp_pcm_size_rate; 106 uint32_t eapdbtl; 107 } param; 108 union { 109 struct { 110 uint32_t config; 111 uint32_t original; 112 uint32_t newconf; 113 uint32_t cap; 114 uint32_t ctrl; 115 } pin; 116 } wclass; 117 }; 118 119 struct hdaa_audio_ctl { 120 struct hdaa_widget *widget, *childwidget; 121 int enable; 122 int index, dir, ndir; 123 int mute, step, size, offset; 124 int left, right, forcemute; 125 uint32_t muted; 126 uint32_t ossmask, possmask; 127 }; 128 129 /* Association is a group of pins bound for some special function. */ 130 struct hdaa_audio_as { 131 u_char enable; 132 u_char index; 133 u_char dir; 134 u_char pincnt; 135 u_char fakeredir; 136 u_char digital; 137 uint16_t pinset; 138 nid_t hpredir; 139 nid_t pins[16]; 140 nid_t dacs[2][16]; 141 int num_chans; 142 int chans[2]; 143 int unsol; 144 int location; /* Pins location, if all have the same */ 145 int mixed; /* Mixed/multiplexed recording, not multichannel. */ 146 }; 147 148 struct hdaa_pcm_devinfo { 149 device_t dev; 150 struct hdaa_devinfo *devinfo; 151 int index; 152 int registered; 153 int playas, recas; 154 u_char left[SOUND_MIXER_NRDEVICES]; 155 u_char right[SOUND_MIXER_NRDEVICES]; 156 int chan_size; 157 int chan_blkcnt; 158 u_char digital; 159 }; 160 161 struct hdaa_devinfo { 162 device_t dev; 163 struct mtx *lock; 164 nid_t nid; 165 nid_t startnode, endnode; 166 uint32_t outamp_cap; 167 uint32_t inamp_cap; 168 uint32_t supp_stream_formats; 169 uint32_t supp_pcm_size_rate; 170 uint32_t gpio_cap; 171 uint32_t quirks; 172 uint32_t newquirks; 173 uint32_t gpio; 174 uint32_t newgpio; 175 uint32_t gpo; 176 uint32_t newgpo; 177 int nodecnt; 178 int ctlcnt; 179 int ascnt; 180 int num_devs; 181 int num_chans; 182 struct hdaa_widget *widget; 183 struct hdaa_audio_ctl *ctl; 184 struct hdaa_audio_as *as; 185 struct hdaa_pcm_devinfo *devs; 186 struct hdaa_chan *chans; 187 struct callout poll_jack; 188 int poll_ival; 189 }; 190 191 #define HDAA_CHN_RUNNING 0x00000001 192 #define HDAA_CHN_SUSPEND 0x00000002 193 194 struct hdaa_chan { 195 struct snd_dbuf *b; 196 struct pcm_channel *c; 197 struct pcmchan_caps caps; 198 struct hdaa_devinfo *devinfo; 199 struct hdaa_pcm_devinfo *pdevinfo; 200 uint32_t spd, fmt, fmtlist[16], pcmrates[16]; 201 uint32_t supp_stream_formats, supp_pcm_size_rate; 202 uint32_t ptr, prevptr, blkcnt, blksz; 203 uint32_t *dmapos; 204 uint32_t flags; 205 int dir; 206 int off; 207 int sid; 208 int bit16, bit32; 209 int channels; /* Number of audio channels. */ 210 int as; /* Number of association. */ 211 int asindex; /* Index within association. */ 212 nid_t io[16]; 213 }; 214 215 #define hdaa_codec_id(devinfo) \ 216 (((uint32_t)hda_get_vendor_id(devinfo->dev) << 16) + \ 217 hda_get_device_id(devinfo->dev)) 218 219 #define hdaa_subvendor_id(devinfo) \ 220 (((uint32_t)hda_get_subvendor_id(devinfo->dev) << 16) + \ 221 hda_get_subdevice_id(devinfo->dev)) 222 223 struct hdaa_widget *hdaa_widget_get(struct hdaa_devinfo *, nid_t); 224 uint32_t hdaa_widget_pin_patch(uint32_t config, const char *str); 225 uint32_t hdaa_gpio_patch(uint32_t gpio, const char *str); 226 227 void hdaa_patch(struct hdaa_devinfo *devinfo); 228 void hdaa_patch_direct(struct hdaa_devinfo *devinfo); 229 230 #endif 231