ice1712.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. /*
  22. NOTES:
  23. - spdif nonaudio consumer mode does not work (at least with my
  24. Sony STR-DB830)
  25. */
  26. /*
  27. * Changes:
  28. *
  29. * 2002.09.09 Takashi Iwai <tiwai@suse.de>
  30. * split the code to several files. each low-level routine
  31. * is stored in the local file and called from registration
  32. * function from card_info struct.
  33. *
  34. * 2002.11.26 James Stafford <jstafford@ampltd.com>
  35. * Added support for VT1724 (Envy24HT)
  36. * I have left out support for 176.4 and 192 KHz for the moment.
  37. * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
  38. *
  39. * 2003.02.20 Taksahi Iwai <tiwai@suse.de>
  40. * Split vt1724 part to an independent driver.
  41. * The GPIO is accessed through the callback functions now.
  42. *
  43. * 2004.03.31 Doug McLain <nostar@comcast.net>
  44. * Added support for Event Electronics EZ8 card to hoontech.c.
  45. */
  46. #include <sound/driver.h>
  47. #include <asm/io.h>
  48. #include <linux/delay.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/init.h>
  51. #include <linux/pci.h>
  52. #include <linux/slab.h>
  53. #include <linux/moduleparam.h>
  54. #include <sound/core.h>
  55. #include <sound/cs8427.h>
  56. #include <sound/info.h>
  57. #include <sound/mpu401.h>
  58. #include <sound/initval.h>
  59. #include <sound/asoundef.h>
  60. #include "ice1712.h"
  61. /* lowlevel routines */
  62. #include "delta.h"
  63. #include "ews.h"
  64. #include "hoontech.h"
  65. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  66. MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
  67. MODULE_LICENSE("GPL");
  68. MODULE_SUPPORTED_DEVICE("{"
  69. HOONTECH_DEVICE_DESC
  70. DELTA_DEVICE_DESC
  71. EWS_DEVICE_DESC
  72. "{ICEnsemble,Generic ICE1712},"
  73. "{ICEnsemble,Generic Envy24}}");
  74. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  75. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  76. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  77. static char *model[SNDRV_CARDS];
  78. static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
  79. static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
  80. module_param_array(index, int, NULL, 0444);
  81. MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
  82. module_param_array(id, charp, NULL, 0444);
  83. MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
  84. module_param_array(enable, bool, NULL, 0444);
  85. MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
  86. module_param_array(omni, bool, NULL, 0444);
  87. MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
  88. module_param_array(cs8427_timeout, int, NULL, 0444);
  89. MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
  90. module_param_array(model, charp, NULL, 0444);
  91. MODULE_PARM_DESC(model, "Use the given board model.");
  92. static struct pci_device_id snd_ice1712_ids[] = {
  93. { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
  94. { 0, }
  95. };
  96. MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
  97. static int snd_ice1712_build_pro_mixer(ice1712_t *ice);
  98. static int snd_ice1712_build_controls(ice1712_t *ice);
  99. static int PRO_RATE_LOCKED;
  100. static int PRO_RATE_RESET = 1;
  101. static unsigned int PRO_RATE_DEFAULT = 44100;
  102. /*
  103. * Basic I/O
  104. */
  105. /* check whether the clock mode is spdif-in */
  106. static inline int is_spdif_master(ice1712_t *ice)
  107. {
  108. return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
  109. }
  110. static inline int is_pro_rate_locked(ice1712_t *ice)
  111. {
  112. return is_spdif_master(ice) || PRO_RATE_LOCKED;
  113. }
  114. static inline void snd_ice1712_ds_write(ice1712_t * ice, u8 channel, u8 addr, u32 data)
  115. {
  116. outb((channel << 4) | addr, ICEDS(ice, INDEX));
  117. outl(data, ICEDS(ice, DATA));
  118. }
  119. static inline u32 snd_ice1712_ds_read(ice1712_t * ice, u8 channel, u8 addr)
  120. {
  121. outb((channel << 4) | addr, ICEDS(ice, INDEX));
  122. return inl(ICEDS(ice, DATA));
  123. }
  124. static void snd_ice1712_ac97_write(ac97_t *ac97,
  125. unsigned short reg,
  126. unsigned short val)
  127. {
  128. ice1712_t *ice = (ice1712_t *)ac97->private_data;
  129. int tm;
  130. unsigned char old_cmd = 0;
  131. for (tm = 0; tm < 0x10000; tm++) {
  132. old_cmd = inb(ICEREG(ice, AC97_CMD));
  133. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  134. continue;
  135. if (!(old_cmd & ICE1712_AC97_READY))
  136. continue;
  137. break;
  138. }
  139. outb(reg, ICEREG(ice, AC97_INDEX));
  140. outw(val, ICEREG(ice, AC97_DATA));
  141. old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
  142. outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
  143. for (tm = 0; tm < 0x10000; tm++)
  144. if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
  145. break;
  146. }
  147. static unsigned short snd_ice1712_ac97_read(ac97_t *ac97,
  148. unsigned short reg)
  149. {
  150. ice1712_t *ice = (ice1712_t *)ac97->private_data;
  151. int tm;
  152. unsigned char old_cmd = 0;
  153. for (tm = 0; tm < 0x10000; tm++) {
  154. old_cmd = inb(ICEREG(ice, AC97_CMD));
  155. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  156. continue;
  157. if (!(old_cmd & ICE1712_AC97_READY))
  158. continue;
  159. break;
  160. }
  161. outb(reg, ICEREG(ice, AC97_INDEX));
  162. outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
  163. for (tm = 0; tm < 0x10000; tm++)
  164. if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
  165. break;
  166. if (tm >= 0x10000) /* timeout */
  167. return ~0;
  168. return inw(ICEREG(ice, AC97_DATA));
  169. }
  170. /*
  171. * pro ac97 section
  172. */
  173. static void snd_ice1712_pro_ac97_write(ac97_t *ac97,
  174. unsigned short reg,
  175. unsigned short val)
  176. {
  177. ice1712_t *ice = (ice1712_t *)ac97->private_data;
  178. int tm;
  179. unsigned char old_cmd = 0;
  180. for (tm = 0; tm < 0x10000; tm++) {
  181. old_cmd = inb(ICEMT(ice, AC97_CMD));
  182. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  183. continue;
  184. if (!(old_cmd & ICE1712_AC97_READY))
  185. continue;
  186. break;
  187. }
  188. outb(reg, ICEMT(ice, AC97_INDEX));
  189. outw(val, ICEMT(ice, AC97_DATA));
  190. old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
  191. outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
  192. for (tm = 0; tm < 0x10000; tm++)
  193. if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
  194. break;
  195. }
  196. static unsigned short snd_ice1712_pro_ac97_read(ac97_t *ac97,
  197. unsigned short reg)
  198. {
  199. ice1712_t *ice = (ice1712_t *)ac97->private_data;
  200. int tm;
  201. unsigned char old_cmd = 0;
  202. for (tm = 0; tm < 0x10000; tm++) {
  203. old_cmd = inb(ICEMT(ice, AC97_CMD));
  204. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  205. continue;
  206. if (!(old_cmd & ICE1712_AC97_READY))
  207. continue;
  208. break;
  209. }
  210. outb(reg, ICEMT(ice, AC97_INDEX));
  211. outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
  212. for (tm = 0; tm < 0x10000; tm++)
  213. if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
  214. break;
  215. if (tm >= 0x10000) /* timeout */
  216. return ~0;
  217. return inw(ICEMT(ice, AC97_DATA));
  218. }
  219. /*
  220. * consumer ac97 digital mix
  221. */
  222. static int snd_ice1712_digmix_route_ac97_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  223. {
  224. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  225. uinfo->count = 1;
  226. uinfo->value.integer.min = 0;
  227. uinfo->value.integer.max = 1;
  228. return 0;
  229. }
  230. static int snd_ice1712_digmix_route_ac97_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  231. {
  232. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  233. ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
  234. return 0;
  235. }
  236. static int snd_ice1712_digmix_route_ac97_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  237. {
  238. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  239. unsigned char val, nval;
  240. spin_lock_irq(&ice->reg_lock);
  241. val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
  242. nval = val & ~ICE1712_ROUTE_AC97;
  243. if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
  244. outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
  245. spin_unlock_irq(&ice->reg_lock);
  246. return val != nval;
  247. }
  248. static snd_kcontrol_new_t snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
  249. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  250. .name = "Digital Mixer To AC97",
  251. .info = snd_ice1712_digmix_route_ac97_info,
  252. .get = snd_ice1712_digmix_route_ac97_get,
  253. .put = snd_ice1712_digmix_route_ac97_put,
  254. };
  255. /*
  256. * gpio operations
  257. */
  258. static void snd_ice1712_set_gpio_dir(ice1712_t *ice, unsigned int data)
  259. {
  260. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
  261. inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
  262. }
  263. static void snd_ice1712_set_gpio_mask(ice1712_t *ice, unsigned int data)
  264. {
  265. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
  266. inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
  267. }
  268. static unsigned int snd_ice1712_get_gpio_data(ice1712_t *ice)
  269. {
  270. return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  271. }
  272. static void snd_ice1712_set_gpio_data(ice1712_t *ice, unsigned int val)
  273. {
  274. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
  275. inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
  276. }
  277. /*
  278. *
  279. * CS8427 interface
  280. *
  281. */
  282. /*
  283. * change the input clock selection
  284. * spdif_clock = 1 - IEC958 input, 0 - Envy24
  285. */
  286. static int snd_ice1712_cs8427_set_input_clock(ice1712_t *ice, int spdif_clock)
  287. {
  288. unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
  289. unsigned char val, nval;
  290. int res = 0;
  291. snd_i2c_lock(ice->i2c);
  292. if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
  293. snd_i2c_unlock(ice->i2c);
  294. return -EIO;
  295. }
  296. if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
  297. snd_i2c_unlock(ice->i2c);
  298. return -EIO;
  299. }
  300. nval = val & 0xf0;
  301. if (spdif_clock)
  302. nval |= 0x01;
  303. else
  304. nval |= 0x04;
  305. if (val != nval) {
  306. reg[1] = nval;
  307. if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
  308. res = -EIO;
  309. } else {
  310. res++;
  311. }
  312. }
  313. snd_i2c_unlock(ice->i2c);
  314. return res;
  315. }
  316. /*
  317. * spdif callbacks
  318. */
  319. static void open_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
  320. {
  321. snd_cs8427_iec958_active(ice->cs8427, 1);
  322. }
  323. static void close_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
  324. {
  325. snd_cs8427_iec958_active(ice->cs8427, 0);
  326. }
  327. static void setup_cs8427(ice1712_t *ice, int rate)
  328. {
  329. snd_cs8427_iec958_pcm(ice->cs8427, rate);
  330. }
  331. /*
  332. * create and initialize callbacks for cs8427 interface
  333. */
  334. int __devinit snd_ice1712_init_cs8427(ice1712_t *ice, int addr)
  335. {
  336. int err;
  337. if ((err = snd_cs8427_create(ice->i2c, addr,
  338. (ice->cs8427_timeout * HZ) / 1000,
  339. &ice->cs8427)) < 0) {
  340. snd_printk("CS8427 initialization failed\n");
  341. return err;
  342. }
  343. ice->spdif.ops.open = open_cs8427;
  344. ice->spdif.ops.close = close_cs8427;
  345. ice->spdif.ops.setup_rate = setup_cs8427;
  346. return 0;
  347. }
  348. /*
  349. * Interrupt handler
  350. */
  351. static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  352. {
  353. ice1712_t *ice = dev_id;
  354. unsigned char status;
  355. int handled = 0;
  356. while (1) {
  357. status = inb(ICEREG(ice, IRQSTAT));
  358. if (status == 0)
  359. break;
  360. handled = 1;
  361. if (status & ICE1712_IRQ_MPU1) {
  362. if (ice->rmidi[0])
  363. snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
  364. outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
  365. status &= ~ICE1712_IRQ_MPU1;
  366. }
  367. if (status & ICE1712_IRQ_TIMER)
  368. outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
  369. if (status & ICE1712_IRQ_MPU2) {
  370. if (ice->rmidi[1])
  371. snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data, regs);
  372. outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
  373. status &= ~ICE1712_IRQ_MPU2;
  374. }
  375. if (status & ICE1712_IRQ_PROPCM) {
  376. unsigned char mtstat = inb(ICEMT(ice, IRQ));
  377. if (mtstat & ICE1712_MULTI_PBKSTATUS) {
  378. if (ice->playback_pro_substream)
  379. snd_pcm_period_elapsed(ice->playback_pro_substream);
  380. outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
  381. }
  382. if (mtstat & ICE1712_MULTI_CAPSTATUS) {
  383. if (ice->capture_pro_substream)
  384. snd_pcm_period_elapsed(ice->capture_pro_substream);
  385. outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
  386. }
  387. }
  388. if (status & ICE1712_IRQ_FM)
  389. outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
  390. if (status & ICE1712_IRQ_PBKDS) {
  391. u32 idx;
  392. u16 pbkstatus;
  393. snd_pcm_substream_t *substream;
  394. pbkstatus = inw(ICEDS(ice, INTSTAT));
  395. //printk("pbkstatus = 0x%x\n", pbkstatus);
  396. for (idx = 0; idx < 6; idx++) {
  397. if ((pbkstatus & (3 << (idx * 2))) == 0)
  398. continue;
  399. if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
  400. snd_pcm_period_elapsed(substream);
  401. outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
  402. }
  403. outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
  404. }
  405. if (status & ICE1712_IRQ_CONCAP) {
  406. if (ice->capture_con_substream)
  407. snd_pcm_period_elapsed(ice->capture_con_substream);
  408. outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
  409. }
  410. if (status & ICE1712_IRQ_CONPBK) {
  411. if (ice->playback_con_substream)
  412. snd_pcm_period_elapsed(ice->playback_con_substream);
  413. outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
  414. }
  415. }
  416. return IRQ_RETVAL(handled);
  417. }
  418. /*
  419. * PCM part - misc
  420. */
  421. static int snd_ice1712_hw_params(snd_pcm_substream_t * substream,
  422. snd_pcm_hw_params_t * hw_params)
  423. {
  424. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  425. }
  426. static int snd_ice1712_hw_free(snd_pcm_substream_t * substream)
  427. {
  428. return snd_pcm_lib_free_pages(substream);
  429. }
  430. /*
  431. * PCM part - consumer I/O
  432. */
  433. static int snd_ice1712_playback_trigger(snd_pcm_substream_t * substream,
  434. int cmd)
  435. {
  436. ice1712_t *ice = snd_pcm_substream_chip(substream);
  437. int result = 0;
  438. u32 tmp;
  439. spin_lock(&ice->reg_lock);
  440. tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
  441. if (cmd == SNDRV_PCM_TRIGGER_START) {
  442. tmp |= 1;
  443. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  444. tmp &= ~1;
  445. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
  446. tmp |= 2;
  447. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
  448. tmp &= ~2;
  449. } else {
  450. result = -EINVAL;
  451. }
  452. snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
  453. spin_unlock(&ice->reg_lock);
  454. return result;
  455. }
  456. static int snd_ice1712_playback_ds_trigger(snd_pcm_substream_t * substream,
  457. int cmd)
  458. {
  459. ice1712_t *ice = snd_pcm_substream_chip(substream);
  460. int result = 0;
  461. u32 tmp;
  462. spin_lock(&ice->reg_lock);
  463. tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
  464. if (cmd == SNDRV_PCM_TRIGGER_START) {
  465. tmp |= 1;
  466. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  467. tmp &= ~1;
  468. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
  469. tmp |= 2;
  470. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
  471. tmp &= ~2;
  472. } else {
  473. result = -EINVAL;
  474. }
  475. snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
  476. spin_unlock(&ice->reg_lock);
  477. return result;
  478. }
  479. static int snd_ice1712_capture_trigger(snd_pcm_substream_t * substream,
  480. int cmd)
  481. {
  482. ice1712_t *ice = snd_pcm_substream_chip(substream);
  483. int result = 0;
  484. u8 tmp;
  485. spin_lock(&ice->reg_lock);
  486. tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
  487. if (cmd == SNDRV_PCM_TRIGGER_START) {
  488. tmp |= 1;
  489. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  490. tmp &= ~1;
  491. } else {
  492. result = -EINVAL;
  493. }
  494. snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
  495. spin_unlock(&ice->reg_lock);
  496. return result;
  497. }
  498. static int snd_ice1712_playback_prepare(snd_pcm_substream_t * substream)
  499. {
  500. ice1712_t *ice = snd_pcm_substream_chip(substream);
  501. snd_pcm_runtime_t *runtime = substream->runtime;
  502. u32 period_size, buf_size, rate, tmp;
  503. period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
  504. buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
  505. tmp = 0x0000;
  506. if (snd_pcm_format_width(runtime->format) == 16)
  507. tmp |= 0x10;
  508. if (runtime->channels == 2)
  509. tmp |= 0x08;
  510. rate = (runtime->rate * 8192) / 375;
  511. if (rate > 0x000fffff)
  512. rate = 0x000fffff;
  513. spin_lock_irq(&ice->reg_lock);
  514. outb(0, ice->ddma_port + 15);
  515. outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
  516. outl(runtime->dma_addr, ice->ddma_port + 0);
  517. outw(buf_size, ice->ddma_port + 4);
  518. snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
  519. snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
  520. snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
  521. snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
  522. snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
  523. snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
  524. snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
  525. snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
  526. spin_unlock_irq(&ice->reg_lock);
  527. return 0;
  528. }
  529. static int snd_ice1712_playback_ds_prepare(snd_pcm_substream_t * substream)
  530. {
  531. ice1712_t *ice = snd_pcm_substream_chip(substream);
  532. snd_pcm_runtime_t *runtime = substream->runtime;
  533. u32 period_size, buf_size, rate, tmp, chn;
  534. period_size = snd_pcm_lib_period_bytes(substream) - 1;
  535. buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
  536. tmp = 0x0064;
  537. if (snd_pcm_format_width(runtime->format) == 16)
  538. tmp &= ~0x04;
  539. if (runtime->channels == 2)
  540. tmp |= 0x08;
  541. rate = (runtime->rate * 8192) / 375;
  542. if (rate > 0x000fffff)
  543. rate = 0x000fffff;
  544. ice->playback_con_active_buf[substream->number] = 0;
  545. ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
  546. chn = substream->number * 2;
  547. spin_lock_irq(&ice->reg_lock);
  548. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
  549. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
  550. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
  551. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
  552. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
  553. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
  554. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
  555. if (runtime->channels == 2) {
  556. snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
  557. snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
  558. }
  559. spin_unlock_irq(&ice->reg_lock);
  560. return 0;
  561. }
  562. static int snd_ice1712_capture_prepare(snd_pcm_substream_t * substream)
  563. {
  564. ice1712_t *ice = snd_pcm_substream_chip(substream);
  565. snd_pcm_runtime_t *runtime = substream->runtime;
  566. u32 period_size, buf_size;
  567. u8 tmp;
  568. period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
  569. buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
  570. tmp = 0x06;
  571. if (snd_pcm_format_width(runtime->format) == 16)
  572. tmp &= ~0x04;
  573. if (runtime->channels == 2)
  574. tmp &= ~0x02;
  575. spin_lock_irq(&ice->reg_lock);
  576. outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
  577. outw(buf_size, ICEREG(ice, CONCAP_COUNT));
  578. snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
  579. snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
  580. snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
  581. spin_unlock_irq(&ice->reg_lock);
  582. snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
  583. return 0;
  584. }
  585. static snd_pcm_uframes_t snd_ice1712_playback_pointer(snd_pcm_substream_t * substream)
  586. {
  587. ice1712_t *ice = snd_pcm_substream_chip(substream);
  588. snd_pcm_runtime_t *runtime = substream->runtime;
  589. size_t ptr;
  590. if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
  591. return 0;
  592. ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
  593. if (ptr == runtime->buffer_size)
  594. ptr = 0;
  595. return bytes_to_frames(substream->runtime, ptr);
  596. }
  597. static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(snd_pcm_substream_t * substream)
  598. {
  599. ice1712_t *ice = snd_pcm_substream_chip(substream);
  600. u8 addr;
  601. size_t ptr;
  602. if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
  603. return 0;
  604. if (ice->playback_con_active_buf[substream->number])
  605. addr = ICE1712_DSC_ADDR1;
  606. else
  607. addr = ICE1712_DSC_ADDR0;
  608. ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
  609. ice->playback_con_virt_addr[substream->number];
  610. if (ptr == substream->runtime->buffer_size)
  611. ptr = 0;
  612. return bytes_to_frames(substream->runtime, ptr);
  613. }
  614. static snd_pcm_uframes_t snd_ice1712_capture_pointer(snd_pcm_substream_t * substream)
  615. {
  616. ice1712_t *ice = snd_pcm_substream_chip(substream);
  617. size_t ptr;
  618. if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
  619. return 0;
  620. ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
  621. if (ptr == substream->runtime->buffer_size)
  622. ptr = 0;
  623. return bytes_to_frames(substream->runtime, ptr);
  624. }
  625. static snd_pcm_hardware_t snd_ice1712_playback =
  626. {
  627. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  628. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  629. SNDRV_PCM_INFO_MMAP_VALID |
  630. SNDRV_PCM_INFO_PAUSE),
  631. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  632. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  633. .rate_min = 4000,
  634. .rate_max = 48000,
  635. .channels_min = 1,
  636. .channels_max = 2,
  637. .buffer_bytes_max = (64*1024),
  638. .period_bytes_min = 64,
  639. .period_bytes_max = (64*1024),
  640. .periods_min = 1,
  641. .periods_max = 1024,
  642. .fifo_size = 0,
  643. };
  644. static snd_pcm_hardware_t snd_ice1712_playback_ds =
  645. {
  646. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  647. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  648. SNDRV_PCM_INFO_MMAP_VALID |
  649. SNDRV_PCM_INFO_PAUSE),
  650. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  651. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  652. .rate_min = 4000,
  653. .rate_max = 48000,
  654. .channels_min = 1,
  655. .channels_max = 2,
  656. .buffer_bytes_max = (128*1024),
  657. .period_bytes_min = 64,
  658. .period_bytes_max = (128*1024),
  659. .periods_min = 2,
  660. .periods_max = 2,
  661. .fifo_size = 0,
  662. };
  663. static snd_pcm_hardware_t snd_ice1712_capture =
  664. {
  665. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  666. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  667. SNDRV_PCM_INFO_MMAP_VALID),
  668. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  669. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  670. .rate_min = 4000,
  671. .rate_max = 48000,
  672. .channels_min = 1,
  673. .channels_max = 2,
  674. .buffer_bytes_max = (64*1024),
  675. .period_bytes_min = 64,
  676. .period_bytes_max = (64*1024),
  677. .periods_min = 1,
  678. .periods_max = 1024,
  679. .fifo_size = 0,
  680. };
  681. static int snd_ice1712_playback_open(snd_pcm_substream_t * substream)
  682. {
  683. snd_pcm_runtime_t *runtime = substream->runtime;
  684. ice1712_t *ice = snd_pcm_substream_chip(substream);
  685. ice->playback_con_substream = substream;
  686. runtime->hw = snd_ice1712_playback;
  687. return 0;
  688. }
  689. static int snd_ice1712_playback_ds_open(snd_pcm_substream_t * substream)
  690. {
  691. snd_pcm_runtime_t *runtime = substream->runtime;
  692. ice1712_t *ice = snd_pcm_substream_chip(substream);
  693. u32 tmp;
  694. ice->playback_con_substream_ds[substream->number] = substream;
  695. runtime->hw = snd_ice1712_playback_ds;
  696. spin_lock_irq(&ice->reg_lock);
  697. tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
  698. outw(tmp, ICEDS(ice, INTMASK));
  699. spin_unlock_irq(&ice->reg_lock);
  700. return 0;
  701. }
  702. static int snd_ice1712_capture_open(snd_pcm_substream_t * substream)
  703. {
  704. snd_pcm_runtime_t *runtime = substream->runtime;
  705. ice1712_t *ice = snd_pcm_substream_chip(substream);
  706. ice->capture_con_substream = substream;
  707. runtime->hw = snd_ice1712_capture;
  708. runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
  709. if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
  710. runtime->hw.rate_min = 48000;
  711. return 0;
  712. }
  713. static int snd_ice1712_playback_close(snd_pcm_substream_t * substream)
  714. {
  715. ice1712_t *ice = snd_pcm_substream_chip(substream);
  716. ice->playback_con_substream = NULL;
  717. return 0;
  718. }
  719. static int snd_ice1712_playback_ds_close(snd_pcm_substream_t * substream)
  720. {
  721. ice1712_t *ice = snd_pcm_substream_chip(substream);
  722. u32 tmp;
  723. spin_lock_irq(&ice->reg_lock);
  724. tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
  725. outw(tmp, ICEDS(ice, INTMASK));
  726. spin_unlock_irq(&ice->reg_lock);
  727. ice->playback_con_substream_ds[substream->number] = NULL;
  728. return 0;
  729. }
  730. static int snd_ice1712_capture_close(snd_pcm_substream_t * substream)
  731. {
  732. ice1712_t *ice = snd_pcm_substream_chip(substream);
  733. ice->capture_con_substream = NULL;
  734. return 0;
  735. }
  736. static snd_pcm_ops_t snd_ice1712_playback_ops = {
  737. .open = snd_ice1712_playback_open,
  738. .close = snd_ice1712_playback_close,
  739. .ioctl = snd_pcm_lib_ioctl,
  740. .hw_params = snd_ice1712_hw_params,
  741. .hw_free = snd_ice1712_hw_free,
  742. .prepare = snd_ice1712_playback_prepare,
  743. .trigger = snd_ice1712_playback_trigger,
  744. .pointer = snd_ice1712_playback_pointer,
  745. };
  746. static snd_pcm_ops_t snd_ice1712_playback_ds_ops = {
  747. .open = snd_ice1712_playback_ds_open,
  748. .close = snd_ice1712_playback_ds_close,
  749. .ioctl = snd_pcm_lib_ioctl,
  750. .hw_params = snd_ice1712_hw_params,
  751. .hw_free = snd_ice1712_hw_free,
  752. .prepare = snd_ice1712_playback_ds_prepare,
  753. .trigger = snd_ice1712_playback_ds_trigger,
  754. .pointer = snd_ice1712_playback_ds_pointer,
  755. };
  756. static snd_pcm_ops_t snd_ice1712_capture_ops = {
  757. .open = snd_ice1712_capture_open,
  758. .close = snd_ice1712_capture_close,
  759. .ioctl = snd_pcm_lib_ioctl,
  760. .hw_params = snd_ice1712_hw_params,
  761. .hw_free = snd_ice1712_hw_free,
  762. .prepare = snd_ice1712_capture_prepare,
  763. .trigger = snd_ice1712_capture_trigger,
  764. .pointer = snd_ice1712_capture_pointer,
  765. };
  766. static void snd_ice1712_pcm_free(snd_pcm_t *pcm)
  767. {
  768. ice1712_t *ice = pcm->private_data;
  769. ice->pcm = NULL;
  770. snd_pcm_lib_preallocate_free_for_all(pcm);
  771. }
  772. static int __devinit snd_ice1712_pcm(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
  773. {
  774. snd_pcm_t *pcm;
  775. int err;
  776. if (rpcm)
  777. *rpcm = NULL;
  778. err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
  779. if (err < 0)
  780. return err;
  781. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
  782. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
  783. pcm->private_data = ice;
  784. pcm->private_free = snd_ice1712_pcm_free;
  785. pcm->info_flags = 0;
  786. strcpy(pcm->name, "ICE1712 consumer");
  787. ice->pcm = pcm;
  788. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  789. snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
  790. if (rpcm)
  791. *rpcm = pcm;
  792. printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
  793. return 0;
  794. }
  795. static void snd_ice1712_pcm_free_ds(snd_pcm_t *pcm)
  796. {
  797. ice1712_t *ice = pcm->private_data;
  798. ice->pcm_ds = NULL;
  799. snd_pcm_lib_preallocate_free_for_all(pcm);
  800. }
  801. static int __devinit snd_ice1712_pcm_ds(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
  802. {
  803. snd_pcm_t *pcm;
  804. int err;
  805. if (rpcm)
  806. *rpcm = NULL;
  807. err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
  808. if (err < 0)
  809. return err;
  810. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
  811. pcm->private_data = ice;
  812. pcm->private_free = snd_ice1712_pcm_free_ds;
  813. pcm->info_flags = 0;
  814. strcpy(pcm->name, "ICE1712 consumer (DS)");
  815. ice->pcm_ds = pcm;
  816. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  817. snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
  818. if (rpcm)
  819. *rpcm = pcm;
  820. return 0;
  821. }
  822. /*
  823. * PCM code - professional part (multitrack)
  824. */
  825. static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  826. 32000, 44100, 48000, 64000, 88200, 96000 };
  827. static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
  828. .count = ARRAY_SIZE(rates),
  829. .list = rates,
  830. .mask = 0,
  831. };
  832. static int snd_ice1712_pro_trigger(snd_pcm_substream_t *substream,
  833. int cmd)
  834. {
  835. ice1712_t *ice = snd_pcm_substream_chip(substream);
  836. switch (cmd) {
  837. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  838. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  839. {
  840. unsigned int what;
  841. unsigned int old;
  842. if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
  843. return -EINVAL;
  844. what = ICE1712_PLAYBACK_PAUSE;
  845. snd_pcm_trigger_done(substream, substream);
  846. spin_lock(&ice->reg_lock);
  847. old = inl(ICEMT(ice, PLAYBACK_CONTROL));
  848. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  849. old |= what;
  850. else
  851. old &= ~what;
  852. outl(old, ICEMT(ice, PLAYBACK_CONTROL));
  853. spin_unlock(&ice->reg_lock);
  854. break;
  855. }
  856. case SNDRV_PCM_TRIGGER_START:
  857. case SNDRV_PCM_TRIGGER_STOP:
  858. {
  859. unsigned int what = 0;
  860. unsigned int old;
  861. struct list_head *pos;
  862. snd_pcm_substream_t *s;
  863. snd_pcm_group_for_each(pos, substream) {
  864. s = snd_pcm_group_substream_entry(pos);
  865. if (s == ice->playback_pro_substream) {
  866. what |= ICE1712_PLAYBACK_START;
  867. snd_pcm_trigger_done(s, substream);
  868. } else if (s == ice->capture_pro_substream) {
  869. what |= ICE1712_CAPTURE_START_SHADOW;
  870. snd_pcm_trigger_done(s, substream);
  871. }
  872. }
  873. spin_lock(&ice->reg_lock);
  874. old = inl(ICEMT(ice, PLAYBACK_CONTROL));
  875. if (cmd == SNDRV_PCM_TRIGGER_START)
  876. old |= what;
  877. else
  878. old &= ~what;
  879. outl(old, ICEMT(ice, PLAYBACK_CONTROL));
  880. spin_unlock(&ice->reg_lock);
  881. break;
  882. }
  883. default:
  884. return -EINVAL;
  885. }
  886. return 0;
  887. }
  888. /*
  889. */
  890. static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
  891. {
  892. unsigned long flags;
  893. unsigned char val, old;
  894. unsigned int i;
  895. switch (rate) {
  896. case 8000: val = 6; break;
  897. case 9600: val = 3; break;
  898. case 11025: val = 10; break;
  899. case 12000: val = 2; break;
  900. case 16000: val = 5; break;
  901. case 22050: val = 9; break;
  902. case 24000: val = 1; break;
  903. case 32000: val = 4; break;
  904. case 44100: val = 8; break;
  905. case 48000: val = 0; break;
  906. case 64000: val = 15; break;
  907. case 88200: val = 11; break;
  908. case 96000: val = 7; break;
  909. default:
  910. snd_BUG();
  911. val = 0;
  912. rate = 48000;
  913. break;
  914. }
  915. spin_lock_irqsave(&ice->reg_lock, flags);
  916. if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
  917. ICE1712_PLAYBACK_PAUSE|
  918. ICE1712_PLAYBACK_START)) {
  919. __out:
  920. spin_unlock_irqrestore(&ice->reg_lock, flags);
  921. return;
  922. }
  923. if (!force && is_pro_rate_locked(ice))
  924. goto __out;
  925. old = inb(ICEMT(ice, RATE));
  926. if (!force && old == val)
  927. goto __out;
  928. outb(val, ICEMT(ice, RATE));
  929. spin_unlock_irqrestore(&ice->reg_lock, flags);
  930. if (ice->gpio.set_pro_rate)
  931. ice->gpio.set_pro_rate(ice, rate);
  932. for (i = 0; i < ice->akm_codecs; i++) {
  933. if (ice->akm[i].ops.set_rate_val)
  934. ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
  935. }
  936. if (ice->spdif.ops.setup_rate)
  937. ice->spdif.ops.setup_rate(ice, rate);
  938. }
  939. static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
  940. {
  941. ice1712_t *ice = snd_pcm_substream_chip(substream);
  942. ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
  943. spin_lock_irq(&ice->reg_lock);
  944. outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
  945. outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
  946. outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
  947. spin_unlock_irq(&ice->reg_lock);
  948. return 0;
  949. }
  950. static int snd_ice1712_playback_pro_hw_params(snd_pcm_substream_t * substream,
  951. snd_pcm_hw_params_t * hw_params)
  952. {
  953. ice1712_t *ice = snd_pcm_substream_chip(substream);
  954. snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
  955. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  956. }
  957. static int snd_ice1712_capture_pro_prepare(snd_pcm_substream_t * substream)
  958. {
  959. ice1712_t *ice = snd_pcm_substream_chip(substream);
  960. ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
  961. spin_lock_irq(&ice->reg_lock);
  962. outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
  963. outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
  964. outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
  965. spin_unlock_irq(&ice->reg_lock);
  966. return 0;
  967. }
  968. static int snd_ice1712_capture_pro_hw_params(snd_pcm_substream_t * substream,
  969. snd_pcm_hw_params_t * hw_params)
  970. {
  971. ice1712_t *ice = snd_pcm_substream_chip(substream);
  972. snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
  973. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  974. }
  975. static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(snd_pcm_substream_t * substream)
  976. {
  977. ice1712_t *ice = snd_pcm_substream_chip(substream);
  978. size_t ptr;
  979. if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
  980. return 0;
  981. ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
  982. if (ptr == substream->runtime->buffer_size)
  983. ptr = 0;
  984. return bytes_to_frames(substream->runtime, ptr);
  985. }
  986. static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(snd_pcm_substream_t * substream)
  987. {
  988. ice1712_t *ice = snd_pcm_substream_chip(substream);
  989. size_t ptr;
  990. if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
  991. return 0;
  992. ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
  993. if (ptr == substream->runtime->buffer_size)
  994. ptr = 0;
  995. return bytes_to_frames(substream->runtime, ptr);
  996. }
  997. static snd_pcm_hardware_t snd_ice1712_playback_pro =
  998. {
  999. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1000. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1001. SNDRV_PCM_INFO_MMAP_VALID |
  1002. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  1003. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  1004. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
  1005. .rate_min = 4000,
  1006. .rate_max = 96000,
  1007. .channels_min = 10,
  1008. .channels_max = 10,
  1009. .buffer_bytes_max = (256*1024),
  1010. .period_bytes_min = 10 * 4 * 2,
  1011. .period_bytes_max = 131040,
  1012. .periods_min = 1,
  1013. .periods_max = 1024,
  1014. .fifo_size = 0,
  1015. };
  1016. static snd_pcm_hardware_t snd_ice1712_capture_pro =
  1017. {
  1018. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1019. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1020. SNDRV_PCM_INFO_MMAP_VALID |
  1021. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  1022. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  1023. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
  1024. .rate_min = 4000,
  1025. .rate_max = 96000,
  1026. .channels_min = 12,
  1027. .channels_max = 12,
  1028. .buffer_bytes_max = (256*1024),
  1029. .period_bytes_min = 12 * 4 * 2,
  1030. .period_bytes_max = 131040,
  1031. .periods_min = 1,
  1032. .periods_max = 1024,
  1033. .fifo_size = 0,
  1034. };
  1035. static int snd_ice1712_playback_pro_open(snd_pcm_substream_t * substream)
  1036. {
  1037. snd_pcm_runtime_t *runtime = substream->runtime;
  1038. ice1712_t *ice = snd_pcm_substream_chip(substream);
  1039. ice->playback_pro_substream = substream;
  1040. runtime->hw = snd_ice1712_playback_pro;
  1041. snd_pcm_set_sync(substream);
  1042. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1043. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
  1044. if (ice->spdif.ops.open)
  1045. ice->spdif.ops.open(ice, substream);
  1046. return 0;
  1047. }
  1048. static int snd_ice1712_capture_pro_open(snd_pcm_substream_t * substream)
  1049. {
  1050. ice1712_t *ice = snd_pcm_substream_chip(substream);
  1051. snd_pcm_runtime_t *runtime = substream->runtime;
  1052. ice->capture_pro_substream = substream;
  1053. runtime->hw = snd_ice1712_capture_pro;
  1054. snd_pcm_set_sync(substream);
  1055. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1056. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
  1057. return 0;
  1058. }
  1059. static int snd_ice1712_playback_pro_close(snd_pcm_substream_t * substream)
  1060. {
  1061. ice1712_t *ice = snd_pcm_substream_chip(substream);
  1062. if (PRO_RATE_RESET)
  1063. snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  1064. ice->playback_pro_substream = NULL;
  1065. if (ice->spdif.ops.close)
  1066. ice->spdif.ops.close(ice, substream);
  1067. return 0;
  1068. }
  1069. static int snd_ice1712_capture_pro_close(snd_pcm_substream_t * substream)
  1070. {
  1071. ice1712_t *ice = snd_pcm_substream_chip(substream);
  1072. if (PRO_RATE_RESET)
  1073. snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  1074. ice->capture_pro_substream = NULL;
  1075. return 0;
  1076. }
  1077. static void snd_ice1712_pcm_profi_free(snd_pcm_t *pcm)
  1078. {
  1079. ice1712_t *ice = pcm->private_data;
  1080. ice->pcm_pro = NULL;
  1081. snd_pcm_lib_preallocate_free_for_all(pcm);
  1082. }
  1083. static snd_pcm_ops_t snd_ice1712_playback_pro_ops = {
  1084. .open = snd_ice1712_playback_pro_open,
  1085. .close = snd_ice1712_playback_pro_close,
  1086. .ioctl = snd_pcm_lib_ioctl,
  1087. .hw_params = snd_ice1712_playback_pro_hw_params,
  1088. .hw_free = snd_ice1712_hw_free,
  1089. .prepare = snd_ice1712_playback_pro_prepare,
  1090. .trigger = snd_ice1712_pro_trigger,
  1091. .pointer = snd_ice1712_playback_pro_pointer,
  1092. };
  1093. static snd_pcm_ops_t snd_ice1712_capture_pro_ops = {
  1094. .open = snd_ice1712_capture_pro_open,
  1095. .close = snd_ice1712_capture_pro_close,
  1096. .ioctl = snd_pcm_lib_ioctl,
  1097. .hw_params = snd_ice1712_capture_pro_hw_params,
  1098. .hw_free = snd_ice1712_hw_free,
  1099. .prepare = snd_ice1712_capture_pro_prepare,
  1100. .trigger = snd_ice1712_pro_trigger,
  1101. .pointer = snd_ice1712_capture_pro_pointer,
  1102. };
  1103. static int __devinit snd_ice1712_pcm_profi(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
  1104. {
  1105. snd_pcm_t *pcm;
  1106. int err;
  1107. if (rpcm)
  1108. *rpcm = NULL;
  1109. err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
  1110. if (err < 0)
  1111. return err;
  1112. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
  1113. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
  1114. pcm->private_data = ice;
  1115. pcm->private_free = snd_ice1712_pcm_profi_free;
  1116. pcm->info_flags = 0;
  1117. strcpy(pcm->name, "ICE1712 multi");
  1118. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1119. snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
  1120. ice->pcm_pro = pcm;
  1121. if (rpcm)
  1122. *rpcm = pcm;
  1123. if (ice->cs8427) {
  1124. /* assign channels to iec958 */
  1125. err = snd_cs8427_iec958_build(ice->cs8427,
  1126. pcm->streams[0].substream,
  1127. pcm->streams[1].substream);
  1128. if (err < 0)
  1129. return err;
  1130. }
  1131. if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
  1132. return err;
  1133. return 0;
  1134. }
  1135. /*
  1136. * Mixer section
  1137. */
  1138. static void snd_ice1712_update_volume(ice1712_t *ice, int index)
  1139. {
  1140. unsigned int vol = ice->pro_volumes[index];
  1141. unsigned short val = 0;
  1142. val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
  1143. val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
  1144. outb(index, ICEMT(ice, MONITOR_INDEX));
  1145. outw(val, ICEMT(ice, MONITOR_VOLUME));
  1146. }
  1147. static int snd_ice1712_pro_mixer_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1148. {
  1149. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1150. uinfo->count = 2;
  1151. uinfo->value.integer.min = 0;
  1152. uinfo->value.integer.max = 1;
  1153. return 0;
  1154. }
  1155. static int snd_ice1712_pro_mixer_switch_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1156. {
  1157. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1158. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1159. spin_lock_irq(&ice->reg_lock);
  1160. ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
  1161. ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
  1162. spin_unlock_irq(&ice->reg_lock);
  1163. return 0;
  1164. }
  1165. static int snd_ice1712_pro_mixer_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1166. {
  1167. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1168. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1169. unsigned int nval, change;
  1170. nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
  1171. (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
  1172. spin_lock_irq(&ice->reg_lock);
  1173. nval |= ice->pro_volumes[index] & ~0x80008000;
  1174. change = nval != ice->pro_volumes[index];
  1175. ice->pro_volumes[index] = nval;
  1176. snd_ice1712_update_volume(ice, index);
  1177. spin_unlock_irq(&ice->reg_lock);
  1178. return change;
  1179. }
  1180. static int snd_ice1712_pro_mixer_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1181. {
  1182. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1183. uinfo->count = 2;
  1184. uinfo->value.integer.min = 0;
  1185. uinfo->value.integer.max = 96;
  1186. return 0;
  1187. }
  1188. static int snd_ice1712_pro_mixer_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1189. {
  1190. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1191. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1192. spin_lock_irq(&ice->reg_lock);
  1193. ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
  1194. ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
  1195. spin_unlock_irq(&ice->reg_lock);
  1196. return 0;
  1197. }
  1198. static int snd_ice1712_pro_mixer_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1199. {
  1200. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1201. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1202. unsigned int nval, change;
  1203. nval = (ucontrol->value.integer.value[0] & 127) |
  1204. ((ucontrol->value.integer.value[1] & 127) << 16);
  1205. spin_lock_irq(&ice->reg_lock);
  1206. nval |= ice->pro_volumes[index] & ~0x007f007f;
  1207. change = nval != ice->pro_volumes[index];
  1208. ice->pro_volumes[index] = nval;
  1209. snd_ice1712_update_volume(ice, index);
  1210. spin_unlock_irq(&ice->reg_lock);
  1211. return change;
  1212. }
  1213. static snd_kcontrol_new_t snd_ice1712_multi_playback_ctrls[] __devinitdata = {
  1214. {
  1215. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1216. .name = "Multi Playback Switch",
  1217. .info = snd_ice1712_pro_mixer_switch_info,
  1218. .get = snd_ice1712_pro_mixer_switch_get,
  1219. .put = snd_ice1712_pro_mixer_switch_put,
  1220. .private_value = 0,
  1221. .count = 10,
  1222. },
  1223. {
  1224. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1225. .name = "Multi Playback Volume",
  1226. .info = snd_ice1712_pro_mixer_volume_info,
  1227. .get = snd_ice1712_pro_mixer_volume_get,
  1228. .put = snd_ice1712_pro_mixer_volume_put,
  1229. .private_value = 0,
  1230. .count = 10,
  1231. },
  1232. };
  1233. static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_switch __devinitdata = {
  1234. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1235. .name = "H/W Multi Capture Switch",
  1236. .info = snd_ice1712_pro_mixer_switch_info,
  1237. .get = snd_ice1712_pro_mixer_switch_get,
  1238. .put = snd_ice1712_pro_mixer_switch_put,
  1239. .private_value = 10,
  1240. };
  1241. static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_switch __devinitdata = {
  1242. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1243. .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
  1244. .info = snd_ice1712_pro_mixer_switch_info,
  1245. .get = snd_ice1712_pro_mixer_switch_get,
  1246. .put = snd_ice1712_pro_mixer_switch_put,
  1247. .private_value = 18,
  1248. .count = 2,
  1249. };
  1250. static snd_kcontrol_new_t snd_ice1712_multi_capture_analog_volume __devinitdata = {
  1251. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1252. .name = "H/W Multi Capture Volume",
  1253. .info = snd_ice1712_pro_mixer_volume_info,
  1254. .get = snd_ice1712_pro_mixer_volume_get,
  1255. .put = snd_ice1712_pro_mixer_volume_put,
  1256. .private_value = 10,
  1257. };
  1258. static snd_kcontrol_new_t snd_ice1712_multi_capture_spdif_volume __devinitdata = {
  1259. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1260. .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
  1261. .info = snd_ice1712_pro_mixer_volume_info,
  1262. .get = snd_ice1712_pro_mixer_volume_get,
  1263. .put = snd_ice1712_pro_mixer_volume_put,
  1264. .private_value = 18,
  1265. .count = 2,
  1266. };
  1267. static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
  1268. {
  1269. snd_card_t * card = ice->card;
  1270. unsigned int idx;
  1271. int err;
  1272. /* multi-channel mixer */
  1273. for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
  1274. err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
  1275. if (err < 0)
  1276. return err;
  1277. }
  1278. if (ice->num_total_adcs > 0) {
  1279. snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_switch;
  1280. tmp.count = ice->num_total_adcs;
  1281. err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
  1282. if (err < 0)
  1283. return err;
  1284. }
  1285. err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
  1286. if (err < 0)
  1287. return err;
  1288. if (ice->num_total_adcs > 0) {
  1289. snd_kcontrol_new_t tmp = snd_ice1712_multi_capture_analog_volume;
  1290. tmp.count = ice->num_total_adcs;
  1291. err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
  1292. if (err < 0)
  1293. return err;
  1294. }
  1295. err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
  1296. if (err < 0)
  1297. return err;
  1298. /* initialize volumes */
  1299. for (idx = 0; idx < 10; idx++) {
  1300. ice->pro_volumes[idx] = 0x80008000; /* mute */
  1301. snd_ice1712_update_volume(ice, idx);
  1302. }
  1303. for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
  1304. ice->pro_volumes[idx] = 0x80008000; /* mute */
  1305. snd_ice1712_update_volume(ice, idx);
  1306. }
  1307. for (idx = 18; idx < 20; idx++) {
  1308. ice->pro_volumes[idx] = 0x80008000; /* mute */
  1309. snd_ice1712_update_volume(ice, idx);
  1310. }
  1311. return 0;
  1312. }
  1313. static void snd_ice1712_mixer_free_ac97(ac97_t *ac97)
  1314. {
  1315. ice1712_t *ice = ac97->private_data;
  1316. ice->ac97 = NULL;
  1317. }
  1318. static int __devinit snd_ice1712_ac97_mixer(ice1712_t * ice)
  1319. {
  1320. int err, bus_num = 0;
  1321. ac97_template_t ac97;
  1322. ac97_bus_t *pbus;
  1323. static ac97_bus_ops_t con_ops = {
  1324. .write = snd_ice1712_ac97_write,
  1325. .read = snd_ice1712_ac97_read,
  1326. };
  1327. static ac97_bus_ops_t pro_ops = {
  1328. .write = snd_ice1712_pro_ac97_write,
  1329. .read = snd_ice1712_pro_ac97_read,
  1330. };
  1331. if (ice_has_con_ac97(ice)) {
  1332. if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
  1333. return err;
  1334. memset(&ac97, 0, sizeof(ac97));
  1335. ac97.private_data = ice;
  1336. ac97.private_free = snd_ice1712_mixer_free_ac97;
  1337. if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
  1338. printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
  1339. else {
  1340. if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
  1341. return err;
  1342. return 0;
  1343. }
  1344. }
  1345. if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
  1346. if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
  1347. return err;
  1348. memset(&ac97, 0, sizeof(ac97));
  1349. ac97.private_data = ice;
  1350. ac97.private_free = snd_ice1712_mixer_free_ac97;
  1351. if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
  1352. printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
  1353. else
  1354. return 0;
  1355. }
  1356. /* I2S mixer only */
  1357. strcat(ice->card->mixername, "ICE1712 - multitrack");
  1358. return 0;
  1359. }
  1360. /*
  1361. *
  1362. */
  1363. static inline unsigned int eeprom_double(ice1712_t *ice, int idx)
  1364. {
  1365. return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
  1366. }
  1367. static void snd_ice1712_proc_read(snd_info_entry_t *entry,
  1368. snd_info_buffer_t * buffer)
  1369. {
  1370. ice1712_t *ice = entry->private_data;
  1371. unsigned int idx;
  1372. snd_iprintf(buffer, "%s\n\n", ice->card->longname);
  1373. snd_iprintf(buffer, "EEPROM:\n");
  1374. snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
  1375. snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
  1376. snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
  1377. snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
  1378. snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
  1379. snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
  1380. snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
  1381. snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
  1382. snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
  1383. snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
  1384. snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
  1385. snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
  1386. snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
  1387. snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
  1388. for (idx = 0; idx < 4; idx++)
  1389. snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
  1390. for (idx = 0; idx < 4; idx++)
  1391. snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
  1392. for (idx = 0x1c; idx < ice->eeprom.size; idx++)
  1393. snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
  1394. snd_iprintf(buffer, "\nRegisters:\n");
  1395. snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
  1396. snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
  1397. snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
  1398. snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
  1399. }
  1400. static void __devinit snd_ice1712_proc_init(ice1712_t * ice)
  1401. {
  1402. snd_info_entry_t *entry;
  1403. if (! snd_card_proc_new(ice->card, "ice1712", &entry))
  1404. snd_info_set_text_ops(entry, ice, 1024, snd_ice1712_proc_read);
  1405. }
  1406. /*
  1407. *
  1408. */
  1409. static int snd_ice1712_eeprom_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1410. {
  1411. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1412. uinfo->count = sizeof(ice1712_eeprom_t);
  1413. return 0;
  1414. }
  1415. static int snd_ice1712_eeprom_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1416. {
  1417. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1418. memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
  1419. return 0;
  1420. }
  1421. static snd_kcontrol_new_t snd_ice1712_eeprom __devinitdata = {
  1422. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1423. .name = "ICE1712 EEPROM",
  1424. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1425. .info = snd_ice1712_eeprom_info,
  1426. .get = snd_ice1712_eeprom_get
  1427. };
  1428. /*
  1429. */
  1430. static int snd_ice1712_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1431. {
  1432. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1433. uinfo->count = 1;
  1434. return 0;
  1435. }
  1436. static int snd_ice1712_spdif_default_get(snd_kcontrol_t * kcontrol,
  1437. snd_ctl_elem_value_t * ucontrol)
  1438. {
  1439. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1440. if (ice->spdif.ops.default_get)
  1441. ice->spdif.ops.default_get(ice, ucontrol);
  1442. return 0;
  1443. }
  1444. static int snd_ice1712_spdif_default_put(snd_kcontrol_t * kcontrol,
  1445. snd_ctl_elem_value_t * ucontrol)
  1446. {
  1447. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1448. if (ice->spdif.ops.default_put)
  1449. return ice->spdif.ops.default_put(ice, ucontrol);
  1450. return 0;
  1451. }
  1452. static snd_kcontrol_new_t snd_ice1712_spdif_default __devinitdata =
  1453. {
  1454. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1455. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  1456. .info = snd_ice1712_spdif_info,
  1457. .get = snd_ice1712_spdif_default_get,
  1458. .put = snd_ice1712_spdif_default_put
  1459. };
  1460. static int snd_ice1712_spdif_maskc_get(snd_kcontrol_t * kcontrol,
  1461. snd_ctl_elem_value_t * ucontrol)
  1462. {
  1463. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1464. if (ice->spdif.ops.default_get) {
  1465. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1466. IEC958_AES0_PROFESSIONAL |
  1467. IEC958_AES0_CON_NOT_COPYRIGHT |
  1468. IEC958_AES0_CON_EMPHASIS;
  1469. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
  1470. IEC958_AES1_CON_CATEGORY;
  1471. ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
  1472. } else {
  1473. ucontrol->value.iec958.status[0] = 0xff;
  1474. ucontrol->value.iec958.status[1] = 0xff;
  1475. ucontrol->value.iec958.status[2] = 0xff;
  1476. ucontrol->value.iec958.status[3] = 0xff;
  1477. ucontrol->value.iec958.status[4] = 0xff;
  1478. }
  1479. return 0;
  1480. }
  1481. static int snd_ice1712_spdif_maskp_get(snd_kcontrol_t * kcontrol,
  1482. snd_ctl_elem_value_t * ucontrol)
  1483. {
  1484. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1485. if (ice->spdif.ops.default_get) {
  1486. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1487. IEC958_AES0_PROFESSIONAL |
  1488. IEC958_AES0_PRO_FS |
  1489. IEC958_AES0_PRO_EMPHASIS;
  1490. ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
  1491. } else {
  1492. ucontrol->value.iec958.status[0] = 0xff;
  1493. ucontrol->value.iec958.status[1] = 0xff;
  1494. ucontrol->value.iec958.status[2] = 0xff;
  1495. ucontrol->value.iec958.status[3] = 0xff;
  1496. ucontrol->value.iec958.status[4] = 0xff;
  1497. }
  1498. return 0;
  1499. }
  1500. static snd_kcontrol_new_t snd_ice1712_spdif_maskc __devinitdata =
  1501. {
  1502. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1503. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1504. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  1505. .info = snd_ice1712_spdif_info,
  1506. .get = snd_ice1712_spdif_maskc_get,
  1507. };
  1508. static snd_kcontrol_new_t snd_ice1712_spdif_maskp __devinitdata =
  1509. {
  1510. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1511. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1512. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  1513. .info = snd_ice1712_spdif_info,
  1514. .get = snd_ice1712_spdif_maskp_get,
  1515. };
  1516. static int snd_ice1712_spdif_stream_get(snd_kcontrol_t * kcontrol,
  1517. snd_ctl_elem_value_t * ucontrol)
  1518. {
  1519. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1520. if (ice->spdif.ops.stream_get)
  1521. ice->spdif.ops.stream_get(ice, ucontrol);
  1522. return 0;
  1523. }
  1524. static int snd_ice1712_spdif_stream_put(snd_kcontrol_t * kcontrol,
  1525. snd_ctl_elem_value_t * ucontrol)
  1526. {
  1527. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1528. if (ice->spdif.ops.stream_put)
  1529. return ice->spdif.ops.stream_put(ice, ucontrol);
  1530. return 0;
  1531. }
  1532. static snd_kcontrol_new_t snd_ice1712_spdif_stream __devinitdata =
  1533. {
  1534. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  1535. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1536. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  1537. .info = snd_ice1712_spdif_info,
  1538. .get = snd_ice1712_spdif_stream_get,
  1539. .put = snd_ice1712_spdif_stream_put
  1540. };
  1541. int snd_ice1712_gpio_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1542. {
  1543. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1544. uinfo->count = 1;
  1545. uinfo->value.integer.min = 0;
  1546. uinfo->value.integer.max = 1;
  1547. return 0;
  1548. }
  1549. int snd_ice1712_gpio_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1550. {
  1551. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1552. unsigned char mask = kcontrol->private_value & 0xff;
  1553. int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
  1554. snd_ice1712_save_gpio_status(ice);
  1555. ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
  1556. snd_ice1712_restore_gpio_status(ice);
  1557. return 0;
  1558. }
  1559. int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1560. {
  1561. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1562. unsigned char mask = kcontrol->private_value & 0xff;
  1563. int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
  1564. unsigned int val, nval;
  1565. if (kcontrol->private_value & (1 << 31))
  1566. return -EPERM;
  1567. nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
  1568. snd_ice1712_save_gpio_status(ice);
  1569. val = snd_ice1712_gpio_read(ice);
  1570. nval |= val & ~mask;
  1571. if (val != nval)
  1572. snd_ice1712_gpio_write(ice, nval);
  1573. snd_ice1712_restore_gpio_status(ice);
  1574. return val != nval;
  1575. }
  1576. /*
  1577. * rate
  1578. */
  1579. static int snd_ice1712_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1580. {
  1581. static char *texts[] = {
  1582. "8000", /* 0: 6 */
  1583. "9600", /* 1: 3 */
  1584. "11025", /* 2: 10 */
  1585. "12000", /* 3: 2 */
  1586. "16000", /* 4: 5 */
  1587. "22050", /* 5: 9 */
  1588. "24000", /* 6: 1 */
  1589. "32000", /* 7: 4 */
  1590. "44100", /* 8: 8 */
  1591. "48000", /* 9: 0 */
  1592. "64000", /* 10: 15 */
  1593. "88200", /* 11: 11 */
  1594. "96000", /* 12: 7 */
  1595. "IEC958 Input", /* 13: -- */
  1596. };
  1597. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1598. uinfo->count = 1;
  1599. uinfo->value.enumerated.items = 14;
  1600. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1601. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1602. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1603. return 0;
  1604. }
  1605. static int snd_ice1712_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1606. {
  1607. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1608. static unsigned char xlate[16] = {
  1609. 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
  1610. };
  1611. unsigned char val;
  1612. spin_lock_irq(&ice->reg_lock);
  1613. if (is_spdif_master(ice)) {
  1614. ucontrol->value.enumerated.item[0] = 13;
  1615. } else {
  1616. val = xlate[inb(ICEMT(ice, RATE)) & 15];
  1617. if (val == 255) {
  1618. snd_BUG();
  1619. val = 0;
  1620. }
  1621. ucontrol->value.enumerated.item[0] = val;
  1622. }
  1623. spin_unlock_irq(&ice->reg_lock);
  1624. return 0;
  1625. }
  1626. static int snd_ice1712_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1627. {
  1628. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1629. static unsigned int xrate[13] = {
  1630. 8000, 9600, 11025, 12000, 1600, 22050, 24000,
  1631. 32000, 44100, 48000, 64000, 88200, 96000
  1632. };
  1633. unsigned char oval;
  1634. int change = 0;
  1635. spin_lock_irq(&ice->reg_lock);
  1636. oval = inb(ICEMT(ice, RATE));
  1637. if (ucontrol->value.enumerated.item[0] == 13) {
  1638. outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
  1639. } else {
  1640. PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
  1641. spin_unlock_irq(&ice->reg_lock);
  1642. snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
  1643. spin_lock_irq(&ice->reg_lock);
  1644. }
  1645. change = inb(ICEMT(ice, RATE)) != oval;
  1646. spin_unlock_irq(&ice->reg_lock);
  1647. if ((oval & ICE1712_SPDIF_MASTER) != (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
  1648. /* change CS8427 clock source too */
  1649. if (ice->cs8427) {
  1650. snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
  1651. }
  1652. /* notify ak4524 chip as well */
  1653. if (is_spdif_master(ice)) {
  1654. unsigned int i;
  1655. for (i = 0; i < ice->akm_codecs; i++) {
  1656. if (ice->akm[i].ops.set_rate_val)
  1657. ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
  1658. }
  1659. }
  1660. }
  1661. return change;
  1662. }
  1663. static snd_kcontrol_new_t snd_ice1712_pro_internal_clock __devinitdata = {
  1664. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1665. .name = "Multi Track Internal Clock",
  1666. .info = snd_ice1712_pro_internal_clock_info,
  1667. .get = snd_ice1712_pro_internal_clock_get,
  1668. .put = snd_ice1712_pro_internal_clock_put
  1669. };
  1670. static int snd_ice1712_pro_internal_clock_default_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1671. {
  1672. static char *texts[] = {
  1673. "8000", /* 0: 6 */
  1674. "9600", /* 1: 3 */
  1675. "11025", /* 2: 10 */
  1676. "12000", /* 3: 2 */
  1677. "16000", /* 4: 5 */
  1678. "22050", /* 5: 9 */
  1679. "24000", /* 6: 1 */
  1680. "32000", /* 7: 4 */
  1681. "44100", /* 8: 8 */
  1682. "48000", /* 9: 0 */
  1683. "64000", /* 10: 15 */
  1684. "88200", /* 11: 11 */
  1685. "96000", /* 12: 7 */
  1686. // "IEC958 Input", /* 13: -- */
  1687. };
  1688. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1689. uinfo->count = 1;
  1690. uinfo->value.enumerated.items = 13;
  1691. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1692. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1693. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1694. return 0;
  1695. }
  1696. static int snd_ice1712_pro_internal_clock_default_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1697. {
  1698. int val;
  1699. static unsigned int xrate[13] = {
  1700. 8000, 9600, 11025, 12000, 1600, 22050, 24000,
  1701. 32000, 44100, 48000, 64000, 88200, 96000
  1702. };
  1703. for (val = 0; val < 13; val++) {
  1704. if (xrate[val] == PRO_RATE_DEFAULT)
  1705. break;
  1706. }
  1707. ucontrol->value.enumerated.item[0] = val;
  1708. return 0;
  1709. }
  1710. static int snd_ice1712_pro_internal_clock_default_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1711. {
  1712. static unsigned int xrate[13] = {
  1713. 8000, 9600, 11025, 12000, 1600, 22050, 24000,
  1714. 32000, 44100, 48000, 64000, 88200, 96000
  1715. };
  1716. unsigned char oval;
  1717. int change = 0;
  1718. oval = PRO_RATE_DEFAULT;
  1719. PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
  1720. change = PRO_RATE_DEFAULT != oval;
  1721. return change;
  1722. }
  1723. static snd_kcontrol_new_t snd_ice1712_pro_internal_clock_default __devinitdata = {
  1724. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1725. .name = "Multi Track Internal Clock Default",
  1726. .info = snd_ice1712_pro_internal_clock_default_info,
  1727. .get = snd_ice1712_pro_internal_clock_default_get,
  1728. .put = snd_ice1712_pro_internal_clock_default_put
  1729. };
  1730. static int snd_ice1712_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1731. {
  1732. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1733. uinfo->count = 1;
  1734. uinfo->value.integer.min = 0;
  1735. uinfo->value.integer.max = 1;
  1736. return 0;
  1737. }
  1738. static int snd_ice1712_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1739. {
  1740. ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
  1741. return 0;
  1742. }
  1743. static int snd_ice1712_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1744. {
  1745. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1746. int change = 0, nval;
  1747. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1748. spin_lock_irq(&ice->reg_lock);
  1749. change = PRO_RATE_LOCKED != nval;
  1750. PRO_RATE_LOCKED = nval;
  1751. spin_unlock_irq(&ice->reg_lock);
  1752. return change;
  1753. }
  1754. static snd_kcontrol_new_t snd_ice1712_pro_rate_locking __devinitdata = {
  1755. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1756. .name = "Multi Track Rate Locking",
  1757. .info = snd_ice1712_pro_rate_locking_info,
  1758. .get = snd_ice1712_pro_rate_locking_get,
  1759. .put = snd_ice1712_pro_rate_locking_put
  1760. };
  1761. static int snd_ice1712_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1762. {
  1763. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1764. uinfo->count = 1;
  1765. uinfo->value.integer.min = 0;
  1766. uinfo->value.integer.max = 1;
  1767. return 0;
  1768. }
  1769. static int snd_ice1712_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1770. {
  1771. ucontrol->value.integer.value[0] = PRO_RATE_RESET;
  1772. return 0;
  1773. }
  1774. static int snd_ice1712_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1775. {
  1776. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1777. int change = 0, nval;
  1778. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1779. spin_lock_irq(&ice->reg_lock);
  1780. change = PRO_RATE_RESET != nval;
  1781. PRO_RATE_RESET = nval;
  1782. spin_unlock_irq(&ice->reg_lock);
  1783. return change;
  1784. }
  1785. static snd_kcontrol_new_t snd_ice1712_pro_rate_reset __devinitdata = {
  1786. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1787. .name = "Multi Track Rate Reset",
  1788. .info = snd_ice1712_pro_rate_reset_info,
  1789. .get = snd_ice1712_pro_rate_reset_get,
  1790. .put = snd_ice1712_pro_rate_reset_put
  1791. };
  1792. /*
  1793. * routing
  1794. */
  1795. static int snd_ice1712_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1796. {
  1797. static char *texts[] = {
  1798. "PCM Out", /* 0 */
  1799. "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
  1800. "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
  1801. "IEC958 In L", "IEC958 In R", /* 9-10 */
  1802. "Digital Mixer", /* 11 - optional */
  1803. };
  1804. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1805. uinfo->count = 1;
  1806. uinfo->value.enumerated.items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
  1807. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1808. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1809. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1810. return 0;
  1811. }
  1812. static int snd_ice1712_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
  1813. {
  1814. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1815. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1816. unsigned int val, cval;
  1817. spin_lock_irq(&ice->reg_lock);
  1818. val = inw(ICEMT(ice, ROUTE_PSDOUT03));
  1819. cval = inl(ICEMT(ice, ROUTE_CAPTURE));
  1820. spin_unlock_irq(&ice->reg_lock);
  1821. val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
  1822. val &= 3;
  1823. cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
  1824. if (val == 1 && idx < 2)
  1825. ucontrol->value.enumerated.item[0] = 11;
  1826. else if (val == 2)
  1827. ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
  1828. else if (val == 3)
  1829. ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
  1830. else
  1831. ucontrol->value.enumerated.item[0] = 0;
  1832. return 0;
  1833. }
  1834. static int snd_ice1712_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
  1835. {
  1836. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1837. int change, shift;
  1838. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1839. unsigned int val, old_val, nval;
  1840. /* update PSDOUT */
  1841. if (ucontrol->value.enumerated.item[0] >= 11)
  1842. nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
  1843. else if (ucontrol->value.enumerated.item[0] >= 9)
  1844. nval = 3; /* spdif in */
  1845. else if (ucontrol->value.enumerated.item[0] >= 1)
  1846. nval = 2; /* analog in */
  1847. else
  1848. nval = 0; /* pcm */
  1849. shift = ((idx % 2) * 8) + ((idx / 2) * 2);
  1850. spin_lock_irq(&ice->reg_lock);
  1851. val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
  1852. val &= ~(0x03 << shift);
  1853. val |= nval << shift;
  1854. change = val != old_val;
  1855. if (change)
  1856. outw(val, ICEMT(ice, ROUTE_PSDOUT03));
  1857. spin_unlock_irq(&ice->reg_lock);
  1858. if (nval < 2) /* dig mixer of pcm */
  1859. return change;
  1860. /* update CAPTURE */
  1861. spin_lock_irq(&ice->reg_lock);
  1862. val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
  1863. shift = ((idx / 2) * 8) + ((idx % 2) * 4);
  1864. if (nval == 2) { /* analog in */
  1865. nval = ucontrol->value.enumerated.item[0] - 1;
  1866. val &= ~(0x07 << shift);
  1867. val |= nval << shift;
  1868. } else { /* spdif in */
  1869. nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
  1870. val &= ~(0x08 << shift);
  1871. val |= nval << shift;
  1872. }
  1873. if (val != old_val) {
  1874. change = 1;
  1875. outl(val, ICEMT(ice, ROUTE_CAPTURE));
  1876. }
  1877. spin_unlock_irq(&ice->reg_lock);
  1878. return change;
  1879. }
  1880. static int snd_ice1712_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
  1881. {
  1882. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1883. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1884. unsigned int val, cval;
  1885. val = inw(ICEMT(ice, ROUTE_SPDOUT));
  1886. cval = (val >> (idx * 4 + 8)) & 0x0f;
  1887. val = (val >> (idx * 2)) & 0x03;
  1888. if (val == 1)
  1889. ucontrol->value.enumerated.item[0] = 11;
  1890. else if (val == 2)
  1891. ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
  1892. else if (val == 3)
  1893. ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
  1894. else
  1895. ucontrol->value.enumerated.item[0] = 0;
  1896. return 0;
  1897. }
  1898. static int snd_ice1712_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
  1899. {
  1900. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1901. int change, shift;
  1902. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1903. unsigned int val, old_val, nval;
  1904. /* update SPDOUT */
  1905. spin_lock_irq(&ice->reg_lock);
  1906. val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
  1907. if (ucontrol->value.enumerated.item[0] >= 11)
  1908. nval = 1;
  1909. else if (ucontrol->value.enumerated.item[0] >= 9)
  1910. nval = 3;
  1911. else if (ucontrol->value.enumerated.item[0] >= 1)
  1912. nval = 2;
  1913. else
  1914. nval = 0;
  1915. shift = idx * 2;
  1916. val &= ~(0x03 << shift);
  1917. val |= nval << shift;
  1918. shift = idx * 4 + 8;
  1919. if (nval == 2) {
  1920. nval = ucontrol->value.enumerated.item[0] - 1;
  1921. val &= ~(0x07 << shift);
  1922. val |= nval << shift;
  1923. } else if (nval == 3) {
  1924. nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
  1925. val &= ~(0x08 << shift);
  1926. val |= nval << shift;
  1927. }
  1928. change = val != old_val;
  1929. if (change)
  1930. outw(val, ICEMT(ice, ROUTE_SPDOUT));
  1931. spin_unlock_irq(&ice->reg_lock);
  1932. return change;
  1933. }
  1934. static snd_kcontrol_new_t snd_ice1712_mixer_pro_analog_route __devinitdata = {
  1935. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1936. .name = "H/W Playback Route",
  1937. .info = snd_ice1712_pro_route_info,
  1938. .get = snd_ice1712_pro_route_analog_get,
  1939. .put = snd_ice1712_pro_route_analog_put,
  1940. };
  1941. static snd_kcontrol_new_t snd_ice1712_mixer_pro_spdif_route __devinitdata = {
  1942. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1943. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
  1944. .info = snd_ice1712_pro_route_info,
  1945. .get = snd_ice1712_pro_route_spdif_get,
  1946. .put = snd_ice1712_pro_route_spdif_put,
  1947. .count = 2,
  1948. };
  1949. static int snd_ice1712_pro_volume_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1950. {
  1951. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1952. uinfo->count = 1;
  1953. uinfo->value.integer.min = 0;
  1954. uinfo->value.integer.max = 255;
  1955. return 0;
  1956. }
  1957. static int snd_ice1712_pro_volume_rate_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1958. {
  1959. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1960. ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
  1961. return 0;
  1962. }
  1963. static int snd_ice1712_pro_volume_rate_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1964. {
  1965. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1966. int change;
  1967. spin_lock_irq(&ice->reg_lock);
  1968. change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
  1969. outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
  1970. spin_unlock_irq(&ice->reg_lock);
  1971. return change;
  1972. }
  1973. static snd_kcontrol_new_t snd_ice1712_mixer_pro_volume_rate __devinitdata = {
  1974. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1975. .name = "Multi Track Volume Rate",
  1976. .info = snd_ice1712_pro_volume_rate_info,
  1977. .get = snd_ice1712_pro_volume_rate_get,
  1978. .put = snd_ice1712_pro_volume_rate_put
  1979. };
  1980. static int snd_ice1712_pro_peak_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1981. {
  1982. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1983. uinfo->count = 22;
  1984. uinfo->value.integer.min = 0;
  1985. uinfo->value.integer.max = 255;
  1986. return 0;
  1987. }
  1988. static int snd_ice1712_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1989. {
  1990. ice1712_t *ice = snd_kcontrol_chip(kcontrol);
  1991. int idx;
  1992. spin_lock_irq(&ice->reg_lock);
  1993. for (idx = 0; idx < 22; idx++) {
  1994. outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
  1995. ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
  1996. }
  1997. spin_unlock_irq(&ice->reg_lock);
  1998. return 0;
  1999. }
  2000. static snd_kcontrol_new_t snd_ice1712_mixer_pro_peak __devinitdata = {
  2001. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2002. .name = "Multi Track Peak",
  2003. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  2004. .info = snd_ice1712_pro_peak_info,
  2005. .get = snd_ice1712_pro_peak_get
  2006. };
  2007. /*
  2008. *
  2009. */
  2010. /*
  2011. * list of available boards
  2012. */
  2013. static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
  2014. snd_ice1712_hoontech_cards,
  2015. snd_ice1712_delta_cards,
  2016. snd_ice1712_ews_cards,
  2017. NULL,
  2018. };
  2019. static unsigned char __devinit snd_ice1712_read_i2c(ice1712_t *ice,
  2020. unsigned char dev,
  2021. unsigned char addr)
  2022. {
  2023. long t = 0x10000;
  2024. outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
  2025. outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
  2026. while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
  2027. return inb(ICEREG(ice, I2C_DATA));
  2028. }
  2029. static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice, const char *modelname)
  2030. {
  2031. int dev = 0xa0; /* EEPROM device address */
  2032. unsigned int i, size;
  2033. struct snd_ice1712_card_info **tbl, *c;
  2034. if (! modelname || ! *modelname) {
  2035. ice->eeprom.subvendor = 0;
  2036. if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
  2037. ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
  2038. (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
  2039. (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
  2040. (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
  2041. if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
  2042. /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
  2043. u16 vendor, device;
  2044. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
  2045. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
  2046. ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
  2047. if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
  2048. printk(KERN_ERR "ice1712: No valid ID is found\n");
  2049. return -ENXIO;
  2050. }
  2051. }
  2052. }
  2053. for (tbl = card_tables; *tbl; tbl++) {
  2054. for (c = *tbl; c->subvendor; c++) {
  2055. if (modelname && c->model && ! strcmp(modelname, c->model)) {
  2056. printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
  2057. ice->eeprom.subvendor = c->subvendor;
  2058. } else if (c->subvendor != ice->eeprom.subvendor)
  2059. continue;
  2060. if (! c->eeprom_size || ! c->eeprom_data)
  2061. goto found;
  2062. /* if the EEPROM is given by the driver, use it */
  2063. snd_printdd("using the defined eeprom..\n");
  2064. ice->eeprom.version = 1;
  2065. ice->eeprom.size = c->eeprom_size + 6;
  2066. memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
  2067. goto read_skipped;
  2068. }
  2069. }
  2070. printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n", ice->eeprom.subvendor);
  2071. found:
  2072. ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
  2073. if (ice->eeprom.size < 6)
  2074. ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
  2075. else if (ice->eeprom.size > 32) {
  2076. snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size);
  2077. return -EIO;
  2078. }
  2079. ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
  2080. if (ice->eeprom.version != 1) {
  2081. snd_printk("invalid EEPROM version %i\n", ice->eeprom.version);
  2082. /* return -EIO; */
  2083. }
  2084. size = ice->eeprom.size - 6;
  2085. for (i = 0; i < size; i++)
  2086. ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
  2087. read_skipped:
  2088. ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
  2089. ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
  2090. ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
  2091. return 0;
  2092. }
  2093. static int __devinit snd_ice1712_chip_init(ice1712_t *ice)
  2094. {
  2095. outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
  2096. udelay(200);
  2097. outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
  2098. udelay(200);
  2099. pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
  2100. pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
  2101. pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
  2102. pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
  2103. if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
  2104. ice->gpio.write_mask = ice->eeprom.gpiomask;
  2105. ice->gpio.direction = ice->eeprom.gpiodir;
  2106. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
  2107. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
  2108. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
  2109. } else {
  2110. ice->gpio.write_mask = 0xc0;
  2111. ice->gpio.direction = 0xff;
  2112. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
  2113. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
  2114. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_STDSP24_CLOCK_BIT);
  2115. }
  2116. snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
  2117. if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
  2118. outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
  2119. udelay(100);
  2120. outb(0, ICEREG(ice, AC97_CMD));
  2121. udelay(200);
  2122. snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
  2123. }
  2124. snd_ice1712_set_pro_rate(ice, 48000, 1);
  2125. return 0;
  2126. }
  2127. int __devinit snd_ice1712_spdif_build_controls(ice1712_t *ice)
  2128. {
  2129. int err;
  2130. snd_kcontrol_t *kctl;
  2131. snd_assert(ice->pcm_pro != NULL, return -EIO);
  2132. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
  2133. if (err < 0)
  2134. return err;
  2135. kctl->id.device = ice->pcm_pro->device;
  2136. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
  2137. if (err < 0)
  2138. return err;
  2139. kctl->id.device = ice->pcm_pro->device;
  2140. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
  2141. if (err < 0)
  2142. return err;
  2143. kctl->id.device = ice->pcm_pro->device;
  2144. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
  2145. if (err < 0)
  2146. return err;
  2147. kctl->id.device = ice->pcm_pro->device;
  2148. ice->spdif.stream_ctl = kctl;
  2149. return 0;
  2150. }
  2151. static int __devinit snd_ice1712_build_controls(ice1712_t *ice)
  2152. {
  2153. int err;
  2154. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
  2155. if (err < 0)
  2156. return err;
  2157. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
  2158. if (err < 0)
  2159. return err;
  2160. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
  2161. if (err < 0)
  2162. return err;
  2163. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
  2164. if (err < 0)
  2165. return err;
  2166. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
  2167. if (err < 0)
  2168. return err;
  2169. if (ice->num_total_dacs > 0) {
  2170. snd_kcontrol_new_t tmp = snd_ice1712_mixer_pro_analog_route;
  2171. tmp.count = ice->num_total_dacs;
  2172. err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
  2173. if (err < 0)
  2174. return err;
  2175. }
  2176. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
  2177. if (err < 0)
  2178. return err;
  2179. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
  2180. if (err < 0)
  2181. return err;
  2182. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
  2183. if (err < 0)
  2184. return err;
  2185. return 0;
  2186. }
  2187. static int snd_ice1712_free(ice1712_t *ice)
  2188. {
  2189. if (! ice->port)
  2190. goto __hw_end;
  2191. /* mask all interrupts */
  2192. outb(0xc0, ICEMT(ice, IRQ));
  2193. outb(0xff, ICEREG(ice, IRQMASK));
  2194. /* --- */
  2195. __hw_end:
  2196. if (ice->irq >= 0) {
  2197. synchronize_irq(ice->irq);
  2198. free_irq(ice->irq, (void *) ice);
  2199. }
  2200. if (ice->port)
  2201. pci_release_regions(ice->pci);
  2202. snd_ice1712_akm4xxx_free(ice);
  2203. pci_disable_device(ice->pci);
  2204. kfree(ice);
  2205. return 0;
  2206. }
  2207. static int snd_ice1712_dev_free(snd_device_t *device)
  2208. {
  2209. ice1712_t *ice = device->device_data;
  2210. return snd_ice1712_free(ice);
  2211. }
  2212. static int __devinit snd_ice1712_create(snd_card_t * card,
  2213. struct pci_dev *pci,
  2214. const char *modelname,
  2215. int omni,
  2216. int cs8427_timeout,
  2217. ice1712_t ** r_ice1712)
  2218. {
  2219. ice1712_t *ice;
  2220. int err;
  2221. static snd_device_ops_t ops = {
  2222. .dev_free = snd_ice1712_dev_free,
  2223. };
  2224. *r_ice1712 = NULL;
  2225. /* enable PCI device */
  2226. if ((err = pci_enable_device(pci)) < 0)
  2227. return err;
  2228. /* check, if we can restrict PCI DMA transfers to 28 bits */
  2229. if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
  2230. pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
  2231. snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
  2232. pci_disable_device(pci);
  2233. return -ENXIO;
  2234. }
  2235. ice = kzalloc(sizeof(*ice), GFP_KERNEL);
  2236. if (ice == NULL) {
  2237. pci_disable_device(pci);
  2238. return -ENOMEM;
  2239. }
  2240. ice->omni = omni ? 1 : 0;
  2241. if (cs8427_timeout < 1)
  2242. cs8427_timeout = 1;
  2243. else if (cs8427_timeout > 1000)
  2244. cs8427_timeout = 1000;
  2245. ice->cs8427_timeout = cs8427_timeout;
  2246. spin_lock_init(&ice->reg_lock);
  2247. init_MUTEX(&ice->gpio_mutex);
  2248. init_MUTEX(&ice->i2c_mutex);
  2249. init_MUTEX(&ice->open_mutex);
  2250. ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
  2251. ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
  2252. ice->gpio.set_data = snd_ice1712_set_gpio_data;
  2253. ice->gpio.get_data = snd_ice1712_get_gpio_data;
  2254. ice->spdif.cs8403_bits =
  2255. ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
  2256. 0x10 | /* no emphasis */
  2257. 0x20); /* PCM encoder/decoder */
  2258. ice->card = card;
  2259. ice->pci = pci;
  2260. ice->irq = -1;
  2261. pci_set_master(pci);
  2262. pci_write_config_word(ice->pci, 0x40, 0x807f);
  2263. pci_write_config_word(ice->pci, 0x42, 0x0006);
  2264. snd_ice1712_proc_init(ice);
  2265. synchronize_irq(pci->irq);
  2266. if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
  2267. kfree(ice);
  2268. pci_disable_device(pci);
  2269. return err;
  2270. }
  2271. ice->port = pci_resource_start(pci, 0);
  2272. ice->ddma_port = pci_resource_start(pci, 1);
  2273. ice->dmapath_port = pci_resource_start(pci, 2);
  2274. ice->profi_port = pci_resource_start(pci, 3);
  2275. if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
  2276. snd_printk("unable to grab IRQ %d\n", pci->irq);
  2277. snd_ice1712_free(ice);
  2278. return -EIO;
  2279. }
  2280. ice->irq = pci->irq;
  2281. if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
  2282. snd_ice1712_free(ice);
  2283. return -EIO;
  2284. }
  2285. if (snd_ice1712_chip_init(ice) < 0) {
  2286. snd_ice1712_free(ice);
  2287. return -EIO;
  2288. }
  2289. /* unmask used interrupts */
  2290. outb((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
  2291. (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
  2292. ICEREG(ice, IRQMASK));
  2293. outb(0x00, ICEMT(ice, IRQ));
  2294. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
  2295. snd_ice1712_free(ice);
  2296. return err;
  2297. }
  2298. snd_card_set_dev(card, &pci->dev);
  2299. *r_ice1712 = ice;
  2300. return 0;
  2301. }
  2302. /*
  2303. *
  2304. * Registration
  2305. *
  2306. */
  2307. static struct snd_ice1712_card_info no_matched __devinitdata;
  2308. static int __devinit snd_ice1712_probe(struct pci_dev *pci,
  2309. const struct pci_device_id *pci_id)
  2310. {
  2311. static int dev;
  2312. snd_card_t *card;
  2313. ice1712_t *ice;
  2314. int pcm_dev = 0, err;
  2315. struct snd_ice1712_card_info **tbl, *c;
  2316. if (dev >= SNDRV_CARDS)
  2317. return -ENODEV;
  2318. if (!enable[dev]) {
  2319. dev++;
  2320. return -ENOENT;
  2321. }
  2322. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  2323. if (card == NULL)
  2324. return -ENOMEM;
  2325. strcpy(card->driver, "ICE1712");
  2326. strcpy(card->shortname, "ICEnsemble ICE1712");
  2327. if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev], cs8427_timeout[dev], &ice)) < 0) {
  2328. snd_card_free(card);
  2329. return err;
  2330. }
  2331. for (tbl = card_tables; *tbl; tbl++) {
  2332. for (c = *tbl; c->subvendor; c++) {
  2333. if (c->subvendor == ice->eeprom.subvendor) {
  2334. strcpy(card->shortname, c->name);
  2335. if (c->driver) /* specific driver? */
  2336. strcpy(card->driver, c->driver);
  2337. if (c->chip_init) {
  2338. if ((err = c->chip_init(ice)) < 0) {
  2339. snd_card_free(card);
  2340. return err;
  2341. }
  2342. }
  2343. goto __found;
  2344. }
  2345. }
  2346. }
  2347. c = &no_matched;
  2348. __found:
  2349. if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
  2350. snd_card_free(card);
  2351. return err;
  2352. }
  2353. if (ice_has_con_ac97(ice))
  2354. if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
  2355. snd_card_free(card);
  2356. return err;
  2357. }
  2358. if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
  2359. snd_card_free(card);
  2360. return err;
  2361. }
  2362. if ((err = snd_ice1712_build_controls(ice)) < 0) {
  2363. snd_card_free(card);
  2364. return err;
  2365. }
  2366. if (c->build_controls) {
  2367. if ((err = c->build_controls(ice)) < 0) {
  2368. snd_card_free(card);
  2369. return err;
  2370. }
  2371. }
  2372. if (ice_has_con_ac97(ice))
  2373. if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
  2374. snd_card_free(card);
  2375. return err;
  2376. }
  2377. if (! c->no_mpu401) {
  2378. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
  2379. ICEREG(ice, MPU1_CTRL), 1,
  2380. ice->irq, 0,
  2381. &ice->rmidi[0])) < 0) {
  2382. snd_card_free(card);
  2383. return err;
  2384. }
  2385. if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
  2386. if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
  2387. ICEREG(ice, MPU2_CTRL), 1,
  2388. ice->irq, 0,
  2389. &ice->rmidi[1])) < 0) {
  2390. snd_card_free(card);
  2391. return err;
  2392. }
  2393. }
  2394. sprintf(card->longname, "%s at 0x%lx, irq %i",
  2395. card->shortname, ice->port, ice->irq);
  2396. if ((err = snd_card_register(card)) < 0) {
  2397. snd_card_free(card);
  2398. return err;
  2399. }
  2400. pci_set_drvdata(pci, card);
  2401. dev++;
  2402. return 0;
  2403. }
  2404. static void __devexit snd_ice1712_remove(struct pci_dev *pci)
  2405. {
  2406. snd_card_free(pci_get_drvdata(pci));
  2407. pci_set_drvdata(pci, NULL);
  2408. }
  2409. static struct pci_driver driver = {
  2410. .name = "ICE1712",
  2411. .owner = THIS_MODULE,
  2412. .id_table = snd_ice1712_ids,
  2413. .probe = snd_ice1712_probe,
  2414. .remove = __devexit_p(snd_ice1712_remove),
  2415. };
  2416. static int __init alsa_card_ice1712_init(void)
  2417. {
  2418. return pci_register_driver(&driver);
  2419. }
  2420. static void __exit alsa_card_ice1712_exit(void)
  2421. {
  2422. pci_unregister_driver(&driver);
  2423. }
  2424. module_init(alsa_card_ice1712_init)
  2425. module_exit(alsa_card_ice1712_exit)