ad1816.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. /*
  2. *
  3. * AD1816 lowlevel sound driver for Linux 2.6.0 and above
  4. *
  5. * Copyright (C) 1998-2003 by Thorsten Knabe <linux@thorsten-knabe.de>
  6. *
  7. * Based on the CS4232/AD1848 driver Copyright (C) by Hannu Savolainen 1993-1996
  8. *
  9. *
  10. * version: 1.5
  11. * status: beta
  12. * date: 2003/07/15
  13. *
  14. * Changes:
  15. * Oleg Drokin: Some cleanup of load/unload functions. 1998/11/24
  16. *
  17. * Thorsten Knabe: attach and unload rewritten,
  18. * some argument checks added 1998/11/30
  19. *
  20. * Thorsten Knabe: Buggy isa bridge workaround added 1999/01/16
  21. *
  22. * David Moews/Thorsten Knabe: Introduced options
  23. * parameter. Added slightly modified patch from
  24. * David Moews to disable dsp audio sources by setting
  25. * bit 0 of options parameter. This seems to be
  26. * required by some Aztech/Newcom SC-16 cards. 1999/04/18
  27. *
  28. * Christoph Hellwig: Adapted to module_init/module_exit. 2000/03/03
  29. *
  30. * Christoph Hellwig: Added isapnp support 2000/03/15
  31. *
  32. * Arnaldo Carvalho de Melo: get rid of check_region 2001/10/07
  33. *
  34. * Thorsten Knabe: Compiling with CONFIG_PNP enabled
  35. * works again. It is now possible to use more than one
  36. * AD1816 sound card. Sample rate now may be changed during
  37. * playback/capture. printk() uses log levels everywhere.
  38. * SMP fixes. DMA handling fixes.
  39. * Other minor code cleanup. 2003/07/15
  40. *
  41. */
  42. #include <linux/config.h>
  43. #include <linux/module.h>
  44. #include <linux/init.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/isapnp.h>
  47. #include <linux/stddef.h>
  48. #include <linux/spinlock.h>
  49. #include "sound_config.h"
  50. #define DEBUGNOISE(x)
  51. #define CHECK_FOR_POWER { int timeout=100; \
  52. while (timeout > 0 && (inb(devc->base)&0x80)!= 0x80) {\
  53. timeout--; \
  54. } \
  55. if (timeout==0) {\
  56. printk(KERN_WARNING "ad1816: Check for power failed in %s line: %d\n",__FILE__,__LINE__); \
  57. } \
  58. }
  59. /* structure to hold device specific information */
  60. typedef struct
  61. {
  62. int base; /* set in attach */
  63. int irq;
  64. int dma_playback;
  65. int dma_capture;
  66. int opened; /* open */
  67. int speed;
  68. int channels;
  69. int audio_format;
  70. int audio_mode;
  71. int recmask; /* setup */
  72. unsigned char format_bits;
  73. int supported_devices;
  74. int supported_rec_devices;
  75. unsigned short levels[SOUND_MIXER_NRDEVICES];
  76. /* misc */
  77. struct pnp_dev *pnpdev; /* configured via pnp */
  78. int dev_no; /* this is the # in audio_devs and NOT
  79. in ad1816_info */
  80. spinlock_t lock;
  81. } ad1816_info;
  82. static int nr_ad1816_devs;
  83. static int ad1816_clockfreq = 33000;
  84. static int options;
  85. /* supported audio formats */
  86. static int ad_format_mask =
  87. AFMT_U8 | AFMT_S16_LE | AFMT_S16_BE | AFMT_MU_LAW | AFMT_A_LAW;
  88. /* array of device info structures */
  89. static ad1816_info dev_info[MAX_AUDIO_DEV];
  90. /* ------------------------------------------------------------------- */
  91. /* functions for easier access to inderect registers */
  92. static int ad_read (ad1816_info * devc, int reg)
  93. {
  94. int result;
  95. CHECK_FOR_POWER;
  96. outb ((unsigned char) (reg & 0x3f), devc->base+0);
  97. result = inb(devc->base+2);
  98. result+= inb(devc->base+3)<<8;
  99. return (result);
  100. }
  101. static void ad_write (ad1816_info * devc, int reg, int data)
  102. {
  103. CHECK_FOR_POWER;
  104. outb ((unsigned char) (reg & 0xff), devc->base+0);
  105. outb ((unsigned char) (data & 0xff),devc->base+2);
  106. outb ((unsigned char) ((data>>8)&0xff),devc->base+3);
  107. }
  108. /* ------------------------------------------------------------------- */
  109. /* function interface required by struct audio_driver */
  110. static void ad1816_halt_input (int dev)
  111. {
  112. unsigned long flags;
  113. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  114. unsigned char buffer;
  115. DEBUGNOISE(printk(KERN_DEBUG "ad1816: halt_input called\n"));
  116. spin_lock_irqsave(&devc->lock,flags);
  117. if(!isa_dma_bridge_buggy) {
  118. disable_dma(audio_devs[dev]->dmap_in->dma);
  119. }
  120. buffer=inb(devc->base+9);
  121. if (buffer & 0x01) {
  122. /* disable capture */
  123. outb(buffer & ~0x01,devc->base+9);
  124. }
  125. if(!isa_dma_bridge_buggy) {
  126. enable_dma(audio_devs[dev]->dmap_in->dma);
  127. }
  128. /* Clear interrupt status */
  129. outb (~0x40, devc->base+1);
  130. devc->audio_mode &= ~PCM_ENABLE_INPUT;
  131. spin_unlock_irqrestore(&devc->lock,flags);
  132. }
  133. static void ad1816_halt_output (int dev)
  134. {
  135. unsigned long flags;
  136. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  137. unsigned char buffer;
  138. DEBUGNOISE(printk(KERN_DEBUG "ad1816: halt_output called!\n"));
  139. spin_lock_irqsave(&devc->lock,flags);
  140. /* Mute pcm output */
  141. ad_write(devc, 4, ad_read(devc,4)|0x8080);
  142. if(!isa_dma_bridge_buggy) {
  143. disable_dma(audio_devs[dev]->dmap_out->dma);
  144. }
  145. buffer=inb(devc->base+8);
  146. if (buffer & 0x01) {
  147. /* disable capture */
  148. outb(buffer & ~0x01,devc->base+8);
  149. }
  150. if(!isa_dma_bridge_buggy) {
  151. enable_dma(audio_devs[dev]->dmap_out->dma);
  152. }
  153. /* Clear interrupt status */
  154. outb ((unsigned char)~0x80, devc->base+1);
  155. devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
  156. spin_unlock_irqrestore(&devc->lock,flags);
  157. }
  158. static void ad1816_output_block (int dev, unsigned long buf,
  159. int count, int intrflag)
  160. {
  161. unsigned long flags;
  162. unsigned long cnt;
  163. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  164. DEBUGNOISE(printk(KERN_DEBUG "ad1816: output_block called buf=%ld count=%d flags=%d\n",buf,count,intrflag));
  165. cnt = count/4 - 1;
  166. spin_lock_irqsave(&devc->lock,flags);
  167. /* set transfer count */
  168. ad_write (devc, 8, cnt & 0xffff);
  169. devc->audio_mode |= PCM_ENABLE_OUTPUT;
  170. spin_unlock_irqrestore(&devc->lock,flags);
  171. }
  172. static void ad1816_start_input (int dev, unsigned long buf, int count,
  173. int intrflag)
  174. {
  175. unsigned long flags;
  176. unsigned long cnt;
  177. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  178. DEBUGNOISE(printk(KERN_DEBUG "ad1816: start_input called buf=%ld count=%d flags=%d\n",buf,count,intrflag));
  179. cnt = count/4 - 1;
  180. spin_lock_irqsave(&devc->lock,flags);
  181. /* set transfer count */
  182. ad_write (devc, 10, cnt & 0xffff);
  183. devc->audio_mode |= PCM_ENABLE_INPUT;
  184. spin_unlock_irqrestore(&devc->lock,flags);
  185. }
  186. static int ad1816_prepare_for_input (int dev, int bsize, int bcount)
  187. {
  188. unsigned long flags;
  189. unsigned int freq;
  190. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  191. unsigned char fmt_bits;
  192. DEBUGNOISE(printk(KERN_DEBUG "ad1816: prepare_for_input called: bsize=%d bcount=%d\n",bsize,bcount));
  193. spin_lock_irqsave(&devc->lock,flags);
  194. fmt_bits= (devc->format_bits&0x7)<<3;
  195. /* set mono/stereo mode */
  196. if (devc->channels > 1) {
  197. fmt_bits |=0x4;
  198. }
  199. /* set Mono/Stereo in playback/capture register */
  200. outb( (inb(devc->base+8) & ~0x3C)|fmt_bits, devc->base+8);
  201. outb( (inb(devc->base+9) & ~0x3C)|fmt_bits, devc->base+9);
  202. freq=((unsigned int)devc->speed*33000)/ad1816_clockfreq;
  203. /* write playback/capture speeds */
  204. ad_write (devc, 2, freq & 0xffff);
  205. ad_write (devc, 3, freq & 0xffff);
  206. spin_unlock_irqrestore(&devc->lock,flags);
  207. ad1816_halt_input(dev);
  208. return 0;
  209. }
  210. static int ad1816_prepare_for_output (int dev, int bsize, int bcount)
  211. {
  212. unsigned long flags;
  213. unsigned int freq;
  214. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  215. unsigned char fmt_bits;
  216. DEBUGNOISE(printk(KERN_DEBUG "ad1816: prepare_for_output called: bsize=%d bcount=%d\n",bsize,bcount));
  217. spin_lock_irqsave(&devc->lock,flags);
  218. fmt_bits= (devc->format_bits&0x7)<<3;
  219. /* set mono/stereo mode */
  220. if (devc->channels > 1) {
  221. fmt_bits |=0x4;
  222. }
  223. /* write format bits to playback/capture registers */
  224. outb( (inb(devc->base+8) & ~0x3C)|fmt_bits, devc->base+8);
  225. outb( (inb(devc->base+9) & ~0x3C)|fmt_bits, devc->base+9);
  226. freq=((unsigned int)devc->speed*33000)/ad1816_clockfreq;
  227. /* write playback/capture speeds */
  228. ad_write (devc, 2, freq & 0xffff);
  229. ad_write (devc, 3, freq & 0xffff);
  230. spin_unlock_irqrestore(&devc->lock,flags);
  231. ad1816_halt_output(dev);
  232. return 0;
  233. }
  234. static void ad1816_trigger (int dev, int state)
  235. {
  236. unsigned long flags;
  237. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  238. DEBUGNOISE(printk(KERN_DEBUG "ad1816: trigger called! (devc=%d,devc->base=%d\n", devc, devc->base));
  239. /* mode may have changed */
  240. spin_lock_irqsave(&devc->lock,flags);
  241. /* mask out modes not specified on open call */
  242. state &= devc->audio_mode;
  243. /* setup soundchip to new io-mode */
  244. if (state & PCM_ENABLE_INPUT) {
  245. /* enable capture */
  246. outb(inb(devc->base+9)|0x01, devc->base+9);
  247. } else {
  248. /* disable capture */
  249. outb(inb(devc->base+9)&~0x01, devc->base+9);
  250. }
  251. if (state & PCM_ENABLE_OUTPUT) {
  252. /* enable playback */
  253. outb(inb(devc->base+8)|0x01, devc->base+8);
  254. /* unmute pcm output */
  255. ad_write(devc, 4, ad_read(devc,4)&~0x8080);
  256. } else {
  257. /* mute pcm output */
  258. ad_write(devc, 4, ad_read(devc,4)|0x8080);
  259. /* disable capture */
  260. outb(inb(devc->base+8)&~0x01, devc->base+8);
  261. }
  262. spin_unlock_irqrestore(&devc->lock,flags);
  263. }
  264. /* halt input & output */
  265. static void ad1816_halt (int dev)
  266. {
  267. ad1816_halt_input(dev);
  268. ad1816_halt_output(dev);
  269. }
  270. static void ad1816_reset (int dev)
  271. {
  272. ad1816_halt (dev);
  273. }
  274. /* set playback speed */
  275. static int ad1816_set_speed (int dev, int arg)
  276. {
  277. unsigned long flags;
  278. unsigned int freq;
  279. int ret;
  280. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  281. spin_lock_irqsave(&devc->lock, flags);
  282. if (arg == 0) {
  283. ret = devc->speed;
  284. spin_unlock_irqrestore(&devc->lock, flags);
  285. return ret;
  286. }
  287. /* range checking */
  288. if (arg < 4000) {
  289. arg = 4000;
  290. }
  291. if (arg > 55000) {
  292. arg = 55000;
  293. }
  294. devc->speed = arg;
  295. /* change speed during playback */
  296. freq=((unsigned int)devc->speed*33000)/ad1816_clockfreq;
  297. /* write playback/capture speeds */
  298. ad_write (devc, 2, freq & 0xffff);
  299. ad_write (devc, 3, freq & 0xffff);
  300. ret = devc->speed;
  301. spin_unlock_irqrestore(&devc->lock, flags);
  302. return ret;
  303. }
  304. static unsigned int ad1816_set_bits (int dev, unsigned int arg)
  305. {
  306. unsigned long flags;
  307. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  308. static struct format_tbl {
  309. int format;
  310. unsigned char bits;
  311. } format2bits[] = {
  312. { 0, 0 },
  313. { AFMT_MU_LAW, 1 },
  314. { AFMT_A_LAW, 3 },
  315. { AFMT_IMA_ADPCM, 0 },
  316. { AFMT_U8, 0 },
  317. { AFMT_S16_LE, 2 },
  318. { AFMT_S16_BE, 6 },
  319. { AFMT_S8, 0 },
  320. { AFMT_U16_LE, 0 },
  321. { AFMT_U16_BE, 0 }
  322. };
  323. int i, n = sizeof (format2bits) / sizeof (struct format_tbl);
  324. spin_lock_irqsave(&devc->lock, flags);
  325. /* return current format */
  326. if (arg == 0) {
  327. arg = devc->audio_format;
  328. spin_unlock_irqrestore(&devc->lock, flags);
  329. return arg;
  330. }
  331. devc->audio_format = arg;
  332. /* search matching format bits */
  333. for (i = 0; i < n; i++)
  334. if (format2bits[i].format == arg) {
  335. devc->format_bits = format2bits[i].bits;
  336. devc->audio_format = arg;
  337. spin_unlock_irqrestore(&devc->lock, flags);
  338. return arg;
  339. }
  340. /* Still hanging here. Something must be terribly wrong */
  341. devc->format_bits = 0;
  342. devc->audio_format = AFMT_U8;
  343. spin_unlock_irqrestore(&devc->lock, flags);
  344. return(AFMT_U8);
  345. }
  346. static short ad1816_set_channels (int dev, short arg)
  347. {
  348. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  349. if (arg != 1 && arg != 2)
  350. return devc->channels;
  351. devc->channels = arg;
  352. return arg;
  353. }
  354. /* open device */
  355. static int ad1816_open (int dev, int mode)
  356. {
  357. ad1816_info *devc = NULL;
  358. unsigned long flags;
  359. /* is device number valid ? */
  360. if (dev < 0 || dev >= num_audiodevs)
  361. return -(ENXIO);
  362. /* get device info of this dev */
  363. devc = (ad1816_info *) audio_devs[dev]->devc;
  364. /* make check if device already open atomic */
  365. spin_lock_irqsave(&devc->lock,flags);
  366. if (devc->opened) {
  367. spin_unlock_irqrestore(&devc->lock,flags);
  368. return -(EBUSY);
  369. }
  370. /* mark device as open */
  371. devc->opened = 1;
  372. devc->audio_mode = 0;
  373. devc->speed = 8000;
  374. devc->audio_format=AFMT_U8;
  375. devc->channels=1;
  376. spin_unlock_irqrestore(&devc->lock,flags);
  377. ad1816_reset(devc->dev_no); /* halt all pending output */
  378. return 0;
  379. }
  380. static void ad1816_close (int dev) /* close device */
  381. {
  382. unsigned long flags;
  383. ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
  384. /* halt all pending output */
  385. ad1816_reset(devc->dev_no);
  386. spin_lock_irqsave(&devc->lock,flags);
  387. devc->opened = 0;
  388. devc->audio_mode = 0;
  389. devc->speed = 8000;
  390. devc->audio_format=AFMT_U8;
  391. devc->format_bits = 0;
  392. spin_unlock_irqrestore(&devc->lock,flags);
  393. }
  394. /* ------------------------------------------------------------------- */
  395. /* Audio driver structure */
  396. static struct audio_driver ad1816_audio_driver =
  397. {
  398. .owner = THIS_MODULE,
  399. .open = ad1816_open,
  400. .close = ad1816_close,
  401. .output_block = ad1816_output_block,
  402. .start_input = ad1816_start_input,
  403. .prepare_for_input = ad1816_prepare_for_input,
  404. .prepare_for_output = ad1816_prepare_for_output,
  405. .halt_io = ad1816_halt,
  406. .halt_input = ad1816_halt_input,
  407. .halt_output = ad1816_halt_output,
  408. .trigger = ad1816_trigger,
  409. .set_speed = ad1816_set_speed,
  410. .set_bits = ad1816_set_bits,
  411. .set_channels = ad1816_set_channels,
  412. };
  413. /* ------------------------------------------------------------------- */
  414. /* Interrupt handler */
  415. static irqreturn_t ad1816_interrupt (int irq, void *dev_id, struct pt_regs *dummy)
  416. {
  417. unsigned char status;
  418. ad1816_info *devc = (ad1816_info *)dev_id;
  419. if (irq < 0 || irq > 15) {
  420. printk(KERN_WARNING "ad1816: Got bogus interrupt %d\n", irq);
  421. return IRQ_NONE;
  422. }
  423. spin_lock(&devc->lock);
  424. /* read interrupt register */
  425. status = inb (devc->base+1);
  426. /* Clear all interrupt */
  427. outb (~status, devc->base+1);
  428. DEBUGNOISE(printk(KERN_DEBUG "ad1816: Got interrupt subclass %d\n",status));
  429. if (status == 0) {
  430. DEBUGNOISE(printk(KERN_DEBUG "ad1816: interrupt: Got interrupt, but no source.\n"));
  431. spin_unlock(&devc->lock);
  432. return IRQ_NONE;
  433. }
  434. if (devc->opened && (devc->audio_mode & PCM_ENABLE_INPUT) && (status&64))
  435. DMAbuf_inputintr (devc->dev_no);
  436. if (devc->opened && (devc->audio_mode & PCM_ENABLE_OUTPUT) && (status & 128))
  437. DMAbuf_outputintr (devc->dev_no, 1);
  438. spin_unlock(&devc->lock);
  439. return IRQ_HANDLED;
  440. }
  441. /* ------------------------------------------------------------------- */
  442. /* Mixer stuff */
  443. struct mixer_def {
  444. unsigned int regno: 7;
  445. unsigned int polarity:1; /* 0=normal, 1=reversed */
  446. unsigned int bitpos:4;
  447. unsigned int nbits:4;
  448. };
  449. static char mix_cvt[101] = {
  450. 0, 0, 3, 7,10,13,16,19,21,23,26,28,30,32,34,35,37,39,40,42,
  451. 43,45,46,47,49,50,51,52,53,55,56,57,58,59,60,61,62,63,64,65,
  452. 65,66,67,68,69,70,70,71,72,73,73,74,75,75,76,77,77,78,79,79,
  453. 80,81,81,82,82,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,
  454. 91,91,92,92,93,93,94,94,95,95,96,96,96,97,97,98,98,98,99,99,
  455. 100
  456. };
  457. typedef struct mixer_def mixer_ent;
  458. /*
  459. * Most of the mixer entries work in backwards. Setting the polarity field
  460. * makes them to work correctly.
  461. *
  462. * The channel numbering used by individual soundcards is not fixed. Some
  463. * cards have assigned different meanings for the AUX1, AUX2 and LINE inputs.
  464. * The current version doesn't try to compensate this.
  465. */
  466. #define MIX_ENT(name, reg_l, pola_l, pos_l, len_l, reg_r, pola_r, pos_r, len_r) \
  467. {{reg_l, pola_l, pos_l, len_l}, {reg_r, pola_r, pos_r, len_r}}
  468. static mixer_ent mix_devices[SOUND_MIXER_NRDEVICES][2] = {
  469. MIX_ENT(SOUND_MIXER_VOLUME, 14, 1, 8, 5, 14, 1, 0, 5),
  470. MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0),
  471. MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0),
  472. MIX_ENT(SOUND_MIXER_SYNTH, 5, 1, 8, 6, 5, 1, 0, 6),
  473. MIX_ENT(SOUND_MIXER_PCM, 4, 1, 8, 6, 4, 1, 0, 6),
  474. MIX_ENT(SOUND_MIXER_SPEAKER, 0, 0, 0, 0, 0, 0, 0, 0),
  475. MIX_ENT(SOUND_MIXER_LINE, 18, 1, 8, 5, 18, 1, 0, 5),
  476. MIX_ENT(SOUND_MIXER_MIC, 19, 1, 8, 5, 19, 1, 0, 5),
  477. MIX_ENT(SOUND_MIXER_CD, 15, 1, 8, 5, 15, 1, 0, 5),
  478. MIX_ENT(SOUND_MIXER_IMIX, 0, 0, 0, 0, 0, 0, 0, 0),
  479. MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0),
  480. MIX_ENT(SOUND_MIXER_RECLEV, 20, 0, 8, 4, 20, 0, 0, 4),
  481. MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 0, 0, 0, 0, 0),
  482. MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0),
  483. MIX_ENT(SOUND_MIXER_LINE1, 17, 1, 8, 5, 17, 1, 0, 5),
  484. MIX_ENT(SOUND_MIXER_LINE2, 16, 1, 8, 5, 16, 1, 0, 5),
  485. MIX_ENT(SOUND_MIXER_LINE3, 39, 0, 9, 4, 39, 1, 0, 5)
  486. };
  487. static unsigned short default_mixer_levels[SOUND_MIXER_NRDEVICES] =
  488. {
  489. 0x4343, /* Master Volume */
  490. 0x3232, /* Bass */
  491. 0x3232, /* Treble */
  492. 0x0000, /* FM */
  493. 0x4343, /* PCM */
  494. 0x0000, /* PC Speaker */
  495. 0x0000, /* Ext Line */
  496. 0x0000, /* Mic */
  497. 0x0000, /* CD */
  498. 0x0000, /* Recording monitor */
  499. 0x0000, /* SB PCM */
  500. 0x0000, /* Recording level */
  501. 0x0000, /* Input gain */
  502. 0x0000, /* Output gain */
  503. 0x0000, /* Line1 */
  504. 0x0000, /* Line2 */
  505. 0x0000 /* Line3 (usually line in)*/
  506. };
  507. #define LEFT_CHN 0
  508. #define RIGHT_CHN 1
  509. static int
  510. ad1816_set_recmask (ad1816_info * devc, int mask)
  511. {
  512. unsigned long flags;
  513. unsigned char recdev;
  514. int i, n;
  515. spin_lock_irqsave(&devc->lock, flags);
  516. mask &= devc->supported_rec_devices;
  517. n = 0;
  518. /* Count selected device bits */
  519. for (i = 0; i < 32; i++)
  520. if (mask & (1 << i))
  521. n++;
  522. if (n == 0)
  523. mask = SOUND_MASK_MIC;
  524. else if (n != 1) { /* Too many devices selected */
  525. /* Filter out active settings */
  526. mask &= ~devc->recmask;
  527. n = 0;
  528. /* Count selected device bits */
  529. for (i = 0; i < 32; i++)
  530. if (mask & (1 << i))
  531. n++;
  532. if (n != 1)
  533. mask = SOUND_MASK_MIC;
  534. }
  535. switch (mask) {
  536. case SOUND_MASK_MIC:
  537. recdev = 5;
  538. break;
  539. case SOUND_MASK_LINE:
  540. recdev = 0;
  541. break;
  542. case SOUND_MASK_CD:
  543. recdev = 2;
  544. break;
  545. case SOUND_MASK_LINE1:
  546. recdev = 4;
  547. break;
  548. case SOUND_MASK_LINE2:
  549. recdev = 3;
  550. break;
  551. case SOUND_MASK_VOLUME:
  552. recdev = 1;
  553. break;
  554. default:
  555. mask = SOUND_MASK_MIC;
  556. recdev = 5;
  557. }
  558. recdev <<= 4;
  559. ad_write (devc, 20,
  560. (ad_read (devc, 20) & 0x8f8f) | recdev | (recdev<<8));
  561. devc->recmask = mask;
  562. spin_unlock_irqrestore(&devc->lock, flags);
  563. return mask;
  564. }
  565. static void
  566. change_bits (int *regval, int dev, int chn, int newval)
  567. {
  568. unsigned char mask;
  569. int shift;
  570. /* Reverse polarity*/
  571. if (mix_devices[dev][chn].polarity == 1)
  572. newval = 100 - newval;
  573. mask = (1 << mix_devices[dev][chn].nbits) - 1;
  574. shift = mix_devices[dev][chn].bitpos;
  575. /* Scale it */
  576. newval = (int) ((newval * mask) + 50) / 100;
  577. /* Clear bits */
  578. *regval &= ~(mask << shift);
  579. /* Set new value */
  580. *regval |= (newval & mask) << shift;
  581. }
  582. static int
  583. ad1816_mixer_get (ad1816_info * devc, int dev)
  584. {
  585. DEBUGNOISE(printk(KERN_DEBUG "ad1816: mixer_get called!\n"));
  586. /* range check + supported mixer check */
  587. if (dev < 0 || dev >= SOUND_MIXER_NRDEVICES )
  588. return (-(EINVAL));
  589. if (!((1 << dev) & devc->supported_devices))
  590. return -(EINVAL);
  591. return devc->levels[dev];
  592. }
  593. static int
  594. ad1816_mixer_set (ad1816_info * devc, int dev, int value)
  595. {
  596. int left = value & 0x000000ff;
  597. int right = (value & 0x0000ff00) >> 8;
  598. int retvol;
  599. int regoffs;
  600. int val;
  601. int valmute;
  602. unsigned long flags;
  603. DEBUGNOISE(printk(KERN_DEBUG "ad1816: mixer_set called!\n"));
  604. if (dev < 0 || dev >= SOUND_MIXER_NRDEVICES )
  605. return -(EINVAL);
  606. if (left > 100)
  607. left = 100;
  608. if (left < 0)
  609. left = 0;
  610. if (right > 100)
  611. right = 100;
  612. if (right < 0)
  613. right = 0;
  614. /* Mono control */
  615. if (mix_devices[dev][RIGHT_CHN].nbits == 0)
  616. right = left;
  617. retvol = left | (right << 8);
  618. /* Scale it */
  619. left = mix_cvt[left];
  620. right = mix_cvt[right];
  621. /* reject all mixers that are not supported */
  622. if (!(devc->supported_devices & (1 << dev)))
  623. return -(EINVAL);
  624. /* sanity check */
  625. if (mix_devices[dev][LEFT_CHN].nbits == 0)
  626. return -(EINVAL);
  627. spin_lock_irqsave(&devc->lock, flags);
  628. /* keep precise volume internal */
  629. devc->levels[dev] = retvol;
  630. /* Set the left channel */
  631. regoffs = mix_devices[dev][LEFT_CHN].regno;
  632. val = ad_read (devc, regoffs);
  633. change_bits (&val, dev, LEFT_CHN, left);
  634. valmute=val;
  635. /* Mute bit masking on some registers */
  636. if ( regoffs==5 || regoffs==14 || regoffs==15 ||
  637. regoffs==16 || regoffs==17 || regoffs==18 ||
  638. regoffs==19 || regoffs==39) {
  639. if (left==0)
  640. valmute |= 0x8000;
  641. else
  642. valmute &= ~0x8000;
  643. }
  644. ad_write (devc, regoffs, valmute); /* mute */
  645. /*
  646. * Set the right channel
  647. */
  648. /* Was just a mono channel */
  649. if (mix_devices[dev][RIGHT_CHN].nbits == 0) {
  650. spin_unlock_irqrestore(&devc->lock, flags);
  651. return retvol;
  652. }
  653. regoffs = mix_devices[dev][RIGHT_CHN].regno;
  654. val = ad_read (devc, regoffs);
  655. change_bits (&val, dev, RIGHT_CHN, right);
  656. valmute=val;
  657. if ( regoffs==5 || regoffs==14 || regoffs==15 ||
  658. regoffs==16 || regoffs==17 || regoffs==18 ||
  659. regoffs==19 || regoffs==39) {
  660. if (right==0)
  661. valmute |= 0x80;
  662. else
  663. valmute &= ~0x80;
  664. }
  665. ad_write (devc, regoffs, valmute); /* mute */
  666. spin_unlock_irqrestore(&devc->lock, flags);
  667. return retvol;
  668. }
  669. #define MIXER_DEVICES ( SOUND_MASK_VOLUME | \
  670. SOUND_MASK_SYNTH | \
  671. SOUND_MASK_PCM | \
  672. SOUND_MASK_LINE | \
  673. SOUND_MASK_LINE1 | \
  674. SOUND_MASK_LINE2 | \
  675. SOUND_MASK_LINE3 | \
  676. SOUND_MASK_MIC | \
  677. SOUND_MASK_CD | \
  678. SOUND_MASK_RECLEV \
  679. )
  680. #define REC_DEVICES ( SOUND_MASK_LINE2 |\
  681. SOUND_MASK_LINE |\
  682. SOUND_MASK_LINE1 |\
  683. SOUND_MASK_MIC |\
  684. SOUND_MASK_CD |\
  685. SOUND_MASK_VOLUME \
  686. )
  687. static void
  688. ad1816_mixer_reset (ad1816_info * devc)
  689. {
  690. int i;
  691. devc->supported_devices = MIXER_DEVICES;
  692. devc->supported_rec_devices = REC_DEVICES;
  693. for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
  694. if (devc->supported_devices & (1 << i))
  695. ad1816_mixer_set (devc, i, default_mixer_levels[i]);
  696. ad1816_set_recmask (devc, SOUND_MASK_MIC);
  697. }
  698. static int
  699. ad1816_mixer_ioctl (int dev, unsigned int cmd, void __user * arg)
  700. {
  701. ad1816_info *devc = mixer_devs[dev]->devc;
  702. int val;
  703. int __user *p = arg;
  704. DEBUGNOISE(printk(KERN_DEBUG "ad1816: mixer_ioctl called!\n"));
  705. /* Mixer ioctl */
  706. if (((cmd >> 8) & 0xff) == 'M') {
  707. /* set ioctl */
  708. if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
  709. switch (cmd & 0xff){
  710. case SOUND_MIXER_RECSRC:
  711. if (get_user(val, p))
  712. return -EFAULT;
  713. val=ad1816_set_recmask (devc, val);
  714. return put_user(val, p);
  715. break;
  716. default:
  717. if (get_user(val, p))
  718. return -EFAULT;
  719. if ((val=ad1816_mixer_set (devc, cmd & 0xff, val))<0)
  720. return val;
  721. else
  722. return put_user(val, p);
  723. }
  724. } else {
  725. /* read ioctl */
  726. switch (cmd & 0xff) {
  727. case SOUND_MIXER_RECSRC:
  728. val=devc->recmask;
  729. return put_user(val, p);
  730. break;
  731. case SOUND_MIXER_DEVMASK:
  732. val=devc->supported_devices;
  733. return put_user(val, p);
  734. break;
  735. case SOUND_MIXER_STEREODEVS:
  736. val=devc->supported_devices & ~(SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
  737. return put_user(val, p);
  738. break;
  739. case SOUND_MIXER_RECMASK:
  740. val=devc->supported_rec_devices;
  741. return put_user(val, p);
  742. break;
  743. case SOUND_MIXER_CAPS:
  744. val=SOUND_CAP_EXCL_INPUT;
  745. return put_user(val, p);
  746. break;
  747. default:
  748. if ((val=ad1816_mixer_get (devc, cmd & 0xff))<0)
  749. return val;
  750. else
  751. return put_user(val, p);
  752. }
  753. }
  754. } else
  755. /* not for mixer */
  756. return -(EINVAL);
  757. }
  758. /* ------------------------------------------------------------------- */
  759. /* Mixer structure */
  760. static struct mixer_operations ad1816_mixer_operations = {
  761. .owner = THIS_MODULE,
  762. .id = "AD1816",
  763. .name = "AD1816 Mixer",
  764. .ioctl = ad1816_mixer_ioctl
  765. };
  766. /* ------------------------------------------------------------------- */
  767. /* stuff for card recognition, init and unloading PNP ...*/
  768. /* check if AD1816 present at specified hw_config and register device with OS
  769. * return 1 if initialization was successful, 0 otherwise
  770. */
  771. static int __init ad1816_init_card (struct address_info *hw_config,
  772. struct pnp_dev *pnp)
  773. {
  774. ad1816_info *devc = NULL;
  775. int tmp;
  776. int oss_devno = -1;
  777. printk(KERN_INFO "ad1816: initializing card: io=0x%x, irq=%d, dma=%d, "
  778. "dma2=%d, clockfreq=%d, options=%d isadmabug=%d "
  779. "%s\n",
  780. hw_config->io_base,
  781. hw_config->irq,
  782. hw_config->dma,
  783. hw_config->dma2,
  784. ad1816_clockfreq,
  785. options,
  786. isa_dma_bridge_buggy,
  787. pnp?"(PNP)":"");
  788. /* ad1816_info structure remaining ? */
  789. if (nr_ad1816_devs >= MAX_AUDIO_DEV) {
  790. printk(KERN_WARNING "ad1816: no more ad1816_info structures "
  791. "left\n");
  792. goto out;
  793. }
  794. devc = &dev_info[nr_ad1816_devs];
  795. devc->base = hw_config->io_base;
  796. devc->irq = hw_config->irq;
  797. devc->dma_playback=hw_config->dma;
  798. devc->dma_capture=hw_config->dma2;
  799. devc->opened = 0;
  800. devc->pnpdev = pnp;
  801. spin_lock_init(&devc->lock);
  802. if (!request_region(devc->base, 16, "AD1816 Sound")) {
  803. printk(KERN_WARNING "ad1816: I/O port 0x%03x not free\n",
  804. devc->base);
  805. goto out;
  806. }
  807. printk(KERN_INFO "ad1816: Examining AD1816 at address 0x%03x.\n",
  808. devc->base);
  809. /* tests for ad1816 */
  810. /* base+0: bit 1 must be set but not 255 */
  811. tmp=inb(devc->base);
  812. if ( (tmp&0x80)==0 || tmp==255 ) {
  813. printk (KERN_INFO "ad1816: Chip is not an AD1816 or chip "
  814. "is not active (Test 0)\n");
  815. goto out_release_region;
  816. }
  817. /* writes to ireg 8 are copied to ireg 9 */
  818. ad_write(devc,8,12345);
  819. if (ad_read(devc,9)!=12345) {
  820. printk(KERN_INFO "ad1816: Chip is not an AD1816 (Test 1)\n");
  821. goto out_release_region;
  822. }
  823. /* writes to ireg 8 are copied to ireg 9 */
  824. ad_write(devc,8,54321);
  825. if (ad_read(devc,9)!=54321) {
  826. printk(KERN_INFO "ad1816: Chip is not an AD1816 (Test 2)\n");
  827. goto out_release_region;
  828. }
  829. /* writes to ireg 10 are copied to ireg 11 */
  830. ad_write(devc,10,54321);
  831. if (ad_read(devc,11)!=54321) {
  832. printk (KERN_INFO "ad1816: Chip is not an AD1816 (Test 3)\n");
  833. goto out_release_region;
  834. }
  835. /* writes to ireg 10 are copied to ireg 11 */
  836. ad_write(devc,10,12345);
  837. if (ad_read(devc,11)!=12345) {
  838. printk (KERN_INFO "ad1816: Chip is not an AD1816 (Test 4)\n");
  839. goto out_release_region;
  840. }
  841. /* bit in base +1 cannot be set to 1 */
  842. tmp=inb(devc->base+1);
  843. outb(0xff,devc->base+1);
  844. if (inb(devc->base+1)!=tmp) {
  845. printk(KERN_INFO "ad1816: Chip is not an AD1816 (Test 5)\n");
  846. goto out_release_region;
  847. }
  848. printk(KERN_INFO "ad1816: AD1816 (version %d) successfully detected!\n",
  849. ad_read(devc,45));
  850. /* disable all interrupts */
  851. ad_write(devc,1,0);
  852. /* Clear pending interrupts */
  853. outb (0, devc->base+1);
  854. /* allocate irq */
  855. if (devc->irq < 0 || devc->irq > 15)
  856. goto out_release_region;
  857. if (request_irq(devc->irq, ad1816_interrupt,0,
  858. "SoundPort", devc) < 0) {
  859. printk(KERN_WARNING "ad1816: IRQ in use\n");
  860. goto out_release_region;
  861. }
  862. /* DMA stuff */
  863. if (sound_alloc_dma (devc->dma_playback, "Sound System")) {
  864. printk(KERN_WARNING "ad1816: Can't allocate DMA%d\n",
  865. devc->dma_playback);
  866. goto out_free_irq;
  867. }
  868. if ( devc->dma_capture >= 0 &&
  869. devc->dma_capture != devc->dma_playback) {
  870. if (sound_alloc_dma(devc->dma_capture,
  871. "Sound System (capture)")) {
  872. printk(KERN_WARNING "ad1816: Can't allocate DMA%d\n",
  873. devc->dma_capture);
  874. goto out_free_dma;
  875. }
  876. devc->audio_mode=DMA_AUTOMODE|DMA_DUPLEX;
  877. } else {
  878. printk(KERN_WARNING "ad1816: Only one DMA channel "
  879. "available/configured. No duplex operation possible\n");
  880. devc->audio_mode=DMA_AUTOMODE;
  881. }
  882. conf_printf2 ("AD1816 audio driver",
  883. devc->base, devc->irq, devc->dma_playback,
  884. devc->dma_capture);
  885. /* register device */
  886. if ((oss_devno = sound_install_audiodrv (AUDIO_DRIVER_VERSION,
  887. "AD1816 audio driver",
  888. &ad1816_audio_driver,
  889. sizeof (struct audio_driver),
  890. devc->audio_mode,
  891. ad_format_mask,
  892. devc,
  893. devc->dma_playback,
  894. devc->dma_capture)) < 0) {
  895. printk(KERN_WARNING "ad1816: Can't install sound driver\n");
  896. goto out_free_dma_2;
  897. }
  898. ad_write(devc,32,0x80f0); /* sound system mode */
  899. if (options&1) {
  900. ad_write(devc,33,0); /* disable all audiosources for dsp */
  901. } else {
  902. ad_write(devc,33,0x03f8); /* enable all audiosources for dsp */
  903. }
  904. ad_write(devc,4,0x8080); /* default values for volumes (muted)*/
  905. ad_write(devc,5,0x8080);
  906. ad_write(devc,6,0x8080);
  907. ad_write(devc,7,0x8080);
  908. ad_write(devc,15,0x8888);
  909. ad_write(devc,16,0x8888);
  910. ad_write(devc,17,0x8888);
  911. ad_write(devc,18,0x8888);
  912. ad_write(devc,19,0xc888); /* +20db mic active */
  913. ad_write(devc,14,0x0000); /* Master volume unmuted */
  914. ad_write(devc,39,0x009f); /* 3D effect on 0% phone out muted */
  915. ad_write(devc,44,0x0080); /* everything on power, 3d enabled for d/a */
  916. outb(0x10,devc->base+8); /* set dma mode */
  917. outb(0x10,devc->base+9);
  918. /* enable capture + playback interrupt */
  919. ad_write(devc,1,0xc000);
  920. /* set mixer defaults */
  921. ad1816_mixer_reset (devc);
  922. /* register mixer */
  923. if ((audio_devs[oss_devno]->mixer_dev=sound_install_mixer(
  924. MIXER_DRIVER_VERSION,
  925. "AD1816 audio driver",
  926. &ad1816_mixer_operations,
  927. sizeof (struct mixer_operations),
  928. devc)) < 0) {
  929. printk(KERN_WARNING "Can't install mixer\n");
  930. }
  931. /* make ad1816_info active */
  932. nr_ad1816_devs++;
  933. printk(KERN_INFO "ad1816: card successfully installed!\n");
  934. return 1;
  935. /* error handling */
  936. out_free_dma_2:
  937. if (devc->dma_capture >= 0 && devc->dma_capture != devc->dma_playback)
  938. sound_free_dma(devc->dma_capture);
  939. out_free_dma:
  940. sound_free_dma(devc->dma_playback);
  941. out_free_irq:
  942. free_irq(devc->irq, devc);
  943. out_release_region:
  944. release_region(devc->base, 16);
  945. out:
  946. return 0;
  947. }
  948. static void __exit unload_card(ad1816_info *devc)
  949. {
  950. int mixer, dev = 0;
  951. if (devc != NULL) {
  952. printk("ad1816: Unloading card at address 0x%03x\n",devc->base);
  953. dev = devc->dev_no;
  954. mixer = audio_devs[dev]->mixer_dev;
  955. /* unreg mixer*/
  956. if(mixer>=0) {
  957. sound_unload_mixerdev(mixer);
  958. }
  959. /* unreg audiodev */
  960. sound_unload_audiodev(dev);
  961. /* free dma channels */
  962. if (devc->dma_capture>=0 &&
  963. devc->dma_capture != devc->dma_playback) {
  964. sound_free_dma(devc->dma_capture);
  965. }
  966. sound_free_dma (devc->dma_playback);
  967. /* free irq */
  968. free_irq(devc->irq, devc);
  969. /* free io */
  970. release_region (devc->base, 16);
  971. #ifdef __ISAPNP__
  972. if (devc->pnpdev) {
  973. pnp_disable_dev(devc->pnpdev);
  974. pnp_device_detach(devc->pnpdev);
  975. }
  976. #endif
  977. } else
  978. printk(KERN_WARNING "ad1816: no device/card specified\n");
  979. }
  980. static int __initdata io = -1;
  981. static int __initdata irq = -1;
  982. static int __initdata dma = -1;
  983. static int __initdata dma2 = -1;
  984. #ifdef __ISAPNP__
  985. /* use isapnp for configuration */
  986. static int isapnp = 1;
  987. static int isapnpjump;
  988. module_param(isapnp, bool, 0);
  989. module_param(isapnpjump, int, 0);
  990. #endif
  991. module_param(io, int, 0);
  992. module_param(irq, int, 0);
  993. module_param(dma, int, 0);
  994. module_param(dma2, int, 0);
  995. module_param(ad1816_clockfreq, int, 0);
  996. module_param(options, int, 0);
  997. #ifdef __ISAPNP__
  998. static struct {
  999. unsigned short card_vendor, card_device;
  1000. unsigned short vendor;
  1001. unsigned short function;
  1002. struct ad1816_data *data;
  1003. } isapnp_ad1816_list[] __initdata = {
  1004. { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
  1005. ISAPNP_VENDOR('A','D','S'), ISAPNP_FUNCTION(0x7150),
  1006. NULL },
  1007. { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
  1008. ISAPNP_VENDOR('A','D','S'), ISAPNP_FUNCTION(0x7180),
  1009. NULL },
  1010. {0}
  1011. };
  1012. MODULE_DEVICE_TABLE(isapnp, isapnp_ad1816_list);
  1013. static void __init ad1816_config_pnp_card(struct pnp_card *card,
  1014. unsigned short vendor,
  1015. unsigned short function)
  1016. {
  1017. struct address_info cfg;
  1018. struct pnp_dev *card_dev = pnp_find_dev(card, vendor, function, NULL);
  1019. if (!card_dev) return;
  1020. if (pnp_device_attach(card_dev) < 0) {
  1021. printk(KERN_WARNING "ad1816: Failed to attach PnP device\n");
  1022. return;
  1023. }
  1024. if (pnp_activate_dev(card_dev) < 0) {
  1025. printk(KERN_WARNING "ad1816: Failed to activate PnP device\n");
  1026. pnp_device_detach(card_dev);
  1027. return;
  1028. }
  1029. cfg.io_base = pnp_port_start(card_dev, 2);
  1030. cfg.irq = pnp_irq(card_dev, 0);
  1031. cfg.dma = pnp_irq(card_dev, 0);
  1032. cfg.dma2 = pnp_irq(card_dev, 1);
  1033. if (!ad1816_init_card(&cfg, card_dev)) {
  1034. pnp_disable_dev(card_dev);
  1035. pnp_device_detach(card_dev);
  1036. }
  1037. }
  1038. static void __init ad1816_config_pnp_cards(void)
  1039. {
  1040. int nr_pnp_cfg;
  1041. int i;
  1042. /* Count entries in isapnp_ad1816_list */
  1043. for (nr_pnp_cfg = 0; isapnp_ad1816_list[nr_pnp_cfg].card_vendor != 0;
  1044. nr_pnp_cfg++);
  1045. /* Check and adjust isapnpjump */
  1046. if( isapnpjump < 0 || isapnpjump >= nr_pnp_cfg) {
  1047. printk(KERN_WARNING
  1048. "ad1816: Valid range for isapnpjump is 0-%d. "
  1049. "Adjusted to 0.\n", nr_pnp_cfg-1);
  1050. isapnpjump = 0;
  1051. }
  1052. for (i = isapnpjump; isapnp_ad1816_list[i].card_vendor != 0; i++) {
  1053. struct pnp_card *card = NULL;
  1054. /* iterate over all pnp cards */
  1055. while ((card = pnp_find_card(isapnp_ad1816_list[i].card_vendor,
  1056. isapnp_ad1816_list[i].card_device, card)))
  1057. ad1816_config_pnp_card(card,
  1058. isapnp_ad1816_list[i].vendor,
  1059. isapnp_ad1816_list[i].function);
  1060. }
  1061. }
  1062. #endif
  1063. /* module initialization */
  1064. static int __init init_ad1816(void)
  1065. {
  1066. printk(KERN_INFO "ad1816: AD1816 sounddriver "
  1067. "Copyright (C) 1998-2003 by Thorsten Knabe and "
  1068. "others\n");
  1069. #ifdef AD1816_CLOCK
  1070. /* set ad1816_clockfreq if set during compilation */
  1071. ad1816_clockfreq=AD1816_CLOCK;
  1072. #endif
  1073. if (ad1816_clockfreq<5000 || ad1816_clockfreq>100000) {
  1074. ad1816_clockfreq=33000;
  1075. }
  1076. #ifdef __ISAPNP__
  1077. /* configure PnP cards */
  1078. if(isapnp) ad1816_config_pnp_cards();
  1079. #endif
  1080. /* configure card by module params */
  1081. if (io != -1 && irq != -1 && dma != -1) {
  1082. struct address_info cfg;
  1083. cfg.io_base = io;
  1084. cfg.irq = irq;
  1085. cfg.dma = dma;
  1086. cfg.dma2 = dma2;
  1087. ad1816_init_card(&cfg, NULL);
  1088. }
  1089. if (nr_ad1816_devs <= 0)
  1090. return -ENODEV;
  1091. return 0;
  1092. }
  1093. /* module cleanup */
  1094. static void __exit cleanup_ad1816 (void)
  1095. {
  1096. int i;
  1097. ad1816_info *devc = NULL;
  1098. /* remove any soundcard */
  1099. for (i = 0; i < nr_ad1816_devs; i++) {
  1100. devc = &dev_info[i];
  1101. unload_card(devc);
  1102. }
  1103. nr_ad1816_devs=0;
  1104. printk(KERN_INFO "ad1816: driver unloaded!\n");
  1105. }
  1106. module_init(init_ad1816);
  1107. module_exit(cleanup_ad1816);
  1108. #ifndef MODULE
  1109. /* kernel command line parameter evaluation */
  1110. static int __init setup_ad1816(char *str)
  1111. {
  1112. /* io, irq, dma, dma2 */
  1113. int ints[5];
  1114. str = get_options(str, ARRAY_SIZE(ints), ints);
  1115. io = ints[1];
  1116. irq = ints[2];
  1117. dma = ints[3];
  1118. dma2 = ints[4];
  1119. return 1;
  1120. }
  1121. __setup("ad1816=", setup_ad1816);
  1122. #endif
  1123. MODULE_LICENSE("GPL");