miro.c 38 KB

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