ad1816.c 33 KB

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