ice1724.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424
  1. /*
  2. * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
  3. * VIA VT1720 (Envy24PT)
  4. *
  5. * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  6. * 2002 James Stafford <jstafford@ampltd.com>
  7. * 2003 Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/driver.h>
  25. #include <asm/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/init.h>
  29. #include <linux/pci.h>
  30. #include <linux/slab.h>
  31. #include <linux/moduleparam.h>
  32. #include <linux/mutex.h>
  33. #include <sound/core.h>
  34. #include <sound/info.h>
  35. #include <sound/mpu401.h>
  36. #include <sound/initval.h>
  37. #include <sound/asoundef.h>
  38. #include "ice1712.h"
  39. #include "envy24ht.h"
  40. /* lowlevel routines */
  41. #include "amp.h"
  42. #include "revo.h"
  43. #include "aureon.h"
  44. #include "vt1720_mobo.h"
  45. #include "pontis.h"
  46. #include "prodigy192.h"
  47. #include "juli.h"
  48. #include "phase.h"
  49. #include "wtm.h"
  50. #include "se.h"
  51. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  52. MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
  53. MODULE_LICENSE("GPL");
  54. MODULE_SUPPORTED_DEVICE("{"
  55. REVO_DEVICE_DESC
  56. AMP_AUDIO2000_DEVICE_DESC
  57. AUREON_DEVICE_DESC
  58. VT1720_MOBO_DEVICE_DESC
  59. PONTIS_DEVICE_DESC
  60. PRODIGY192_DEVICE_DESC
  61. JULI_DEVICE_DESC
  62. PHASE_DEVICE_DESC
  63. WTM_DEVICE_DESC
  64. SE_DEVICE_DESC
  65. "{VIA,VT1720},"
  66. "{VIA,VT1724},"
  67. "{ICEnsemble,Generic ICE1724},"
  68. "{ICEnsemble,Generic Envy24HT}"
  69. "{ICEnsemble,Generic Envy24PT}}");
  70. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  71. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  72. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  73. static char *model[SNDRV_CARDS];
  74. module_param_array(index, int, NULL, 0444);
  75. MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
  76. module_param_array(id, charp, NULL, 0444);
  77. MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
  78. module_param_array(enable, bool, NULL, 0444);
  79. MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
  80. module_param_array(model, charp, NULL, 0444);
  81. MODULE_PARM_DESC(model, "Use the given board model.");
  82. /* Both VT1720 and VT1724 have the same PCI IDs */
  83. static const struct pci_device_id snd_vt1724_ids[] = {
  84. { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  85. { 0, }
  86. };
  87. MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
  88. static int PRO_RATE_LOCKED;
  89. static int PRO_RATE_RESET = 1;
  90. static unsigned int PRO_RATE_DEFAULT = 44100;
  91. /*
  92. * Basic I/O
  93. */
  94. /* check whether the clock mode is spdif-in */
  95. static inline int is_spdif_master(struct snd_ice1712 *ice)
  96. {
  97. return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
  98. }
  99. static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
  100. {
  101. return is_spdif_master(ice) || PRO_RATE_LOCKED;
  102. }
  103. /*
  104. * ac97 section
  105. */
  106. static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
  107. {
  108. unsigned char old_cmd;
  109. int tm;
  110. for (tm = 0; tm < 0x10000; tm++) {
  111. old_cmd = inb(ICEMT1724(ice, AC97_CMD));
  112. if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
  113. continue;
  114. if (!(old_cmd & VT1724_AC97_READY))
  115. continue;
  116. return old_cmd;
  117. }
  118. snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
  119. return old_cmd;
  120. }
  121. static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
  122. {
  123. int tm;
  124. for (tm = 0; tm < 0x10000; tm++)
  125. if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
  126. return 0;
  127. snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
  128. return -EIO;
  129. }
  130. static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
  131. unsigned short reg,
  132. unsigned short val)
  133. {
  134. struct snd_ice1712 *ice = ac97->private_data;
  135. unsigned char old_cmd;
  136. old_cmd = snd_vt1724_ac97_ready(ice);
  137. old_cmd &= ~VT1724_AC97_ID_MASK;
  138. old_cmd |= ac97->num;
  139. outb(reg, ICEMT1724(ice, AC97_INDEX));
  140. outw(val, ICEMT1724(ice, AC97_DATA));
  141. outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
  142. snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
  143. }
  144. static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
  145. {
  146. struct snd_ice1712 *ice = ac97->private_data;
  147. unsigned char old_cmd;
  148. old_cmd = snd_vt1724_ac97_ready(ice);
  149. old_cmd &= ~VT1724_AC97_ID_MASK;
  150. old_cmd |= ac97->num;
  151. outb(reg, ICEMT1724(ice, AC97_INDEX));
  152. outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
  153. if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
  154. return ~0;
  155. return inw(ICEMT1724(ice, AC97_DATA));
  156. }
  157. /*
  158. * GPIO operations
  159. */
  160. /* set gpio direction 0 = read, 1 = write */
  161. static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
  162. {
  163. outl(data, ICEREG1724(ice, GPIO_DIRECTION));
  164. inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
  165. }
  166. /* set the gpio mask (0 = writable) */
  167. static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
  168. {
  169. outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
  170. if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
  171. outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
  172. inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
  173. }
  174. static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
  175. {
  176. outw(data, ICEREG1724(ice, GPIO_DATA));
  177. if (! ice->vt1720)
  178. outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
  179. inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
  180. }
  181. static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
  182. {
  183. unsigned int data;
  184. if (! ice->vt1720)
  185. data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
  186. else
  187. data = 0;
  188. data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
  189. return data;
  190. }
  191. /*
  192. * Interrupt handler
  193. */
  194. static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
  195. {
  196. struct snd_ice1712 *ice = dev_id;
  197. unsigned char status;
  198. int handled = 0;
  199. while (1) {
  200. status = inb(ICEREG1724(ice, IRQSTAT));
  201. if (status == 0)
  202. break;
  203. handled = 1;
  204. /* these should probably be separated at some point,
  205. * but as we don't currently have MPU support on the board
  206. * I will leave it
  207. */
  208. if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
  209. if (ice->rmidi[0])
  210. snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
  211. outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
  212. status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
  213. }
  214. if (status & VT1724_IRQ_MTPCM) {
  215. /*
  216. * Multi-track PCM
  217. * PCM assignment are:
  218. * Playback DMA0 (M/C) = playback_pro_substream
  219. * Playback DMA1 = playback_con_substream_ds[0]
  220. * Playback DMA2 = playback_con_substream_ds[1]
  221. * Playback DMA3 = playback_con_substream_ds[2]
  222. * Playback DMA4 (SPDIF) = playback_con_substream
  223. * Record DMA0 = capture_pro_substream
  224. * Record DMA1 = capture_con_substream
  225. */
  226. unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
  227. if (mtstat & VT1724_MULTI_PDMA0) {
  228. if (ice->playback_pro_substream)
  229. snd_pcm_period_elapsed(ice->playback_pro_substream);
  230. }
  231. if (mtstat & VT1724_MULTI_RDMA0) {
  232. if (ice->capture_pro_substream)
  233. snd_pcm_period_elapsed(ice->capture_pro_substream);
  234. }
  235. if (mtstat & VT1724_MULTI_PDMA1) {
  236. if (ice->playback_con_substream_ds[0])
  237. snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
  238. }
  239. if (mtstat & VT1724_MULTI_PDMA2) {
  240. if (ice->playback_con_substream_ds[1])
  241. snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
  242. }
  243. if (mtstat & VT1724_MULTI_PDMA3) {
  244. if (ice->playback_con_substream_ds[2])
  245. snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
  246. }
  247. if (mtstat & VT1724_MULTI_PDMA4) {
  248. if (ice->playback_con_substream)
  249. snd_pcm_period_elapsed(ice->playback_con_substream);
  250. }
  251. if (mtstat & VT1724_MULTI_RDMA1) {
  252. if (ice->capture_con_substream)
  253. snd_pcm_period_elapsed(ice->capture_con_substream);
  254. }
  255. /* ack anyway to avoid freeze */
  256. outb(mtstat, ICEMT1724(ice, IRQ));
  257. /* ought to really handle this properly */
  258. if (mtstat & VT1724_MULTI_FIFO_ERR) {
  259. unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
  260. outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
  261. outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
  262. /* If I don't do this, I get machine lockup due to continual interrupts */
  263. }
  264. }
  265. }
  266. return IRQ_RETVAL(handled);
  267. }
  268. /*
  269. * PCM code - professional part (multitrack)
  270. */
  271. static unsigned int rates[] = {
  272. 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  273. 32000, 44100, 48000, 64000, 88200, 96000,
  274. 176400, 192000,
  275. };
  276. static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
  277. .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
  278. .list = rates,
  279. .mask = 0,
  280. };
  281. static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
  282. .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
  283. .list = rates,
  284. .mask = 0,
  285. };
  286. static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
  287. .count = ARRAY_SIZE(rates),
  288. .list = rates,
  289. .mask = 0,
  290. };
  291. struct vt1724_pcm_reg {
  292. unsigned int addr; /* ADDR register offset */
  293. unsigned int size; /* SIZE register offset */
  294. unsigned int count; /* COUNT register offset */
  295. unsigned int start; /* start & pause bit */
  296. };
  297. static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  298. {
  299. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  300. unsigned char what;
  301. unsigned char old;
  302. struct snd_pcm_substream *s;
  303. what = 0;
  304. snd_pcm_group_for_each_entry(s, substream) {
  305. if (snd_pcm_substream_chip(s) == ice) {
  306. const struct vt1724_pcm_reg *reg;
  307. reg = s->runtime->private_data;
  308. what |= reg->start;
  309. snd_pcm_trigger_done(s, substream);
  310. }
  311. }
  312. switch (cmd) {
  313. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  314. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  315. spin_lock(&ice->reg_lock);
  316. old = inb(ICEMT1724(ice, DMA_PAUSE));
  317. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  318. old |= what;
  319. else
  320. old &= ~what;
  321. outb(old, ICEMT1724(ice, DMA_PAUSE));
  322. spin_unlock(&ice->reg_lock);
  323. break;
  324. case SNDRV_PCM_TRIGGER_START:
  325. case SNDRV_PCM_TRIGGER_STOP:
  326. spin_lock(&ice->reg_lock);
  327. old = inb(ICEMT1724(ice, DMA_CONTROL));
  328. if (cmd == SNDRV_PCM_TRIGGER_START)
  329. old |= what;
  330. else
  331. old &= ~what;
  332. outb(old, ICEMT1724(ice, DMA_CONTROL));
  333. spin_unlock(&ice->reg_lock);
  334. break;
  335. default:
  336. return -EINVAL;
  337. }
  338. return 0;
  339. }
  340. /*
  341. */
  342. #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
  343. VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
  344. #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
  345. VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
  346. static int get_max_rate(struct snd_ice1712 *ice)
  347. {
  348. if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
  349. if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
  350. return 192000;
  351. else
  352. return 96000;
  353. } else
  354. return 48000;
  355. }
  356. static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
  357. int force)
  358. {
  359. unsigned long flags;
  360. unsigned char val, old;
  361. unsigned int i, mclk_change;
  362. if (rate > get_max_rate(ice))
  363. return;
  364. switch (rate) {
  365. case 8000: val = 6; break;
  366. case 9600: val = 3; break;
  367. case 11025: val = 10; break;
  368. case 12000: val = 2; break;
  369. case 16000: val = 5; break;
  370. case 22050: val = 9; break;
  371. case 24000: val = 1; break;
  372. case 32000: val = 4; break;
  373. case 44100: val = 8; break;
  374. case 48000: val = 0; break;
  375. case 64000: val = 15; break;
  376. case 88200: val = 11; break;
  377. case 96000: val = 7; break;
  378. case 176400: val = 12; break;
  379. case 192000: val = 14; break;
  380. default:
  381. snd_BUG();
  382. val = 0;
  383. break;
  384. }
  385. spin_lock_irqsave(&ice->reg_lock, flags);
  386. if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
  387. (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
  388. /* running? we cannot change the rate now... */
  389. spin_unlock_irqrestore(&ice->reg_lock, flags);
  390. return;
  391. }
  392. if (!force && is_pro_rate_locked(ice)) {
  393. spin_unlock_irqrestore(&ice->reg_lock, flags);
  394. return;
  395. }
  396. old = inb(ICEMT1724(ice, RATE));
  397. if (force || old != val)
  398. outb(val, ICEMT1724(ice, RATE));
  399. else if (rate == ice->cur_rate) {
  400. spin_unlock_irqrestore(&ice->reg_lock, flags);
  401. return;
  402. }
  403. ice->cur_rate = rate;
  404. /* check MT02 */
  405. mclk_change = 0;
  406. if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
  407. val = old = inb(ICEMT1724(ice, I2S_FORMAT));
  408. if (rate > 96000)
  409. val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
  410. else
  411. val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
  412. if (val != old) {
  413. outb(val, ICEMT1724(ice, I2S_FORMAT));
  414. mclk_change = 1;
  415. }
  416. }
  417. spin_unlock_irqrestore(&ice->reg_lock, flags);
  418. if (mclk_change && ice->gpio.i2s_mclk_changed)
  419. ice->gpio.i2s_mclk_changed(ice);
  420. if (ice->gpio.set_pro_rate)
  421. ice->gpio.set_pro_rate(ice, rate);
  422. /* set up codecs */
  423. for (i = 0; i < ice->akm_codecs; i++) {
  424. if (ice->akm[i].ops.set_rate_val)
  425. ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
  426. }
  427. if (ice->spdif.ops.setup_rate)
  428. ice->spdif.ops.setup_rate(ice, rate);
  429. }
  430. static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
  431. struct snd_pcm_hw_params *hw_params)
  432. {
  433. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  434. int i, chs;
  435. chs = params_channels(hw_params);
  436. mutex_lock(&ice->open_mutex);
  437. /* mark surround channels */
  438. if (substream == ice->playback_pro_substream) {
  439. /* PDMA0 can be multi-channel up to 8 */
  440. chs = chs / 2 - 1;
  441. for (i = 0; i < chs; i++) {
  442. if (ice->pcm_reserved[i] &&
  443. ice->pcm_reserved[i] != substream) {
  444. mutex_unlock(&ice->open_mutex);
  445. return -EBUSY;
  446. }
  447. ice->pcm_reserved[i] = substream;
  448. }
  449. for (; i < 3; i++) {
  450. if (ice->pcm_reserved[i] == substream)
  451. ice->pcm_reserved[i] = NULL;
  452. }
  453. } else {
  454. for (i = 0; i < 3; i++) {
  455. /* check individual playback stream */
  456. if (ice->playback_con_substream_ds[i] == substream) {
  457. if (ice->pcm_reserved[i] &&
  458. ice->pcm_reserved[i] != substream) {
  459. mutex_unlock(&ice->open_mutex);
  460. return -EBUSY;
  461. }
  462. ice->pcm_reserved[i] = substream;
  463. break;
  464. }
  465. }
  466. }
  467. mutex_unlock(&ice->open_mutex);
  468. snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
  469. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  470. }
  471. static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
  472. {
  473. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  474. int i;
  475. mutex_lock(&ice->open_mutex);
  476. /* unmark surround channels */
  477. for (i = 0; i < 3; i++)
  478. if (ice->pcm_reserved[i] == substream)
  479. ice->pcm_reserved[i] = NULL;
  480. mutex_unlock(&ice->open_mutex);
  481. return snd_pcm_lib_free_pages(substream);
  482. }
  483. static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
  484. {
  485. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  486. unsigned char val;
  487. unsigned int size;
  488. spin_lock_irq(&ice->reg_lock);
  489. val = (8 - substream->runtime->channels) >> 1;
  490. outb(val, ICEMT1724(ice, BURST));
  491. outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
  492. size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
  493. // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
  494. outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
  495. outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
  496. size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
  497. // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
  498. outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
  499. outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
  500. spin_unlock_irq(&ice->reg_lock);
  501. // printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream));
  502. return 0;
  503. }
  504. static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
  505. {
  506. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  507. size_t ptr;
  508. if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
  509. return 0;
  510. #if 0 /* read PLAYBACK_ADDR */
  511. ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
  512. if (ptr < substream->runtime->dma_addr) {
  513. snd_printd("ice1724: invalid negative ptr\n");
  514. return 0;
  515. }
  516. ptr -= substream->runtime->dma_addr;
  517. ptr = bytes_to_frames(substream->runtime, ptr);
  518. if (ptr >= substream->runtime->buffer_size) {
  519. snd_printd("ice1724: invalid ptr %d (size=%d)\n",
  520. (int)ptr, (int)substream->runtime->period_size);
  521. return 0;
  522. }
  523. #else /* read PLAYBACK_SIZE */
  524. ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
  525. ptr = (ptr + 1) << 2;
  526. ptr = bytes_to_frames(substream->runtime, ptr);
  527. if (! ptr)
  528. ;
  529. else if (ptr <= substream->runtime->buffer_size)
  530. ptr = substream->runtime->buffer_size - ptr;
  531. else {
  532. snd_printd("ice1724: invalid ptr %d (size=%d)\n",
  533. (int)ptr, (int)substream->runtime->buffer_size);
  534. ptr = 0;
  535. }
  536. #endif
  537. return ptr;
  538. }
  539. static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
  540. {
  541. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  542. const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
  543. spin_lock_irq(&ice->reg_lock);
  544. outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
  545. outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
  546. ice->profi_port + reg->size);
  547. outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
  548. ice->profi_port + reg->count);
  549. spin_unlock_irq(&ice->reg_lock);
  550. return 0;
  551. }
  552. static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
  553. {
  554. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  555. const struct vt1724_pcm_reg *reg = substream->runtime->private_data;
  556. size_t ptr;
  557. if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
  558. return 0;
  559. #if 0 /* use ADDR register */
  560. ptr = inl(ice->profi_port + reg->addr);
  561. ptr -= substream->runtime->dma_addr;
  562. return bytes_to_frames(substream->runtime, ptr);
  563. #else /* use SIZE register */
  564. ptr = inw(ice->profi_port + reg->size);
  565. ptr = (ptr + 1) << 2;
  566. ptr = bytes_to_frames(substream->runtime, ptr);
  567. if (! ptr)
  568. ;
  569. else if (ptr <= substream->runtime->buffer_size)
  570. ptr = substream->runtime->buffer_size - ptr;
  571. else {
  572. snd_printd("ice1724: invalid ptr %d (size=%d)\n",
  573. (int)ptr, (int)substream->runtime->buffer_size);
  574. ptr = 0;
  575. }
  576. return ptr;
  577. #endif
  578. }
  579. static const struct vt1724_pcm_reg vt1724_playback_pro_reg = {
  580. .addr = VT1724_MT_PLAYBACK_ADDR,
  581. .size = VT1724_MT_PLAYBACK_SIZE,
  582. .count = VT1724_MT_PLAYBACK_COUNT,
  583. .start = VT1724_PDMA0_START,
  584. };
  585. static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
  586. .addr = VT1724_MT_CAPTURE_ADDR,
  587. .size = VT1724_MT_CAPTURE_SIZE,
  588. .count = VT1724_MT_CAPTURE_COUNT,
  589. .start = VT1724_RDMA0_START,
  590. };
  591. static const struct snd_pcm_hardware snd_vt1724_playback_pro =
  592. {
  593. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  594. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  595. SNDRV_PCM_INFO_MMAP_VALID |
  596. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  597. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  598. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
  599. .rate_min = 8000,
  600. .rate_max = 192000,
  601. .channels_min = 2,
  602. .channels_max = 8,
  603. .buffer_bytes_max = (1UL << 21), /* 19bits dword */
  604. .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
  605. .period_bytes_max = (1UL << 21),
  606. .periods_min = 2,
  607. .periods_max = 1024,
  608. };
  609. static const struct snd_pcm_hardware snd_vt1724_spdif =
  610. {
  611. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  612. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  613. SNDRV_PCM_INFO_MMAP_VALID |
  614. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  615. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  616. .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
  617. SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
  618. SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
  619. SNDRV_PCM_RATE_192000),
  620. .rate_min = 32000,
  621. .rate_max = 192000,
  622. .channels_min = 2,
  623. .channels_max = 2,
  624. .buffer_bytes_max = (1UL << 18), /* 16bits dword */
  625. .period_bytes_min = 2 * 4 * 2,
  626. .period_bytes_max = (1UL << 18),
  627. .periods_min = 2,
  628. .periods_max = 1024,
  629. };
  630. static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
  631. {
  632. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  633. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  634. SNDRV_PCM_INFO_MMAP_VALID |
  635. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  636. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  637. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
  638. .rate_min = 8000,
  639. .rate_max = 192000,
  640. .channels_min = 2,
  641. .channels_max = 2,
  642. .buffer_bytes_max = (1UL << 18), /* 16bits dword */
  643. .period_bytes_min = 2 * 4 * 2,
  644. .period_bytes_max = (1UL << 18),
  645. .periods_min = 2,
  646. .periods_max = 1024,
  647. };
  648. /*
  649. * set rate constraints
  650. */
  651. static int set_rate_constraints(struct snd_ice1712 *ice,
  652. struct snd_pcm_substream *substream)
  653. {
  654. struct snd_pcm_runtime *runtime = substream->runtime;
  655. if (ice->hw_rates) {
  656. /* hardware specific */
  657. runtime->hw.rate_min = ice->hw_rates->list[0];
  658. runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
  659. runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
  660. return snd_pcm_hw_constraint_list(runtime, 0,
  661. SNDRV_PCM_HW_PARAM_RATE,
  662. ice->hw_rates);
  663. }
  664. if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
  665. /* I2S */
  666. /* VT1720 doesn't support more than 96kHz */
  667. if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
  668. return snd_pcm_hw_constraint_list(runtime, 0,
  669. SNDRV_PCM_HW_PARAM_RATE,
  670. &hw_constraints_rates_192);
  671. else {
  672. runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
  673. SNDRV_PCM_RATE_8000_96000;
  674. runtime->hw.rate_max = 96000;
  675. return snd_pcm_hw_constraint_list(runtime, 0,
  676. SNDRV_PCM_HW_PARAM_RATE,
  677. &hw_constraints_rates_96);
  678. }
  679. } else if (ice->ac97) {
  680. /* ACLINK */
  681. runtime->hw.rate_max = 48000;
  682. runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
  683. return snd_pcm_hw_constraint_list(runtime, 0,
  684. SNDRV_PCM_HW_PARAM_RATE,
  685. &hw_constraints_rates_48);
  686. }
  687. return 0;
  688. }
  689. /* multi-channel playback needs alignment 8x32bit regardless of the channels
  690. * actually used
  691. */
  692. #define VT1724_BUFFER_ALIGN 0x20
  693. static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
  694. {
  695. struct snd_pcm_runtime *runtime = substream->runtime;
  696. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  697. int chs;
  698. runtime->private_data = (void *)&vt1724_playback_pro_reg;
  699. ice->playback_pro_substream = substream;
  700. runtime->hw = snd_vt1724_playback_pro;
  701. snd_pcm_set_sync(substream);
  702. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  703. set_rate_constraints(ice, substream);
  704. mutex_lock(&ice->open_mutex);
  705. /* calculate the currently available channels */
  706. for (chs = 0; chs < 3; chs++) {
  707. if (ice->pcm_reserved[chs])
  708. break;
  709. }
  710. chs = (chs + 1) * 2;
  711. runtime->hw.channels_max = chs;
  712. if (chs > 2) /* channels must be even */
  713. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  714. mutex_unlock(&ice->open_mutex);
  715. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  716. VT1724_BUFFER_ALIGN);
  717. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  718. VT1724_BUFFER_ALIGN);
  719. return 0;
  720. }
  721. static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
  722. {
  723. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  724. struct snd_pcm_runtime *runtime = substream->runtime;
  725. runtime->private_data = (void *)&vt1724_capture_pro_reg;
  726. ice->capture_pro_substream = substream;
  727. runtime->hw = snd_vt1724_2ch_stereo;
  728. snd_pcm_set_sync(substream);
  729. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  730. set_rate_constraints(ice, substream);
  731. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  732. VT1724_BUFFER_ALIGN);
  733. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  734. VT1724_BUFFER_ALIGN);
  735. return 0;
  736. }
  737. static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
  738. {
  739. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  740. if (PRO_RATE_RESET)
  741. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  742. ice->playback_pro_substream = NULL;
  743. return 0;
  744. }
  745. static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
  746. {
  747. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  748. if (PRO_RATE_RESET)
  749. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  750. ice->capture_pro_substream = NULL;
  751. return 0;
  752. }
  753. static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
  754. .open = snd_vt1724_playback_pro_open,
  755. .close = snd_vt1724_playback_pro_close,
  756. .ioctl = snd_pcm_lib_ioctl,
  757. .hw_params = snd_vt1724_pcm_hw_params,
  758. .hw_free = snd_vt1724_pcm_hw_free,
  759. .prepare = snd_vt1724_playback_pro_prepare,
  760. .trigger = snd_vt1724_pcm_trigger,
  761. .pointer = snd_vt1724_playback_pro_pointer,
  762. };
  763. static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
  764. .open = snd_vt1724_capture_pro_open,
  765. .close = snd_vt1724_capture_pro_close,
  766. .ioctl = snd_pcm_lib_ioctl,
  767. .hw_params = snd_vt1724_pcm_hw_params,
  768. .hw_free = snd_vt1724_pcm_hw_free,
  769. .prepare = snd_vt1724_pcm_prepare,
  770. .trigger = snd_vt1724_pcm_trigger,
  771. .pointer = snd_vt1724_pcm_pointer,
  772. };
  773. static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
  774. {
  775. struct snd_pcm *pcm;
  776. int err;
  777. err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
  778. if (err < 0)
  779. return err;
  780. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
  781. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
  782. pcm->private_data = ice;
  783. pcm->info_flags = 0;
  784. strcpy(pcm->name, "ICE1724");
  785. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  786. snd_dma_pci_data(ice->pci),
  787. 256*1024, 256*1024);
  788. ice->pcm_pro = pcm;
  789. return 0;
  790. }
  791. /*
  792. * SPDIF PCM
  793. */
  794. static const struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
  795. .addr = VT1724_MT_PDMA4_ADDR,
  796. .size = VT1724_MT_PDMA4_SIZE,
  797. .count = VT1724_MT_PDMA4_COUNT,
  798. .start = VT1724_PDMA4_START,
  799. };
  800. static const struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
  801. .addr = VT1724_MT_RDMA1_ADDR,
  802. .size = VT1724_MT_RDMA1_SIZE,
  803. .count = VT1724_MT_RDMA1_COUNT,
  804. .start = VT1724_RDMA1_START,
  805. };
  806. /* update spdif control bits; call with reg_lock */
  807. static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
  808. {
  809. unsigned char cbit, disabled;
  810. cbit = inb(ICEREG1724(ice, SPDIF_CFG));
  811. disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
  812. if (cbit != disabled)
  813. outb(disabled, ICEREG1724(ice, SPDIF_CFG));
  814. outw(val, ICEMT1724(ice, SPDIF_CTRL));
  815. if (cbit != disabled)
  816. outb(cbit, ICEREG1724(ice, SPDIF_CFG));
  817. outw(val, ICEMT1724(ice, SPDIF_CTRL));
  818. }
  819. /* update SPDIF control bits according to the given rate */
  820. static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
  821. {
  822. unsigned int val, nval;
  823. unsigned long flags;
  824. spin_lock_irqsave(&ice->reg_lock, flags);
  825. nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
  826. nval &= ~(7 << 12);
  827. switch (rate) {
  828. case 44100: break;
  829. case 48000: nval |= 2 << 12; break;
  830. case 32000: nval |= 3 << 12; break;
  831. case 88200: nval |= 4 << 12; break;
  832. case 96000: nval |= 5 << 12; break;
  833. case 192000: nval |= 6 << 12; break;
  834. case 176400: nval |= 7 << 12; break;
  835. }
  836. if (val != nval)
  837. update_spdif_bits(ice, nval);
  838. spin_unlock_irqrestore(&ice->reg_lock, flags);
  839. }
  840. static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
  841. {
  842. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  843. if (! ice->force_pdma4)
  844. update_spdif_rate(ice, substream->runtime->rate);
  845. return snd_vt1724_pcm_prepare(substream);
  846. }
  847. static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
  848. {
  849. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  850. struct snd_pcm_runtime *runtime = substream->runtime;
  851. runtime->private_data = (void *)&vt1724_playback_spdif_reg;
  852. ice->playback_con_substream = substream;
  853. if (ice->force_pdma4) {
  854. runtime->hw = snd_vt1724_2ch_stereo;
  855. set_rate_constraints(ice, substream);
  856. } else
  857. runtime->hw = snd_vt1724_spdif;
  858. snd_pcm_set_sync(substream);
  859. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  860. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  861. VT1724_BUFFER_ALIGN);
  862. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  863. VT1724_BUFFER_ALIGN);
  864. return 0;
  865. }
  866. static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
  867. {
  868. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  869. if (PRO_RATE_RESET)
  870. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  871. ice->playback_con_substream = NULL;
  872. return 0;
  873. }
  874. static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
  875. {
  876. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  877. struct snd_pcm_runtime *runtime = substream->runtime;
  878. runtime->private_data = (void *)&vt1724_capture_spdif_reg;
  879. ice->capture_con_substream = substream;
  880. if (ice->force_rdma1) {
  881. runtime->hw = snd_vt1724_2ch_stereo;
  882. set_rate_constraints(ice, substream);
  883. } else
  884. runtime->hw = snd_vt1724_spdif;
  885. snd_pcm_set_sync(substream);
  886. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  887. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  888. VT1724_BUFFER_ALIGN);
  889. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  890. VT1724_BUFFER_ALIGN);
  891. return 0;
  892. }
  893. static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
  894. {
  895. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  896. if (PRO_RATE_RESET)
  897. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  898. ice->capture_con_substream = NULL;
  899. return 0;
  900. }
  901. static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
  902. .open = snd_vt1724_playback_spdif_open,
  903. .close = snd_vt1724_playback_spdif_close,
  904. .ioctl = snd_pcm_lib_ioctl,
  905. .hw_params = snd_vt1724_pcm_hw_params,
  906. .hw_free = snd_vt1724_pcm_hw_free,
  907. .prepare = snd_vt1724_playback_spdif_prepare,
  908. .trigger = snd_vt1724_pcm_trigger,
  909. .pointer = snd_vt1724_pcm_pointer,
  910. };
  911. static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
  912. .open = snd_vt1724_capture_spdif_open,
  913. .close = snd_vt1724_capture_spdif_close,
  914. .ioctl = snd_pcm_lib_ioctl,
  915. .hw_params = snd_vt1724_pcm_hw_params,
  916. .hw_free = snd_vt1724_pcm_hw_free,
  917. .prepare = snd_vt1724_pcm_prepare,
  918. .trigger = snd_vt1724_pcm_trigger,
  919. .pointer = snd_vt1724_pcm_pointer,
  920. };
  921. static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
  922. {
  923. char *name;
  924. struct snd_pcm *pcm;
  925. int play, capt;
  926. int err;
  927. if (ice->force_pdma4 ||
  928. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
  929. play = 1;
  930. ice->has_spdif = 1;
  931. } else
  932. play = 0;
  933. if (ice->force_rdma1 ||
  934. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
  935. capt = 1;
  936. ice->has_spdif = 1;
  937. } else
  938. capt = 0;
  939. if (! play && ! capt)
  940. return 0; /* no spdif device */
  941. if (ice->force_pdma4 || ice->force_rdma1)
  942. name = "ICE1724 Secondary";
  943. else
  944. name = "IEC1724 IEC958";
  945. err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
  946. if (err < 0)
  947. return err;
  948. if (play)
  949. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  950. &snd_vt1724_playback_spdif_ops);
  951. if (capt)
  952. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  953. &snd_vt1724_capture_spdif_ops);
  954. pcm->private_data = ice;
  955. pcm->info_flags = 0;
  956. strcpy(pcm->name, name);
  957. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  958. snd_dma_pci_data(ice->pci),
  959. 64*1024, 64*1024);
  960. ice->pcm = pcm;
  961. return 0;
  962. }
  963. /*
  964. * independent surround PCMs
  965. */
  966. static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
  967. {
  968. .addr = VT1724_MT_PDMA1_ADDR,
  969. .size = VT1724_MT_PDMA1_SIZE,
  970. .count = VT1724_MT_PDMA1_COUNT,
  971. .start = VT1724_PDMA1_START,
  972. },
  973. {
  974. .addr = VT1724_MT_PDMA2_ADDR,
  975. .size = VT1724_MT_PDMA2_SIZE,
  976. .count = VT1724_MT_PDMA2_COUNT,
  977. .start = VT1724_PDMA2_START,
  978. },
  979. {
  980. .addr = VT1724_MT_PDMA3_ADDR,
  981. .size = VT1724_MT_PDMA3_SIZE,
  982. .count = VT1724_MT_PDMA3_COUNT,
  983. .start = VT1724_PDMA3_START,
  984. },
  985. };
  986. static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
  987. {
  988. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  989. unsigned char val;
  990. spin_lock_irq(&ice->reg_lock);
  991. val = 3 - substream->number;
  992. if (inb(ICEMT1724(ice, BURST)) < val)
  993. outb(val, ICEMT1724(ice, BURST));
  994. spin_unlock_irq(&ice->reg_lock);
  995. return snd_vt1724_pcm_prepare(substream);
  996. }
  997. static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
  998. {
  999. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1000. struct snd_pcm_runtime *runtime = substream->runtime;
  1001. mutex_lock(&ice->open_mutex);
  1002. /* already used by PDMA0? */
  1003. if (ice->pcm_reserved[substream->number]) {
  1004. mutex_unlock(&ice->open_mutex);
  1005. return -EBUSY; /* FIXME: should handle blocking mode properly */
  1006. }
  1007. mutex_unlock(&ice->open_mutex);
  1008. runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
  1009. ice->playback_con_substream_ds[substream->number] = substream;
  1010. runtime->hw = snd_vt1724_2ch_stereo;
  1011. snd_pcm_set_sync(substream);
  1012. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1013. set_rate_constraints(ice, substream);
  1014. return 0;
  1015. }
  1016. static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
  1017. {
  1018. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1019. if (PRO_RATE_RESET)
  1020. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  1021. ice->playback_con_substream_ds[substream->number] = NULL;
  1022. ice->pcm_reserved[substream->number] = NULL;
  1023. return 0;
  1024. }
  1025. static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
  1026. .open = snd_vt1724_playback_indep_open,
  1027. .close = snd_vt1724_playback_indep_close,
  1028. .ioctl = snd_pcm_lib_ioctl,
  1029. .hw_params = snd_vt1724_pcm_hw_params,
  1030. .hw_free = snd_vt1724_pcm_hw_free,
  1031. .prepare = snd_vt1724_playback_indep_prepare,
  1032. .trigger = snd_vt1724_pcm_trigger,
  1033. .pointer = snd_vt1724_pcm_pointer,
  1034. };
  1035. static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
  1036. {
  1037. struct snd_pcm *pcm;
  1038. int play;
  1039. int err;
  1040. play = ice->num_total_dacs / 2 - 1;
  1041. if (play <= 0)
  1042. return 0;
  1043. err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
  1044. if (err < 0)
  1045. return err;
  1046. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1047. &snd_vt1724_playback_indep_ops);
  1048. pcm->private_data = ice;
  1049. pcm->info_flags = 0;
  1050. strcpy(pcm->name, "ICE1724 Surround PCM");
  1051. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1052. snd_dma_pci_data(ice->pci),
  1053. 64*1024, 64*1024);
  1054. ice->pcm_ds = pcm;
  1055. return 0;
  1056. }
  1057. /*
  1058. * Mixer section
  1059. */
  1060. static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
  1061. {
  1062. int err;
  1063. if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
  1064. struct snd_ac97_bus *pbus;
  1065. struct snd_ac97_template ac97;
  1066. static struct snd_ac97_bus_ops ops = {
  1067. .write = snd_vt1724_ac97_write,
  1068. .read = snd_vt1724_ac97_read,
  1069. };
  1070. /* cold reset */
  1071. outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
  1072. mdelay(5); /* FIXME */
  1073. outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
  1074. if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
  1075. return err;
  1076. memset(&ac97, 0, sizeof(ac97));
  1077. ac97.private_data = ice;
  1078. if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
  1079. printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
  1080. else
  1081. return 0;
  1082. }
  1083. /* I2S mixer only */
  1084. strcat(ice->card->mixername, "ICE1724 - multitrack");
  1085. return 0;
  1086. }
  1087. /*
  1088. *
  1089. */
  1090. static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
  1091. {
  1092. return (unsigned int)ice->eeprom.data[idx] | \
  1093. ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
  1094. ((unsigned int)ice->eeprom.data[idx + 2] << 16);
  1095. }
  1096. static void snd_vt1724_proc_read(struct snd_info_entry *entry,
  1097. struct snd_info_buffer *buffer)
  1098. {
  1099. struct snd_ice1712 *ice = entry->private_data;
  1100. unsigned int idx;
  1101. snd_iprintf(buffer, "%s\n\n", ice->card->longname);
  1102. snd_iprintf(buffer, "EEPROM:\n");
  1103. snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
  1104. snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
  1105. snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
  1106. snd_iprintf(buffer, " System Config : 0x%x\n",
  1107. ice->eeprom.data[ICE_EEP2_SYSCONF]);
  1108. snd_iprintf(buffer, " ACLink : 0x%x\n",
  1109. ice->eeprom.data[ICE_EEP2_ACLINK]);
  1110. snd_iprintf(buffer, " I2S : 0x%x\n",
  1111. ice->eeprom.data[ICE_EEP2_I2S]);
  1112. snd_iprintf(buffer, " S/PDIF : 0x%x\n",
  1113. ice->eeprom.data[ICE_EEP2_SPDIF]);
  1114. snd_iprintf(buffer, " GPIO direction : 0x%x\n",
  1115. ice->eeprom.gpiodir);
  1116. snd_iprintf(buffer, " GPIO mask : 0x%x\n",
  1117. ice->eeprom.gpiomask);
  1118. snd_iprintf(buffer, " GPIO state : 0x%x\n",
  1119. ice->eeprom.gpiostate);
  1120. for (idx = 0x12; idx < ice->eeprom.size; idx++)
  1121. snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
  1122. idx, ice->eeprom.data[idx]);
  1123. snd_iprintf(buffer, "\nRegisters:\n");
  1124. snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
  1125. (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
  1126. for (idx = 0x0; idx < 0x20 ; idx++)
  1127. snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
  1128. idx, inb(ice->port+idx));
  1129. for (idx = 0x0; idx < 0x30 ; idx++)
  1130. snd_iprintf(buffer, " MT%02x : 0x%02x\n",
  1131. idx, inb(ice->profi_port+idx));
  1132. }
  1133. static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
  1134. {
  1135. struct snd_info_entry *entry;
  1136. if (! snd_card_proc_new(ice->card, "ice1724", &entry))
  1137. snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
  1138. }
  1139. /*
  1140. *
  1141. */
  1142. static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
  1143. struct snd_ctl_elem_info *uinfo)
  1144. {
  1145. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1146. uinfo->count = sizeof(struct snd_ice1712_eeprom);
  1147. return 0;
  1148. }
  1149. static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
  1150. struct snd_ctl_elem_value *ucontrol)
  1151. {
  1152. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1153. memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
  1154. return 0;
  1155. }
  1156. static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
  1157. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1158. .name = "ICE1724 EEPROM",
  1159. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1160. .info = snd_vt1724_eeprom_info,
  1161. .get = snd_vt1724_eeprom_get
  1162. };
  1163. /*
  1164. */
  1165. static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
  1166. struct snd_ctl_elem_info *uinfo)
  1167. {
  1168. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1169. uinfo->count = 1;
  1170. return 0;
  1171. }
  1172. static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
  1173. {
  1174. unsigned int val, rbits;
  1175. val = diga->status[0] & 0x03; /* professional, non-audio */
  1176. if (val & 0x01) {
  1177. /* professional */
  1178. if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
  1179. IEC958_AES0_PRO_EMPHASIS_5015)
  1180. val |= 1U << 3;
  1181. rbits = (diga->status[4] >> 3) & 0x0f;
  1182. if (rbits) {
  1183. switch (rbits) {
  1184. case 2: val |= 5 << 12; break; /* 96k */
  1185. case 3: val |= 6 << 12; break; /* 192k */
  1186. case 10: val |= 4 << 12; break; /* 88.2k */
  1187. case 11: val |= 7 << 12; break; /* 176.4k */
  1188. }
  1189. } else {
  1190. switch (diga->status[0] & IEC958_AES0_PRO_FS) {
  1191. case IEC958_AES0_PRO_FS_44100:
  1192. break;
  1193. case IEC958_AES0_PRO_FS_32000:
  1194. val |= 3U << 12;
  1195. break;
  1196. default:
  1197. val |= 2U << 12;
  1198. break;
  1199. }
  1200. }
  1201. } else {
  1202. /* consumer */
  1203. val |= diga->status[1] & 0x04; /* copyright */
  1204. if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
  1205. IEC958_AES0_CON_EMPHASIS_5015)
  1206. val |= 1U << 3;
  1207. val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
  1208. val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
  1209. }
  1210. return val;
  1211. }
  1212. static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
  1213. {
  1214. memset(diga->status, 0, sizeof(diga->status));
  1215. diga->status[0] = val & 0x03; /* professional, non-audio */
  1216. if (val & 0x01) {
  1217. /* professional */
  1218. if (val & (1U << 3))
  1219. diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
  1220. switch ((val >> 12) & 0x7) {
  1221. case 0:
  1222. break;
  1223. case 2:
  1224. diga->status[0] |= IEC958_AES0_PRO_FS_32000;
  1225. break;
  1226. default:
  1227. diga->status[0] |= IEC958_AES0_PRO_FS_48000;
  1228. break;
  1229. }
  1230. } else {
  1231. /* consumer */
  1232. diga->status[0] |= val & (1U << 2); /* copyright */
  1233. if (val & (1U << 3))
  1234. diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
  1235. diga->status[1] |= (val >> 4) & 0x3f; /* category */
  1236. diga->status[3] |= (val >> 12) & 0x07; /* fs */
  1237. }
  1238. }
  1239. static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
  1240. struct snd_ctl_elem_value *ucontrol)
  1241. {
  1242. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1243. unsigned int val;
  1244. val = inw(ICEMT1724(ice, SPDIF_CTRL));
  1245. decode_spdif_bits(&ucontrol->value.iec958, val);
  1246. return 0;
  1247. }
  1248. static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
  1249. struct snd_ctl_elem_value *ucontrol)
  1250. {
  1251. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1252. unsigned int val, old;
  1253. val = encode_spdif_bits(&ucontrol->value.iec958);
  1254. spin_lock_irq(&ice->reg_lock);
  1255. old = inw(ICEMT1724(ice, SPDIF_CTRL));
  1256. if (val != old)
  1257. update_spdif_bits(ice, val);
  1258. spin_unlock_irq(&ice->reg_lock);
  1259. return (val != old);
  1260. }
  1261. static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
  1262. {
  1263. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1264. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  1265. .info = snd_vt1724_spdif_info,
  1266. .get = snd_vt1724_spdif_default_get,
  1267. .put = snd_vt1724_spdif_default_put
  1268. };
  1269. static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
  1270. struct snd_ctl_elem_value *ucontrol)
  1271. {
  1272. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1273. IEC958_AES0_PROFESSIONAL |
  1274. IEC958_AES0_CON_NOT_COPYRIGHT |
  1275. IEC958_AES0_CON_EMPHASIS;
  1276. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
  1277. IEC958_AES1_CON_CATEGORY;
  1278. ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
  1279. return 0;
  1280. }
  1281. static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
  1282. struct snd_ctl_elem_value *ucontrol)
  1283. {
  1284. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1285. IEC958_AES0_PROFESSIONAL |
  1286. IEC958_AES0_PRO_FS |
  1287. IEC958_AES0_PRO_EMPHASIS;
  1288. return 0;
  1289. }
  1290. static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
  1291. {
  1292. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1293. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1294. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  1295. .info = snd_vt1724_spdif_info,
  1296. .get = snd_vt1724_spdif_maskc_get,
  1297. };
  1298. static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
  1299. {
  1300. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1301. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1302. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  1303. .info = snd_vt1724_spdif_info,
  1304. .get = snd_vt1724_spdif_maskp_get,
  1305. };
  1306. #define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
  1307. static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
  1308. struct snd_ctl_elem_value *ucontrol)
  1309. {
  1310. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1311. ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
  1312. VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
  1313. return 0;
  1314. }
  1315. static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
  1316. struct snd_ctl_elem_value *ucontrol)
  1317. {
  1318. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1319. unsigned char old, val;
  1320. spin_lock_irq(&ice->reg_lock);
  1321. old = val = inb(ICEREG1724(ice, SPDIF_CFG));
  1322. val &= ~VT1724_CFG_SPDIF_OUT_EN;
  1323. if (ucontrol->value.integer.value[0])
  1324. val |= VT1724_CFG_SPDIF_OUT_EN;
  1325. if (old != val)
  1326. outb(val, ICEREG1724(ice, SPDIF_CFG));
  1327. spin_unlock_irq(&ice->reg_lock);
  1328. return old != val;
  1329. }
  1330. static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
  1331. {
  1332. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1333. /* FIXME: the following conflict with IEC958 Playback Route */
  1334. // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
  1335. .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
  1336. .info = snd_vt1724_spdif_sw_info,
  1337. .get = snd_vt1724_spdif_sw_get,
  1338. .put = snd_vt1724_spdif_sw_put
  1339. };
  1340. #if 0 /* NOT USED YET */
  1341. /*
  1342. * GPIO access from extern
  1343. */
  1344. #define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
  1345. int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
  1346. struct snd_ctl_elem_value *ucontrol)
  1347. {
  1348. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1349. int shift = kcontrol->private_value & 0xff;
  1350. int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
  1351. snd_ice1712_save_gpio_status(ice);
  1352. ucontrol->value.integer.value[0] =
  1353. (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
  1354. snd_ice1712_restore_gpio_status(ice);
  1355. return 0;
  1356. }
  1357. int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
  1358. struct snd_ctl_elem_value *ucontrol)
  1359. {
  1360. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1361. int shift = kcontrol->private_value & 0xff;
  1362. int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
  1363. unsigned int val, nval;
  1364. if (kcontrol->private_value & (1 << 31))
  1365. return -EPERM;
  1366. nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
  1367. snd_ice1712_save_gpio_status(ice);
  1368. val = snd_ice1712_gpio_read(ice);
  1369. nval |= val & ~(1 << shift);
  1370. if (val != nval)
  1371. snd_ice1712_gpio_write(ice, nval);
  1372. snd_ice1712_restore_gpio_status(ice);
  1373. return val != nval;
  1374. }
  1375. #endif /* NOT USED YET */
  1376. /*
  1377. * rate
  1378. */
  1379. static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
  1380. struct snd_ctl_elem_info *uinfo)
  1381. {
  1382. static const char * const texts_1724[] = {
  1383. "8000", /* 0: 6 */
  1384. "9600", /* 1: 3 */
  1385. "11025", /* 2: 10 */
  1386. "12000", /* 3: 2 */
  1387. "16000", /* 4: 5 */
  1388. "22050", /* 5: 9 */
  1389. "24000", /* 6: 1 */
  1390. "32000", /* 7: 4 */
  1391. "44100", /* 8: 8 */
  1392. "48000", /* 9: 0 */
  1393. "64000", /* 10: 15 */
  1394. "88200", /* 11: 11 */
  1395. "96000", /* 12: 7 */
  1396. "176400", /* 13: 12 */
  1397. "192000", /* 14: 14 */
  1398. "IEC958 Input", /* 15: -- */
  1399. };
  1400. static const char * const texts_1720[] = {
  1401. "8000", /* 0: 6 */
  1402. "9600", /* 1: 3 */
  1403. "11025", /* 2: 10 */
  1404. "12000", /* 3: 2 */
  1405. "16000", /* 4: 5 */
  1406. "22050", /* 5: 9 */
  1407. "24000", /* 6: 1 */
  1408. "32000", /* 7: 4 */
  1409. "44100", /* 8: 8 */
  1410. "48000", /* 9: 0 */
  1411. "64000", /* 10: 15 */
  1412. "88200", /* 11: 11 */
  1413. "96000", /* 12: 7 */
  1414. "IEC958 Input", /* 13: -- */
  1415. };
  1416. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1417. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1418. uinfo->count = 1;
  1419. uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
  1420. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1421. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1422. strcpy(uinfo->value.enumerated.name,
  1423. ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
  1424. texts_1724[uinfo->value.enumerated.item]);
  1425. return 0;
  1426. }
  1427. static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
  1428. struct snd_ctl_elem_value *ucontrol)
  1429. {
  1430. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1431. static const unsigned char xlate[16] = {
  1432. 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
  1433. };
  1434. unsigned char val;
  1435. spin_lock_irq(&ice->reg_lock);
  1436. if (is_spdif_master(ice)) {
  1437. ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
  1438. } else {
  1439. val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
  1440. if (val == 255) {
  1441. snd_BUG();
  1442. val = 0;
  1443. }
  1444. ucontrol->value.enumerated.item[0] = val;
  1445. }
  1446. spin_unlock_irq(&ice->reg_lock);
  1447. return 0;
  1448. }
  1449. static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
  1450. struct snd_ctl_elem_value *ucontrol)
  1451. {
  1452. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1453. unsigned char oval;
  1454. int rate;
  1455. int change = 0;
  1456. int spdif = ice->vt1720 ? 13 : 15;
  1457. spin_lock_irq(&ice->reg_lock);
  1458. oval = inb(ICEMT1724(ice, RATE));
  1459. if (ucontrol->value.enumerated.item[0] == spdif) {
  1460. unsigned char i2s_oval;
  1461. outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
  1462. /* setting 256fs */
  1463. i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
  1464. outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X,
  1465. ICEMT1724(ice, I2S_FORMAT));
  1466. } else {
  1467. rate = rates[ucontrol->value.integer.value[0] % 15];
  1468. if (rate <= get_max_rate(ice)) {
  1469. PRO_RATE_DEFAULT = rate;
  1470. spin_unlock_irq(&ice->reg_lock);
  1471. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
  1472. spin_lock_irq(&ice->reg_lock);
  1473. }
  1474. }
  1475. change = inb(ICEMT1724(ice, RATE)) != oval;
  1476. spin_unlock_irq(&ice->reg_lock);
  1477. if ((oval & VT1724_SPDIF_MASTER) !=
  1478. (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
  1479. /* notify akm chips as well */
  1480. if (is_spdif_master(ice)) {
  1481. unsigned int i;
  1482. for (i = 0; i < ice->akm_codecs; i++) {
  1483. if (ice->akm[i].ops.set_rate_val)
  1484. ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
  1485. }
  1486. }
  1487. }
  1488. return change;
  1489. }
  1490. static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
  1491. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1492. .name = "Multi Track Internal Clock",
  1493. .info = snd_vt1724_pro_internal_clock_info,
  1494. .get = snd_vt1724_pro_internal_clock_get,
  1495. .put = snd_vt1724_pro_internal_clock_put
  1496. };
  1497. #define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
  1498. static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
  1499. struct snd_ctl_elem_value *ucontrol)
  1500. {
  1501. ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
  1502. return 0;
  1503. }
  1504. static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
  1505. struct snd_ctl_elem_value *ucontrol)
  1506. {
  1507. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1508. int change = 0, nval;
  1509. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1510. spin_lock_irq(&ice->reg_lock);
  1511. change = PRO_RATE_LOCKED != nval;
  1512. PRO_RATE_LOCKED = nval;
  1513. spin_unlock_irq(&ice->reg_lock);
  1514. return change;
  1515. }
  1516. static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
  1517. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1518. .name = "Multi Track Rate Locking",
  1519. .info = snd_vt1724_pro_rate_locking_info,
  1520. .get = snd_vt1724_pro_rate_locking_get,
  1521. .put = snd_vt1724_pro_rate_locking_put
  1522. };
  1523. #define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
  1524. static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
  1525. struct snd_ctl_elem_value *ucontrol)
  1526. {
  1527. ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
  1528. return 0;
  1529. }
  1530. static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
  1531. struct snd_ctl_elem_value *ucontrol)
  1532. {
  1533. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1534. int change = 0, nval;
  1535. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1536. spin_lock_irq(&ice->reg_lock);
  1537. change = PRO_RATE_RESET != nval;
  1538. PRO_RATE_RESET = nval;
  1539. spin_unlock_irq(&ice->reg_lock);
  1540. return change;
  1541. }
  1542. static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
  1543. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1544. .name = "Multi Track Rate Reset",
  1545. .info = snd_vt1724_pro_rate_reset_info,
  1546. .get = snd_vt1724_pro_rate_reset_get,
  1547. .put = snd_vt1724_pro_rate_reset_put
  1548. };
  1549. /*
  1550. * routing
  1551. */
  1552. static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
  1553. struct snd_ctl_elem_info *uinfo)
  1554. {
  1555. static char *texts[] = {
  1556. "PCM Out", /* 0 */
  1557. "H/W In 0", "H/W In 1", /* 1-2 */
  1558. "IEC958 In L", "IEC958 In R", /* 3-4 */
  1559. };
  1560. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1561. uinfo->count = 1;
  1562. uinfo->value.enumerated.items = 5;
  1563. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1564. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1565. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1566. return 0;
  1567. }
  1568. static inline int analog_route_shift(int idx)
  1569. {
  1570. return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
  1571. }
  1572. static inline int digital_route_shift(int idx)
  1573. {
  1574. return idx * 3;
  1575. }
  1576. static int get_route_val(struct snd_ice1712 *ice, int shift)
  1577. {
  1578. unsigned long val;
  1579. unsigned char eitem;
  1580. static const unsigned char xlate[8] = {
  1581. 0, 255, 1, 2, 255, 255, 3, 4,
  1582. };
  1583. val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  1584. val >>= shift;
  1585. val &= 7; //we now have 3 bits per output
  1586. eitem = xlate[val];
  1587. if (eitem == 255) {
  1588. snd_BUG();
  1589. return 0;
  1590. }
  1591. return eitem;
  1592. }
  1593. static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
  1594. {
  1595. unsigned int old_val, nval;
  1596. int change;
  1597. static const unsigned char xroute[8] = {
  1598. 0, /* PCM */
  1599. 2, /* PSDIN0 Left */
  1600. 3, /* PSDIN0 Right */
  1601. 6, /* SPDIN Left */
  1602. 7, /* SPDIN Right */
  1603. };
  1604. nval = xroute[val % 5];
  1605. val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  1606. val &= ~(0x07 << shift);
  1607. val |= nval << shift;
  1608. change = val != old_val;
  1609. if (change)
  1610. outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
  1611. return change;
  1612. }
  1613. static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
  1614. struct snd_ctl_elem_value *ucontrol)
  1615. {
  1616. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1617. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1618. ucontrol->value.enumerated.item[0] =
  1619. get_route_val(ice, analog_route_shift(idx));
  1620. return 0;
  1621. }
  1622. static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
  1623. struct snd_ctl_elem_value *ucontrol)
  1624. {
  1625. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1626. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1627. return put_route_val(ice, ucontrol->value.enumerated.item[0],
  1628. analog_route_shift(idx));
  1629. }
  1630. static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
  1631. struct snd_ctl_elem_value *ucontrol)
  1632. {
  1633. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1634. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1635. ucontrol->value.enumerated.item[0] =
  1636. get_route_val(ice, digital_route_shift(idx));
  1637. return 0;
  1638. }
  1639. static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
  1640. struct snd_ctl_elem_value *ucontrol)
  1641. {
  1642. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1643. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1644. return put_route_val(ice, ucontrol->value.enumerated.item[0],
  1645. digital_route_shift(idx));
  1646. }
  1647. static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
  1648. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1649. .name = "H/W Playback Route",
  1650. .info = snd_vt1724_pro_route_info,
  1651. .get = snd_vt1724_pro_route_analog_get,
  1652. .put = snd_vt1724_pro_route_analog_put,
  1653. };
  1654. static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
  1655. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1656. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
  1657. .info = snd_vt1724_pro_route_info,
  1658. .get = snd_vt1724_pro_route_spdif_get,
  1659. .put = snd_vt1724_pro_route_spdif_put,
  1660. .count = 2,
  1661. };
  1662. static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
  1663. struct snd_ctl_elem_info *uinfo)
  1664. {
  1665. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1666. uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
  1667. uinfo->value.integer.min = 0;
  1668. uinfo->value.integer.max = 255;
  1669. return 0;
  1670. }
  1671. static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
  1672. struct snd_ctl_elem_value *ucontrol)
  1673. {
  1674. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1675. int idx;
  1676. spin_lock_irq(&ice->reg_lock);
  1677. for (idx = 0; idx < 22; idx++) {
  1678. outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
  1679. ucontrol->value.integer.value[idx] =
  1680. inb(ICEMT1724(ice, MONITOR_PEAKDATA));
  1681. }
  1682. spin_unlock_irq(&ice->reg_lock);
  1683. return 0;
  1684. }
  1685. static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
  1686. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1687. .name = "Multi Track Peak",
  1688. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1689. .info = snd_vt1724_pro_peak_info,
  1690. .get = snd_vt1724_pro_peak_get
  1691. };
  1692. /*
  1693. *
  1694. */
  1695. static struct snd_ice1712_card_info no_matched __devinitdata;
  1696. static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
  1697. snd_vt1724_revo_cards,
  1698. snd_vt1724_amp_cards,
  1699. snd_vt1724_aureon_cards,
  1700. snd_vt1720_mobo_cards,
  1701. snd_vt1720_pontis_cards,
  1702. snd_vt1724_prodigy192_cards,
  1703. snd_vt1724_juli_cards,
  1704. snd_vt1724_phase_cards,
  1705. snd_vt1724_wtm_cards,
  1706. snd_vt1724_se_cards,
  1707. NULL,
  1708. };
  1709. /*
  1710. */
  1711. static void wait_i2c_busy(struct snd_ice1712 *ice)
  1712. {
  1713. int t = 0x10000;
  1714. while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
  1715. ;
  1716. if (t == -1)
  1717. printk(KERN_ERR "ice1724: i2c busy timeout\n");
  1718. }
  1719. unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
  1720. unsigned char dev, unsigned char addr)
  1721. {
  1722. unsigned char val;
  1723. mutex_lock(&ice->i2c_mutex);
  1724. wait_i2c_busy(ice);
  1725. outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
  1726. outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
  1727. wait_i2c_busy(ice);
  1728. val = inb(ICEREG1724(ice, I2C_DATA));
  1729. mutex_unlock(&ice->i2c_mutex);
  1730. //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
  1731. return val;
  1732. }
  1733. void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
  1734. unsigned char dev, unsigned char addr, unsigned char data)
  1735. {
  1736. mutex_lock(&ice->i2c_mutex);
  1737. wait_i2c_busy(ice);
  1738. //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
  1739. outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
  1740. outb(data, ICEREG1724(ice, I2C_DATA));
  1741. outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
  1742. wait_i2c_busy(ice);
  1743. mutex_unlock(&ice->i2c_mutex);
  1744. }
  1745. static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
  1746. const char *modelname)
  1747. {
  1748. const int dev = 0xa0; /* EEPROM device address */
  1749. unsigned int i, size;
  1750. struct snd_ice1712_card_info * const *tbl, *c;
  1751. if (! modelname || ! *modelname) {
  1752. ice->eeprom.subvendor = 0;
  1753. if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
  1754. ice->eeprom.subvendor =
  1755. (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
  1756. (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
  1757. (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
  1758. (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
  1759. if (ice->eeprom.subvendor == 0 ||
  1760. ice->eeprom.subvendor == (unsigned int)-1) {
  1761. /* invalid subvendor from EEPROM, try the PCI
  1762. * subststem ID instead
  1763. */
  1764. u16 vendor, device;
  1765. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
  1766. &vendor);
  1767. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
  1768. ice->eeprom.subvendor =
  1769. ((unsigned int)swab16(vendor) << 16) | swab16(device);
  1770. if (ice->eeprom.subvendor == 0 ||
  1771. ice->eeprom.subvendor == (unsigned int)-1) {
  1772. printk(KERN_ERR "ice1724: No valid ID is found\n");
  1773. return -ENXIO;
  1774. }
  1775. }
  1776. }
  1777. for (tbl = card_tables; *tbl; tbl++) {
  1778. for (c = *tbl; c->subvendor; c++) {
  1779. if (modelname && c->model &&
  1780. ! strcmp(modelname, c->model)) {
  1781. printk(KERN_INFO "ice1724: Using board model %s\n",
  1782. c->name);
  1783. ice->eeprom.subvendor = c->subvendor;
  1784. } else if (c->subvendor != ice->eeprom.subvendor)
  1785. continue;
  1786. if (! c->eeprom_size || ! c->eeprom_data)
  1787. goto found;
  1788. /* if the EEPROM is given by the driver, use it */
  1789. snd_printdd("using the defined eeprom..\n");
  1790. ice->eeprom.version = 2;
  1791. ice->eeprom.size = c->eeprom_size + 6;
  1792. memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
  1793. goto read_skipped;
  1794. }
  1795. }
  1796. printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
  1797. ice->eeprom.subvendor);
  1798. found:
  1799. ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
  1800. if (ice->eeprom.size < 6)
  1801. ice->eeprom.size = 32;
  1802. else if (ice->eeprom.size > 32) {
  1803. printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
  1804. ice->eeprom.size);
  1805. return -EIO;
  1806. }
  1807. ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
  1808. if (ice->eeprom.version != 2)
  1809. printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
  1810. ice->eeprom.version);
  1811. size = ice->eeprom.size - 6;
  1812. for (i = 0; i < size; i++)
  1813. ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
  1814. read_skipped:
  1815. ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
  1816. ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
  1817. ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
  1818. return 0;
  1819. }
  1820. static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
  1821. {
  1822. outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
  1823. udelay(200);
  1824. outb(0, ICEREG1724(ice, CONTROL));
  1825. udelay(200);
  1826. outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
  1827. outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
  1828. outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
  1829. outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
  1830. ice->gpio.write_mask = ice->eeprom.gpiomask;
  1831. ice->gpio.direction = ice->eeprom.gpiodir;
  1832. snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
  1833. snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
  1834. snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
  1835. outb(0, ICEREG1724(ice, POWERDOWN));
  1836. return 0;
  1837. }
  1838. static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
  1839. {
  1840. int err;
  1841. struct snd_kcontrol *kctl;
  1842. snd_assert(ice->pcm != NULL, return -EIO);
  1843. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
  1844. if (err < 0)
  1845. return err;
  1846. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
  1847. if (err < 0)
  1848. return err;
  1849. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
  1850. if (err < 0)
  1851. return err;
  1852. kctl->id.device = ice->pcm->device;
  1853. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
  1854. if (err < 0)
  1855. return err;
  1856. kctl->id.device = ice->pcm->device;
  1857. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
  1858. if (err < 0)
  1859. return err;
  1860. kctl->id.device = ice->pcm->device;
  1861. #if 0 /* use default only */
  1862. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
  1863. if (err < 0)
  1864. return err;
  1865. kctl->id.device = ice->pcm->device;
  1866. ice->spdif.stream_ctl = kctl;
  1867. #endif
  1868. return 0;
  1869. }
  1870. static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
  1871. {
  1872. int err;
  1873. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
  1874. if (err < 0)
  1875. return err;
  1876. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
  1877. if (err < 0)
  1878. return err;
  1879. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
  1880. if (err < 0)
  1881. return err;
  1882. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
  1883. if (err < 0)
  1884. return err;
  1885. if (ice->num_total_dacs > 0) {
  1886. struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
  1887. tmp.count = ice->num_total_dacs;
  1888. if (ice->vt1720 && tmp.count > 2)
  1889. tmp.count = 2;
  1890. err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
  1891. if (err < 0)
  1892. return err;
  1893. }
  1894. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
  1895. if (err < 0)
  1896. return err;
  1897. return 0;
  1898. }
  1899. static int snd_vt1724_free(struct snd_ice1712 *ice)
  1900. {
  1901. if (! ice->port)
  1902. goto __hw_end;
  1903. /* mask all interrupts */
  1904. outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
  1905. outb(0xff, ICEREG1724(ice, IRQMASK));
  1906. /* --- */
  1907. __hw_end:
  1908. if (ice->irq >= 0) {
  1909. synchronize_irq(ice->irq);
  1910. free_irq(ice->irq, ice);
  1911. }
  1912. pci_release_regions(ice->pci);
  1913. snd_ice1712_akm4xxx_free(ice);
  1914. pci_disable_device(ice->pci);
  1915. kfree(ice);
  1916. return 0;
  1917. }
  1918. static int snd_vt1724_dev_free(struct snd_device *device)
  1919. {
  1920. struct snd_ice1712 *ice = device->device_data;
  1921. return snd_vt1724_free(ice);
  1922. }
  1923. static int __devinit snd_vt1724_create(struct snd_card *card,
  1924. struct pci_dev *pci,
  1925. const char *modelname,
  1926. struct snd_ice1712 ** r_ice1712)
  1927. {
  1928. struct snd_ice1712 *ice;
  1929. int err;
  1930. unsigned char mask;
  1931. static struct snd_device_ops ops = {
  1932. .dev_free = snd_vt1724_dev_free,
  1933. };
  1934. *r_ice1712 = NULL;
  1935. /* enable PCI device */
  1936. if ((err = pci_enable_device(pci)) < 0)
  1937. return err;
  1938. ice = kzalloc(sizeof(*ice), GFP_KERNEL);
  1939. if (ice == NULL) {
  1940. pci_disable_device(pci);
  1941. return -ENOMEM;
  1942. }
  1943. ice->vt1724 = 1;
  1944. spin_lock_init(&ice->reg_lock);
  1945. mutex_init(&ice->gpio_mutex);
  1946. mutex_init(&ice->open_mutex);
  1947. mutex_init(&ice->i2c_mutex);
  1948. ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
  1949. ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
  1950. ice->gpio.set_data = snd_vt1724_set_gpio_data;
  1951. ice->gpio.get_data = snd_vt1724_get_gpio_data;
  1952. ice->card = card;
  1953. ice->pci = pci;
  1954. ice->irq = -1;
  1955. pci_set_master(pci);
  1956. snd_vt1724_proc_init(ice);
  1957. synchronize_irq(pci->irq);
  1958. if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
  1959. kfree(ice);
  1960. pci_disable_device(pci);
  1961. return err;
  1962. }
  1963. ice->port = pci_resource_start(pci, 0);
  1964. ice->profi_port = pci_resource_start(pci, 1);
  1965. if (request_irq(pci->irq, snd_vt1724_interrupt,
  1966. IRQF_SHARED, "ICE1724", ice)) {
  1967. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  1968. snd_vt1724_free(ice);
  1969. return -EIO;
  1970. }
  1971. ice->irq = pci->irq;
  1972. if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
  1973. snd_vt1724_free(ice);
  1974. return -EIO;
  1975. }
  1976. if (snd_vt1724_chip_init(ice) < 0) {
  1977. snd_vt1724_free(ice);
  1978. return -EIO;
  1979. }
  1980. /* unmask used interrupts */
  1981. if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
  1982. mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
  1983. else
  1984. mask = 0;
  1985. outb(mask, ICEREG1724(ice, IRQMASK));
  1986. /* don't handle FIFO overrun/underruns (just yet),
  1987. * since they cause machine lockups
  1988. */
  1989. outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
  1990. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
  1991. snd_vt1724_free(ice);
  1992. return err;
  1993. }
  1994. snd_card_set_dev(card, &pci->dev);
  1995. *r_ice1712 = ice;
  1996. return 0;
  1997. }
  1998. /*
  1999. *
  2000. * Registration
  2001. *
  2002. */
  2003. static int __devinit snd_vt1724_probe(struct pci_dev *pci,
  2004. const struct pci_device_id *pci_id)
  2005. {
  2006. static int dev;
  2007. struct snd_card *card;
  2008. struct snd_ice1712 *ice;
  2009. int pcm_dev = 0, err;
  2010. struct snd_ice1712_card_info * const *tbl, *c;
  2011. if (dev >= SNDRV_CARDS)
  2012. return -ENODEV;
  2013. if (!enable[dev]) {
  2014. dev++;
  2015. return -ENOENT;
  2016. }
  2017. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  2018. if (card == NULL)
  2019. return -ENOMEM;
  2020. strcpy(card->driver, "ICE1724");
  2021. strcpy(card->shortname, "ICEnsemble ICE1724");
  2022. if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
  2023. snd_card_free(card);
  2024. return err;
  2025. }
  2026. for (tbl = card_tables; *tbl; tbl++) {
  2027. for (c = *tbl; c->subvendor; c++) {
  2028. if (c->subvendor == ice->eeprom.subvendor) {
  2029. strcpy(card->shortname, c->name);
  2030. if (c->driver) /* specific driver? */
  2031. strcpy(card->driver, c->driver);
  2032. if (c->chip_init) {
  2033. if ((err = c->chip_init(ice)) < 0) {
  2034. snd_card_free(card);
  2035. return err;
  2036. }
  2037. }
  2038. goto __found;
  2039. }
  2040. }
  2041. }
  2042. c = &no_matched;
  2043. __found:
  2044. /*
  2045. * VT1724 has separate DMAs for the analog and the SPDIF streams while
  2046. * ICE1712 has only one for both (mixed up).
  2047. *
  2048. * Confusingly the analog PCM is named "professional" here because it
  2049. * was called so in ice1712 driver, and vt1724 driver is derived from
  2050. * ice1712 driver.
  2051. */
  2052. if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
  2053. snd_card_free(card);
  2054. return err;
  2055. }
  2056. if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
  2057. snd_card_free(card);
  2058. return err;
  2059. }
  2060. if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
  2061. snd_card_free(card);
  2062. return err;
  2063. }
  2064. if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
  2065. snd_card_free(card);
  2066. return err;
  2067. }
  2068. if ((err = snd_vt1724_build_controls(ice)) < 0) {
  2069. snd_card_free(card);
  2070. return err;
  2071. }
  2072. if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
  2073. if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
  2074. snd_card_free(card);
  2075. return err;
  2076. }
  2077. }
  2078. if (c->build_controls) {
  2079. if ((err = c->build_controls(ice)) < 0) {
  2080. snd_card_free(card);
  2081. return err;
  2082. }
  2083. }
  2084. if (! c->no_mpu401) {
  2085. if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
  2086. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
  2087. ICEREG1724(ice, MPU_CTRL),
  2088. MPU401_INFO_INTEGRATED,
  2089. ice->irq, 0,
  2090. &ice->rmidi[0])) < 0) {
  2091. snd_card_free(card);
  2092. return err;
  2093. }
  2094. }
  2095. }
  2096. sprintf(card->longname, "%s at 0x%lx, irq %i",
  2097. card->shortname, ice->port, ice->irq);
  2098. if ((err = snd_card_register(card)) < 0) {
  2099. snd_card_free(card);
  2100. return err;
  2101. }
  2102. pci_set_drvdata(pci, card);
  2103. dev++;
  2104. return 0;
  2105. }
  2106. static void __devexit snd_vt1724_remove(struct pci_dev *pci)
  2107. {
  2108. snd_card_free(pci_get_drvdata(pci));
  2109. pci_set_drvdata(pci, NULL);
  2110. }
  2111. static struct pci_driver driver = {
  2112. .name = "ICE1724",
  2113. .id_table = snd_vt1724_ids,
  2114. .probe = snd_vt1724_probe,
  2115. .remove = __devexit_p(snd_vt1724_remove),
  2116. };
  2117. static int __init alsa_card_ice1724_init(void)
  2118. {
  2119. return pci_register_driver(&driver);
  2120. }
  2121. static void __exit alsa_card_ice1724_exit(void)
  2122. {
  2123. pci_unregister_driver(&driver);
  2124. }
  2125. module_init(alsa_card_ice1724_init)
  2126. module_exit(alsa_card_ice1724_exit)