ice1724.c 72 KB

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