miro.c 36 KB

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