waveartist.c 46 KB

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