miro.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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/cs4231.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 fm_port;
  109. long mpu_port;
  110. int mpu_irq;
  111. unsigned long aci_port;
  112. int aci_vendor;
  113. int aci_product;
  114. int aci_version;
  115. int aci_amp;
  116. int aci_preamp;
  117. int aci_solomode;
  118. struct mutex aci_mutex;
  119. };
  120. static void snd_miro_proc_init(struct snd_miro * miro);
  121. static char * snd_opti9xx_names[] = {
  122. "unkown",
  123. "82C928", "82C929",
  124. "82C924", "82C925",
  125. "82C930", "82C931", "82C933"
  126. };
  127. /*
  128. * ACI control
  129. */
  130. static int aci_busy_wait(struct snd_miro * miro)
  131. {
  132. long timeout;
  133. unsigned char byte;
  134. for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) {
  135. if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) {
  136. if (timeout >= ACI_MINTIME)
  137. snd_printd("aci ready in round %ld.\n",
  138. timeout-ACI_MINTIME);
  139. return byte;
  140. }
  141. if (timeout >= ACI_MINTIME) {
  142. long out=10*HZ;
  143. switch (timeout-ACI_MINTIME) {
  144. case 0 ... 9:
  145. out /= 10;
  146. case 10 ... 19:
  147. out /= 10;
  148. case 20 ... 30:
  149. out /= 10;
  150. default:
  151. set_current_state(TASK_UNINTERRUPTIBLE);
  152. schedule_timeout(out);
  153. break;
  154. }
  155. }
  156. }
  157. snd_printk(KERN_ERR "aci_busy_wait() time out\n");
  158. return -EBUSY;
  159. }
  160. static inline int aci_write(struct snd_miro * miro, unsigned char byte)
  161. {
  162. if (aci_busy_wait(miro) >= 0) {
  163. outb(byte, miro->aci_port + ACI_REG_COMMAND);
  164. return 0;
  165. } else {
  166. snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte);
  167. return -EBUSY;
  168. }
  169. }
  170. static inline int aci_read(struct snd_miro * miro)
  171. {
  172. unsigned char byte;
  173. if (aci_busy_wait(miro) >= 0) {
  174. byte=inb(miro->aci_port + ACI_REG_STATUS);
  175. return byte;
  176. } else {
  177. snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n");
  178. return -EBUSY;
  179. }
  180. }
  181. static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3)
  182. {
  183. int write[] = {write1, write2, write3};
  184. int value, i;
  185. if (mutex_lock_interruptible(&miro->aci_mutex))
  186. return -EINTR;
  187. for (i=0; i<3; i++) {
  188. if (write[i]< 0 || write[i] > 255)
  189. break;
  190. else {
  191. value = aci_write(miro, write[i]);
  192. if (value < 0)
  193. goto out;
  194. }
  195. }
  196. value = aci_read(miro);
  197. out: mutex_unlock(&miro->aci_mutex);
  198. return value;
  199. }
  200. static int aci_getvalue(struct snd_miro * miro, unsigned char index)
  201. {
  202. return aci_cmd(miro, ACI_STATUS, index, -1);
  203. }
  204. static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value)
  205. {
  206. return aci_cmd(miro, index, value, -1);
  207. }
  208. /*
  209. * MIXER part
  210. */
  211. #define snd_miro_info_capture snd_ctl_boolean_mono_info
  212. static int snd_miro_get_capture(struct snd_kcontrol *kcontrol,
  213. struct snd_ctl_elem_value *ucontrol)
  214. {
  215. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  216. int value;
  217. if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) {
  218. snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value);
  219. return value;
  220. }
  221. ucontrol->value.integer.value[0] = value & 0x20;
  222. return 0;
  223. }
  224. static int snd_miro_put_capture(struct snd_kcontrol *kcontrol,
  225. struct snd_ctl_elem_value *ucontrol)
  226. {
  227. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  228. int change, value, error;
  229. value = !(ucontrol->value.integer.value[0]);
  230. if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) {
  231. snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error);
  232. return error;
  233. }
  234. change = (value != miro->aci_solomode);
  235. miro->aci_solomode = value;
  236. return change;
  237. }
  238. static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol,
  239. struct snd_ctl_elem_info *uinfo)
  240. {
  241. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  242. uinfo->count = 1;
  243. uinfo->value.integer.min = 0;
  244. uinfo->value.integer.max = 3;
  245. return 0;
  246. }
  247. static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
  248. struct snd_ctl_elem_value *ucontrol)
  249. {
  250. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  251. int value;
  252. if (miro->aci_version <= 176) {
  253. /*
  254. OSS says it's not readable with versions < 176.
  255. But it doesn't work on my card,
  256. which is a PCM12 with aci_version = 176.
  257. */
  258. ucontrol->value.integer.value[0] = miro->aci_preamp;
  259. return 0;
  260. }
  261. if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) {
  262. snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value);
  263. return value;
  264. }
  265. ucontrol->value.integer.value[0] = value;
  266. return 0;
  267. }
  268. static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol,
  269. struct snd_ctl_elem_value *ucontrol)
  270. {
  271. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  272. int error, value, change;
  273. value = ucontrol->value.integer.value[0];
  274. if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) {
  275. snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error);
  276. return error;
  277. }
  278. change = (value != miro->aci_preamp);
  279. miro->aci_preamp = value;
  280. return change;
  281. }
  282. #define snd_miro_info_amp snd_ctl_boolean_mono_info
  283. static int snd_miro_get_amp(struct snd_kcontrol *kcontrol,
  284. struct snd_ctl_elem_value *ucontrol)
  285. {
  286. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  287. ucontrol->value.integer.value[0] = miro->aci_amp;
  288. return 0;
  289. }
  290. static int snd_miro_put_amp(struct snd_kcontrol *kcontrol,
  291. struct snd_ctl_elem_value *ucontrol)
  292. {
  293. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  294. int error, value, change;
  295. value = ucontrol->value.integer.value[0];
  296. if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) {
  297. snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error);
  298. return error;
  299. }
  300. change = (value != miro->aci_amp);
  301. miro->aci_amp = value;
  302. return change;
  303. }
  304. #define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \
  305. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  306. .name = ctl_name, \
  307. .index = ctl_index, \
  308. .info = snd_miro_info_double, \
  309. .get = snd_miro_get_double, \
  310. .put = snd_miro_put_double, \
  311. .private_value = get_right_reg | (set_right_reg << 8) \
  312. }
  313. static int snd_miro_info_double(struct snd_kcontrol *kcontrol,
  314. struct snd_ctl_elem_info *uinfo)
  315. {
  316. int reg = kcontrol->private_value & 0xff;
  317. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  318. uinfo->count = 2;
  319. if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) {
  320. /* equalizer elements */
  321. uinfo->value.integer.min = - 0x7f;
  322. uinfo->value.integer.max = 0x7f;
  323. } else {
  324. /* non-equalizer elements */
  325. uinfo->value.integer.min = 0;
  326. uinfo->value.integer.max = 0x20;
  327. }
  328. return 0;
  329. }
  330. static int snd_miro_get_double(struct snd_kcontrol *kcontrol,
  331. struct snd_ctl_elem_value *uinfo)
  332. {
  333. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  334. int left_val, right_val;
  335. int right_reg = kcontrol->private_value & 0xff;
  336. int left_reg = right_reg + 1;
  337. if ((right_val = aci_getvalue(miro, right_reg)) < 0) {
  338. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val);
  339. return right_val;
  340. }
  341. if ((left_val = aci_getvalue(miro, left_reg)) < 0) {
  342. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val);
  343. return left_val;
  344. }
  345. if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) {
  346. /* equalizer elements */
  347. if (left_val < 0x80) {
  348. uinfo->value.integer.value[0] = left_val;
  349. } else {
  350. uinfo->value.integer.value[0] = 0x80 - left_val;
  351. }
  352. if (right_val < 0x80) {
  353. uinfo->value.integer.value[1] = right_val;
  354. } else {
  355. uinfo->value.integer.value[1] = 0x80 - right_val;
  356. }
  357. } else {
  358. /* non-equalizer elements */
  359. uinfo->value.integer.value[0] = 0x20 - left_val;
  360. uinfo->value.integer.value[1] = 0x20 - right_val;
  361. }
  362. return 0;
  363. }
  364. static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
  365. struct snd_ctl_elem_value *ucontrol)
  366. {
  367. struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
  368. int left, right, left_old, right_old;
  369. int setreg_left, setreg_right, getreg_left, getreg_right;
  370. int change, error;
  371. left = ucontrol->value.integer.value[0];
  372. right = ucontrol->value.integer.value[1];
  373. setreg_right = (kcontrol->private_value >> 8) & 0xff;
  374. if (setreg_right == ACI_SET_MASTER) {
  375. setreg_left = setreg_right + 1;
  376. } else {
  377. setreg_left = setreg_right + 8;
  378. }
  379. getreg_right = kcontrol->private_value & 0xff;
  380. getreg_left = getreg_right + 1;
  381. if ((left_old = aci_getvalue(miro, getreg_left)) < 0) {
  382. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old);
  383. return left_old;
  384. }
  385. if ((right_old = aci_getvalue(miro, getreg_right)) < 0) {
  386. snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old);
  387. return right_old;
  388. }
  389. if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) {
  390. /* equalizer elements */
  391. if (left < -0x7f || left > 0x7f ||
  392. right < -0x7f || right > 0x7f)
  393. return -EINVAL;
  394. if (left_old > 0x80)
  395. left_old = 0x80 - left_old;
  396. if (right_old > 0x80)
  397. right_old = 0x80 - right_old;
  398. if (left >= 0) {
  399. if ((error = aci_setvalue(miro, setreg_left, left)) < 0) {
  400. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  401. left, error);
  402. return error;
  403. }
  404. } else {
  405. if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) {
  406. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  407. 0x80 - left, error);
  408. return error;
  409. }
  410. }
  411. if (right >= 0) {
  412. if ((error = aci_setvalue(miro, setreg_right, right)) < 0) {
  413. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  414. right, error);
  415. return error;
  416. }
  417. } else {
  418. if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) {
  419. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  420. 0x80 - right, error);
  421. return error;
  422. }
  423. }
  424. } else {
  425. /* non-equalizer elements */
  426. if (left < 0 || left > 0x20 ||
  427. right < 0 || right > 0x20)
  428. return -EINVAL;
  429. left_old = 0x20 - left_old;
  430. right_old = 0x20 - right_old;
  431. if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) {
  432. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  433. 0x20 - left, error);
  434. return error;
  435. }
  436. if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) {
  437. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  438. 0x20 - right, error);
  439. return error;
  440. }
  441. }
  442. change = (left != left_old) || (right != right_old);
  443. return change;
  444. }
  445. static struct snd_kcontrol_new snd_miro_controls[] __devinitdata = {
  446. MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER),
  447. MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC),
  448. MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE),
  449. MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD),
  450. MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH),
  451. MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM),
  452. MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2),
  453. };
  454. /* Equalizer with seven bands (only PCM20)
  455. from -12dB up to +12dB on each band */
  456. static struct snd_kcontrol_new snd_miro_eq_controls[] __devinitdata = {
  457. MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1),
  458. MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2),
  459. MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3),
  460. MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4),
  461. MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5),
  462. MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6),
  463. MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7),
  464. };
  465. static struct snd_kcontrol_new snd_miro_radio_control[] __devinitdata = {
  466. MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1),
  467. };
  468. static struct snd_kcontrol_new snd_miro_line_control[] __devinitdata = {
  469. MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1),
  470. };
  471. static struct snd_kcontrol_new snd_miro_preamp_control[] __devinitdata = {
  472. {
  473. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  474. .name = "Mic Boost",
  475. .index = 1,
  476. .info = snd_miro_info_preamp,
  477. .get = snd_miro_get_preamp,
  478. .put = snd_miro_put_preamp,
  479. }};
  480. static struct snd_kcontrol_new snd_miro_amp_control[] __devinitdata = {
  481. {
  482. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  483. .name = "Line Boost",
  484. .index = 0,
  485. .info = snd_miro_info_amp,
  486. .get = snd_miro_get_amp,
  487. .put = snd_miro_put_amp,
  488. }};
  489. static struct snd_kcontrol_new snd_miro_capture_control[] __devinitdata = {
  490. {
  491. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  492. .name = "PCM Capture Switch",
  493. .index = 0,
  494. .info = snd_miro_info_capture,
  495. .get = snd_miro_get_capture,
  496. .put = snd_miro_put_capture,
  497. }};
  498. static unsigned char aci_init_values[][2] __devinitdata = {
  499. { ACI_SET_MUTE, 0x00 },
  500. { ACI_SET_POWERAMP, 0x00 },
  501. { ACI_SET_PREAMP, 0x00 },
  502. { ACI_SET_SOLOMODE, 0x00 },
  503. { ACI_SET_MIC + 0, 0x20 },
  504. { ACI_SET_MIC + 8, 0x20 },
  505. { ACI_SET_LINE + 0, 0x20 },
  506. { ACI_SET_LINE + 8, 0x20 },
  507. { ACI_SET_CD + 0, 0x20 },
  508. { ACI_SET_CD + 8, 0x20 },
  509. { ACI_SET_PCM + 0, 0x20 },
  510. { ACI_SET_PCM + 8, 0x20 },
  511. { ACI_SET_LINE1 + 0, 0x20 },
  512. { ACI_SET_LINE1 + 8, 0x20 },
  513. { ACI_SET_LINE2 + 0, 0x20 },
  514. { ACI_SET_LINE2 + 8, 0x20 },
  515. { ACI_SET_SYNTH + 0, 0x20 },
  516. { ACI_SET_SYNTH + 8, 0x20 },
  517. { ACI_SET_MASTER + 0, 0x20 },
  518. { ACI_SET_MASTER + 1, 0x20 },
  519. };
  520. static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
  521. {
  522. int idx, error;
  523. /* enable WSS on PCM1 */
  524. if ((miro->aci_product == 'A') && wss) {
  525. if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) {
  526. snd_printk(KERN_ERR "enabling WSS mode failed\n");
  527. return error;
  528. }
  529. }
  530. /* enable IDE port */
  531. if (ide) {
  532. if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) {
  533. snd_printk(KERN_ERR "enabling IDE port failed\n");
  534. return error;
  535. }
  536. }
  537. /* set common aci values */
  538. for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++)
  539. if ((error = aci_setvalue(miro, aci_init_values[idx][0],
  540. aci_init_values[idx][1])) < 0) {
  541. snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
  542. aci_init_values[idx][0], error);
  543. return error;
  544. }
  545. miro->aci_amp = 0;
  546. miro->aci_preamp = 0;
  547. miro->aci_solomode = 1;
  548. return 0;
  549. }
  550. static int __devinit snd_miro_mixer(struct snd_miro *miro)
  551. {
  552. struct snd_card *card;
  553. unsigned int idx;
  554. int err;
  555. snd_assert(miro != NULL && miro->card != NULL, 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->fm_port = -1;
  624. chip->mpu_port = -1;
  625. chip->mpu_irq = -1;
  626. switch (hardware) {
  627. case OPTi9XX_HW_82C929:
  628. chip->mc_base = 0xf8c;
  629. chip->password = 0xe3;
  630. chip->pwd_reg = 3;
  631. break;
  632. case OPTi9XX_HW_82C924:
  633. chip->mc_base = 0xf8c;
  634. chip->password = 0xe5;
  635. chip->pwd_reg = 3;
  636. break;
  637. default:
  638. snd_printk(KERN_ERR "sorry, no support for %d\n", hardware);
  639. return -ENODEV;
  640. }
  641. return 0;
  642. }
  643. static unsigned char snd_miro_read(struct snd_miro *chip,
  644. unsigned char reg)
  645. {
  646. unsigned long flags;
  647. unsigned char retval = 0xff;
  648. spin_lock_irqsave(&chip->lock, flags);
  649. outb(chip->password, chip->mc_base + chip->pwd_reg);
  650. switch (chip->hardware) {
  651. case OPTi9XX_HW_82C924:
  652. if (reg > 7) {
  653. outb(reg, chip->mc_base + 8);
  654. outb(chip->password, chip->mc_base + chip->pwd_reg);
  655. retval = inb(chip->mc_base + 9);
  656. break;
  657. }
  658. case OPTi9XX_HW_82C929:
  659. retval = inb(chip->mc_base + reg);
  660. break;
  661. default:
  662. snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
  663. }
  664. spin_unlock_irqrestore(&chip->lock, flags);
  665. return retval;
  666. }
  667. static void snd_miro_write(struct snd_miro *chip, unsigned char reg,
  668. unsigned char value)
  669. {
  670. unsigned long flags;
  671. spin_lock_irqsave(&chip->lock, flags);
  672. outb(chip->password, chip->mc_base + chip->pwd_reg);
  673. switch (chip->hardware) {
  674. case OPTi9XX_HW_82C924:
  675. if (reg > 7) {
  676. outb(reg, chip->mc_base + 8);
  677. outb(chip->password, chip->mc_base + chip->pwd_reg);
  678. outb(value, chip->mc_base + 9);
  679. break;
  680. }
  681. case OPTi9XX_HW_82C929:
  682. outb(value, chip->mc_base + reg);
  683. break;
  684. default:
  685. snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
  686. }
  687. spin_unlock_irqrestore(&chip->lock, flags);
  688. }
  689. #define snd_miro_write_mask(chip, reg, value, mask) \
  690. snd_miro_write(chip, reg, \
  691. (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
  692. /*
  693. * Proc Interface
  694. */
  695. static void snd_miro_proc_read(struct snd_info_entry * entry,
  696. struct snd_info_buffer *buffer)
  697. {
  698. struct snd_miro *miro = (struct snd_miro *) entry->private_data;
  699. char* model = "unknown";
  700. /* miroSOUND PCM1 pro, early PCM12 */
  701. if ((miro->hardware == OPTi9XX_HW_82C929) &&
  702. (miro->aci_vendor == 'm') &&
  703. (miro->aci_product == 'A')) {
  704. switch(miro->aci_version) {
  705. case 3:
  706. model = "miroSOUND PCM1 pro";
  707. break;
  708. default:
  709. model = "miroSOUND PCM1 pro / (early) PCM12";
  710. break;
  711. }
  712. }
  713. /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
  714. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  715. (miro->aci_vendor == 'm') &&
  716. (miro->aci_product == 'B')) {
  717. switch(miro->aci_version) {
  718. case 4:
  719. model = "miroSOUND PCM12";
  720. break;
  721. case 176:
  722. model = "miroSOUND PCM12 (Rev. E)";
  723. break;
  724. default:
  725. model = "miroSOUND PCM12 / PCM12 pnp";
  726. break;
  727. }
  728. }
  729. /* miroSOUND PCM20 radio */
  730. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  731. (miro->aci_vendor == 'm') &&
  732. (miro->aci_product == 'C')) {
  733. switch(miro->aci_version) {
  734. case 7:
  735. model = "miroSOUND PCM20 radio (Rev. E)";
  736. break;
  737. default:
  738. model = "miroSOUND PCM20 radio";
  739. break;
  740. }
  741. }
  742. snd_iprintf(buffer, "\nGeneral information:\n");
  743. snd_iprintf(buffer, " model : %s\n", model);
  744. snd_iprintf(buffer, " opti : %s\n", miro->name);
  745. snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
  746. snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
  747. snd_iprintf(buffer, " irq : %d\n", miro->irq);
  748. snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
  749. snd_iprintf(buffer, "MPU-401:\n");
  750. snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
  751. snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
  752. snd_iprintf(buffer, "ACI information:\n");
  753. snd_iprintf(buffer, " vendor : ");
  754. switch(miro->aci_vendor) {
  755. case 'm':
  756. snd_iprintf(buffer, "Miro\n");
  757. break;
  758. default:
  759. snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor);
  760. break;
  761. }
  762. snd_iprintf(buffer, " product : ");
  763. switch(miro->aci_product) {
  764. case 'A':
  765. snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
  766. break;
  767. case 'B':
  768. snd_iprintf(buffer, "miroSOUND PCM12\n");
  769. break;
  770. case 'C':
  771. snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
  772. break;
  773. default:
  774. snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product);
  775. break;
  776. }
  777. snd_iprintf(buffer, " firmware: %d (0x%x)\n",
  778. miro->aci_version, miro->aci_version);
  779. snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
  780. miro->aci_port, miro->aci_port+2);
  781. snd_iprintf(buffer, " wss : 0x%x\n", wss);
  782. snd_iprintf(buffer, " ide : 0x%x\n", ide);
  783. snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode);
  784. snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp);
  785. snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp);
  786. }
  787. static void __devinit snd_miro_proc_init(struct snd_miro * miro)
  788. {
  789. struct snd_info_entry *entry;
  790. if (! snd_card_proc_new(miro->card, "miro", &entry))
  791. snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
  792. }
  793. /*
  794. * Init
  795. */
  796. static int __devinit snd_miro_configure(struct snd_miro *chip)
  797. {
  798. unsigned char wss_base_bits;
  799. unsigned char irq_bits;
  800. unsigned char dma_bits;
  801. unsigned char mpu_port_bits = 0;
  802. unsigned char mpu_irq_bits;
  803. unsigned long flags;
  804. switch (chip->hardware) {
  805. case OPTi9XX_HW_82C924:
  806. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
  807. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  808. snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
  809. snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
  810. snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  811. break;
  812. case OPTi9XX_HW_82C929:
  813. /* untested init commands for OPTi929 */
  814. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  815. snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
  816. snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
  817. snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  818. break;
  819. default:
  820. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  821. return -EINVAL;
  822. }
  823. switch (chip->wss_base) {
  824. case 0x530:
  825. wss_base_bits = 0x00;
  826. break;
  827. case 0x604:
  828. wss_base_bits = 0x03;
  829. break;
  830. case 0xe80:
  831. wss_base_bits = 0x01;
  832. break;
  833. case 0xf40:
  834. wss_base_bits = 0x02;
  835. break;
  836. default:
  837. snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
  838. goto __skip_base;
  839. }
  840. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
  841. __skip_base:
  842. switch (chip->irq) {
  843. case 5:
  844. irq_bits = 0x05;
  845. break;
  846. case 7:
  847. irq_bits = 0x01;
  848. break;
  849. case 9:
  850. irq_bits = 0x02;
  851. break;
  852. case 10:
  853. irq_bits = 0x03;
  854. break;
  855. case 11:
  856. irq_bits = 0x04;
  857. break;
  858. default:
  859. snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
  860. goto __skip_resources;
  861. }
  862. switch (chip->dma1) {
  863. case 0:
  864. dma_bits = 0x01;
  865. break;
  866. case 1:
  867. dma_bits = 0x02;
  868. break;
  869. case 3:
  870. dma_bits = 0x03;
  871. break;
  872. default:
  873. snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
  874. goto __skip_resources;
  875. }
  876. if (chip->dma1 == chip->dma2) {
  877. snd_printk(KERN_ERR "don't want to share dmas\n");
  878. return -EBUSY;
  879. }
  880. switch (chip->dma2) {
  881. case 0:
  882. case 1:
  883. break;
  884. default:
  885. snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
  886. goto __skip_resources;
  887. }
  888. dma_bits |= 0x04;
  889. spin_lock_irqsave(&chip->lock, flags);
  890. outb(irq_bits << 3 | dma_bits, chip->wss_base);
  891. spin_unlock_irqrestore(&chip->lock, flags);
  892. __skip_resources:
  893. if (chip->hardware > OPTi9XX_HW_82C928) {
  894. switch (chip->mpu_port) {
  895. case 0:
  896. case -1:
  897. break;
  898. case 0x300:
  899. mpu_port_bits = 0x03;
  900. break;
  901. case 0x310:
  902. mpu_port_bits = 0x02;
  903. break;
  904. case 0x320:
  905. mpu_port_bits = 0x01;
  906. break;
  907. case 0x330:
  908. mpu_port_bits = 0x00;
  909. break;
  910. default:
  911. snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
  912. chip->mpu_port);
  913. goto __skip_mpu;
  914. }
  915. switch (chip->mpu_irq) {
  916. case 5:
  917. mpu_irq_bits = 0x02;
  918. break;
  919. case 7:
  920. mpu_irq_bits = 0x03;
  921. break;
  922. case 9:
  923. mpu_irq_bits = 0x00;
  924. break;
  925. case 10:
  926. mpu_irq_bits = 0x01;
  927. break;
  928. default:
  929. snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
  930. chip->mpu_irq);
  931. goto __skip_mpu;
  932. }
  933. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
  934. (chip->mpu_port <= 0) ? 0x00 :
  935. 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
  936. 0xf8);
  937. }
  938. __skip_mpu:
  939. return 0;
  940. }
  941. static int __devinit snd_card_miro_detect(struct snd_card *card,
  942. struct snd_miro *chip)
  943. {
  944. int i, err;
  945. unsigned char value;
  946. for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
  947. if ((err = snd_miro_init(chip, i)) < 0)
  948. return err;
  949. if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
  950. continue;
  951. value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
  952. if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
  953. if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
  954. return 1;
  955. release_and_free_resource(chip->res_mc_base);
  956. chip->res_mc_base = NULL;
  957. }
  958. return -ENODEV;
  959. }
  960. static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
  961. struct snd_miro * miro)
  962. {
  963. unsigned char regval;
  964. int i;
  965. mutex_init(&miro->aci_mutex);
  966. /* get ACI port from OPTi9xx MC 4 */
  967. miro->mc_base = 0xf8c;
  968. regval=inb(miro->mc_base + 4);
  969. miro->aci_port = (regval & 0x10) ? 0x344: 0x354;
  970. if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) {
  971. snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
  972. miro->aci_port, miro->aci_port+2);
  973. return -ENOMEM;
  974. }
  975. /* force ACI into a known state */
  976. for (i = 0; i < 3; i++)
  977. if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) {
  978. snd_printk(KERN_ERR "can't force aci into known state.\n");
  979. return -ENXIO;
  980. }
  981. if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 ||
  982. (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) {
  983. snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port);
  984. return -ENXIO;
  985. }
  986. if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) {
  987. snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
  988. miro->aci_port);
  989. return -ENXIO;
  990. }
  991. if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 ||
  992. aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
  993. aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
  994. snd_printk(KERN_ERR "can't initialize aci.\n");
  995. return -ENXIO;
  996. }
  997. return 0;
  998. }
  999. static void snd_card_miro_free(struct snd_card *card)
  1000. {
  1001. struct snd_miro *miro = card->private_data;
  1002. release_and_free_resource(miro->res_aci_port);
  1003. release_and_free_resource(miro->res_mc_base);
  1004. }
  1005. static int __devinit snd_miro_match(struct device *devptr, unsigned int n)
  1006. {
  1007. return 1;
  1008. }
  1009. static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
  1010. {
  1011. static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
  1012. static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
  1013. static int possible_irqs[] = {11, 9, 10, 7, -1};
  1014. static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
  1015. static int possible_dma1s[] = {3, 1, 0, -1};
  1016. static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
  1017. int error;
  1018. struct snd_miro *miro;
  1019. struct snd_cs4231 *codec;
  1020. struct snd_timer *timer;
  1021. struct snd_card *card;
  1022. struct snd_pcm *pcm;
  1023. struct snd_rawmidi *rmidi;
  1024. if (!(card = snd_card_new(index, id, THIS_MODULE,
  1025. sizeof(struct snd_miro))))
  1026. return -ENOMEM;
  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->fm_port = fm_port;
  1051. miro->mpu_port = mpu_port;
  1052. miro->irq = irq;
  1053. miro->mpu_irq = mpu_irq;
  1054. miro->dma1 = dma1;
  1055. miro->dma2 = dma2;
  1056. if (miro->wss_base == SNDRV_AUTO_PORT) {
  1057. if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
  1058. snd_card_free(card);
  1059. snd_printk(KERN_ERR "unable to find a free WSS port\n");
  1060. return -EBUSY;
  1061. }
  1062. }
  1063. if (miro->mpu_port == SNDRV_AUTO_PORT) {
  1064. if ((miro->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 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. if ((error = snd_miro_configure(miro))) {
  1099. snd_card_free(card);
  1100. return error;
  1101. }
  1102. if ((error = snd_cs4231_create(card, miro->wss_base + 4, -1,
  1103. miro->irq, miro->dma1, miro->dma2,
  1104. CS4231_HW_AD1845,
  1105. 0,
  1106. &codec)) < 0) {
  1107. snd_card_free(card);
  1108. return error;
  1109. }
  1110. if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
  1111. snd_card_free(card);
  1112. return error;
  1113. }
  1114. if ((error = snd_cs4231_mixer(codec)) < 0) {
  1115. snd_card_free(card);
  1116. return error;
  1117. }
  1118. if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
  1119. snd_card_free(card);
  1120. return error;
  1121. }
  1122. miro->pcm = pcm;
  1123. if ((error = snd_miro_mixer(miro)) < 0) {
  1124. snd_card_free(card);
  1125. return error;
  1126. }
  1127. if (miro->aci_vendor == 'm') {
  1128. /* It looks like a miro sound card. */
  1129. switch (miro->aci_product) {
  1130. case 'A':
  1131. sprintf(card->shortname,
  1132. "miroSOUND PCM1 pro / PCM12");
  1133. break;
  1134. case 'B':
  1135. sprintf(card->shortname,
  1136. "miroSOUND PCM12");
  1137. break;
  1138. case 'C':
  1139. sprintf(card->shortname,
  1140. "miroSOUND PCM20 radio");
  1141. break;
  1142. default:
  1143. sprintf(card->shortname,
  1144. "unknown miro");
  1145. snd_printk(KERN_INFO "unknown miro aci id\n");
  1146. break;
  1147. }
  1148. } else {
  1149. snd_printk(KERN_INFO "found unsupported aci card\n");
  1150. sprintf(card->shortname, "unknown Cardinal Technologies");
  1151. }
  1152. strcpy(card->driver, "miro");
  1153. sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
  1154. card->shortname, miro->name, pcm->name, miro->wss_base + 4,
  1155. miro->irq, miro->dma1, miro->dma2);
  1156. if (miro->mpu_port <= 0 || miro->mpu_port == SNDRV_AUTO_PORT)
  1157. rmidi = NULL;
  1158. else
  1159. if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  1160. miro->mpu_port, 0, miro->mpu_irq, IRQF_DISABLED,
  1161. &rmidi)))
  1162. snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", miro->mpu_port);
  1163. if (miro->fm_port > 0 && miro->fm_port != SNDRV_AUTO_PORT) {
  1164. struct snd_opl3 *opl3 = NULL;
  1165. struct snd_opl4 *opl4;
  1166. if (snd_opl4_create(card, miro->fm_port, miro->fm_port - 8,
  1167. 2, &opl3, &opl4) < 0)
  1168. snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", miro->fm_port);
  1169. }
  1170. if ((error = snd_set_aci_init_values(miro)) < 0) {
  1171. snd_card_free(card);
  1172. return error;
  1173. }
  1174. snd_card_set_dev(card, devptr);
  1175. if ((error = snd_card_register(card))) {
  1176. snd_card_free(card);
  1177. return error;
  1178. }
  1179. dev_set_drvdata(devptr, card);
  1180. return 0;
  1181. }
  1182. static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev)
  1183. {
  1184. snd_card_free(dev_get_drvdata(devptr));
  1185. dev_set_drvdata(devptr, NULL);
  1186. return 0;
  1187. }
  1188. #define DEV_NAME "miro"
  1189. static struct isa_driver snd_miro_driver = {
  1190. .match = snd_miro_match,
  1191. .probe = snd_miro_probe,
  1192. .remove = __devexit_p(snd_miro_remove),
  1193. /* FIXME: suspend/resume */
  1194. .driver = {
  1195. .name = DEV_NAME
  1196. },
  1197. };
  1198. static int __init alsa_card_miro_init(void)
  1199. {
  1200. return isa_register_driver(&snd_miro_driver, 1);
  1201. }
  1202. static void __exit alsa_card_miro_exit(void)
  1203. {
  1204. isa_unregister_driver(&snd_miro_driver);
  1205. }
  1206. module_init(alsa_card_miro_init)
  1207. module_exit(alsa_card_miro_exit)