hda_codec.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef __SOUND_HDA_CODEC_H
  21. #define __SOUND_HDA_CODEC_H
  22. #include <sound/info.h>
  23. #include <sound/control.h>
  24. #include <sound/pcm.h>
  25. #include <sound/hwdep.h>
  26. #if defined(CONFIG_PM) || defined(CONFIG_SND_HDA_POWER_SAVE)
  27. #define SND_HDA_NEEDS_RESUME /* resume control code is required */
  28. #endif
  29. /*
  30. * nodes
  31. */
  32. #define AC_NODE_ROOT 0x00
  33. /*
  34. * function group types
  35. */
  36. enum {
  37. AC_GRP_AUDIO_FUNCTION = 0x01,
  38. AC_GRP_MODEM_FUNCTION = 0x02,
  39. };
  40. /*
  41. * widget types
  42. */
  43. enum {
  44. AC_WID_AUD_OUT, /* Audio Out */
  45. AC_WID_AUD_IN, /* Audio In */
  46. AC_WID_AUD_MIX, /* Audio Mixer */
  47. AC_WID_AUD_SEL, /* Audio Selector */
  48. AC_WID_PIN, /* Pin Complex */
  49. AC_WID_POWER, /* Power */
  50. AC_WID_VOL_KNB, /* Volume Knob */
  51. AC_WID_BEEP, /* Beep Generator */
  52. AC_WID_VENDOR = 0x0f /* Vendor specific */
  53. };
  54. /*
  55. * GET verbs
  56. */
  57. #define AC_VERB_GET_STREAM_FORMAT 0x0a00
  58. #define AC_VERB_GET_AMP_GAIN_MUTE 0x0b00
  59. #define AC_VERB_GET_PROC_COEF 0x0c00
  60. #define AC_VERB_GET_COEF_INDEX 0x0d00
  61. #define AC_VERB_PARAMETERS 0x0f00
  62. #define AC_VERB_GET_CONNECT_SEL 0x0f01
  63. #define AC_VERB_GET_CONNECT_LIST 0x0f02
  64. #define AC_VERB_GET_PROC_STATE 0x0f03
  65. #define AC_VERB_GET_SDI_SELECT 0x0f04
  66. #define AC_VERB_GET_POWER_STATE 0x0f05
  67. #define AC_VERB_GET_CONV 0x0f06
  68. #define AC_VERB_GET_PIN_WIDGET_CONTROL 0x0f07
  69. #define AC_VERB_GET_UNSOLICITED_RESPONSE 0x0f08
  70. #define AC_VERB_GET_PIN_SENSE 0x0f09
  71. #define AC_VERB_GET_BEEP_CONTROL 0x0f0a
  72. #define AC_VERB_GET_EAPD_BTLENABLE 0x0f0c
  73. #define AC_VERB_GET_DIGI_CONVERT_1 0x0f0d
  74. #define AC_VERB_GET_DIGI_CONVERT_2 0x0f0e /* unused */
  75. #define AC_VERB_GET_VOLUME_KNOB_CONTROL 0x0f0f
  76. /* f10-f1a: GPIO */
  77. #define AC_VERB_GET_GPIO_DATA 0x0f15
  78. #define AC_VERB_GET_GPIO_MASK 0x0f16
  79. #define AC_VERB_GET_GPIO_DIRECTION 0x0f17
  80. #define AC_VERB_GET_GPIO_WAKE_MASK 0x0f18
  81. #define AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK 0x0f19
  82. #define AC_VERB_GET_GPIO_STICKY_MASK 0x0f1a
  83. #define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c
  84. /* f20: AFG/MFG */
  85. #define AC_VERB_GET_SUBSYSTEM_ID 0x0f20
  86. #define AC_VERB_GET_CVT_CHAN_COUNT 0x0f2d
  87. #define AC_VERB_GET_HDMI_DIP_SIZE 0x0f2e
  88. #define AC_VERB_GET_HDMI_ELDD 0x0f2f
  89. #define AC_VERB_GET_HDMI_DIP_INDEX 0x0f30
  90. #define AC_VERB_GET_HDMI_DIP_DATA 0x0f31
  91. #define AC_VERB_GET_HDMI_DIP_XMIT 0x0f32
  92. #define AC_VERB_GET_HDMI_CP_CTRL 0x0f33
  93. #define AC_VERB_GET_HDMI_CHAN_SLOT 0x0f34
  94. /*
  95. * SET verbs
  96. */
  97. #define AC_VERB_SET_STREAM_FORMAT 0x200
  98. #define AC_VERB_SET_AMP_GAIN_MUTE 0x300
  99. #define AC_VERB_SET_PROC_COEF 0x400
  100. #define AC_VERB_SET_COEF_INDEX 0x500
  101. #define AC_VERB_SET_CONNECT_SEL 0x701
  102. #define AC_VERB_SET_PROC_STATE 0x703
  103. #define AC_VERB_SET_SDI_SELECT 0x704
  104. #define AC_VERB_SET_POWER_STATE 0x705
  105. #define AC_VERB_SET_CHANNEL_STREAMID 0x706
  106. #define AC_VERB_SET_PIN_WIDGET_CONTROL 0x707
  107. #define AC_VERB_SET_UNSOLICITED_ENABLE 0x708
  108. #define AC_VERB_SET_PIN_SENSE 0x709
  109. #define AC_VERB_SET_BEEP_CONTROL 0x70a
  110. #define AC_VERB_SET_EAPD_BTLENABLE 0x70c
  111. #define AC_VERB_SET_DIGI_CONVERT_1 0x70d
  112. #define AC_VERB_SET_DIGI_CONVERT_2 0x70e
  113. #define AC_VERB_SET_VOLUME_KNOB_CONTROL 0x70f
  114. #define AC_VERB_SET_GPIO_DATA 0x715
  115. #define AC_VERB_SET_GPIO_MASK 0x716
  116. #define AC_VERB_SET_GPIO_DIRECTION 0x717
  117. #define AC_VERB_SET_GPIO_WAKE_MASK 0x718
  118. #define AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK 0x719
  119. #define AC_VERB_SET_GPIO_STICKY_MASK 0x71a
  120. #define AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 0x71c
  121. #define AC_VERB_SET_CONFIG_DEFAULT_BYTES_1 0x71d
  122. #define AC_VERB_SET_CONFIG_DEFAULT_BYTES_2 0x71e
  123. #define AC_VERB_SET_CONFIG_DEFAULT_BYTES_3 0x71f
  124. #define AC_VERB_SET_EAPD 0x788
  125. #define AC_VERB_SET_CODEC_RESET 0x7ff
  126. #define AC_VERB_SET_CVT_CHAN_COUNT 0x72d
  127. #define AC_VERB_SET_HDMI_DIP_INDEX 0x730
  128. #define AC_VERB_SET_HDMI_DIP_DATA 0x731
  129. #define AC_VERB_SET_HDMI_DIP_XMIT 0x732
  130. #define AC_VERB_SET_HDMI_CP_CTRL 0x733
  131. #define AC_VERB_SET_HDMI_CHAN_SLOT 0x734
  132. /*
  133. * Parameter IDs
  134. */
  135. #define AC_PAR_VENDOR_ID 0x00
  136. #define AC_PAR_SUBSYSTEM_ID 0x01
  137. #define AC_PAR_REV_ID 0x02
  138. #define AC_PAR_NODE_COUNT 0x04
  139. #define AC_PAR_FUNCTION_TYPE 0x05
  140. #define AC_PAR_AUDIO_FG_CAP 0x08
  141. #define AC_PAR_AUDIO_WIDGET_CAP 0x09
  142. #define AC_PAR_PCM 0x0a
  143. #define AC_PAR_STREAM 0x0b
  144. #define AC_PAR_PIN_CAP 0x0c
  145. #define AC_PAR_AMP_IN_CAP 0x0d
  146. #define AC_PAR_CONNLIST_LEN 0x0e
  147. #define AC_PAR_POWER_STATE 0x0f
  148. #define AC_PAR_PROC_CAP 0x10
  149. #define AC_PAR_GPIO_CAP 0x11
  150. #define AC_PAR_AMP_OUT_CAP 0x12
  151. #define AC_PAR_VOL_KNB_CAP 0x13
  152. #define AC_PAR_HDMI_LPCM_CAP 0x20
  153. /*
  154. * AC_VERB_PARAMETERS results (32bit)
  155. */
  156. /* Function Group Type */
  157. #define AC_FGT_TYPE (0xff<<0)
  158. #define AC_FGT_TYPE_SHIFT 0
  159. #define AC_FGT_UNSOL_CAP (1<<8)
  160. /* Audio Function Group Capabilities */
  161. #define AC_AFG_OUT_DELAY (0xf<<0)
  162. #define AC_AFG_IN_DELAY (0xf<<8)
  163. #define AC_AFG_BEEP_GEN (1<<16)
  164. /* Audio Widget Capabilities */
  165. #define AC_WCAP_STEREO (1<<0) /* stereo I/O */
  166. #define AC_WCAP_IN_AMP (1<<1) /* AMP-in present */
  167. #define AC_WCAP_OUT_AMP (1<<2) /* AMP-out present */
  168. #define AC_WCAP_AMP_OVRD (1<<3) /* AMP-parameter override */
  169. #define AC_WCAP_FORMAT_OVRD (1<<4) /* format override */
  170. #define AC_WCAP_STRIPE (1<<5) /* stripe */
  171. #define AC_WCAP_PROC_WID (1<<6) /* Proc Widget */
  172. #define AC_WCAP_UNSOL_CAP (1<<7) /* Unsol capable */
  173. #define AC_WCAP_CONN_LIST (1<<8) /* connection list */
  174. #define AC_WCAP_DIGITAL (1<<9) /* digital I/O */
  175. #define AC_WCAP_POWER (1<<10) /* power control */
  176. #define AC_WCAP_LR_SWAP (1<<11) /* L/R swap */
  177. #define AC_WCAP_CP_CAPS (1<<12) /* content protection */
  178. #define AC_WCAP_CHAN_CNT_EXT (7<<13) /* channel count ext */
  179. #define AC_WCAP_DELAY (0xf<<16)
  180. #define AC_WCAP_DELAY_SHIFT 16
  181. #define AC_WCAP_TYPE (0xf<<20)
  182. #define AC_WCAP_TYPE_SHIFT 20
  183. /* supported PCM rates and bits */
  184. #define AC_SUPPCM_RATES (0xfff << 0)
  185. #define AC_SUPPCM_BITS_8 (1<<16)
  186. #define AC_SUPPCM_BITS_16 (1<<17)
  187. #define AC_SUPPCM_BITS_20 (1<<18)
  188. #define AC_SUPPCM_BITS_24 (1<<19)
  189. #define AC_SUPPCM_BITS_32 (1<<20)
  190. /* supported PCM stream format */
  191. #define AC_SUPFMT_PCM (1<<0)
  192. #define AC_SUPFMT_FLOAT32 (1<<1)
  193. #define AC_SUPFMT_AC3 (1<<2)
  194. /* GP I/O count */
  195. #define AC_GPIO_IO_COUNT (0xff<<0)
  196. #define AC_GPIO_O_COUNT (0xff<<8)
  197. #define AC_GPIO_O_COUNT_SHIFT 8
  198. #define AC_GPIO_I_COUNT (0xff<<16)
  199. #define AC_GPIO_I_COUNT_SHIFT 16
  200. #define AC_GPIO_UNSOLICITED (1<<30)
  201. #define AC_GPIO_WAKE (1<<31)
  202. /* Converter stream, channel */
  203. #define AC_CONV_CHANNEL (0xf<<0)
  204. #define AC_CONV_STREAM (0xf<<4)
  205. #define AC_CONV_STREAM_SHIFT 4
  206. /* Input converter SDI select */
  207. #define AC_SDI_SELECT (0xf<<0)
  208. /* Unsolicited response control */
  209. #define AC_UNSOL_TAG (0x3f<<0)
  210. #define AC_UNSOL_ENABLED (1<<7)
  211. #define AC_USRSP_EN AC_UNSOL_ENABLED
  212. /* Unsolicited responses */
  213. #define AC_UNSOL_RES_TAG (0x3f<<26)
  214. #define AC_UNSOL_RES_TAG_SHIFT 26
  215. #define AC_UNSOL_RES_SUBTAG (0x1f<<21)
  216. #define AC_UNSOL_RES_SUBTAG_SHIFT 21
  217. #define AC_UNSOL_RES_ELDV (1<<1) /* ELD Data valid (for HDMI) */
  218. #define AC_UNSOL_RES_PD (1<<0) /* pinsense detect */
  219. #define AC_UNSOL_RES_CP_STATE (1<<1) /* content protection */
  220. #define AC_UNSOL_RES_CP_READY (1<<0) /* content protection */
  221. /* Pin widget capabilies */
  222. #define AC_PINCAP_IMP_SENSE (1<<0) /* impedance sense capable */
  223. #define AC_PINCAP_TRIG_REQ (1<<1) /* trigger required */
  224. #define AC_PINCAP_PRES_DETECT (1<<2) /* presence detect capable */
  225. #define AC_PINCAP_HP_DRV (1<<3) /* headphone drive capable */
  226. #define AC_PINCAP_OUT (1<<4) /* output capable */
  227. #define AC_PINCAP_IN (1<<5) /* input capable */
  228. #define AC_PINCAP_BALANCE (1<<6) /* balanced I/O capable */
  229. /* Note: This LR_SWAP pincap is defined in the Realtek ALC883 specification,
  230. * but is marked reserved in the Intel HDA specification.
  231. */
  232. #define AC_PINCAP_LR_SWAP (1<<7) /* L/R swap */
  233. /* Note: The same bit as LR_SWAP is newly defined as HDMI capability
  234. * in HD-audio specification
  235. */
  236. #define AC_PINCAP_HDMI (1<<7) /* HDMI pin */
  237. #define AC_PINCAP_DP (1<<24) /* DisplayPort pin, can
  238. * coexist with AC_PINCAP_HDMI
  239. */
  240. #define AC_PINCAP_VREF (0x37<<8)
  241. #define AC_PINCAP_VREF_SHIFT 8
  242. #define AC_PINCAP_EAPD (1<<16) /* EAPD capable */
  243. #define AC_PINCAP_HBR (1<<27) /* High Bit Rate */
  244. /* Vref status (used in pin cap) */
  245. #define AC_PINCAP_VREF_HIZ (1<<0) /* Hi-Z */
  246. #define AC_PINCAP_VREF_50 (1<<1) /* 50% */
  247. #define AC_PINCAP_VREF_GRD (1<<2) /* ground */
  248. #define AC_PINCAP_VREF_80 (1<<4) /* 80% */
  249. #define AC_PINCAP_VREF_100 (1<<5) /* 100% */
  250. /* Amplifier capabilities */
  251. #define AC_AMPCAP_OFFSET (0x7f<<0) /* 0dB offset */
  252. #define AC_AMPCAP_OFFSET_SHIFT 0
  253. #define AC_AMPCAP_NUM_STEPS (0x7f<<8) /* number of steps */
  254. #define AC_AMPCAP_NUM_STEPS_SHIFT 8
  255. #define AC_AMPCAP_STEP_SIZE (0x7f<<16) /* step size 0-32dB
  256. * in 0.25dB
  257. */
  258. #define AC_AMPCAP_STEP_SIZE_SHIFT 16
  259. #define AC_AMPCAP_MUTE (1<<31) /* mute capable */
  260. #define AC_AMPCAP_MUTE_SHIFT 31
  261. /* Connection list */
  262. #define AC_CLIST_LENGTH (0x7f<<0)
  263. #define AC_CLIST_LONG (1<<7)
  264. /* Supported power status */
  265. #define AC_PWRST_D0SUP (1<<0)
  266. #define AC_PWRST_D1SUP (1<<1)
  267. #define AC_PWRST_D2SUP (1<<2)
  268. #define AC_PWRST_D3SUP (1<<3)
  269. #define AC_PWRST_D3COLDSUP (1<<4)
  270. #define AC_PWRST_S3D3COLDSUP (1<<29)
  271. #define AC_PWRST_CLKSTOP (1<<30)
  272. #define AC_PWRST_EPSS (1U<<31)
  273. /* Power state values */
  274. #define AC_PWRST_SETTING (0xf<<0)
  275. #define AC_PWRST_ACTUAL (0xf<<4)
  276. #define AC_PWRST_ACTUAL_SHIFT 4
  277. #define AC_PWRST_D0 0x00
  278. #define AC_PWRST_D1 0x01
  279. #define AC_PWRST_D2 0x02
  280. #define AC_PWRST_D3 0x03
  281. /* Processing capabilies */
  282. #define AC_PCAP_BENIGN (1<<0)
  283. #define AC_PCAP_NUM_COEF (0xff<<8)
  284. #define AC_PCAP_NUM_COEF_SHIFT 8
  285. /* Volume knobs capabilities */
  286. #define AC_KNBCAP_NUM_STEPS (0x7f<<0)
  287. #define AC_KNBCAP_DELTA (1<<7)
  288. /* HDMI LPCM capabilities */
  289. #define AC_LPCMCAP_48K_CP_CHNS (0x0f<<0) /* max channels w/ CP-on */
  290. #define AC_LPCMCAP_48K_NO_CHNS (0x0f<<4) /* max channels w/o CP-on */
  291. #define AC_LPCMCAP_48K_20BIT (1<<8) /* 20b bitrate supported */
  292. #define AC_LPCMCAP_48K_24BIT (1<<9) /* 24b bitrate supported */
  293. #define AC_LPCMCAP_96K_CP_CHNS (0x0f<<10) /* max channels w/ CP-on */
  294. #define AC_LPCMCAP_96K_NO_CHNS (0x0f<<14) /* max channels w/o CP-on */
  295. #define AC_LPCMCAP_96K_20BIT (1<<18) /* 20b bitrate supported */
  296. #define AC_LPCMCAP_96K_24BIT (1<<19) /* 24b bitrate supported */
  297. #define AC_LPCMCAP_192K_CP_CHNS (0x0f<<20) /* max channels w/ CP-on */
  298. #define AC_LPCMCAP_192K_NO_CHNS (0x0f<<24) /* max channels w/o CP-on */
  299. #define AC_LPCMCAP_192K_20BIT (1<<28) /* 20b bitrate supported */
  300. #define AC_LPCMCAP_192K_24BIT (1<<29) /* 24b bitrate supported */
  301. #define AC_LPCMCAP_44K (1<<30) /* 44.1kHz support */
  302. #define AC_LPCMCAP_44K_MS (1<<31) /* 44.1kHz-multiplies support */
  303. /*
  304. * Control Parameters
  305. */
  306. /* Amp gain/mute */
  307. #define AC_AMP_MUTE (1<<7)
  308. #define AC_AMP_GAIN (0x7f)
  309. #define AC_AMP_GET_INDEX (0xf<<0)
  310. #define AC_AMP_GET_LEFT (1<<13)
  311. #define AC_AMP_GET_RIGHT (0<<13)
  312. #define AC_AMP_GET_OUTPUT (1<<15)
  313. #define AC_AMP_GET_INPUT (0<<15)
  314. #define AC_AMP_SET_INDEX (0xf<<8)
  315. #define AC_AMP_SET_INDEX_SHIFT 8
  316. #define AC_AMP_SET_RIGHT (1<<12)
  317. #define AC_AMP_SET_LEFT (1<<13)
  318. #define AC_AMP_SET_INPUT (1<<14)
  319. #define AC_AMP_SET_OUTPUT (1<<15)
  320. /* DIGITAL1 bits */
  321. #define AC_DIG1_ENABLE (1<<0)
  322. #define AC_DIG1_V (1<<1)
  323. #define AC_DIG1_VCFG (1<<2)
  324. #define AC_DIG1_EMPHASIS (1<<3)
  325. #define AC_DIG1_COPYRIGHT (1<<4)
  326. #define AC_DIG1_NONAUDIO (1<<5)
  327. #define AC_DIG1_PROFESSIONAL (1<<6)
  328. #define AC_DIG1_LEVEL (1<<7)
  329. /* DIGITAL2 bits */
  330. #define AC_DIG2_CC (0x7f<<0)
  331. /* Pin widget control - 8bit */
  332. #define AC_PINCTL_VREFEN (0x7<<0)
  333. #define AC_PINCTL_VREF_HIZ 0 /* Hi-Z */
  334. #define AC_PINCTL_VREF_50 1 /* 50% */
  335. #define AC_PINCTL_VREF_GRD 2 /* ground */
  336. #define AC_PINCTL_VREF_80 4 /* 80% */
  337. #define AC_PINCTL_VREF_100 5 /* 100% */
  338. #define AC_PINCTL_IN_EN (1<<5)
  339. #define AC_PINCTL_OUT_EN (1<<6)
  340. #define AC_PINCTL_HP_EN (1<<7)
  341. /* Pin sense - 32bit */
  342. #define AC_PINSENSE_IMPEDANCE_MASK (0x7fffffff)
  343. #define AC_PINSENSE_PRESENCE (1<<31)
  344. #define AC_PINSENSE_ELDV (1<<30) /* ELD valid (HDMI) */
  345. /* EAPD/BTL enable - 32bit */
  346. #define AC_EAPDBTL_BALANCED (1<<0)
  347. #define AC_EAPDBTL_EAPD (1<<1)
  348. #define AC_EAPDBTL_LR_SWAP (1<<2)
  349. /* HDMI ELD data */
  350. #define AC_ELDD_ELD_VALID (1<<31)
  351. #define AC_ELDD_ELD_DATA 0xff
  352. /* HDMI DIP size */
  353. #define AC_DIPSIZE_ELD_BUF (1<<3) /* ELD buf size of packet size */
  354. #define AC_DIPSIZE_PACK_IDX (0x07<<0) /* packet index */
  355. /* HDMI DIP index */
  356. #define AC_DIPIDX_PACK_IDX (0x07<<5) /* packet idnex */
  357. #define AC_DIPIDX_BYTE_IDX (0x1f<<0) /* byte index */
  358. /* HDMI DIP xmit (transmit) control */
  359. #define AC_DIPXMIT_MASK (0x3<<6)
  360. #define AC_DIPXMIT_DISABLE (0x0<<6) /* disable xmit */
  361. #define AC_DIPXMIT_ONCE (0x2<<6) /* xmit once then disable */
  362. #define AC_DIPXMIT_BEST (0x3<<6) /* best effort */
  363. /* HDMI content protection (CP) control */
  364. #define AC_CPCTRL_CES (1<<9) /* current encryption state */
  365. #define AC_CPCTRL_READY (1<<8) /* ready bit */
  366. #define AC_CPCTRL_SUBTAG (0x1f<<3) /* subtag for unsol-resp */
  367. #define AC_CPCTRL_STATE (3<<0) /* current CP request state */
  368. /* Converter channel <-> HDMI slot mapping */
  369. #define AC_CVTMAP_HDMI_SLOT (0xf<<0) /* HDMI slot number */
  370. #define AC_CVTMAP_CHAN (0xf<<4) /* converter channel number */
  371. /* configuration default - 32bit */
  372. #define AC_DEFCFG_SEQUENCE (0xf<<0)
  373. #define AC_DEFCFG_DEF_ASSOC (0xf<<4)
  374. #define AC_DEFCFG_ASSOC_SHIFT 4
  375. #define AC_DEFCFG_MISC (0xf<<8)
  376. #define AC_DEFCFG_MISC_SHIFT 8
  377. #define AC_DEFCFG_MISC_NO_PRESENCE (1<<0)
  378. #define AC_DEFCFG_COLOR (0xf<<12)
  379. #define AC_DEFCFG_COLOR_SHIFT 12
  380. #define AC_DEFCFG_CONN_TYPE (0xf<<16)
  381. #define AC_DEFCFG_CONN_TYPE_SHIFT 16
  382. #define AC_DEFCFG_DEVICE (0xf<<20)
  383. #define AC_DEFCFG_DEVICE_SHIFT 20
  384. #define AC_DEFCFG_LOCATION (0x3f<<24)
  385. #define AC_DEFCFG_LOCATION_SHIFT 24
  386. #define AC_DEFCFG_PORT_CONN (0x3<<30)
  387. #define AC_DEFCFG_PORT_CONN_SHIFT 30
  388. /* device device types (0x0-0xf) */
  389. enum {
  390. AC_JACK_LINE_OUT,
  391. AC_JACK_SPEAKER,
  392. AC_JACK_HP_OUT,
  393. AC_JACK_CD,
  394. AC_JACK_SPDIF_OUT,
  395. AC_JACK_DIG_OTHER_OUT,
  396. AC_JACK_MODEM_LINE_SIDE,
  397. AC_JACK_MODEM_HAND_SIDE,
  398. AC_JACK_LINE_IN,
  399. AC_JACK_AUX,
  400. AC_JACK_MIC_IN,
  401. AC_JACK_TELEPHONY,
  402. AC_JACK_SPDIF_IN,
  403. AC_JACK_DIG_OTHER_IN,
  404. AC_JACK_OTHER = 0xf,
  405. };
  406. /* jack connection types (0x0-0xf) */
  407. enum {
  408. AC_JACK_CONN_UNKNOWN,
  409. AC_JACK_CONN_1_8,
  410. AC_JACK_CONN_1_4,
  411. AC_JACK_CONN_ATAPI,
  412. AC_JACK_CONN_RCA,
  413. AC_JACK_CONN_OPTICAL,
  414. AC_JACK_CONN_OTHER_DIGITAL,
  415. AC_JACK_CONN_OTHER_ANALOG,
  416. AC_JACK_CONN_DIN,
  417. AC_JACK_CONN_XLR,
  418. AC_JACK_CONN_RJ11,
  419. AC_JACK_CONN_COMB,
  420. AC_JACK_CONN_OTHER = 0xf,
  421. };
  422. /* jack colors (0x0-0xf) */
  423. enum {
  424. AC_JACK_COLOR_UNKNOWN,
  425. AC_JACK_COLOR_BLACK,
  426. AC_JACK_COLOR_GREY,
  427. AC_JACK_COLOR_BLUE,
  428. AC_JACK_COLOR_GREEN,
  429. AC_JACK_COLOR_RED,
  430. AC_JACK_COLOR_ORANGE,
  431. AC_JACK_COLOR_YELLOW,
  432. AC_JACK_COLOR_PURPLE,
  433. AC_JACK_COLOR_PINK,
  434. AC_JACK_COLOR_WHITE = 0xe,
  435. AC_JACK_COLOR_OTHER,
  436. };
  437. /* Jack location (0x0-0x3f) */
  438. /* common case */
  439. enum {
  440. AC_JACK_LOC_NONE,
  441. AC_JACK_LOC_REAR,
  442. AC_JACK_LOC_FRONT,
  443. AC_JACK_LOC_LEFT,
  444. AC_JACK_LOC_RIGHT,
  445. AC_JACK_LOC_TOP,
  446. AC_JACK_LOC_BOTTOM,
  447. };
  448. /* bits 4-5 */
  449. enum {
  450. AC_JACK_LOC_EXTERNAL = 0x00,
  451. AC_JACK_LOC_INTERNAL = 0x10,
  452. AC_JACK_LOC_SEPARATE = 0x20,
  453. AC_JACK_LOC_OTHER = 0x30,
  454. };
  455. enum {
  456. /* external on primary chasis */
  457. AC_JACK_LOC_REAR_PANEL = 0x07,
  458. AC_JACK_LOC_DRIVE_BAY,
  459. /* internal */
  460. AC_JACK_LOC_RISER = 0x17,
  461. AC_JACK_LOC_HDMI,
  462. AC_JACK_LOC_ATAPI,
  463. /* others */
  464. AC_JACK_LOC_MOBILE_IN = 0x37,
  465. AC_JACK_LOC_MOBILE_OUT,
  466. };
  467. /* Port connectivity (0-3) */
  468. enum {
  469. AC_JACK_PORT_COMPLEX,
  470. AC_JACK_PORT_NONE,
  471. AC_JACK_PORT_FIXED,
  472. AC_JACK_PORT_BOTH,
  473. };
  474. /* max. connections to a widget */
  475. #define HDA_MAX_CONNECTIONS 32
  476. /* max. codec address */
  477. #define HDA_MAX_CODEC_ADDRESS 0x0f
  478. /* max number of PCM devics per card */
  479. #define HDA_MAX_PCMS 10
  480. /*
  481. * generic arrays
  482. */
  483. struct snd_array {
  484. unsigned int used;
  485. unsigned int alloced;
  486. unsigned int elem_size;
  487. unsigned int alloc_align;
  488. void *list;
  489. };
  490. void *snd_array_new(struct snd_array *array);
  491. void snd_array_free(struct snd_array *array);
  492. static inline void snd_array_init(struct snd_array *array, unsigned int size,
  493. unsigned int align)
  494. {
  495. array->elem_size = size;
  496. array->alloc_align = align;
  497. }
  498. static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
  499. {
  500. return array->list + idx * array->elem_size;
  501. }
  502. static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
  503. {
  504. return (unsigned long)(ptr - array->list) / array->elem_size;
  505. }
  506. /*
  507. * Structures
  508. */
  509. struct hda_bus;
  510. struct hda_beep;
  511. struct hda_codec;
  512. struct hda_pcm;
  513. struct hda_pcm_stream;
  514. struct hda_bus_unsolicited;
  515. /* NID type */
  516. typedef u16 hda_nid_t;
  517. /* bus operators */
  518. struct hda_bus_ops {
  519. /* send a single command */
  520. int (*command)(struct hda_bus *bus, unsigned int cmd);
  521. /* get a response from the last command */
  522. unsigned int (*get_response)(struct hda_bus *bus, unsigned int addr);
  523. /* free the private data */
  524. void (*private_free)(struct hda_bus *);
  525. /* attach a PCM stream */
  526. int (*attach_pcm)(struct hda_bus *bus, struct hda_codec *codec,
  527. struct hda_pcm *pcm);
  528. /* reset bus for retry verb */
  529. void (*bus_reset)(struct hda_bus *bus);
  530. #ifdef CONFIG_SND_HDA_POWER_SAVE
  531. /* notify power-up/down from codec to controller */
  532. void (*pm_notify)(struct hda_bus *bus);
  533. #endif
  534. };
  535. /* template to pass to the bus constructor */
  536. struct hda_bus_template {
  537. void *private_data;
  538. struct pci_dev *pci;
  539. const char *modelname;
  540. int *power_save;
  541. struct hda_bus_ops ops;
  542. };
  543. /*
  544. * codec bus
  545. *
  546. * each controller needs to creata a hda_bus to assign the accessor.
  547. * A hda_bus contains several codecs in the list codec_list.
  548. */
  549. struct hda_bus {
  550. struct snd_card *card;
  551. /* copied from template */
  552. void *private_data;
  553. struct pci_dev *pci;
  554. const char *modelname;
  555. int *power_save;
  556. struct hda_bus_ops ops;
  557. /* codec linked list */
  558. struct list_head codec_list;
  559. /* link caddr -> codec */
  560. struct hda_codec *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1];
  561. struct mutex cmd_mutex;
  562. /* unsolicited event queue */
  563. struct hda_bus_unsolicited *unsol;
  564. char workq_name[16];
  565. struct workqueue_struct *workq; /* common workqueue for codecs */
  566. /* assigned PCMs */
  567. DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
  568. /* misc op flags */
  569. unsigned int needs_damn_long_delay :1;
  570. unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */
  571. unsigned int sync_write:1; /* sync after verb write */
  572. /* status for codec/controller */
  573. unsigned int shutdown :1; /* being unloaded */
  574. unsigned int rirb_error:1; /* error in codec communication */
  575. unsigned int response_reset:1; /* controller was reset */
  576. unsigned int in_reset:1; /* during reset operation */
  577. unsigned int power_keep_link_on:1; /* don't power off HDA link */
  578. };
  579. /*
  580. * codec preset
  581. *
  582. * Known codecs have the patch to build and set up the controls/PCMs
  583. * better than the generic parser.
  584. */
  585. struct hda_codec_preset {
  586. unsigned int id;
  587. unsigned int mask;
  588. unsigned int subs;
  589. unsigned int subs_mask;
  590. unsigned int rev;
  591. hda_nid_t afg, mfg;
  592. const char *name;
  593. int (*patch)(struct hda_codec *codec);
  594. };
  595. struct hda_codec_preset_list {
  596. const struct hda_codec_preset *preset;
  597. struct module *owner;
  598. struct list_head list;
  599. };
  600. /* initial hook */
  601. int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset);
  602. int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset);
  603. /* ops set by the preset patch */
  604. struct hda_codec_ops {
  605. int (*build_controls)(struct hda_codec *codec);
  606. int (*build_pcms)(struct hda_codec *codec);
  607. int (*init)(struct hda_codec *codec);
  608. void (*free)(struct hda_codec *codec);
  609. void (*unsol_event)(struct hda_codec *codec, unsigned int res);
  610. #ifdef SND_HDA_NEEDS_RESUME
  611. int (*suspend)(struct hda_codec *codec, pm_message_t state);
  612. int (*resume)(struct hda_codec *codec);
  613. #endif
  614. #ifdef CONFIG_SND_HDA_POWER_SAVE
  615. int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
  616. #endif
  617. void (*reboot_notify)(struct hda_codec *codec);
  618. };
  619. /* record for amp information cache */
  620. struct hda_cache_head {
  621. u32 key; /* hash key */
  622. u16 val; /* assigned value */
  623. u16 next; /* next link; -1 = terminal */
  624. };
  625. struct hda_amp_info {
  626. struct hda_cache_head head;
  627. u32 amp_caps; /* amp capabilities */
  628. u16 vol[2]; /* current volume & mute */
  629. };
  630. struct hda_cache_rec {
  631. u16 hash[64]; /* hash table for index */
  632. struct snd_array buf; /* record entries */
  633. };
  634. /* PCM callbacks */
  635. struct hda_pcm_ops {
  636. int (*open)(struct hda_pcm_stream *info, struct hda_codec *codec,
  637. struct snd_pcm_substream *substream);
  638. int (*close)(struct hda_pcm_stream *info, struct hda_codec *codec,
  639. struct snd_pcm_substream *substream);
  640. int (*prepare)(struct hda_pcm_stream *info, struct hda_codec *codec,
  641. unsigned int stream_tag, unsigned int format,
  642. struct snd_pcm_substream *substream);
  643. int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
  644. struct snd_pcm_substream *substream);
  645. };
  646. /* PCM information for each substream */
  647. struct hda_pcm_stream {
  648. unsigned int substreams; /* number of substreams, 0 = not exist*/
  649. unsigned int channels_min; /* min. number of channels */
  650. unsigned int channels_max; /* max. number of channels */
  651. hda_nid_t nid; /* default NID to query rates/formats/bps, or set up */
  652. u32 rates; /* supported rates */
  653. u64 formats; /* supported formats (SNDRV_PCM_FMTBIT_) */
  654. unsigned int maxbps; /* supported max. bit per sample */
  655. struct hda_pcm_ops ops;
  656. };
  657. /* PCM types */
  658. enum {
  659. HDA_PCM_TYPE_AUDIO,
  660. HDA_PCM_TYPE_SPDIF,
  661. HDA_PCM_TYPE_HDMI,
  662. HDA_PCM_TYPE_MODEM,
  663. HDA_PCM_NTYPES
  664. };
  665. /* for PCM creation */
  666. struct hda_pcm {
  667. char *name;
  668. struct hda_pcm_stream stream[2];
  669. unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */
  670. int device; /* device number to assign */
  671. struct snd_pcm *pcm; /* assigned PCM instance */
  672. };
  673. /* codec information */
  674. struct hda_codec {
  675. struct hda_bus *bus;
  676. unsigned int addr; /* codec addr*/
  677. struct list_head list; /* list point */
  678. hda_nid_t afg; /* AFG node id */
  679. hda_nid_t mfg; /* MFG node id */
  680. /* ids */
  681. u32 function_id;
  682. u32 vendor_id;
  683. u32 subsystem_id;
  684. u32 revision_id;
  685. /* detected preset */
  686. const struct hda_codec_preset *preset;
  687. struct module *owner;
  688. const char *vendor_name; /* codec vendor name */
  689. const char *chip_name; /* codec chip name */
  690. const char *modelname; /* model name for preset */
  691. /* set by patch */
  692. struct hda_codec_ops patch_ops;
  693. /* PCM to create, set by patch_ops.build_pcms callback */
  694. unsigned int num_pcms;
  695. struct hda_pcm *pcm_info;
  696. /* codec specific info */
  697. void *spec;
  698. /* beep device */
  699. struct hda_beep *beep;
  700. unsigned int beep_mode;
  701. /* widget capabilities cache */
  702. unsigned int num_nodes;
  703. hda_nid_t start_nid;
  704. u32 *wcaps;
  705. struct snd_array mixers; /* list of assigned mixer elements */
  706. struct snd_array nids; /* list of mapped mixer elements */
  707. struct hda_cache_rec amp_cache; /* cache for amp access */
  708. struct hda_cache_rec cmd_cache; /* cache for other commands */
  709. struct mutex spdif_mutex;
  710. struct mutex control_mutex;
  711. unsigned int spdif_status; /* IEC958 status bits */
  712. unsigned short spdif_ctls; /* SPDIF control bits */
  713. unsigned int spdif_in_enable; /* SPDIF input enable? */
  714. hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
  715. struct snd_array init_pins; /* initial (BIOS) pin configurations */
  716. struct snd_array driver_pins; /* pin configs set by codec parser */
  717. #ifdef CONFIG_SND_HDA_HWDEP
  718. struct snd_hwdep *hwdep; /* assigned hwdep device */
  719. struct snd_array init_verbs; /* additional init verbs */
  720. struct snd_array hints; /* additional hints */
  721. struct snd_array user_pins; /* default pin configs to override */
  722. #endif
  723. /* misc flags */
  724. unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
  725. * status change
  726. * (e.g. Realtek codecs)
  727. */
  728. unsigned int pin_amp_workaround:1; /* pin out-amp takes index
  729. * (e.g. Conexant codecs)
  730. */
  731. unsigned int pins_shutup:1; /* pins are shut up */
  732. unsigned int no_trigger_sense:1; /* don't trigger at pin-sensing */
  733. #ifdef CONFIG_SND_HDA_POWER_SAVE
  734. unsigned int power_on :1; /* current (global) power-state */
  735. unsigned int power_transition :1; /* power-state in transition */
  736. int power_count; /* current (global) power refcount */
  737. struct delayed_work power_work; /* delayed task for powerdown */
  738. unsigned long power_on_acct;
  739. unsigned long power_off_acct;
  740. unsigned long power_jiffies;
  741. #endif
  742. /* codec-specific additional proc output */
  743. void (*proc_widget_hook)(struct snd_info_buffer *buffer,
  744. struct hda_codec *codec, hda_nid_t nid);
  745. };
  746. /* direction */
  747. enum {
  748. HDA_INPUT, HDA_OUTPUT
  749. };
  750. /*
  751. * constructors
  752. */
  753. int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
  754. struct hda_bus **busp);
  755. int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
  756. struct hda_codec **codecp);
  757. int snd_hda_codec_configure(struct hda_codec *codec);
  758. /*
  759. * low level functions
  760. */
  761. unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
  762. int direct,
  763. unsigned int verb, unsigned int parm);
  764. int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
  765. unsigned int verb, unsigned int parm);
  766. #define snd_hda_param_read(codec, nid, param) \
  767. snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param)
  768. int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
  769. hda_nid_t *start_id);
  770. int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
  771. hda_nid_t *conn_list, int max_conns);
  772. struct hda_verb {
  773. hda_nid_t nid;
  774. u32 verb;
  775. u32 param;
  776. };
  777. void snd_hda_sequence_write(struct hda_codec *codec,
  778. const struct hda_verb *seq);
  779. /* unsolicited event */
  780. int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex);
  781. /* cached write */
  782. #ifdef SND_HDA_NEEDS_RESUME
  783. int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
  784. int direct, unsigned int verb, unsigned int parm);
  785. void snd_hda_sequence_write_cache(struct hda_codec *codec,
  786. const struct hda_verb *seq);
  787. int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
  788. int direct, unsigned int verb, unsigned int parm);
  789. void snd_hda_codec_resume_cache(struct hda_codec *codec);
  790. #else
  791. #define snd_hda_codec_write_cache snd_hda_codec_write
  792. #define snd_hda_codec_update_cache snd_hda_codec_write
  793. #define snd_hda_sequence_write_cache snd_hda_sequence_write
  794. #endif
  795. /* the struct for codec->pin_configs */
  796. struct hda_pincfg {
  797. hda_nid_t nid;
  798. unsigned char ctrl; /* current pin control value */
  799. unsigned char pad; /* reserved */
  800. unsigned int cfg; /* default configuration */
  801. };
  802. unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid);
  803. int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid,
  804. unsigned int cfg);
  805. int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
  806. hda_nid_t nid, unsigned int cfg); /* for hwdep */
  807. void snd_hda_shutup_pins(struct hda_codec *codec);
  808. /*
  809. * Mixer
  810. */
  811. int snd_hda_build_controls(struct hda_bus *bus);
  812. int snd_hda_codec_build_controls(struct hda_codec *codec);
  813. /*
  814. * PCM
  815. */
  816. int snd_hda_build_pcms(struct hda_bus *bus);
  817. int snd_hda_codec_build_pcms(struct hda_codec *codec);
  818. void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
  819. u32 stream_tag,
  820. int channel_id, int format);
  821. void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid);
  822. unsigned int snd_hda_calc_stream_format(unsigned int rate,
  823. unsigned int channels,
  824. unsigned int format,
  825. unsigned int maxbps);
  826. int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
  827. unsigned int format);
  828. /*
  829. * Misc
  830. */
  831. void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
  832. void snd_hda_bus_reboot_notify(struct hda_bus *bus);
  833. /*
  834. * power management
  835. */
  836. #ifdef CONFIG_PM
  837. int snd_hda_suspend(struct hda_bus *bus);
  838. int snd_hda_resume(struct hda_bus *bus);
  839. #endif
  840. /*
  841. * get widget information
  842. */
  843. const char *snd_hda_get_jack_connectivity(u32 cfg);
  844. const char *snd_hda_get_jack_type(u32 cfg);
  845. const char *snd_hda_get_jack_location(u32 cfg);
  846. /*
  847. * power saving
  848. */
  849. #ifdef CONFIG_SND_HDA_POWER_SAVE
  850. void snd_hda_power_up(struct hda_codec *codec);
  851. void snd_hda_power_down(struct hda_codec *codec);
  852. #define snd_hda_codec_needs_resume(codec) codec->power_count
  853. void snd_hda_update_power_acct(struct hda_codec *codec);
  854. #else
  855. static inline void snd_hda_power_up(struct hda_codec *codec) {}
  856. static inline void snd_hda_power_down(struct hda_codec *codec) {}
  857. #define snd_hda_codec_needs_resume(codec) 1
  858. #endif
  859. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  860. /*
  861. * patch firmware
  862. */
  863. int snd_hda_load_patch(struct hda_bus *bus, const char *patch);
  864. #endif
  865. /*
  866. * Codec modularization
  867. */
  868. /* Export symbols only for communication with codec drivers;
  869. * When built in kernel, all HD-audio drivers are supposed to be statically
  870. * linked to the kernel. Thus, the symbols don't have to (or shouldn't) be
  871. * exported unless it's built as a module.
  872. */
  873. #ifdef MODULE
  874. #define EXPORT_SYMBOL_HDA(sym) EXPORT_SYMBOL_GPL(sym)
  875. #else
  876. #define EXPORT_SYMBOL_HDA(sym)
  877. #endif
  878. #endif /* __SOUND_HDA_CODEC_H */