miro.c 36 KB

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