miro.c 38 KB

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