waveartist.c 46 KB

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