hda_codec.c 61 KB

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