miro.c 36 KB

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