miro.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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. #define snd_miro_write_mask(chip, reg, value, mask) \
  729. snd_miro_write(chip, reg, \
  730. (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
  731. /*
  732. * Proc Interface
  733. */
  734. static void snd_miro_proc_read(struct snd_info_entry * entry,
  735. struct snd_info_buffer *buffer)
  736. {
  737. struct snd_miro *miro = (struct snd_miro *) entry->private_data;
  738. struct snd_miro_aci *aci = miro->aci;
  739. char* model = "unknown";
  740. /* miroSOUND PCM1 pro, early PCM12 */
  741. if ((miro->hardware == OPTi9XX_HW_82C929) &&
  742. (aci->aci_vendor == 'm') &&
  743. (aci->aci_product == 'A')) {
  744. switch (aci->aci_version) {
  745. case 3:
  746. model = "miroSOUND PCM1 pro";
  747. break;
  748. default:
  749. model = "miroSOUND PCM1 pro / (early) PCM12";
  750. break;
  751. }
  752. }
  753. /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
  754. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  755. (aci->aci_vendor == 'm') &&
  756. (aci->aci_product == 'B')) {
  757. switch (aci->aci_version) {
  758. case 4:
  759. model = "miroSOUND PCM12";
  760. break;
  761. case 176:
  762. model = "miroSOUND PCM12 (Rev. E)";
  763. break;
  764. default:
  765. model = "miroSOUND PCM12 / PCM12 pnp";
  766. break;
  767. }
  768. }
  769. /* miroSOUND PCM20 radio */
  770. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  771. (aci->aci_vendor == 'm') &&
  772. (aci->aci_product == 'C')) {
  773. switch (aci->aci_version) {
  774. case 7:
  775. model = "miroSOUND PCM20 radio (Rev. E)";
  776. break;
  777. default:
  778. model = "miroSOUND PCM20 radio";
  779. break;
  780. }
  781. }
  782. snd_iprintf(buffer, "\nGeneral information:\n");
  783. snd_iprintf(buffer, " model : %s\n", model);
  784. snd_iprintf(buffer, " opti : %s\n", miro->name);
  785. snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
  786. snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
  787. snd_iprintf(buffer, " irq : %d\n", miro->irq);
  788. snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
  789. snd_iprintf(buffer, "MPU-401:\n");
  790. snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
  791. snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
  792. snd_iprintf(buffer, "ACI information:\n");
  793. snd_iprintf(buffer, " vendor : ");
  794. switch (aci->aci_vendor) {
  795. case 'm':
  796. snd_iprintf(buffer, "Miro\n");
  797. break;
  798. default:
  799. snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_vendor);
  800. break;
  801. }
  802. snd_iprintf(buffer, " product : ");
  803. switch (aci->aci_product) {
  804. case 'A':
  805. snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
  806. break;
  807. case 'B':
  808. snd_iprintf(buffer, "miroSOUND PCM12\n");
  809. break;
  810. case 'C':
  811. snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
  812. break;
  813. default:
  814. snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_product);
  815. break;
  816. }
  817. snd_iprintf(buffer, " firmware: %d (0x%x)\n",
  818. aci->aci_version, aci->aci_version);
  819. snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
  820. aci->aci_port, aci->aci_port+2);
  821. snd_iprintf(buffer, " wss : 0x%x\n", wss);
  822. snd_iprintf(buffer, " ide : 0x%x\n", ide);
  823. snd_iprintf(buffer, " solomode: 0x%x\n", aci->aci_solomode);
  824. snd_iprintf(buffer, " amp : 0x%x\n", aci->aci_amp);
  825. snd_iprintf(buffer, " preamp : 0x%x\n", aci->aci_preamp);
  826. }
  827. static void snd_miro_proc_init(struct snd_card *card,
  828. struct snd_miro *miro)
  829. {
  830. struct snd_info_entry *entry;
  831. if (!snd_card_proc_new(card, "miro", &entry))
  832. snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
  833. }
  834. /*
  835. * Init
  836. */
  837. static int snd_miro_configure(struct snd_miro *chip)
  838. {
  839. unsigned char wss_base_bits;
  840. unsigned char irq_bits;
  841. unsigned char dma_bits;
  842. unsigned char mpu_port_bits = 0;
  843. unsigned char mpu_irq_bits;
  844. unsigned long flags;
  845. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  846. snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
  847. snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  848. switch (chip->hardware) {
  849. case OPTi9XX_HW_82C924:
  850. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
  851. snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
  852. break;
  853. case OPTi9XX_HW_82C929:
  854. /* untested init commands for OPTi929 */
  855. snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
  856. break;
  857. default:
  858. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  859. return -EINVAL;
  860. }
  861. /* PnP resource says it decodes only 10 bits of address */
  862. switch (chip->wss_base & 0x3ff) {
  863. case 0x130:
  864. chip->wss_base = 0x530;
  865. wss_base_bits = 0x00;
  866. break;
  867. case 0x204:
  868. chip->wss_base = 0x604;
  869. wss_base_bits = 0x03;
  870. break;
  871. case 0x280:
  872. chip->wss_base = 0xe80;
  873. wss_base_bits = 0x01;
  874. break;
  875. case 0x340:
  876. chip->wss_base = 0xf40;
  877. wss_base_bits = 0x02;
  878. break;
  879. default:
  880. snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
  881. goto __skip_base;
  882. }
  883. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
  884. __skip_base:
  885. switch (chip->irq) {
  886. case 5:
  887. irq_bits = 0x05;
  888. break;
  889. case 7:
  890. irq_bits = 0x01;
  891. break;
  892. case 9:
  893. irq_bits = 0x02;
  894. break;
  895. case 10:
  896. irq_bits = 0x03;
  897. break;
  898. case 11:
  899. irq_bits = 0x04;
  900. break;
  901. default:
  902. snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
  903. goto __skip_resources;
  904. }
  905. switch (chip->dma1) {
  906. case 0:
  907. dma_bits = 0x01;
  908. break;
  909. case 1:
  910. dma_bits = 0x02;
  911. break;
  912. case 3:
  913. dma_bits = 0x03;
  914. break;
  915. default:
  916. snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
  917. goto __skip_resources;
  918. }
  919. if (chip->dma1 == chip->dma2) {
  920. snd_printk(KERN_ERR "don't want to share dmas\n");
  921. return -EBUSY;
  922. }
  923. switch (chip->dma2) {
  924. case 0:
  925. case 1:
  926. break;
  927. default:
  928. snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
  929. goto __skip_resources;
  930. }
  931. dma_bits |= 0x04;
  932. spin_lock_irqsave(&chip->lock, flags);
  933. outb(irq_bits << 3 | dma_bits, chip->wss_base);
  934. spin_unlock_irqrestore(&chip->lock, flags);
  935. __skip_resources:
  936. if (chip->hardware > OPTi9XX_HW_82C928) {
  937. switch (chip->mpu_port) {
  938. case 0:
  939. case -1:
  940. break;
  941. case 0x300:
  942. mpu_port_bits = 0x03;
  943. break;
  944. case 0x310:
  945. mpu_port_bits = 0x02;
  946. break;
  947. case 0x320:
  948. mpu_port_bits = 0x01;
  949. break;
  950. case 0x330:
  951. mpu_port_bits = 0x00;
  952. break;
  953. default:
  954. snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
  955. chip->mpu_port);
  956. goto __skip_mpu;
  957. }
  958. switch (chip->mpu_irq) {
  959. case 5:
  960. mpu_irq_bits = 0x02;
  961. break;
  962. case 7:
  963. mpu_irq_bits = 0x03;
  964. break;
  965. case 9:
  966. mpu_irq_bits = 0x00;
  967. break;
  968. case 10:
  969. mpu_irq_bits = 0x01;
  970. break;
  971. default:
  972. snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
  973. chip->mpu_irq);
  974. goto __skip_mpu;
  975. }
  976. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
  977. (chip->mpu_port <= 0) ? 0x00 :
  978. 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
  979. 0xf8);
  980. }
  981. __skip_mpu:
  982. return 0;
  983. }
  984. static int snd_miro_opti_check(struct snd_miro *chip)
  985. {
  986. unsigned char value;
  987. chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
  988. "OPTi9xx MC");
  989. if (chip->res_mc_base == NULL)
  990. return -ENOMEM;
  991. value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
  992. if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
  993. if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
  994. return 0;
  995. release_and_free_resource(chip->res_mc_base);
  996. chip->res_mc_base = NULL;
  997. return -ENODEV;
  998. }
  999. static int snd_card_miro_detect(struct snd_card *card,
  1000. struct snd_miro *chip)
  1001. {
  1002. int i, err;
  1003. for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
  1004. if ((err = snd_miro_init(chip, i)) < 0)
  1005. return err;
  1006. err = snd_miro_opti_check(chip);
  1007. if (err == 0)
  1008. return 1;
  1009. }
  1010. return -ENODEV;
  1011. }
  1012. static int snd_card_miro_aci_detect(struct snd_card *card,
  1013. struct snd_miro *miro)
  1014. {
  1015. unsigned char regval;
  1016. int i;
  1017. struct snd_miro_aci *aci = &aci_device;
  1018. miro->aci = aci;
  1019. mutex_init(&aci->aci_mutex);
  1020. /* get ACI port from OPTi9xx MC 4 */
  1021. regval=inb(miro->mc_base + 4);
  1022. aci->aci_port = (regval & 0x10) ? 0x344 : 0x354;
  1023. miro->res_aci_port = request_region(aci->aci_port, 3, "miro aci");
  1024. if (miro->res_aci_port == NULL) {
  1025. snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
  1026. aci->aci_port, aci->aci_port+2);
  1027. return -ENOMEM;
  1028. }
  1029. /* force ACI into a known state */
  1030. for (i = 0; i < 3; i++)
  1031. if (snd_aci_cmd(aci, ACI_ERROR_OP, -1, -1) < 0) {
  1032. snd_printk(KERN_ERR "can't force aci into known state.\n");
  1033. return -ENXIO;
  1034. }
  1035. aci->aci_vendor = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
  1036. aci->aci_product = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
  1037. if (aci->aci_vendor < 0 || aci->aci_product < 0) {
  1038. snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n",
  1039. aci->aci_port);
  1040. return -ENXIO;
  1041. }
  1042. aci->aci_version = snd_aci_cmd(aci, ACI_READ_VERSION, -1, -1);
  1043. if (aci->aci_version < 0) {
  1044. snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
  1045. aci->aci_port);
  1046. return -ENXIO;
  1047. }
  1048. if (snd_aci_cmd(aci, ACI_INIT, -1, -1) < 0 ||
  1049. snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
  1050. snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
  1051. snd_printk(KERN_ERR "can't initialize aci.\n");
  1052. return -ENXIO;
  1053. }
  1054. return 0;
  1055. }
  1056. static void snd_card_miro_free(struct snd_card *card)
  1057. {
  1058. struct snd_miro *miro = card->private_data;
  1059. release_and_free_resource(miro->res_aci_port);
  1060. if (miro->aci)
  1061. miro->aci->aci_port = 0;
  1062. release_and_free_resource(miro->res_mc_base);
  1063. }
  1064. static int snd_miro_probe(struct snd_card *card)
  1065. {
  1066. int error;
  1067. struct snd_miro *miro = card->private_data;
  1068. struct snd_wss *codec;
  1069. struct snd_rawmidi *rmidi;
  1070. if (!miro->res_mc_base) {
  1071. miro->res_mc_base = request_region(miro->mc_base,
  1072. miro->mc_base_size,
  1073. "miro (OPTi9xx MC)");
  1074. if (miro->res_mc_base == NULL) {
  1075. snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
  1076. return -ENOMEM;
  1077. }
  1078. }
  1079. error = snd_card_miro_aci_detect(card, miro);
  1080. if (error < 0) {
  1081. snd_printk(KERN_ERR "unable to detect aci chip\n");
  1082. return -ENODEV;
  1083. }
  1084. miro->wss_base = port;
  1085. miro->mpu_port = mpu_port;
  1086. miro->irq = irq;
  1087. miro->mpu_irq = mpu_irq;
  1088. miro->dma1 = dma1;
  1089. miro->dma2 = dma2;
  1090. /* init proc interface */
  1091. snd_miro_proc_init(card, miro);
  1092. error = snd_miro_configure(miro);
  1093. if (error)
  1094. return error;
  1095. error = snd_wss_create(card, miro->wss_base + 4, -1,
  1096. miro->irq, miro->dma1, miro->dma2,
  1097. WSS_HW_DETECT, 0, &codec);
  1098. if (error < 0)
  1099. return error;
  1100. error = snd_wss_pcm(codec, 0);
  1101. if (error < 0)
  1102. return error;
  1103. error = snd_wss_mixer(codec);
  1104. if (error < 0)
  1105. return error;
  1106. error = snd_wss_timer(codec, 0);
  1107. if (error < 0)
  1108. return error;
  1109. miro->pcm = codec->pcm;
  1110. error = snd_miro_mixer(card, miro);
  1111. if (error < 0)
  1112. return error;
  1113. if (miro->aci->aci_vendor == 'm') {
  1114. /* It looks like a miro sound card. */
  1115. switch (miro->aci->aci_product) {
  1116. case 'A':
  1117. sprintf(card->shortname,
  1118. "miroSOUND PCM1 pro / PCM12");
  1119. break;
  1120. case 'B':
  1121. sprintf(card->shortname,
  1122. "miroSOUND PCM12");
  1123. break;
  1124. case 'C':
  1125. sprintf(card->shortname,
  1126. "miroSOUND PCM20 radio");
  1127. break;
  1128. default:
  1129. sprintf(card->shortname,
  1130. "unknown miro");
  1131. snd_printk(KERN_INFO "unknown miro aci id\n");
  1132. break;
  1133. }
  1134. } else {
  1135. snd_printk(KERN_INFO "found unsupported aci card\n");
  1136. sprintf(card->shortname, "unknown Cardinal Technologies");
  1137. }
  1138. strcpy(card->driver, "miro");
  1139. snprintf(card->longname, sizeof(card->longname),
  1140. "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
  1141. card->shortname, miro->name, codec->pcm->name,
  1142. miro->wss_base + 4, miro->irq, miro->dma1, miro->dma2);
  1143. if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
  1144. rmidi = NULL;
  1145. else {
  1146. error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  1147. mpu_port, 0, miro->mpu_irq, &rmidi);
  1148. if (error < 0)
  1149. snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
  1150. mpu_port);
  1151. }
  1152. if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
  1153. struct snd_opl3 *opl3 = NULL;
  1154. struct snd_opl4 *opl4;
  1155. if (snd_opl4_create(card, fm_port, fm_port - 8,
  1156. 2, &opl3, &opl4) < 0)
  1157. snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n",
  1158. fm_port);
  1159. }
  1160. error = snd_set_aci_init_values(miro);
  1161. if (error < 0)
  1162. return error;
  1163. return snd_card_register(card);
  1164. }
  1165. static int snd_miro_isa_match(struct device *devptr, unsigned int n)
  1166. {
  1167. #ifdef CONFIG_PNP
  1168. if (snd_miro_pnp_is_probed)
  1169. return 0;
  1170. if (isapnp)
  1171. return 0;
  1172. #endif
  1173. return 1;
  1174. }
  1175. static int snd_miro_isa_probe(struct device *devptr, unsigned int n)
  1176. {
  1177. static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
  1178. static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
  1179. static int possible_irqs[] = {11, 9, 10, 7, -1};
  1180. static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
  1181. static int possible_dma1s[] = {3, 1, 0, -1};
  1182. static int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1},
  1183. {0, -1} };
  1184. int error;
  1185. struct snd_miro *miro;
  1186. struct snd_card *card;
  1187. error = snd_card_new(devptr, index, id, THIS_MODULE,
  1188. sizeof(struct snd_miro), &card);
  1189. if (error < 0)
  1190. return error;
  1191. card->private_free = snd_card_miro_free;
  1192. miro = card->private_data;
  1193. error = snd_card_miro_detect(card, miro);
  1194. if (error < 0) {
  1195. snd_card_free(card);
  1196. snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
  1197. return -ENODEV;
  1198. }
  1199. if (port == SNDRV_AUTO_PORT) {
  1200. port = snd_legacy_find_free_ioport(possible_ports, 4);
  1201. if (port < 0) {
  1202. snd_card_free(card);
  1203. snd_printk(KERN_ERR "unable to find a free WSS port\n");
  1204. return -EBUSY;
  1205. }
  1206. }
  1207. if (mpu_port == SNDRV_AUTO_PORT) {
  1208. mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
  1209. if (mpu_port < 0) {
  1210. snd_card_free(card);
  1211. snd_printk(KERN_ERR
  1212. "unable to find a free MPU401 port\n");
  1213. return -EBUSY;
  1214. }
  1215. }
  1216. if (irq == SNDRV_AUTO_IRQ) {
  1217. irq = snd_legacy_find_free_irq(possible_irqs);
  1218. if (irq < 0) {
  1219. snd_card_free(card);
  1220. snd_printk(KERN_ERR "unable to find a free IRQ\n");
  1221. return -EBUSY;
  1222. }
  1223. }
  1224. if (mpu_irq == SNDRV_AUTO_IRQ) {
  1225. mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
  1226. if (mpu_irq < 0) {
  1227. snd_card_free(card);
  1228. snd_printk(KERN_ERR
  1229. "unable to find a free MPU401 IRQ\n");
  1230. return -EBUSY;
  1231. }
  1232. }
  1233. if (dma1 == SNDRV_AUTO_DMA) {
  1234. dma1 = snd_legacy_find_free_dma(possible_dma1s);
  1235. if (dma1 < 0) {
  1236. snd_card_free(card);
  1237. snd_printk(KERN_ERR "unable to find a free DMA1\n");
  1238. return -EBUSY;
  1239. }
  1240. }
  1241. if (dma2 == SNDRV_AUTO_DMA) {
  1242. dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
  1243. if (dma2 < 0) {
  1244. snd_card_free(card);
  1245. snd_printk(KERN_ERR "unable to find a free DMA2\n");
  1246. return -EBUSY;
  1247. }
  1248. }
  1249. error = snd_miro_probe(card);
  1250. if (error < 0) {
  1251. snd_card_free(card);
  1252. return error;
  1253. }
  1254. dev_set_drvdata(devptr, card);
  1255. return 0;
  1256. }
  1257. static int snd_miro_isa_remove(struct device *devptr,
  1258. unsigned int dev)
  1259. {
  1260. snd_card_free(dev_get_drvdata(devptr));
  1261. return 0;
  1262. }
  1263. #define DEV_NAME "miro"
  1264. static struct isa_driver snd_miro_driver = {
  1265. .match = snd_miro_isa_match,
  1266. .probe = snd_miro_isa_probe,
  1267. .remove = snd_miro_isa_remove,
  1268. /* FIXME: suspend/resume */
  1269. .driver = {
  1270. .name = DEV_NAME
  1271. },
  1272. };
  1273. #ifdef CONFIG_PNP
  1274. static int snd_card_miro_pnp(struct snd_miro *chip,
  1275. struct pnp_card_link *card,
  1276. const struct pnp_card_device_id *pid)
  1277. {
  1278. struct pnp_dev *pdev;
  1279. int err;
  1280. struct pnp_dev *devmpu;
  1281. struct pnp_dev *devmc;
  1282. pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
  1283. if (pdev == NULL)
  1284. return -EBUSY;
  1285. devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
  1286. if (devmpu == NULL)
  1287. return -EBUSY;
  1288. devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
  1289. if (devmc == NULL)
  1290. return -EBUSY;
  1291. err = pnp_activate_dev(pdev);
  1292. if (err < 0) {
  1293. snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
  1294. return err;
  1295. }
  1296. err = pnp_activate_dev(devmc);
  1297. if (err < 0) {
  1298. snd_printk(KERN_ERR "MC pnp configure failure: %d\n",
  1299. err);
  1300. return err;
  1301. }
  1302. port = pnp_port_start(pdev, 1);
  1303. fm_port = pnp_port_start(pdev, 2) + 8;
  1304. /*
  1305. * The MC(0) is never accessed and the miroSOUND PCM20 card does not
  1306. * include it in the PnP resource range. OPTI93x include it.
  1307. */
  1308. chip->mc_base = pnp_port_start(devmc, 0) - 1;
  1309. chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
  1310. irq = pnp_irq(pdev, 0);
  1311. dma1 = pnp_dma(pdev, 0);
  1312. dma2 = pnp_dma(pdev, 1);
  1313. if (mpu_port > 0) {
  1314. err = pnp_activate_dev(devmpu);
  1315. if (err < 0) {
  1316. snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
  1317. mpu_port = -1;
  1318. return err;
  1319. }
  1320. mpu_port = pnp_port_start(devmpu, 0);
  1321. mpu_irq = pnp_irq(devmpu, 0);
  1322. }
  1323. return 0;
  1324. }
  1325. static int snd_miro_pnp_probe(struct pnp_card_link *pcard,
  1326. const struct pnp_card_device_id *pid)
  1327. {
  1328. struct snd_card *card;
  1329. int err;
  1330. struct snd_miro *miro;
  1331. if (snd_miro_pnp_is_probed)
  1332. return -EBUSY;
  1333. if (!isapnp)
  1334. return -ENODEV;
  1335. err = snd_card_new(&pcard->card->dev, index, id, THIS_MODULE,
  1336. sizeof(struct snd_miro), &card);
  1337. if (err < 0)
  1338. return err;
  1339. card->private_free = snd_card_miro_free;
  1340. miro = card->private_data;
  1341. err = snd_card_miro_pnp(miro, pcard, pid);
  1342. if (err) {
  1343. snd_card_free(card);
  1344. return err;
  1345. }
  1346. /* only miroSOUND PCM20 and PCM12 == OPTi924 */
  1347. err = snd_miro_init(miro, OPTi9XX_HW_82C924);
  1348. if (err) {
  1349. snd_card_free(card);
  1350. return err;
  1351. }
  1352. err = snd_miro_opti_check(miro);
  1353. if (err) {
  1354. snd_printk(KERN_ERR "OPTI chip not found\n");
  1355. snd_card_free(card);
  1356. return err;
  1357. }
  1358. err = snd_miro_probe(card);
  1359. if (err < 0) {
  1360. snd_card_free(card);
  1361. return err;
  1362. }
  1363. pnp_set_card_drvdata(pcard, card);
  1364. snd_miro_pnp_is_probed = 1;
  1365. return 0;
  1366. }
  1367. static void snd_miro_pnp_remove(struct pnp_card_link *pcard)
  1368. {
  1369. snd_card_free(pnp_get_card_drvdata(pcard));
  1370. pnp_set_card_drvdata(pcard, NULL);
  1371. snd_miro_pnp_is_probed = 0;
  1372. }
  1373. static struct pnp_card_driver miro_pnpc_driver = {
  1374. .flags = PNP_DRIVER_RES_DISABLE,
  1375. .name = "miro",
  1376. .id_table = snd_miro_pnpids,
  1377. .probe = snd_miro_pnp_probe,
  1378. .remove = snd_miro_pnp_remove,
  1379. };
  1380. #endif
  1381. static int __init alsa_card_miro_init(void)
  1382. {
  1383. #ifdef CONFIG_PNP
  1384. pnp_register_card_driver(&miro_pnpc_driver);
  1385. if (snd_miro_pnp_is_probed)
  1386. return 0;
  1387. pnp_unregister_card_driver(&miro_pnpc_driver);
  1388. #endif
  1389. return isa_register_driver(&snd_miro_driver, 1);
  1390. }
  1391. static void __exit alsa_card_miro_exit(void)
  1392. {
  1393. if (!snd_miro_pnp_is_probed) {
  1394. isa_unregister_driver(&snd_miro_driver);
  1395. return;
  1396. }
  1397. #ifdef CONFIG_PNP
  1398. pnp_unregister_card_driver(&miro_pnpc_driver);
  1399. #endif
  1400. }
  1401. module_init(alsa_card_miro_init)
  1402. module_exit(alsa_card_miro_exit)