ice1724.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899
  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. /* if the card has the internal rate locked (is_pro_locked), limit runtime
  898. hw rates to the current internal rate only.
  899. */
  900. static void constrain_rate_if_locked(struct snd_pcm_substream *substream)
  901. {
  902. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  903. struct snd_pcm_runtime *runtime = substream->runtime;
  904. unsigned int rate;
  905. if (is_pro_rate_locked(ice)) {
  906. rate = ice->get_rate(ice);
  907. if (rate >= runtime->hw.rate_min
  908. && rate <= runtime->hw.rate_max) {
  909. runtime->hw.rate_min = rate;
  910. runtime->hw.rate_max = rate;
  911. }
  912. }
  913. }
  914. /* multi-channel playback needs alignment 8x32bit regardless of the channels
  915. * actually used
  916. */
  917. #define VT1724_BUFFER_ALIGN 0x20
  918. static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
  919. {
  920. struct snd_pcm_runtime *runtime = substream->runtime;
  921. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  922. int chs, num_indeps;
  923. runtime->private_data = (void *)&vt1724_playback_pro_reg;
  924. ice->playback_pro_substream = substream;
  925. runtime->hw = snd_vt1724_playback_pro;
  926. snd_pcm_set_sync(substream);
  927. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  928. set_rate_constraints(ice, substream);
  929. mutex_lock(&ice->open_mutex);
  930. /* calculate the currently available channels */
  931. num_indeps = ice->num_total_dacs / 2 - 1;
  932. for (chs = 0; chs < num_indeps; chs++) {
  933. if (ice->pcm_reserved[chs])
  934. break;
  935. }
  936. chs = (chs + 1) * 2;
  937. runtime->hw.channels_max = chs;
  938. if (chs > 2) /* channels must be even */
  939. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  940. mutex_unlock(&ice->open_mutex);
  941. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  942. VT1724_BUFFER_ALIGN);
  943. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  944. VT1724_BUFFER_ALIGN);
  945. constrain_rate_if_locked(substream);
  946. if (ice->pro_open)
  947. ice->pro_open(ice, substream);
  948. return 0;
  949. }
  950. static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
  951. {
  952. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  953. struct snd_pcm_runtime *runtime = substream->runtime;
  954. runtime->private_data = (void *)&vt1724_capture_pro_reg;
  955. ice->capture_pro_substream = substream;
  956. runtime->hw = snd_vt1724_2ch_stereo;
  957. snd_pcm_set_sync(substream);
  958. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  959. set_rate_constraints(ice, substream);
  960. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  961. VT1724_BUFFER_ALIGN);
  962. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  963. VT1724_BUFFER_ALIGN);
  964. constrain_rate_if_locked(substream);
  965. if (ice->pro_open)
  966. ice->pro_open(ice, substream);
  967. return 0;
  968. }
  969. static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
  970. {
  971. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  972. if (PRO_RATE_RESET)
  973. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
  974. ice->playback_pro_substream = NULL;
  975. return 0;
  976. }
  977. static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
  978. {
  979. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  980. if (PRO_RATE_RESET)
  981. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
  982. ice->capture_pro_substream = NULL;
  983. return 0;
  984. }
  985. static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
  986. .open = snd_vt1724_playback_pro_open,
  987. .close = snd_vt1724_playback_pro_close,
  988. .ioctl = snd_pcm_lib_ioctl,
  989. .hw_params = snd_vt1724_pcm_hw_params,
  990. .hw_free = snd_vt1724_pcm_hw_free,
  991. .prepare = snd_vt1724_playback_pro_prepare,
  992. .trigger = snd_vt1724_pcm_trigger,
  993. .pointer = snd_vt1724_playback_pro_pointer,
  994. };
  995. static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
  996. .open = snd_vt1724_capture_pro_open,
  997. .close = snd_vt1724_capture_pro_close,
  998. .ioctl = snd_pcm_lib_ioctl,
  999. .hw_params = snd_vt1724_pcm_hw_params,
  1000. .hw_free = snd_vt1724_pcm_hw_free,
  1001. .prepare = snd_vt1724_pcm_prepare,
  1002. .trigger = snd_vt1724_pcm_trigger,
  1003. .pointer = snd_vt1724_pcm_pointer,
  1004. };
  1005. static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 *ice, int device)
  1006. {
  1007. struct snd_pcm *pcm;
  1008. int capt, err;
  1009. if ((ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_ADC_MASK) ==
  1010. VT1724_CFG_ADC_NONE)
  1011. capt = 0;
  1012. else
  1013. capt = 1;
  1014. err = snd_pcm_new(ice->card, "ICE1724", device, 1, capt, &pcm);
  1015. if (err < 0)
  1016. return err;
  1017. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
  1018. if (capt)
  1019. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  1020. &snd_vt1724_capture_pro_ops);
  1021. pcm->private_data = ice;
  1022. pcm->info_flags = 0;
  1023. strcpy(pcm->name, "ICE1724");
  1024. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1025. snd_dma_pci_data(ice->pci),
  1026. 256*1024, 256*1024);
  1027. ice->pcm_pro = pcm;
  1028. return 0;
  1029. }
  1030. /*
  1031. * SPDIF PCM
  1032. */
  1033. /* update spdif control bits; call with reg_lock */
  1034. static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
  1035. {
  1036. unsigned char cbit, disabled;
  1037. cbit = inb(ICEREG1724(ice, SPDIF_CFG));
  1038. disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
  1039. if (cbit != disabled)
  1040. outb(disabled, ICEREG1724(ice, SPDIF_CFG));
  1041. outw(val, ICEMT1724(ice, SPDIF_CTRL));
  1042. if (cbit != disabled)
  1043. outb(cbit, ICEREG1724(ice, SPDIF_CFG));
  1044. outw(val, ICEMT1724(ice, SPDIF_CTRL));
  1045. }
  1046. /* update SPDIF control bits according to the given rate */
  1047. static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
  1048. {
  1049. unsigned int val, nval;
  1050. unsigned long flags;
  1051. spin_lock_irqsave(&ice->reg_lock, flags);
  1052. nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
  1053. nval &= ~(7 << 12);
  1054. switch (rate) {
  1055. case 44100: break;
  1056. case 48000: nval |= 2 << 12; break;
  1057. case 32000: nval |= 3 << 12; break;
  1058. case 88200: nval |= 4 << 12; break;
  1059. case 96000: nval |= 5 << 12; break;
  1060. case 192000: nval |= 6 << 12; break;
  1061. case 176400: nval |= 7 << 12; break;
  1062. }
  1063. if (val != nval)
  1064. update_spdif_bits(ice, nval);
  1065. spin_unlock_irqrestore(&ice->reg_lock, flags);
  1066. }
  1067. static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
  1068. {
  1069. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1070. if (!ice->force_pdma4)
  1071. update_spdif_rate(ice, substream->runtime->rate);
  1072. return snd_vt1724_pcm_prepare(substream);
  1073. }
  1074. static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
  1075. {
  1076. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1077. struct snd_pcm_runtime *runtime = substream->runtime;
  1078. runtime->private_data = (void *)&vt1724_playback_spdif_reg;
  1079. ice->playback_con_substream = substream;
  1080. if (ice->force_pdma4) {
  1081. runtime->hw = snd_vt1724_2ch_stereo;
  1082. set_rate_constraints(ice, substream);
  1083. } else
  1084. runtime->hw = snd_vt1724_spdif;
  1085. snd_pcm_set_sync(substream);
  1086. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1087. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1088. VT1724_BUFFER_ALIGN);
  1089. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1090. VT1724_BUFFER_ALIGN);
  1091. constrain_rate_if_locked(substream);
  1092. if (ice->spdif.ops.open)
  1093. ice->spdif.ops.open(ice, substream);
  1094. return 0;
  1095. }
  1096. static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
  1097. {
  1098. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1099. if (PRO_RATE_RESET)
  1100. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
  1101. ice->playback_con_substream = NULL;
  1102. if (ice->spdif.ops.close)
  1103. ice->spdif.ops.close(ice, substream);
  1104. return 0;
  1105. }
  1106. static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
  1107. {
  1108. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1109. struct snd_pcm_runtime *runtime = substream->runtime;
  1110. runtime->private_data = (void *)&vt1724_capture_spdif_reg;
  1111. ice->capture_con_substream = substream;
  1112. if (ice->force_rdma1) {
  1113. runtime->hw = snd_vt1724_2ch_stereo;
  1114. set_rate_constraints(ice, substream);
  1115. } else
  1116. runtime->hw = snd_vt1724_spdif;
  1117. snd_pcm_set_sync(substream);
  1118. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1119. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1120. VT1724_BUFFER_ALIGN);
  1121. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1122. VT1724_BUFFER_ALIGN);
  1123. constrain_rate_if_locked(substream);
  1124. if (ice->spdif.ops.open)
  1125. ice->spdif.ops.open(ice, substream);
  1126. return 0;
  1127. }
  1128. static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
  1129. {
  1130. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1131. if (PRO_RATE_RESET)
  1132. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
  1133. ice->capture_con_substream = NULL;
  1134. if (ice->spdif.ops.close)
  1135. ice->spdif.ops.close(ice, substream);
  1136. return 0;
  1137. }
  1138. static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
  1139. .open = snd_vt1724_playback_spdif_open,
  1140. .close = snd_vt1724_playback_spdif_close,
  1141. .ioctl = snd_pcm_lib_ioctl,
  1142. .hw_params = snd_vt1724_pcm_hw_params,
  1143. .hw_free = snd_vt1724_pcm_hw_free,
  1144. .prepare = snd_vt1724_playback_spdif_prepare,
  1145. .trigger = snd_vt1724_pcm_trigger,
  1146. .pointer = snd_vt1724_pcm_pointer,
  1147. };
  1148. static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
  1149. .open = snd_vt1724_capture_spdif_open,
  1150. .close = snd_vt1724_capture_spdif_close,
  1151. .ioctl = snd_pcm_lib_ioctl,
  1152. .hw_params = snd_vt1724_pcm_hw_params,
  1153. .hw_free = snd_vt1724_pcm_hw_free,
  1154. .prepare = snd_vt1724_pcm_prepare,
  1155. .trigger = snd_vt1724_pcm_trigger,
  1156. .pointer = snd_vt1724_pcm_pointer,
  1157. };
  1158. static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 *ice, int device)
  1159. {
  1160. char *name;
  1161. struct snd_pcm *pcm;
  1162. int play, capt;
  1163. int err;
  1164. if (ice->force_pdma4 ||
  1165. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
  1166. play = 1;
  1167. ice->has_spdif = 1;
  1168. } else
  1169. play = 0;
  1170. if (ice->force_rdma1 ||
  1171. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
  1172. capt = 1;
  1173. ice->has_spdif = 1;
  1174. } else
  1175. capt = 0;
  1176. if (!play && !capt)
  1177. return 0; /* no spdif device */
  1178. if (ice->force_pdma4 || ice->force_rdma1)
  1179. name = "ICE1724 Secondary";
  1180. else
  1181. name = "ICE1724 IEC958";
  1182. err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
  1183. if (err < 0)
  1184. return err;
  1185. if (play)
  1186. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1187. &snd_vt1724_playback_spdif_ops);
  1188. if (capt)
  1189. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  1190. &snd_vt1724_capture_spdif_ops);
  1191. pcm->private_data = ice;
  1192. pcm->info_flags = 0;
  1193. strcpy(pcm->name, name);
  1194. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1195. snd_dma_pci_data(ice->pci),
  1196. 256*1024, 256*1024);
  1197. ice->pcm = pcm;
  1198. return 0;
  1199. }
  1200. /*
  1201. * independent surround PCMs
  1202. */
  1203. static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
  1204. {
  1205. .addr = VT1724_MT_PDMA1_ADDR,
  1206. .size = VT1724_MT_PDMA1_SIZE,
  1207. .count = VT1724_MT_PDMA1_COUNT,
  1208. .start = VT1724_PDMA1_START,
  1209. },
  1210. {
  1211. .addr = VT1724_MT_PDMA2_ADDR,
  1212. .size = VT1724_MT_PDMA2_SIZE,
  1213. .count = VT1724_MT_PDMA2_COUNT,
  1214. .start = VT1724_PDMA2_START,
  1215. },
  1216. {
  1217. .addr = VT1724_MT_PDMA3_ADDR,
  1218. .size = VT1724_MT_PDMA3_SIZE,
  1219. .count = VT1724_MT_PDMA3_COUNT,
  1220. .start = VT1724_PDMA3_START,
  1221. },
  1222. };
  1223. static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
  1224. {
  1225. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1226. unsigned char val;
  1227. spin_lock_irq(&ice->reg_lock);
  1228. val = 3 - substream->number;
  1229. if (inb(ICEMT1724(ice, BURST)) < val)
  1230. outb(val, ICEMT1724(ice, BURST));
  1231. spin_unlock_irq(&ice->reg_lock);
  1232. return snd_vt1724_pcm_prepare(substream);
  1233. }
  1234. static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
  1235. {
  1236. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1237. struct snd_pcm_runtime *runtime = substream->runtime;
  1238. mutex_lock(&ice->open_mutex);
  1239. /* already used by PDMA0? */
  1240. if (ice->pcm_reserved[substream->number]) {
  1241. mutex_unlock(&ice->open_mutex);
  1242. return -EBUSY; /* FIXME: should handle blocking mode properly */
  1243. }
  1244. mutex_unlock(&ice->open_mutex);
  1245. runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number];
  1246. ice->playback_con_substream_ds[substream->number] = substream;
  1247. runtime->hw = snd_vt1724_2ch_stereo;
  1248. snd_pcm_set_sync(substream);
  1249. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1250. set_rate_constraints(ice, substream);
  1251. return 0;
  1252. }
  1253. static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
  1254. {
  1255. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1256. if (PRO_RATE_RESET)
  1257. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
  1258. ice->playback_con_substream_ds[substream->number] = NULL;
  1259. ice->pcm_reserved[substream->number] = NULL;
  1260. return 0;
  1261. }
  1262. static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
  1263. .open = snd_vt1724_playback_indep_open,
  1264. .close = snd_vt1724_playback_indep_close,
  1265. .ioctl = snd_pcm_lib_ioctl,
  1266. .hw_params = snd_vt1724_pcm_hw_params,
  1267. .hw_free = snd_vt1724_pcm_hw_free,
  1268. .prepare = snd_vt1724_playback_indep_prepare,
  1269. .trigger = snd_vt1724_pcm_trigger,
  1270. .pointer = snd_vt1724_pcm_pointer,
  1271. };
  1272. static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 *ice, int device)
  1273. {
  1274. struct snd_pcm *pcm;
  1275. int play;
  1276. int err;
  1277. play = ice->num_total_dacs / 2 - 1;
  1278. if (play <= 0)
  1279. return 0;
  1280. err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
  1281. if (err < 0)
  1282. return err;
  1283. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1284. &snd_vt1724_playback_indep_ops);
  1285. pcm->private_data = ice;
  1286. pcm->info_flags = 0;
  1287. strcpy(pcm->name, "ICE1724 Surround PCM");
  1288. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1289. snd_dma_pci_data(ice->pci),
  1290. 256*1024, 256*1024);
  1291. ice->pcm_ds = pcm;
  1292. return 0;
  1293. }
  1294. /*
  1295. * Mixer section
  1296. */
  1297. static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 *ice)
  1298. {
  1299. int err;
  1300. if (!(ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
  1301. struct snd_ac97_bus *pbus;
  1302. struct snd_ac97_template ac97;
  1303. static struct snd_ac97_bus_ops ops = {
  1304. .write = snd_vt1724_ac97_write,
  1305. .read = snd_vt1724_ac97_read,
  1306. };
  1307. /* cold reset */
  1308. outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
  1309. mdelay(5); /* FIXME */
  1310. outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
  1311. err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus);
  1312. if (err < 0)
  1313. return err;
  1314. memset(&ac97, 0, sizeof(ac97));
  1315. ac97.private_data = ice;
  1316. err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
  1317. if (err < 0)
  1318. printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
  1319. else
  1320. return 0;
  1321. }
  1322. /* I2S mixer only */
  1323. strcat(ice->card->mixername, "ICE1724 - multitrack");
  1324. return 0;
  1325. }
  1326. /*
  1327. *
  1328. */
  1329. static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
  1330. {
  1331. return (unsigned int)ice->eeprom.data[idx] | \
  1332. ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
  1333. ((unsigned int)ice->eeprom.data[idx + 2] << 16);
  1334. }
  1335. static void snd_vt1724_proc_read(struct snd_info_entry *entry,
  1336. struct snd_info_buffer *buffer)
  1337. {
  1338. struct snd_ice1712 *ice = entry->private_data;
  1339. unsigned int idx;
  1340. snd_iprintf(buffer, "%s\n\n", ice->card->longname);
  1341. snd_iprintf(buffer, "EEPROM:\n");
  1342. snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
  1343. snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
  1344. snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
  1345. snd_iprintf(buffer, " System Config : 0x%x\n",
  1346. ice->eeprom.data[ICE_EEP2_SYSCONF]);
  1347. snd_iprintf(buffer, " ACLink : 0x%x\n",
  1348. ice->eeprom.data[ICE_EEP2_ACLINK]);
  1349. snd_iprintf(buffer, " I2S : 0x%x\n",
  1350. ice->eeprom.data[ICE_EEP2_I2S]);
  1351. snd_iprintf(buffer, " S/PDIF : 0x%x\n",
  1352. ice->eeprom.data[ICE_EEP2_SPDIF]);
  1353. snd_iprintf(buffer, " GPIO direction : 0x%x\n",
  1354. ice->eeprom.gpiodir);
  1355. snd_iprintf(buffer, " GPIO mask : 0x%x\n",
  1356. ice->eeprom.gpiomask);
  1357. snd_iprintf(buffer, " GPIO state : 0x%x\n",
  1358. ice->eeprom.gpiostate);
  1359. for (idx = 0x12; idx < ice->eeprom.size; idx++)
  1360. snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
  1361. idx, ice->eeprom.data[idx]);
  1362. snd_iprintf(buffer, "\nRegisters:\n");
  1363. snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
  1364. (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
  1365. for (idx = 0x0; idx < 0x20 ; idx++)
  1366. snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
  1367. idx, inb(ice->port+idx));
  1368. for (idx = 0x0; idx < 0x30 ; idx++)
  1369. snd_iprintf(buffer, " MT%02x : 0x%02x\n",
  1370. idx, inb(ice->profi_port+idx));
  1371. }
  1372. static void __devinit snd_vt1724_proc_init(struct snd_ice1712 *ice)
  1373. {
  1374. struct snd_info_entry *entry;
  1375. if (!snd_card_proc_new(ice->card, "ice1724", &entry))
  1376. snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
  1377. }
  1378. /*
  1379. *
  1380. */
  1381. static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
  1382. struct snd_ctl_elem_info *uinfo)
  1383. {
  1384. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1385. uinfo->count = sizeof(struct snd_ice1712_eeprom);
  1386. return 0;
  1387. }
  1388. static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
  1389. struct snd_ctl_elem_value *ucontrol)
  1390. {
  1391. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1392. memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
  1393. return 0;
  1394. }
  1395. static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
  1396. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1397. .name = "ICE1724 EEPROM",
  1398. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1399. .info = snd_vt1724_eeprom_info,
  1400. .get = snd_vt1724_eeprom_get
  1401. };
  1402. /*
  1403. */
  1404. static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
  1405. struct snd_ctl_elem_info *uinfo)
  1406. {
  1407. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1408. uinfo->count = 1;
  1409. return 0;
  1410. }
  1411. static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
  1412. {
  1413. unsigned int val, rbits;
  1414. val = diga->status[0] & 0x03; /* professional, non-audio */
  1415. if (val & 0x01) {
  1416. /* professional */
  1417. if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
  1418. IEC958_AES0_PRO_EMPHASIS_5015)
  1419. val |= 1U << 3;
  1420. rbits = (diga->status[4] >> 3) & 0x0f;
  1421. if (rbits) {
  1422. switch (rbits) {
  1423. case 2: val |= 5 << 12; break; /* 96k */
  1424. case 3: val |= 6 << 12; break; /* 192k */
  1425. case 10: val |= 4 << 12; break; /* 88.2k */
  1426. case 11: val |= 7 << 12; break; /* 176.4k */
  1427. }
  1428. } else {
  1429. switch (diga->status[0] & IEC958_AES0_PRO_FS) {
  1430. case IEC958_AES0_PRO_FS_44100:
  1431. break;
  1432. case IEC958_AES0_PRO_FS_32000:
  1433. val |= 3U << 12;
  1434. break;
  1435. default:
  1436. val |= 2U << 12;
  1437. break;
  1438. }
  1439. }
  1440. } else {
  1441. /* consumer */
  1442. val |= diga->status[1] & 0x04; /* copyright */
  1443. if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
  1444. IEC958_AES0_CON_EMPHASIS_5015)
  1445. val |= 1U << 3;
  1446. val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
  1447. val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
  1448. }
  1449. return val;
  1450. }
  1451. static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
  1452. {
  1453. memset(diga->status, 0, sizeof(diga->status));
  1454. diga->status[0] = val & 0x03; /* professional, non-audio */
  1455. if (val & 0x01) {
  1456. /* professional */
  1457. if (val & (1U << 3))
  1458. diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
  1459. switch ((val >> 12) & 0x7) {
  1460. case 0:
  1461. break;
  1462. case 2:
  1463. diga->status[0] |= IEC958_AES0_PRO_FS_32000;
  1464. break;
  1465. default:
  1466. diga->status[0] |= IEC958_AES0_PRO_FS_48000;
  1467. break;
  1468. }
  1469. } else {
  1470. /* consumer */
  1471. diga->status[0] |= val & (1U << 2); /* copyright */
  1472. if (val & (1U << 3))
  1473. diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
  1474. diga->status[1] |= (val >> 4) & 0x3f; /* category */
  1475. diga->status[3] |= (val >> 12) & 0x07; /* fs */
  1476. }
  1477. }
  1478. static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
  1479. struct snd_ctl_elem_value *ucontrol)
  1480. {
  1481. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1482. unsigned int val;
  1483. val = inw(ICEMT1724(ice, SPDIF_CTRL));
  1484. decode_spdif_bits(&ucontrol->value.iec958, val);
  1485. return 0;
  1486. }
  1487. static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
  1488. struct snd_ctl_elem_value *ucontrol)
  1489. {
  1490. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1491. unsigned int val, old;
  1492. val = encode_spdif_bits(&ucontrol->value.iec958);
  1493. spin_lock_irq(&ice->reg_lock);
  1494. old = inw(ICEMT1724(ice, SPDIF_CTRL));
  1495. if (val != old)
  1496. update_spdif_bits(ice, val);
  1497. spin_unlock_irq(&ice->reg_lock);
  1498. return val != old;
  1499. }
  1500. static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
  1501. {
  1502. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1503. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  1504. .info = snd_vt1724_spdif_info,
  1505. .get = snd_vt1724_spdif_default_get,
  1506. .put = snd_vt1724_spdif_default_put
  1507. };
  1508. static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
  1509. struct snd_ctl_elem_value *ucontrol)
  1510. {
  1511. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1512. IEC958_AES0_PROFESSIONAL |
  1513. IEC958_AES0_CON_NOT_COPYRIGHT |
  1514. IEC958_AES0_CON_EMPHASIS;
  1515. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
  1516. IEC958_AES1_CON_CATEGORY;
  1517. ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
  1518. return 0;
  1519. }
  1520. static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
  1521. struct snd_ctl_elem_value *ucontrol)
  1522. {
  1523. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1524. IEC958_AES0_PROFESSIONAL |
  1525. IEC958_AES0_PRO_FS |
  1526. IEC958_AES0_PRO_EMPHASIS;
  1527. return 0;
  1528. }
  1529. static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
  1530. {
  1531. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1532. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1533. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  1534. .info = snd_vt1724_spdif_info,
  1535. .get = snd_vt1724_spdif_maskc_get,
  1536. };
  1537. static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
  1538. {
  1539. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1540. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1541. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
  1542. .info = snd_vt1724_spdif_info,
  1543. .get = snd_vt1724_spdif_maskp_get,
  1544. };
  1545. #define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info
  1546. static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
  1547. struct snd_ctl_elem_value *ucontrol)
  1548. {
  1549. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1550. ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
  1551. VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
  1552. return 0;
  1553. }
  1554. static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
  1555. struct snd_ctl_elem_value *ucontrol)
  1556. {
  1557. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1558. unsigned char old, val;
  1559. spin_lock_irq(&ice->reg_lock);
  1560. old = val = inb(ICEREG1724(ice, SPDIF_CFG));
  1561. val &= ~VT1724_CFG_SPDIF_OUT_EN;
  1562. if (ucontrol->value.integer.value[0])
  1563. val |= VT1724_CFG_SPDIF_OUT_EN;
  1564. if (old != val)
  1565. outb(val, ICEREG1724(ice, SPDIF_CFG));
  1566. spin_unlock_irq(&ice->reg_lock);
  1567. return old != val;
  1568. }
  1569. static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
  1570. {
  1571. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1572. /* FIXME: the following conflict with IEC958 Playback Route */
  1573. /* .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), */
  1574. .name = SNDRV_CTL_NAME_IEC958("Output ", NONE, SWITCH),
  1575. .info = snd_vt1724_spdif_sw_info,
  1576. .get = snd_vt1724_spdif_sw_get,
  1577. .put = snd_vt1724_spdif_sw_put
  1578. };
  1579. #if 0 /* NOT USED YET */
  1580. /*
  1581. * GPIO access from extern
  1582. */
  1583. #define snd_vt1724_gpio_info snd_ctl_boolean_mono_info
  1584. int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
  1585. struct snd_ctl_elem_value *ucontrol)
  1586. {
  1587. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1588. int shift = kcontrol->private_value & 0xff;
  1589. int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
  1590. snd_ice1712_save_gpio_status(ice);
  1591. ucontrol->value.integer.value[0] =
  1592. (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
  1593. snd_ice1712_restore_gpio_status(ice);
  1594. return 0;
  1595. }
  1596. int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
  1597. struct snd_ctl_elem_value *ucontrol)
  1598. {
  1599. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1600. int shift = kcontrol->private_value & 0xff;
  1601. int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
  1602. unsigned int val, nval;
  1603. if (kcontrol->private_value & (1 << 31))
  1604. return -EPERM;
  1605. nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
  1606. snd_ice1712_save_gpio_status(ice);
  1607. val = snd_ice1712_gpio_read(ice);
  1608. nval |= val & ~(1 << shift);
  1609. if (val != nval)
  1610. snd_ice1712_gpio_write(ice, nval);
  1611. snd_ice1712_restore_gpio_status(ice);
  1612. return val != nval;
  1613. }
  1614. #endif /* NOT USED YET */
  1615. /*
  1616. * rate
  1617. */
  1618. static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
  1619. struct snd_ctl_elem_info *uinfo)
  1620. {
  1621. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1622. int hw_rates_count = ice->hw_rates->count;
  1623. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1624. uinfo->count = 1;
  1625. /* internal clocks */
  1626. uinfo->value.enumerated.items = hw_rates_count;
  1627. /* external clocks */
  1628. if (ice->force_rdma1 ||
  1629. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN))
  1630. uinfo->value.enumerated.items += ice->ext_clock_count;
  1631. /* upper limit - keep at top */
  1632. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1633. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1634. if (uinfo->value.enumerated.item >= hw_rates_count)
  1635. /* ext_clock items */
  1636. strcpy(uinfo->value.enumerated.name,
  1637. ice->ext_clock_names[
  1638. uinfo->value.enumerated.item - hw_rates_count]);
  1639. else
  1640. /* int clock items */
  1641. sprintf(uinfo->value.enumerated.name, "%d",
  1642. ice->hw_rates->list[uinfo->value.enumerated.item]);
  1643. return 0;
  1644. }
  1645. static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
  1646. struct snd_ctl_elem_value *ucontrol)
  1647. {
  1648. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1649. unsigned int i, rate;
  1650. spin_lock_irq(&ice->reg_lock);
  1651. if (ice->is_spdif_master(ice)) {
  1652. ucontrol->value.enumerated.item[0] = ice->hw_rates->count +
  1653. ice->get_spdif_master_type(ice);
  1654. } else {
  1655. rate = ice->get_rate(ice);
  1656. ucontrol->value.enumerated.item[0] = 0;
  1657. for (i = 0; i < ice->hw_rates->count; i++) {
  1658. if (ice->hw_rates->list[i] == rate) {
  1659. ucontrol->value.enumerated.item[0] = i;
  1660. break;
  1661. }
  1662. }
  1663. }
  1664. spin_unlock_irq(&ice->reg_lock);
  1665. return 0;
  1666. }
  1667. static int stdclock_get_spdif_master_type(struct snd_ice1712 *ice)
  1668. {
  1669. /* standard external clock - only single type - SPDIF IN */
  1670. return 0;
  1671. }
  1672. /* setting clock to external - SPDIF */
  1673. static int stdclock_set_spdif_clock(struct snd_ice1712 *ice, int type)
  1674. {
  1675. unsigned char oval;
  1676. unsigned char i2s_oval;
  1677. oval = inb(ICEMT1724(ice, RATE));
  1678. outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
  1679. /* setting 256fs */
  1680. i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
  1681. outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
  1682. return 0;
  1683. }
  1684. static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
  1685. struct snd_ctl_elem_value *ucontrol)
  1686. {
  1687. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1688. unsigned int old_rate, new_rate;
  1689. unsigned int item = ucontrol->value.enumerated.item[0];
  1690. unsigned int first_ext_clock = ice->hw_rates->count;
  1691. if (item > first_ext_clock + ice->ext_clock_count - 1)
  1692. return -EINVAL;
  1693. /* if rate = 0 => external clock */
  1694. spin_lock_irq(&ice->reg_lock);
  1695. if (ice->is_spdif_master(ice))
  1696. old_rate = 0;
  1697. else
  1698. old_rate = ice->get_rate(ice);
  1699. if (item >= first_ext_clock) {
  1700. /* switching to external clock */
  1701. ice->set_spdif_clock(ice, item - first_ext_clock);
  1702. new_rate = 0;
  1703. } else {
  1704. /* internal on-card clock */
  1705. new_rate = ice->hw_rates->list[item];
  1706. ice->pro_rate_default = new_rate;
  1707. spin_unlock_irq(&ice->reg_lock);
  1708. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
  1709. spin_lock_irq(&ice->reg_lock);
  1710. }
  1711. spin_unlock_irq(&ice->reg_lock);
  1712. /* the first switch to the ext. clock mode? */
  1713. if (old_rate != new_rate && !new_rate) {
  1714. /* notify akm chips as well */
  1715. unsigned int i;
  1716. if (ice->gpio.set_pro_rate)
  1717. ice->gpio.set_pro_rate(ice, 0);
  1718. for (i = 0; i < ice->akm_codecs; i++) {
  1719. if (ice->akm[i].ops.set_rate_val)
  1720. ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
  1721. }
  1722. }
  1723. return old_rate != new_rate;
  1724. }
  1725. static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
  1726. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1727. .name = "Multi Track Internal Clock",
  1728. .info = snd_vt1724_pro_internal_clock_info,
  1729. .get = snd_vt1724_pro_internal_clock_get,
  1730. .put = snd_vt1724_pro_internal_clock_put
  1731. };
  1732. #define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info
  1733. static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
  1734. struct snd_ctl_elem_value *ucontrol)
  1735. {
  1736. ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
  1737. return 0;
  1738. }
  1739. static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
  1740. struct snd_ctl_elem_value *ucontrol)
  1741. {
  1742. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1743. int change = 0, nval;
  1744. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1745. spin_lock_irq(&ice->reg_lock);
  1746. change = PRO_RATE_LOCKED != nval;
  1747. PRO_RATE_LOCKED = nval;
  1748. spin_unlock_irq(&ice->reg_lock);
  1749. return change;
  1750. }
  1751. static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
  1752. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1753. .name = "Multi Track Rate Locking",
  1754. .info = snd_vt1724_pro_rate_locking_info,
  1755. .get = snd_vt1724_pro_rate_locking_get,
  1756. .put = snd_vt1724_pro_rate_locking_put
  1757. };
  1758. #define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info
  1759. static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
  1760. struct snd_ctl_elem_value *ucontrol)
  1761. {
  1762. ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
  1763. return 0;
  1764. }
  1765. static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
  1766. struct snd_ctl_elem_value *ucontrol)
  1767. {
  1768. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1769. int change = 0, nval;
  1770. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1771. spin_lock_irq(&ice->reg_lock);
  1772. change = PRO_RATE_RESET != nval;
  1773. PRO_RATE_RESET = nval;
  1774. spin_unlock_irq(&ice->reg_lock);
  1775. return change;
  1776. }
  1777. static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
  1778. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1779. .name = "Multi Track Rate Reset",
  1780. .info = snd_vt1724_pro_rate_reset_info,
  1781. .get = snd_vt1724_pro_rate_reset_get,
  1782. .put = snd_vt1724_pro_rate_reset_put
  1783. };
  1784. /*
  1785. * routing
  1786. */
  1787. static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
  1788. struct snd_ctl_elem_info *uinfo)
  1789. {
  1790. static char *texts[] = {
  1791. "PCM Out", /* 0 */
  1792. "H/W In 0", "H/W In 1", /* 1-2 */
  1793. "IEC958 In L", "IEC958 In R", /* 3-4 */
  1794. };
  1795. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1796. uinfo->count = 1;
  1797. uinfo->value.enumerated.items = 5;
  1798. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1799. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1800. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1801. return 0;
  1802. }
  1803. static inline int analog_route_shift(int idx)
  1804. {
  1805. return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
  1806. }
  1807. static inline int digital_route_shift(int idx)
  1808. {
  1809. return idx * 3;
  1810. }
  1811. int snd_ice1724_get_route_val(struct snd_ice1712 *ice, int shift)
  1812. {
  1813. unsigned long val;
  1814. unsigned char eitem;
  1815. static const unsigned char xlate[8] = {
  1816. 0, 255, 1, 2, 255, 255, 3, 4,
  1817. };
  1818. val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  1819. val >>= shift;
  1820. val &= 7; /* we now have 3 bits per output */
  1821. eitem = xlate[val];
  1822. if (eitem == 255) {
  1823. snd_BUG();
  1824. return 0;
  1825. }
  1826. return eitem;
  1827. }
  1828. int snd_ice1724_put_route_val(struct snd_ice1712 *ice, unsigned int val,
  1829. int shift)
  1830. {
  1831. unsigned int old_val, nval;
  1832. int change;
  1833. static const unsigned char xroute[8] = {
  1834. 0, /* PCM */
  1835. 2, /* PSDIN0 Left */
  1836. 3, /* PSDIN0 Right */
  1837. 6, /* SPDIN Left */
  1838. 7, /* SPDIN Right */
  1839. };
  1840. nval = xroute[val % 5];
  1841. val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  1842. val &= ~(0x07 << shift);
  1843. val |= nval << shift;
  1844. change = val != old_val;
  1845. if (change)
  1846. outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
  1847. return change;
  1848. }
  1849. static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
  1850. struct snd_ctl_elem_value *ucontrol)
  1851. {
  1852. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1853. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1854. ucontrol->value.enumerated.item[0] =
  1855. snd_ice1724_get_route_val(ice, analog_route_shift(idx));
  1856. return 0;
  1857. }
  1858. static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
  1859. struct snd_ctl_elem_value *ucontrol)
  1860. {
  1861. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1862. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1863. return snd_ice1724_put_route_val(ice,
  1864. ucontrol->value.enumerated.item[0],
  1865. analog_route_shift(idx));
  1866. }
  1867. static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
  1868. struct snd_ctl_elem_value *ucontrol)
  1869. {
  1870. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1871. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1872. ucontrol->value.enumerated.item[0] =
  1873. snd_ice1724_get_route_val(ice, digital_route_shift(idx));
  1874. return 0;
  1875. }
  1876. static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
  1877. struct snd_ctl_elem_value *ucontrol)
  1878. {
  1879. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1880. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1881. return snd_ice1724_put_route_val(ice,
  1882. ucontrol->value.enumerated.item[0],
  1883. digital_route_shift(idx));
  1884. }
  1885. static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata =
  1886. {
  1887. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1888. .name = "H/W Playback Route",
  1889. .info = snd_vt1724_pro_route_info,
  1890. .get = snd_vt1724_pro_route_analog_get,
  1891. .put = snd_vt1724_pro_route_analog_put,
  1892. };
  1893. static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
  1894. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1895. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route",
  1896. .info = snd_vt1724_pro_route_info,
  1897. .get = snd_vt1724_pro_route_spdif_get,
  1898. .put = snd_vt1724_pro_route_spdif_put,
  1899. .count = 2,
  1900. };
  1901. static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
  1902. struct snd_ctl_elem_info *uinfo)
  1903. {
  1904. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1905. uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
  1906. uinfo->value.integer.min = 0;
  1907. uinfo->value.integer.max = 255;
  1908. return 0;
  1909. }
  1910. static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
  1911. struct snd_ctl_elem_value *ucontrol)
  1912. {
  1913. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1914. int idx;
  1915. spin_lock_irq(&ice->reg_lock);
  1916. for (idx = 0; idx < 22; idx++) {
  1917. outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
  1918. ucontrol->value.integer.value[idx] =
  1919. inb(ICEMT1724(ice, MONITOR_PEAKDATA));
  1920. }
  1921. spin_unlock_irq(&ice->reg_lock);
  1922. return 0;
  1923. }
  1924. static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
  1925. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1926. .name = "Multi Track Peak",
  1927. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1928. .info = snd_vt1724_pro_peak_info,
  1929. .get = snd_vt1724_pro_peak_get
  1930. };
  1931. /*
  1932. *
  1933. */
  1934. static struct snd_ice1712_card_info no_matched __devinitdata;
  1935. /*
  1936. ooAoo cards with no controls
  1937. */
  1938. static unsigned char ooaoo_sq210_eeprom[] __devinitdata = {
  1939. [ICE_EEP2_SYSCONF] = 0x4c, /* 49MHz crystal, no mpu401, no ADC,
  1940. 1xDACs */
  1941. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  1942. [ICE_EEP2_I2S] = 0x78, /* no volume, 96k, 24bit, 192k */
  1943. [ICE_EEP2_SPDIF] = 0xc1, /* out-en, out-int, out-ext */
  1944. [ICE_EEP2_GPIO_DIR] = 0x00, /* no GPIOs are used */
  1945. [ICE_EEP2_GPIO_DIR1] = 0x00,
  1946. [ICE_EEP2_GPIO_DIR2] = 0x00,
  1947. [ICE_EEP2_GPIO_MASK] = 0xff,
  1948. [ICE_EEP2_GPIO_MASK1] = 0xff,
  1949. [ICE_EEP2_GPIO_MASK2] = 0xff,
  1950. [ICE_EEP2_GPIO_STATE] = 0x00, /* inputs */
  1951. [ICE_EEP2_GPIO_STATE1] = 0x00, /* all 1, but GPIO_CPLD_RW
  1952. and GPIO15 always zero */
  1953. [ICE_EEP2_GPIO_STATE2] = 0x00, /* inputs */
  1954. };
  1955. struct snd_ice1712_card_info snd_vt1724_ooaoo_cards[] __devinitdata = {
  1956. {
  1957. .name = "ooAoo SQ210a",
  1958. .model = "sq210a",
  1959. .eeprom_size = sizeof(ooaoo_sq210_eeprom),
  1960. .eeprom_data = ooaoo_sq210_eeprom,
  1961. },
  1962. { } /* terminator */
  1963. };
  1964. static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
  1965. snd_vt1724_revo_cards,
  1966. snd_vt1724_amp_cards,
  1967. snd_vt1724_aureon_cards,
  1968. snd_vt1720_mobo_cards,
  1969. snd_vt1720_pontis_cards,
  1970. snd_vt1724_prodigy_hifi_cards,
  1971. snd_vt1724_prodigy192_cards,
  1972. snd_vt1724_juli_cards,
  1973. snd_vt1724_maya44_cards,
  1974. snd_vt1724_phase_cards,
  1975. snd_vt1724_wtm_cards,
  1976. snd_vt1724_se_cards,
  1977. snd_vt1724_qtet_cards,
  1978. snd_vt1724_ooaoo_cards,
  1979. NULL,
  1980. };
  1981. /*
  1982. */
  1983. static void wait_i2c_busy(struct snd_ice1712 *ice)
  1984. {
  1985. int t = 0x10000;
  1986. while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
  1987. ;
  1988. if (t == -1)
  1989. printk(KERN_ERR "ice1724: i2c busy timeout\n");
  1990. }
  1991. unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
  1992. unsigned char dev, unsigned char addr)
  1993. {
  1994. unsigned char val;
  1995. mutex_lock(&ice->i2c_mutex);
  1996. wait_i2c_busy(ice);
  1997. outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
  1998. outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
  1999. wait_i2c_busy(ice);
  2000. val = inb(ICEREG1724(ice, I2C_DATA));
  2001. mutex_unlock(&ice->i2c_mutex);
  2002. /*
  2003. printk(KERN_DEBUG "i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
  2004. */
  2005. return val;
  2006. }
  2007. void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
  2008. unsigned char dev, unsigned char addr, unsigned char data)
  2009. {
  2010. mutex_lock(&ice->i2c_mutex);
  2011. wait_i2c_busy(ice);
  2012. /*
  2013. printk(KERN_DEBUG "i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
  2014. */
  2015. outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
  2016. outb(data, ICEREG1724(ice, I2C_DATA));
  2017. outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
  2018. wait_i2c_busy(ice);
  2019. mutex_unlock(&ice->i2c_mutex);
  2020. }
  2021. static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
  2022. const char *modelname)
  2023. {
  2024. const int dev = 0xa0; /* EEPROM device address */
  2025. unsigned int i, size;
  2026. struct snd_ice1712_card_info * const *tbl, *c;
  2027. if (!modelname || !*modelname) {
  2028. ice->eeprom.subvendor = 0;
  2029. if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
  2030. ice->eeprom.subvendor =
  2031. (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
  2032. (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
  2033. (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
  2034. (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
  2035. if (ice->eeprom.subvendor == 0 ||
  2036. ice->eeprom.subvendor == (unsigned int)-1) {
  2037. /* invalid subvendor from EEPROM, try the PCI
  2038. * subststem ID instead
  2039. */
  2040. u16 vendor, device;
  2041. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
  2042. &vendor);
  2043. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
  2044. ice->eeprom.subvendor =
  2045. ((unsigned int)swab16(vendor) << 16) | swab16(device);
  2046. if (ice->eeprom.subvendor == 0 ||
  2047. ice->eeprom.subvendor == (unsigned int)-1) {
  2048. printk(KERN_ERR "ice1724: No valid ID is found\n");
  2049. return -ENXIO;
  2050. }
  2051. }
  2052. }
  2053. for (tbl = card_tables; *tbl; tbl++) {
  2054. for (c = *tbl; c->name; c++) {
  2055. if (modelname && c->model &&
  2056. !strcmp(modelname, c->model)) {
  2057. printk(KERN_INFO "ice1724: Using board model %s\n",
  2058. c->name);
  2059. ice->eeprom.subvendor = c->subvendor;
  2060. } else if (c->subvendor != ice->eeprom.subvendor)
  2061. continue;
  2062. if (!c->eeprom_size || !c->eeprom_data)
  2063. goto found;
  2064. /* if the EEPROM is given by the driver, use it */
  2065. snd_printdd("using the defined eeprom..\n");
  2066. ice->eeprom.version = 2;
  2067. ice->eeprom.size = c->eeprom_size + 6;
  2068. memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
  2069. goto read_skipped;
  2070. }
  2071. }
  2072. printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
  2073. ice->eeprom.subvendor);
  2074. found:
  2075. ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
  2076. if (ice->eeprom.size < 6)
  2077. ice->eeprom.size = 32;
  2078. else if (ice->eeprom.size > 32) {
  2079. printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
  2080. ice->eeprom.size);
  2081. return -EIO;
  2082. }
  2083. ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
  2084. if (ice->eeprom.version != 2)
  2085. printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
  2086. ice->eeprom.version);
  2087. size = ice->eeprom.size - 6;
  2088. for (i = 0; i < size; i++)
  2089. ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
  2090. read_skipped:
  2091. ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
  2092. ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
  2093. ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
  2094. return 0;
  2095. }
  2096. static void snd_vt1724_chip_reset(struct snd_ice1712 *ice)
  2097. {
  2098. outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
  2099. inb(ICEREG1724(ice, CONTROL)); /* pci posting flush */
  2100. msleep(10);
  2101. outb(0, ICEREG1724(ice, CONTROL));
  2102. inb(ICEREG1724(ice, CONTROL)); /* pci posting flush */
  2103. msleep(10);
  2104. }
  2105. static int snd_vt1724_chip_init(struct snd_ice1712 *ice)
  2106. {
  2107. outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
  2108. outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
  2109. outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
  2110. outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
  2111. ice->gpio.write_mask = ice->eeprom.gpiomask;
  2112. ice->gpio.direction = ice->eeprom.gpiodir;
  2113. snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
  2114. snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
  2115. snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
  2116. outb(0, ICEREG1724(ice, POWERDOWN));
  2117. /* MPU_RX and TX irq masks are cleared later dynamically */
  2118. outb(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX , ICEREG1724(ice, IRQMASK));
  2119. /* don't handle FIFO overrun/underruns (just yet),
  2120. * since they cause machine lockups
  2121. */
  2122. outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
  2123. return 0;
  2124. }
  2125. static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
  2126. {
  2127. int err;
  2128. struct snd_kcontrol *kctl;
  2129. if (snd_BUG_ON(!ice->pcm))
  2130. return -EIO;
  2131. if (!ice->own_routing) {
  2132. err = snd_ctl_add(ice->card,
  2133. snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
  2134. if (err < 0)
  2135. return err;
  2136. }
  2137. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
  2138. if (err < 0)
  2139. return err;
  2140. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
  2141. if (err < 0)
  2142. return err;
  2143. kctl->id.device = ice->pcm->device;
  2144. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
  2145. if (err < 0)
  2146. return err;
  2147. kctl->id.device = ice->pcm->device;
  2148. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
  2149. if (err < 0)
  2150. return err;
  2151. kctl->id.device = ice->pcm->device;
  2152. #if 0 /* use default only */
  2153. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
  2154. if (err < 0)
  2155. return err;
  2156. kctl->id.device = ice->pcm->device;
  2157. ice->spdif.stream_ctl = kctl;
  2158. #endif
  2159. return 0;
  2160. }
  2161. static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
  2162. {
  2163. int err;
  2164. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
  2165. if (err < 0)
  2166. return err;
  2167. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
  2168. if (err < 0)
  2169. return err;
  2170. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
  2171. if (err < 0)
  2172. return err;
  2173. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
  2174. if (err < 0)
  2175. return err;
  2176. if (!ice->own_routing && ice->num_total_dacs > 0) {
  2177. struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
  2178. tmp.count = ice->num_total_dacs;
  2179. if (ice->vt1720 && tmp.count > 2)
  2180. tmp.count = 2;
  2181. err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
  2182. if (err < 0)
  2183. return err;
  2184. }
  2185. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
  2186. if (err < 0)
  2187. return err;
  2188. return 0;
  2189. }
  2190. static int snd_vt1724_free(struct snd_ice1712 *ice)
  2191. {
  2192. if (!ice->port)
  2193. goto __hw_end;
  2194. /* mask all interrupts */
  2195. outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
  2196. outb(0xff, ICEREG1724(ice, IRQMASK));
  2197. /* --- */
  2198. __hw_end:
  2199. if (ice->irq >= 0)
  2200. free_irq(ice->irq, ice);
  2201. pci_release_regions(ice->pci);
  2202. snd_ice1712_akm4xxx_free(ice);
  2203. pci_disable_device(ice->pci);
  2204. kfree(ice->spec);
  2205. kfree(ice);
  2206. return 0;
  2207. }
  2208. static int snd_vt1724_dev_free(struct snd_device *device)
  2209. {
  2210. struct snd_ice1712 *ice = device->device_data;
  2211. return snd_vt1724_free(ice);
  2212. }
  2213. static int __devinit snd_vt1724_create(struct snd_card *card,
  2214. struct pci_dev *pci,
  2215. const char *modelname,
  2216. struct snd_ice1712 **r_ice1712)
  2217. {
  2218. struct snd_ice1712 *ice;
  2219. int err;
  2220. static struct snd_device_ops ops = {
  2221. .dev_free = snd_vt1724_dev_free,
  2222. };
  2223. *r_ice1712 = NULL;
  2224. /* enable PCI device */
  2225. err = pci_enable_device(pci);
  2226. if (err < 0)
  2227. return err;
  2228. ice = kzalloc(sizeof(*ice), GFP_KERNEL);
  2229. if (ice == NULL) {
  2230. pci_disable_device(pci);
  2231. return -ENOMEM;
  2232. }
  2233. ice->vt1724 = 1;
  2234. spin_lock_init(&ice->reg_lock);
  2235. mutex_init(&ice->gpio_mutex);
  2236. mutex_init(&ice->open_mutex);
  2237. mutex_init(&ice->i2c_mutex);
  2238. ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
  2239. ice->gpio.get_mask = snd_vt1724_get_gpio_mask;
  2240. ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
  2241. ice->gpio.get_dir = snd_vt1724_get_gpio_dir;
  2242. ice->gpio.set_data = snd_vt1724_set_gpio_data;
  2243. ice->gpio.get_data = snd_vt1724_get_gpio_data;
  2244. ice->card = card;
  2245. ice->pci = pci;
  2246. ice->irq = -1;
  2247. pci_set_master(pci);
  2248. snd_vt1724_proc_init(ice);
  2249. synchronize_irq(pci->irq);
  2250. card->private_data = ice;
  2251. err = pci_request_regions(pci, "ICE1724");
  2252. if (err < 0) {
  2253. kfree(ice);
  2254. pci_disable_device(pci);
  2255. return err;
  2256. }
  2257. ice->port = pci_resource_start(pci, 0);
  2258. ice->profi_port = pci_resource_start(pci, 1);
  2259. if (request_irq(pci->irq, snd_vt1724_interrupt,
  2260. IRQF_SHARED, KBUILD_MODNAME, ice)) {
  2261. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  2262. snd_vt1724_free(ice);
  2263. return -EIO;
  2264. }
  2265. ice->irq = pci->irq;
  2266. snd_vt1724_chip_reset(ice);
  2267. if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
  2268. snd_vt1724_free(ice);
  2269. return -EIO;
  2270. }
  2271. if (snd_vt1724_chip_init(ice) < 0) {
  2272. snd_vt1724_free(ice);
  2273. return -EIO;
  2274. }
  2275. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops);
  2276. if (err < 0) {
  2277. snd_vt1724_free(ice);
  2278. return err;
  2279. }
  2280. snd_card_set_dev(card, &pci->dev);
  2281. *r_ice1712 = ice;
  2282. return 0;
  2283. }
  2284. /*
  2285. *
  2286. * Registration
  2287. *
  2288. */
  2289. static int __devinit snd_vt1724_probe(struct pci_dev *pci,
  2290. const struct pci_device_id *pci_id)
  2291. {
  2292. static int dev;
  2293. struct snd_card *card;
  2294. struct snd_ice1712 *ice;
  2295. int pcm_dev = 0, err;
  2296. struct snd_ice1712_card_info * const *tbl, *c;
  2297. if (dev >= SNDRV_CARDS)
  2298. return -ENODEV;
  2299. if (!enable[dev]) {
  2300. dev++;
  2301. return -ENOENT;
  2302. }
  2303. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  2304. if (err < 0)
  2305. return err;
  2306. strcpy(card->driver, "ICE1724");
  2307. strcpy(card->shortname, "ICEnsemble ICE1724");
  2308. err = snd_vt1724_create(card, pci, model[dev], &ice);
  2309. if (err < 0) {
  2310. snd_card_free(card);
  2311. return err;
  2312. }
  2313. /* field init before calling chip_init */
  2314. ice->ext_clock_count = 0;
  2315. for (tbl = card_tables; *tbl; tbl++) {
  2316. for (c = *tbl; c->name; c++) {
  2317. if ((model[dev] && c->model &&
  2318. !strcmp(model[dev], c->model)) ||
  2319. (c->subvendor == ice->eeprom.subvendor)) {
  2320. strcpy(card->shortname, c->name);
  2321. if (c->driver) /* specific driver? */
  2322. strcpy(card->driver, c->driver);
  2323. if (c->chip_init) {
  2324. err = c->chip_init(ice);
  2325. if (err < 0) {
  2326. snd_card_free(card);
  2327. return err;
  2328. }
  2329. }
  2330. goto __found;
  2331. }
  2332. }
  2333. }
  2334. c = &no_matched;
  2335. __found:
  2336. /*
  2337. * VT1724 has separate DMAs for the analog and the SPDIF streams while
  2338. * ICE1712 has only one for both (mixed up).
  2339. *
  2340. * Confusingly the analog PCM is named "professional" here because it
  2341. * was called so in ice1712 driver, and vt1724 driver is derived from
  2342. * ice1712 driver.
  2343. */
  2344. ice->pro_rate_default = PRO_RATE_DEFAULT;
  2345. if (!ice->is_spdif_master)
  2346. ice->is_spdif_master = stdclock_is_spdif_master;
  2347. if (!ice->get_rate)
  2348. ice->get_rate = stdclock_get_rate;
  2349. if (!ice->set_rate)
  2350. ice->set_rate = stdclock_set_rate;
  2351. if (!ice->set_mclk)
  2352. ice->set_mclk = stdclock_set_mclk;
  2353. if (!ice->set_spdif_clock)
  2354. ice->set_spdif_clock = stdclock_set_spdif_clock;
  2355. if (!ice->get_spdif_master_type)
  2356. ice->get_spdif_master_type = stdclock_get_spdif_master_type;
  2357. if (!ice->ext_clock_names)
  2358. ice->ext_clock_names = ext_clock_names;
  2359. if (!ice->ext_clock_count)
  2360. ice->ext_clock_count = ARRAY_SIZE(ext_clock_names);
  2361. if (!ice->hw_rates)
  2362. set_std_hw_rates(ice);
  2363. err = snd_vt1724_pcm_profi(ice, pcm_dev++);
  2364. if (err < 0) {
  2365. snd_card_free(card);
  2366. return err;
  2367. }
  2368. err = snd_vt1724_pcm_spdif(ice, pcm_dev++);
  2369. if (err < 0) {
  2370. snd_card_free(card);
  2371. return err;
  2372. }
  2373. err = snd_vt1724_pcm_indep(ice, pcm_dev++);
  2374. if (err < 0) {
  2375. snd_card_free(card);
  2376. return err;
  2377. }
  2378. err = snd_vt1724_ac97_mixer(ice);
  2379. if (err < 0) {
  2380. snd_card_free(card);
  2381. return err;
  2382. }
  2383. err = snd_vt1724_build_controls(ice);
  2384. if (err < 0) {
  2385. snd_card_free(card);
  2386. return err;
  2387. }
  2388. if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
  2389. err = snd_vt1724_spdif_build_controls(ice);
  2390. if (err < 0) {
  2391. snd_card_free(card);
  2392. return err;
  2393. }
  2394. }
  2395. if (c->build_controls) {
  2396. err = c->build_controls(ice);
  2397. if (err < 0) {
  2398. snd_card_free(card);
  2399. return err;
  2400. }
  2401. }
  2402. if (!c->no_mpu401) {
  2403. if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
  2404. struct snd_rawmidi *rmidi;
  2405. err = snd_rawmidi_new(card, "MIDI", 0, 1, 1, &rmidi);
  2406. if (err < 0) {
  2407. snd_card_free(card);
  2408. return err;
  2409. }
  2410. ice->rmidi[0] = rmidi;
  2411. rmidi->private_data = ice;
  2412. strcpy(rmidi->name, "ICE1724 MIDI");
  2413. rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
  2414. SNDRV_RAWMIDI_INFO_INPUT |
  2415. SNDRV_RAWMIDI_INFO_DUPLEX;
  2416. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
  2417. &vt1724_midi_output_ops);
  2418. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
  2419. &vt1724_midi_input_ops);
  2420. /* set watermarks */
  2421. outb(VT1724_MPU_RX_FIFO | 0x1,
  2422. ICEREG1724(ice, MPU_FIFO_WM));
  2423. outb(0x1, ICEREG1724(ice, MPU_FIFO_WM));
  2424. /* set UART mode */
  2425. outb(VT1724_MPU_UART, ICEREG1724(ice, MPU_CTRL));
  2426. }
  2427. }
  2428. sprintf(card->longname, "%s at 0x%lx, irq %i",
  2429. card->shortname, ice->port, ice->irq);
  2430. err = snd_card_register(card);
  2431. if (err < 0) {
  2432. snd_card_free(card);
  2433. return err;
  2434. }
  2435. pci_set_drvdata(pci, card);
  2436. dev++;
  2437. return 0;
  2438. }
  2439. static void __devexit snd_vt1724_remove(struct pci_dev *pci)
  2440. {
  2441. snd_card_free(pci_get_drvdata(pci));
  2442. pci_set_drvdata(pci, NULL);
  2443. }
  2444. #ifdef CONFIG_PM
  2445. static int snd_vt1724_suspend(struct pci_dev *pci, pm_message_t state)
  2446. {
  2447. struct snd_card *card = pci_get_drvdata(pci);
  2448. struct snd_ice1712 *ice = card->private_data;
  2449. if (!ice->pm_suspend_enabled)
  2450. return 0;
  2451. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  2452. snd_pcm_suspend_all(ice->pcm);
  2453. snd_pcm_suspend_all(ice->pcm_pro);
  2454. snd_pcm_suspend_all(ice->pcm_ds);
  2455. snd_ac97_suspend(ice->ac97);
  2456. spin_lock_irq(&ice->reg_lock);
  2457. ice->pm_saved_is_spdif_master = ice->is_spdif_master(ice);
  2458. ice->pm_saved_spdif_ctrl = inw(ICEMT1724(ice, SPDIF_CTRL));
  2459. ice->pm_saved_spdif_cfg = inb(ICEREG1724(ice, SPDIF_CFG));
  2460. ice->pm_saved_route = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  2461. spin_unlock_irq(&ice->reg_lock);
  2462. if (ice->pm_suspend)
  2463. ice->pm_suspend(ice);
  2464. pci_disable_device(pci);
  2465. pci_save_state(pci);
  2466. pci_set_power_state(pci, pci_choose_state(pci, state));
  2467. return 0;
  2468. }
  2469. static int snd_vt1724_resume(struct pci_dev *pci)
  2470. {
  2471. struct snd_card *card = pci_get_drvdata(pci);
  2472. struct snd_ice1712 *ice = card->private_data;
  2473. if (!ice->pm_suspend_enabled)
  2474. return 0;
  2475. pci_set_power_state(pci, PCI_D0);
  2476. pci_restore_state(pci);
  2477. if (pci_enable_device(pci) < 0) {
  2478. snd_card_disconnect(card);
  2479. return -EIO;
  2480. }
  2481. pci_set_master(pci);
  2482. snd_vt1724_chip_reset(ice);
  2483. if (snd_vt1724_chip_init(ice) < 0) {
  2484. snd_card_disconnect(card);
  2485. return -EIO;
  2486. }
  2487. if (ice->pm_resume)
  2488. ice->pm_resume(ice);
  2489. if (ice->pm_saved_is_spdif_master) {
  2490. /* switching to external clock via SPDIF */
  2491. ice->set_spdif_clock(ice, 0);
  2492. } else {
  2493. /* internal on-card clock */
  2494. snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
  2495. }
  2496. update_spdif_bits(ice, ice->pm_saved_spdif_ctrl);
  2497. outb(ice->pm_saved_spdif_cfg, ICEREG1724(ice, SPDIF_CFG));
  2498. outl(ice->pm_saved_route, ICEMT1724(ice, ROUTE_PLAYBACK));
  2499. if (ice->ac97)
  2500. snd_ac97_resume(ice->ac97);
  2501. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  2502. return 0;
  2503. }
  2504. #endif
  2505. static struct pci_driver driver = {
  2506. .name = KBUILD_MODNAME,
  2507. .id_table = snd_vt1724_ids,
  2508. .probe = snd_vt1724_probe,
  2509. .remove = __devexit_p(snd_vt1724_remove),
  2510. #ifdef CONFIG_PM
  2511. .suspend = snd_vt1724_suspend,
  2512. .resume = snd_vt1724_resume,
  2513. #endif
  2514. };
  2515. static int __init alsa_card_ice1724_init(void)
  2516. {
  2517. return pci_register_driver(&driver);
  2518. }
  2519. static void __exit alsa_card_ice1724_exit(void)
  2520. {
  2521. pci_unregister_driver(&driver);
  2522. }
  2523. module_init(alsa_card_ice1724_init)
  2524. module_exit(alsa_card_ice1724_exit)