waveartist.c 47 KB

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