hda_codec.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  5. *
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This driver is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/mutex.h>
  28. #include <sound/core.h>
  29. #include "hda_codec.h"
  30. #include <sound/asoundef.h>
  31. #include <sound/initval.h>
  32. #include "hda_local.h"
  33. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  34. MODULE_DESCRIPTION("Universal interface for High Definition Audio Codec");
  35. MODULE_LICENSE("GPL");
  36. /*
  37. * vendor / preset table
  38. */
  39. struct hda_vendor_id {
  40. unsigned int id;
  41. const char *name;
  42. };
  43. /* codec vendor labels */
  44. static struct hda_vendor_id hda_vendor_ids[] = {
  45. { 0x10ec, "Realtek" },
  46. { 0x11d4, "Analog Devices" },
  47. { 0x13f6, "C-Media" },
  48. { 0x434d, "C-Media" },
  49. { 0x8384, "SigmaTel" },
  50. {} /* terminator */
  51. };
  52. /* codec presets */
  53. #include "hda_patch.h"
  54. /**
  55. * snd_hda_codec_read - send a command and get the response
  56. * @codec: the HDA codec
  57. * @nid: NID to send the command
  58. * @direct: direct flag
  59. * @verb: the verb to send
  60. * @parm: the parameter for the verb
  61. *
  62. * Send a single command and read the corresponding response.
  63. *
  64. * Returns the obtained response value, or -1 for an error.
  65. */
  66. unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, int direct,
  67. unsigned int verb, unsigned int parm)
  68. {
  69. unsigned int res;
  70. mutex_lock(&codec->bus->cmd_mutex);
  71. if (! codec->bus->ops.command(codec, nid, direct, verb, parm))
  72. res = codec->bus->ops.get_response(codec);
  73. else
  74. res = (unsigned int)-1;
  75. mutex_unlock(&codec->bus->cmd_mutex);
  76. return res;
  77. }
  78. EXPORT_SYMBOL(snd_hda_codec_read);
  79. /**
  80. * snd_hda_codec_write - send a single command without waiting for response
  81. * @codec: the HDA codec
  82. * @nid: NID to send the command
  83. * @direct: direct flag
  84. * @verb: the verb to send
  85. * @parm: the parameter for the verb
  86. *
  87. * Send a single command without waiting for response.
  88. *
  89. * Returns 0 if successful, or a negative error code.
  90. */
  91. int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
  92. unsigned int verb, unsigned int parm)
  93. {
  94. int err;
  95. mutex_lock(&codec->bus->cmd_mutex);
  96. err = codec->bus->ops.command(codec, nid, direct, verb, parm);
  97. mutex_unlock(&codec->bus->cmd_mutex);
  98. return err;
  99. }
  100. EXPORT_SYMBOL(snd_hda_codec_write);
  101. /**
  102. * snd_hda_sequence_write - sequence writes
  103. * @codec: the HDA codec
  104. * @seq: VERB array to send
  105. *
  106. * Send the commands sequentially from the given array.
  107. * The array must be terminated with NID=0.
  108. */
  109. void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
  110. {
  111. for (; seq->nid; seq++)
  112. snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
  113. }
  114. EXPORT_SYMBOL(snd_hda_sequence_write);
  115. /**
  116. * snd_hda_get_sub_nodes - get the range of sub nodes
  117. * @codec: the HDA codec
  118. * @nid: NID to parse
  119. * @start_id: the pointer to store the start NID
  120. *
  121. * Parse the NID and store the start NID of its sub-nodes.
  122. * Returns the number of sub-nodes.
  123. */
  124. int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, hda_nid_t *start_id)
  125. {
  126. unsigned int parm;
  127. parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
  128. *start_id = (parm >> 16) & 0x7fff;
  129. return (int)(parm & 0x7fff);
  130. }
  131. EXPORT_SYMBOL(snd_hda_get_sub_nodes);
  132. /**
  133. * snd_hda_get_connections - get connection list
  134. * @codec: the HDA codec
  135. * @nid: NID to parse
  136. * @conn_list: connection list array
  137. * @max_conns: max. number of connections to store
  138. *
  139. * Parses the connection list of the given widget and stores the list
  140. * of NIDs.
  141. *
  142. * Returns the number of connections, or a negative error code.
  143. */
  144. int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
  145. hda_nid_t *conn_list, int max_conns)
  146. {
  147. unsigned int parm;
  148. int i, conn_len, conns;
  149. unsigned int shift, num_elems, mask;
  150. hda_nid_t prev_nid;
  151. snd_assert(conn_list && max_conns > 0, return -EINVAL);
  152. parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
  153. if (parm & AC_CLIST_LONG) {
  154. /* long form */
  155. shift = 16;
  156. num_elems = 2;
  157. } else {
  158. /* short form */
  159. shift = 8;
  160. num_elems = 4;
  161. }
  162. conn_len = parm & AC_CLIST_LENGTH;
  163. mask = (1 << (shift-1)) - 1;
  164. if (! conn_len)
  165. return 0; /* no connection */
  166. if (conn_len == 1) {
  167. /* single connection */
  168. parm = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_LIST, 0);
  169. conn_list[0] = parm & mask;
  170. return 1;
  171. }
  172. /* multi connection */
  173. conns = 0;
  174. prev_nid = 0;
  175. for (i = 0; i < conn_len; i++) {
  176. int range_val;
  177. hda_nid_t val, n;
  178. if (i % num_elems == 0)
  179. parm = snd_hda_codec_read(codec, nid, 0,
  180. AC_VERB_GET_CONNECT_LIST, i);
  181. range_val = !! (parm & (1 << (shift-1))); /* ranges */
  182. val = parm & mask;
  183. parm >>= shift;
  184. if (range_val) {
  185. /* ranges between the previous and this one */
  186. if (! prev_nid || prev_nid >= val) {
  187. snd_printk(KERN_WARNING "hda_codec: invalid dep_range_val %x:%x\n", prev_nid, val);
  188. continue;
  189. }
  190. for (n = prev_nid + 1; n <= val; n++) {
  191. if (conns >= max_conns) {
  192. snd_printk(KERN_ERR "Too many connections\n");
  193. return -EINVAL;
  194. }
  195. conn_list[conns++] = n;
  196. }
  197. } else {
  198. if (conns >= max_conns) {
  199. snd_printk(KERN_ERR "Too many connections\n");
  200. return -EINVAL;
  201. }
  202. conn_list[conns++] = val;
  203. }
  204. prev_nid = val;
  205. }
  206. return conns;
  207. }
  208. /**
  209. * snd_hda_queue_unsol_event - add an unsolicited event to queue
  210. * @bus: the BUS
  211. * @res: unsolicited event (lower 32bit of RIRB entry)
  212. * @res_ex: codec addr and flags (upper 32bit or RIRB entry)
  213. *
  214. * Adds the given event to the queue. The events are processed in
  215. * the workqueue asynchronously. Call this function in the interrupt
  216. * hanlder when RIRB receives an unsolicited event.
  217. *
  218. * Returns 0 if successful, or a negative error code.
  219. */
  220. int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
  221. {
  222. struct hda_bus_unsolicited *unsol;
  223. unsigned int wp;
  224. if ((unsol = bus->unsol) == NULL)
  225. return 0;
  226. wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
  227. unsol->wp = wp;
  228. wp <<= 1;
  229. unsol->queue[wp] = res;
  230. unsol->queue[wp + 1] = res_ex;
  231. queue_work(unsol->workq, &unsol->work);
  232. return 0;
  233. }
  234. EXPORT_SYMBOL(snd_hda_queue_unsol_event);
  235. /*
  236. * process queueud unsolicited events
  237. */
  238. static void process_unsol_events(void *data)
  239. {
  240. struct hda_bus *bus = data;
  241. struct hda_bus_unsolicited *unsol = bus->unsol;
  242. struct hda_codec *codec;
  243. unsigned int rp, caddr, res;
  244. while (unsol->rp != unsol->wp) {
  245. rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE;
  246. unsol->rp = rp;
  247. rp <<= 1;
  248. res = unsol->queue[rp];
  249. caddr = unsol->queue[rp + 1];
  250. if (! (caddr & (1 << 4))) /* no unsolicited event? */
  251. continue;
  252. codec = bus->caddr_tbl[caddr & 0x0f];
  253. if (codec && codec->patch_ops.unsol_event)
  254. codec->patch_ops.unsol_event(codec, res);
  255. }
  256. }
  257. /*
  258. * initialize unsolicited queue
  259. */
  260. static int init_unsol_queue(struct hda_bus *bus)
  261. {
  262. struct hda_bus_unsolicited *unsol;
  263. if (bus->unsol) /* already initialized */
  264. return 0;
  265. unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
  266. if (! unsol) {
  267. snd_printk(KERN_ERR "hda_codec: can't allocate unsolicited queue\n");
  268. return -ENOMEM;
  269. }
  270. unsol->workq = create_singlethread_workqueue("hda_codec");
  271. if (! unsol->workq) {
  272. snd_printk(KERN_ERR "hda_codec: can't create workqueue\n");
  273. kfree(unsol);
  274. return -ENOMEM;
  275. }
  276. INIT_WORK(&unsol->work, process_unsol_events, bus);
  277. bus->unsol = unsol;
  278. return 0;
  279. }
  280. /*
  281. * destructor
  282. */
  283. static void snd_hda_codec_free(struct hda_codec *codec);
  284. static int snd_hda_bus_free(struct hda_bus *bus)
  285. {
  286. struct list_head *p, *n;
  287. if (! bus)
  288. return 0;
  289. if (bus->unsol) {
  290. destroy_workqueue(bus->unsol->workq);
  291. kfree(bus->unsol);
  292. }
  293. list_for_each_safe(p, n, &bus->codec_list) {
  294. struct hda_codec *codec = list_entry(p, struct hda_codec, list);
  295. snd_hda_codec_free(codec);
  296. }
  297. if (bus->ops.private_free)
  298. bus->ops.private_free(bus);
  299. kfree(bus);
  300. return 0;
  301. }
  302. static int snd_hda_bus_dev_free(struct snd_device *device)
  303. {
  304. struct hda_bus *bus = device->device_data;
  305. return snd_hda_bus_free(bus);
  306. }
  307. /**
  308. * snd_hda_bus_new - create a HDA bus
  309. * @card: the card entry
  310. * @temp: the template for hda_bus information
  311. * @busp: the pointer to store the created bus instance
  312. *
  313. * Returns 0 if successful, or a negative error code.
  314. */
  315. int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
  316. struct hda_bus **busp)
  317. {
  318. struct hda_bus *bus;
  319. int err;
  320. static struct snd_device_ops dev_ops = {
  321. .dev_free = snd_hda_bus_dev_free,
  322. };
  323. snd_assert(temp, return -EINVAL);
  324. snd_assert(temp->ops.command && temp->ops.get_response, return -EINVAL);
  325. if (busp)
  326. *busp = NULL;
  327. bus = kzalloc(sizeof(*bus), GFP_KERNEL);
  328. if (bus == NULL) {
  329. snd_printk(KERN_ERR "can't allocate struct hda_bus\n");
  330. return -ENOMEM;
  331. }
  332. bus->card = card;
  333. bus->private_data = temp->private_data;
  334. bus->pci = temp->pci;
  335. bus->modelname = temp->modelname;
  336. bus->ops = temp->ops;
  337. mutex_init(&bus->cmd_mutex);
  338. INIT_LIST_HEAD(&bus->codec_list);
  339. if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops)) < 0) {
  340. snd_hda_bus_free(bus);
  341. return err;
  342. }
  343. if (busp)
  344. *busp = bus;
  345. return 0;
  346. }
  347. EXPORT_SYMBOL(snd_hda_bus_new);
  348. /*
  349. * find a matching codec preset
  350. */
  351. static const struct hda_codec_preset *find_codec_preset(struct hda_codec *codec)
  352. {
  353. const struct hda_codec_preset **tbl, *preset;
  354. for (tbl = hda_preset_tables; *tbl; tbl++) {
  355. for (preset = *tbl; preset->id; preset++) {
  356. u32 mask = preset->mask;
  357. if (! mask)
  358. mask = ~0;
  359. if (preset->id == (codec->vendor_id & mask) &&
  360. (! preset->rev ||
  361. preset->rev == codec->revision_id))
  362. return preset;
  363. }
  364. }
  365. return NULL;
  366. }
  367. /*
  368. * snd_hda_get_codec_name - store the codec name
  369. */
  370. void snd_hda_get_codec_name(struct hda_codec *codec,
  371. char *name, int namelen)
  372. {
  373. const struct hda_vendor_id *c;
  374. const char *vendor = NULL;
  375. u16 vendor_id = codec->vendor_id >> 16;
  376. char tmp[16];
  377. for (c = hda_vendor_ids; c->id; c++) {
  378. if (c->id == vendor_id) {
  379. vendor = c->name;
  380. break;
  381. }
  382. }
  383. if (! vendor) {
  384. sprintf(tmp, "Generic %04x", vendor_id);
  385. vendor = tmp;
  386. }
  387. if (codec->preset && codec->preset->name)
  388. snprintf(name, namelen, "%s %s", vendor, codec->preset->name);
  389. else
  390. snprintf(name, namelen, "%s ID %x", vendor, codec->vendor_id & 0xffff);
  391. }
  392. /*
  393. * look for an AFG and MFG nodes
  394. */
  395. static void setup_fg_nodes(struct hda_codec *codec)
  396. {
  397. int i, total_nodes;
  398. hda_nid_t nid;
  399. total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
  400. for (i = 0; i < total_nodes; i++, nid++) {
  401. switch((snd_hda_param_read(codec, nid, AC_PAR_FUNCTION_TYPE) & 0xff)) {
  402. case AC_GRP_AUDIO_FUNCTION:
  403. codec->afg = nid;
  404. break;
  405. case AC_GRP_MODEM_FUNCTION:
  406. codec->mfg = nid;
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. }
  413. /*
  414. * read widget caps for each widget and store in cache
  415. */
  416. static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
  417. {
  418. int i;
  419. hda_nid_t nid;
  420. codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node,
  421. &codec->start_nid);
  422. codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL);
  423. if (! codec->wcaps)
  424. return -ENOMEM;
  425. nid = codec->start_nid;
  426. for (i = 0; i < codec->num_nodes; i++, nid++)
  427. codec->wcaps[i] = snd_hda_param_read(codec, nid,
  428. AC_PAR_AUDIO_WIDGET_CAP);
  429. return 0;
  430. }
  431. /*
  432. * codec destructor
  433. */
  434. static void snd_hda_codec_free(struct hda_codec *codec)
  435. {
  436. if (! codec)
  437. return;
  438. list_del(&codec->list);
  439. codec->bus->caddr_tbl[codec->addr] = NULL;
  440. if (codec->patch_ops.free)
  441. codec->patch_ops.free(codec);
  442. kfree(codec->amp_info);
  443. kfree(codec->wcaps);
  444. kfree(codec);
  445. }
  446. static void init_amp_hash(struct hda_codec *codec);
  447. /**
  448. * snd_hda_codec_new - create a HDA codec
  449. * @bus: the bus to assign
  450. * @codec_addr: the codec address
  451. * @codecp: the pointer to store the generated codec
  452. *
  453. * Returns 0 if successful, or a negative error code.
  454. */
  455. int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
  456. struct hda_codec **codecp)
  457. {
  458. struct hda_codec *codec;
  459. char component[13];
  460. int err;
  461. snd_assert(bus, return -EINVAL);
  462. snd_assert(codec_addr <= HDA_MAX_CODEC_ADDRESS, return -EINVAL);
  463. if (bus->caddr_tbl[codec_addr]) {
  464. snd_printk(KERN_ERR "hda_codec: address 0x%x is already occupied\n", codec_addr);
  465. return -EBUSY;
  466. }
  467. codec = kzalloc(sizeof(*codec), GFP_KERNEL);
  468. if (codec == NULL) {
  469. snd_printk(KERN_ERR "can't allocate struct hda_codec\n");
  470. return -ENOMEM;
  471. }
  472. codec->bus = bus;
  473. codec->addr = codec_addr;
  474. mutex_init(&codec->spdif_mutex);
  475. init_amp_hash(codec);
  476. list_add_tail(&codec->list, &bus->codec_list);
  477. bus->caddr_tbl[codec_addr] = codec;
  478. codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_VENDOR_ID);
  479. if (codec->vendor_id == -1)
  480. /* read again, hopefully the access method was corrected
  481. * in the last read...
  482. */
  483. codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
  484. AC_PAR_VENDOR_ID);
  485. codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_SUBSYSTEM_ID);
  486. codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_REV_ID);
  487. setup_fg_nodes(codec);
  488. if (! codec->afg && ! codec->mfg) {
  489. snd_printdd("hda_codec: no AFG or MFG node found\n");
  490. snd_hda_codec_free(codec);
  491. return -ENODEV;
  492. }
  493. if (read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg) < 0) {
  494. snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
  495. snd_hda_codec_free(codec);
  496. return -ENOMEM;
  497. }
  498. if (! codec->subsystem_id) {
  499. hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
  500. codec->subsystem_id = snd_hda_codec_read(codec, nid, 0,
  501. AC_VERB_GET_SUBSYSTEM_ID,
  502. 0);
  503. }
  504. codec->preset = find_codec_preset(codec);
  505. if (! *bus->card->mixername)
  506. snd_hda_get_codec_name(codec, bus->card->mixername,
  507. sizeof(bus->card->mixername));
  508. if (codec->preset && codec->preset->patch)
  509. err = codec->preset->patch(codec);
  510. else
  511. err = snd_hda_parse_generic_codec(codec);
  512. if (err < 0) {
  513. snd_hda_codec_free(codec);
  514. return err;
  515. }
  516. if (codec->patch_ops.unsol_event)
  517. init_unsol_queue(bus);
  518. snd_hda_codec_proc_new(codec);
  519. sprintf(component, "HDA:%08x", codec->vendor_id);
  520. snd_component_add(codec->bus->card, component);
  521. if (codecp)
  522. *codecp = codec;
  523. return 0;
  524. }
  525. EXPORT_SYMBOL(snd_hda_codec_new);
  526. /**
  527. * snd_hda_codec_setup_stream - set up the codec for streaming
  528. * @codec: the CODEC to set up
  529. * @nid: the NID to set up
  530. * @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
  531. * @channel_id: channel id to pass, zero based.
  532. * @format: stream format.
  533. */
  534. void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, u32 stream_tag,
  535. int channel_id, int format)
  536. {
  537. if (! nid)
  538. return;
  539. snd_printdd("hda_codec_setup_stream: NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
  540. nid, stream_tag, channel_id, format);
  541. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID,
  542. (stream_tag << 4) | channel_id);
  543. msleep(1);
  544. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
  545. }
  546. EXPORT_SYMBOL(snd_hda_codec_setup_stream);
  547. /*
  548. * amp access functions
  549. */
  550. /* FIXME: more better hash key? */
  551. #define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
  552. #define INFO_AMP_CAPS (1<<0)
  553. #define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
  554. /* initialize the hash table */
  555. static void init_amp_hash(struct hda_codec *codec)
  556. {
  557. memset(codec->amp_hash, 0xff, sizeof(codec->amp_hash));
  558. codec->num_amp_entries = 0;
  559. codec->amp_info_size = 0;
  560. codec->amp_info = NULL;
  561. }
  562. /* query the hash. allocate an entry if not found. */
  563. static struct hda_amp_info *get_alloc_amp_hash(struct hda_codec *codec, u32 key)
  564. {
  565. u16 idx = key % (u16)ARRAY_SIZE(codec->amp_hash);
  566. u16 cur = codec->amp_hash[idx];
  567. struct hda_amp_info *info;
  568. while (cur != 0xffff) {
  569. info = &codec->amp_info[cur];
  570. if (info->key == key)
  571. return info;
  572. cur = info->next;
  573. }
  574. /* add a new hash entry */
  575. if (codec->num_amp_entries >= codec->amp_info_size) {
  576. /* reallocate the array */
  577. int new_size = codec->amp_info_size + 64;
  578. struct hda_amp_info *new_info = kcalloc(new_size, sizeof(struct hda_amp_info),
  579. GFP_KERNEL);
  580. if (! new_info) {
  581. snd_printk(KERN_ERR "hda_codec: can't malloc amp_info\n");
  582. return NULL;
  583. }
  584. if (codec->amp_info) {
  585. memcpy(new_info, codec->amp_info,
  586. codec->amp_info_size * sizeof(struct hda_amp_info));
  587. kfree(codec->amp_info);
  588. }
  589. codec->amp_info_size = new_size;
  590. codec->amp_info = new_info;
  591. }
  592. cur = codec->num_amp_entries++;
  593. info = &codec->amp_info[cur];
  594. info->key = key;
  595. info->status = 0; /* not initialized yet */
  596. info->next = codec->amp_hash[idx];
  597. codec->amp_hash[idx] = cur;
  598. return info;
  599. }
  600. /*
  601. * query AMP capabilities for the given widget and direction
  602. */
  603. static u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
  604. {
  605. struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0));
  606. if (! info)
  607. return 0;
  608. if (! (info->status & INFO_AMP_CAPS)) {
  609. if (! (get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
  610. nid = codec->afg;
  611. info->amp_caps = snd_hda_param_read(codec, nid, direction == HDA_OUTPUT ?
  612. AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
  613. info->status |= INFO_AMP_CAPS;
  614. }
  615. return info->amp_caps;
  616. }
  617. /*
  618. * read the current volume to info
  619. * if the cache exists, read the cache value.
  620. */
  621. static unsigned int get_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
  622. hda_nid_t nid, int ch, int direction, int index)
  623. {
  624. u32 val, parm;
  625. if (info->status & INFO_AMP_VOL(ch))
  626. return info->vol[ch];
  627. parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
  628. parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
  629. parm |= index;
  630. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_AMP_GAIN_MUTE, parm);
  631. info->vol[ch] = val & 0xff;
  632. info->status |= INFO_AMP_VOL(ch);
  633. return info->vol[ch];
  634. }
  635. /*
  636. * write the current volume in info to the h/w and update the cache
  637. */
  638. static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
  639. hda_nid_t nid, int ch, int direction, int index, int val)
  640. {
  641. u32 parm;
  642. parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
  643. parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
  644. parm |= index << AC_AMP_SET_INDEX_SHIFT;
  645. parm |= val;
  646. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
  647. info->vol[ch] = val;
  648. }
  649. /*
  650. * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
  651. */
  652. int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
  653. int direction, int index)
  654. {
  655. struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
  656. if (! info)
  657. return 0;
  658. return get_vol_mute(codec, info, nid, ch, direction, index);
  659. }
  660. /*
  661. * update the AMP value, mask = bit mask to set, val = the value
  662. */
  663. int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
  664. int direction, int idx, int mask, int val)
  665. {
  666. struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
  667. if (! info)
  668. return 0;
  669. val &= mask;
  670. val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
  671. if (info->vol[ch] == val && ! codec->in_resume)
  672. return 0;
  673. put_vol_mute(codec, info, nid, ch, direction, idx, val);
  674. return 1;
  675. }
  676. /*
  677. * AMP control callbacks
  678. */
  679. /* retrieve parameters from private_value */
  680. #define get_amp_nid(kc) ((kc)->private_value & 0xffff)
  681. #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
  682. #define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
  683. #define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
  684. /* volume */
  685. int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  686. {
  687. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  688. u16 nid = get_amp_nid(kcontrol);
  689. u8 chs = get_amp_channels(kcontrol);
  690. int dir = get_amp_direction(kcontrol);
  691. u32 caps;
  692. caps = query_amp_caps(codec, nid, dir);
  693. caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; /* num steps */
  694. if (! caps) {
  695. printk(KERN_WARNING "hda_codec: num_steps = 0 for NID=0x%x\n", nid);
  696. return -EINVAL;
  697. }
  698. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  699. uinfo->count = chs == 3 ? 2 : 1;
  700. uinfo->value.integer.min = 0;
  701. uinfo->value.integer.max = caps;
  702. return 0;
  703. }
  704. int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  705. {
  706. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  707. hda_nid_t nid = get_amp_nid(kcontrol);
  708. int chs = get_amp_channels(kcontrol);
  709. int dir = get_amp_direction(kcontrol);
  710. int idx = get_amp_index(kcontrol);
  711. long *valp = ucontrol->value.integer.value;
  712. if (chs & 1)
  713. *valp++ = snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & 0x7f;
  714. if (chs & 2)
  715. *valp = snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & 0x7f;
  716. return 0;
  717. }
  718. int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  719. {
  720. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  721. hda_nid_t nid = get_amp_nid(kcontrol);
  722. int chs = get_amp_channels(kcontrol);
  723. int dir = get_amp_direction(kcontrol);
  724. int idx = get_amp_index(kcontrol);
  725. long *valp = ucontrol->value.integer.value;
  726. int change = 0;
  727. if (chs & 1) {
  728. change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
  729. 0x7f, *valp);
  730. valp++;
  731. }
  732. if (chs & 2)
  733. change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
  734. 0x7f, *valp);
  735. return change;
  736. }
  737. /* switch */
  738. int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  739. {
  740. int chs = get_amp_channels(kcontrol);
  741. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  742. uinfo->count = chs == 3 ? 2 : 1;
  743. uinfo->value.integer.min = 0;
  744. uinfo->value.integer.max = 1;
  745. return 0;
  746. }
  747. int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  748. {
  749. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  750. hda_nid_t nid = get_amp_nid(kcontrol);
  751. int chs = get_amp_channels(kcontrol);
  752. int dir = get_amp_direction(kcontrol);
  753. int idx = get_amp_index(kcontrol);
  754. long *valp = ucontrol->value.integer.value;
  755. if (chs & 1)
  756. *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & 0x80) ? 0 : 1;
  757. if (chs & 2)
  758. *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & 0x80) ? 0 : 1;
  759. return 0;
  760. }
  761. int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  762. {
  763. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  764. hda_nid_t nid = get_amp_nid(kcontrol);
  765. int chs = get_amp_channels(kcontrol);
  766. int dir = get_amp_direction(kcontrol);
  767. int idx = get_amp_index(kcontrol);
  768. long *valp = ucontrol->value.integer.value;
  769. int change = 0;
  770. if (chs & 1) {
  771. change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
  772. 0x80, *valp ? 0 : 0x80);
  773. valp++;
  774. }
  775. if (chs & 2)
  776. change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
  777. 0x80, *valp ? 0 : 0x80);
  778. return change;
  779. }
  780. /*
  781. * bound volume controls
  782. *
  783. * bind multiple volumes (# indices, from 0)
  784. */
  785. #define AMP_VAL_IDX_SHIFT 19
  786. #define AMP_VAL_IDX_MASK (0x0f<<19)
  787. int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  788. {
  789. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  790. unsigned long pval;
  791. int err;
  792. mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
  793. pval = kcontrol->private_value;
  794. kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
  795. err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
  796. kcontrol->private_value = pval;
  797. mutex_unlock(&codec->spdif_mutex);
  798. return err;
  799. }
  800. int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  801. {
  802. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  803. unsigned long pval;
  804. int i, indices, err = 0, change = 0;
  805. mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
  806. pval = kcontrol->private_value;
  807. indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
  808. for (i = 0; i < indices; i++) {
  809. kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | (i << AMP_VAL_IDX_SHIFT);
  810. err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  811. if (err < 0)
  812. break;
  813. change |= err;
  814. }
  815. kcontrol->private_value = pval;
  816. mutex_unlock(&codec->spdif_mutex);
  817. return err < 0 ? err : change;
  818. }
  819. /*
  820. * SPDIF out controls
  821. */
  822. static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  823. {
  824. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  825. uinfo->count = 1;
  826. return 0;
  827. }
  828. static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  829. {
  830. ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
  831. IEC958_AES0_NONAUDIO |
  832. IEC958_AES0_CON_EMPHASIS_5015 |
  833. IEC958_AES0_CON_NOT_COPYRIGHT;
  834. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
  835. IEC958_AES1_CON_ORIGINAL;
  836. return 0;
  837. }
  838. static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  839. {
  840. ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
  841. IEC958_AES0_NONAUDIO |
  842. IEC958_AES0_PRO_EMPHASIS_5015;
  843. return 0;
  844. }
  845. static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  846. {
  847. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  848. ucontrol->value.iec958.status[0] = codec->spdif_status & 0xff;
  849. ucontrol->value.iec958.status[1] = (codec->spdif_status >> 8) & 0xff;
  850. ucontrol->value.iec958.status[2] = (codec->spdif_status >> 16) & 0xff;
  851. ucontrol->value.iec958.status[3] = (codec->spdif_status >> 24) & 0xff;
  852. return 0;
  853. }
  854. /* convert from SPDIF status bits to HDA SPDIF bits
  855. * bit 0 (DigEn) is always set zero (to be filled later)
  856. */
  857. static unsigned short convert_from_spdif_status(unsigned int sbits)
  858. {
  859. unsigned short val = 0;
  860. if (sbits & IEC958_AES0_PROFESSIONAL)
  861. val |= 1 << 6;
  862. if (sbits & IEC958_AES0_NONAUDIO)
  863. val |= 1 << 5;
  864. if (sbits & IEC958_AES0_PROFESSIONAL) {
  865. if ((sbits & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
  866. val |= 1 << 3;
  867. } else {
  868. if ((sbits & IEC958_AES0_CON_EMPHASIS) == IEC958_AES0_CON_EMPHASIS_5015)
  869. val |= 1 << 3;
  870. if (! (sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
  871. val |= 1 << 4;
  872. if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
  873. val |= 1 << 7;
  874. val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
  875. }
  876. return val;
  877. }
  878. /* convert to SPDIF status bits from HDA SPDIF bits
  879. */
  880. static unsigned int convert_to_spdif_status(unsigned short val)
  881. {
  882. unsigned int sbits = 0;
  883. if (val & (1 << 5))
  884. sbits |= IEC958_AES0_NONAUDIO;
  885. if (val & (1 << 6))
  886. sbits |= IEC958_AES0_PROFESSIONAL;
  887. if (sbits & IEC958_AES0_PROFESSIONAL) {
  888. if (sbits & (1 << 3))
  889. sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
  890. } else {
  891. if (val & (1 << 3))
  892. sbits |= IEC958_AES0_CON_EMPHASIS_5015;
  893. if (! (val & (1 << 4)))
  894. sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
  895. if (val & (1 << 7))
  896. sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
  897. sbits |= val & (0x7f << 8);
  898. }
  899. return sbits;
  900. }
  901. static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  902. {
  903. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  904. hda_nid_t nid = kcontrol->private_value;
  905. unsigned short val;
  906. int change;
  907. mutex_lock(&codec->spdif_mutex);
  908. codec->spdif_status = ucontrol->value.iec958.status[0] |
  909. ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
  910. ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
  911. ((unsigned int)ucontrol->value.iec958.status[3] << 24);
  912. val = convert_from_spdif_status(codec->spdif_status);
  913. val |= codec->spdif_ctls & 1;
  914. change = codec->spdif_ctls != val;
  915. codec->spdif_ctls = val;
  916. if (change || codec->in_resume) {
  917. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, val & 0xff);
  918. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_2, val >> 8);
  919. }
  920. mutex_unlock(&codec->spdif_mutex);
  921. return change;
  922. }
  923. static int snd_hda_spdif_out_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  924. {
  925. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  926. uinfo->count = 1;
  927. uinfo->value.integer.min = 0;
  928. uinfo->value.integer.max = 1;
  929. return 0;
  930. }
  931. static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  932. {
  933. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  934. ucontrol->value.integer.value[0] = codec->spdif_ctls & 1;
  935. return 0;
  936. }
  937. static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  938. {
  939. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  940. hda_nid_t nid = kcontrol->private_value;
  941. unsigned short val;
  942. int change;
  943. mutex_lock(&codec->spdif_mutex);
  944. val = codec->spdif_ctls & ~1;
  945. if (ucontrol->value.integer.value[0])
  946. val |= 1;
  947. change = codec->spdif_ctls != val;
  948. if (change || codec->in_resume) {
  949. codec->spdif_ctls = val;
  950. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, val & 0xff);
  951. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  952. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT |
  953. AC_AMP_SET_OUTPUT | ((val & 1) ? 0 : 0x80));
  954. }
  955. mutex_unlock(&codec->spdif_mutex);
  956. return change;
  957. }
  958. static struct snd_kcontrol_new dig_mixes[] = {
  959. {
  960. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  961. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  962. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  963. .info = snd_hda_spdif_mask_info,
  964. .get = snd_hda_spdif_cmask_get,
  965. },
  966. {
  967. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  968. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  969. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  970. .info = snd_hda_spdif_mask_info,
  971. .get = snd_hda_spdif_pmask_get,
  972. },
  973. {
  974. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  975. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  976. .info = snd_hda_spdif_mask_info,
  977. .get = snd_hda_spdif_default_get,
  978. .put = snd_hda_spdif_default_put,
  979. },
  980. {
  981. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  982. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
  983. .info = snd_hda_spdif_out_switch_info,
  984. .get = snd_hda_spdif_out_switch_get,
  985. .put = snd_hda_spdif_out_switch_put,
  986. },
  987. { } /* end */
  988. };
  989. /**
  990. * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
  991. * @codec: the HDA codec
  992. * @nid: audio out widget NID
  993. *
  994. * Creates controls related with the SPDIF output.
  995. * Called from each patch supporting the SPDIF out.
  996. *
  997. * Returns 0 if successful, or a negative error code.
  998. */
  999. int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
  1000. {
  1001. int err;
  1002. struct snd_kcontrol *kctl;
  1003. struct snd_kcontrol_new *dig_mix;
  1004. for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
  1005. kctl = snd_ctl_new1(dig_mix, codec);
  1006. kctl->private_value = nid;
  1007. if ((err = snd_ctl_add(codec->bus->card, kctl)) < 0)
  1008. return err;
  1009. }
  1010. codec->spdif_ctls = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0);
  1011. codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
  1012. return 0;
  1013. }
  1014. /*
  1015. * SPDIF input
  1016. */
  1017. #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info
  1018. static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1019. {
  1020. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1021. ucontrol->value.integer.value[0] = codec->spdif_in_enable;
  1022. return 0;
  1023. }
  1024. static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1025. {
  1026. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1027. hda_nid_t nid = kcontrol->private_value;
  1028. unsigned int val = !!ucontrol->value.integer.value[0];
  1029. int change;
  1030. mutex_lock(&codec->spdif_mutex);
  1031. change = codec->spdif_in_enable != val;
  1032. if (change || codec->in_resume) {
  1033. codec->spdif_in_enable = val;
  1034. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, val);
  1035. }
  1036. mutex_unlock(&codec->spdif_mutex);
  1037. return change;
  1038. }
  1039. static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1040. {
  1041. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1042. hda_nid_t nid = kcontrol->private_value;
  1043. unsigned short val;
  1044. unsigned int sbits;
  1045. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0);
  1046. sbits = convert_to_spdif_status(val);
  1047. ucontrol->value.iec958.status[0] = sbits;
  1048. ucontrol->value.iec958.status[1] = sbits >> 8;
  1049. ucontrol->value.iec958.status[2] = sbits >> 16;
  1050. ucontrol->value.iec958.status[3] = sbits >> 24;
  1051. return 0;
  1052. }
  1053. static struct snd_kcontrol_new dig_in_ctls[] = {
  1054. {
  1055. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1056. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH),
  1057. .info = snd_hda_spdif_in_switch_info,
  1058. .get = snd_hda_spdif_in_switch_get,
  1059. .put = snd_hda_spdif_in_switch_put,
  1060. },
  1061. {
  1062. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1063. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1064. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
  1065. .info = snd_hda_spdif_mask_info,
  1066. .get = snd_hda_spdif_in_status_get,
  1067. },
  1068. { } /* end */
  1069. };
  1070. /**
  1071. * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
  1072. * @codec: the HDA codec
  1073. * @nid: audio in widget NID
  1074. *
  1075. * Creates controls related with the SPDIF input.
  1076. * Called from each patch supporting the SPDIF in.
  1077. *
  1078. * Returns 0 if successful, or a negative error code.
  1079. */
  1080. int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
  1081. {
  1082. int err;
  1083. struct snd_kcontrol *kctl;
  1084. struct snd_kcontrol_new *dig_mix;
  1085. for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
  1086. kctl = snd_ctl_new1(dig_mix, codec);
  1087. kctl->private_value = nid;
  1088. if ((err = snd_ctl_add(codec->bus->card, kctl)) < 0)
  1089. return err;
  1090. }
  1091. codec->spdif_in_enable = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0) & 1;
  1092. return 0;
  1093. }
  1094. /*
  1095. * set power state of the codec
  1096. */
  1097. static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
  1098. unsigned int power_state)
  1099. {
  1100. hda_nid_t nid, nid_start;
  1101. int nodes;
  1102. snd_hda_codec_write(codec, fg, 0, AC_VERB_SET_POWER_STATE,
  1103. power_state);
  1104. nodes = snd_hda_get_sub_nodes(codec, fg, &nid_start);
  1105. for (nid = nid_start; nid < nodes + nid_start; nid++) {
  1106. if (get_wcaps(codec, nid) & AC_WCAP_POWER)
  1107. snd_hda_codec_write(codec, nid, 0,
  1108. AC_VERB_SET_POWER_STATE,
  1109. power_state);
  1110. }
  1111. if (power_state == AC_PWRST_D0)
  1112. msleep(10);
  1113. }
  1114. /**
  1115. * snd_hda_build_controls - build mixer controls
  1116. * @bus: the BUS
  1117. *
  1118. * Creates mixer controls for each codec included in the bus.
  1119. *
  1120. * Returns 0 if successful, otherwise a negative error code.
  1121. */
  1122. int snd_hda_build_controls(struct hda_bus *bus)
  1123. {
  1124. struct list_head *p;
  1125. /* build controls */
  1126. list_for_each(p, &bus->codec_list) {
  1127. struct hda_codec *codec = list_entry(p, struct hda_codec, list);
  1128. int err;
  1129. if (! codec->patch_ops.build_controls)
  1130. continue;
  1131. err = codec->patch_ops.build_controls(codec);
  1132. if (err < 0)
  1133. return err;
  1134. }
  1135. /* initialize */
  1136. list_for_each(p, &bus->codec_list) {
  1137. struct hda_codec *codec = list_entry(p, struct hda_codec, list);
  1138. int err;
  1139. hda_set_power_state(codec,
  1140. codec->afg ? codec->afg : codec->mfg,
  1141. AC_PWRST_D0);
  1142. if (! codec->patch_ops.init)
  1143. continue;
  1144. err = codec->patch_ops.init(codec);
  1145. if (err < 0)
  1146. return err;
  1147. }
  1148. return 0;
  1149. }
  1150. EXPORT_SYMBOL(snd_hda_build_controls);
  1151. /*
  1152. * stream formats
  1153. */
  1154. struct hda_rate_tbl {
  1155. unsigned int hz;
  1156. unsigned int alsa_bits;
  1157. unsigned int hda_fmt;
  1158. };
  1159. static struct hda_rate_tbl rate_bits[] = {
  1160. /* rate in Hz, ALSA rate bitmask, HDA format value */
  1161. /* autodetected value used in snd_hda_query_supported_pcm */
  1162. { 8000, SNDRV_PCM_RATE_8000, 0x0500 }, /* 1/6 x 48 */
  1163. { 11025, SNDRV_PCM_RATE_11025, 0x4300 }, /* 1/4 x 44 */
  1164. { 16000, SNDRV_PCM_RATE_16000, 0x0200 }, /* 1/3 x 48 */
  1165. { 22050, SNDRV_PCM_RATE_22050, 0x4100 }, /* 1/2 x 44 */
  1166. { 32000, SNDRV_PCM_RATE_32000, 0x0a00 }, /* 2/3 x 48 */
  1167. { 44100, SNDRV_PCM_RATE_44100, 0x4000 }, /* 44 */
  1168. { 48000, SNDRV_PCM_RATE_48000, 0x0000 }, /* 48 */
  1169. { 88200, SNDRV_PCM_RATE_88200, 0x4800 }, /* 2 x 44 */
  1170. { 96000, SNDRV_PCM_RATE_96000, 0x0800 }, /* 2 x 48 */
  1171. { 176400, SNDRV_PCM_RATE_176400, 0x5800 },/* 4 x 44 */
  1172. { 192000, SNDRV_PCM_RATE_192000, 0x1800 }, /* 4 x 48 */
  1173. /* not autodetected value */
  1174. { 9600, SNDRV_PCM_RATE_KNOT, 0x0400 }, /* 1/5 x 48 */
  1175. { 0 } /* terminator */
  1176. };
  1177. /**
  1178. * snd_hda_calc_stream_format - calculate format bitset
  1179. * @rate: the sample rate
  1180. * @channels: the number of channels
  1181. * @format: the PCM format (SNDRV_PCM_FORMAT_XXX)
  1182. * @maxbps: the max. bps
  1183. *
  1184. * Calculate the format bitset from the given rate, channels and th PCM format.
  1185. *
  1186. * Return zero if invalid.
  1187. */
  1188. unsigned int snd_hda_calc_stream_format(unsigned int rate,
  1189. unsigned int channels,
  1190. unsigned int format,
  1191. unsigned int maxbps)
  1192. {
  1193. int i;
  1194. unsigned int val = 0;
  1195. for (i = 0; rate_bits[i].hz; i++)
  1196. if (rate_bits[i].hz == rate) {
  1197. val = rate_bits[i].hda_fmt;
  1198. break;
  1199. }
  1200. if (! rate_bits[i].hz) {
  1201. snd_printdd("invalid rate %d\n", rate);
  1202. return 0;
  1203. }
  1204. if (channels == 0 || channels > 8) {
  1205. snd_printdd("invalid channels %d\n", channels);
  1206. return 0;
  1207. }
  1208. val |= channels - 1;
  1209. switch (snd_pcm_format_width(format)) {
  1210. case 8: val |= 0x00; break;
  1211. case 16: val |= 0x10; break;
  1212. case 20:
  1213. case 24:
  1214. case 32:
  1215. if (maxbps >= 32)
  1216. val |= 0x40;
  1217. else if (maxbps >= 24)
  1218. val |= 0x30;
  1219. else
  1220. val |= 0x20;
  1221. break;
  1222. default:
  1223. snd_printdd("invalid format width %d\n", snd_pcm_format_width(format));
  1224. return 0;
  1225. }
  1226. return val;
  1227. }
  1228. EXPORT_SYMBOL(snd_hda_calc_stream_format);
  1229. /**
  1230. * snd_hda_query_supported_pcm - query the supported PCM rates and formats
  1231. * @codec: the HDA codec
  1232. * @nid: NID to query
  1233. * @ratesp: the pointer to store the detected rate bitflags
  1234. * @formatsp: the pointer to store the detected formats
  1235. * @bpsp: the pointer to store the detected format widths
  1236. *
  1237. * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp
  1238. * or @bsps argument is ignored.
  1239. *
  1240. * Returns 0 if successful, otherwise a negative error code.
  1241. */
  1242. int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
  1243. u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
  1244. {
  1245. int i;
  1246. unsigned int val, streams;
  1247. val = 0;
  1248. if (nid != codec->afg &&
  1249. (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) {
  1250. val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
  1251. if (val == -1)
  1252. return -EIO;
  1253. }
  1254. if (! val)
  1255. val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
  1256. if (ratesp) {
  1257. u32 rates = 0;
  1258. for (i = 0; rate_bits[i].hz; i++) {
  1259. if (val & (1 << i))
  1260. rates |= rate_bits[i].alsa_bits;
  1261. }
  1262. *ratesp = rates;
  1263. }
  1264. if (formatsp || bpsp) {
  1265. u64 formats = 0;
  1266. unsigned int bps;
  1267. unsigned int wcaps;
  1268. wcaps = get_wcaps(codec, nid);
  1269. streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
  1270. if (streams == -1)
  1271. return -EIO;
  1272. if (! streams) {
  1273. streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
  1274. if (streams == -1)
  1275. return -EIO;
  1276. }
  1277. bps = 0;
  1278. if (streams & AC_SUPFMT_PCM) {
  1279. if (val & AC_SUPPCM_BITS_8) {
  1280. formats |= SNDRV_PCM_FMTBIT_U8;
  1281. bps = 8;
  1282. }
  1283. if (val & AC_SUPPCM_BITS_16) {
  1284. formats |= SNDRV_PCM_FMTBIT_S16_LE;
  1285. bps = 16;
  1286. }
  1287. if (wcaps & AC_WCAP_DIGITAL) {
  1288. if (val & AC_SUPPCM_BITS_32)
  1289. formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
  1290. if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24))
  1291. formats |= SNDRV_PCM_FMTBIT_S32_LE;
  1292. if (val & AC_SUPPCM_BITS_24)
  1293. bps = 24;
  1294. else if (val & AC_SUPPCM_BITS_20)
  1295. bps = 20;
  1296. } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|AC_SUPPCM_BITS_32)) {
  1297. formats |= SNDRV_PCM_FMTBIT_S32_LE;
  1298. if (val & AC_SUPPCM_BITS_32)
  1299. bps = 32;
  1300. else if (val & AC_SUPPCM_BITS_20)
  1301. bps = 20;
  1302. else if (val & AC_SUPPCM_BITS_24)
  1303. bps = 24;
  1304. }
  1305. }
  1306. else if (streams == AC_SUPFMT_FLOAT32) { /* should be exclusive */
  1307. formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
  1308. bps = 32;
  1309. } else if (streams == AC_SUPFMT_AC3) { /* should be exclusive */
  1310. /* temporary hack: we have still no proper support
  1311. * for the direct AC3 stream...
  1312. */
  1313. formats |= SNDRV_PCM_FMTBIT_U8;
  1314. bps = 8;
  1315. }
  1316. if (formatsp)
  1317. *formatsp = formats;
  1318. if (bpsp)
  1319. *bpsp = bps;
  1320. }
  1321. return 0;
  1322. }
  1323. /**
  1324. * snd_hda_is_supported_format - check whether the given node supports the format val
  1325. *
  1326. * Returns 1 if supported, 0 if not.
  1327. */
  1328. int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
  1329. unsigned int format)
  1330. {
  1331. int i;
  1332. unsigned int val = 0, rate, stream;
  1333. if (nid != codec->afg &&
  1334. (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) {
  1335. val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
  1336. if (val == -1)
  1337. return 0;
  1338. }
  1339. if (! val) {
  1340. val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
  1341. if (val == -1)
  1342. return 0;
  1343. }
  1344. rate = format & 0xff00;
  1345. for (i = 0; rate_bits[i].hz; i++)
  1346. if (rate_bits[i].hda_fmt == rate) {
  1347. if (val & (1 << i))
  1348. break;
  1349. return 0;
  1350. }
  1351. if (! rate_bits[i].hz)
  1352. return 0;
  1353. stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
  1354. if (stream == -1)
  1355. return 0;
  1356. if (! stream && nid != codec->afg)
  1357. stream = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
  1358. if (! stream || stream == -1)
  1359. return 0;
  1360. if (stream & AC_SUPFMT_PCM) {
  1361. switch (format & 0xf0) {
  1362. case 0x00:
  1363. if (! (val & AC_SUPPCM_BITS_8))
  1364. return 0;
  1365. break;
  1366. case 0x10:
  1367. if (! (val & AC_SUPPCM_BITS_16))
  1368. return 0;
  1369. break;
  1370. case 0x20:
  1371. if (! (val & AC_SUPPCM_BITS_20))
  1372. return 0;
  1373. break;
  1374. case 0x30:
  1375. if (! (val & AC_SUPPCM_BITS_24))
  1376. return 0;
  1377. break;
  1378. case 0x40:
  1379. if (! (val & AC_SUPPCM_BITS_32))
  1380. return 0;
  1381. break;
  1382. default:
  1383. return 0;
  1384. }
  1385. } else {
  1386. /* FIXME: check for float32 and AC3? */
  1387. }
  1388. return 1;
  1389. }
  1390. /*
  1391. * PCM stuff
  1392. */
  1393. static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo,
  1394. struct hda_codec *codec,
  1395. struct snd_pcm_substream *substream)
  1396. {
  1397. return 0;
  1398. }
  1399. static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo,
  1400. struct hda_codec *codec,
  1401. unsigned int stream_tag,
  1402. unsigned int format,
  1403. struct snd_pcm_substream *substream)
  1404. {
  1405. snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
  1406. return 0;
  1407. }
  1408. static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
  1409. struct hda_codec *codec,
  1410. struct snd_pcm_substream *substream)
  1411. {
  1412. snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0);
  1413. return 0;
  1414. }
  1415. static int set_pcm_default_values(struct hda_codec *codec, struct hda_pcm_stream *info)
  1416. {
  1417. if (info->nid) {
  1418. /* query support PCM information from the given NID */
  1419. if (! info->rates || ! info->formats)
  1420. snd_hda_query_supported_pcm(codec, info->nid,
  1421. info->rates ? NULL : &info->rates,
  1422. info->formats ? NULL : &info->formats,
  1423. info->maxbps ? NULL : &info->maxbps);
  1424. }
  1425. if (info->ops.open == NULL)
  1426. info->ops.open = hda_pcm_default_open_close;
  1427. if (info->ops.close == NULL)
  1428. info->ops.close = hda_pcm_default_open_close;
  1429. if (info->ops.prepare == NULL) {
  1430. snd_assert(info->nid, return -EINVAL);
  1431. info->ops.prepare = hda_pcm_default_prepare;
  1432. }
  1433. if (info->ops.cleanup == NULL) {
  1434. snd_assert(info->nid, return -EINVAL);
  1435. info->ops.cleanup = hda_pcm_default_cleanup;
  1436. }
  1437. return 0;
  1438. }
  1439. /**
  1440. * snd_hda_build_pcms - build PCM information
  1441. * @bus: the BUS
  1442. *
  1443. * Create PCM information for each codec included in the bus.
  1444. *
  1445. * The build_pcms codec patch is requested to set up codec->num_pcms and
  1446. * codec->pcm_info properly. The array is referred by the top-level driver
  1447. * to create its PCM instances.
  1448. * The allocated codec->pcm_info should be released in codec->patch_ops.free
  1449. * callback.
  1450. *
  1451. * At least, substreams, channels_min and channels_max must be filled for
  1452. * each stream. substreams = 0 indicates that the stream doesn't exist.
  1453. * When rates and/or formats are zero, the supported values are queried
  1454. * from the given nid. The nid is used also by the default ops.prepare
  1455. * and ops.cleanup callbacks.
  1456. *
  1457. * The driver needs to call ops.open in its open callback. Similarly,
  1458. * ops.close is supposed to be called in the close callback.
  1459. * ops.prepare should be called in the prepare or hw_params callback
  1460. * with the proper parameters for set up.
  1461. * ops.cleanup should be called in hw_free for clean up of streams.
  1462. *
  1463. * This function returns 0 if successfull, or a negative error code.
  1464. */
  1465. int snd_hda_build_pcms(struct hda_bus *bus)
  1466. {
  1467. struct list_head *p;
  1468. list_for_each(p, &bus->codec_list) {
  1469. struct hda_codec *codec = list_entry(p, struct hda_codec, list);
  1470. unsigned int pcm, s;
  1471. int err;
  1472. if (! codec->patch_ops.build_pcms)
  1473. continue;
  1474. err = codec->patch_ops.build_pcms(codec);
  1475. if (err < 0)
  1476. return err;
  1477. for (pcm = 0; pcm < codec->num_pcms; pcm++) {
  1478. for (s = 0; s < 2; s++) {
  1479. struct hda_pcm_stream *info;
  1480. info = &codec->pcm_info[pcm].stream[s];
  1481. if (! info->substreams)
  1482. continue;
  1483. err = set_pcm_default_values(codec, info);
  1484. if (err < 0)
  1485. return err;
  1486. }
  1487. }
  1488. }
  1489. return 0;
  1490. }
  1491. EXPORT_SYMBOL(snd_hda_build_pcms);
  1492. /**
  1493. * snd_hda_check_board_config - compare the current codec with the config table
  1494. * @codec: the HDA codec
  1495. * @tbl: configuration table, terminated by null entries
  1496. *
  1497. * Compares the modelname or PCI subsystem id of the current codec with the
  1498. * given configuration table. If a matching entry is found, returns its
  1499. * config value (supposed to be 0 or positive).
  1500. *
  1501. * If no entries are matching, the function returns a negative value.
  1502. */
  1503. int snd_hda_check_board_config(struct hda_codec *codec, const struct hda_board_config *tbl)
  1504. {
  1505. const struct hda_board_config *c;
  1506. if (codec->bus->modelname) {
  1507. for (c = tbl; c->modelname || c->pci_subvendor; c++) {
  1508. if (c->modelname &&
  1509. ! strcmp(codec->bus->modelname, c->modelname)) {
  1510. snd_printd(KERN_INFO "hda_codec: model '%s' is selected\n", c->modelname);
  1511. return c->config;
  1512. }
  1513. }
  1514. }
  1515. if (codec->bus->pci) {
  1516. u16 subsystem_vendor, subsystem_device;
  1517. pci_read_config_word(codec->bus->pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
  1518. pci_read_config_word(codec->bus->pci, PCI_SUBSYSTEM_ID, &subsystem_device);
  1519. for (c = tbl; c->modelname || c->pci_subvendor; c++) {
  1520. if (c->pci_subvendor == subsystem_vendor &&
  1521. (! c->pci_subdevice /* all match */||
  1522. (c->pci_subdevice == subsystem_device))) {
  1523. snd_printdd(KERN_INFO "hda_codec: PCI %x:%x, codec config %d is selected\n",
  1524. subsystem_vendor, subsystem_device, c->config);
  1525. return c->config;
  1526. }
  1527. }
  1528. }
  1529. return -1;
  1530. }
  1531. /**
  1532. * snd_hda_add_new_ctls - create controls from the array
  1533. * @codec: the HDA codec
  1534. * @knew: the array of struct snd_kcontrol_new
  1535. *
  1536. * This helper function creates and add new controls in the given array.
  1537. * The array must be terminated with an empty entry as terminator.
  1538. *
  1539. * Returns 0 if successful, or a negative error code.
  1540. */
  1541. int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
  1542. {
  1543. int err;
  1544. for (; knew->name; knew++) {
  1545. struct snd_kcontrol *kctl;
  1546. kctl = snd_ctl_new1(knew, codec);
  1547. if (! kctl)
  1548. return -ENOMEM;
  1549. err = snd_ctl_add(codec->bus->card, kctl);
  1550. if (err < 0) {
  1551. if (! codec->addr)
  1552. return err;
  1553. kctl = snd_ctl_new1(knew, codec);
  1554. if (! kctl)
  1555. return -ENOMEM;
  1556. kctl->id.device = codec->addr;
  1557. if ((err = snd_ctl_add(codec->bus->card, kctl)) < 0)
  1558. return err;
  1559. }
  1560. }
  1561. return 0;
  1562. }
  1563. /*
  1564. * Channel mode helper
  1565. */
  1566. int snd_hda_ch_mode_info(struct hda_codec *codec, struct snd_ctl_elem_info *uinfo,
  1567. const struct hda_channel_mode *chmode, int num_chmodes)
  1568. {
  1569. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1570. uinfo->count = 1;
  1571. uinfo->value.enumerated.items = num_chmodes;
  1572. if (uinfo->value.enumerated.item >= num_chmodes)
  1573. uinfo->value.enumerated.item = num_chmodes - 1;
  1574. sprintf(uinfo->value.enumerated.name, "%dch",
  1575. chmode[uinfo->value.enumerated.item].channels);
  1576. return 0;
  1577. }
  1578. int snd_hda_ch_mode_get(struct hda_codec *codec, struct snd_ctl_elem_value *ucontrol,
  1579. const struct hda_channel_mode *chmode, int num_chmodes,
  1580. int max_channels)
  1581. {
  1582. int i;
  1583. for (i = 0; i < num_chmodes; i++) {
  1584. if (max_channels == chmode[i].channels) {
  1585. ucontrol->value.enumerated.item[0] = i;
  1586. break;
  1587. }
  1588. }
  1589. return 0;
  1590. }
  1591. int snd_hda_ch_mode_put(struct hda_codec *codec, struct snd_ctl_elem_value *ucontrol,
  1592. const struct hda_channel_mode *chmode, int num_chmodes,
  1593. int *max_channelsp)
  1594. {
  1595. unsigned int mode;
  1596. mode = ucontrol->value.enumerated.item[0];
  1597. snd_assert(mode < num_chmodes, return -EINVAL);
  1598. if (*max_channelsp == chmode[mode].channels && ! codec->in_resume)
  1599. return 0;
  1600. /* change the current channel setting */
  1601. *max_channelsp = chmode[mode].channels;
  1602. if (chmode[mode].sequence)
  1603. snd_hda_sequence_write(codec, chmode[mode].sequence);
  1604. return 1;
  1605. }
  1606. /*
  1607. * input MUX helper
  1608. */
  1609. int snd_hda_input_mux_info(const struct hda_input_mux *imux, struct snd_ctl_elem_info *uinfo)
  1610. {
  1611. unsigned int index;
  1612. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1613. uinfo->count = 1;
  1614. uinfo->value.enumerated.items = imux->num_items;
  1615. index = uinfo->value.enumerated.item;
  1616. if (index >= imux->num_items)
  1617. index = imux->num_items - 1;
  1618. strcpy(uinfo->value.enumerated.name, imux->items[index].label);
  1619. return 0;
  1620. }
  1621. int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *imux,
  1622. struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
  1623. unsigned int *cur_val)
  1624. {
  1625. unsigned int idx;
  1626. idx = ucontrol->value.enumerated.item[0];
  1627. if (idx >= imux->num_items)
  1628. idx = imux->num_items - 1;
  1629. if (*cur_val == idx && ! codec->in_resume)
  1630. return 0;
  1631. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
  1632. imux->items[idx].index);
  1633. *cur_val = idx;
  1634. return 1;
  1635. }
  1636. /*
  1637. * Multi-channel / digital-out PCM helper functions
  1638. */
  1639. /*
  1640. * open the digital out in the exclusive mode
  1641. */
  1642. int snd_hda_multi_out_dig_open(struct hda_codec *codec, struct hda_multi_out *mout)
  1643. {
  1644. mutex_lock(&codec->spdif_mutex);
  1645. if (mout->dig_out_used) {
  1646. mutex_unlock(&codec->spdif_mutex);
  1647. return -EBUSY; /* already being used */
  1648. }
  1649. mout->dig_out_used = HDA_DIG_EXCLUSIVE;
  1650. mutex_unlock(&codec->spdif_mutex);
  1651. return 0;
  1652. }
  1653. /*
  1654. * release the digital out
  1655. */
  1656. int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *mout)
  1657. {
  1658. mutex_lock(&codec->spdif_mutex);
  1659. mout->dig_out_used = 0;
  1660. mutex_unlock(&codec->spdif_mutex);
  1661. return 0;
  1662. }
  1663. /*
  1664. * set up more restrictions for analog out
  1665. */
  1666. int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out *mout,
  1667. struct snd_pcm_substream *substream)
  1668. {
  1669. substream->runtime->hw.channels_max = mout->max_channels;
  1670. return snd_pcm_hw_constraint_step(substream->runtime, 0,
  1671. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1672. }
  1673. /*
  1674. * set up the i/o for analog out
  1675. * when the digital out is available, copy the front out to digital out, too.
  1676. */
  1677. int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout,
  1678. unsigned int stream_tag,
  1679. unsigned int format,
  1680. struct snd_pcm_substream *substream)
  1681. {
  1682. hda_nid_t *nids = mout->dac_nids;
  1683. int chs = substream->runtime->channels;
  1684. int i;
  1685. mutex_lock(&codec->spdif_mutex);
  1686. if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
  1687. if (chs == 2 &&
  1688. snd_hda_is_supported_format(codec, mout->dig_out_nid, format) &&
  1689. ! (codec->spdif_status & IEC958_AES0_NONAUDIO)) {
  1690. mout->dig_out_used = HDA_DIG_ANALOG_DUP;
  1691. /* setup digital receiver */
  1692. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1693. stream_tag, 0, format);
  1694. } else {
  1695. mout->dig_out_used = 0;
  1696. snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0);
  1697. }
  1698. }
  1699. mutex_unlock(&codec->spdif_mutex);
  1700. /* front */
  1701. snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 0, format);
  1702. if (mout->hp_nid)
  1703. /* headphone out will just decode front left/right (stereo) */
  1704. snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format);
  1705. /* extra outputs copied from front */
  1706. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  1707. if (mout->extra_out_nid[i])
  1708. snd_hda_codec_setup_stream(codec,
  1709. mout->extra_out_nid[i],
  1710. stream_tag, 0, format);
  1711. /* surrounds */
  1712. for (i = 1; i < mout->num_dacs; i++) {
  1713. if (chs >= (i + 1) * 2) /* independent out */
  1714. snd_hda_codec_setup_stream(codec, nids[i], stream_tag, i * 2,
  1715. format);
  1716. else /* copy front */
  1717. snd_hda_codec_setup_stream(codec, nids[i], stream_tag, 0,
  1718. format);
  1719. }
  1720. return 0;
  1721. }
  1722. /*
  1723. * clean up the setting for analog out
  1724. */
  1725. int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout)
  1726. {
  1727. hda_nid_t *nids = mout->dac_nids;
  1728. int i;
  1729. for (i = 0; i < mout->num_dacs; i++)
  1730. snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
  1731. if (mout->hp_nid)
  1732. snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0);
  1733. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  1734. if (mout->extra_out_nid[i])
  1735. snd_hda_codec_setup_stream(codec,
  1736. mout->extra_out_nid[i],
  1737. 0, 0, 0);
  1738. mutex_lock(&codec->spdif_mutex);
  1739. if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
  1740. snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0);
  1741. mout->dig_out_used = 0;
  1742. }
  1743. mutex_unlock(&codec->spdif_mutex);
  1744. return 0;
  1745. }
  1746. /*
  1747. * Helper for automatic ping configuration
  1748. */
  1749. static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
  1750. {
  1751. for (; *list; list++)
  1752. if (*list == nid)
  1753. return 1;
  1754. return 0;
  1755. }
  1756. /*
  1757. * Parse all pin widgets and store the useful pin nids to cfg
  1758. *
  1759. * The number of line-outs or any primary output is stored in line_outs,
  1760. * and the corresponding output pins are assigned to line_out_pins[],
  1761. * in the order of front, rear, CLFE, side, ...
  1762. *
  1763. * If more extra outputs (speaker and headphone) are found, the pins are
  1764. * assisnged to hp_pin and speaker_pins[], respectively. If no line-out jack
  1765. * is detected, one of speaker of HP pins is assigned as the primary
  1766. * output, i.e. to line_out_pins[0]. So, line_outs is always positive
  1767. * if any analog output exists.
  1768. *
  1769. * The analog input pins are assigned to input_pins array.
  1770. * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
  1771. * respectively.
  1772. */
  1773. int snd_hda_parse_pin_def_config(struct hda_codec *codec, struct auto_pin_cfg *cfg,
  1774. hda_nid_t *ignore_nids)
  1775. {
  1776. hda_nid_t nid, nid_start;
  1777. int i, j, nodes;
  1778. short seq, assoc_line_out, sequences[ARRAY_SIZE(cfg->line_out_pins)];
  1779. memset(cfg, 0, sizeof(*cfg));
  1780. memset(sequences, 0, sizeof(sequences));
  1781. assoc_line_out = 0;
  1782. nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid_start);
  1783. for (nid = nid_start; nid < nodes + nid_start; nid++) {
  1784. unsigned int wid_caps = get_wcaps(codec, nid);
  1785. unsigned int wid_type = (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1786. unsigned int def_conf;
  1787. short assoc, loc;
  1788. /* read all default configuration for pin complex */
  1789. if (wid_type != AC_WID_PIN)
  1790. continue;
  1791. /* ignore the given nids (e.g. pc-beep returns error) */
  1792. if (ignore_nids && is_in_nid_list(nid, ignore_nids))
  1793. continue;
  1794. def_conf = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
  1795. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1796. continue;
  1797. loc = get_defcfg_location(def_conf);
  1798. switch (get_defcfg_device(def_conf)) {
  1799. case AC_JACK_LINE_OUT:
  1800. seq = get_defcfg_sequence(def_conf);
  1801. assoc = get_defcfg_association(def_conf);
  1802. if (! assoc)
  1803. continue;
  1804. if (! assoc_line_out)
  1805. assoc_line_out = assoc;
  1806. else if (assoc_line_out != assoc)
  1807. continue;
  1808. if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
  1809. continue;
  1810. cfg->line_out_pins[cfg->line_outs] = nid;
  1811. sequences[cfg->line_outs] = seq;
  1812. cfg->line_outs++;
  1813. break;
  1814. case AC_JACK_SPEAKER:
  1815. if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
  1816. continue;
  1817. cfg->speaker_pins[cfg->speaker_outs] = nid;
  1818. cfg->speaker_outs++;
  1819. break;
  1820. case AC_JACK_HP_OUT:
  1821. cfg->hp_pin = nid;
  1822. break;
  1823. case AC_JACK_MIC_IN:
  1824. if (loc == AC_JACK_LOC_FRONT)
  1825. cfg->input_pins[AUTO_PIN_FRONT_MIC] = nid;
  1826. else
  1827. cfg->input_pins[AUTO_PIN_MIC] = nid;
  1828. break;
  1829. case AC_JACK_LINE_IN:
  1830. if (loc == AC_JACK_LOC_FRONT)
  1831. cfg->input_pins[AUTO_PIN_FRONT_LINE] = nid;
  1832. else
  1833. cfg->input_pins[AUTO_PIN_LINE] = nid;
  1834. break;
  1835. case AC_JACK_CD:
  1836. cfg->input_pins[AUTO_PIN_CD] = nid;
  1837. break;
  1838. case AC_JACK_AUX:
  1839. cfg->input_pins[AUTO_PIN_AUX] = nid;
  1840. break;
  1841. case AC_JACK_SPDIF_OUT:
  1842. cfg->dig_out_pin = nid;
  1843. break;
  1844. case AC_JACK_SPDIF_IN:
  1845. cfg->dig_in_pin = nid;
  1846. break;
  1847. }
  1848. }
  1849. /* sort by sequence */
  1850. for (i = 0; i < cfg->line_outs; i++)
  1851. for (j = i + 1; j < cfg->line_outs; j++)
  1852. if (sequences[i] > sequences[j]) {
  1853. seq = sequences[i];
  1854. sequences[i] = sequences[j];
  1855. sequences[j] = seq;
  1856. nid = cfg->line_out_pins[i];
  1857. cfg->line_out_pins[i] = cfg->line_out_pins[j];
  1858. cfg->line_out_pins[j] = nid;
  1859. }
  1860. /* Reorder the surround channels
  1861. * ALSA sequence is front/surr/clfe/side
  1862. * HDA sequence is:
  1863. * 4-ch: front/surr => OK as it is
  1864. * 6-ch: front/clfe/surr
  1865. * 8-ch: front/clfe/side/surr
  1866. */
  1867. switch (cfg->line_outs) {
  1868. case 3:
  1869. nid = cfg->line_out_pins[1];
  1870. cfg->line_out_pins[1] = cfg->line_out_pins[2];
  1871. cfg->line_out_pins[2] = nid;
  1872. break;
  1873. case 4:
  1874. nid = cfg->line_out_pins[1];
  1875. cfg->line_out_pins[1] = cfg->line_out_pins[3];
  1876. cfg->line_out_pins[3] = cfg->line_out_pins[2];
  1877. cfg->line_out_pins[2] = nid;
  1878. break;
  1879. }
  1880. /*
  1881. * debug prints of the parsed results
  1882. */
  1883. snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  1884. cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
  1885. cfg->line_out_pins[2], cfg->line_out_pins[3],
  1886. cfg->line_out_pins[4]);
  1887. snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  1888. cfg->speaker_outs, cfg->speaker_pins[0],
  1889. cfg->speaker_pins[1], cfg->speaker_pins[2],
  1890. cfg->speaker_pins[3], cfg->speaker_pins[4]);
  1891. snd_printd(" hp=0x%x, dig_out=0x%x, din_in=0x%x\n",
  1892. cfg->hp_pin, cfg->dig_out_pin, cfg->dig_in_pin);
  1893. snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
  1894. " cd=0x%x, aux=0x%x\n",
  1895. cfg->input_pins[AUTO_PIN_MIC],
  1896. cfg->input_pins[AUTO_PIN_FRONT_MIC],
  1897. cfg->input_pins[AUTO_PIN_LINE],
  1898. cfg->input_pins[AUTO_PIN_FRONT_LINE],
  1899. cfg->input_pins[AUTO_PIN_CD],
  1900. cfg->input_pins[AUTO_PIN_AUX]);
  1901. /*
  1902. * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
  1903. * as a primary output
  1904. */
  1905. if (! cfg->line_outs) {
  1906. if (cfg->speaker_outs) {
  1907. cfg->line_outs = cfg->speaker_outs;
  1908. memcpy(cfg->line_out_pins, cfg->speaker_pins,
  1909. sizeof(cfg->speaker_pins));
  1910. cfg->speaker_outs = 0;
  1911. memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
  1912. } else if (cfg->hp_pin) {
  1913. cfg->line_outs = 1;
  1914. cfg->line_out_pins[0] = cfg->hp_pin;
  1915. cfg->hp_pin = 0;
  1916. }
  1917. }
  1918. return 0;
  1919. }
  1920. /* labels for input pins */
  1921. const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
  1922. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
  1923. };
  1924. #ifdef CONFIG_PM
  1925. /*
  1926. * power management
  1927. */
  1928. /**
  1929. * snd_hda_suspend - suspend the codecs
  1930. * @bus: the HDA bus
  1931. * @state: suspsend state
  1932. *
  1933. * Returns 0 if successful.
  1934. */
  1935. int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
  1936. {
  1937. struct list_head *p;
  1938. /* FIXME: should handle power widget capabilities */
  1939. list_for_each(p, &bus->codec_list) {
  1940. struct hda_codec *codec = list_entry(p, struct hda_codec, list);
  1941. if (codec->patch_ops.suspend)
  1942. codec->patch_ops.suspend(codec, state);
  1943. hda_set_power_state(codec,
  1944. codec->afg ? codec->afg : codec->mfg,
  1945. AC_PWRST_D3);
  1946. }
  1947. return 0;
  1948. }
  1949. EXPORT_SYMBOL(snd_hda_suspend);
  1950. /**
  1951. * snd_hda_resume - resume the codecs
  1952. * @bus: the HDA bus
  1953. * @state: resume state
  1954. *
  1955. * Returns 0 if successful.
  1956. */
  1957. int snd_hda_resume(struct hda_bus *bus)
  1958. {
  1959. struct list_head *p;
  1960. list_for_each(p, &bus->codec_list) {
  1961. struct hda_codec *codec = list_entry(p, struct hda_codec, list);
  1962. hda_set_power_state(codec,
  1963. codec->afg ? codec->afg : codec->mfg,
  1964. AC_PWRST_D0);
  1965. if (codec->patch_ops.resume)
  1966. codec->patch_ops.resume(codec);
  1967. }
  1968. return 0;
  1969. }
  1970. EXPORT_SYMBOL(snd_hda_resume);
  1971. /**
  1972. * snd_hda_resume_ctls - resume controls in the new control list
  1973. * @codec: the HDA codec
  1974. * @knew: the array of struct snd_kcontrol_new
  1975. *
  1976. * This function resumes the mixer controls in the struct snd_kcontrol_new array,
  1977. * originally for snd_hda_add_new_ctls().
  1978. * The array must be terminated with an empty entry as terminator.
  1979. */
  1980. int snd_hda_resume_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
  1981. {
  1982. struct snd_ctl_elem_value *val;
  1983. val = kmalloc(sizeof(*val), GFP_KERNEL);
  1984. if (! val)
  1985. return -ENOMEM;
  1986. codec->in_resume = 1;
  1987. for (; knew->name; knew++) {
  1988. int i, count;
  1989. count = knew->count ? knew->count : 1;
  1990. for (i = 0; i < count; i++) {
  1991. memset(val, 0, sizeof(*val));
  1992. val->id.iface = knew->iface;
  1993. val->id.device = knew->device;
  1994. val->id.subdevice = knew->subdevice;
  1995. strcpy(val->id.name, knew->name);
  1996. val->id.index = knew->index ? knew->index : i;
  1997. /* Assume that get callback reads only from cache,
  1998. * not accessing to the real hardware
  1999. */
  2000. if (snd_ctl_elem_read(codec->bus->card, val) < 0)
  2001. continue;
  2002. snd_ctl_elem_write(codec->bus->card, NULL, val);
  2003. }
  2004. }
  2005. codec->in_resume = 0;
  2006. kfree(val);
  2007. return 0;
  2008. }
  2009. /**
  2010. * snd_hda_resume_spdif_out - resume the digital out
  2011. * @codec: the HDA codec
  2012. */
  2013. int snd_hda_resume_spdif_out(struct hda_codec *codec)
  2014. {
  2015. return snd_hda_resume_ctls(codec, dig_mixes);
  2016. }
  2017. /**
  2018. * snd_hda_resume_spdif_in - resume the digital in
  2019. * @codec: the HDA codec
  2020. */
  2021. int snd_hda_resume_spdif_in(struct hda_codec *codec)
  2022. {
  2023. return snd_hda_resume_ctls(codec, dig_in_ctls);
  2024. }
  2025. #endif
  2026. /*
  2027. * INIT part
  2028. */
  2029. static int __init alsa_hda_init(void)
  2030. {
  2031. return 0;
  2032. }
  2033. static void __exit alsa_hda_exit(void)
  2034. {
  2035. }
  2036. module_init(alsa_hda_init)
  2037. module_exit(alsa_hda_exit)