miro.c 39 KB

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