ac97_codec.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. #ifndef _AC97_CODEC_H_
  2. #define _AC97_CODEC_H_
  3. #include <linux/types.h>
  4. #include <linux/soundcard.h>
  5. /* AC97 1.0 */
  6. #define AC97_RESET 0x0000 //
  7. #define AC97_MASTER_VOL_STEREO 0x0002 // Line Out
  8. #define AC97_HEADPHONE_VOL 0x0004 //
  9. #define AC97_MASTER_VOL_MONO 0x0006 // TAD Output
  10. #define AC97_MASTER_TONE 0x0008 //
  11. #define AC97_PCBEEP_VOL 0x000a // none
  12. #define AC97_PHONE_VOL 0x000c // TAD Input (mono)
  13. #define AC97_MIC_VOL 0x000e // MIC Input (mono)
  14. #define AC97_LINEIN_VOL 0x0010 // Line Input (stereo)
  15. #define AC97_CD_VOL 0x0012 // CD Input (stereo)
  16. #define AC97_VIDEO_VOL 0x0014 // none
  17. #define AC97_AUX_VOL 0x0016 // Aux Input (stereo)
  18. #define AC97_PCMOUT_VOL 0x0018 // Wave Output (stereo)
  19. #define AC97_RECORD_SELECT 0x001a //
  20. #define AC97_RECORD_GAIN 0x001c
  21. #define AC97_RECORD_GAIN_MIC 0x001e
  22. #define AC97_GENERAL_PURPOSE 0x0020
  23. #define AC97_3D_CONTROL 0x0022
  24. #define AC97_MODEM_RATE 0x0024
  25. #define AC97_POWER_CONTROL 0x0026
  26. /* AC'97 2.0 */
  27. #define AC97_EXTENDED_ID 0x0028 /* Extended Audio ID */
  28. #define AC97_EXTENDED_STATUS 0x002A /* Extended Audio Status */
  29. #define AC97_PCM_FRONT_DAC_RATE 0x002C /* PCM Front DAC Rate */
  30. #define AC97_PCM_SURR_DAC_RATE 0x002E /* PCM Surround DAC Rate */
  31. #define AC97_PCM_LFE_DAC_RATE 0x0030 /* PCM LFE DAC Rate */
  32. #define AC97_PCM_LR_ADC_RATE 0x0032 /* PCM LR ADC Rate */
  33. #define AC97_PCM_MIC_ADC_RATE 0x0034 /* PCM MIC ADC Rate */
  34. #define AC97_CENTER_LFE_MASTER 0x0036 /* Center + LFE Master Volume */
  35. #define AC97_SURROUND_MASTER 0x0038 /* Surround (Rear) Master Volume */
  36. #define AC97_RESERVED_3A 0x003A /* Reserved in AC '97 < 2.2 */
  37. /* AC'97 2.2 */
  38. #define AC97_SPDIF_CONTROL 0x003A /* S/PDIF Control */
  39. /* range 0x3c-0x58 - MODEM */
  40. #define AC97_EXTENDED_MODEM_ID 0x003C
  41. #define AC97_EXTEND_MODEM_STAT 0x003E
  42. #define AC97_LINE1_RATE 0x0040
  43. #define AC97_LINE2_RATE 0x0042
  44. #define AC97_HANDSET_RATE 0x0044
  45. #define AC97_LINE1_LEVEL 0x0046
  46. #define AC97_LINE2_LEVEL 0x0048
  47. #define AC97_HANDSET_LEVEL 0x004A
  48. #define AC97_GPIO_CONFIG 0x004C
  49. #define AC97_GPIO_POLARITY 0x004E
  50. #define AC97_GPIO_STICKY 0x0050
  51. #define AC97_GPIO_WAKE_UP 0x0052
  52. #define AC97_GPIO_STATUS 0x0054
  53. #define AC97_MISC_MODEM_STAT 0x0056
  54. #define AC97_RESERVED_58 0x0058
  55. /* registers 0x005a - 0x007a are vendor reserved */
  56. #define AC97_VENDOR_ID1 0x007c
  57. #define AC97_VENDOR_ID2 0x007e
  58. /* volume control bit defines */
  59. #define AC97_MUTE 0x8000
  60. #define AC97_MICBOOST 0x0040
  61. #define AC97_LEFTVOL 0x3f00
  62. #define AC97_RIGHTVOL 0x003f
  63. /* record mux defines */
  64. #define AC97_RECMUX_MIC 0x0000
  65. #define AC97_RECMUX_CD 0x0101
  66. #define AC97_RECMUX_VIDEO 0x0202
  67. #define AC97_RECMUX_AUX 0x0303
  68. #define AC97_RECMUX_LINE 0x0404
  69. #define AC97_RECMUX_STEREO_MIX 0x0505
  70. #define AC97_RECMUX_MONO_MIX 0x0606
  71. #define AC97_RECMUX_PHONE 0x0707
  72. /* general purpose register bit defines */
  73. #define AC97_GP_LPBK 0x0080 /* Loopback mode */
  74. #define AC97_GP_MS 0x0100 /* Mic Select 0=Mic1, 1=Mic2 */
  75. #define AC97_GP_MIX 0x0200 /* Mono output select 0=Mix, 1=Mic */
  76. #define AC97_GP_RLBK 0x0400 /* Remote Loopback - Modem line codec */
  77. #define AC97_GP_LLBK 0x0800 /* Local Loopback - Modem Line codec */
  78. #define AC97_GP_LD 0x1000 /* Loudness 1=on */
  79. #define AC97_GP_3D 0x2000 /* 3D Enhancement 1=on */
  80. #define AC97_GP_ST 0x4000 /* Stereo Enhancement 1=on */
  81. #define AC97_GP_POP 0x8000 /* Pcm Out Path, 0=pre 3D, 1=post 3D */
  82. /* extended audio status and control bit defines */
  83. #define AC97_EA_VRA 0x0001 /* Variable bit rate enable bit */
  84. #define AC97_EA_DRA 0x0002 /* Double-rate audio enable bit */
  85. #define AC97_EA_SPDIF 0x0004 /* S/PDIF Enable bit */
  86. #define AC97_EA_VRM 0x0008 /* Variable bit rate for MIC enable bit */
  87. #define AC97_EA_CDAC 0x0040 /* PCM Center DAC is ready (Read only) */
  88. #define AC97_EA_SDAC 0x0040 /* PCM Surround DACs are ready (Read only) */
  89. #define AC97_EA_LDAC 0x0080 /* PCM LFE DAC is ready (Read only) */
  90. #define AC97_EA_MDAC 0x0100 /* MIC ADC is ready (Read only) */
  91. #define AC97_EA_SPCV 0x0400 /* S/PDIF configuration valid (Read only) */
  92. #define AC97_EA_PRI 0x0800 /* Turns the PCM Center DAC off */
  93. #define AC97_EA_PRJ 0x1000 /* Turns the PCM Surround DACs off */
  94. #define AC97_EA_PRK 0x2000 /* Turns the PCM LFE DAC off */
  95. #define AC97_EA_PRL 0x4000 /* Turns the MIC ADC off */
  96. #define AC97_EA_SLOT_MASK 0xffcf /* Mask for slot assignment bits */
  97. #define AC97_EA_SPSA_3_4 0x0000 /* Slot assigned to 3 & 4 */
  98. #define AC97_EA_SPSA_7_8 0x0010 /* Slot assigned to 7 & 8 */
  99. #define AC97_EA_SPSA_6_9 0x0020 /* Slot assigned to 6 & 9 */
  100. #define AC97_EA_SPSA_10_11 0x0030 /* Slot assigned to 10 & 11 */
  101. /* S/PDIF control bit defines */
  102. #define AC97_SC_PRO 0x0001 /* Professional status */
  103. #define AC97_SC_NAUDIO 0x0002 /* Non audio stream */
  104. #define AC97_SC_COPY 0x0004 /* Copyright status */
  105. #define AC97_SC_PRE 0x0008 /* Preemphasis status */
  106. #define AC97_SC_CC_MASK 0x07f0 /* Category Code mask */
  107. #define AC97_SC_L 0x0800 /* Generation Level status */
  108. #define AC97_SC_SPSR_MASK 0xcfff /* S/PDIF Sample Rate bits */
  109. #define AC97_SC_SPSR_44K 0x0000 /* Use 44.1kHz Sample rate */
  110. #define AC97_SC_SPSR_48K 0x2000 /* Use 48kHz Sample rate */
  111. #define AC97_SC_SPSR_32K 0x3000 /* Use 32kHz Sample rate */
  112. #define AC97_SC_DRS 0x4000 /* Double Rate S/PDIF */
  113. #define AC97_SC_V 0x8000 /* Validity status */
  114. /* powerdown control and status bit defines */
  115. /* status */
  116. #define AC97_PWR_MDM 0x0010 /* Modem section ready */
  117. #define AC97_PWR_REF 0x0008 /* Vref nominal */
  118. #define AC97_PWR_ANL 0x0004 /* Analog section ready */
  119. #define AC97_PWR_DAC 0x0002 /* DAC section ready */
  120. #define AC97_PWR_ADC 0x0001 /* ADC section ready */
  121. /* control */
  122. #define AC97_PWR_PR0 0x0100 /* ADC and Mux powerdown */
  123. #define AC97_PWR_PR1 0x0200 /* DAC powerdown */
  124. #define AC97_PWR_PR2 0x0400 /* Output mixer powerdown (Vref on) */
  125. #define AC97_PWR_PR3 0x0800 /* Output mixer powerdown (Vref off) */
  126. #define AC97_PWR_PR4 0x1000 /* AC-link powerdown */
  127. #define AC97_PWR_PR5 0x2000 /* Internal Clk disable */
  128. #define AC97_PWR_PR6 0x4000 /* HP amp powerdown */
  129. #define AC97_PWR_PR7 0x8000 /* Modem off - if supported */
  130. /* extended audio ID register bit defines */
  131. #define AC97_EXTID_VRA 0x0001
  132. #define AC97_EXTID_DRA 0x0002
  133. #define AC97_EXTID_SPDIF 0x0004
  134. #define AC97_EXTID_VRM 0x0008
  135. #define AC97_EXTID_DSA0 0x0010
  136. #define AC97_EXTID_DSA1 0x0020
  137. #define AC97_EXTID_CDAC 0x0040
  138. #define AC97_EXTID_SDAC 0x0080
  139. #define AC97_EXTID_LDAC 0x0100
  140. #define AC97_EXTID_AMAP 0x0200
  141. #define AC97_EXTID_REV0 0x0400
  142. #define AC97_EXTID_REV1 0x0800
  143. #define AC97_EXTID_ID0 0x4000
  144. #define AC97_EXTID_ID1 0x8000
  145. /* extended status register bit defines */
  146. #define AC97_EXTSTAT_VRA 0x0001
  147. #define AC97_EXTSTAT_DRA 0x0002
  148. #define AC97_EXTSTAT_SPDIF 0x0004
  149. #define AC97_EXTSTAT_VRM 0x0008
  150. #define AC97_EXTSTAT_SPSA0 0x0010
  151. #define AC97_EXTSTAT_SPSA1 0x0020
  152. #define AC97_EXTSTAT_CDAC 0x0040
  153. #define AC97_EXTSTAT_SDAC 0x0080
  154. #define AC97_EXTSTAT_LDAC 0x0100
  155. #define AC97_EXTSTAT_MADC 0x0200
  156. #define AC97_EXTSTAT_SPCV 0x0400
  157. #define AC97_EXTSTAT_PRI 0x0800
  158. #define AC97_EXTSTAT_PRJ 0x1000
  159. #define AC97_EXTSTAT_PRK 0x2000
  160. #define AC97_EXTSTAT_PRL 0x4000
  161. /* extended audio ID register bit defines */
  162. #define AC97_EXTID_VRA 0x0001
  163. #define AC97_EXTID_DRA 0x0002
  164. #define AC97_EXTID_SPDIF 0x0004
  165. #define AC97_EXTID_VRM 0x0008
  166. #define AC97_EXTID_DSA0 0x0010
  167. #define AC97_EXTID_DSA1 0x0020
  168. #define AC97_EXTID_CDAC 0x0040
  169. #define AC97_EXTID_SDAC 0x0080
  170. #define AC97_EXTID_LDAC 0x0100
  171. #define AC97_EXTID_AMAP 0x0200
  172. #define AC97_EXTID_REV0 0x0400
  173. #define AC97_EXTID_REV1 0x0800
  174. #define AC97_EXTID_ID0 0x4000
  175. #define AC97_EXTID_ID1 0x8000
  176. /* extended status register bit defines */
  177. #define AC97_EXTSTAT_VRA 0x0001
  178. #define AC97_EXTSTAT_DRA 0x0002
  179. #define AC97_EXTSTAT_SPDIF 0x0004
  180. #define AC97_EXTSTAT_VRM 0x0008
  181. #define AC97_EXTSTAT_SPSA0 0x0010
  182. #define AC97_EXTSTAT_SPSA1 0x0020
  183. #define AC97_EXTSTAT_CDAC 0x0040
  184. #define AC97_EXTSTAT_SDAC 0x0080
  185. #define AC97_EXTSTAT_LDAC 0x0100
  186. #define AC97_EXTSTAT_MADC 0x0200
  187. #define AC97_EXTSTAT_SPCV 0x0400
  188. #define AC97_EXTSTAT_PRI 0x0800
  189. #define AC97_EXTSTAT_PRJ 0x1000
  190. #define AC97_EXTSTAT_PRK 0x2000
  191. #define AC97_EXTSTAT_PRL 0x4000
  192. /* useful power states */
  193. #define AC97_PWR_D0 0x0000 /* everything on */
  194. #define AC97_PWR_D1 AC97_PWR_PR0|AC97_PWR_PR1|AC97_PWR_PR4
  195. #define AC97_PWR_D2 AC97_PWR_PR0|AC97_PWR_PR1|AC97_PWR_PR2|AC97_PWR_PR3|AC97_PWR_PR4
  196. #define AC97_PWR_D3 AC97_PWR_PR0|AC97_PWR_PR1|AC97_PWR_PR2|AC97_PWR_PR3|AC97_PWR_PR4
  197. #define AC97_PWR_ANLOFF AC97_PWR_PR2|AC97_PWR_PR3 /* analog section off */
  198. /* Total number of defined registers. */
  199. #define AC97_REG_CNT 64
  200. /* OSS interface to the ac97s.. */
  201. #define AC97_STEREO_MASK (SOUND_MASK_VOLUME|SOUND_MASK_PCM|\
  202. SOUND_MASK_LINE|SOUND_MASK_CD|\
  203. SOUND_MASK_ALTPCM|SOUND_MASK_IGAIN|\
  204. SOUND_MASK_LINE1|SOUND_MASK_VIDEO)
  205. #define AC97_SUPPORTED_MASK (AC97_STEREO_MASK | \
  206. SOUND_MASK_BASS|SOUND_MASK_TREBLE|\
  207. SOUND_MASK_SPEAKER|SOUND_MASK_MIC|\
  208. SOUND_MASK_PHONEIN|SOUND_MASK_PHONEOUT)
  209. #define AC97_RECORD_MASK (SOUND_MASK_MIC|\
  210. SOUND_MASK_CD|SOUND_MASK_IGAIN|SOUND_MASK_VIDEO|\
  211. SOUND_MASK_LINE1| SOUND_MASK_LINE|\
  212. SOUND_MASK_PHONEIN)
  213. /* original check is not good enough in case FOO is greater than
  214. * SOUND_MIXER_NRDEVICES because the supported_mixers has exactly
  215. * SOUND_MIXER_NRDEVICES elements.
  216. * before matching the given mixer against the bitmask in supported_mixers we
  217. * check if mixer number exceeds maximum allowed size which is as mentioned
  218. * above SOUND_MIXER_NRDEVICES */
  219. #define supported_mixer(CODEC,FOO) ((FOO >= 0) && \
  220. (FOO < SOUND_MIXER_NRDEVICES) && \
  221. (CODEC)->supported_mixers & (1<<FOO) )
  222. struct ac97_codec {
  223. /* Linked list of codecs */
  224. struct list_head list;
  225. /* AC97 controller connected with */
  226. void *private_data;
  227. char *name;
  228. int id;
  229. int dev_mixer;
  230. int type;
  231. u32 model;
  232. unsigned int modem:1;
  233. struct ac97_ops *codec_ops;
  234. /* controller specific lower leverl ac97 accessing routines.
  235. must be re-entrant safe */
  236. u16 (*codec_read) (struct ac97_codec *codec, u8 reg);
  237. void (*codec_write) (struct ac97_codec *codec, u8 reg, u16 val);
  238. /* Wait for codec-ready. Ok to sleep here. */
  239. void (*codec_wait) (struct ac97_codec *codec);
  240. /* callback used by helper drivers for interesting ac97 setups */
  241. void (*codec_unregister) (struct ac97_codec *codec);
  242. struct ac97_driver *driver;
  243. void *driver_private; /* Private data for the driver */
  244. spinlock_t lock;
  245. /* OSS mixer masks */
  246. int modcnt;
  247. int supported_mixers;
  248. int stereo_mixers;
  249. int record_sources;
  250. /* Property flags */
  251. int flags;
  252. int bit_resolution;
  253. /* OSS mixer interface */
  254. int (*read_mixer) (struct ac97_codec *codec, int oss_channel);
  255. void (*write_mixer)(struct ac97_codec *codec, int oss_channel,
  256. unsigned int left, unsigned int right);
  257. int (*recmask_io) (struct ac97_codec *codec, int rw, int mask);
  258. int (*mixer_ioctl)(struct ac97_codec *codec, unsigned int cmd, unsigned long arg);
  259. /* saved OSS mixer states */
  260. unsigned int mixer_state[SOUND_MIXER_NRDEVICES];
  261. /* Software Modem interface */
  262. int (*modem_ioctl)(struct ac97_codec *codec, unsigned int cmd, unsigned long arg);
  263. };
  264. /*
  265. * Operation structures for each known AC97 chip
  266. */
  267. struct ac97_ops
  268. {
  269. /* Initialise */
  270. int (*init)(struct ac97_codec *c);
  271. /* Amplifier control */
  272. int (*amplifier)(struct ac97_codec *codec, int on);
  273. /* Digital mode control */
  274. int (*digital)(struct ac97_codec *codec, int slots, int rate, int mode);
  275. #define AUDIO_DIGITAL 0x8000
  276. #define AUDIO_PRO 0x4000
  277. #define AUDIO_DRS 0x2000
  278. #define AUDIO_CCMASK 0x003F
  279. #define AC97_DELUDED_MODEM 1 /* Audio codec reports its a modem */
  280. #define AC97_NO_PCM_VOLUME 2 /* Volume control is missing */
  281. #define AC97_DEFAULT_POWER_OFF 4 /* Needs warm reset to power up */
  282. };
  283. extern int ac97_probe_codec(struct ac97_codec *);
  284. extern struct ac97_codec *ac97_alloc_codec(void);
  285. extern void ac97_release_codec(struct ac97_codec *codec);
  286. struct ac97_driver {
  287. struct list_head list;
  288. char *name;
  289. u32 codec_id;
  290. u32 codec_mask;
  291. int (*probe) (struct ac97_codec *codec, struct ac97_driver *driver);
  292. void (*remove) (struct ac97_codec *codec, struct ac97_driver *driver);
  293. };
  294. /* quirk types */
  295. enum {
  296. AC97_TUNE_DEFAULT = -1, /* use default from quirk list (not valid in list) */
  297. AC97_TUNE_NONE = 0, /* nothing extra to do */
  298. AC97_TUNE_HP_ONLY, /* headphone (true line-out) control as master only */
  299. AC97_TUNE_SWAP_HP, /* swap headphone and master controls */
  300. AC97_TUNE_SWAP_SURROUND, /* swap master and surround controls */
  301. AC97_TUNE_AD_SHARING, /* for AD1985, turn on OMS bit and use headphone */
  302. AC97_TUNE_ALC_JACK, /* for Realtek, enable JACK detection */
  303. };
  304. struct ac97_quirk {
  305. unsigned short vendor; /* PCI vendor id */
  306. unsigned short device; /* PCI device id */
  307. unsigned short mask; /* device id bit mask, 0 = accept all */
  308. const char *name; /* name shown as info */
  309. int type; /* quirk type above */
  310. };
  311. #endif /* _AC97_CODEC_H_ */