waveartist.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044
  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. setup_timer(&vnc_timer, vnc_slider_tick,
  1148. nr_waveartist_devs);
  1149. mod_timer(&vnc_timer, jiffies);
  1150. vnc_configure_mixer(devc, 0);
  1151. devc->no_autoselect = 1;
  1152. }
  1153. #endif
  1154. nr_waveartist_devs += 1;
  1155. }
  1156. }
  1157. static void __exit unload_waveartist(struct address_info *hw)
  1158. {
  1159. struct wavnc_info *devc = NULL;
  1160. int i;
  1161. for (i = 0; i < nr_waveartist_devs; i++)
  1162. if (hw->io_base == adev_info[i].hw.io_base) {
  1163. devc = adev_info + i;
  1164. break;
  1165. }
  1166. if (devc != NULL) {
  1167. int mixer;
  1168. #ifdef CONFIG_ARCH_NETWINDER
  1169. if (machine_is_netwinder())
  1170. del_timer(&vnc_timer);
  1171. #endif
  1172. release_region(devc->hw.io_base, 15);
  1173. waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
  1174. if (devc->hw.irq >= 0)
  1175. free_irq(devc->hw.irq, devc);
  1176. sound_free_dma(devc->hw.dma);
  1177. if (devc->hw.dma != devc->hw.dma2 &&
  1178. devc->hw.dma2 != NO_DMA)
  1179. sound_free_dma(devc->hw.dma2);
  1180. mixer = audio_devs[devc->dev_no]->mixer_dev;
  1181. if (mixer >= 0)
  1182. sound_unload_mixerdev(mixer);
  1183. if (devc->dev_no >= 0)
  1184. sound_unload_audiodev(devc->dev_no);
  1185. nr_waveartist_devs -= 1;
  1186. for (; i < nr_waveartist_devs; i++)
  1187. adev_info[i] = adev_info[i + 1];
  1188. } else
  1189. printk(KERN_WARNING "waveartist: can't find device "
  1190. "to unload\n");
  1191. }
  1192. #ifdef CONFIG_ARCH_NETWINDER
  1193. /*
  1194. * Rebel.com Netwinder specifics...
  1195. */
  1196. #include <asm/hardware/dec21285.h>
  1197. #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
  1198. #define MIXER_PRIVATE3_RESET 0x53570000
  1199. #define MIXER_PRIVATE3_READ 0x53570001
  1200. #define MIXER_PRIVATE3_WRITE 0x53570002
  1201. #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
  1202. #define VNC_MUTE_LINE_OUT 0x10
  1203. #define VNC_PHONE_DETECT 0x20
  1204. #define VNC_HANDSET_DETECT 0x40
  1205. #define VNC_DISABLE_AUTOSWITCH 0x80
  1206. static inline void
  1207. vnc_mute_spkr(struct wavnc_info *devc)
  1208. {
  1209. unsigned long flags;
  1210. raw_spin_lock_irqsave(&nw_gpio_lock, flags);
  1211. nw_cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
  1212. raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
  1213. }
  1214. static void
  1215. vnc_mute_lout(struct wavnc_info *devc)
  1216. {
  1217. unsigned int left, right;
  1218. left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
  1219. right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
  1220. if (devc->line_mute_state) {
  1221. left &= ~1;
  1222. right &= ~1;
  1223. } else {
  1224. left |= 1;
  1225. right |= 1;
  1226. }
  1227. waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
  1228. }
  1229. static int
  1230. vnc_volume_slider(struct wavnc_info *devc)
  1231. {
  1232. static signed int old_slider_volume;
  1233. unsigned long flags;
  1234. signed int volume = 255;
  1235. *CSR_TIMER1_LOAD = 0x00ffffff;
  1236. spin_lock_irqsave(&waveartist_lock, flags);
  1237. outb(0xFF, 0x201);
  1238. *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
  1239. while (volume && (inb(0x201) & 0x01))
  1240. volume--;
  1241. *CSR_TIMER1_CNTL = 0;
  1242. spin_unlock_irqrestore(&waveartist_lock,flags);
  1243. volume = 0x00ffffff - *CSR_TIMER1_VALUE;
  1244. #ifndef REVERSE
  1245. volume = 150 - (volume >> 5);
  1246. #else
  1247. volume = (volume >> 6) - 25;
  1248. #endif
  1249. if (volume < 0)
  1250. volume = 0;
  1251. if (volume > 100)
  1252. volume = 100;
  1253. /*
  1254. * slider quite often reads +-8, so debounce this random noise
  1255. */
  1256. if (abs(volume - old_slider_volume) > 7) {
  1257. old_slider_volume = volume;
  1258. if (debug_flg & DEBUG_MIXER)
  1259. printk(KERN_DEBUG "Slider volume: %d.\n", volume);
  1260. }
  1261. return old_slider_volume;
  1262. }
  1263. /*
  1264. * Decode a recording mask into a mixer selection on the NetWinder
  1265. * as follows:
  1266. *
  1267. * OSS Source WA Source Actual source
  1268. * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
  1269. * SOUND_MASK_LINE Line Line in
  1270. * SOUND_MASK_LINE1 Left Mic Handset
  1271. * SOUND_MASK_PHONEIN Left Aux Telephone microphone
  1272. * SOUND_MASK_MIC Right Mic Builtin microphone
  1273. */
  1274. static unsigned int
  1275. netwinder_select_input(struct wavnc_info *devc, unsigned int recmask,
  1276. unsigned char *dev_l, unsigned char *dev_r)
  1277. {
  1278. unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
  1279. if (recmask & SOUND_MASK_IMIX) {
  1280. recmask = SOUND_MASK_IMIX;
  1281. recdev_l = ADC_MUX_MIXER;
  1282. recdev_r = ADC_MUX_MIXER;
  1283. } else if (recmask & SOUND_MASK_LINE) {
  1284. recmask = SOUND_MASK_LINE;
  1285. recdev_l = ADC_MUX_LINE;
  1286. recdev_r = ADC_MUX_LINE;
  1287. } else if (recmask & SOUND_MASK_LINE1) {
  1288. recmask = SOUND_MASK_LINE1;
  1289. waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
  1290. recdev_l = ADC_MUX_MIC;
  1291. recdev_r = ADC_MUX_NONE;
  1292. } else if (recmask & SOUND_MASK_PHONEIN) {
  1293. recmask = SOUND_MASK_PHONEIN;
  1294. waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
  1295. recdev_l = ADC_MUX_AUX1;
  1296. recdev_r = ADC_MUX_NONE;
  1297. } else if (recmask & SOUND_MASK_MIC) {
  1298. recmask = SOUND_MASK_MIC;
  1299. waveartist_cmd1(devc, WACMD_SET_MONO | 0x100); /* right */
  1300. recdev_l = ADC_MUX_NONE;
  1301. recdev_r = ADC_MUX_MIC;
  1302. }
  1303. *dev_l = recdev_l;
  1304. *dev_r = recdev_r;
  1305. return recmask;
  1306. }
  1307. static int
  1308. netwinder_decode_mixer(struct wavnc_info *devc, int dev, unsigned char lev_l,
  1309. unsigned char lev_r)
  1310. {
  1311. switch (dev) {
  1312. case SOUND_MIXER_VOLUME:
  1313. case SOUND_MIXER_SYNTH:
  1314. case SOUND_MIXER_PCM:
  1315. case SOUND_MIXER_LINE:
  1316. case SOUND_MIXER_IGAIN:
  1317. devc->levels[dev] = lev_l | lev_r << 8;
  1318. break;
  1319. case SOUND_MIXER_MIC: /* right mic only */
  1320. devc->levels[SOUND_MIXER_MIC] &= 0xff;
  1321. devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
  1322. break;
  1323. case SOUND_MIXER_LINE1: /* left mic only */
  1324. devc->levels[SOUND_MIXER_MIC] &= 0xff00;
  1325. devc->levels[SOUND_MIXER_MIC] |= lev_l;
  1326. dev = SOUND_MIXER_MIC;
  1327. break;
  1328. case SOUND_MIXER_PHONEIN: /* left aux only */
  1329. devc->levels[SOUND_MIXER_LINE1] = lev_l;
  1330. dev = SOUND_MIXER_LINE1;
  1331. break;
  1332. case SOUND_MIXER_IMIX:
  1333. case SOUND_MIXER_PHONEOUT:
  1334. break;
  1335. default:
  1336. dev = -EINVAL;
  1337. break;
  1338. }
  1339. return dev;
  1340. }
  1341. static int netwinder_get_mixer(struct wavnc_info *devc, int dev)
  1342. {
  1343. int levels;
  1344. switch (dev) {
  1345. case SOUND_MIXER_VOLUME:
  1346. case SOUND_MIXER_SYNTH:
  1347. case SOUND_MIXER_PCM:
  1348. case SOUND_MIXER_LINE:
  1349. case SOUND_MIXER_IGAIN:
  1350. levels = devc->levels[dev];
  1351. break;
  1352. case SOUND_MIXER_MIC: /* builtin mic: right mic only */
  1353. levels = devc->levels[SOUND_MIXER_MIC] >> 8;
  1354. levels |= levels << 8;
  1355. break;
  1356. case SOUND_MIXER_LINE1: /* handset mic: left mic only */
  1357. levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
  1358. levels |= levels << 8;
  1359. break;
  1360. case SOUND_MIXER_PHONEIN: /* phone mic: left aux1 only */
  1361. levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
  1362. levels |= levels << 8;
  1363. break;
  1364. default:
  1365. levels = 0;
  1366. }
  1367. return levels;
  1368. }
  1369. /*
  1370. * Waveartist specific mixer information.
  1371. */
  1372. static const struct waveartist_mixer_info netwinder_mixer = {
  1373. .supported_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
  1374. SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
  1375. SOUND_MASK_LINE | SOUND_MASK_MIC |
  1376. SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
  1377. SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT|
  1378. SOUND_MASK_IGAIN,
  1379. .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
  1380. SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
  1381. SOUND_MASK_PHONEIN,
  1382. .stereo_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
  1383. SOUND_MASK_PCM | SOUND_MASK_LINE |
  1384. SOUND_MASK_IMIX | SOUND_MASK_IGAIN,
  1385. .select_input = netwinder_select_input,
  1386. .decode_mixer = netwinder_decode_mixer,
  1387. .get_mixer = netwinder_get_mixer,
  1388. };
  1389. static void
  1390. vnc_configure_mixer(struct wavnc_info *devc, unsigned int recmask)
  1391. {
  1392. if (!devc->no_autoselect) {
  1393. if (devc->handset_detect) {
  1394. recmask = SOUND_MASK_LINE1;
  1395. devc->spkr_mute_state = devc->line_mute_state = 1;
  1396. } else if (devc->telephone_detect) {
  1397. recmask = SOUND_MASK_PHONEIN;
  1398. devc->spkr_mute_state = devc->line_mute_state = 1;
  1399. } else {
  1400. /* unless someone has asked for LINE-IN,
  1401. * we default to MIC
  1402. */
  1403. if ((devc->recmask & SOUND_MASK_LINE) == 0)
  1404. devc->recmask = SOUND_MASK_MIC;
  1405. devc->spkr_mute_state = devc->line_mute_state = 0;
  1406. }
  1407. vnc_mute_spkr(devc);
  1408. vnc_mute_lout(devc);
  1409. if (recmask != devc->recmask)
  1410. waveartist_set_recmask(devc, recmask);
  1411. }
  1412. }
  1413. static int
  1414. vnc_slider(struct wavnc_info *devc)
  1415. {
  1416. signed int slider_volume;
  1417. unsigned int temp, old_hs, old_td;
  1418. /*
  1419. * read the "buttons" state.
  1420. * Bit 4 = 0 means handset present
  1421. * Bit 5 = 1 means phone offhook
  1422. */
  1423. temp = inb(0x201);
  1424. old_hs = devc->handset_detect;
  1425. old_td = devc->telephone_detect;
  1426. devc->handset_detect = !(temp & 0x10);
  1427. devc->telephone_detect = !!(temp & 0x20);
  1428. if (!devc->no_autoselect &&
  1429. (old_hs != devc->handset_detect ||
  1430. old_td != devc->telephone_detect))
  1431. vnc_configure_mixer(devc, devc->recmask);
  1432. slider_volume = vnc_volume_slider(devc);
  1433. /*
  1434. * If we're using software controlled volume, and
  1435. * the slider moves by more than 20%, then we
  1436. * switch back to slider controlled volume.
  1437. */
  1438. if (abs(devc->slider_vol - slider_volume) > 20)
  1439. devc->use_slider = 1;
  1440. /*
  1441. * use only left channel
  1442. */
  1443. temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
  1444. if (slider_volume != temp && devc->use_slider) {
  1445. devc->slider_vol = slider_volume;
  1446. waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
  1447. slider_volume | slider_volume << 8);
  1448. return 1;
  1449. }
  1450. return 0;
  1451. }
  1452. static void
  1453. vnc_slider_tick(unsigned long data)
  1454. {
  1455. int next_timeout;
  1456. if (vnc_slider(adev_info + data))
  1457. next_timeout = 5; // mixer reported change
  1458. else
  1459. next_timeout = VNC_TIMER_PERIOD;
  1460. mod_timer(&vnc_timer, jiffies + next_timeout);
  1461. }
  1462. static int
  1463. vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
  1464. {
  1465. struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
  1466. int val;
  1467. switch (cmd) {
  1468. case SOUND_MIXER_PRIVATE1:
  1469. {
  1470. u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
  1471. int val;
  1472. if (get_user(val, arg))
  1473. return -EFAULT;
  1474. /* check if parameter is logical */
  1475. if (val & ~(VNC_MUTE_INTERNAL_SPKR |
  1476. VNC_MUTE_LINE_OUT |
  1477. VNC_DISABLE_AUTOSWITCH))
  1478. return -EINVAL;
  1479. prev_auto_state = devc->no_autoselect;
  1480. prev_spkr_mute = devc->spkr_mute_state;
  1481. prev_line_mute = devc->line_mute_state;
  1482. devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
  1483. devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
  1484. devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
  1485. if (prev_spkr_mute != devc->spkr_mute_state)
  1486. vnc_mute_spkr(devc);
  1487. if (prev_line_mute != devc->line_mute_state)
  1488. vnc_mute_lout(devc);
  1489. if (prev_auto_state != devc->no_autoselect)
  1490. vnc_configure_mixer(devc, devc->recmask);
  1491. return 0;
  1492. }
  1493. case SOUND_MIXER_PRIVATE2:
  1494. if (get_user(val, arg))
  1495. return -EFAULT;
  1496. switch (val) {
  1497. #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
  1498. #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
  1499. case VNC_SOUND_PAUSE:
  1500. waveartist_cmd1(devc, 0x16);
  1501. break;
  1502. case VNC_SOUND_RESUME:
  1503. waveartist_cmd1(devc, 0x18);
  1504. break;
  1505. default:
  1506. return -EINVAL;
  1507. }
  1508. return 0;
  1509. /* private ioctl to allow bulk access to waveartist */
  1510. case SOUND_MIXER_PRIVATE3:
  1511. {
  1512. unsigned long flags;
  1513. int mixer_reg[15], i, val;
  1514. if (get_user(val, arg))
  1515. return -EFAULT;
  1516. if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
  1517. return -EFAULT;
  1518. switch (mixer_reg[14]) {
  1519. case MIXER_PRIVATE3_RESET:
  1520. waveartist_mixer_reset(devc);
  1521. break;
  1522. case MIXER_PRIVATE3_WRITE:
  1523. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
  1524. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
  1525. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
  1526. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
  1527. waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
  1528. waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
  1529. waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
  1530. break;
  1531. case MIXER_PRIVATE3_READ:
  1532. spin_lock_irqsave(&waveartist_lock, flags);
  1533. for (i = 0x30; i < 14 << 8; i += 1 << 8)
  1534. waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
  1535. spin_unlock_irqrestore(&waveartist_lock, flags);
  1536. if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
  1537. return -EFAULT;
  1538. break;
  1539. default:
  1540. return -EINVAL;
  1541. }
  1542. return 0;
  1543. }
  1544. /* read back the state from PRIVATE1 */
  1545. case SOUND_MIXER_PRIVATE4:
  1546. val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
  1547. (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
  1548. (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
  1549. (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
  1550. (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
  1551. return put_user(val, arg) ? -EFAULT : 0;
  1552. }
  1553. if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
  1554. /*
  1555. * special case for master volume: if we
  1556. * received this call - switch from hw
  1557. * volume control to a software volume
  1558. * control, till the hw volume is modified
  1559. * to signal that user wants to be back in
  1560. * hardware...
  1561. */
  1562. if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
  1563. devc->use_slider = 0;
  1564. /* speaker output */
  1565. if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
  1566. unsigned int val, l, r;
  1567. if (get_user(val, arg))
  1568. return -EFAULT;
  1569. l = val & 0x7f;
  1570. r = (val & 0x7f00) >> 8;
  1571. val = (l + r) / 2;
  1572. devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
  1573. devc->spkr_mute_state = (val <= 50);
  1574. vnc_mute_spkr(devc);
  1575. return 0;
  1576. }
  1577. }
  1578. return -ENOIOCTLCMD;
  1579. }
  1580. #endif
  1581. static struct address_info cfg;
  1582. static int attached;
  1583. static int __initdata io = 0;
  1584. static int __initdata irq = 0;
  1585. static int __initdata dma = 0;
  1586. static int __initdata dma2 = 0;
  1587. static int __init init_waveartist(void)
  1588. {
  1589. const struct waveartist_mixer_info *mix;
  1590. if (!io && machine_is_netwinder()) {
  1591. /*
  1592. * The NetWinder WaveArtist is at a fixed address.
  1593. * If the user does not supply an address, use the
  1594. * well-known parameters.
  1595. */
  1596. io = 0x250;
  1597. irq = 12;
  1598. dma = 3;
  1599. dma2 = 7;
  1600. }
  1601. mix = &waveartist_mixer;
  1602. #ifdef CONFIG_ARCH_NETWINDER
  1603. if (machine_is_netwinder())
  1604. mix = &netwinder_mixer;
  1605. #endif
  1606. cfg.io_base = io;
  1607. cfg.irq = irq;
  1608. cfg.dma = dma;
  1609. cfg.dma2 = dma2;
  1610. if (!probe_waveartist(&cfg))
  1611. return -ENODEV;
  1612. attach_waveartist(&cfg, mix);
  1613. attached = 1;
  1614. return 0;
  1615. }
  1616. static void __exit cleanup_waveartist(void)
  1617. {
  1618. if (attached)
  1619. unload_waveartist(&cfg);
  1620. }
  1621. module_init(init_waveartist);
  1622. module_exit(cleanup_waveartist);
  1623. #ifndef MODULE
  1624. static int __init setup_waveartist(char *str)
  1625. {
  1626. /* io, irq, dma, dma2 */
  1627. int ints[5];
  1628. str = get_options(str, ARRAY_SIZE(ints), ints);
  1629. io = ints[1];
  1630. irq = ints[2];
  1631. dma = ints[3];
  1632. dma2 = ints[4];
  1633. return 1;
  1634. }
  1635. __setup("waveartist=", setup_waveartist);
  1636. #endif
  1637. MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
  1638. module_param(io, int, 0); /* IO base */
  1639. module_param(irq, int, 0); /* IRQ */
  1640. module_param(dma, int, 0); /* DMA */
  1641. module_param(dma2, int, 0); /* DMA2 */
  1642. MODULE_LICENSE("GPL");