miro.c 40 KB

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