ice1724.c 78 KB

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