miro.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  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(port, long, 0444);
  69. MODULE_PARM_DESC(port, "WSS port # for miro driver.");
  70. module_param(mpu_port, long, 0444);
  71. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver.");
  72. module_param(fm_port, long, 0444);
  73. MODULE_PARM_DESC(fm_port, "FM Port # for miro driver.");
  74. module_param(irq, int, 0444);
  75. MODULE_PARM_DESC(irq, "WSS irq # for miro driver.");
  76. module_param(mpu_irq, int, 0444);
  77. MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver.");
  78. module_param(dma1, int, 0444);
  79. MODULE_PARM_DESC(dma1, "1st dma # for miro driver.");
  80. module_param(dma2, int, 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 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. #define snd_miro_write_mask(chip, reg, value, mask) \
  724. snd_miro_write(chip, reg, \
  725. (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
  726. /*
  727. * Proc Interface
  728. */
  729. static void snd_miro_proc_read(struct snd_info_entry * entry,
  730. struct snd_info_buffer *buffer)
  731. {
  732. struct snd_miro *miro = (struct snd_miro *) entry->private_data;
  733. struct snd_miro_aci *aci = miro->aci;
  734. char* model = "unknown";
  735. /* miroSOUND PCM1 pro, early PCM12 */
  736. if ((miro->hardware == OPTi9XX_HW_82C929) &&
  737. (aci->aci_vendor == 'm') &&
  738. (aci->aci_product == 'A')) {
  739. switch (aci->aci_version) {
  740. case 3:
  741. model = "miroSOUND PCM1 pro";
  742. break;
  743. default:
  744. model = "miroSOUND PCM1 pro / (early) PCM12";
  745. break;
  746. }
  747. }
  748. /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
  749. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  750. (aci->aci_vendor == 'm') &&
  751. (aci->aci_product == 'B')) {
  752. switch (aci->aci_version) {
  753. case 4:
  754. model = "miroSOUND PCM12";
  755. break;
  756. case 176:
  757. model = "miroSOUND PCM12 (Rev. E)";
  758. break;
  759. default:
  760. model = "miroSOUND PCM12 / PCM12 pnp";
  761. break;
  762. }
  763. }
  764. /* miroSOUND PCM20 radio */
  765. if ((miro->hardware == OPTi9XX_HW_82C924) &&
  766. (aci->aci_vendor == 'm') &&
  767. (aci->aci_product == 'C')) {
  768. switch (aci->aci_version) {
  769. case 7:
  770. model = "miroSOUND PCM20 radio (Rev. E)";
  771. break;
  772. default:
  773. model = "miroSOUND PCM20 radio";
  774. break;
  775. }
  776. }
  777. snd_iprintf(buffer, "\nGeneral information:\n");
  778. snd_iprintf(buffer, " model : %s\n", model);
  779. snd_iprintf(buffer, " opti : %s\n", miro->name);
  780. snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
  781. snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
  782. snd_iprintf(buffer, " irq : %d\n", miro->irq);
  783. snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
  784. snd_iprintf(buffer, "MPU-401:\n");
  785. snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
  786. snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
  787. snd_iprintf(buffer, "ACI information:\n");
  788. snd_iprintf(buffer, " vendor : ");
  789. switch (aci->aci_vendor) {
  790. case 'm':
  791. snd_iprintf(buffer, "Miro\n");
  792. break;
  793. default:
  794. snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_vendor);
  795. break;
  796. }
  797. snd_iprintf(buffer, " product : ");
  798. switch (aci->aci_product) {
  799. case 'A':
  800. snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
  801. break;
  802. case 'B':
  803. snd_iprintf(buffer, "miroSOUND PCM12\n");
  804. break;
  805. case 'C':
  806. snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
  807. break;
  808. default:
  809. snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_product);
  810. break;
  811. }
  812. snd_iprintf(buffer, " firmware: %d (0x%x)\n",
  813. aci->aci_version, aci->aci_version);
  814. snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
  815. aci->aci_port, aci->aci_port+2);
  816. snd_iprintf(buffer, " wss : 0x%x\n", wss);
  817. snd_iprintf(buffer, " ide : 0x%x\n", ide);
  818. snd_iprintf(buffer, " solomode: 0x%x\n", aci->aci_solomode);
  819. snd_iprintf(buffer, " amp : 0x%x\n", aci->aci_amp);
  820. snd_iprintf(buffer, " preamp : 0x%x\n", aci->aci_preamp);
  821. }
  822. static void snd_miro_proc_init(struct snd_card *card,
  823. struct snd_miro *miro)
  824. {
  825. struct snd_info_entry *entry;
  826. if (!snd_card_proc_new(card, "miro", &entry))
  827. snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
  828. }
  829. /*
  830. * Init
  831. */
  832. static int snd_miro_configure(struct snd_miro *chip)
  833. {
  834. unsigned char wss_base_bits;
  835. unsigned char irq_bits;
  836. unsigned char dma_bits;
  837. unsigned char mpu_port_bits = 0;
  838. unsigned char mpu_irq_bits;
  839. unsigned long flags;
  840. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  841. snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
  842. snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  843. switch (chip->hardware) {
  844. case OPTi9XX_HW_82C924:
  845. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
  846. snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
  847. break;
  848. case OPTi9XX_HW_82C929:
  849. /* untested init commands for OPTi929 */
  850. snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
  851. break;
  852. default:
  853. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  854. return -EINVAL;
  855. }
  856. /* PnP resource says it decodes only 10 bits of address */
  857. switch (chip->wss_base & 0x3ff) {
  858. case 0x130:
  859. chip->wss_base = 0x530;
  860. wss_base_bits = 0x00;
  861. break;
  862. case 0x204:
  863. chip->wss_base = 0x604;
  864. wss_base_bits = 0x03;
  865. break;
  866. case 0x280:
  867. chip->wss_base = 0xe80;
  868. wss_base_bits = 0x01;
  869. break;
  870. case 0x340:
  871. chip->wss_base = 0xf40;
  872. wss_base_bits = 0x02;
  873. break;
  874. default:
  875. snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
  876. goto __skip_base;
  877. }
  878. snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
  879. __skip_base:
  880. switch (chip->irq) {
  881. case 5:
  882. irq_bits = 0x05;
  883. break;
  884. case 7:
  885. irq_bits = 0x01;
  886. break;
  887. case 9:
  888. irq_bits = 0x02;
  889. break;
  890. case 10:
  891. irq_bits = 0x03;
  892. break;
  893. case 11:
  894. irq_bits = 0x04;
  895. break;
  896. default:
  897. snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
  898. goto __skip_resources;
  899. }
  900. switch (chip->dma1) {
  901. case 0:
  902. dma_bits = 0x01;
  903. break;
  904. case 1:
  905. dma_bits = 0x02;
  906. break;
  907. case 3:
  908. dma_bits = 0x03;
  909. break;
  910. default:
  911. snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
  912. goto __skip_resources;
  913. }
  914. if (chip->dma1 == chip->dma2) {
  915. snd_printk(KERN_ERR "don't want to share dmas\n");
  916. return -EBUSY;
  917. }
  918. switch (chip->dma2) {
  919. case 0:
  920. case 1:
  921. break;
  922. default:
  923. snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
  924. goto __skip_resources;
  925. }
  926. dma_bits |= 0x04;
  927. spin_lock_irqsave(&chip->lock, flags);
  928. outb(irq_bits << 3 | dma_bits, chip->wss_base);
  929. spin_unlock_irqrestore(&chip->lock, flags);
  930. __skip_resources:
  931. if (chip->hardware > OPTi9XX_HW_82C928) {
  932. switch (chip->mpu_port) {
  933. case 0:
  934. case -1:
  935. break;
  936. case 0x300:
  937. mpu_port_bits = 0x03;
  938. break;
  939. case 0x310:
  940. mpu_port_bits = 0x02;
  941. break;
  942. case 0x320:
  943. mpu_port_bits = 0x01;
  944. break;
  945. case 0x330:
  946. mpu_port_bits = 0x00;
  947. break;
  948. default:
  949. snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
  950. chip->mpu_port);
  951. goto __skip_mpu;
  952. }
  953. switch (chip->mpu_irq) {
  954. case 5:
  955. mpu_irq_bits = 0x02;
  956. break;
  957. case 7:
  958. mpu_irq_bits = 0x03;
  959. break;
  960. case 9:
  961. mpu_irq_bits = 0x00;
  962. break;
  963. case 10:
  964. mpu_irq_bits = 0x01;
  965. break;
  966. default:
  967. snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
  968. chip->mpu_irq);
  969. goto __skip_mpu;
  970. }
  971. snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
  972. (chip->mpu_port <= 0) ? 0x00 :
  973. 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
  974. 0xf8);
  975. }
  976. __skip_mpu:
  977. return 0;
  978. }
  979. static int snd_miro_opti_check(struct snd_miro *chip)
  980. {
  981. unsigned char value;
  982. chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
  983. "OPTi9xx MC");
  984. if (chip->res_mc_base == NULL)
  985. return -ENOMEM;
  986. value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
  987. if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
  988. if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
  989. return 0;
  990. release_and_free_resource(chip->res_mc_base);
  991. chip->res_mc_base = NULL;
  992. return -ENODEV;
  993. }
  994. static int snd_card_miro_detect(struct snd_card *card,
  995. struct snd_miro *chip)
  996. {
  997. int i, err;
  998. for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
  999. if ((err = snd_miro_init(chip, i)) < 0)
  1000. return err;
  1001. err = snd_miro_opti_check(chip);
  1002. if (err == 0)
  1003. return 1;
  1004. }
  1005. return -ENODEV;
  1006. }
  1007. static int snd_card_miro_aci_detect(struct snd_card *card,
  1008. struct snd_miro *miro)
  1009. {
  1010. unsigned char regval;
  1011. int i;
  1012. struct snd_miro_aci *aci = &aci_device;
  1013. miro->aci = aci;
  1014. mutex_init(&aci->aci_mutex);
  1015. /* get ACI port from OPTi9xx MC 4 */
  1016. regval=inb(miro->mc_base + 4);
  1017. aci->aci_port = (regval & 0x10) ? 0x344 : 0x354;
  1018. miro->res_aci_port = request_region(aci->aci_port, 3, "miro aci");
  1019. if (miro->res_aci_port == NULL) {
  1020. snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
  1021. aci->aci_port, aci->aci_port+2);
  1022. return -ENOMEM;
  1023. }
  1024. /* force ACI into a known state */
  1025. for (i = 0; i < 3; i++)
  1026. if (snd_aci_cmd(aci, ACI_ERROR_OP, -1, -1) < 0) {
  1027. snd_printk(KERN_ERR "can't force aci into known state.\n");
  1028. return -ENXIO;
  1029. }
  1030. aci->aci_vendor = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
  1031. aci->aci_product = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
  1032. if (aci->aci_vendor < 0 || aci->aci_product < 0) {
  1033. snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n",
  1034. aci->aci_port);
  1035. return -ENXIO;
  1036. }
  1037. aci->aci_version = snd_aci_cmd(aci, ACI_READ_VERSION, -1, -1);
  1038. if (aci->aci_version < 0) {
  1039. snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
  1040. aci->aci_port);
  1041. return -ENXIO;
  1042. }
  1043. if (snd_aci_cmd(aci, ACI_INIT, -1, -1) < 0 ||
  1044. snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
  1045. snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
  1046. snd_printk(KERN_ERR "can't initialize aci.\n");
  1047. return -ENXIO;
  1048. }
  1049. return 0;
  1050. }
  1051. static void snd_card_miro_free(struct snd_card *card)
  1052. {
  1053. struct snd_miro *miro = card->private_data;
  1054. release_and_free_resource(miro->res_aci_port);
  1055. if (miro->aci)
  1056. miro->aci->aci_port = 0;
  1057. release_and_free_resource(miro->res_mc_base);
  1058. }
  1059. static int snd_miro_probe(struct snd_card *card)
  1060. {
  1061. int error;
  1062. struct snd_miro *miro = card->private_data;
  1063. struct snd_wss *codec;
  1064. struct snd_rawmidi *rmidi;
  1065. if (!miro->res_mc_base) {
  1066. miro->res_mc_base = request_region(miro->mc_base,
  1067. miro->mc_base_size,
  1068. "miro (OPTi9xx MC)");
  1069. if (miro->res_mc_base == NULL) {
  1070. snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
  1071. return -ENOMEM;
  1072. }
  1073. }
  1074. error = snd_card_miro_aci_detect(card, miro);
  1075. if (error < 0) {
  1076. snd_printk(KERN_ERR "unable to detect aci chip\n");
  1077. return -ENODEV;
  1078. }
  1079. miro->wss_base = port;
  1080. miro->mpu_port = mpu_port;
  1081. miro->irq = irq;
  1082. miro->mpu_irq = mpu_irq;
  1083. miro->dma1 = dma1;
  1084. miro->dma2 = dma2;
  1085. /* init proc interface */
  1086. snd_miro_proc_init(card, miro);
  1087. error = snd_miro_configure(miro);
  1088. if (error)
  1089. return error;
  1090. error = snd_wss_create(card, miro->wss_base + 4, -1,
  1091. miro->irq, miro->dma1, miro->dma2,
  1092. WSS_HW_DETECT, 0, &codec);
  1093. if (error < 0)
  1094. return error;
  1095. error = snd_wss_pcm(codec, 0);
  1096. if (error < 0)
  1097. return error;
  1098. error = snd_wss_mixer(codec);
  1099. if (error < 0)
  1100. return error;
  1101. error = snd_wss_timer(codec, 0);
  1102. if (error < 0)
  1103. return error;
  1104. miro->pcm = codec->pcm;
  1105. error = snd_miro_mixer(card, miro);
  1106. if (error < 0)
  1107. return error;
  1108. if (miro->aci->aci_vendor == 'm') {
  1109. /* It looks like a miro sound card. */
  1110. switch (miro->aci->aci_product) {
  1111. case 'A':
  1112. sprintf(card->shortname,
  1113. "miroSOUND PCM1 pro / PCM12");
  1114. break;
  1115. case 'B':
  1116. sprintf(card->shortname,
  1117. "miroSOUND PCM12");
  1118. break;
  1119. case 'C':
  1120. sprintf(card->shortname,
  1121. "miroSOUND PCM20 radio");
  1122. break;
  1123. default:
  1124. sprintf(card->shortname,
  1125. "unknown miro");
  1126. snd_printk(KERN_INFO "unknown miro aci id\n");
  1127. break;
  1128. }
  1129. } else {
  1130. snd_printk(KERN_INFO "found unsupported aci card\n");
  1131. sprintf(card->shortname, "unknown Cardinal Technologies");
  1132. }
  1133. strcpy(card->driver, "miro");
  1134. sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
  1135. card->shortname, miro->name, codec->pcm->name,
  1136. miro->wss_base + 4, miro->irq, miro->dma1, miro->dma2);
  1137. if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
  1138. rmidi = NULL;
  1139. else {
  1140. error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  1141. mpu_port, 0, miro->mpu_irq, &rmidi);
  1142. if (error < 0)
  1143. snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
  1144. mpu_port);
  1145. }
  1146. if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
  1147. struct snd_opl3 *opl3 = NULL;
  1148. struct snd_opl4 *opl4;
  1149. if (snd_opl4_create(card, fm_port, fm_port - 8,
  1150. 2, &opl3, &opl4) < 0)
  1151. snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n",
  1152. fm_port);
  1153. }
  1154. error = snd_set_aci_init_values(miro);
  1155. if (error < 0)
  1156. return error;
  1157. return snd_card_register(card);
  1158. }
  1159. static int snd_miro_isa_match(struct device *devptr, unsigned int n)
  1160. {
  1161. #ifdef CONFIG_PNP
  1162. if (snd_miro_pnp_is_probed)
  1163. return 0;
  1164. if (isapnp)
  1165. return 0;
  1166. #endif
  1167. return 1;
  1168. }
  1169. static int snd_miro_isa_probe(struct device *devptr, unsigned int n)
  1170. {
  1171. static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
  1172. static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
  1173. static int possible_irqs[] = {11, 9, 10, 7, -1};
  1174. static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
  1175. static int possible_dma1s[] = {3, 1, 0, -1};
  1176. static int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1},
  1177. {0, -1} };
  1178. int error;
  1179. struct snd_miro *miro;
  1180. struct snd_card *card;
  1181. error = snd_card_new(devptr, index, id, THIS_MODULE,
  1182. sizeof(struct snd_miro), &card);
  1183. if (error < 0)
  1184. return error;
  1185. card->private_free = snd_card_miro_free;
  1186. miro = card->private_data;
  1187. error = snd_card_miro_detect(card, miro);
  1188. if (error < 0) {
  1189. snd_card_free(card);
  1190. snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
  1191. return -ENODEV;
  1192. }
  1193. if (port == SNDRV_AUTO_PORT) {
  1194. port = snd_legacy_find_free_ioport(possible_ports, 4);
  1195. if (port < 0) {
  1196. snd_card_free(card);
  1197. snd_printk(KERN_ERR "unable to find a free WSS port\n");
  1198. return -EBUSY;
  1199. }
  1200. }
  1201. if (mpu_port == SNDRV_AUTO_PORT) {
  1202. mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
  1203. if (mpu_port < 0) {
  1204. snd_card_free(card);
  1205. snd_printk(KERN_ERR
  1206. "unable to find a free MPU401 port\n");
  1207. return -EBUSY;
  1208. }
  1209. }
  1210. if (irq == SNDRV_AUTO_IRQ) {
  1211. irq = snd_legacy_find_free_irq(possible_irqs);
  1212. if (irq < 0) {
  1213. snd_card_free(card);
  1214. snd_printk(KERN_ERR "unable to find a free IRQ\n");
  1215. return -EBUSY;
  1216. }
  1217. }
  1218. if (mpu_irq == SNDRV_AUTO_IRQ) {
  1219. mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
  1220. if (mpu_irq < 0) {
  1221. snd_card_free(card);
  1222. snd_printk(KERN_ERR
  1223. "unable to find a free MPU401 IRQ\n");
  1224. return -EBUSY;
  1225. }
  1226. }
  1227. if (dma1 == SNDRV_AUTO_DMA) {
  1228. dma1 = snd_legacy_find_free_dma(possible_dma1s);
  1229. if (dma1 < 0) {
  1230. snd_card_free(card);
  1231. snd_printk(KERN_ERR "unable to find a free DMA1\n");
  1232. return -EBUSY;
  1233. }
  1234. }
  1235. if (dma2 == SNDRV_AUTO_DMA) {
  1236. dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
  1237. if (dma2 < 0) {
  1238. snd_card_free(card);
  1239. snd_printk(KERN_ERR "unable to find a free DMA2\n");
  1240. return -EBUSY;
  1241. }
  1242. }
  1243. error = snd_miro_probe(card);
  1244. if (error < 0) {
  1245. snd_card_free(card);
  1246. return error;
  1247. }
  1248. dev_set_drvdata(devptr, card);
  1249. return 0;
  1250. }
  1251. static int snd_miro_isa_remove(struct device *devptr,
  1252. unsigned int dev)
  1253. {
  1254. snd_card_free(dev_get_drvdata(devptr));
  1255. return 0;
  1256. }
  1257. #define DEV_NAME "miro"
  1258. static struct isa_driver snd_miro_driver = {
  1259. .match = snd_miro_isa_match,
  1260. .probe = snd_miro_isa_probe,
  1261. .remove = snd_miro_isa_remove,
  1262. /* FIXME: suspend/resume */
  1263. .driver = {
  1264. .name = DEV_NAME
  1265. },
  1266. };
  1267. #ifdef CONFIG_PNP
  1268. static int snd_card_miro_pnp(struct snd_miro *chip,
  1269. struct pnp_card_link *card,
  1270. const struct pnp_card_device_id *pid)
  1271. {
  1272. struct pnp_dev *pdev;
  1273. int err;
  1274. struct pnp_dev *devmpu;
  1275. struct pnp_dev *devmc;
  1276. pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
  1277. if (pdev == NULL)
  1278. return -EBUSY;
  1279. devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
  1280. if (devmpu == NULL)
  1281. return -EBUSY;
  1282. devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
  1283. if (devmc == NULL)
  1284. return -EBUSY;
  1285. err = pnp_activate_dev(pdev);
  1286. if (err < 0) {
  1287. snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
  1288. return err;
  1289. }
  1290. err = pnp_activate_dev(devmc);
  1291. if (err < 0) {
  1292. snd_printk(KERN_ERR "MC pnp configure failure: %d\n",
  1293. err);
  1294. return err;
  1295. }
  1296. port = pnp_port_start(pdev, 1);
  1297. fm_port = pnp_port_start(pdev, 2) + 8;
  1298. /*
  1299. * The MC(0) is never accessed and the miroSOUND PCM20 card does not
  1300. * include it in the PnP resource range. OPTI93x include it.
  1301. */
  1302. chip->mc_base = pnp_port_start(devmc, 0) - 1;
  1303. chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
  1304. irq = pnp_irq(pdev, 0);
  1305. dma1 = pnp_dma(pdev, 0);
  1306. dma2 = pnp_dma(pdev, 1);
  1307. if (mpu_port > 0) {
  1308. err = pnp_activate_dev(devmpu);
  1309. if (err < 0) {
  1310. snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
  1311. mpu_port = -1;
  1312. return err;
  1313. }
  1314. mpu_port = pnp_port_start(devmpu, 0);
  1315. mpu_irq = pnp_irq(devmpu, 0);
  1316. }
  1317. return 0;
  1318. }
  1319. static int snd_miro_pnp_probe(struct pnp_card_link *pcard,
  1320. const struct pnp_card_device_id *pid)
  1321. {
  1322. struct snd_card *card;
  1323. int err;
  1324. struct snd_miro *miro;
  1325. if (snd_miro_pnp_is_probed)
  1326. return -EBUSY;
  1327. if (!isapnp)
  1328. return -ENODEV;
  1329. err = snd_card_new(&pcard->card->dev, index, id, THIS_MODULE,
  1330. sizeof(struct snd_miro), &card);
  1331. if (err < 0)
  1332. return err;
  1333. card->private_free = snd_card_miro_free;
  1334. miro = card->private_data;
  1335. err = snd_card_miro_pnp(miro, pcard, pid);
  1336. if (err) {
  1337. snd_card_free(card);
  1338. return err;
  1339. }
  1340. /* only miroSOUND PCM20 and PCM12 == OPTi924 */
  1341. err = snd_miro_init(miro, OPTi9XX_HW_82C924);
  1342. if (err) {
  1343. snd_card_free(card);
  1344. return err;
  1345. }
  1346. err = snd_miro_opti_check(miro);
  1347. if (err) {
  1348. snd_printk(KERN_ERR "OPTI chip not found\n");
  1349. snd_card_free(card);
  1350. return err;
  1351. }
  1352. err = snd_miro_probe(card);
  1353. if (err < 0) {
  1354. snd_card_free(card);
  1355. return err;
  1356. }
  1357. pnp_set_card_drvdata(pcard, card);
  1358. snd_miro_pnp_is_probed = 1;
  1359. return 0;
  1360. }
  1361. static void snd_miro_pnp_remove(struct pnp_card_link *pcard)
  1362. {
  1363. snd_card_free(pnp_get_card_drvdata(pcard));
  1364. pnp_set_card_drvdata(pcard, NULL);
  1365. snd_miro_pnp_is_probed = 0;
  1366. }
  1367. static struct pnp_card_driver miro_pnpc_driver = {
  1368. .flags = PNP_DRIVER_RES_DISABLE,
  1369. .name = "miro",
  1370. .id_table = snd_miro_pnpids,
  1371. .probe = snd_miro_pnp_probe,
  1372. .remove = snd_miro_pnp_remove,
  1373. };
  1374. #endif
  1375. static int __init alsa_card_miro_init(void)
  1376. {
  1377. #ifdef CONFIG_PNP
  1378. pnp_register_card_driver(&miro_pnpc_driver);
  1379. if (snd_miro_pnp_is_probed)
  1380. return 0;
  1381. pnp_unregister_card_driver(&miro_pnpc_driver);
  1382. #endif
  1383. return isa_register_driver(&snd_miro_driver, 1);
  1384. }
  1385. static void __exit alsa_card_miro_exit(void)
  1386. {
  1387. if (!snd_miro_pnp_is_probed) {
  1388. isa_unregister_driver(&snd_miro_driver);
  1389. return;
  1390. }
  1391. #ifdef CONFIG_PNP
  1392. pnp_unregister_card_driver(&miro_pnpc_driver);
  1393. #endif
  1394. }
  1395. module_init(alsa_card_miro_init)
  1396. module_exit(alsa_card_miro_exit)