ice1712.c 83 KB

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