waveartist.c 46 KB

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