1*cbab9cadSchs /* $NetBSD: ac97var.h,v 1.23 2012/10/27 17:18:18 chs Exp $ */ 205d5f375Sthorpej /* $OpenBSD: ac97.h,v 1.4 2000/07/19 09:01:35 csapuntz Exp $ */ 31838aef2Sthorpej 41838aef2Sthorpej /* 51838aef2Sthorpej * Copyright (c) 1999 Constantine Sapuntzakis 61838aef2Sthorpej * 71838aef2Sthorpej * Author: Constantine Sapuntzakis <csapuntz@stanford.edu> 81838aef2Sthorpej * 91838aef2Sthorpej * Redistribution and use in source and binary forms, with or without 101838aef2Sthorpej * modification, are permitted provided that the following conditions 111838aef2Sthorpej * are met: 121838aef2Sthorpej * 1. Redistributions of source code must retain the above copyright 131838aef2Sthorpej * notice, this list of conditions and the following disclaimer. 141838aef2Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 151838aef2Sthorpej * notice, this list of conditions and the following disclaimer in the 161838aef2Sthorpej * documentation and/or other materials provided with the distribution. 171838aef2Sthorpej * 181838aef2Sthorpej * THIS SOFTWARE IS PROVIDED BY CONSTANTINE SAPUNTZAKIS AND CONTRIBUTORS 191838aef2Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 201838aef2Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 211838aef2Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 221838aef2Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 231838aef2Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 241838aef2Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 251838aef2Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 261838aef2Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 271838aef2Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 281838aef2Sthorpej * POSSIBILITY OF SUCH DAMAGE. 291838aef2Sthorpej */ 301838aef2Sthorpej 3145bd8be9Sthorpej #ifndef _DEV_IC_AC97VAR_H_ 3245bd8be9Sthorpej #define _DEV_IC_AC97VAR_H_ 3323b5d914Skent #include <sys/types.h> 3445bd8be9Sthorpej 351838aef2Sthorpej struct ac97_codec_if; 361838aef2Sthorpej 371838aef2Sthorpej /* 381838aef2Sthorpej * This is the interface used to attach the AC97 compliant CODEC. 391838aef2Sthorpej */ 40aedf8226Sthorpej enum ac97_host_flags { 41aedf8226Sthorpej AC97_HOST_DONT_READ = 0x1, 42c74eb31fSjmcneill AC97_HOST_SWAPPED_CHANNELS = 0x2, /* l/r is reversed */ 43c74eb31fSjmcneill AC97_HOST_SKIP_AUDIO = 0x4, 44f08bb8f8Sjmcneill AC97_HOST_SKIP_MODEM = 0x8, 45f08bb8f8Sjmcneill AC97_HOST_INVERTED_EAMP = 0x10 46aedf8226Sthorpej }; 47aedf8226Sthorpej 481838aef2Sthorpej struct ac97_host_if { 491838aef2Sthorpej void *arg; 501838aef2Sthorpej 517f6ed16eSitojun int (*attach)(void *, struct ac97_codec_if *); 5223b5d914Skent int (*read)(void *, uint8_t, uint16_t *); 5323b5d914Skent int (*write)(void *, uint8_t, uint16_t); 5454cf6460Skent int (*reset)(void *); 5505d5f375Sthorpej 567f6ed16eSitojun enum ac97_host_flags (*flags)(void *); 57712239e3Sthorpej void (*spdif_event)(void *, bool); 581838aef2Sthorpej }; 591838aef2Sthorpej 601838aef2Sthorpej /* 611838aef2Sthorpej * This is the interface exported by the AC97 compliant CODEC 621838aef2Sthorpej */ 631838aef2Sthorpej struct ac97_codec_if_vtbl { 647f6ed16eSitojun int (*mixer_get_port)(struct ac97_codec_if *, mixer_ctrl_t *); 657f6ed16eSitojun int (*mixer_set_port)(struct ac97_codec_if *, mixer_ctrl_t *); 667f6ed16eSitojun int (*query_devinfo)(struct ac97_codec_if *, mixer_devinfo_t *); 677f6ed16eSitojun int (*get_portnum_by_name)(struct ac97_codec_if *, const char *, 687f6ed16eSitojun const char *, const char *); 6905d5f375Sthorpej /* 7005d5f375Sthorpej * The AC97 codec driver records the various port settings. This 7105d5f375Sthorpej * function can be used to restore the port settings, e.g. after 7205d5f375Sthorpej * resume from a laptop suspend to disk. 73f08bb8f8Sjmcneill * Also restores AC97_POWER_REG. 7405d5f375Sthorpej */ 757f6ed16eSitojun void (*restore_ports)(struct ac97_codec_if *); 7620040ef7Skent 777f6ed16eSitojun u_int16_t (*get_extcaps)(struct ac97_codec_if *); 7823b5d914Skent int (*set_rate)(struct ac97_codec_if *, int, u_int *); 797f6ed16eSitojun void (*set_clock)(struct ac97_codec_if *, unsigned int); 8080620cc1Skent void (*detach)(struct ac97_codec_if *); 81117c4cc6Skent /** 82117c4cc6Skent * To enable SPDIF, 83117c4cc6Skent * - call unlock() just after ac97_attach() 84117c4cc6Skent * - call lock() in audio_hw_if::open() 85117c4cc6Skent * - call unlock() in audio_hw_if::close() 86117c4cc6Skent */ 87117c4cc6Skent void (*lock)(struct ac97_codec_if *); 88117c4cc6Skent void (*unlock)(struct ac97_codec_if *); 891838aef2Sthorpej }; 901838aef2Sthorpej 911838aef2Sthorpej struct ac97_codec_if { 921838aef2Sthorpej struct ac97_codec_if_vtbl *vtbl; 931838aef2Sthorpej }; 941838aef2Sthorpej 958a962f23Sjmcneill int ac97_attach_type(struct ac97_host_if *, device_t, int, kmutex_t *); 968a962f23Sjmcneill int ac97_attach(struct ac97_host_if *, device_t, kmutex_t *); 9745bd8be9Sthorpej 98145085fcSkent #define AC97_IS_FIXED_RATE(codec) \ 99145085fcSkent !((codec)->vtbl->get_extcaps(codec) & AC97_EXT_AUDIO_VRA) 100145085fcSkent #define AC97_IS_4CH(codec) \ 101145085fcSkent ((codec)->vtbl->get_extcaps(codec) & AC97_EXT_AUDIO_SDAC) 102145085fcSkent #define AC97_IS_6CH(codec) \ 103145085fcSkent (((codec)->vtbl->get_extcaps(codec) \ 104145085fcSkent & (AC97_EXT_AUDIO_SDAC | AC97_EXT_AUDIO_CDAC | AC97_EXT_AUDIO_LDAC)) \ 105145085fcSkent == (AC97_EXT_AUDIO_SDAC | AC97_EXT_AUDIO_CDAC | AC97_EXT_AUDIO_LDAC)) 106cca3038bSreinoud #define AC97_HAS_SPDIF(codec) \ 107cca3038bSreinoud ((codec)->vtbl->get_extcaps(codec) & AC97_EXT_AUDIO_SPDIF) 108c674ab7bSjmcneill 109c674ab7bSjmcneill #define AC97_CODEC_TYPE_AUDIO 1 110c674ab7bSjmcneill #define AC97_CODEC_TYPE_MODEM 2 111c674ab7bSjmcneill 11245bd8be9Sthorpej #endif /* _DEV_IC_AC97VAR_H_ */ 113