miro.c 40 KB

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