waveartist.c 46 KB

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