waveartist.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030
  1. /*
  2. * linux/sound/oss/waveartist.c
  3. *
  4. * The low level driver for the RWA010 Rockwell Wave Artist
  5. * codec chip used in the Rebel.com NetWinder.
  6. *
  7. * Cleaned up and integrated into 2.1 by Russell King (rmk@arm.linux.org.uk)
  8. * and Pat Beirne (patb@corel.ca)
  9. *
  10. *
  11. * Copyright (C) by Rebel.com 1998-1999
  12. *
  13. * RWA010 specs received under NDA from Rockwell
  14. *
  15. * Copyright (C) by Hannu Savolainen 1993-1997
  16. *
  17. * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
  18. * Version 2 (June 1991). See the "COPYING" file distributed with this software
  19. * for more info.
  20. *
  21. * Changes:
  22. * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
  23. * Added __init to waveartist_init()
  24. */
  25. /* Debugging */
  26. #define DEBUG_CMD 1
  27. #define DEBUG_OUT 2
  28. #define DEBUG_IN 4
  29. #define DEBUG_INTR 8
  30. #define DEBUG_MIXER 16
  31. #define DEBUG_TRIGGER 32
  32. #define debug_flg (0)
  33. #include <linux/module.h>
  34. #include <linux/init.h>
  35. #include <linux/sched.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/delay.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/bitops.h>
  40. #include <asm/system.h>
  41. #include "sound_config.h"
  42. #include "waveartist.h"
  43. #ifdef CONFIG_ARM
  44. #include <mach/hardware.h>
  45. #include <asm/mach-types.h>
  46. #endif
  47. #ifndef NO_DMA
  48. #define NO_DMA 255
  49. #endif
  50. #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
  51. SOUND_MASK_PCM |\
  52. SOUND_MASK_LINE |\
  53. SOUND_MASK_MIC |\
  54. SOUND_MASK_LINE1 |\
  55. SOUND_MASK_RECLEV |\
  56. SOUND_MASK_VOLUME |\
  57. SOUND_MASK_IMIX)
  58. static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
  59. 0x5555, /* Master Volume */
  60. 0x0000, /* Bass */
  61. 0x0000, /* Treble */
  62. 0x2323, /* Synth (FM) */
  63. 0x4b4b, /* PCM */
  64. 0x6464, /* PC Speaker */
  65. 0x0000, /* Ext Line */
  66. 0x0000, /* Mic */
  67. 0x0000, /* CD */
  68. 0x6464, /* Recording monitor */
  69. 0x0000, /* SB PCM (ALT PCM) */
  70. 0x0000, /* Recording level */
  71. 0x6464, /* Input gain */
  72. 0x6464, /* Output gain */
  73. 0x0000, /* Line1 (Aux1) */
  74. 0x0000, /* Line2 (Aux2) */
  75. 0x0000, /* Line3 (Aux3) */
  76. 0x0000, /* Digital1 */
  77. 0x0000, /* Digital2 */
  78. 0x0000, /* Digital3 */
  79. 0x0000, /* Phone In */
  80. 0x6464, /* Phone Out */
  81. 0x0000, /* Video */
  82. 0x0000, /* Radio */
  83. 0x0000 /* Monitor */
  84. };
  85. typedef struct {
  86. struct address_info hw; /* hardware */
  87. char *chip_name;
  88. int xfer_count;
  89. int audio_mode;
  90. int open_mode;
  91. int audio_flags;
  92. int record_dev;
  93. int playback_dev;
  94. int dev_no;
  95. /* Mixer parameters */
  96. const struct waveartist_mixer_info *mix;
  97. unsigned short *levels; /* cache of volume settings */
  98. int recmask; /* currently enabled recording device! */
  99. #ifdef CONFIG_ARCH_NETWINDER
  100. signed int slider_vol; /* hardware slider volume */
  101. unsigned int handset_detect :1;
  102. unsigned int telephone_detect:1;
  103. unsigned int no_autoselect :1;/* handset/telephone autoselects a path */
  104. unsigned int spkr_mute_state :1;/* set by ioctl or autoselect */
  105. unsigned int line_mute_state :1;/* set by ioctl or autoselect */
  106. unsigned int use_slider :1;/* use slider setting for o/p vol */
  107. #endif
  108. } wavnc_info;
  109. /*
  110. * This is the implementation specific mixer information.
  111. */
  112. struct waveartist_mixer_info {
  113. unsigned int supported_devs; /* Supported devices */
  114. unsigned int recording_devs; /* Recordable devies */
  115. unsigned int stereo_devs; /* Stereo devices */
  116. unsigned int (*select_input)(wavnc_info *, unsigned int,
  117. unsigned char *, unsigned char *);
  118. int (*decode_mixer)(wavnc_info *, int,
  119. unsigned char, unsigned char);
  120. int (*get_mixer)(wavnc_info *, int);
  121. };
  122. typedef struct wavnc_port_info {
  123. int open_mode;
  124. int speed;
  125. int channels;
  126. int audio_format;
  127. } wavnc_port_info;
  128. static int nr_waveartist_devs;
  129. static wavnc_info adev_info[MAX_AUDIO_DEV];
  130. static DEFINE_SPINLOCK(waveartist_lock);
  131. #ifndef CONFIG_ARCH_NETWINDER
  132. #define machine_is_netwinder() 0
  133. #else
  134. static struct timer_list vnc_timer;
  135. static void vnc_configure_mixer(wavnc_info *devc, unsigned int input_mask);
  136. static int vnc_private_ioctl(int dev, unsigned int cmd, int __user *arg);
  137. static void vnc_slider_tick(unsigned long data);
  138. #endif
  139. static inline void
  140. waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
  141. {
  142. unsigned int ctlr_port = hw->io_base + CTLR;
  143. clear = ~clear & inb(ctlr_port);
  144. outb(clear | set, ctlr_port);
  145. }
  146. /* Toggle IRQ acknowledge line
  147. */
  148. static inline void
  149. waveartist_iack(wavnc_info *devc)
  150. {
  151. unsigned int ctlr_port = devc->hw.io_base + CTLR;
  152. int old_ctlr;
  153. old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
  154. outb(old_ctlr | IRQ_ACK, ctlr_port);
  155. outb(old_ctlr, ctlr_port);
  156. }
  157. static inline int
  158. waveartist_sleep(int timeout_ms)
  159. {
  160. unsigned int timeout = timeout_ms * 10 * HZ / 100;
  161. do {
  162. set_current_state(TASK_INTERRUPTIBLE);
  163. timeout = schedule_timeout(timeout);
  164. } while (timeout);
  165. return 0;
  166. }
  167. static int
  168. waveartist_reset(wavnc_info *devc)
  169. {
  170. struct address_info *hw = &devc->hw;
  171. unsigned int timeout, res = -1;
  172. waveartist_set_ctlr(hw, -1, RESET);
  173. waveartist_sleep(2);
  174. waveartist_set_ctlr(hw, RESET, 0);
  175. timeout = 500;
  176. do {
  177. mdelay(2);
  178. if (inb(hw->io_base + STATR) & CMD_RF) {
  179. res = inw(hw->io_base + CMDR);
  180. if (res == 0x55aa)
  181. break;
  182. }
  183. } while (--timeout);
  184. if (timeout == 0) {
  185. printk(KERN_WARNING "WaveArtist: reset timeout ");
  186. if (res != (unsigned int)-1)
  187. printk("(res=%04X)", res);
  188. printk("\n");
  189. return 1;
  190. }
  191. return 0;
  192. }
  193. /* Helper function to send and receive words
  194. * from WaveArtist. It handles all the handshaking
  195. * and can send or receive multiple words.
  196. */
  197. static int
  198. waveartist_cmd(wavnc_info *devc,
  199. int nr_cmd, unsigned int *cmd,
  200. int nr_resp, unsigned int *resp)
  201. {
  202. unsigned int io_base = devc->hw.io_base;
  203. unsigned int timed_out = 0;
  204. unsigned int i;
  205. if (debug_flg & DEBUG_CMD) {
  206. printk("waveartist_cmd: cmd=");
  207. for (i = 0; i < nr_cmd; i++)
  208. printk("%04X ", cmd[i]);
  209. printk("\n");
  210. }
  211. if (inb(io_base + STATR) & CMD_RF) {
  212. int old_data;
  213. /* flush the port
  214. */
  215. old_data = inw(io_base + CMDR);
  216. if (debug_flg & DEBUG_CMD)
  217. printk("flushed %04X...", old_data);
  218. udelay(10);
  219. }
  220. for (i = 0; !timed_out && i < nr_cmd; i++) {
  221. int count;
  222. for (count = 5000; count; count--)
  223. if (inb(io_base + STATR) & CMD_WE)
  224. break;
  225. if (!count)
  226. timed_out = 1;
  227. else
  228. outw(cmd[i], io_base + CMDR);
  229. }
  230. for (i = 0; !timed_out && i < nr_resp; i++) {
  231. int count;
  232. for (count = 5000; count; count--)
  233. if (inb(io_base + STATR) & CMD_RF)
  234. break;
  235. if (!count)
  236. timed_out = 1;
  237. else
  238. resp[i] = inw(io_base + CMDR);
  239. }
  240. if (debug_flg & DEBUG_CMD) {
  241. if (!timed_out) {
  242. printk("waveartist_cmd: resp=");
  243. for (i = 0; i < nr_resp; i++)
  244. printk("%04X ", resp[i]);
  245. printk("\n");
  246. } else
  247. printk("waveartist_cmd: timed out\n");
  248. }
  249. return timed_out ? 1 : 0;
  250. }
  251. /*
  252. * Send one command word
  253. */
  254. static inline int
  255. waveartist_cmd1(wavnc_info *devc, unsigned int cmd)
  256. {
  257. return waveartist_cmd(devc, 1, &cmd, 0, NULL);
  258. }
  259. /*
  260. * Send one command, receive one word
  261. */
  262. static inline unsigned int
  263. waveartist_cmd1_r(wavnc_info *devc, unsigned int cmd)
  264. {
  265. unsigned int ret;
  266. waveartist_cmd(devc, 1, &cmd, 1, &ret);
  267. return ret;
  268. }
  269. /*
  270. * Send a double command, receive one
  271. * word (and throw it away)
  272. */
  273. static inline int
  274. waveartist_cmd2(wavnc_info *devc, unsigned int cmd, unsigned int arg)
  275. {
  276. unsigned int vals[2];
  277. vals[0] = cmd;
  278. vals[1] = arg;
  279. return waveartist_cmd(devc, 2, vals, 1, vals);
  280. }
  281. /*
  282. * Send a triple command
  283. */
  284. static inline int
  285. waveartist_cmd3(wavnc_info *devc, unsigned int cmd,
  286. unsigned int arg1, unsigned int arg2)
  287. {
  288. unsigned int vals[3];
  289. vals[0] = cmd;
  290. vals[1] = arg1;
  291. vals[2] = arg2;
  292. return waveartist_cmd(devc, 3, vals, 0, NULL);
  293. }
  294. static int
  295. waveartist_getrev(wavnc_info *devc, char *rev)
  296. {
  297. unsigned int temp[2];
  298. unsigned int cmd = WACMD_GETREV;
  299. waveartist_cmd(devc, 1, &cmd, 2, temp);
  300. rev[0] = temp[0] >> 8;
  301. rev[1] = temp[0] & 255;
  302. rev[2] = '\0';
  303. return temp[0];
  304. }
  305. static void waveartist_halt_output(int dev);
  306. static void waveartist_halt_input(int dev);
  307. static void waveartist_halt(int dev);
  308. static void waveartist_trigger(int dev, int state);
  309. static int
  310. waveartist_open(int dev, int mode)
  311. {
  312. wavnc_info *devc;
  313. wavnc_port_info *portc;
  314. unsigned long flags;
  315. if (dev < 0 || dev >= num_audiodevs)
  316. return -ENXIO;
  317. devc = (wavnc_info *) audio_devs[dev]->devc;
  318. portc = (wavnc_port_info *) audio_devs[dev]->portc;
  319. spin_lock_irqsave(&waveartist_lock, flags);
  320. if (portc->open_mode || (devc->open_mode & mode)) {
  321. spin_unlock_irqrestore(&waveartist_lock, flags);
  322. return -EBUSY;
  323. }
  324. devc->audio_mode = 0;
  325. devc->open_mode |= mode;
  326. portc->open_mode = mode;
  327. waveartist_trigger(dev, 0);
  328. if (mode & OPEN_READ)
  329. devc->record_dev = dev;
  330. if (mode & OPEN_WRITE)
  331. devc->playback_dev = dev;
  332. spin_unlock_irqrestore(&waveartist_lock, flags);
  333. return 0;
  334. }
  335. static void
  336. waveartist_close(int dev)
  337. {
  338. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  339. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  340. unsigned long flags;
  341. spin_lock_irqsave(&waveartist_lock, flags);
  342. waveartist_halt(dev);
  343. devc->audio_mode = 0;
  344. devc->open_mode &= ~portc->open_mode;
  345. portc->open_mode = 0;
  346. spin_unlock_irqrestore(&waveartist_lock, flags);
  347. }
  348. static void
  349. waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
  350. {
  351. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  352. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  353. unsigned long flags;
  354. unsigned int count = __count;
  355. if (debug_flg & DEBUG_OUT)
  356. printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
  357. buf, count);
  358. /*
  359. * 16 bit data
  360. */
  361. if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
  362. count >>= 1;
  363. if (portc->channels > 1)
  364. count >>= 1;
  365. count -= 1;
  366. if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
  367. audio_devs[dev]->flags & DMA_AUTOMODE &&
  368. intrflag &&
  369. count == devc->xfer_count) {
  370. devc->audio_mode |= PCM_ENABLE_OUTPUT;
  371. return; /*
  372. * Auto DMA mode on. No need to react
  373. */
  374. }
  375. spin_lock_irqsave(&waveartist_lock, flags);
  376. /*
  377. * set sample count
  378. */
  379. waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
  380. devc->xfer_count = count;
  381. devc->audio_mode |= PCM_ENABLE_OUTPUT;
  382. spin_unlock_irqrestore(&waveartist_lock, flags);
  383. }
  384. static void
  385. waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
  386. {
  387. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  388. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  389. unsigned long flags;
  390. unsigned int count = __count;
  391. if (debug_flg & DEBUG_IN)
  392. printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
  393. buf, count);
  394. if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
  395. count >>= 1;
  396. if (portc->channels > 1)
  397. count >>= 1;
  398. count -= 1;
  399. if (devc->audio_mode & PCM_ENABLE_INPUT &&
  400. audio_devs[dev]->flags & DMA_AUTOMODE &&
  401. intrflag &&
  402. count == devc->xfer_count) {
  403. devc->audio_mode |= PCM_ENABLE_INPUT;
  404. return; /*
  405. * Auto DMA mode on. No need to react
  406. */
  407. }
  408. spin_lock_irqsave(&waveartist_lock, flags);
  409. /*
  410. * set sample count
  411. */
  412. waveartist_cmd2(devc, WACMD_INPUTSIZE, count);
  413. devc->xfer_count = count;
  414. devc->audio_mode |= PCM_ENABLE_INPUT;
  415. spin_unlock_irqrestore(&waveartist_lock, flags);
  416. }
  417. static int
  418. waveartist_ioctl(int dev, unsigned int cmd, void __user * arg)
  419. {
  420. return -EINVAL;
  421. }
  422. static unsigned int
  423. waveartist_get_speed(wavnc_port_info *portc)
  424. {
  425. unsigned int speed;
  426. /*
  427. * program the speed, channels, bits
  428. */
  429. if (portc->speed == 8000)
  430. speed = 0x2E71;
  431. else if (portc->speed == 11025)
  432. speed = 0x4000;
  433. else if (portc->speed == 22050)
  434. speed = 0x8000;
  435. else if (portc->speed == 44100)
  436. speed = 0x0;
  437. else {
  438. /*
  439. * non-standard - just calculate
  440. */
  441. speed = portc->speed << 16;
  442. speed = (speed / 44100) & 65535;
  443. }
  444. return speed;
  445. }
  446. static unsigned int
  447. waveartist_get_bits(wavnc_port_info *portc)
  448. {
  449. unsigned int bits;
  450. if (portc->audio_format == AFMT_S16_LE)
  451. bits = 1;
  452. else if (portc->audio_format == AFMT_S8)
  453. bits = 0;
  454. else
  455. bits = 2; //default AFMT_U8
  456. return bits;
  457. }
  458. static int
  459. waveartist_prepare_for_input(int dev, int bsize, int bcount)
  460. {
  461. unsigned long flags;
  462. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  463. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  464. unsigned int speed, bits;
  465. if (devc->audio_mode)
  466. return 0;
  467. speed = waveartist_get_speed(portc);
  468. bits = waveartist_get_bits(portc);
  469. spin_lock_irqsave(&waveartist_lock, flags);
  470. if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
  471. printk(KERN_WARNING "waveartist: error setting the "
  472. "record format to %d\n", portc->audio_format);
  473. if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
  474. printk(KERN_WARNING "waveartist: error setting record "
  475. "to %d channels\n", portc->channels);
  476. /*
  477. * write cmd SetSampleSpeedTimeConstant
  478. */
  479. if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
  480. printk(KERN_WARNING "waveartist: error setting the record "
  481. "speed to %dHz.\n", portc->speed);
  482. if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
  483. printk(KERN_WARNING "waveartist: error setting the record "
  484. "data path to 0x%X\n", 1);
  485. if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
  486. printk(KERN_WARNING "waveartist: error setting the record "
  487. "format to %d\n", portc->audio_format);
  488. devc->xfer_count = 0;
  489. spin_unlock_irqrestore(&waveartist_lock, flags);
  490. waveartist_halt_input(dev);
  491. if (debug_flg & DEBUG_INTR) {
  492. printk("WA CTLR reg: 0x%02X.\n",
  493. inb(devc->hw.io_base + CTLR));
  494. printk("WA STAT reg: 0x%02X.\n",
  495. inb(devc->hw.io_base + STATR));
  496. printk("WA IRQS reg: 0x%02X.\n",
  497. inb(devc->hw.io_base + IRQSTAT));
  498. }
  499. return 0;
  500. }
  501. static int
  502. waveartist_prepare_for_output(int dev, int bsize, int bcount)
  503. {
  504. unsigned long flags;
  505. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  506. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  507. unsigned int speed, bits;
  508. /*
  509. * program the speed, channels, bits
  510. */
  511. speed = waveartist_get_speed(portc);
  512. bits = waveartist_get_bits(portc);
  513. spin_lock_irqsave(&waveartist_lock, flags);
  514. if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
  515. waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
  516. printk(KERN_WARNING "waveartist: error setting the playback "
  517. "speed to %dHz.\n", portc->speed);
  518. if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
  519. printk(KERN_WARNING "waveartist: error setting the playback "
  520. "to %d channels\n", portc->channels);
  521. if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
  522. printk(KERN_WARNING "waveartist: error setting the playback "
  523. "data path to 0x%X\n", 0);
  524. if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
  525. printk(KERN_WARNING "waveartist: error setting the playback "
  526. "format to %d\n", portc->audio_format);
  527. devc->xfer_count = 0;
  528. spin_unlock_irqrestore(&waveartist_lock, flags);
  529. waveartist_halt_output(dev);
  530. if (debug_flg & DEBUG_INTR) {
  531. printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
  532. printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
  533. printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
  534. }
  535. return 0;
  536. }
  537. static void
  538. waveartist_halt(int dev)
  539. {
  540. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  541. wavnc_info *devc;
  542. if (portc->open_mode & OPEN_WRITE)
  543. waveartist_halt_output(dev);
  544. if (portc->open_mode & OPEN_READ)
  545. waveartist_halt_input(dev);
  546. devc = (wavnc_info *) audio_devs[dev]->devc;
  547. devc->audio_mode = 0;
  548. }
  549. static void
  550. waveartist_halt_input(int dev)
  551. {
  552. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  553. unsigned long flags;
  554. spin_lock_irqsave(&waveartist_lock, flags);
  555. /*
  556. * Stop capture
  557. */
  558. waveartist_cmd1(devc, WACMD_INPUTSTOP);
  559. devc->audio_mode &= ~PCM_ENABLE_INPUT;
  560. /*
  561. * Clear interrupt by toggling
  562. * the IRQ_ACK bit in CTRL
  563. */
  564. if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
  565. waveartist_iack(devc);
  566. // devc->audio_mode &= ~PCM_ENABLE_INPUT;
  567. spin_unlock_irqrestore(&waveartist_lock, flags);
  568. }
  569. static void
  570. waveartist_halt_output(int dev)
  571. {
  572. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  573. unsigned long flags;
  574. spin_lock_irqsave(&waveartist_lock, flags);
  575. waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
  576. devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
  577. /*
  578. * Clear interrupt by toggling
  579. * the IRQ_ACK bit in CTRL
  580. */
  581. if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
  582. waveartist_iack(devc);
  583. // devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
  584. spin_unlock_irqrestore(&waveartist_lock, flags);
  585. }
  586. static void
  587. waveartist_trigger(int dev, int state)
  588. {
  589. wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
  590. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  591. unsigned long flags;
  592. if (debug_flg & DEBUG_TRIGGER) {
  593. printk("wavnc: audio trigger ");
  594. if (state & PCM_ENABLE_INPUT)
  595. printk("in ");
  596. if (state & PCM_ENABLE_OUTPUT)
  597. printk("out");
  598. printk("\n");
  599. }
  600. spin_lock_irqsave(&waveartist_lock, flags);
  601. state &= devc->audio_mode;
  602. if (portc->open_mode & OPEN_READ &&
  603. state & PCM_ENABLE_INPUT)
  604. /*
  605. * enable ADC Data Transfer to PC
  606. */
  607. waveartist_cmd1(devc, WACMD_INPUTSTART);
  608. if (portc->open_mode & OPEN_WRITE &&
  609. state & PCM_ENABLE_OUTPUT)
  610. /*
  611. * enable DAC data transfer from PC
  612. */
  613. waveartist_cmd1(devc, WACMD_OUTPUTSTART);
  614. spin_unlock_irqrestore(&waveartist_lock, flags);
  615. }
  616. static int
  617. waveartist_set_speed(int dev, int arg)
  618. {
  619. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  620. if (arg <= 0)
  621. return portc->speed;
  622. if (arg < 5000)
  623. arg = 5000;
  624. if (arg > 44100)
  625. arg = 44100;
  626. portc->speed = arg;
  627. return portc->speed;
  628. }
  629. static short
  630. waveartist_set_channels(int dev, short arg)
  631. {
  632. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  633. if (arg != 1 && arg != 2)
  634. return portc->channels;
  635. portc->channels = arg;
  636. return arg;
  637. }
  638. static unsigned int
  639. waveartist_set_bits(int dev, unsigned int arg)
  640. {
  641. wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
  642. if (arg == 0)
  643. return portc->audio_format;
  644. if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
  645. arg = AFMT_U8;
  646. portc->audio_format = arg;
  647. return arg;
  648. }
  649. static struct audio_driver waveartist_audio_driver = {
  650. .owner = THIS_MODULE,
  651. .open = waveartist_open,
  652. .close = waveartist_close,
  653. .output_block = waveartist_output_block,
  654. .start_input = waveartist_start_input,
  655. .ioctl = waveartist_ioctl,
  656. .prepare_for_input = waveartist_prepare_for_input,
  657. .prepare_for_output = waveartist_prepare_for_output,
  658. .halt_io = waveartist_halt,
  659. .halt_input = waveartist_halt_input,
  660. .halt_output = waveartist_halt_output,
  661. .trigger = waveartist_trigger,
  662. .set_speed = waveartist_set_speed,
  663. .set_bits = waveartist_set_bits,
  664. .set_channels = waveartist_set_channels
  665. };
  666. static irqreturn_t
  667. waveartist_intr(int irq, void *dev_id)
  668. {
  669. wavnc_info *devc = dev_id;
  670. int irqstatus, status;
  671. spin_lock(&waveartist_lock);
  672. irqstatus = inb(devc->hw.io_base + IRQSTAT);
  673. status = inb(devc->hw.io_base + STATR);
  674. if (debug_flg & DEBUG_INTR)
  675. printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
  676. status, irqstatus);
  677. if (status & IRQ_REQ) /* Clear interrupt */
  678. waveartist_iack(devc);
  679. else
  680. printk(KERN_WARNING "waveartist: unexpected interrupt\n");
  681. if (irqstatus & 0x01) {
  682. int temp = 1;
  683. /* PCM buffer done
  684. */
  685. if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
  686. DMAbuf_outputintr(devc->playback_dev, 1);
  687. temp = 0;
  688. }
  689. if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
  690. DMAbuf_inputintr(devc->record_dev);
  691. temp = 0;
  692. }
  693. if (temp) //default:
  694. printk(KERN_WARNING "waveartist: Unknown interrupt\n");
  695. }
  696. if (irqstatus & 0x2)
  697. // We do not use SB mode natively...
  698. printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
  699. spin_unlock(&waveartist_lock);
  700. return IRQ_HANDLED;
  701. }
  702. /* -------------------------------------------------------------------------
  703. * Mixer stuff
  704. */
  705. struct mix_ent {
  706. unsigned char reg_l;
  707. unsigned char reg_r;
  708. unsigned char shift;
  709. unsigned char max;
  710. };
  711. static const struct mix_ent mix_devs[SOUND_MIXER_NRDEVICES] = {
  712. { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
  713. { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
  714. { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
  715. { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
  716. { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
  717. { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
  718. { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
  719. { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
  720. { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
  721. { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
  722. { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
  723. #if 0
  724. { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
  725. { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
  726. #else
  727. { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
  728. { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
  729. #endif
  730. { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
  731. { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
  732. { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
  733. { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
  734. { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
  735. { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
  736. { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
  737. { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
  738. { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
  739. { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
  740. { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
  741. { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
  742. };
  743. static void
  744. waveartist_mixer_update(wavnc_info *devc, int whichDev)
  745. {
  746. unsigned int lev_left, lev_right;
  747. lev_left = devc->levels[whichDev] & 0xff;
  748. lev_right = devc->levels[whichDev] >> 8;
  749. if (lev_left > 100)
  750. lev_left = 100;
  751. if (lev_right > 100)
  752. lev_right = 100;
  753. #define SCALE(lev,max) ((lev) * (max) / 100)
  754. if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
  755. whichDev = SOUND_MIXER_VOLUME;
  756. if (mix_devs[whichDev].reg_l || mix_devs[whichDev].reg_r) {
  757. const struct mix_ent *mix = mix_devs + whichDev;
  758. unsigned int mask, left, right;
  759. mask = mix->max << mix->shift;
  760. lev_left = SCALE(lev_left, mix->max) << mix->shift;
  761. lev_right = SCALE(lev_right, mix->max) << mix->shift;
  762. /* read left setting */
  763. left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
  764. mix->reg_l << 8);
  765. /* read right setting */
  766. right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
  767. mix->reg_r << 8);
  768. left = (left & ~mask) | (lev_left & mask);
  769. right = (right & ~mask) | (lev_right & mask);
  770. /* write left,right back */
  771. waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
  772. } else {
  773. switch(whichDev) {
  774. case SOUND_MIXER_PCM:
  775. waveartist_cmd3(devc, WACMD_SET_LEVEL,
  776. SCALE(lev_left, 32767),
  777. SCALE(lev_right, 32767));
  778. break;
  779. case SOUND_MIXER_SYNTH:
  780. waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
  781. SCALE(lev_left, 32767),
  782. SCALE(lev_right, 32767));
  783. break;
  784. }
  785. }
  786. }
  787. /*
  788. * Set the ADC MUX to the specified values. We do NOT do any
  789. * checking of the values passed, since we assume that the
  790. * relevant *_select_input function has done that for us.
  791. */
  792. static void
  793. waveartist_set_adc_mux(wavnc_info *devc, char left_dev, char right_dev)
  794. {
  795. unsigned int reg_08, reg_09;
  796. reg_08 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0800);
  797. reg_09 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0900);
  798. reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
  799. waveartist_cmd3(devc, WACMD_SET_MIXER, reg_08, reg_09);
  800. }
  801. /*
  802. * Decode a recording mask into a mixer selection as follows:
  803. *
  804. * OSS Source WA Source Actual source
  805. * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
  806. * SOUND_MASK_LINE Line Line in
  807. * SOUND_MASK_LINE1 Aux 1 Aux 1 in
  808. * SOUND_MASK_LINE2 Aux 2 Aux 2 in
  809. * SOUND_MASK_MIC Mic Microphone
  810. */
  811. static unsigned int
  812. waveartist_select_input(wavnc_info *devc, unsigned int recmask,
  813. unsigned char *dev_l, unsigned char *dev_r)
  814. {
  815. unsigned int recdev = ADC_MUX_NONE;
  816. if (recmask & SOUND_MASK_IMIX) {
  817. recmask = SOUND_MASK_IMIX;
  818. recdev = ADC_MUX_MIXER;
  819. } else if (recmask & SOUND_MASK_LINE2) {
  820. recmask = SOUND_MASK_LINE2;
  821. recdev = ADC_MUX_AUX2;
  822. } else if (recmask & SOUND_MASK_LINE1) {
  823. recmask = SOUND_MASK_LINE1;
  824. recdev = ADC_MUX_AUX1;
  825. } else if (recmask & SOUND_MASK_LINE) {
  826. recmask = SOUND_MASK_LINE;
  827. recdev = ADC_MUX_LINE;
  828. } else if (recmask & SOUND_MASK_MIC) {
  829. recmask = SOUND_MASK_MIC;
  830. recdev = ADC_MUX_MIC;
  831. }
  832. *dev_l = *dev_r = recdev;
  833. return recmask;
  834. }
  835. static int
  836. waveartist_decode_mixer(wavnc_info *devc, int dev, unsigned char lev_l,
  837. unsigned char lev_r)
  838. {
  839. switch (dev) {
  840. case SOUND_MIXER_VOLUME:
  841. case SOUND_MIXER_SYNTH:
  842. case SOUND_MIXER_PCM:
  843. case SOUND_MIXER_LINE:
  844. case SOUND_MIXER_MIC:
  845. case SOUND_MIXER_IGAIN:
  846. case SOUND_MIXER_LINE1:
  847. case SOUND_MIXER_LINE2:
  848. devc->levels[dev] = lev_l | lev_r << 8;
  849. break;
  850. case SOUND_MIXER_IMIX:
  851. break;
  852. default:
  853. dev = -EINVAL;
  854. break;
  855. }
  856. return dev;
  857. }
  858. static int waveartist_get_mixer(wavnc_info *devc, int dev)
  859. {
  860. return devc->levels[dev];
  861. }
  862. static const struct waveartist_mixer_info waveartist_mixer = {
  863. .supported_devs = SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN,
  864. .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
  865. SOUND_MASK_LINE1 | SOUND_MASK_LINE2 |
  866. SOUND_MASK_IMIX,
  867. .stereo_devs = (SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN) & ~
  868. (SOUND_MASK_SPEAKER | SOUND_MASK_IMIX),
  869. .select_input = waveartist_select_input,
  870. .decode_mixer = waveartist_decode_mixer,
  871. .get_mixer = waveartist_get_mixer,
  872. };
  873. static void
  874. waveartist_set_recmask(wavnc_info *devc, unsigned int recmask)
  875. {
  876. unsigned char dev_l, dev_r;
  877. recmask &= devc->mix->recording_devs;
  878. /*
  879. * If more than one recording device selected,
  880. * disable the device that is currently in use.
  881. */
  882. if (hweight32(recmask) > 1)
  883. recmask &= ~devc->recmask;
  884. /*
  885. * Translate the recording device mask into
  886. * the ADC multiplexer settings.
  887. */
  888. devc->recmask = devc->mix->select_input(devc, recmask,
  889. &dev_l, &dev_r);
  890. waveartist_set_adc_mux(devc, dev_l, dev_r);
  891. }
  892. static int
  893. waveartist_set_mixer(wavnc_info *devc, int dev, unsigned int level)
  894. {
  895. unsigned int lev_left = level & 0x00ff;
  896. unsigned int lev_right = (level & 0xff00) >> 8;
  897. if (lev_left > 100)
  898. lev_left = 100;
  899. if (lev_right > 100)
  900. lev_right = 100;
  901. /*
  902. * Mono devices have their right volume forced to their
  903. * left volume. (from ALSA driver OSS emulation).
  904. */
  905. if (!(devc->mix->stereo_devs & (1 << dev)))
  906. lev_right = lev_left;
  907. dev = devc->mix->decode_mixer(devc, dev, lev_left, lev_right);
  908. if (dev >= 0)
  909. waveartist_mixer_update(devc, dev);
  910. return dev < 0 ? dev : 0;
  911. }
  912. static int
  913. waveartist_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
  914. {
  915. wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
  916. int ret = 0, val, nr;
  917. /*
  918. * All SOUND_MIXER_* ioctls use type 'M'
  919. */
  920. if (((cmd >> 8) & 255) != 'M')
  921. return -ENOIOCTLCMD;
  922. #ifdef CONFIG_ARCH_NETWINDER
  923. if (machine_is_netwinder()) {
  924. ret = vnc_private_ioctl(dev, cmd, arg);
  925. if (ret != -ENOIOCTLCMD)
  926. return ret;
  927. else
  928. ret = 0;
  929. }
  930. #endif
  931. nr = cmd & 0xff;
  932. if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
  933. if (get_user(val, (int __user *)arg))
  934. return -EFAULT;
  935. switch (nr) {
  936. case SOUND_MIXER_RECSRC:
  937. waveartist_set_recmask(devc, val);
  938. break;
  939. default:
  940. ret = -EINVAL;
  941. if (nr < SOUND_MIXER_NRDEVICES &&
  942. devc->mix->supported_devs & (1 << nr))
  943. ret = waveartist_set_mixer(devc, nr, val);
  944. }
  945. }
  946. if (ret == 0 && _SIOC_DIR(cmd) & _SIOC_READ) {
  947. ret = -EINVAL;
  948. switch (nr) {
  949. case SOUND_MIXER_RECSRC:
  950. ret = devc->recmask;
  951. break;
  952. case SOUND_MIXER_DEVMASK:
  953. ret = devc->mix->supported_devs;
  954. break;
  955. case SOUND_MIXER_STEREODEVS:
  956. ret = devc->mix->stereo_devs;
  957. break;
  958. case SOUND_MIXER_RECMASK:
  959. ret = devc->mix->recording_devs;
  960. break;
  961. case SOUND_MIXER_CAPS:
  962. ret = SOUND_CAP_EXCL_INPUT;
  963. break;
  964. default:
  965. if (nr < SOUND_MIXER_NRDEVICES)
  966. ret = devc->mix->get_mixer(devc, nr);
  967. break;
  968. }
  969. if (ret >= 0)
  970. ret = put_user(ret, (int __user *)arg) ? -EFAULT : 0;
  971. }
  972. return ret;
  973. }
  974. static struct mixer_operations waveartist_mixer_operations =
  975. {
  976. .owner = THIS_MODULE,
  977. .id = "WaveArtist",
  978. .name = "WaveArtist",
  979. .ioctl = waveartist_mixer_ioctl
  980. };
  981. static void
  982. waveartist_mixer_reset(wavnc_info *devc)
  983. {
  984. int i;
  985. if (debug_flg & DEBUG_MIXER)
  986. printk("%s: mixer_reset\n", devc->hw.name);
  987. /*
  988. * reset mixer cmd
  989. */
  990. waveartist_cmd1(devc, WACMD_RST_MIXER);
  991. /*
  992. * set input for ADC to come from 'quiet'
  993. * turn on default modes
  994. */
  995. waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
  996. /*
  997. * set mixer input select to none, RX filter gains 0 dB
  998. */
  999. waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
  1000. /*
  1001. * set bit 0 reg 2 to 1 - unmute MonoOut
  1002. */
  1003. waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
  1004. /* set default input device = internal mic
  1005. * current recording device = none
  1006. */
  1007. waveartist_set_recmask(devc, 0);
  1008. for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
  1009. waveartist_mixer_update(devc, i);
  1010. }
  1011. static int __init waveartist_init(wavnc_info *devc)
  1012. {
  1013. wavnc_port_info *portc;
  1014. char rev[3], dev_name[64];
  1015. int my_dev;
  1016. if (waveartist_reset(devc))
  1017. return -ENODEV;
  1018. sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
  1019. if (waveartist_getrev(devc, rev)) {
  1020. strcat(dev_name, " rev. ");
  1021. strcat(dev_name, rev);
  1022. }
  1023. strcat(dev_name, ")");
  1024. conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
  1025. devc->hw.dma, devc->hw.dma2);
  1026. portc = kzalloc(sizeof(wavnc_port_info), GFP_KERNEL);
  1027. if (portc == NULL)
  1028. goto nomem;
  1029. my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
  1030. &waveartist_audio_driver, sizeof(struct audio_driver),
  1031. devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
  1032. devc, devc->hw.dma, devc->hw.dma2);
  1033. if (my_dev < 0)
  1034. goto free;
  1035. audio_devs[my_dev]->portc = portc;
  1036. waveartist_mixer_reset(devc);
  1037. /*
  1038. * clear any pending interrupt
  1039. */
  1040. waveartist_iack(devc);
  1041. if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
  1042. printk(KERN_ERR "%s: IRQ %d in use\n",
  1043. devc->hw.name, devc->hw.irq);
  1044. goto uninstall;
  1045. }
  1046. if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
  1047. printk(KERN_ERR "%s: Can't allocate DMA%d\n",
  1048. devc->hw.name, devc->hw.dma);
  1049. goto uninstall_irq;
  1050. }
  1051. if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
  1052. if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
  1053. printk(KERN_ERR "%s: can't allocate DMA%d\n",
  1054. devc->hw.name, devc->hw.dma2);
  1055. goto uninstall_dma;
  1056. }
  1057. waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
  1058. audio_devs[my_dev]->mixer_dev =
  1059. sound_install_mixer(MIXER_DRIVER_VERSION,
  1060. dev_name,
  1061. &waveartist_mixer_operations,
  1062. sizeof(struct mixer_operations),
  1063. devc);
  1064. return my_dev;
  1065. uninstall_dma:
  1066. sound_free_dma(devc->hw.dma);
  1067. uninstall_irq:
  1068. free_irq(devc->hw.irq, devc);
  1069. uninstall:
  1070. sound_unload_audiodev(my_dev);
  1071. free:
  1072. kfree(portc);
  1073. nomem:
  1074. return -1;
  1075. }
  1076. static int __init probe_waveartist(struct address_info *hw_config)
  1077. {
  1078. wavnc_info *devc = &adev_info[nr_waveartist_devs];
  1079. if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
  1080. printk(KERN_WARNING "waveartist: too many audio devices\n");
  1081. return 0;
  1082. }
  1083. if (!request_region(hw_config->io_base, 15, hw_config->name)) {
  1084. printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
  1085. return 0;
  1086. }
  1087. if (hw_config->irq > 15 || hw_config->irq < 0) {
  1088. release_region(hw_config->io_base, 15);
  1089. printk(KERN_WARNING "WaveArtist: Bad IRQ %d\n",
  1090. hw_config->irq);
  1091. return 0;
  1092. }
  1093. if (hw_config->dma != 3) {
  1094. release_region(hw_config->io_base, 15);
  1095. printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
  1096. hw_config->dma);
  1097. return 0;
  1098. }
  1099. hw_config->name = "WaveArtist";
  1100. devc->hw = *hw_config;
  1101. devc->open_mode = 0;
  1102. devc->chip_name = "RWA-010";
  1103. return 1;
  1104. }
  1105. static void __init
  1106. attach_waveartist(struct address_info *hw, const struct waveartist_mixer_info *mix)
  1107. {
  1108. wavnc_info *devc = &adev_info[nr_waveartist_devs];
  1109. /*
  1110. * NOTE! If irq < 0, there is another driver which has allocated the
  1111. * IRQ so that this driver doesn't need to allocate/deallocate it.
  1112. * The actually used IRQ is ABS(irq).
  1113. */
  1114. devc->hw = *hw;
  1115. devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
  1116. devc->open_mode = 0;
  1117. devc->playback_dev = 0;
  1118. devc->record_dev = 0;
  1119. devc->audio_flags = DMA_AUTOMODE;
  1120. devc->levels = levels;
  1121. if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
  1122. devc->audio_flags |= DMA_DUPLEX;
  1123. devc->mix = mix;
  1124. devc->dev_no = waveartist_init(devc);
  1125. if (devc->dev_no < 0)
  1126. release_region(hw->io_base, 15);
  1127. else {
  1128. #ifdef CONFIG_ARCH_NETWINDER
  1129. if (machine_is_netwinder()) {
  1130. init_timer(&vnc_timer);
  1131. vnc_timer.function = vnc_slider_tick;
  1132. vnc_timer.expires = jiffies;
  1133. vnc_timer.data = nr_waveartist_devs;
  1134. add_timer(&vnc_timer);
  1135. vnc_configure_mixer(devc, 0);
  1136. devc->no_autoselect = 1;
  1137. }
  1138. #endif
  1139. nr_waveartist_devs += 1;
  1140. }
  1141. }
  1142. static void __exit unload_waveartist(struct address_info *hw)
  1143. {
  1144. wavnc_info *devc = NULL;
  1145. int i;
  1146. for (i = 0; i < nr_waveartist_devs; i++)
  1147. if (hw->io_base == adev_info[i].hw.io_base) {
  1148. devc = adev_info + i;
  1149. break;
  1150. }
  1151. if (devc != NULL) {
  1152. int mixer;
  1153. #ifdef CONFIG_ARCH_NETWINDER
  1154. if (machine_is_netwinder())
  1155. del_timer(&vnc_timer);
  1156. #endif
  1157. release_region(devc->hw.io_base, 15);
  1158. waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
  1159. if (devc->hw.irq >= 0)
  1160. free_irq(devc->hw.irq, devc);
  1161. sound_free_dma(devc->hw.dma);
  1162. if (devc->hw.dma != devc->hw.dma2 &&
  1163. devc->hw.dma2 != NO_DMA)
  1164. sound_free_dma(devc->hw.dma2);
  1165. mixer = audio_devs[devc->dev_no]->mixer_dev;
  1166. if (mixer >= 0)
  1167. sound_unload_mixerdev(mixer);
  1168. if (devc->dev_no >= 0)
  1169. sound_unload_audiodev(devc->dev_no);
  1170. nr_waveartist_devs -= 1;
  1171. for (; i < nr_waveartist_devs; i++)
  1172. adev_info[i] = adev_info[i + 1];
  1173. } else
  1174. printk(KERN_WARNING "waveartist: can't find device "
  1175. "to unload\n");
  1176. }
  1177. #ifdef CONFIG_ARCH_NETWINDER
  1178. /*
  1179. * Rebel.com Netwinder specifics...
  1180. */
  1181. #include <asm/hardware/dec21285.h>
  1182. #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
  1183. #define MIXER_PRIVATE3_RESET 0x53570000
  1184. #define MIXER_PRIVATE3_READ 0x53570001
  1185. #define MIXER_PRIVATE3_WRITE 0x53570002
  1186. #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
  1187. #define VNC_MUTE_LINE_OUT 0x10
  1188. #define VNC_PHONE_DETECT 0x20
  1189. #define VNC_HANDSET_DETECT 0x40
  1190. #define VNC_DISABLE_AUTOSWITCH 0x80
  1191. static inline void
  1192. vnc_mute_spkr(wavnc_info *devc)
  1193. {
  1194. unsigned long flags;
  1195. spin_lock_irqsave(&nw_gpio_lock, flags);
  1196. nw_cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
  1197. spin_unlock_irqrestore(&nw_gpio_lock, flags);
  1198. }
  1199. static void
  1200. vnc_mute_lout(wavnc_info *devc)
  1201. {
  1202. unsigned int left, right;
  1203. left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
  1204. right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
  1205. if (devc->line_mute_state) {
  1206. left &= ~1;
  1207. right &= ~1;
  1208. } else {
  1209. left |= 1;
  1210. right |= 1;
  1211. }
  1212. waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
  1213. }
  1214. static int
  1215. vnc_volume_slider(wavnc_info *devc)
  1216. {
  1217. static signed int old_slider_volume;
  1218. unsigned long flags;
  1219. signed int volume = 255;
  1220. *CSR_TIMER1_LOAD = 0x00ffffff;
  1221. spin_lock_irqsave(&waveartist_lock, flags);
  1222. outb(0xFF, 0x201);
  1223. *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
  1224. while (volume && (inb(0x201) & 0x01))
  1225. volume--;
  1226. *CSR_TIMER1_CNTL = 0;
  1227. spin_unlock_irqrestore(&waveartist_lock,flags);
  1228. volume = 0x00ffffff - *CSR_TIMER1_VALUE;
  1229. #ifndef REVERSE
  1230. volume = 150 - (volume >> 5);
  1231. #else
  1232. volume = (volume >> 6) - 25;
  1233. #endif
  1234. if (volume < 0)
  1235. volume = 0;
  1236. if (volume > 100)
  1237. volume = 100;
  1238. /*
  1239. * slider quite often reads +-8, so debounce this random noise
  1240. */
  1241. if (abs(volume - old_slider_volume) > 7) {
  1242. old_slider_volume = volume;
  1243. if (debug_flg & DEBUG_MIXER)
  1244. printk(KERN_DEBUG "Slider volume: %d.\n", volume);
  1245. }
  1246. return old_slider_volume;
  1247. }
  1248. /*
  1249. * Decode a recording mask into a mixer selection on the NetWinder
  1250. * as follows:
  1251. *
  1252. * OSS Source WA Source Actual source
  1253. * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
  1254. * SOUND_MASK_LINE Line Line in
  1255. * SOUND_MASK_LINE1 Left Mic Handset
  1256. * SOUND_MASK_PHONEIN Left Aux Telephone microphone
  1257. * SOUND_MASK_MIC Right Mic Builtin microphone
  1258. */
  1259. static unsigned int
  1260. netwinder_select_input(wavnc_info *devc, unsigned int recmask,
  1261. unsigned char *dev_l, unsigned char *dev_r)
  1262. {
  1263. unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
  1264. if (recmask & SOUND_MASK_IMIX) {
  1265. recmask = SOUND_MASK_IMIX;
  1266. recdev_l = ADC_MUX_MIXER;
  1267. recdev_r = ADC_MUX_MIXER;
  1268. } else if (recmask & SOUND_MASK_LINE) {
  1269. recmask = SOUND_MASK_LINE;
  1270. recdev_l = ADC_MUX_LINE;
  1271. recdev_r = ADC_MUX_LINE;
  1272. } else if (recmask & SOUND_MASK_LINE1) {
  1273. recmask = SOUND_MASK_LINE1;
  1274. waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
  1275. recdev_l = ADC_MUX_MIC;
  1276. recdev_r = ADC_MUX_NONE;
  1277. } else if (recmask & SOUND_MASK_PHONEIN) {
  1278. recmask = SOUND_MASK_PHONEIN;
  1279. waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
  1280. recdev_l = ADC_MUX_AUX1;
  1281. recdev_r = ADC_MUX_NONE;
  1282. } else if (recmask & SOUND_MASK_MIC) {
  1283. recmask = SOUND_MASK_MIC;
  1284. waveartist_cmd1(devc, WACMD_SET_MONO | 0x100); /* right */
  1285. recdev_l = ADC_MUX_NONE;
  1286. recdev_r = ADC_MUX_MIC;
  1287. }
  1288. *dev_l = recdev_l;
  1289. *dev_r = recdev_r;
  1290. return recmask;
  1291. }
  1292. static int
  1293. netwinder_decode_mixer(wavnc_info *devc, int dev, unsigned char lev_l,
  1294. unsigned char lev_r)
  1295. {
  1296. switch (dev) {
  1297. case SOUND_MIXER_VOLUME:
  1298. case SOUND_MIXER_SYNTH:
  1299. case SOUND_MIXER_PCM:
  1300. case SOUND_MIXER_LINE:
  1301. case SOUND_MIXER_IGAIN:
  1302. devc->levels[dev] = lev_l | lev_r << 8;
  1303. break;
  1304. case SOUND_MIXER_MIC: /* right mic only */
  1305. devc->levels[SOUND_MIXER_MIC] &= 0xff;
  1306. devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
  1307. break;
  1308. case SOUND_MIXER_LINE1: /* left mic only */
  1309. devc->levels[SOUND_MIXER_MIC] &= 0xff00;
  1310. devc->levels[SOUND_MIXER_MIC] |= lev_l;
  1311. dev = SOUND_MIXER_MIC;
  1312. break;
  1313. case SOUND_MIXER_PHONEIN: /* left aux only */
  1314. devc->levels[SOUND_MIXER_LINE1] = lev_l;
  1315. dev = SOUND_MIXER_LINE1;
  1316. break;
  1317. case SOUND_MIXER_IMIX:
  1318. case SOUND_MIXER_PHONEOUT:
  1319. break;
  1320. default:
  1321. dev = -EINVAL;
  1322. break;
  1323. }
  1324. return dev;
  1325. }
  1326. static int netwinder_get_mixer(wavnc_info *devc, int dev)
  1327. {
  1328. int levels;
  1329. switch (dev) {
  1330. case SOUND_MIXER_VOLUME:
  1331. case SOUND_MIXER_SYNTH:
  1332. case SOUND_MIXER_PCM:
  1333. case SOUND_MIXER_LINE:
  1334. case SOUND_MIXER_IGAIN:
  1335. levels = devc->levels[dev];
  1336. break;
  1337. case SOUND_MIXER_MIC: /* builtin mic: right mic only */
  1338. levels = devc->levels[SOUND_MIXER_MIC] >> 8;
  1339. levels |= levels << 8;
  1340. break;
  1341. case SOUND_MIXER_LINE1: /* handset mic: left mic only */
  1342. levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
  1343. levels |= levels << 8;
  1344. break;
  1345. case SOUND_MIXER_PHONEIN: /* phone mic: left aux1 only */
  1346. levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
  1347. levels |= levels << 8;
  1348. break;
  1349. default:
  1350. levels = 0;
  1351. }
  1352. return levels;
  1353. }
  1354. /*
  1355. * Waveartist specific mixer information.
  1356. */
  1357. static const struct waveartist_mixer_info netwinder_mixer = {
  1358. .supported_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
  1359. SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
  1360. SOUND_MASK_LINE | SOUND_MASK_MIC |
  1361. SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
  1362. SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT|
  1363. SOUND_MASK_IGAIN,
  1364. .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
  1365. SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
  1366. SOUND_MASK_PHONEIN,
  1367. .stereo_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
  1368. SOUND_MASK_PCM | SOUND_MASK_LINE |
  1369. SOUND_MASK_IMIX | SOUND_MASK_IGAIN,
  1370. .select_input = netwinder_select_input,
  1371. .decode_mixer = netwinder_decode_mixer,
  1372. .get_mixer = netwinder_get_mixer,
  1373. };
  1374. static void
  1375. vnc_configure_mixer(wavnc_info *devc, unsigned int recmask)
  1376. {
  1377. if (!devc->no_autoselect) {
  1378. if (devc->handset_detect) {
  1379. recmask = SOUND_MASK_LINE1;
  1380. devc->spkr_mute_state = devc->line_mute_state = 1;
  1381. } else if (devc->telephone_detect) {
  1382. recmask = SOUND_MASK_PHONEIN;
  1383. devc->spkr_mute_state = devc->line_mute_state = 1;
  1384. } else {
  1385. /* unless someone has asked for LINE-IN,
  1386. * we default to MIC
  1387. */
  1388. if ((devc->recmask & SOUND_MASK_LINE) == 0)
  1389. devc->recmask = SOUND_MASK_MIC;
  1390. devc->spkr_mute_state = devc->line_mute_state = 0;
  1391. }
  1392. vnc_mute_spkr(devc);
  1393. vnc_mute_lout(devc);
  1394. if (recmask != devc->recmask)
  1395. waveartist_set_recmask(devc, recmask);
  1396. }
  1397. }
  1398. static int
  1399. vnc_slider(wavnc_info *devc)
  1400. {
  1401. signed int slider_volume;
  1402. unsigned int temp, old_hs, old_td;
  1403. /*
  1404. * read the "buttons" state.
  1405. * Bit 4 = 0 means handset present
  1406. * Bit 5 = 1 means phone offhook
  1407. */
  1408. temp = inb(0x201);
  1409. old_hs = devc->handset_detect;
  1410. old_td = devc->telephone_detect;
  1411. devc->handset_detect = !(temp & 0x10);
  1412. devc->telephone_detect = !!(temp & 0x20);
  1413. if (!devc->no_autoselect &&
  1414. (old_hs != devc->handset_detect ||
  1415. old_td != devc->telephone_detect))
  1416. vnc_configure_mixer(devc, devc->recmask);
  1417. slider_volume = vnc_volume_slider(devc);
  1418. /*
  1419. * If we're using software controlled volume, and
  1420. * the slider moves by more than 20%, then we
  1421. * switch back to slider controlled volume.
  1422. */
  1423. if (abs(devc->slider_vol - slider_volume) > 20)
  1424. devc->use_slider = 1;
  1425. /*
  1426. * use only left channel
  1427. */
  1428. temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
  1429. if (slider_volume != temp && devc->use_slider) {
  1430. devc->slider_vol = slider_volume;
  1431. waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
  1432. slider_volume | slider_volume << 8);
  1433. return 1;
  1434. }
  1435. return 0;
  1436. }
  1437. static void
  1438. vnc_slider_tick(unsigned long data)
  1439. {
  1440. int next_timeout;
  1441. if (vnc_slider(adev_info + data))
  1442. next_timeout = 5; // mixer reported change
  1443. else
  1444. next_timeout = VNC_TIMER_PERIOD;
  1445. mod_timer(&vnc_timer, jiffies + next_timeout);
  1446. }
  1447. static int
  1448. vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
  1449. {
  1450. wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
  1451. int val;
  1452. switch (cmd) {
  1453. case SOUND_MIXER_PRIVATE1:
  1454. {
  1455. u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
  1456. int val;
  1457. if (get_user(val, arg))
  1458. return -EFAULT;
  1459. /* check if parameter is logical */
  1460. if (val & ~(VNC_MUTE_INTERNAL_SPKR |
  1461. VNC_MUTE_LINE_OUT |
  1462. VNC_DISABLE_AUTOSWITCH))
  1463. return -EINVAL;
  1464. prev_auto_state = devc->no_autoselect;
  1465. prev_spkr_mute = devc->spkr_mute_state;
  1466. prev_line_mute = devc->line_mute_state;
  1467. devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
  1468. devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
  1469. devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
  1470. if (prev_spkr_mute != devc->spkr_mute_state)
  1471. vnc_mute_spkr(devc);
  1472. if (prev_line_mute != devc->line_mute_state)
  1473. vnc_mute_lout(devc);
  1474. if (prev_auto_state != devc->no_autoselect)
  1475. vnc_configure_mixer(devc, devc->recmask);
  1476. return 0;
  1477. }
  1478. case SOUND_MIXER_PRIVATE2:
  1479. if (get_user(val, arg))
  1480. return -EFAULT;
  1481. switch (val) {
  1482. #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
  1483. #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
  1484. case VNC_SOUND_PAUSE:
  1485. waveartist_cmd1(devc, 0x16);
  1486. break;
  1487. case VNC_SOUND_RESUME:
  1488. waveartist_cmd1(devc, 0x18);
  1489. break;
  1490. default:
  1491. return -EINVAL;
  1492. }
  1493. return 0;
  1494. /* private ioctl to allow bulk access to waveartist */
  1495. case SOUND_MIXER_PRIVATE3:
  1496. {
  1497. unsigned long flags;
  1498. int mixer_reg[15], i, val;
  1499. if (get_user(val, arg))
  1500. return -EFAULT;
  1501. if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
  1502. return -EFAULT;
  1503. switch (mixer_reg[14]) {
  1504. case MIXER_PRIVATE3_RESET:
  1505. waveartist_mixer_reset(devc);
  1506. break;
  1507. case MIXER_PRIVATE3_WRITE:
  1508. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
  1509. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
  1510. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
  1511. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
  1512. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
  1513. waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
  1514. waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
  1515. break;
  1516. case MIXER_PRIVATE3_READ:
  1517. spin_lock_irqsave(&waveartist_lock, flags);
  1518. for (i = 0x30; i < 14 << 8; i += 1 << 8)
  1519. waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
  1520. spin_unlock_irqrestore(&waveartist_lock, flags);
  1521. if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
  1522. return -EFAULT;
  1523. break;
  1524. default:
  1525. return -EINVAL;
  1526. }
  1527. return 0;
  1528. }
  1529. /* read back the state from PRIVATE1 */
  1530. case SOUND_MIXER_PRIVATE4:
  1531. val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
  1532. (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
  1533. (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
  1534. (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
  1535. (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
  1536. return put_user(val, arg) ? -EFAULT : 0;
  1537. }
  1538. if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
  1539. /*
  1540. * special case for master volume: if we
  1541. * received this call - switch from hw
  1542. * volume control to a software volume
  1543. * control, till the hw volume is modified
  1544. * to signal that user wants to be back in
  1545. * hardware...
  1546. */
  1547. if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
  1548. devc->use_slider = 0;
  1549. /* speaker output */
  1550. if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
  1551. unsigned int val, l, r;
  1552. if (get_user(val, arg))
  1553. return -EFAULT;
  1554. l = val & 0x7f;
  1555. r = (val & 0x7f00) >> 8;
  1556. val = (l + r) / 2;
  1557. devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
  1558. devc->spkr_mute_state = (val <= 50);
  1559. vnc_mute_spkr(devc);
  1560. return 0;
  1561. }
  1562. }
  1563. return -ENOIOCTLCMD;
  1564. }
  1565. #endif
  1566. static struct address_info cfg;
  1567. static int attached;
  1568. static int __initdata io = 0;
  1569. static int __initdata irq = 0;
  1570. static int __initdata dma = 0;
  1571. static int __initdata dma2 = 0;
  1572. static int __init init_waveartist(void)
  1573. {
  1574. const struct waveartist_mixer_info *mix;
  1575. if (!io && machine_is_netwinder()) {
  1576. /*
  1577. * The NetWinder WaveArtist is at a fixed address.
  1578. * If the user does not supply an address, use the
  1579. * well-known parameters.
  1580. */
  1581. io = 0x250;
  1582. irq = 12;
  1583. dma = 3;
  1584. dma2 = 7;
  1585. }
  1586. mix = &waveartist_mixer;
  1587. #ifdef CONFIG_ARCH_NETWINDER
  1588. if (machine_is_netwinder())
  1589. mix = &netwinder_mixer;
  1590. #endif
  1591. cfg.io_base = io;
  1592. cfg.irq = irq;
  1593. cfg.dma = dma;
  1594. cfg.dma2 = dma2;
  1595. if (!probe_waveartist(&cfg))
  1596. return -ENODEV;
  1597. attach_waveartist(&cfg, mix);
  1598. attached = 1;
  1599. return 0;
  1600. }
  1601. static void __exit cleanup_waveartist(void)
  1602. {
  1603. if (attached)
  1604. unload_waveartist(&cfg);
  1605. }
  1606. module_init(init_waveartist);
  1607. module_exit(cleanup_waveartist);
  1608. #ifndef MODULE
  1609. static int __init setup_waveartist(char *str)
  1610. {
  1611. /* io, irq, dma, dma2 */
  1612. int ints[5];
  1613. str = get_options(str, ARRAY_SIZE(ints), ints);
  1614. io = ints[1];
  1615. irq = ints[2];
  1616. dma = ints[3];
  1617. dma2 = ints[4];
  1618. return 1;
  1619. }
  1620. __setup("waveartist=", setup_waveartist);
  1621. #endif
  1622. MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
  1623. module_param(io, int, 0); /* IO base */
  1624. module_param(irq, int, 0); /* IRQ */
  1625. module_param(dma, int, 0); /* DMA */
  1626. module_param(dma2, int, 0); /* DMA2 */
  1627. MODULE_LICENSE("GPL");