miro.c 36 KB

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