waveartist.c 46 KB

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