aci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Audio Command Interface (ACI) driver (sound/aci.c)
  3. *
  4. * ACI is a protocol used to communicate with the microcontroller on
  5. * some sound cards produced by miro, e.g. the miroSOUND PCM12 and
  6. * PCM20. The ACI has been developed for miro by Norberto Pellicci
  7. * <pellicci@home.com>. Special thanks to both him and miro for
  8. * providing the ACI specification.
  9. *
  10. * The main function of the ACI is to control the mixer and to get a
  11. * product identification. On the PCM20, ACI also controls the radio
  12. * tuner on this card, this is supported in the Video for Linux
  13. * miropcm20 driver.
  14. * -
  15. * This is a fullfeatured implementation. Unsupported features
  16. * are bugs... (:
  17. *
  18. * It is not longer necessary to load the mad16 module first. The
  19. * user is currently responsible to set the mad16 mixer correctly.
  20. *
  21. * To toggle the solo mode for full duplex operation just use the OSS
  22. * record switch for the pcm ('wave') controller. Robert
  23. * -
  24. *
  25. * Revision history:
  26. *
  27. * 1995-11-10 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
  28. * First version written.
  29. * 1995-12-31 Markus Kuhn
  30. * Second revision, general code cleanup.
  31. * 1996-05-16 Hannu Savolainen
  32. * Integrated with other parts of the driver.
  33. * 1996-05-28 Markus Kuhn
  34. * Initialize CS4231A mixer, make ACI first mixer,
  35. * use new private mixer API for solo mode.
  36. * 1998-08-18 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
  37. * Small modification to export ACI functions and
  38. * complete modularisation.
  39. * 2000-06-20 Robert Siemer <Robert.Siemer@gmx.de>
  40. * Don't initialize the CS4231A mixer anymore, so the code is
  41. * working again, and other small changes to fit in todays
  42. * kernels.
  43. * 2000-08-26 Robert Siemer
  44. * Clean up and rewrite for 2.4.x. Maybe it's SMP safe now... (:
  45. * ioctl bugfix, and integration of solo-mode into OSS-API,
  46. * added (OSS-limited) equalizer support, return value bugfix,
  47. * changed param aci_reset to reset, new params: ide, wss.
  48. * 2001-04-20 Robert Siemer
  49. * even more cleanups...
  50. * 2001-10-08 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  51. * Get rid of check_region, .bss optimizations, use set_current_state
  52. */
  53. #include <linux/kernel.h>
  54. #include <linux/init.h>
  55. #include <linux/module.h>
  56. #include <linux/proc_fs.h>
  57. #include <linux/slab.h>
  58. #include <linux/mutex.h>
  59. #include <asm/io.h>
  60. #include <asm/uaccess.h>
  61. #include "sound_config.h"
  62. int aci_port; /* as determined by bit 4 in the OPTi 929 MC4 register */
  63. static int aci_idcode[2]; /* manufacturer and product ID */
  64. int aci_version; /* ACI firmware version */
  65. EXPORT_SYMBOL(aci_port);
  66. EXPORT_SYMBOL(aci_version);
  67. #include "aci.h"
  68. static int aci_solo; /* status bit of the card that can't be *
  69. * checked with ACI versions prior to 0xb0 */
  70. static int aci_amp; /* status bit for power-amp/line-out level
  71. but I have no docs about what is what... */
  72. static int aci_micpreamp=3; /* microphone preamp-level that can't be *
  73. * checked with ACI versions prior to 0xb0 */
  74. static int mixer_device;
  75. static struct mutex aci_mutex;
  76. #ifdef MODULE
  77. static int reset;
  78. module_param(reset, bool, 0);
  79. MODULE_PARM_DESC(reset,"When set to 1, reset aci mixer.");
  80. #else
  81. static int reset = 1;
  82. #endif
  83. static int ide=-1;
  84. module_param(ide, int, 0);
  85. MODULE_PARM_DESC(ide,"1 enable, 0 disable ide-port - untested"
  86. " default: do nothing");
  87. static int wss=-1;
  88. module_param(wss, int, 0);
  89. MODULE_PARM_DESC(wss,"change between ACI/WSS-mixer; use 0 and 1 - untested"
  90. " default: do nothing; for PCM1-pro only");
  91. #ifdef DEBUG
  92. static void print_bits(unsigned char c)
  93. {
  94. int j;
  95. printk(KERN_DEBUG "aci: ");
  96. for (j=7; j>=0; j--) {
  97. printk("%d", (c >> j) & 0x1);
  98. }
  99. printk("\n");
  100. }
  101. #endif
  102. /*
  103. * This busy wait code normally requires less than 15 loops and
  104. * practically always less than 100 loops on my i486/DX2 66 MHz.
  105. *
  106. * Warning: Waiting on the general status flag after reseting the MUTE
  107. * function can take a VERY long time, because the PCM12 does some kind
  108. * of fade-in effect. For this reason, access to the MUTE function has
  109. * not been implemented at all.
  110. *
  111. * - The OSS interface has no mute option. It takes about 3 seconds to
  112. * fade-in on my PCM20. busy_wait() handles it great now... Robert
  113. */
  114. static int busy_wait(void)
  115. {
  116. #define MINTIME 500
  117. long timeout;
  118. unsigned char byte;
  119. for (timeout = 1; timeout <= MINTIME+30; timeout++) {
  120. if (((byte=inb(BUSY_REGISTER)) & 1) == 0) {
  121. if (timeout >= MINTIME)
  122. printk(KERN_DEBUG "aci: Got READYFLAG in round %ld.\n", timeout-MINTIME);
  123. return byte;
  124. }
  125. if (timeout >= MINTIME) {
  126. long out=10*HZ;
  127. switch (timeout-MINTIME) {
  128. case 0 ... 9:
  129. out /= 10;
  130. case 10 ... 19:
  131. out /= 10;
  132. case 20 ... 30:
  133. out /= 10;
  134. default:
  135. set_current_state(TASK_UNINTERRUPTIBLE);
  136. schedule_timeout(out);
  137. break;
  138. }
  139. }
  140. }
  141. printk(KERN_WARNING "aci: busy_wait() time out.\n");
  142. return -EBUSY;
  143. }
  144. /* The four ACI command types are fucked up. [-:
  145. * implied is: 1w - special case for INIT
  146. * write is: 2w1r
  147. * read is: x(1w1r) where x is 1 or 2 (1 CHECK_SIG, 1 CHECK_STER,
  148. * 1 VERSION, 2 IDCODE)
  149. * the command is only in the first write, rest is protocol overhead
  150. *
  151. * indexed is technically a write and used for STATUS
  152. * and the special case for TUNE is: 3w1r
  153. *
  154. * Here the new general sheme: TUNE --> aci_rw_cmd(x, y, z)
  155. * indexed and write --> aci_rw_cmd(x, y, -1)
  156. * implied and read (x=1) --> aci_rw_cmd(x, -1, -1)
  157. *
  158. * Read (x>=2) is not implemented (only used during initialization).
  159. * Use aci_idcode[2] and aci_version... Robert
  160. */
  161. /* Some notes for error detection: theoretically it is possible.
  162. * But it doubles the I/O-traffic from ww(r) to wwwrw(r) in the normal
  163. * case and doesn't seem to be designed for that... Robert
  164. */
  165. static inline int aci_rawwrite(unsigned char byte)
  166. {
  167. if (busy_wait() >= 0) {
  168. #ifdef DEBUG
  169. printk(KERN_DEBUG "aci_rawwrite(%d)\n", byte);
  170. #endif
  171. outb(byte, COMMAND_REGISTER);
  172. return 0;
  173. } else
  174. return -EBUSY;
  175. }
  176. static inline int aci_rawread(void)
  177. {
  178. unsigned char byte;
  179. if (busy_wait() >= 0) {
  180. byte=inb(STATUS_REGISTER);
  181. #ifdef DEBUG
  182. printk(KERN_DEBUG "%d = aci_rawread()\n", byte);
  183. #endif
  184. return byte;
  185. } else
  186. return -EBUSY;
  187. }
  188. int aci_rw_cmd(int write1, int write2, int write3)
  189. {
  190. int write[] = {write1, write2, write3};
  191. int read = -EINTR, i;
  192. if (mutex_lock_interruptible(&aci_mutex))
  193. goto out;
  194. for (i=0; i<3; i++) {
  195. if (write[i]< 0 || write[i] > 255)
  196. break;
  197. else {
  198. read = aci_rawwrite(write[i]);
  199. if (read < 0)
  200. goto out_up;
  201. }
  202. }
  203. read = aci_rawread();
  204. out_up: mutex_unlock(&aci_mutex);
  205. out: return read;
  206. }
  207. EXPORT_SYMBOL(aci_rw_cmd);
  208. static int setvolume(int __user *arg,
  209. unsigned char left_index, unsigned char right_index)
  210. {
  211. int vol, ret, uservol, buf;
  212. __get_user(uservol, arg);
  213. /* left channel */
  214. vol = uservol & 0xff;
  215. if (vol > 100)
  216. vol = 100;
  217. vol = SCALE(100, 0x20, vol);
  218. if ((buf=aci_write_cmd(left_index, 0x20 - vol))<0)
  219. return buf;
  220. ret = SCALE(0x20, 100, vol);
  221. /* right channel */
  222. vol = (uservol >> 8) & 0xff;
  223. if (vol > 100)
  224. vol = 100;
  225. vol = SCALE(100, 0x20, vol);
  226. if ((buf=aci_write_cmd(right_index, 0x20 - vol))<0)
  227. return buf;
  228. ret |= SCALE(0x20, 100, vol) << 8;
  229. __put_user(ret, arg);
  230. return 0;
  231. }
  232. static int getvolume(int __user *arg,
  233. unsigned char left_index, unsigned char right_index)
  234. {
  235. int vol;
  236. int buf;
  237. /* left channel */
  238. if ((buf=aci_indexed_cmd(ACI_STATUS, left_index))<0)
  239. return buf;
  240. vol = SCALE(0x20, 100, buf < 0x20 ? 0x20-buf : 0);
  241. /* right channel */
  242. if ((buf=aci_indexed_cmd(ACI_STATUS, right_index))<0)
  243. return buf;
  244. vol |= SCALE(0x20, 100, buf < 0x20 ? 0x20-buf : 0) << 8;
  245. __put_user(vol, arg);
  246. return 0;
  247. }
  248. /* The equalizer is somewhat strange on the ACI. From -12dB to +12dB
  249. * write: 0xff..down.to..0x80==0x00..up.to..0x7f
  250. */
  251. static inline unsigned int eq_oss2aci(unsigned int vol)
  252. {
  253. int boost=0;
  254. unsigned int ret;
  255. if (vol > 100)
  256. vol = 100;
  257. if (vol > 50) {
  258. vol -= 51;
  259. boost=1;
  260. }
  261. if (boost)
  262. ret=SCALE(49, 0x7e, vol)+1;
  263. else
  264. ret=0xff - SCALE(50, 0x7f, vol);
  265. return ret;
  266. }
  267. static inline unsigned int eq_aci2oss(unsigned int vol)
  268. {
  269. if (vol < 0x80)
  270. return SCALE(0x7f, 50, vol) + 50;
  271. else
  272. return SCALE(0x7f, 50, 0xff-vol);
  273. }
  274. static int setequalizer(int __user *arg,
  275. unsigned char left_index, unsigned char right_index)
  276. {
  277. int buf;
  278. unsigned int vol;
  279. __get_user(vol, arg);
  280. /* left channel */
  281. if ((buf=aci_write_cmd(left_index, eq_oss2aci(vol & 0xff)))<0)
  282. return buf;
  283. /* right channel */
  284. if ((buf=aci_write_cmd(right_index, eq_oss2aci((vol>>8) & 0xff)))<0)
  285. return buf;
  286. /* the ACI equalizer is more precise */
  287. return 0;
  288. }
  289. static int getequalizer(int __user *arg,
  290. unsigned char left_index, unsigned char right_index)
  291. {
  292. int buf;
  293. unsigned int vol;
  294. /* left channel */
  295. if ((buf=aci_indexed_cmd(ACI_STATUS, left_index))<0)
  296. return buf;
  297. vol = eq_aci2oss(buf);
  298. /* right channel */
  299. if ((buf=aci_indexed_cmd(ACI_STATUS, right_index))<0)
  300. return buf;
  301. vol |= eq_aci2oss(buf) << 8;
  302. __put_user(vol, arg);
  303. return 0;
  304. }
  305. static int aci_mixer_ioctl (int dev, unsigned int cmd, void __user * arg)
  306. {
  307. int vol, buf;
  308. int __user *p = arg;
  309. switch (cmd) {
  310. case SOUND_MIXER_WRITE_VOLUME:
  311. return setvolume(p, 0x01, 0x00);
  312. case SOUND_MIXER_WRITE_CD:
  313. return setvolume(p, 0x3c, 0x34);
  314. case SOUND_MIXER_WRITE_MIC:
  315. return setvolume(p, 0x38, 0x30);
  316. case SOUND_MIXER_WRITE_LINE:
  317. return setvolume(p, 0x39, 0x31);
  318. case SOUND_MIXER_WRITE_SYNTH:
  319. return setvolume(p, 0x3b, 0x33);
  320. case SOUND_MIXER_WRITE_PCM:
  321. return setvolume(p, 0x3a, 0x32);
  322. case MIXER_WRITE(SOUND_MIXER_RADIO): /* fall through */
  323. case SOUND_MIXER_WRITE_LINE1: /* AUX1 or radio */
  324. return setvolume(p, 0x3d, 0x35);
  325. case SOUND_MIXER_WRITE_LINE2: /* AUX2 */
  326. return setvolume(p, 0x3e, 0x36);
  327. case SOUND_MIXER_WRITE_BASS: /* set band one and two */
  328. if (aci_idcode[1]=='C') {
  329. if ((buf=setequalizer(p, 0x48, 0x40)) ||
  330. (buf=setequalizer(p, 0x49, 0x41)));
  331. return buf;
  332. }
  333. break;
  334. case SOUND_MIXER_WRITE_TREBLE: /* set band six and seven */
  335. if (aci_idcode[1]=='C') {
  336. if ((buf=setequalizer(p, 0x4d, 0x45)) ||
  337. (buf=setequalizer(p, 0x4e, 0x46)));
  338. return buf;
  339. }
  340. break;
  341. case SOUND_MIXER_WRITE_IGAIN: /* MIC pre-amp */
  342. if (aci_idcode[1]=='B' || aci_idcode[1]=='C') {
  343. __get_user(vol, p);
  344. vol = vol & 0xff;
  345. if (vol > 100)
  346. vol = 100;
  347. vol = SCALE(100, 3, vol);
  348. if ((buf=aci_write_cmd(ACI_WRITE_IGAIN, vol))<0)
  349. return buf;
  350. aci_micpreamp = vol;
  351. vol = SCALE(3, 100, vol);
  352. vol |= (vol << 8);
  353. __put_user(vol, p);
  354. return 0;
  355. }
  356. break;
  357. case SOUND_MIXER_WRITE_OGAIN: /* Power-amp/line-out level */
  358. if (aci_idcode[1]=='A' || aci_idcode[1]=='B') {
  359. __get_user(buf, p);
  360. buf = buf & 0xff;
  361. if (buf > 50)
  362. vol = 1;
  363. else
  364. vol = 0;
  365. if ((buf=aci_write_cmd(ACI_SET_POWERAMP, vol))<0)
  366. return buf;
  367. aci_amp = vol;
  368. if (aci_amp)
  369. buf = (100 || 100<<8);
  370. else
  371. buf = 0;
  372. __put_user(buf, p);
  373. return 0;
  374. }
  375. break;
  376. case SOUND_MIXER_WRITE_RECSRC:
  377. /* handle solo mode control */
  378. __get_user(buf, p);
  379. /* unset solo when RECSRC for PCM is requested */
  380. if (aci_idcode[1]=='B' || aci_idcode[1]=='C') {
  381. vol = !(buf & SOUND_MASK_PCM);
  382. if ((buf=aci_write_cmd(ACI_SET_SOLOMODE, vol))<0)
  383. return buf;
  384. aci_solo = vol;
  385. }
  386. buf = (SOUND_MASK_CD| SOUND_MASK_MIC| SOUND_MASK_LINE|
  387. SOUND_MASK_SYNTH| SOUND_MASK_LINE2);
  388. if (aci_idcode[1] == 'C') /* PCM20 radio */
  389. buf |= SOUND_MASK_RADIO;
  390. else
  391. buf |= SOUND_MASK_LINE1;
  392. if (!aci_solo)
  393. buf |= SOUND_MASK_PCM;
  394. __put_user(buf, p);
  395. return 0;
  396. case SOUND_MIXER_READ_DEVMASK:
  397. buf = (SOUND_MASK_VOLUME | SOUND_MASK_CD |
  398. SOUND_MASK_MIC | SOUND_MASK_LINE |
  399. SOUND_MASK_SYNTH | SOUND_MASK_PCM |
  400. SOUND_MASK_LINE2);
  401. switch (aci_idcode[1]) {
  402. case 'C': /* PCM20 radio */
  403. buf |= (SOUND_MASK_RADIO | SOUND_MASK_IGAIN |
  404. SOUND_MASK_BASS | SOUND_MASK_TREBLE);
  405. break;
  406. case 'B': /* PCM12 */
  407. buf |= (SOUND_MASK_LINE1 | SOUND_MASK_IGAIN |
  408. SOUND_MASK_OGAIN);
  409. break;
  410. case 'A': /* PCM1-pro */
  411. buf |= (SOUND_MASK_LINE1 | SOUND_MASK_OGAIN);
  412. break;
  413. default:
  414. buf |= SOUND_MASK_LINE1;
  415. }
  416. __put_user(buf, p);
  417. return 0;
  418. case SOUND_MIXER_READ_STEREODEVS:
  419. buf = (SOUND_MASK_VOLUME | SOUND_MASK_CD |
  420. SOUND_MASK_MIC | SOUND_MASK_LINE |
  421. SOUND_MASK_SYNTH | SOUND_MASK_PCM |
  422. SOUND_MASK_LINE2);
  423. switch (aci_idcode[1]) {
  424. case 'C': /* PCM20 radio */
  425. buf |= (SOUND_MASK_RADIO |
  426. SOUND_MASK_BASS | SOUND_MASK_TREBLE);
  427. break;
  428. default:
  429. buf |= SOUND_MASK_LINE1;
  430. }
  431. __put_user(buf, p);
  432. return 0;
  433. case SOUND_MIXER_READ_RECMASK:
  434. buf = (SOUND_MASK_CD| SOUND_MASK_MIC| SOUND_MASK_LINE|
  435. SOUND_MASK_SYNTH| SOUND_MASK_LINE2| SOUND_MASK_PCM);
  436. if (aci_idcode[1] == 'C') /* PCM20 radio */
  437. buf |= SOUND_MASK_RADIO;
  438. else
  439. buf |= SOUND_MASK_LINE1;
  440. __put_user(buf, p);
  441. return 0;
  442. case SOUND_MIXER_READ_RECSRC:
  443. buf = (SOUND_MASK_CD | SOUND_MASK_MIC | SOUND_MASK_LINE |
  444. SOUND_MASK_SYNTH | SOUND_MASK_LINE2);
  445. /* do we need aci_solo or can I get it from the ACI? */
  446. switch (aci_idcode[1]) {
  447. case 'B': /* PCM12 */
  448. case 'C': /* PCM20 radio */
  449. if (aci_version >= 0xb0) {
  450. if ((vol=aci_rw_cmd(ACI_STATUS,
  451. ACI_S_GENERAL, -1))<0)
  452. return vol;
  453. if (vol & 0x20)
  454. buf |= SOUND_MASK_PCM;
  455. }
  456. else
  457. if (!aci_solo)
  458. buf |= SOUND_MASK_PCM;
  459. break;
  460. default:
  461. buf |= SOUND_MASK_PCM;
  462. }
  463. if (aci_idcode[1] == 'C') /* PCM20 radio */
  464. buf |= SOUND_MASK_RADIO;
  465. else
  466. buf |= SOUND_MASK_LINE1;
  467. __put_user(buf, p);
  468. return 0;
  469. case SOUND_MIXER_READ_CAPS:
  470. __put_user(0, p);
  471. return 0;
  472. case SOUND_MIXER_READ_VOLUME:
  473. return getvolume(p, 0x04, 0x03);
  474. case SOUND_MIXER_READ_CD:
  475. return getvolume(p, 0x0a, 0x09);
  476. case SOUND_MIXER_READ_MIC:
  477. return getvolume(p, 0x06, 0x05);
  478. case SOUND_MIXER_READ_LINE:
  479. return getvolume(p, 0x08, 0x07);
  480. case SOUND_MIXER_READ_SYNTH:
  481. return getvolume(p, 0x0c, 0x0b);
  482. case SOUND_MIXER_READ_PCM:
  483. return getvolume(p, 0x0e, 0x0d);
  484. case MIXER_READ(SOUND_MIXER_RADIO): /* fall through */
  485. case SOUND_MIXER_READ_LINE1: /* AUX1 */
  486. return getvolume(p, 0x11, 0x10);
  487. case SOUND_MIXER_READ_LINE2: /* AUX2 */
  488. return getvolume(p, 0x13, 0x12);
  489. case SOUND_MIXER_READ_BASS: /* get band one */
  490. if (aci_idcode[1]=='C') {
  491. return getequalizer(p, 0x23, 0x22);
  492. }
  493. break;
  494. case SOUND_MIXER_READ_TREBLE: /* get band seven */
  495. if (aci_idcode[1]=='C') {
  496. return getequalizer(p, 0x2f, 0x2e);
  497. }
  498. break;
  499. case SOUND_MIXER_READ_IGAIN: /* MIC pre-amp */
  500. if (aci_idcode[1]=='B' || aci_idcode[1]=='C') {
  501. /* aci_micpreamp or ACI? */
  502. if (aci_version >= 0xb0) {
  503. if ((buf=aci_indexed_cmd(ACI_STATUS,
  504. ACI_S_READ_IGAIN))<0)
  505. return buf;
  506. }
  507. else
  508. buf=aci_micpreamp;
  509. vol = SCALE(3, 100, buf <= 3 ? buf : 3);
  510. vol |= vol << 8;
  511. __put_user(vol, p);
  512. return 0;
  513. }
  514. break;
  515. case SOUND_MIXER_READ_OGAIN:
  516. if (aci_amp)
  517. buf = (100 || 100<<8);
  518. else
  519. buf = 0;
  520. __put_user(buf, p);
  521. return 0;
  522. }
  523. return -EINVAL;
  524. }
  525. static struct mixer_operations aci_mixer_operations =
  526. {
  527. .owner = THIS_MODULE,
  528. .id = "ACI",
  529. .ioctl = aci_mixer_ioctl
  530. };
  531. /*
  532. * There is also an internal mixer in the codec (CS4231A or AD1845),
  533. * that deserves no purpose in an ACI based system which uses an
  534. * external ACI controlled stereo mixer. Make sure that this codec
  535. * mixer has the AUX1 input selected as the recording source, that the
  536. * input gain is set near maximum and that the other channels going
  537. * from the inputs to the codec output are muted.
  538. */
  539. static int __init attach_aci(void)
  540. {
  541. char *boardname;
  542. int i, rc = -EBUSY;
  543. mutex_init(&aci_mutex);
  544. outb(0xE3, 0xf8f); /* Write MAD16 password */
  545. aci_port = (inb(0xf90) & 0x10) ?
  546. 0x344: 0x354; /* Get aci_port from MC4_PORT */
  547. if (!request_region(aci_port, 3, "sound mixer (ACI)")) {
  548. printk(KERN_NOTICE
  549. "aci: I/O area 0x%03x-0x%03x already used.\n",
  550. aci_port, aci_port+2);
  551. goto out;
  552. }
  553. /* force ACI into a known state */
  554. rc = -EFAULT;
  555. for (i=0; i<3; i++)
  556. if (aci_rw_cmd(ACI_ERROR_OP, -1, -1)<0)
  557. goto out_release_region;
  558. /* official this is one aci read call: */
  559. rc = -EFAULT;
  560. if ((aci_idcode[0]=aci_rw_cmd(ACI_READ_IDCODE, -1, -1))<0 ||
  561. (aci_idcode[1]=aci_rw_cmd(ACI_READ_IDCODE, -1, -1))<0) {
  562. printk(KERN_ERR "aci: Failed to read idcode on 0x%03x.\n",
  563. aci_port);
  564. goto out_release_region;
  565. }
  566. if ((aci_version=aci_rw_cmd(ACI_READ_VERSION, -1, -1))<0) {
  567. printk(KERN_ERR "aci: Failed to read version on 0x%03x.\n",
  568. aci_port);
  569. goto out_release_region;
  570. }
  571. if (aci_idcode[0] == 'm') {
  572. /* It looks like a miro sound card. */
  573. switch (aci_idcode[1]) {
  574. case 'A':
  575. boardname = "PCM1 pro / early PCM12";
  576. break;
  577. case 'B':
  578. boardname = "PCM12";
  579. break;
  580. case 'C':
  581. boardname = "PCM20 radio";
  582. break;
  583. default:
  584. boardname = "unknown miro";
  585. }
  586. } else {
  587. printk(KERN_WARNING "aci: Warning: unsupported card! - "
  588. "no hardware, no specs...\n");
  589. boardname = "unknown Cardinal Technologies";
  590. }
  591. printk(KERN_INFO "<ACI 0x%02x, id %02x/%02x \"%c/%c\", (%s)> at 0x%03x\n",
  592. aci_version,
  593. aci_idcode[0], aci_idcode[1],
  594. aci_idcode[0], aci_idcode[1],
  595. boardname, aci_port);
  596. rc = -EBUSY;
  597. if (reset) {
  598. /* first write()s after reset fail with my PCM20 */
  599. if (aci_rw_cmd(ACI_INIT, -1, -1)<0 ||
  600. aci_rw_cmd(ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP)<0 ||
  601. aci_rw_cmd(ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP)<0)
  602. goto out_release_region;
  603. }
  604. /* the PCM20 is muted after reset (and reboot) */
  605. if (aci_rw_cmd(ACI_SET_MUTE, 0x00, -1)<0)
  606. goto out_release_region;
  607. if (ide>=0)
  608. if (aci_rw_cmd(ACI_SET_IDE, !ide, -1)<0)
  609. goto out_release_region;
  610. if (wss>=0 && aci_idcode[1]=='A')
  611. if (aci_rw_cmd(ACI_SET_WSS, !!wss, -1)<0)
  612. goto out_release_region;
  613. mixer_device = sound_install_mixer(MIXER_DRIVER_VERSION, boardname,
  614. &aci_mixer_operations,
  615. sizeof(aci_mixer_operations), NULL);
  616. rc = 0;
  617. if (mixer_device < 0) {
  618. printk(KERN_ERR "aci: Failed to install mixer.\n");
  619. rc = mixer_device;
  620. goto out_release_region;
  621. } /* else Maybe initialize the CS4231A mixer here... */
  622. out: return rc;
  623. out_release_region:
  624. release_region(aci_port, 3);
  625. goto out;
  626. }
  627. static void __exit unload_aci(void)
  628. {
  629. sound_unload_mixerdev(mixer_device);
  630. release_region(aci_port, 3);
  631. }
  632. module_init(attach_aci);
  633. module_exit(unload_aci);
  634. MODULE_LICENSE("GPL");