waveartist.c 46 KB

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