miro.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. /*
  2. * ALSA soundcard driver for Miro miroSOUND PCM1 pro
  3. * miroSOUND PCM12
  4. * miroSOUND PCM20 Radio
  5. *
  6. * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de>
  7. *
  8. * Based on OSS ACI and ALSA OPTi9xx drivers
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/init.h>
  25. #include <linux/err.h>
  26. #include <linux/isa.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/ioport.h>
  30. #include <linux/moduleparam.h>
  31. #include <asm/io.h>
  32. #include <asm/dma.h>
  33. #include <sound/core.h>
  34. #include <sound/wss.h>
  35. #include <sound/mpu401.h>
  36. #include <sound/opl4.h>
  37. #include <sound/control.h>
  38. #include <sound/info.h>
  39. #define SNDRV_LEGACY_FIND_FREE_IRQ
  40. #define SNDRV_LEGACY_FIND_FREE_DMA
  41. #include <sound/initval.h>
  42. #include "miro.h"
  43. MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>");
  44. MODULE_LICENSE("GPL");
  45. MODULE_DESCRIPTION("Miro miroSOUND PCM1 pro, PCM12, PCM20 Radio");
  46. MODULE_SUPPORTED_DEVICE("{{Miro,miroSOUND PCM1 pro}, "
  47. "{Miro,miroSOUND PCM12}, "
  48. "{Miro,miroSOUND PCM20 Radio}}");
  49. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  50. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  51. static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
  52. static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
  53. static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
  54. static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
  55. static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
  56. static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
  57. static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
  58. static int wss;
  59. static int ide;
  60. module_param(index, int, 0444);
  61. MODULE_PARM_DESC(index, "Index value for miro soundcard.");
  62. module_param(id, charp, 0444);
  63. MODULE_PARM_DESC(id, "ID string for miro soundcard.");
  64. module_param(port, long, 0444);
  65. MODULE_PARM_DESC(port, "WSS port # for miro driver.");
  66. module_param(mpu_port, long, 0444);
  67. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver.");
  68. module_param(fm_port, long, 0444);
  69. MODULE_PARM_DESC(fm_port, "FM Port # for miro driver.");
  70. module_param(irq, int, 0444);
  71. MODULE_PARM_DESC(irq, "WSS irq # for miro driver.");
  72. module_param(mpu_irq, int, 0444);
  73. MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver.");
  74. module_param(dma1, int, 0444);
  75. MODULE_PARM_DESC(dma1, "1st dma # for miro driver.");
  76. module_param(dma2, int, 0444);
  77. MODULE_PARM_DESC(dma2, "2nd dma # for miro driver.");
  78. module_param(wss, int, 0444);
  79. MODULE_PARM_DESC(wss, "wss mode");
  80. module_param(ide, int, 0444);
  81. MODULE_PARM_DESC(ide, "enable ide port");
  82. #define OPTi9XX_HW_DETECT 0
  83. #define OPTi9XX_HW_82C928 1
  84. #define OPTi9XX_HW_82C929 2
  85. #define OPTi9XX_HW_82C924 3
  86. #define OPTi9XX_HW_82C925 4
  87. #define OPTi9XX_HW_82C930 5
  88. #define OPTi9XX_HW_82C931 6
  89. #define OPTi9XX_HW_82C933 7
  90. #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
  91. #define OPTi9XX_MC_REG(n) n
  92. struct snd_miro {
  93. unsigned short hardware;
  94. unsigned char password;
  95. char name[7];
  96. struct resource *res_mc_base;
  97. struct resource *res_aci_port;
  98. unsigned long mc_base;
  99. unsigned long mc_base_size;
  100. unsigned long pwd_reg;
  101. spinlock_t lock;
  102. struct snd_pcm *pcm;
  103. long wss_base;
  104. int irq;
  105. int dma1;
  106. int dma2;
  107. long mpu_port;
  108. int mpu_irq;
  109. unsigned long aci_port;
  110. int aci_vendor;
  111. int aci_product;
  112. int aci_version;
  113. int aci_amp;
  114. int aci_preamp;
  115. int aci_solomode;
  116. struct mutex aci_mutex;
  117. };
  118. static char * snd_opti9xx_names[] = {
  119. "unkown",
  120. "82C928", "82C929",
  121. "82C924", "82C925",
  122. "82C930", "82C931", "82C933"
  123. };
  124. /*
  125. * ACI control
  126. */
  127. static int aci_busy_wait(struct snd_miro * miro)
  128. {
  129. long timeout;
  130. unsigned char byte;
  131. for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) {
  132. if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) {
  133. if (timeout >= ACI_MINTIME)
  134. snd_printd("aci ready in round %ld.\n",
  135. timeout-ACI_MINTIME);
  136. return byte;
  137. }
  138. if (timeout >= ACI_MINTIME) {
  139. long out=10*HZ;
  140. switch (timeout-ACI_MINTIME) {
  141. case 0 ... 9:
  142. out /= 10;
  143. case 10 ... 19:
  144. out /= 10;
  145. case 20 ... 30:
  146. out /= 10;
  147. default:
  148. set_current_state(TASK_UNINTERRUPTIBLE);
  149. schedule_timeout(out);
  150. break;
  151. }
  152. }
  153. }
  154. snd_printk(KERN_ERR "aci_busy_wait() time out\n");
  155. return -EBUSY;
  156. }
  157. static inline int aci_write(struct snd_miro * miro, unsigned char byte)
  158. {
  159. if (aci_busy_wait(miro) >= 0) {
  160. outb(byte, miro->aci_port + ACI_REG_COMMAND);
  161. return 0;
  162. } else {
  163. snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte);
  164. return -EBUSY;
  165. }
  166. }
  167. static inline int aci_read(struct snd_miro * miro)
  168. {
  169. unsigned char byte;
  170. if (aci_busy_wait(miro) >= 0) {
  171. byte=inb(miro->aci_port + ACI_REG_STATUS);
  172. return byte;
  173. } else {
  174. snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n");
  175. return -EBUSY;
  176. }
  177. }
  178. static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3)
  179. {
  180. int write[] = {write1, write2, write3};
  181. int value, i;
  182. if (mutex_lock_interruptible(&miro->aci_mutex))
  183. return -EINTR;
  184. for (i=0; i<3; i++) {
  185. if (write[i]< 0 || write[i] > 255)
  186. break;
  187. else {
  188. value = aci_write(miro, write[i]);
  189. if (value < 0)
  190. goto out;
  191. }
  192. }
  193. value = aci_read(miro);
  194. out: mutex_unlock(&miro->aci_mutex);
  195. return value;
  196. }
  197. static int aci_getvalue(struct snd_miro * miro, unsigned char index)
  198. {
  199. return aci_cmd(miro, ACI_STATUS, index, -1);
  200. }
  201. static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value)
  202. {
  203. return aci_cmd(miro, index, value, -1);
  204. }
  205. /*
  206. * MIXER part
  207. */
  208. #define snd_miro_info_capture snd_ctl_boolean_mono_info
  209. static int snd_miro_get_capture(struct snd_kcontrol *kcontrol,
  210. struct snd_ctl_elem_value *ucontrol)
  211. {
  212. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  213. int value;
  214. if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) {
  215. snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value);
  216. return value;
  217. }
  218. ucontrol->value.integer.value[0] = value & 0x20;
  219. return 0;
  220. }
  221. static int snd_miro_put_capture(struct snd_kcontrol *kcontrol,
  222. struct snd_ctl_elem_value *ucontrol)
  223. {
  224. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  225. int change, value, error;
  226. value = !(ucontrol->value.integer.value[0]);
  227. if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) {
  228. snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error);
  229. return error;
  230. }
  231. change = (value != miro->aci_solomode);
  232. miro->aci_solomode = value;
  233. return change;
  234. }
  235. static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol,
  236. struct snd_ctl_elem_info *uinfo)
  237. {
  238. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  239. uinfo->count = 1;
  240. uinfo->value.integer.min = 0;
  241. uinfo->value.integer.max = 3;
  242. return 0;
  243. }
  244. static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
  245. struct snd_ctl_elem_value *ucontrol)
  246. {
  247. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  248. int value;
  249. if (miro->aci_version <= 176) {
  250. /*
  251. OSS says it's not readable with versions < 176.
  252. But it doesn't work on my card,
  253. which is a PCM12 with aci_version = 176.
  254. */
  255. ucontrol->value.integer.value[0] = miro->aci_preamp;
  256. return 0;
  257. }
  258. if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) {
  259. snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value);
  260. return value;
  261. }
  262. ucontrol->value.integer.value[0] = value;
  263. return 0;
  264. }
  265. static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol,
  266. struct snd_ctl_elem_value *ucontrol)
  267. {
  268. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  269. int error, value, change;
  270. value = ucontrol->value.integer.value[0];
  271. if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) {
  272. snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error);
  273. return error;
  274. }
  275. change = (value != miro->aci_preamp);
  276. miro->aci_preamp = value;
  277. return change;
  278. }
  279. #define snd_miro_info_amp snd_ctl_boolean_mono_info
  280. static int snd_miro_get_amp(struct snd_kcontrol *kcontrol,
  281. struct snd_ctl_elem_value *ucontrol)
  282. {
  283. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  284. ucontrol->value.integer.value[0] = miro->aci_amp;
  285. return 0;
  286. }
  287. static int snd_miro_put_amp(struct snd_kcontrol *kcontrol,
  288. struct snd_ctl_elem_value *ucontrol)
  289. {
  290. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  291. int error, value, change;
  292. value = ucontrol->value.integer.value[0];
  293. if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) {
  294. snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error);
  295. return error;
  296. }
  297. change = (value != miro->aci_amp);
  298. miro->aci_amp = value;
  299. return change;
  300. }
  301. #define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \
  302. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  303. .name = ctl_name, \
  304. .index = ctl_index, \
  305. .info = snd_miro_info_double, \
  306. .get = snd_miro_get_double, \
  307. .put = snd_miro_put_double, \
  308. .private_value = get_right_reg | (set_right_reg << 8) \
  309. }
  310. static int snd_miro_info_double(struct snd_kcontrol *kcontrol,
  311. struct snd_ctl_elem_info *uinfo)
  312. {
  313. int reg = kcontrol->private_value & 0xff;
  314. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  315. uinfo->count = 2;
  316. if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) {
  317. /* equalizer elements */
  318. uinfo->value.integer.min = - 0x7f;
  319. uinfo->value.integer.max = 0x7f;
  320. } else {
  321. /* non-equalizer elements */
  322. uinfo->value.integer.min = 0;
  323. uinfo->value.integer.max = 0x20;
  324. }
  325. return 0;
  326. }
  327. static int snd_miro_get_double(struct snd_kcontrol *kcontrol,
  328. struct snd_ctl_elem_value *uinfo)
  329. {
  330. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  331. int left_val, right_val;
  332. int right_reg = kcontrol->private_value & 0xff;
  333. int left_reg = right_reg + 1;
  334. if ((right_val = aci_getvalue(miro, right_reg)) < 0) {
  335. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val);
  336. return right_val;
  337. }
  338. if ((left_val = aci_getvalue(miro, left_reg)) < 0) {
  339. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val);
  340. return left_val;
  341. }
  342. if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) {
  343. /* equalizer elements */
  344. if (left_val < 0x80) {
  345. uinfo->value.integer.value[0] = left_val;
  346. } else {
  347. uinfo->value.integer.value[0] = 0x80 - left_val;
  348. }
  349. if (right_val < 0x80) {
  350. uinfo->value.integer.value[1] = right_val;
  351. } else {
  352. uinfo->value.integer.value[1] = 0x80 - right_val;
  353. }
  354. } else {
  355. /* non-equalizer elements */
  356. uinfo->value.integer.value[0] = 0x20 - left_val;
  357. uinfo->value.integer.value[1] = 0x20 - right_val;
  358. }
  359. return 0;
  360. }
  361. static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
  362. struct snd_ctl_elem_value *ucontrol)
  363. {
  364. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  365. int left, right, left_old, right_old;
  366. int setreg_left, setreg_right, getreg_left, getreg_right;
  367. int change, error;
  368. left = ucontrol->value.integer.value[0];
  369. right = ucontrol->value.integer.value[1];
  370. setreg_right = (kcontrol->private_value >> 8) & 0xff;
  371. setreg_left = setreg_right + 8;
  372. if (setreg_right == ACI_SET_MASTER)
  373. setreg_left -= 7;
  374. getreg_right = kcontrol->private_value & 0xff;
  375. getreg_left = getreg_right + 1;
  376. if ((left_old = aci_getvalue(miro, getreg_left)) < 0) {
  377. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old);
  378. return left_old;
  379. }
  380. if ((right_old = aci_getvalue(miro, getreg_right)) < 0) {
  381. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old);
  382. return right_old;
  383. }
  384. if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) {
  385. /* equalizer elements */
  386. if (left < -0x7f || left > 0x7f ||
  387. right < -0x7f || right > 0x7f)
  388. return -EINVAL;
  389. if (left_old > 0x80)
  390. left_old = 0x80 - left_old;
  391. if (right_old > 0x80)
  392. right_old = 0x80 - right_old;
  393. if (left >= 0) {
  394. if ((error = aci_setvalue(miro, setreg_left, left)) < 0) {
  395. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  396. left, error);
  397. return error;
  398. }
  399. } else {
  400. if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) {
  401. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  402. 0x80 - left, error);
  403. return error;
  404. }
  405. }
  406. if (right >= 0) {
  407. if ((error = aci_setvalue(miro, setreg_right, right)) < 0) {
  408. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  409. right, error);
  410. return error;
  411. }
  412. } else {
  413. if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) {
  414. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  415. 0x80 - right, error);
  416. return error;
  417. }
  418. }
  419. } else {
  420. /* non-equalizer elements */
  421. if (left < 0 || left > 0x20 ||
  422. right < 0 || right > 0x20)
  423. return -EINVAL;
  424. left_old = 0x20 - left_old;
  425. right_old = 0x20 - right_old;
  426. if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) {
  427. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  428. 0x20 - left, error);
  429. return error;
  430. }
  431. if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) {
  432. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  433. 0x20 - right, error);
  434. return error;
  435. }
  436. }
  437. change = (left != left_old) || (right != right_old);
  438. return change;
  439. }
  440. static struct snd_kcontrol_new snd_miro_controls[] __devinitdata = {
  441. MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER),
  442. MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC),
  443. MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE),
  444. MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD),
  445. MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH),
  446. MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM),
  447. MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2),
  448. };
  449. /* Equalizer with seven bands (only PCM20)
  450. from -12dB up to +12dB on each band */
  451. static struct snd_kcontrol_new snd_miro_eq_controls[] __devinitdata = {
  452. MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1),
  453. MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2),
  454. MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3),
  455. MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4),
  456. MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5),
  457. MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6),
  458. MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7),
  459. };
  460. static struct snd_kcontrol_new snd_miro_radio_control[] __devinitdata = {
  461. MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1),
  462. };
  463. static struct snd_kcontrol_new snd_miro_line_control[] __devinitdata = {
  464. MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1),
  465. };
  466. static struct snd_kcontrol_new snd_miro_preamp_control[] __devinitdata = {
  467. {
  468. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  469. .name = "Mic Boost",
  470. .index = 1,
  471. .info = snd_miro_info_preamp,
  472. .get = snd_miro_get_preamp,
  473. .put = snd_miro_put_preamp,
  474. }};
  475. static struct snd_kcontrol_new snd_miro_amp_control[] __devinitdata = {
  476. {
  477. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  478. .name = "Line Boost",
  479. .index = 0,
  480. .info = snd_miro_info_amp,
  481. .get = snd_miro_get_amp,
  482. .put = snd_miro_put_amp,
  483. }};
  484. static struct snd_kcontrol_new snd_miro_capture_control[] __devinitdata = {
  485. {
  486. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  487. .name = "PCM Capture Switch",
  488. .index = 0,
  489. .info = snd_miro_info_capture,
  490. .get = snd_miro_get_capture,
  491. .put = snd_miro_put_capture,
  492. }};
  493. static unsigned char aci_init_values[][2] __devinitdata = {
  494. { ACI_SET_MUTE, 0x00 },
  495. { ACI_SET_POWERAMP, 0x00 },
  496. { ACI_SET_PREAMP, 0x00 },
  497. { ACI_SET_SOLOMODE, 0x00 },
  498. { ACI_SET_MIC + 0, 0x20 },
  499. { ACI_SET_MIC + 8, 0x20 },
  500. { ACI_SET_LINE + 0, 0x20 },
  501. { ACI_SET_LINE + 8, 0x20 },
  502. { ACI_SET_CD + 0, 0x20 },
  503. { ACI_SET_CD + 8, 0x20 },
  504. { ACI_SET_PCM + 0, 0x20 },
  505. { ACI_SET_PCM + 8, 0x20 },
  506. { ACI_SET_LINE1 + 0, 0x20 },
  507. { ACI_SET_LINE1 + 8, 0x20 },
  508. { ACI_SET_LINE2 + 0, 0x20 },
  509. { ACI_SET_LINE2 + 8, 0x20 },
  510. { ACI_SET_SYNTH + 0, 0x20 },
  511. { ACI_SET_SYNTH + 8, 0x20 },
  512. { ACI_SET_MASTER + 0, 0x20 },
  513. { ACI_SET_MASTER + 1, 0x20 },
  514. };
  515. static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
  516. {
  517. int idx, error;
  518. /* enable WSS on PCM1 */
  519. if ((miro->aci_product == 'A') && wss) {
  520. if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) {
  521. snd_printk(KERN_ERR "enabling WSS mode failed\n");
  522. return error;
  523. }
  524. }
  525. /* enable IDE port */
  526. if (ide) {
  527. if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) {
  528. snd_printk(KERN_ERR "enabling IDE port failed\n");
  529. return error;
  530. }
  531. }
  532. /* set common aci values */
  533. for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++)
  534. if ((error = aci_setvalue(miro, aci_init_values[idx][0],
  535. aci_init_values[idx][1])) < 0) {
  536. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  537. aci_init_values[idx][0], error);
  538. return error;
  539. }
  540. miro->aci_amp = 0;
  541. miro->aci_preamp = 0;
  542. miro->aci_solomode = 1;
  543. return 0;
  544. }
  545. static int __devinit snd_miro_mixer(struct snd_card *card,
  546. struct snd_miro *miro)
  547. {
  548. unsigned int idx;
  549. int err;
  550. if (snd_BUG_ON(!miro || !card))
  551. return -EINVAL;
  552. switch (miro->hardware) {
  553. case OPTi9XX_HW_82C924:
  554. strcpy(card->mixername, "ACI & OPTi924");
  555. break;
  556. case OPTi9XX_HW_82C929:
  557. strcpy(card->mixername, "ACI & OPTi929");
  558. break;
  559. default:
  560. snd_BUG();
  561. break;
  562. }
  563. for (idx = 0; idx < ARRAY_SIZE(snd_miro_controls); idx++) {
  564. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_controls[idx], miro))) < 0)
  565. return err;
  566. }
  567. if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) {
  568. /* PCM1/PCM12 with power-amp and Line 2 */
  569. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0)
  570. return err;
  571. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_amp_control[0], miro))) < 0)
  572. return err;
  573. }
  574. if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) {
  575. /* PCM12/PCM20 with mic-preamp */
  576. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0)
  577. return err;
  578. if (miro->aci_version >= 176)
  579. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0)
  580. return err;
  581. }
  582. if (miro->aci_product == 'C') {
  583. /* PCM20 with radio and 7 band equalizer */
  584. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0)
  585. return err;
  586. for (idx = 0; idx < ARRAY_SIZE(snd_miro_eq_controls); idx++) {
  587. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_eq_controls[idx], miro))) < 0)
  588. return err;
  589. }
  590. }
  591. return 0;
  592. }
  593. static long snd_legacy_find_free_ioport(long *port_table, long size)
  594. {
  595. while (*port_table != -1) {
  596. struct resource *res;
  597. if ((res = request_region(*port_table, size,
  598. "ALSA test")) != NULL) {
  599. release_and_free_resource(res);
  600. return *port_table;
  601. }
  602. port_table++;
  603. }
  604. return -1;
  605. }
  606. static int __devinit snd_miro_init(struct snd_miro *chip,
  607. unsigned short hardware)
  608. {
  609. static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
  610. chip->hardware = hardware;
  611. strcpy(chip->name, snd_opti9xx_names[hardware]);
  612. chip->mc_base_size = opti9xx_mc_size[hardware];
  613. spin_lock_init(&chip->lock);
  614. chip->wss_base = -1;
  615. chip->irq = -1;
  616. chip->dma1 = -1;
  617. chip->dma2 = -1;
  618. chip->mpu_port = -1;
  619. chip->mpu_irq = -1;
  620. switch (hardware) {
  621. case OPTi9XX_HW_82C929:
  622. chip->mc_base = 0xf8c;
  623. chip->password = 0xe3;
  624. chip->pwd_reg = 3;
  625. break;
  626. case OPTi9XX_HW_82C924:
  627. chip->mc_base = 0xf8c;
  628. chip->password = 0xe5;
  629. chip->pwd_reg = 3;
  630. break;
  631. default:
  632. snd_printk(KERN_ERR "sorry, no support for %d\n", hardware);
  633. return -ENODEV;
  634. }
  635. return 0;
  636. }
  637. static unsigned char snd_miro_read(struct snd_miro *chip,
  638. unsigned char reg)
  639. {
  640. unsigned long flags;
  641. unsigned char retval = 0xff;
  642. spin_lock_irqsave(&chip->lock, flags);
  643. outb(chip->password, chip->mc_base + chip->pwd_reg);
  644. switch (chip->hardware) {
  645. case OPTi9XX_HW_82C924:
  646. if (reg > 7) {
  647. outb(reg, chip->mc_base + 8);
  648. outb(chip->password, chip->mc_base + chip->pwd_reg);
  649. retval = inb(chip->mc_base + 9);
  650. break;
  651. }
  652. case OPTi9XX_HW_82C929:
  653. retval = inb(chip->mc_base + reg);
  654. break;
  655. default:
  656. snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
  657. }
  658. spin_unlock_irqrestore(&chip->lock, flags);
  659. return retval;
  660. }
  661. static void snd_miro_write(struct snd_miro *chip, unsigned char reg,
  662. unsigned char value)
  663. {
  664. unsigned long flags;
  665. spin_lock_irqsave(&chip->lock, flags);
  666. outb(chip->password, chip->mc_base + chip->pwd_reg);
  667. switch (chip->hardware) {
  668. case OPTi9XX_HW_82C924:
  669. if (reg > 7) {
  670. outb(reg, chip->mc_base + 8);
  671. outb(chip->password, chip->mc_base + chip->pwd_reg);
  672. outb(value, chip->mc_base + 9);
  673. break;
  674. }
  675. case OPTi9XX_HW_82C929:
  676. outb(value, chip->mc_base + reg);
  677. break;
  678. default:
  679. snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
  680. }
  681. spin_unlock_irqrestore(&chip->lock, flags);
  682. }
  683. #define snd_miro_write_mask(chip, reg, value, mask) \
  684. snd_miro_write(chip, reg, \
  685. (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
  686. /*
  687. * Proc Interface
  688. */
  689. static void snd_miro_proc_read(struct snd_info_entry * entry,
  690. struct snd_info_buffer *buffer)
  691. {
  692. struct snd_miro *miro = (struct snd_miro *) entry->private_data;
  693. char* model = "unknown";
  694. /* miroSOUND PCM1 pro, early PCM12 */
  695. if ((miro->hardware == OPTi9XX_HW_82C929) &&
  696. (miro->aci_vendor == 'm') &&
  697. (miro->aci_product == 'A')) {
  698. switch(miro->aci_version) {
  699. case 3:
  700. model = "miroSOUND PCM1 pro";
  701. break;
  702. default:
  703. model = "miroSOUND PCM1 pro / (early) PCM12";
  704. break;
  705. }
  706. }
  707. /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
  708. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  709. (miro->aci_vendor == 'm') &&
  710. (miro->aci_product == 'B')) {
  711. switch(miro->aci_version) {
  712. case 4:
  713. model = "miroSOUND PCM12";
  714. break;
  715. case 176:
  716. model = "miroSOUND PCM12 (Rev. E)";
  717. break;
  718. default:
  719. model = "miroSOUND PCM12 / PCM12 pnp";
  720. break;
  721. }
  722. }
  723. /* miroSOUND PCM20 radio */
  724. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  725. (miro->aci_vendor == 'm') &&
  726. (miro->aci_product == 'C')) {
  727. switch(miro->aci_version) {
  728. case 7:
  729. model = "miroSOUND PCM20 radio (Rev. E)";
  730. break;
  731. default:
  732. model = "miroSOUND PCM20 radio";
  733. break;
  734. }
  735. }
  736. snd_iprintf(buffer, "\nGeneral information:\n");
  737. snd_iprintf(buffer, " model : %s\n", model);
  738. snd_iprintf(buffer, " opti : %s\n", miro->name);
  739. snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
  740. snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
  741. snd_iprintf(buffer, " irq : %d\n", miro->irq);
  742. snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
  743. snd_iprintf(buffer, "MPU-401:\n");
  744. snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
  745. snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
  746. snd_iprintf(buffer, "ACI information:\n");
  747. snd_iprintf(buffer, " vendor : ");
  748. switch(miro->aci_vendor) {
  749. case 'm':
  750. snd_iprintf(buffer, "Miro\n");
  751. break;
  752. default:
  753. snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor);
  754. break;
  755. }
  756. snd_iprintf(buffer, " product : ");
  757. switch(miro->aci_product) {
  758. case 'A':
  759. snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
  760. break;
  761. case 'B':
  762. snd_iprintf(buffer, "miroSOUND PCM12\n");
  763. break;
  764. case 'C':
  765. snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
  766. break;
  767. default:
  768. snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product);
  769. break;
  770. }
  771. snd_iprintf(buffer, " firmware: %d (0x%x)\n",
  772. miro->aci_version, miro->aci_version);
  773. snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
  774. miro->aci_port, miro->aci_port+2);
  775. snd_iprintf(buffer, " wss : 0x%x\n", wss);
  776. snd_iprintf(buffer, " ide : 0x%x\n", ide);
  777. snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode);
  778. snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp);
  779. snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp);
  780. }
  781. static void __devinit snd_miro_proc_init(struct snd_card *card,
  782. struct snd_miro *miro)
  783. {
  784. struct snd_info_entry *entry;
  785. if (!snd_card_proc_new(card, "miro", &entry))
  786. snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
  787. }
  788. /*
  789. * Init
  790. */
  791. static int __devinit snd_miro_configure(struct snd_miro *chip)
  792. {
  793. unsigned char wss_base_bits;
  794. unsigned char irq_bits;
  795. unsigned char dma_bits;
  796. unsigned char mpu_port_bits = 0;
  797. unsigned char mpu_irq_bits;
  798. unsigned long flags;
  799. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  800. snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
  801. snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  802. switch (chip->hardware) {
  803. case OPTi9XX_HW_82C924:
  804. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
  805. snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
  806. break;
  807. case OPTi9XX_HW_82C929:
  808. /* untested init commands for OPTi929 */
  809. snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
  810. break;
  811. default:
  812. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  813. return -EINVAL;
  814. }
  815. switch (chip->wss_base) {
  816. case 0x530:
  817. wss_base_bits = 0x00;
  818. break;
  819. case 0x604:
  820. wss_base_bits = 0x03;
  821. break;
  822. case 0xe80:
  823. wss_base_bits = 0x01;
  824. break;
  825. case 0xf40:
  826. wss_base_bits = 0x02;
  827. break;
  828. default:
  829. snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
  830. goto __skip_base;
  831. }
  832. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
  833. __skip_base:
  834. switch (chip->irq) {
  835. case 5:
  836. irq_bits = 0x05;
  837. break;
  838. case 7:
  839. irq_bits = 0x01;
  840. break;
  841. case 9:
  842. irq_bits = 0x02;
  843. break;
  844. case 10:
  845. irq_bits = 0x03;
  846. break;
  847. case 11:
  848. irq_bits = 0x04;
  849. break;
  850. default:
  851. snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
  852. goto __skip_resources;
  853. }
  854. switch (chip->dma1) {
  855. case 0:
  856. dma_bits = 0x01;
  857. break;
  858. case 1:
  859. dma_bits = 0x02;
  860. break;
  861. case 3:
  862. dma_bits = 0x03;
  863. break;
  864. default:
  865. snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
  866. goto __skip_resources;
  867. }
  868. if (chip->dma1 == chip->dma2) {
  869. snd_printk(KERN_ERR "don't want to share dmas\n");
  870. return -EBUSY;
  871. }
  872. switch (chip->dma2) {
  873. case 0:
  874. case 1:
  875. break;
  876. default:
  877. snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
  878. goto __skip_resources;
  879. }
  880. dma_bits |= 0x04;
  881. spin_lock_irqsave(&chip->lock, flags);
  882. outb(irq_bits << 3 | dma_bits, chip->wss_base);
  883. spin_unlock_irqrestore(&chip->lock, flags);
  884. __skip_resources:
  885. if (chip->hardware > OPTi9XX_HW_82C928) {
  886. switch (chip->mpu_port) {
  887. case 0:
  888. case -1:
  889. break;
  890. case 0x300:
  891. mpu_port_bits = 0x03;
  892. break;
  893. case 0x310:
  894. mpu_port_bits = 0x02;
  895. break;
  896. case 0x320:
  897. mpu_port_bits = 0x01;
  898. break;
  899. case 0x330:
  900. mpu_port_bits = 0x00;
  901. break;
  902. default:
  903. snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
  904. chip->mpu_port);
  905. goto __skip_mpu;
  906. }
  907. switch (chip->mpu_irq) {
  908. case 5:
  909. mpu_irq_bits = 0x02;
  910. break;
  911. case 7:
  912. mpu_irq_bits = 0x03;
  913. break;
  914. case 9:
  915. mpu_irq_bits = 0x00;
  916. break;
  917. case 10:
  918. mpu_irq_bits = 0x01;
  919. break;
  920. default:
  921. snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
  922. chip->mpu_irq);
  923. goto __skip_mpu;
  924. }
  925. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
  926. (chip->mpu_port <= 0) ? 0x00 :
  927. 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
  928. 0xf8);
  929. }
  930. __skip_mpu:
  931. return 0;
  932. }
  933. static int __devinit snd_card_miro_detect(struct snd_card *card,
  934. struct snd_miro *chip)
  935. {
  936. int i, err;
  937. unsigned char value;
  938. for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
  939. if ((err = snd_miro_init(chip, i)) < 0)
  940. return err;
  941. if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
  942. continue;
  943. value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
  944. if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
  945. if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
  946. return 1;
  947. release_and_free_resource(chip->res_mc_base);
  948. chip->res_mc_base = NULL;
  949. }
  950. return -ENODEV;
  951. }
  952. static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
  953. struct snd_miro * miro)
  954. {
  955. unsigned char regval;
  956. int i;
  957. mutex_init(&miro->aci_mutex);
  958. /* get ACI port from OPTi9xx MC 4 */
  959. regval=inb(miro->mc_base + 4);
  960. miro->aci_port = (regval & 0x10) ? 0x344: 0x354;
  961. if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) {
  962. snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
  963. miro->aci_port, miro->aci_port+2);
  964. return -ENOMEM;
  965. }
  966. /* force ACI into a known state */
  967. for (i = 0; i < 3; i++)
  968. if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) {
  969. snd_printk(KERN_ERR "can't force aci into known state.\n");
  970. return -ENXIO;
  971. }
  972. if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 ||
  973. (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) {
  974. snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port);
  975. return -ENXIO;
  976. }
  977. if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) {
  978. snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
  979. miro->aci_port);
  980. return -ENXIO;
  981. }
  982. if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 ||
  983. aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
  984. aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
  985. snd_printk(KERN_ERR "can't initialize aci.\n");
  986. return -ENXIO;
  987. }
  988. return 0;
  989. }
  990. static void snd_card_miro_free(struct snd_card *card)
  991. {
  992. struct snd_miro *miro = card->private_data;
  993. release_and_free_resource(miro->res_aci_port);
  994. release_and_free_resource(miro->res_mc_base);
  995. }
  996. static int __devinit snd_miro_match(struct device *devptr, unsigned int n)
  997. {
  998. return 1;
  999. }
  1000. static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
  1001. {
  1002. static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
  1003. static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
  1004. static int possible_irqs[] = {11, 9, 10, 7, -1};
  1005. static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
  1006. static int possible_dma1s[] = {3, 1, 0, -1};
  1007. static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
  1008. int error;
  1009. struct snd_miro *miro;
  1010. struct snd_wss *codec;
  1011. struct snd_timer *timer;
  1012. struct snd_card *card;
  1013. struct snd_pcm *pcm;
  1014. struct snd_rawmidi *rmidi;
  1015. error = snd_card_create(index, id, THIS_MODULE,
  1016. sizeof(struct snd_miro), &card);
  1017. if (error < 0)
  1018. return error;
  1019. card->private_free = snd_card_miro_free;
  1020. miro = card->private_data;
  1021. error = snd_card_miro_detect(card, miro);
  1022. if (error < 0) {
  1023. snd_card_free(card);
  1024. snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
  1025. return -ENODEV;
  1026. }
  1027. if ((error = snd_card_miro_aci_detect(card, miro)) < 0) {
  1028. snd_card_free(card);
  1029. snd_printk(KERN_ERR "unable to detect aci chip\n");
  1030. return -ENODEV;
  1031. }
  1032. /* init proc interface */
  1033. snd_miro_proc_init(card, miro);
  1034. if (! miro->res_mc_base &&
  1035. (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size,
  1036. "miro (OPTi9xx MC)")) == NULL) {
  1037. snd_card_free(card);
  1038. snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
  1039. return -ENOMEM;
  1040. }
  1041. miro->wss_base = port;
  1042. miro->mpu_port = mpu_port;
  1043. miro->irq = irq;
  1044. miro->mpu_irq = mpu_irq;
  1045. miro->dma1 = dma1;
  1046. miro->dma2 = dma2;
  1047. if (miro->wss_base == SNDRV_AUTO_PORT) {
  1048. if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
  1049. snd_card_free(card);
  1050. snd_printk(KERN_ERR "unable to find a free WSS port\n");
  1051. return -EBUSY;
  1052. }
  1053. }
  1054. if (mpu_port == SNDRV_AUTO_PORT) {
  1055. mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
  1056. if (mpu_port < 0) {
  1057. snd_card_free(card);
  1058. snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
  1059. return -EBUSY;
  1060. }
  1061. }
  1062. if (miro->irq == SNDRV_AUTO_IRQ) {
  1063. if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
  1064. snd_card_free(card);
  1065. snd_printk(KERN_ERR "unable to find a free IRQ\n");
  1066. return -EBUSY;
  1067. }
  1068. }
  1069. if (miro->mpu_irq == SNDRV_AUTO_IRQ) {
  1070. if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
  1071. snd_card_free(card);
  1072. snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
  1073. return -EBUSY;
  1074. }
  1075. }
  1076. if (miro->dma1 == SNDRV_AUTO_DMA) {
  1077. if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
  1078. snd_card_free(card);
  1079. snd_printk(KERN_ERR "unable to find a free DMA1\n");
  1080. return -EBUSY;
  1081. }
  1082. }
  1083. if (miro->dma2 == SNDRV_AUTO_DMA) {
  1084. if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) {
  1085. snd_card_free(card);
  1086. snd_printk(KERN_ERR "unable to find a free DMA2\n");
  1087. return -EBUSY;
  1088. }
  1089. }
  1090. error = snd_miro_configure(miro);
  1091. if (error) {
  1092. snd_card_free(card);
  1093. return error;
  1094. }
  1095. error = snd_wss_create(card, miro->wss_base + 4, -1,
  1096. miro->irq, miro->dma1, miro->dma2,
  1097. WSS_HW_AD1845, 0, &codec);
  1098. if (error < 0) {
  1099. snd_card_free(card);
  1100. return error;
  1101. }
  1102. error = snd_wss_pcm(codec, 0, &pcm);
  1103. if (error < 0) {
  1104. snd_card_free(card);
  1105. return error;
  1106. }
  1107. error = snd_wss_mixer(codec);
  1108. if (error < 0) {
  1109. snd_card_free(card);
  1110. return error;
  1111. }
  1112. error = snd_wss_timer(codec, 0, &timer);
  1113. if (error < 0) {
  1114. snd_card_free(card);
  1115. return error;
  1116. }
  1117. miro->pcm = pcm;
  1118. error = snd_miro_mixer(card, miro);
  1119. if (error < 0) {
  1120. snd_card_free(card);
  1121. return error;
  1122. }
  1123. if (miro->aci_vendor == 'm') {
  1124. /* It looks like a miro sound card. */
  1125. switch (miro->aci_product) {
  1126. case 'A':
  1127. sprintf(card->shortname,
  1128. "miroSOUND PCM1 pro / PCM12");
  1129. break;
  1130. case 'B':
  1131. sprintf(card->shortname,
  1132. "miroSOUND PCM12");
  1133. break;
  1134. case 'C':
  1135. sprintf(card->shortname,
  1136. "miroSOUND PCM20 radio");
  1137. break;
  1138. default:
  1139. sprintf(card->shortname,
  1140. "unknown miro");
  1141. snd_printk(KERN_INFO "unknown miro aci id\n");
  1142. break;
  1143. }
  1144. } else {
  1145. snd_printk(KERN_INFO "found unsupported aci card\n");
  1146. sprintf(card->shortname, "unknown Cardinal Technologies");
  1147. }
  1148. strcpy(card->driver, "miro");
  1149. sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
  1150. card->shortname, miro->name, pcm->name, miro->wss_base + 4,
  1151. miro->irq, miro->dma1, miro->dma2);
  1152. if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
  1153. rmidi = NULL;
  1154. else {
  1155. error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  1156. mpu_port, 0, miro->mpu_irq, IRQF_DISABLED,
  1157. &rmidi);
  1158. if (error < 0)
  1159. snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
  1160. mpu_port);
  1161. }
  1162. if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
  1163. struct snd_opl3 *opl3 = NULL;
  1164. struct snd_opl4 *opl4;
  1165. if (snd_opl4_create(card, fm_port, fm_port - 8,
  1166. 2, &opl3, &opl4) < 0)
  1167. snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n",
  1168. fm_port);
  1169. }
  1170. if ((error = snd_set_aci_init_values(miro)) < 0) {
  1171. snd_card_free(card);
  1172. return error;
  1173. }
  1174. snd_card_set_dev(card, devptr);
  1175. if ((error = snd_card_register(card))) {
  1176. snd_card_free(card);
  1177. return error;
  1178. }
  1179. dev_set_drvdata(devptr, card);
  1180. return 0;
  1181. }
  1182. static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev)
  1183. {
  1184. snd_card_free(dev_get_drvdata(devptr));
  1185. dev_set_drvdata(devptr, NULL);
  1186. return 0;
  1187. }
  1188. #define DEV_NAME "miro"
  1189. static struct isa_driver snd_miro_driver = {
  1190. .match = snd_miro_match,
  1191. .probe = snd_miro_probe,
  1192. .remove = __devexit_p(snd_miro_remove),
  1193. /* FIXME: suspend/resume */
  1194. .driver = {
  1195. .name = DEV_NAME
  1196. },
  1197. };
  1198. static int __init alsa_card_miro_init(void)
  1199. {
  1200. return isa_register_driver(&snd_miro_driver, 1);
  1201. }
  1202. static void __exit alsa_card_miro_exit(void)
  1203. {
  1204. isa_unregister_driver(&snd_miro_driver);
  1205. }
  1206. module_init(alsa_card_miro_init)
  1207. module_exit(alsa_card_miro_exit)