echoaudio.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290
  1. /*
  2. * ALSA driver for Echoaudio soundcards.
  3. * Copyright (C) 2003-2004 Giuliano Pochini <pochini@shiny.it>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/module.h>
  19. MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>");
  20. MODULE_LICENSE("GPL v2");
  21. MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME " soundcards driver");
  22. MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}");
  23. MODULE_DEVICE_TABLE(pci, snd_echo_ids);
  24. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  25. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  26. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  27. module_param_array(index, int, NULL, 0444);
  28. MODULE_PARM_DESC(index, "Index value for " ECHOCARD_NAME " soundcard.");
  29. module_param_array(id, charp, NULL, 0444);
  30. MODULE_PARM_DESC(id, "ID string for " ECHOCARD_NAME " soundcard.");
  31. module_param_array(enable, bool, NULL, 0444);
  32. MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard.");
  33. static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
  34. static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);
  35. static int get_firmware(const struct firmware **fw_entry,
  36. struct echoaudio *chip, const short fw_index)
  37. {
  38. int err;
  39. char name[30];
  40. #ifdef CONFIG_PM_SLEEP
  41. if (chip->fw_cache[fw_index]) {
  42. dev_dbg(chip->card->dev,
  43. "firmware requested: %s is cached\n",
  44. card_fw[fw_index].data);
  45. *fw_entry = chip->fw_cache[fw_index];
  46. return 0;
  47. }
  48. #endif
  49. dev_dbg(chip->card->dev,
  50. "firmware requested: %s\n", card_fw[fw_index].data);
  51. snprintf(name, sizeof(name), "/*(DEBLOBBED)*/", card_fw[fw_index].data);
  52. err = reject_firmware(fw_entry, name, pci_device(chip));
  53. if (err < 0)
  54. dev_err(chip->card->dev,
  55. "get_firmware(): Firmware not available (%d)\n", err);
  56. #ifdef CONFIG_PM_SLEEP
  57. else
  58. chip->fw_cache[fw_index] = *fw_entry;
  59. #endif
  60. return err;
  61. }
  62. static void free_firmware(const struct firmware *fw_entry,
  63. struct echoaudio *chip)
  64. {
  65. #ifdef CONFIG_PM_SLEEP
  66. dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n");
  67. #else
  68. release_firmware(fw_entry);
  69. #endif
  70. }
  71. static void free_firmware_cache(struct echoaudio *chip)
  72. {
  73. #ifdef CONFIG_PM_SLEEP
  74. int i;
  75. for (i = 0; i < 8 ; i++)
  76. if (chip->fw_cache[i]) {
  77. release_firmware(chip->fw_cache[i]);
  78. dev_dbg(chip->card->dev, "release_firmware(%d)\n", i);
  79. }
  80. #endif
  81. }
  82. /******************************************************************************
  83. PCM interface
  84. ******************************************************************************/
  85. static void audiopipe_free(struct snd_pcm_runtime *runtime)
  86. {
  87. struct audiopipe *pipe = runtime->private_data;
  88. if (pipe->sgpage.area)
  89. snd_dma_free_pages(&pipe->sgpage);
  90. kfree(pipe);
  91. }
  92. static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
  93. struct snd_pcm_hw_rule *rule)
  94. {
  95. struct snd_interval *c = hw_param_interval(params,
  96. SNDRV_PCM_HW_PARAM_CHANNELS);
  97. struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  98. struct snd_mask fmt;
  99. snd_mask_any(&fmt);
  100. #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
  101. /* >=2 channels cannot be S32_BE */
  102. if (c->min == 2) {
  103. fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
  104. return snd_mask_refine(f, &fmt);
  105. }
  106. #endif
  107. /* > 2 channels cannot be U8 and S32_BE */
  108. if (c->min > 2) {
  109. fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
  110. return snd_mask_refine(f, &fmt);
  111. }
  112. /* Mono is ok with any format */
  113. return 0;
  114. }
  115. static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
  116. struct snd_pcm_hw_rule *rule)
  117. {
  118. struct snd_interval *c = hw_param_interval(params,
  119. SNDRV_PCM_HW_PARAM_CHANNELS);
  120. struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  121. struct snd_interval ch;
  122. snd_interval_any(&ch);
  123. /* S32_BE is mono (and stereo) only */
  124. if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
  125. ch.min = 1;
  126. #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
  127. ch.max = 2;
  128. #else
  129. ch.max = 1;
  130. #endif
  131. ch.integer = 1;
  132. return snd_interval_refine(c, &ch);
  133. }
  134. /* U8 can be only mono or stereo */
  135. if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
  136. ch.min = 1;
  137. ch.max = 2;
  138. ch.integer = 1;
  139. return snd_interval_refine(c, &ch);
  140. }
  141. /* S16_LE, S24_3LE and S32_LE support any number of channels. */
  142. return 0;
  143. }
  144. static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
  145. struct snd_pcm_hw_rule *rule)
  146. {
  147. struct snd_interval *c = hw_param_interval(params,
  148. SNDRV_PCM_HW_PARAM_CHANNELS);
  149. struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  150. struct snd_mask fmt;
  151. u64 fmask;
  152. snd_mask_any(&fmt);
  153. fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
  154. /* >2 channels must be S16_LE, S24_3LE or S32_LE */
  155. if (c->min > 2) {
  156. fmask &= SNDRV_PCM_FMTBIT_S16_LE |
  157. SNDRV_PCM_FMTBIT_S24_3LE |
  158. SNDRV_PCM_FMTBIT_S32_LE;
  159. /* 1 channel must be S32_BE or S32_LE */
  160. } else if (c->max == 1)
  161. fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
  162. #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
  163. /* 2 channels cannot be S32_BE */
  164. else if (c->min == 2 && c->max == 2)
  165. fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
  166. #endif
  167. else
  168. return 0;
  169. fmt.bits[0] &= (u32)fmask;
  170. fmt.bits[1] &= (u32)(fmask >> 32);
  171. return snd_mask_refine(f, &fmt);
  172. }
  173. static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
  174. struct snd_pcm_hw_rule *rule)
  175. {
  176. struct snd_interval *c = hw_param_interval(params,
  177. SNDRV_PCM_HW_PARAM_CHANNELS);
  178. struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  179. struct snd_interval ch;
  180. u64 fmask;
  181. snd_interval_any(&ch);
  182. ch.integer = 1;
  183. fmask = f->bits[0] + ((u64)f->bits[1] << 32);
  184. /* S32_BE is mono (and stereo) only */
  185. if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
  186. ch.min = 1;
  187. #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
  188. ch.max = 2;
  189. #else
  190. ch.max = 1;
  191. #endif
  192. /* U8 is stereo only */
  193. } else if (fmask == SNDRV_PCM_FMTBIT_U8)
  194. ch.min = ch.max = 2;
  195. /* S16_LE and S24_3LE must be at least stereo */
  196. else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
  197. SNDRV_PCM_FMTBIT_S24_3LE)))
  198. ch.min = 2;
  199. else
  200. return 0;
  201. return snd_interval_refine(c, &ch);
  202. }
  203. /* Since the sample rate is a global setting, do allow the user to change the
  204. sample rate only if there is only one pcm device open. */
  205. static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
  206. struct snd_pcm_hw_rule *rule)
  207. {
  208. struct snd_interval *rate = hw_param_interval(params,
  209. SNDRV_PCM_HW_PARAM_RATE);
  210. struct echoaudio *chip = rule->private;
  211. struct snd_interval fixed;
  212. if (!chip->can_set_rate) {
  213. snd_interval_any(&fixed);
  214. fixed.min = fixed.max = chip->sample_rate;
  215. return snd_interval_refine(rate, &fixed);
  216. }
  217. return 0;
  218. }
  219. static int pcm_open(struct snd_pcm_substream *substream,
  220. signed char max_channels)
  221. {
  222. struct echoaudio *chip;
  223. struct snd_pcm_runtime *runtime;
  224. struct audiopipe *pipe;
  225. int err, i;
  226. if (max_channels <= 0)
  227. return -EAGAIN;
  228. chip = snd_pcm_substream_chip(substream);
  229. runtime = substream->runtime;
  230. pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
  231. if (!pipe)
  232. return -ENOMEM;
  233. pipe->index = -1; /* Not configured yet */
  234. /* Set up hw capabilities and contraints */
  235. memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
  236. dev_dbg(chip->card->dev, "max_channels=%d\n", max_channels);
  237. pipe->constr.list = channels_list;
  238. pipe->constr.mask = 0;
  239. for (i = 0; channels_list[i] <= max_channels; i++);
  240. pipe->constr.count = i;
  241. if (pipe->hw.channels_max > max_channels)
  242. pipe->hw.channels_max = max_channels;
  243. if (chip->digital_mode == DIGITAL_MODE_ADAT) {
  244. pipe->hw.rate_max = 48000;
  245. pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
  246. }
  247. runtime->hw = pipe->hw;
  248. runtime->private_data = pipe;
  249. runtime->private_free = audiopipe_free;
  250. snd_pcm_set_sync(substream);
  251. /* Only mono and any even number of channels are allowed */
  252. if ((err = snd_pcm_hw_constraint_list(runtime, 0,
  253. SNDRV_PCM_HW_PARAM_CHANNELS,
  254. &pipe->constr)) < 0)
  255. return err;
  256. /* All periods should have the same size */
  257. if ((err = snd_pcm_hw_constraint_integer(runtime,
  258. SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  259. return err;
  260. /* The hw accesses memory in chunks 32 frames long and they should be
  261. 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
  262. generated with a resolution of 32 frames. Thus we need the following */
  263. if ((err = snd_pcm_hw_constraint_step(runtime, 0,
  264. SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
  265. 32)) < 0)
  266. return err;
  267. if ((err = snd_pcm_hw_constraint_step(runtime, 0,
  268. SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
  269. 32)) < 0)
  270. return err;
  271. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  272. SNDRV_PCM_HW_PARAM_RATE,
  273. hw_rule_sample_rate, chip,
  274. SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
  275. return err;
  276. /* Finally allocate a page for the scatter-gather list */
  277. if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  278. snd_dma_pci_data(chip->pci),
  279. PAGE_SIZE, &pipe->sgpage)) < 0) {
  280. dev_err(chip->card->dev, "s-g list allocation failed\n");
  281. return err;
  282. }
  283. return 0;
  284. }
  285. static int pcm_analog_in_open(struct snd_pcm_substream *substream)
  286. {
  287. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  288. int err;
  289. if ((err = pcm_open(substream, num_analog_busses_in(chip) -
  290. substream->number)) < 0)
  291. return err;
  292. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  293. SNDRV_PCM_HW_PARAM_CHANNELS,
  294. hw_rule_capture_channels_by_format, NULL,
  295. SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
  296. return err;
  297. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  298. SNDRV_PCM_HW_PARAM_FORMAT,
  299. hw_rule_capture_format_by_channels, NULL,
  300. SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
  301. return err;
  302. atomic_inc(&chip->opencount);
  303. if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
  304. chip->can_set_rate=0;
  305. dev_dbg(chip->card->dev, "pcm_analog_in_open cs=%d oc=%d r=%d\n",
  306. chip->can_set_rate, atomic_read(&chip->opencount),
  307. chip->sample_rate);
  308. return 0;
  309. }
  310. static int pcm_analog_out_open(struct snd_pcm_substream *substream)
  311. {
  312. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  313. int max_channels, err;
  314. #ifdef ECHOCARD_HAS_VMIXER
  315. max_channels = num_pipes_out(chip);
  316. #else
  317. max_channels = num_analog_busses_out(chip);
  318. #endif
  319. if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
  320. return err;
  321. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  322. SNDRV_PCM_HW_PARAM_CHANNELS,
  323. hw_rule_playback_channels_by_format,
  324. NULL,
  325. SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
  326. return err;
  327. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  328. SNDRV_PCM_HW_PARAM_FORMAT,
  329. hw_rule_playback_format_by_channels,
  330. NULL,
  331. SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
  332. return err;
  333. atomic_inc(&chip->opencount);
  334. if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
  335. chip->can_set_rate=0;
  336. dev_dbg(chip->card->dev, "pcm_analog_out_open cs=%d oc=%d r=%d\n",
  337. chip->can_set_rate, atomic_read(&chip->opencount),
  338. chip->sample_rate);
  339. return 0;
  340. }
  341. #ifdef ECHOCARD_HAS_DIGITAL_IO
  342. static int pcm_digital_in_open(struct snd_pcm_substream *substream)
  343. {
  344. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  345. int err, max_channels;
  346. max_channels = num_digital_busses_in(chip) - substream->number;
  347. mutex_lock(&chip->mode_mutex);
  348. if (chip->digital_mode == DIGITAL_MODE_ADAT)
  349. err = pcm_open(substream, max_channels);
  350. else /* If the card has ADAT, subtract the 6 channels
  351. * that S/PDIF doesn't have
  352. */
  353. err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
  354. if (err < 0)
  355. goto din_exit;
  356. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  357. SNDRV_PCM_HW_PARAM_CHANNELS,
  358. hw_rule_capture_channels_by_format, NULL,
  359. SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
  360. goto din_exit;
  361. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  362. SNDRV_PCM_HW_PARAM_FORMAT,
  363. hw_rule_capture_format_by_channels, NULL,
  364. SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
  365. goto din_exit;
  366. atomic_inc(&chip->opencount);
  367. if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
  368. chip->can_set_rate=0;
  369. din_exit:
  370. mutex_unlock(&chip->mode_mutex);
  371. return err;
  372. }
  373. #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
  374. static int pcm_digital_out_open(struct snd_pcm_substream *substream)
  375. {
  376. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  377. int err, max_channels;
  378. max_channels = num_digital_busses_out(chip) - substream->number;
  379. mutex_lock(&chip->mode_mutex);
  380. if (chip->digital_mode == DIGITAL_MODE_ADAT)
  381. err = pcm_open(substream, max_channels);
  382. else /* If the card has ADAT, subtract the 6 channels
  383. * that S/PDIF doesn't have
  384. */
  385. err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
  386. if (err < 0)
  387. goto dout_exit;
  388. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  389. SNDRV_PCM_HW_PARAM_CHANNELS,
  390. hw_rule_playback_channels_by_format,
  391. NULL, SNDRV_PCM_HW_PARAM_FORMAT,
  392. -1)) < 0)
  393. goto dout_exit;
  394. if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
  395. SNDRV_PCM_HW_PARAM_FORMAT,
  396. hw_rule_playback_format_by_channels,
  397. NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
  398. -1)) < 0)
  399. goto dout_exit;
  400. atomic_inc(&chip->opencount);
  401. if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
  402. chip->can_set_rate=0;
  403. dout_exit:
  404. mutex_unlock(&chip->mode_mutex);
  405. return err;
  406. }
  407. #endif /* !ECHOCARD_HAS_VMIXER */
  408. #endif /* ECHOCARD_HAS_DIGITAL_IO */
  409. static int pcm_close(struct snd_pcm_substream *substream)
  410. {
  411. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  412. int oc;
  413. /* Nothing to do here. Audio is already off and pipe will be
  414. * freed by its callback
  415. */
  416. atomic_dec(&chip->opencount);
  417. oc = atomic_read(&chip->opencount);
  418. dev_dbg(chip->card->dev, "pcm_close oc=%d cs=%d rs=%d\n", oc,
  419. chip->can_set_rate, chip->rate_set);
  420. if (oc < 2)
  421. chip->can_set_rate = 1;
  422. if (oc == 0)
  423. chip->rate_set = 0;
  424. dev_dbg(chip->card->dev, "pcm_close2 oc=%d cs=%d rs=%d\n", oc,
  425. chip->can_set_rate, chip->rate_set);
  426. return 0;
  427. }
  428. /* Channel allocation and scatter-gather list setup */
  429. static int init_engine(struct snd_pcm_substream *substream,
  430. struct snd_pcm_hw_params *hw_params,
  431. int pipe_index, int interleave)
  432. {
  433. struct echoaudio *chip;
  434. int err, per, rest, page, edge, offs;
  435. struct audiopipe *pipe;
  436. chip = snd_pcm_substream_chip(substream);
  437. pipe = (struct audiopipe *) substream->runtime->private_data;
  438. /* Sets up che hardware. If it's already initialized, reset and
  439. * redo with the new parameters
  440. */
  441. spin_lock_irq(&chip->lock);
  442. if (pipe->index >= 0) {
  443. dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index);
  444. err = free_pipes(chip, pipe);
  445. snd_BUG_ON(err);
  446. chip->substream[pipe->index] = NULL;
  447. }
  448. err = allocate_pipes(chip, pipe, pipe_index, interleave);
  449. if (err < 0) {
  450. spin_unlock_irq(&chip->lock);
  451. dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n",
  452. pipe_index, err);
  453. return err;
  454. }
  455. spin_unlock_irq(&chip->lock);
  456. dev_dbg(chip->card->dev, "allocate_pipes()=%d\n", pipe_index);
  457. dev_dbg(chip->card->dev,
  458. "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
  459. params_buffer_bytes(hw_params), params_periods(hw_params),
  460. params_period_bytes(hw_params));
  461. err = snd_pcm_lib_malloc_pages(substream,
  462. params_buffer_bytes(hw_params));
  463. if (err < 0) {
  464. dev_err(chip->card->dev, "malloc_pages err=%d\n", err);
  465. spin_lock_irq(&chip->lock);
  466. free_pipes(chip, pipe);
  467. spin_unlock_irq(&chip->lock);
  468. pipe->index = -1;
  469. return err;
  470. }
  471. sglist_init(chip, pipe);
  472. edge = PAGE_SIZE;
  473. for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
  474. per++) {
  475. rest = params_period_bytes(hw_params);
  476. if (offs + rest > params_buffer_bytes(hw_params))
  477. rest = params_buffer_bytes(hw_params) - offs;
  478. while (rest) {
  479. dma_addr_t addr;
  480. addr = snd_pcm_sgbuf_get_addr(substream, offs);
  481. if (rest <= edge - offs) {
  482. sglist_add_mapping(chip, pipe, addr, rest);
  483. sglist_add_irq(chip, pipe);
  484. offs += rest;
  485. rest = 0;
  486. } else {
  487. sglist_add_mapping(chip, pipe, addr,
  488. edge - offs);
  489. rest -= edge - offs;
  490. offs = edge;
  491. }
  492. if (offs == edge) {
  493. edge += PAGE_SIZE;
  494. page++;
  495. }
  496. }
  497. }
  498. /* Close the ring buffer */
  499. sglist_wrap(chip, pipe);
  500. /* This stuff is used by the irq handler, so it must be
  501. * initialized before chip->substream
  502. */
  503. chip->last_period[pipe_index] = 0;
  504. pipe->last_counter = 0;
  505. pipe->position = 0;
  506. smp_wmb();
  507. chip->substream[pipe_index] = substream;
  508. chip->rate_set = 1;
  509. spin_lock_irq(&chip->lock);
  510. set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
  511. spin_unlock_irq(&chip->lock);
  512. return 0;
  513. }
  514. static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
  515. struct snd_pcm_hw_params *hw_params)
  516. {
  517. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  518. return init_engine(substream, hw_params, px_analog_in(chip) +
  519. substream->number, params_channels(hw_params));
  520. }
  521. static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
  522. struct snd_pcm_hw_params *hw_params)
  523. {
  524. return init_engine(substream, hw_params, substream->number,
  525. params_channels(hw_params));
  526. }
  527. #ifdef ECHOCARD_HAS_DIGITAL_IO
  528. static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
  529. struct snd_pcm_hw_params *hw_params)
  530. {
  531. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  532. return init_engine(substream, hw_params, px_digital_in(chip) +
  533. substream->number, params_channels(hw_params));
  534. }
  535. #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
  536. static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
  537. struct snd_pcm_hw_params *hw_params)
  538. {
  539. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  540. return init_engine(substream, hw_params, px_digital_out(chip) +
  541. substream->number, params_channels(hw_params));
  542. }
  543. #endif /* !ECHOCARD_HAS_VMIXER */
  544. #endif /* ECHOCARD_HAS_DIGITAL_IO */
  545. static int pcm_hw_free(struct snd_pcm_substream *substream)
  546. {
  547. struct echoaudio *chip;
  548. struct audiopipe *pipe;
  549. chip = snd_pcm_substream_chip(substream);
  550. pipe = (struct audiopipe *) substream->runtime->private_data;
  551. spin_lock_irq(&chip->lock);
  552. if (pipe->index >= 0) {
  553. dev_dbg(chip->card->dev, "pcm_hw_free(%d)\n", pipe->index);
  554. free_pipes(chip, pipe);
  555. chip->substream[pipe->index] = NULL;
  556. pipe->index = -1;
  557. }
  558. spin_unlock_irq(&chip->lock);
  559. snd_pcm_lib_free_pages(substream);
  560. return 0;
  561. }
  562. static int pcm_prepare(struct snd_pcm_substream *substream)
  563. {
  564. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  565. struct snd_pcm_runtime *runtime = substream->runtime;
  566. struct audioformat format;
  567. int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
  568. dev_dbg(chip->card->dev, "Prepare rate=%d format=%d channels=%d\n",
  569. runtime->rate, runtime->format, runtime->channels);
  570. format.interleave = runtime->channels;
  571. format.data_are_bigendian = 0;
  572. format.mono_to_stereo = 0;
  573. switch (runtime->format) {
  574. case SNDRV_PCM_FORMAT_U8:
  575. format.bits_per_sample = 8;
  576. break;
  577. case SNDRV_PCM_FORMAT_S16_LE:
  578. format.bits_per_sample = 16;
  579. break;
  580. case SNDRV_PCM_FORMAT_S24_3LE:
  581. format.bits_per_sample = 24;
  582. break;
  583. case SNDRV_PCM_FORMAT_S32_BE:
  584. format.data_are_bigendian = 1;
  585. case SNDRV_PCM_FORMAT_S32_LE:
  586. format.bits_per_sample = 32;
  587. break;
  588. default:
  589. dev_err(chip->card->dev,
  590. "Prepare error: unsupported format %d\n",
  591. runtime->format);
  592. return -EINVAL;
  593. }
  594. if (snd_BUG_ON(pipe_index >= px_num(chip)))
  595. return -EINVAL;
  596. if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
  597. return -EINVAL;
  598. set_audio_format(chip, pipe_index, &format);
  599. return 0;
  600. }
  601. static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  602. {
  603. struct echoaudio *chip = snd_pcm_substream_chip(substream);
  604. struct snd_pcm_runtime *runtime = substream->runtime;
  605. struct audiopipe *pipe = runtime->private_data;
  606. int i, err;
  607. u32 channelmask = 0;
  608. struct snd_pcm_substream *s;
  609. snd_pcm_group_for_each_entry(s, substream) {
  610. for (i = 0; i < DSP_MAXPIPES; i++) {
  611. if (s == chip->substream[i]) {
  612. channelmask |= 1 << i;
  613. snd_pcm_trigger_done(s, substream);
  614. }
  615. }
  616. }
  617. spin_lock(&chip->lock);
  618. switch (cmd) {
  619. case SNDRV_PCM_TRIGGER_RESUME:
  620. case SNDRV_PCM_TRIGGER_START:
  621. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  622. for (i = 0; i < DSP_MAXPIPES; i++) {
  623. if (channelmask & (1 << i)) {
  624. pipe = chip->substream[i]->runtime->private_data;
  625. switch (pipe->state) {
  626. case PIPE_STATE_STOPPED:
  627. chip->last_period[i] = 0;
  628. pipe->last_counter = 0;
  629. pipe->position = 0;
  630. *pipe->dma_counter = 0;
  631. case PIPE_STATE_PAUSED:
  632. pipe->state = PIPE_STATE_STARTED;
  633. break;
  634. case PIPE_STATE_STARTED:
  635. break;
  636. }
  637. }
  638. }
  639. err = start_transport(chip, channelmask,
  640. chip->pipe_cyclic_mask);
  641. break;
  642. case SNDRV_PCM_TRIGGER_SUSPEND:
  643. case SNDRV_PCM_TRIGGER_STOP:
  644. for (i = 0; i < DSP_MAXPIPES; i++) {
  645. if (channelmask & (1 << i)) {
  646. pipe = chip->substream[i]->runtime->private_data;
  647. pipe->state = PIPE_STATE_STOPPED;
  648. }
  649. }
  650. err = stop_transport(chip, channelmask);
  651. break;
  652. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  653. for (i = 0; i < DSP_MAXPIPES; i++) {
  654. if (channelmask & (1 << i)) {
  655. pipe = chip->substream[i]->runtime->private_data;
  656. pipe->state = PIPE_STATE_PAUSED;
  657. }
  658. }
  659. err = pause_transport(chip, channelmask);
  660. break;
  661. default:
  662. err = -EINVAL;
  663. }
  664. spin_unlock(&chip->lock);
  665. return err;
  666. }
  667. static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
  668. {
  669. struct snd_pcm_runtime *runtime = substream->runtime;
  670. struct audiopipe *pipe = runtime->private_data;
  671. size_t cnt, bufsize, pos;
  672. cnt = le32_to_cpu(*pipe->dma_counter);
  673. pipe->position += cnt - pipe->last_counter;
  674. pipe->last_counter = cnt;
  675. bufsize = substream->runtime->buffer_size;
  676. pos = bytes_to_frames(substream->runtime, pipe->position);
  677. while (pos >= bufsize) {
  678. pipe->position -= frames_to_bytes(substream->runtime, bufsize);
  679. pos -= bufsize;
  680. }
  681. return pos;
  682. }
  683. /* pcm *_ops structures */
  684. static struct snd_pcm_ops analog_playback_ops = {
  685. .open = pcm_analog_out_open,
  686. .close = pcm_close,
  687. .ioctl = snd_pcm_lib_ioctl,
  688. .hw_params = pcm_analog_out_hw_params,
  689. .hw_free = pcm_hw_free,
  690. .prepare = pcm_prepare,
  691. .trigger = pcm_trigger,
  692. .pointer = pcm_pointer,
  693. .page = snd_pcm_sgbuf_ops_page,
  694. };
  695. static struct snd_pcm_ops analog_capture_ops = {
  696. .open = pcm_analog_in_open,
  697. .close = pcm_close,
  698. .ioctl = snd_pcm_lib_ioctl,
  699. .hw_params = pcm_analog_in_hw_params,
  700. .hw_free = pcm_hw_free,
  701. .prepare = pcm_prepare,
  702. .trigger = pcm_trigger,
  703. .pointer = pcm_pointer,
  704. .page = snd_pcm_sgbuf_ops_page,
  705. };
  706. #ifdef ECHOCARD_HAS_DIGITAL_IO
  707. #ifndef ECHOCARD_HAS_VMIXER
  708. static struct snd_pcm_ops digital_playback_ops = {
  709. .open = pcm_digital_out_open,
  710. .close = pcm_close,
  711. .ioctl = snd_pcm_lib_ioctl,
  712. .hw_params = pcm_digital_out_hw_params,
  713. .hw_free = pcm_hw_free,
  714. .prepare = pcm_prepare,
  715. .trigger = pcm_trigger,
  716. .pointer = pcm_pointer,
  717. .page = snd_pcm_sgbuf_ops_page,
  718. };
  719. #endif /* !ECHOCARD_HAS_VMIXER */
  720. static struct snd_pcm_ops digital_capture_ops = {
  721. .open = pcm_digital_in_open,
  722. .close = pcm_close,
  723. .ioctl = snd_pcm_lib_ioctl,
  724. .hw_params = pcm_digital_in_hw_params,
  725. .hw_free = pcm_hw_free,
  726. .prepare = pcm_prepare,
  727. .trigger = pcm_trigger,
  728. .pointer = pcm_pointer,
  729. .page = snd_pcm_sgbuf_ops_page,
  730. };
  731. #endif /* ECHOCARD_HAS_DIGITAL_IO */
  732. /* Preallocate memory only for the first substream because it's the most
  733. * used one
  734. */
  735. static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
  736. {
  737. struct snd_pcm_substream *ss;
  738. int stream, err;
  739. for (stream = 0; stream < 2; stream++)
  740. for (ss = pcm->streams[stream].substream; ss; ss = ss->next) {
  741. err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG,
  742. dev,
  743. ss->number ? 0 : 128<<10,
  744. 256<<10);
  745. if (err < 0)
  746. return err;
  747. }
  748. return 0;
  749. }
  750. /*<--snd_echo_probe() */
  751. static int snd_echo_new_pcm(struct echoaudio *chip)
  752. {
  753. struct snd_pcm *pcm;
  754. int err;
  755. #ifdef ECHOCARD_HAS_VMIXER
  756. /* This card has a Vmixer, that is there is no direct mapping from PCM
  757. streams to physical outputs. The user can mix the streams as he wishes
  758. via control interface and it's possible to send any stream to any
  759. output, thus it makes no sense to keep analog and digital outputs
  760. separated */
  761. /* PCM#0 Virtual outputs and analog inputs */
  762. if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
  763. num_analog_busses_in(chip), &pcm)) < 0)
  764. return err;
  765. pcm->private_data = chip;
  766. chip->analog_pcm = pcm;
  767. strcpy(pcm->name, chip->card->shortname);
  768. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
  769. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
  770. if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
  771. return err;
  772. #ifdef ECHOCARD_HAS_DIGITAL_IO
  773. /* PCM#1 Digital inputs, no outputs */
  774. if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
  775. num_digital_busses_in(chip), &pcm)) < 0)
  776. return err;
  777. pcm->private_data = chip;
  778. chip->digital_pcm = pcm;
  779. strcpy(pcm->name, chip->card->shortname);
  780. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
  781. if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
  782. return err;
  783. #endif /* ECHOCARD_HAS_DIGITAL_IO */
  784. #else /* ECHOCARD_HAS_VMIXER */
  785. /* The card can manage substreams formed by analog and digital channels
  786. at the same time, but I prefer to keep analog and digital channels
  787. separated, because that mixed thing is confusing and useless. So we
  788. register two PCM devices: */
  789. /* PCM#0 Analog i/o */
  790. if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
  791. num_analog_busses_out(chip),
  792. num_analog_busses_in(chip), &pcm)) < 0)
  793. return err;
  794. pcm->private_data = chip;
  795. chip->analog_pcm = pcm;
  796. strcpy(pcm->name, chip->card->shortname);
  797. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
  798. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
  799. if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
  800. return err;
  801. #ifdef ECHOCARD_HAS_DIGITAL_IO
  802. /* PCM#1 Digital i/o */
  803. if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
  804. num_digital_busses_out(chip),
  805. num_digital_busses_in(chip), &pcm)) < 0)
  806. return err;
  807. pcm->private_data = chip;
  808. chip->digital_pcm = pcm;
  809. strcpy(pcm->name, chip->card->shortname);
  810. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
  811. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
  812. if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
  813. return err;
  814. #endif /* ECHOCARD_HAS_DIGITAL_IO */
  815. #endif /* ECHOCARD_HAS_VMIXER */
  816. return 0;
  817. }
  818. /******************************************************************************
  819. Control interface
  820. ******************************************************************************/
  821. #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
  822. /******************* PCM output volume *******************/
  823. static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
  824. struct snd_ctl_elem_info *uinfo)
  825. {
  826. struct echoaudio *chip;
  827. chip = snd_kcontrol_chip(kcontrol);
  828. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  829. uinfo->count = num_busses_out(chip);
  830. uinfo->value.integer.min = ECHOGAIN_MINOUT;
  831. uinfo->value.integer.max = ECHOGAIN_MAXOUT;
  832. return 0;
  833. }
  834. static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
  835. struct snd_ctl_elem_value *ucontrol)
  836. {
  837. struct echoaudio *chip;
  838. int c;
  839. chip = snd_kcontrol_chip(kcontrol);
  840. for (c = 0; c < num_busses_out(chip); c++)
  841. ucontrol->value.integer.value[c] = chip->output_gain[c];
  842. return 0;
  843. }
  844. static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
  845. struct snd_ctl_elem_value *ucontrol)
  846. {
  847. struct echoaudio *chip;
  848. int c, changed, gain;
  849. changed = 0;
  850. chip = snd_kcontrol_chip(kcontrol);
  851. spin_lock_irq(&chip->lock);
  852. for (c = 0; c < num_busses_out(chip); c++) {
  853. gain = ucontrol->value.integer.value[c];
  854. /* Ignore out of range values */
  855. if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
  856. continue;
  857. if (chip->output_gain[c] != gain) {
  858. set_output_gain(chip, c, gain);
  859. changed = 1;
  860. }
  861. }
  862. if (changed)
  863. update_output_line_level(chip);
  864. spin_unlock_irq(&chip->lock);
  865. return changed;
  866. }
  867. #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
  868. /* On the Mia this one controls the line-out volume */
  869. static struct snd_kcontrol_new snd_echo_line_output_gain = {
  870. .name = "Line Playback Volume",
  871. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  872. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  873. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  874. .info = snd_echo_output_gain_info,
  875. .get = snd_echo_output_gain_get,
  876. .put = snd_echo_output_gain_put,
  877. .tlv = {.p = db_scale_output_gain},
  878. };
  879. #else
  880. static struct snd_kcontrol_new snd_echo_pcm_output_gain = {
  881. .name = "PCM Playback Volume",
  882. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  883. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  884. .info = snd_echo_output_gain_info,
  885. .get = snd_echo_output_gain_get,
  886. .put = snd_echo_output_gain_put,
  887. .tlv = {.p = db_scale_output_gain},
  888. };
  889. #endif
  890. #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
  891. #ifdef ECHOCARD_HAS_INPUT_GAIN
  892. /******************* Analog input volume *******************/
  893. static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
  894. struct snd_ctl_elem_info *uinfo)
  895. {
  896. struct echoaudio *chip;
  897. chip = snd_kcontrol_chip(kcontrol);
  898. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  899. uinfo->count = num_analog_busses_in(chip);
  900. uinfo->value.integer.min = ECHOGAIN_MININP;
  901. uinfo->value.integer.max = ECHOGAIN_MAXINP;
  902. return 0;
  903. }
  904. static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
  905. struct snd_ctl_elem_value *ucontrol)
  906. {
  907. struct echoaudio *chip;
  908. int c;
  909. chip = snd_kcontrol_chip(kcontrol);
  910. for (c = 0; c < num_analog_busses_in(chip); c++)
  911. ucontrol->value.integer.value[c] = chip->input_gain[c];
  912. return 0;
  913. }
  914. static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
  915. struct snd_ctl_elem_value *ucontrol)
  916. {
  917. struct echoaudio *chip;
  918. int c, gain, changed;
  919. changed = 0;
  920. chip = snd_kcontrol_chip(kcontrol);
  921. spin_lock_irq(&chip->lock);
  922. for (c = 0; c < num_analog_busses_in(chip); c++) {
  923. gain = ucontrol->value.integer.value[c];
  924. /* Ignore out of range values */
  925. if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
  926. continue;
  927. if (chip->input_gain[c] != gain) {
  928. set_input_gain(chip, c, gain);
  929. changed = 1;
  930. }
  931. }
  932. if (changed)
  933. update_input_line_level(chip);
  934. spin_unlock_irq(&chip->lock);
  935. return changed;
  936. }
  937. static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
  938. static struct snd_kcontrol_new snd_echo_line_input_gain = {
  939. .name = "Line Capture Volume",
  940. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  941. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  942. .info = snd_echo_input_gain_info,
  943. .get = snd_echo_input_gain_get,
  944. .put = snd_echo_input_gain_put,
  945. .tlv = {.p = db_scale_input_gain},
  946. };
  947. #endif /* ECHOCARD_HAS_INPUT_GAIN */
  948. #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
  949. /************ Analog output nominal level (+4dBu / -10dBV) ***************/
  950. static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
  951. struct snd_ctl_elem_info *uinfo)
  952. {
  953. struct echoaudio *chip;
  954. chip = snd_kcontrol_chip(kcontrol);
  955. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  956. uinfo->count = num_analog_busses_out(chip);
  957. uinfo->value.integer.min = 0;
  958. uinfo->value.integer.max = 1;
  959. return 0;
  960. }
  961. static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
  962. struct snd_ctl_elem_value *ucontrol)
  963. {
  964. struct echoaudio *chip;
  965. int c;
  966. chip = snd_kcontrol_chip(kcontrol);
  967. for (c = 0; c < num_analog_busses_out(chip); c++)
  968. ucontrol->value.integer.value[c] = chip->nominal_level[c];
  969. return 0;
  970. }
  971. static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
  972. struct snd_ctl_elem_value *ucontrol)
  973. {
  974. struct echoaudio *chip;
  975. int c, changed;
  976. changed = 0;
  977. chip = snd_kcontrol_chip(kcontrol);
  978. spin_lock_irq(&chip->lock);
  979. for (c = 0; c < num_analog_busses_out(chip); c++) {
  980. if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
  981. set_nominal_level(chip, c,
  982. ucontrol->value.integer.value[c]);
  983. changed = 1;
  984. }
  985. }
  986. if (changed)
  987. update_output_line_level(chip);
  988. spin_unlock_irq(&chip->lock);
  989. return changed;
  990. }
  991. static struct snd_kcontrol_new snd_echo_output_nominal_level = {
  992. .name = "Line Playback Switch (-10dBV)",
  993. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  994. .info = snd_echo_output_nominal_info,
  995. .get = snd_echo_output_nominal_get,
  996. .put = snd_echo_output_nominal_put,
  997. };
  998. #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
  999. #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
  1000. /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
  1001. static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
  1002. struct snd_ctl_elem_info *uinfo)
  1003. {
  1004. struct echoaudio *chip;
  1005. chip = snd_kcontrol_chip(kcontrol);
  1006. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1007. uinfo->count = num_analog_busses_in(chip);
  1008. uinfo->value.integer.min = 0;
  1009. uinfo->value.integer.max = 1;
  1010. return 0;
  1011. }
  1012. static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
  1013. struct snd_ctl_elem_value *ucontrol)
  1014. {
  1015. struct echoaudio *chip;
  1016. int c;
  1017. chip = snd_kcontrol_chip(kcontrol);
  1018. for (c = 0; c < num_analog_busses_in(chip); c++)
  1019. ucontrol->value.integer.value[c] =
  1020. chip->nominal_level[bx_analog_in(chip) + c];
  1021. return 0;
  1022. }
  1023. static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
  1024. struct snd_ctl_elem_value *ucontrol)
  1025. {
  1026. struct echoaudio *chip;
  1027. int c, changed;
  1028. changed = 0;
  1029. chip = snd_kcontrol_chip(kcontrol);
  1030. spin_lock_irq(&chip->lock);
  1031. for (c = 0; c < num_analog_busses_in(chip); c++) {
  1032. if (chip->nominal_level[bx_analog_in(chip) + c] !=
  1033. ucontrol->value.integer.value[c]) {
  1034. set_nominal_level(chip, bx_analog_in(chip) + c,
  1035. ucontrol->value.integer.value[c]);
  1036. changed = 1;
  1037. }
  1038. }
  1039. if (changed)
  1040. update_output_line_level(chip); /* "Output" is not a mistake
  1041. * here.
  1042. */
  1043. spin_unlock_irq(&chip->lock);
  1044. return changed;
  1045. }
  1046. static struct snd_kcontrol_new snd_echo_intput_nominal_level = {
  1047. .name = "Line Capture Switch (-10dBV)",
  1048. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1049. .info = snd_echo_input_nominal_info,
  1050. .get = snd_echo_input_nominal_get,
  1051. .put = snd_echo_input_nominal_put,
  1052. };
  1053. #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
  1054. #ifdef ECHOCARD_HAS_MONITOR
  1055. /******************* Monitor mixer *******************/
  1056. static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
  1057. struct snd_ctl_elem_info *uinfo)
  1058. {
  1059. struct echoaudio *chip;
  1060. chip = snd_kcontrol_chip(kcontrol);
  1061. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1062. uinfo->count = 1;
  1063. uinfo->value.integer.min = ECHOGAIN_MINOUT;
  1064. uinfo->value.integer.max = ECHOGAIN_MAXOUT;
  1065. uinfo->dimen.d[0] = num_busses_out(chip);
  1066. uinfo->dimen.d[1] = num_busses_in(chip);
  1067. return 0;
  1068. }
  1069. static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
  1070. struct snd_ctl_elem_value *ucontrol)
  1071. {
  1072. struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
  1073. unsigned int out = ucontrol->id.index / num_busses_in(chip);
  1074. unsigned int in = ucontrol->id.index % num_busses_in(chip);
  1075. if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
  1076. return -EINVAL;
  1077. ucontrol->value.integer.value[0] = chip->monitor_gain[out][in];
  1078. return 0;
  1079. }
  1080. static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
  1081. struct snd_ctl_elem_value *ucontrol)
  1082. {
  1083. struct echoaudio *chip;
  1084. int changed, gain;
  1085. unsigned int out, in;
  1086. changed = 0;
  1087. chip = snd_kcontrol_chip(kcontrol);
  1088. out = ucontrol->id.index / num_busses_in(chip);
  1089. in = ucontrol->id.index % num_busses_in(chip);
  1090. if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
  1091. return -EINVAL;
  1092. gain = ucontrol->value.integer.value[0];
  1093. if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
  1094. return -EINVAL;
  1095. if (chip->monitor_gain[out][in] != gain) {
  1096. spin_lock_irq(&chip->lock);
  1097. set_monitor_gain(chip, out, in, gain);
  1098. update_output_line_level(chip);
  1099. spin_unlock_irq(&chip->lock);
  1100. changed = 1;
  1101. }
  1102. return changed;
  1103. }
  1104. static struct snd_kcontrol_new snd_echo_monitor_mixer = {
  1105. .name = "Monitor Mixer Volume",
  1106. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1107. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  1108. .info = snd_echo_mixer_info,
  1109. .get = snd_echo_mixer_get,
  1110. .put = snd_echo_mixer_put,
  1111. .tlv = {.p = db_scale_output_gain},
  1112. };
  1113. #endif /* ECHOCARD_HAS_MONITOR */
  1114. #ifdef ECHOCARD_HAS_VMIXER
  1115. /******************* Vmixer *******************/
  1116. static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
  1117. struct snd_ctl_elem_info *uinfo)
  1118. {
  1119. struct echoaudio *chip;
  1120. chip = snd_kcontrol_chip(kcontrol);
  1121. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1122. uinfo->count = 1;
  1123. uinfo->value.integer.min = ECHOGAIN_MINOUT;
  1124. uinfo->value.integer.max = ECHOGAIN_MAXOUT;
  1125. uinfo->dimen.d[0] = num_busses_out(chip);
  1126. uinfo->dimen.d[1] = num_pipes_out(chip);
  1127. return 0;
  1128. }
  1129. static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
  1130. struct snd_ctl_elem_value *ucontrol)
  1131. {
  1132. struct echoaudio *chip;
  1133. chip = snd_kcontrol_chip(kcontrol);
  1134. ucontrol->value.integer.value[0] =
  1135. chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
  1136. [ucontrol->id.index % num_pipes_out(chip)];
  1137. return 0;
  1138. }
  1139. static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
  1140. struct snd_ctl_elem_value *ucontrol)
  1141. {
  1142. struct echoaudio *chip;
  1143. int gain, changed;
  1144. short vch, out;
  1145. changed = 0;
  1146. chip = snd_kcontrol_chip(kcontrol);
  1147. out = ucontrol->id.index / num_pipes_out(chip);
  1148. vch = ucontrol->id.index % num_pipes_out(chip);
  1149. gain = ucontrol->value.integer.value[0];
  1150. if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
  1151. return -EINVAL;
  1152. if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
  1153. spin_lock_irq(&chip->lock);
  1154. set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
  1155. update_vmixer_level(chip);
  1156. spin_unlock_irq(&chip->lock);
  1157. changed = 1;
  1158. }
  1159. return changed;
  1160. }
  1161. static struct snd_kcontrol_new snd_echo_vmixer = {
  1162. .name = "VMixer Volume",
  1163. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1164. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  1165. .info = snd_echo_vmixer_info,
  1166. .get = snd_echo_vmixer_get,
  1167. .put = snd_echo_vmixer_put,
  1168. .tlv = {.p = db_scale_output_gain},
  1169. };
  1170. #endif /* ECHOCARD_HAS_VMIXER */
  1171. #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
  1172. /******************* Digital mode switch *******************/
  1173. static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
  1174. struct snd_ctl_elem_info *uinfo)
  1175. {
  1176. static const char * const names[4] = {
  1177. "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
  1178. "S/PDIF Cdrom"
  1179. };
  1180. struct echoaudio *chip;
  1181. chip = snd_kcontrol_chip(kcontrol);
  1182. return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
  1183. }
  1184. static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
  1185. struct snd_ctl_elem_value *ucontrol)
  1186. {
  1187. struct echoaudio *chip;
  1188. int i, mode;
  1189. chip = snd_kcontrol_chip(kcontrol);
  1190. mode = chip->digital_mode;
  1191. for (i = chip->num_digital_modes - 1; i >= 0; i--)
  1192. if (mode == chip->digital_mode_list[i]) {
  1193. ucontrol->value.enumerated.item[0] = i;
  1194. break;
  1195. }
  1196. return 0;
  1197. }
  1198. static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
  1199. struct snd_ctl_elem_value *ucontrol)
  1200. {
  1201. struct echoaudio *chip;
  1202. int changed;
  1203. unsigned short emode, dmode;
  1204. changed = 0;
  1205. chip = snd_kcontrol_chip(kcontrol);
  1206. emode = ucontrol->value.enumerated.item[0];
  1207. if (emode >= chip->num_digital_modes)
  1208. return -EINVAL;
  1209. dmode = chip->digital_mode_list[emode];
  1210. if (dmode != chip->digital_mode) {
  1211. /* mode_mutex is required to make this operation atomic wrt
  1212. pcm_digital_*_open() and set_input_clock() functions. */
  1213. mutex_lock(&chip->mode_mutex);
  1214. /* Do not allow the user to change the digital mode when a pcm
  1215. device is open because it also changes the number of channels
  1216. and the allowed sample rates */
  1217. if (atomic_read(&chip->opencount)) {
  1218. changed = -EAGAIN;
  1219. } else {
  1220. changed = set_digital_mode(chip, dmode);
  1221. /* If we had to change the clock source, report it */
  1222. if (changed > 0 && chip->clock_src_ctl) {
  1223. snd_ctl_notify(chip->card,
  1224. SNDRV_CTL_EVENT_MASK_VALUE,
  1225. &chip->clock_src_ctl->id);
  1226. dev_dbg(chip->card->dev,
  1227. "SDM() =%d\n", changed);
  1228. }
  1229. if (changed >= 0)
  1230. changed = 1; /* No errors */
  1231. }
  1232. mutex_unlock(&chip->mode_mutex);
  1233. }
  1234. return changed;
  1235. }
  1236. static struct snd_kcontrol_new snd_echo_digital_mode_switch = {
  1237. .name = "Digital mode Switch",
  1238. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1239. .info = snd_echo_digital_mode_info,
  1240. .get = snd_echo_digital_mode_get,
  1241. .put = snd_echo_digital_mode_put,
  1242. };
  1243. #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
  1244. #ifdef ECHOCARD_HAS_DIGITAL_IO
  1245. /******************* S/PDIF mode switch *******************/
  1246. static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
  1247. struct snd_ctl_elem_info *uinfo)
  1248. {
  1249. static const char * const names[2] = {"Consumer", "Professional"};
  1250. return snd_ctl_enum_info(uinfo, 1, 2, names);
  1251. }
  1252. static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
  1253. struct snd_ctl_elem_value *ucontrol)
  1254. {
  1255. struct echoaudio *chip;
  1256. chip = snd_kcontrol_chip(kcontrol);
  1257. ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
  1258. return 0;
  1259. }
  1260. static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
  1261. struct snd_ctl_elem_value *ucontrol)
  1262. {
  1263. struct echoaudio *chip;
  1264. int mode;
  1265. chip = snd_kcontrol_chip(kcontrol);
  1266. mode = !!ucontrol->value.enumerated.item[0];
  1267. if (mode != chip->professional_spdif) {
  1268. spin_lock_irq(&chip->lock);
  1269. set_professional_spdif(chip, mode);
  1270. spin_unlock_irq(&chip->lock);
  1271. return 1;
  1272. }
  1273. return 0;
  1274. }
  1275. static struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
  1276. .name = "S/PDIF mode Switch",
  1277. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1278. .info = snd_echo_spdif_mode_info,
  1279. .get = snd_echo_spdif_mode_get,
  1280. .put = snd_echo_spdif_mode_put,
  1281. };
  1282. #endif /* ECHOCARD_HAS_DIGITAL_IO */
  1283. #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
  1284. /******************* Select input clock source *******************/
  1285. static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
  1286. struct snd_ctl_elem_info *uinfo)
  1287. {
  1288. static const char * const names[8] = {
  1289. "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
  1290. "ESync96", "MTC"
  1291. };
  1292. struct echoaudio *chip;
  1293. chip = snd_kcontrol_chip(kcontrol);
  1294. return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
  1295. }
  1296. static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
  1297. struct snd_ctl_elem_value *ucontrol)
  1298. {
  1299. struct echoaudio *chip;
  1300. int i, clock;
  1301. chip = snd_kcontrol_chip(kcontrol);
  1302. clock = chip->input_clock;
  1303. for (i = 0; i < chip->num_clock_sources; i++)
  1304. if (clock == chip->clock_source_list[i])
  1305. ucontrol->value.enumerated.item[0] = i;
  1306. return 0;
  1307. }
  1308. static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
  1309. struct snd_ctl_elem_value *ucontrol)
  1310. {
  1311. struct echoaudio *chip;
  1312. int changed;
  1313. unsigned int eclock, dclock;
  1314. changed = 0;
  1315. chip = snd_kcontrol_chip(kcontrol);
  1316. eclock = ucontrol->value.enumerated.item[0];
  1317. if (eclock >= chip->input_clock_types)
  1318. return -EINVAL;
  1319. dclock = chip->clock_source_list[eclock];
  1320. if (chip->input_clock != dclock) {
  1321. mutex_lock(&chip->mode_mutex);
  1322. spin_lock_irq(&chip->lock);
  1323. if ((changed = set_input_clock(chip, dclock)) == 0)
  1324. changed = 1; /* no errors */
  1325. spin_unlock_irq(&chip->lock);
  1326. mutex_unlock(&chip->mode_mutex);
  1327. }
  1328. if (changed < 0)
  1329. dev_dbg(chip->card->dev,
  1330. "seticlk val%d err 0x%x\n", dclock, changed);
  1331. return changed;
  1332. }
  1333. static struct snd_kcontrol_new snd_echo_clock_source_switch = {
  1334. .name = "Sample Clock Source",
  1335. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1336. .info = snd_echo_clock_source_info,
  1337. .get = snd_echo_clock_source_get,
  1338. .put = snd_echo_clock_source_put,
  1339. };
  1340. #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
  1341. #ifdef ECHOCARD_HAS_PHANTOM_POWER
  1342. /******************* Phantom power switch *******************/
  1343. #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
  1344. static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
  1345. struct snd_ctl_elem_value *ucontrol)
  1346. {
  1347. struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
  1348. ucontrol->value.integer.value[0] = chip->phantom_power;
  1349. return 0;
  1350. }
  1351. static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
  1352. struct snd_ctl_elem_value *ucontrol)
  1353. {
  1354. struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
  1355. int power, changed = 0;
  1356. power = !!ucontrol->value.integer.value[0];
  1357. if (chip->phantom_power != power) {
  1358. spin_lock_irq(&chip->lock);
  1359. changed = set_phantom_power(chip, power);
  1360. spin_unlock_irq(&chip->lock);
  1361. if (changed == 0)
  1362. changed = 1; /* no errors */
  1363. }
  1364. return changed;
  1365. }
  1366. static struct snd_kcontrol_new snd_echo_phantom_power_switch = {
  1367. .name = "Phantom power Switch",
  1368. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1369. .info = snd_echo_phantom_power_info,
  1370. .get = snd_echo_phantom_power_get,
  1371. .put = snd_echo_phantom_power_put,
  1372. };
  1373. #endif /* ECHOCARD_HAS_PHANTOM_POWER */
  1374. #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
  1375. /******************* Digital input automute switch *******************/
  1376. #define snd_echo_automute_info snd_ctl_boolean_mono_info
  1377. static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
  1378. struct snd_ctl_elem_value *ucontrol)
  1379. {
  1380. struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
  1381. ucontrol->value.integer.value[0] = chip->digital_in_automute;
  1382. return 0;
  1383. }
  1384. static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
  1385. struct snd_ctl_elem_value *ucontrol)
  1386. {
  1387. struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
  1388. int automute, changed = 0;
  1389. automute = !!ucontrol->value.integer.value[0];
  1390. if (chip->digital_in_automute != automute) {
  1391. spin_lock_irq(&chip->lock);
  1392. changed = set_input_auto_mute(chip, automute);
  1393. spin_unlock_irq(&chip->lock);
  1394. if (changed == 0)
  1395. changed = 1; /* no errors */
  1396. }
  1397. return changed;
  1398. }
  1399. static struct snd_kcontrol_new snd_echo_automute_switch = {
  1400. .name = "Digital Capture Switch (automute)",
  1401. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1402. .info = snd_echo_automute_info,
  1403. .get = snd_echo_automute_get,
  1404. .put = snd_echo_automute_put,
  1405. };
  1406. #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
  1407. /******************* VU-meters switch *******************/
  1408. #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
  1409. static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
  1410. struct snd_ctl_elem_value *ucontrol)
  1411. {
  1412. struct echoaudio *chip;
  1413. chip = snd_kcontrol_chip(kcontrol);
  1414. spin_lock_irq(&chip->lock);
  1415. set_meters_on(chip, ucontrol->value.integer.value[0]);
  1416. spin_unlock_irq(&chip->lock);
  1417. return 1;
  1418. }
  1419. static struct snd_kcontrol_new snd_echo_vumeters_switch = {
  1420. .name = "VU-meters Switch",
  1421. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1422. .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
  1423. .info = snd_echo_vumeters_switch_info,
  1424. .put = snd_echo_vumeters_switch_put,
  1425. };
  1426. /***** Read VU-meters (input, output, analog and digital together) *****/
  1427. static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
  1428. struct snd_ctl_elem_info *uinfo)
  1429. {
  1430. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1431. uinfo->count = 96;
  1432. uinfo->value.integer.min = ECHOGAIN_MINOUT;
  1433. uinfo->value.integer.max = 0;
  1434. #ifdef ECHOCARD_HAS_VMIXER
  1435. uinfo->dimen.d[0] = 3; /* Out, In, Virt */
  1436. #else
  1437. uinfo->dimen.d[0] = 2; /* Out, In */
  1438. #endif
  1439. uinfo->dimen.d[1] = 16; /* 16 channels */
  1440. uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
  1441. return 0;
  1442. }
  1443. static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
  1444. struct snd_ctl_elem_value *ucontrol)
  1445. {
  1446. struct echoaudio *chip;
  1447. chip = snd_kcontrol_chip(kcontrol);
  1448. get_audio_meters(chip, ucontrol->value.integer.value);
  1449. return 0;
  1450. }
  1451. static struct snd_kcontrol_new snd_echo_vumeters = {
  1452. .name = "VU-meters",
  1453. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1454. .access = SNDRV_CTL_ELEM_ACCESS_READ |
  1455. SNDRV_CTL_ELEM_ACCESS_VOLATILE |
  1456. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  1457. .info = snd_echo_vumeters_info,
  1458. .get = snd_echo_vumeters_get,
  1459. .tlv = {.p = db_scale_output_gain},
  1460. };
  1461. /*** Channels info - it exports informations about the number of channels ***/
  1462. static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
  1463. struct snd_ctl_elem_info *uinfo)
  1464. {
  1465. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1466. uinfo->count = 6;
  1467. uinfo->value.integer.min = 0;
  1468. uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
  1469. return 0;
  1470. }
  1471. static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
  1472. struct snd_ctl_elem_value *ucontrol)
  1473. {
  1474. struct echoaudio *chip;
  1475. int detected, clocks, bit, src;
  1476. chip = snd_kcontrol_chip(kcontrol);
  1477. ucontrol->value.integer.value[0] = num_busses_in(chip);
  1478. ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
  1479. ucontrol->value.integer.value[2] = num_busses_out(chip);
  1480. ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
  1481. ucontrol->value.integer.value[4] = num_pipes_out(chip);
  1482. /* Compute the bitmask of the currently valid input clocks */
  1483. detected = detect_input_clocks(chip);
  1484. clocks = 0;
  1485. src = chip->num_clock_sources - 1;
  1486. for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
  1487. if (detected & (1 << bit))
  1488. for (; src >= 0; src--)
  1489. if (bit == chip->clock_source_list[src]) {
  1490. clocks |= 1 << src;
  1491. break;
  1492. }
  1493. ucontrol->value.integer.value[5] = clocks;
  1494. return 0;
  1495. }
  1496. static struct snd_kcontrol_new snd_echo_channels_info = {
  1497. .name = "Channels info",
  1498. .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
  1499. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1500. .info = snd_echo_channels_info_info,
  1501. .get = snd_echo_channels_info_get,
  1502. };
  1503. /******************************************************************************
  1504. IRQ Handler
  1505. ******************************************************************************/
  1506. static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
  1507. {
  1508. struct echoaudio *chip = dev_id;
  1509. struct snd_pcm_substream *substream;
  1510. int period, ss, st;
  1511. spin_lock(&chip->lock);
  1512. st = service_irq(chip);
  1513. if (st < 0) {
  1514. spin_unlock(&chip->lock);
  1515. return IRQ_NONE;
  1516. }
  1517. /* The hardware doesn't tell us which substream caused the irq,
  1518. thus we have to check all running substreams. */
  1519. for (ss = 0; ss < DSP_MAXPIPES; ss++) {
  1520. substream = chip->substream[ss];
  1521. if (substream && ((struct audiopipe *)substream->runtime->
  1522. private_data)->state == PIPE_STATE_STARTED) {
  1523. period = pcm_pointer(substream) /
  1524. substream->runtime->period_size;
  1525. if (period != chip->last_period[ss]) {
  1526. chip->last_period[ss] = period;
  1527. spin_unlock(&chip->lock);
  1528. snd_pcm_period_elapsed(substream);
  1529. spin_lock(&chip->lock);
  1530. }
  1531. }
  1532. }
  1533. spin_unlock(&chip->lock);
  1534. #ifdef ECHOCARD_HAS_MIDI
  1535. if (st > 0 && chip->midi_in) {
  1536. snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
  1537. dev_dbg(chip->card->dev, "rawmidi_iread=%d\n", st);
  1538. }
  1539. #endif
  1540. return IRQ_HANDLED;
  1541. }
  1542. /******************************************************************************
  1543. Module construction / destruction
  1544. ******************************************************************************/
  1545. static int snd_echo_free(struct echoaudio *chip)
  1546. {
  1547. if (chip->comm_page)
  1548. rest_in_peace(chip);
  1549. if (chip->irq >= 0)
  1550. free_irq(chip->irq, chip);
  1551. if (chip->comm_page)
  1552. snd_dma_free_pages(&chip->commpage_dma_buf);
  1553. iounmap(chip->dsp_registers);
  1554. release_and_free_resource(chip->iores);
  1555. pci_disable_device(chip->pci);
  1556. /* release chip data */
  1557. free_firmware_cache(chip);
  1558. kfree(chip);
  1559. return 0;
  1560. }
  1561. static int snd_echo_dev_free(struct snd_device *device)
  1562. {
  1563. struct echoaudio *chip = device->device_data;
  1564. return snd_echo_free(chip);
  1565. }
  1566. /* <--snd_echo_probe() */
  1567. static int snd_echo_create(struct snd_card *card,
  1568. struct pci_dev *pci,
  1569. struct echoaudio **rchip)
  1570. {
  1571. struct echoaudio *chip;
  1572. int err;
  1573. size_t sz;
  1574. static struct snd_device_ops ops = {
  1575. .dev_free = snd_echo_dev_free,
  1576. };
  1577. *rchip = NULL;
  1578. pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
  1579. if ((err = pci_enable_device(pci)) < 0)
  1580. return err;
  1581. pci_set_master(pci);
  1582. /* Allocate chip if needed */
  1583. if (!*rchip) {
  1584. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1585. if (!chip) {
  1586. pci_disable_device(pci);
  1587. return -ENOMEM;
  1588. }
  1589. dev_dbg(card->dev, "chip=%p\n", chip);
  1590. spin_lock_init(&chip->lock);
  1591. chip->card = card;
  1592. chip->pci = pci;
  1593. chip->irq = -1;
  1594. atomic_set(&chip->opencount, 0);
  1595. mutex_init(&chip->mode_mutex);
  1596. chip->can_set_rate = 1;
  1597. } else {
  1598. /* If this was called from the resume function, chip is
  1599. * already allocated and it contains current card settings.
  1600. */
  1601. chip = *rchip;
  1602. }
  1603. /* PCI resource allocation */
  1604. chip->dsp_registers_phys = pci_resource_start(pci, 0);
  1605. sz = pci_resource_len(pci, 0);
  1606. if (sz > PAGE_SIZE)
  1607. sz = PAGE_SIZE; /* We map only the required part */
  1608. if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
  1609. ECHOCARD_NAME)) == NULL) {
  1610. dev_err(chip->card->dev, "cannot get memory region\n");
  1611. snd_echo_free(chip);
  1612. return -EBUSY;
  1613. }
  1614. chip->dsp_registers = (volatile u32 __iomem *)
  1615. ioremap_nocache(chip->dsp_registers_phys, sz);
  1616. if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
  1617. KBUILD_MODNAME, chip)) {
  1618. dev_err(chip->card->dev, "cannot grab irq\n");
  1619. snd_echo_free(chip);
  1620. return -EBUSY;
  1621. }
  1622. chip->irq = pci->irq;
  1623. dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n",
  1624. chip->pci, chip->irq, chip->pci->subsystem_device);
  1625. /* Create the DSP comm page - this is the area of memory used for most
  1626. of the communication with the DSP, which accesses it via bus mastering */
  1627. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
  1628. sizeof(struct comm_page),
  1629. &chip->commpage_dma_buf) < 0) {
  1630. dev_err(chip->card->dev, "cannot allocate the comm page\n");
  1631. snd_echo_free(chip);
  1632. return -ENOMEM;
  1633. }
  1634. chip->comm_page_phys = chip->commpage_dma_buf.addr;
  1635. chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
  1636. err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
  1637. if (err >= 0)
  1638. err = set_mixer_defaults(chip);
  1639. if (err < 0) {
  1640. dev_err(card->dev, "init_hw err=%d\n", err);
  1641. snd_echo_free(chip);
  1642. return err;
  1643. }
  1644. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  1645. snd_echo_free(chip);
  1646. return err;
  1647. }
  1648. *rchip = chip;
  1649. /* Init done ! */
  1650. return 0;
  1651. }
  1652. /* constructor */
  1653. static int snd_echo_probe(struct pci_dev *pci,
  1654. const struct pci_device_id *pci_id)
  1655. {
  1656. static int dev;
  1657. struct snd_card *card;
  1658. struct echoaudio *chip;
  1659. char *dsp;
  1660. int i, err;
  1661. if (dev >= SNDRV_CARDS)
  1662. return -ENODEV;
  1663. if (!enable[dev]) {
  1664. dev++;
  1665. return -ENOENT;
  1666. }
  1667. i = 0;
  1668. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  1669. 0, &card);
  1670. if (err < 0)
  1671. return err;
  1672. chip = NULL; /* Tells snd_echo_create to allocate chip */
  1673. if ((err = snd_echo_create(card, pci, &chip)) < 0) {
  1674. snd_card_free(card);
  1675. return err;
  1676. }
  1677. strcpy(card->driver, "Echo_" ECHOCARD_NAME);
  1678. strcpy(card->shortname, chip->card_name);
  1679. dsp = "56301";
  1680. if (pci_id->device == 0x3410)
  1681. dsp = "56361";
  1682. sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
  1683. card->shortname, pci_id->subdevice & 0x000f, dsp,
  1684. chip->dsp_registers_phys, chip->irq);
  1685. if ((err = snd_echo_new_pcm(chip)) < 0) {
  1686. dev_err(chip->card->dev, "new pcm error %d\n", err);
  1687. snd_card_free(card);
  1688. return err;
  1689. }
  1690. #ifdef ECHOCARD_HAS_MIDI
  1691. if (chip->has_midi) { /* Some Mia's do not have midi */
  1692. if ((err = snd_echo_midi_create(card, chip)) < 0) {
  1693. dev_err(chip->card->dev, "new midi error %d\n", err);
  1694. snd_card_free(card);
  1695. return err;
  1696. }
  1697. }
  1698. #endif
  1699. #ifdef ECHOCARD_HAS_VMIXER
  1700. snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
  1701. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
  1702. goto ctl_error;
  1703. #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
  1704. err = snd_ctl_add(chip->card,
  1705. snd_ctl_new1(&snd_echo_line_output_gain, chip));
  1706. if (err < 0)
  1707. goto ctl_error;
  1708. #endif
  1709. #else /* ECHOCARD_HAS_VMIXER */
  1710. err = snd_ctl_add(chip->card,
  1711. snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
  1712. if (err < 0)
  1713. goto ctl_error;
  1714. #endif /* ECHOCARD_HAS_VMIXER */
  1715. #ifdef ECHOCARD_HAS_INPUT_GAIN
  1716. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
  1717. goto ctl_error;
  1718. #endif
  1719. #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
  1720. if (!chip->hasnt_input_nominal_level)
  1721. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
  1722. goto ctl_error;
  1723. #endif
  1724. #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
  1725. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
  1726. goto ctl_error;
  1727. #endif
  1728. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
  1729. goto ctl_error;
  1730. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
  1731. goto ctl_error;
  1732. #ifdef ECHOCARD_HAS_MONITOR
  1733. snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
  1734. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
  1735. goto ctl_error;
  1736. #endif
  1737. #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
  1738. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
  1739. goto ctl_error;
  1740. #endif
  1741. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
  1742. goto ctl_error;
  1743. #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
  1744. /* Creates a list of available digital modes */
  1745. chip->num_digital_modes = 0;
  1746. for (i = 0; i < 6; i++)
  1747. if (chip->digital_modes & (1 << i))
  1748. chip->digital_mode_list[chip->num_digital_modes++] = i;
  1749. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
  1750. goto ctl_error;
  1751. #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
  1752. #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
  1753. /* Creates a list of available clock sources */
  1754. chip->num_clock_sources = 0;
  1755. for (i = 0; i < 10; i++)
  1756. if (chip->input_clock_types & (1 << i))
  1757. chip->clock_source_list[chip->num_clock_sources++] = i;
  1758. if (chip->num_clock_sources > 1) {
  1759. chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
  1760. if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
  1761. goto ctl_error;
  1762. }
  1763. #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
  1764. #ifdef ECHOCARD_HAS_DIGITAL_IO
  1765. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
  1766. goto ctl_error;
  1767. #endif
  1768. #ifdef ECHOCARD_HAS_PHANTOM_POWER
  1769. if (chip->has_phantom_power)
  1770. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
  1771. goto ctl_error;
  1772. #endif
  1773. err = snd_card_register(card);
  1774. if (err < 0)
  1775. goto ctl_error;
  1776. dev_info(card->dev, "Card registered: %s\n", card->longname);
  1777. pci_set_drvdata(pci, chip);
  1778. dev++;
  1779. return 0;
  1780. ctl_error:
  1781. dev_err(card->dev, "new control error %d\n", err);
  1782. snd_card_free(card);
  1783. return err;
  1784. }
  1785. #if defined(CONFIG_PM_SLEEP)
  1786. static int snd_echo_suspend(struct device *dev)
  1787. {
  1788. struct echoaudio *chip = dev_get_drvdata(dev);
  1789. snd_pcm_suspend_all(chip->analog_pcm);
  1790. snd_pcm_suspend_all(chip->digital_pcm);
  1791. #ifdef ECHOCARD_HAS_MIDI
  1792. /* This call can sleep */
  1793. if (chip->midi_out)
  1794. snd_echo_midi_output_trigger(chip->midi_out, 0);
  1795. #endif
  1796. spin_lock_irq(&chip->lock);
  1797. if (wait_handshake(chip)) {
  1798. spin_unlock_irq(&chip->lock);
  1799. return -EIO;
  1800. }
  1801. clear_handshake(chip);
  1802. if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
  1803. spin_unlock_irq(&chip->lock);
  1804. return -EIO;
  1805. }
  1806. spin_unlock_irq(&chip->lock);
  1807. chip->dsp_code = NULL;
  1808. free_irq(chip->irq, chip);
  1809. chip->irq = -1;
  1810. return 0;
  1811. }
  1812. static int snd_echo_resume(struct device *dev)
  1813. {
  1814. struct pci_dev *pci = to_pci_dev(dev);
  1815. struct echoaudio *chip = dev_get_drvdata(dev);
  1816. struct comm_page *commpage, *commpage_bak;
  1817. u32 pipe_alloc_mask;
  1818. int err;
  1819. commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL);
  1820. if (commpage_bak == NULL)
  1821. return -ENOMEM;
  1822. commpage = chip->comm_page;
  1823. memcpy(commpage_bak, commpage, sizeof(struct comm_page));
  1824. err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
  1825. if (err < 0) {
  1826. kfree(commpage_bak);
  1827. dev_err(dev, "resume init_hw err=%d\n", err);
  1828. snd_echo_free(chip);
  1829. return err;
  1830. }
  1831. /* Temporarily set chip->pipe_alloc_mask=0 otherwise
  1832. * restore_dsp_settings() fails.
  1833. */
  1834. pipe_alloc_mask = chip->pipe_alloc_mask;
  1835. chip->pipe_alloc_mask = 0;
  1836. err = restore_dsp_rettings(chip);
  1837. chip->pipe_alloc_mask = pipe_alloc_mask;
  1838. if (err < 0) {
  1839. kfree(commpage_bak);
  1840. return err;
  1841. }
  1842. memcpy(&commpage->audio_format, &commpage_bak->audio_format,
  1843. sizeof(commpage->audio_format));
  1844. memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
  1845. sizeof(commpage->sglist_addr));
  1846. memcpy(&commpage->midi_output, &commpage_bak->midi_output,
  1847. sizeof(commpage->midi_output));
  1848. kfree(commpage_bak);
  1849. if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
  1850. KBUILD_MODNAME, chip)) {
  1851. dev_err(chip->card->dev, "cannot grab irq\n");
  1852. snd_echo_free(chip);
  1853. return -EBUSY;
  1854. }
  1855. chip->irq = pci->irq;
  1856. dev_dbg(dev, "resume irq=%d\n", chip->irq);
  1857. #ifdef ECHOCARD_HAS_MIDI
  1858. if (chip->midi_input_enabled)
  1859. enable_midi_input(chip, TRUE);
  1860. if (chip->midi_out)
  1861. snd_echo_midi_output_trigger(chip->midi_out, 1);
  1862. #endif
  1863. return 0;
  1864. }
  1865. static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
  1866. #define SND_ECHO_PM_OPS &snd_echo_pm
  1867. #else
  1868. #define SND_ECHO_PM_OPS NULL
  1869. #endif /* CONFIG_PM_SLEEP */
  1870. static void snd_echo_remove(struct pci_dev *pci)
  1871. {
  1872. struct echoaudio *chip;
  1873. chip = pci_get_drvdata(pci);
  1874. if (chip)
  1875. snd_card_free(chip->card);
  1876. }
  1877. /******************************************************************************
  1878. Everything starts and ends here
  1879. ******************************************************************************/
  1880. /* pci_driver definition */
  1881. static struct pci_driver echo_driver = {
  1882. .name = KBUILD_MODNAME,
  1883. .id_table = snd_echo_ids,
  1884. .probe = snd_echo_probe,
  1885. .remove = snd_echo_remove,
  1886. .driver = {
  1887. .pm = SND_ECHO_PM_OPS,
  1888. },
  1889. };
  1890. module_pci_driver(echo_driver);