echoaudio.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  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), "ea/%s", card_fw[fw_index].data);
  52. err = request_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 (!chip->dsp_registers) {
  1617. dev_err(chip->card->dev, "ioremap failed\n");
  1618. snd_echo_free(chip);
  1619. return -ENOMEM;
  1620. }
  1621. if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
  1622. KBUILD_MODNAME, chip)) {
  1623. dev_err(chip->card->dev, "cannot grab irq\n");
  1624. snd_echo_free(chip);
  1625. return -EBUSY;
  1626. }
  1627. chip->irq = pci->irq;
  1628. dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n",
  1629. chip->pci, chip->irq, chip->pci->subsystem_device);
  1630. /* Create the DSP comm page - this is the area of memory used for most
  1631. of the communication with the DSP, which accesses it via bus mastering */
  1632. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
  1633. sizeof(struct comm_page),
  1634. &chip->commpage_dma_buf) < 0) {
  1635. dev_err(chip->card->dev, "cannot allocate the comm page\n");
  1636. snd_echo_free(chip);
  1637. return -ENOMEM;
  1638. }
  1639. chip->comm_page_phys = chip->commpage_dma_buf.addr;
  1640. chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
  1641. err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
  1642. if (err >= 0)
  1643. err = set_mixer_defaults(chip);
  1644. if (err < 0) {
  1645. dev_err(card->dev, "init_hw err=%d\n", err);
  1646. snd_echo_free(chip);
  1647. return err;
  1648. }
  1649. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  1650. snd_echo_free(chip);
  1651. return err;
  1652. }
  1653. *rchip = chip;
  1654. /* Init done ! */
  1655. return 0;
  1656. }
  1657. /* constructor */
  1658. static int snd_echo_probe(struct pci_dev *pci,
  1659. const struct pci_device_id *pci_id)
  1660. {
  1661. static int dev;
  1662. struct snd_card *card;
  1663. struct echoaudio *chip;
  1664. char *dsp;
  1665. int i, err;
  1666. if (dev >= SNDRV_CARDS)
  1667. return -ENODEV;
  1668. if (!enable[dev]) {
  1669. dev++;
  1670. return -ENOENT;
  1671. }
  1672. i = 0;
  1673. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  1674. 0, &card);
  1675. if (err < 0)
  1676. return err;
  1677. chip = NULL; /* Tells snd_echo_create to allocate chip */
  1678. if ((err = snd_echo_create(card, pci, &chip)) < 0) {
  1679. snd_card_free(card);
  1680. return err;
  1681. }
  1682. strcpy(card->driver, "Echo_" ECHOCARD_NAME);
  1683. strcpy(card->shortname, chip->card_name);
  1684. dsp = "56301";
  1685. if (pci_id->device == 0x3410)
  1686. dsp = "56361";
  1687. sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
  1688. card->shortname, pci_id->subdevice & 0x000f, dsp,
  1689. chip->dsp_registers_phys, chip->irq);
  1690. if ((err = snd_echo_new_pcm(chip)) < 0) {
  1691. dev_err(chip->card->dev, "new pcm error %d\n", err);
  1692. snd_card_free(card);
  1693. return err;
  1694. }
  1695. #ifdef ECHOCARD_HAS_MIDI
  1696. if (chip->has_midi) { /* Some Mia's do not have midi */
  1697. if ((err = snd_echo_midi_create(card, chip)) < 0) {
  1698. dev_err(chip->card->dev, "new midi error %d\n", err);
  1699. snd_card_free(card);
  1700. return err;
  1701. }
  1702. }
  1703. #endif
  1704. #ifdef ECHOCARD_HAS_VMIXER
  1705. snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
  1706. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
  1707. goto ctl_error;
  1708. #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
  1709. err = snd_ctl_add(chip->card,
  1710. snd_ctl_new1(&snd_echo_line_output_gain, chip));
  1711. if (err < 0)
  1712. goto ctl_error;
  1713. #endif
  1714. #else /* ECHOCARD_HAS_VMIXER */
  1715. err = snd_ctl_add(chip->card,
  1716. snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
  1717. if (err < 0)
  1718. goto ctl_error;
  1719. #endif /* ECHOCARD_HAS_VMIXER */
  1720. #ifdef ECHOCARD_HAS_INPUT_GAIN
  1721. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
  1722. goto ctl_error;
  1723. #endif
  1724. #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
  1725. if (!chip->hasnt_input_nominal_level)
  1726. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
  1727. goto ctl_error;
  1728. #endif
  1729. #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
  1730. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
  1731. goto ctl_error;
  1732. #endif
  1733. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
  1734. goto ctl_error;
  1735. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
  1736. goto ctl_error;
  1737. #ifdef ECHOCARD_HAS_MONITOR
  1738. snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
  1739. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
  1740. goto ctl_error;
  1741. #endif
  1742. #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
  1743. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
  1744. goto ctl_error;
  1745. #endif
  1746. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
  1747. goto ctl_error;
  1748. #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
  1749. /* Creates a list of available digital modes */
  1750. chip->num_digital_modes = 0;
  1751. for (i = 0; i < 6; i++)
  1752. if (chip->digital_modes & (1 << i))
  1753. chip->digital_mode_list[chip->num_digital_modes++] = i;
  1754. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
  1755. goto ctl_error;
  1756. #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
  1757. #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
  1758. /* Creates a list of available clock sources */
  1759. chip->num_clock_sources = 0;
  1760. for (i = 0; i < 10; i++)
  1761. if (chip->input_clock_types & (1 << i))
  1762. chip->clock_source_list[chip->num_clock_sources++] = i;
  1763. if (chip->num_clock_sources > 1) {
  1764. chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
  1765. if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
  1766. goto ctl_error;
  1767. }
  1768. #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
  1769. #ifdef ECHOCARD_HAS_DIGITAL_IO
  1770. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
  1771. goto ctl_error;
  1772. #endif
  1773. #ifdef ECHOCARD_HAS_PHANTOM_POWER
  1774. if (chip->has_phantom_power)
  1775. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
  1776. goto ctl_error;
  1777. #endif
  1778. err = snd_card_register(card);
  1779. if (err < 0)
  1780. goto ctl_error;
  1781. dev_info(card->dev, "Card registered: %s\n", card->longname);
  1782. pci_set_drvdata(pci, chip);
  1783. dev++;
  1784. return 0;
  1785. ctl_error:
  1786. dev_err(card->dev, "new control error %d\n", err);
  1787. snd_card_free(card);
  1788. return err;
  1789. }
  1790. #if defined(CONFIG_PM_SLEEP)
  1791. static int snd_echo_suspend(struct device *dev)
  1792. {
  1793. struct echoaudio *chip = dev_get_drvdata(dev);
  1794. snd_pcm_suspend_all(chip->analog_pcm);
  1795. snd_pcm_suspend_all(chip->digital_pcm);
  1796. #ifdef ECHOCARD_HAS_MIDI
  1797. /* This call can sleep */
  1798. if (chip->midi_out)
  1799. snd_echo_midi_output_trigger(chip->midi_out, 0);
  1800. #endif
  1801. spin_lock_irq(&chip->lock);
  1802. if (wait_handshake(chip)) {
  1803. spin_unlock_irq(&chip->lock);
  1804. return -EIO;
  1805. }
  1806. clear_handshake(chip);
  1807. if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
  1808. spin_unlock_irq(&chip->lock);
  1809. return -EIO;
  1810. }
  1811. spin_unlock_irq(&chip->lock);
  1812. chip->dsp_code = NULL;
  1813. free_irq(chip->irq, chip);
  1814. chip->irq = -1;
  1815. return 0;
  1816. }
  1817. static int snd_echo_resume(struct device *dev)
  1818. {
  1819. struct pci_dev *pci = to_pci_dev(dev);
  1820. struct echoaudio *chip = dev_get_drvdata(dev);
  1821. struct comm_page *commpage, *commpage_bak;
  1822. u32 pipe_alloc_mask;
  1823. int err;
  1824. commpage_bak = kmalloc(sizeof(*commpage), GFP_KERNEL);
  1825. if (commpage_bak == NULL)
  1826. return -ENOMEM;
  1827. commpage = chip->comm_page;
  1828. memcpy(commpage_bak, commpage, sizeof(*commpage));
  1829. err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
  1830. if (err < 0) {
  1831. kfree(commpage_bak);
  1832. dev_err(dev, "resume init_hw err=%d\n", err);
  1833. snd_echo_free(chip);
  1834. return err;
  1835. }
  1836. /* Temporarily set chip->pipe_alloc_mask=0 otherwise
  1837. * restore_dsp_settings() fails.
  1838. */
  1839. pipe_alloc_mask = chip->pipe_alloc_mask;
  1840. chip->pipe_alloc_mask = 0;
  1841. err = restore_dsp_rettings(chip);
  1842. chip->pipe_alloc_mask = pipe_alloc_mask;
  1843. if (err < 0) {
  1844. kfree(commpage_bak);
  1845. return err;
  1846. }
  1847. memcpy(&commpage->audio_format, &commpage_bak->audio_format,
  1848. sizeof(commpage->audio_format));
  1849. memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
  1850. sizeof(commpage->sglist_addr));
  1851. memcpy(&commpage->midi_output, &commpage_bak->midi_output,
  1852. sizeof(commpage->midi_output));
  1853. kfree(commpage_bak);
  1854. if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
  1855. KBUILD_MODNAME, chip)) {
  1856. dev_err(chip->card->dev, "cannot grab irq\n");
  1857. snd_echo_free(chip);
  1858. return -EBUSY;
  1859. }
  1860. chip->irq = pci->irq;
  1861. dev_dbg(dev, "resume irq=%d\n", chip->irq);
  1862. #ifdef ECHOCARD_HAS_MIDI
  1863. if (chip->midi_input_enabled)
  1864. enable_midi_input(chip, true);
  1865. if (chip->midi_out)
  1866. snd_echo_midi_output_trigger(chip->midi_out, 1);
  1867. #endif
  1868. return 0;
  1869. }
  1870. static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
  1871. #define SND_ECHO_PM_OPS &snd_echo_pm
  1872. #else
  1873. #define SND_ECHO_PM_OPS NULL
  1874. #endif /* CONFIG_PM_SLEEP */
  1875. static void snd_echo_remove(struct pci_dev *pci)
  1876. {
  1877. struct echoaudio *chip;
  1878. chip = pci_get_drvdata(pci);
  1879. if (chip)
  1880. snd_card_free(chip->card);
  1881. }
  1882. /******************************************************************************
  1883. Everything starts and ends here
  1884. ******************************************************************************/
  1885. /* pci_driver definition */
  1886. static struct pci_driver echo_driver = {
  1887. .name = KBUILD_MODNAME,
  1888. .id_table = snd_echo_ids,
  1889. .probe = snd_echo_probe,
  1890. .remove = snd_echo_remove,
  1891. .driver = {
  1892. .pm = SND_ECHO_PM_OPS,
  1893. },
  1894. };
  1895. module_pci_driver(echo_driver);