123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046 |
- #define DEBUG_CMD 1
- #define DEBUG_OUT 2
- #define DEBUG_IN 4
- #define DEBUG_INTR 8
- #define DEBUG_MIXER 16
- #define DEBUG_TRIGGER 32
- #define debug_flg (0)
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/slab.h>
- #include <linux/sched.h>
- #include <linux/interrupt.h>
- #include <linux/delay.h>
- #include <linux/spinlock.h>
- #include <linux/bitops.h>
- #include "sound_config.h"
- #include "waveartist.h"
- #ifdef CONFIG_ARM
- #include <mach/hardware.h>
- #include <asm/mach-types.h>
- #endif
- #ifndef NO_DMA
- #define NO_DMA 255
- #endif
- #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
- SOUND_MASK_PCM |\
- SOUND_MASK_LINE |\
- SOUND_MASK_MIC |\
- SOUND_MASK_LINE1 |\
- SOUND_MASK_RECLEV |\
- SOUND_MASK_VOLUME |\
- SOUND_MASK_IMIX)
- static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
- 0x5555,
- 0x0000,
- 0x0000,
- 0x2323,
- 0x4b4b,
- 0x6464,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x6464,
- 0x0000,
- 0x0000,
- 0x6464,
- 0x6464,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x6464,
- 0x0000,
- 0x0000,
- 0x0000
- };
- struct wavnc_info {
- struct address_info hw;
- char *chip_name;
- int xfer_count;
- int audio_mode;
- int open_mode;
- int audio_flags;
- int record_dev;
- int playback_dev;
- int dev_no;
-
- const struct waveartist_mixer_info *mix;
- unsigned short *levels;
- int recmask;
- #ifdef CONFIG_ARCH_NETWINDER
- signed int slider_vol;
- unsigned int handset_detect :1;
- unsigned int telephone_detect:1;
- unsigned int no_autoselect :1;
- unsigned int spkr_mute_state :1;
- unsigned int line_mute_state :1;
- unsigned int use_slider :1;
- #endif
- };
- struct waveartist_mixer_info {
- unsigned int supported_devs;
- unsigned int recording_devs;
- unsigned int stereo_devs;
- unsigned int (*select_input)(struct wavnc_info *, unsigned int,
- unsigned char *, unsigned char *);
- int (*decode_mixer)(struct wavnc_info *, int,
- unsigned char, unsigned char);
- int (*get_mixer)(struct wavnc_info *, int);
- };
- struct wavnc_port_info {
- int open_mode;
- int speed;
- int channels;
- int audio_format;
- };
- static int nr_waveartist_devs;
- static struct wavnc_info adev_info[MAX_AUDIO_DEV];
- static DEFINE_SPINLOCK(waveartist_lock);
- #ifndef CONFIG_ARCH_NETWINDER
- #define machine_is_netwinder() 0
- #else
- static struct timer_list vnc_timer;
- static void vnc_configure_mixer(struct wavnc_info *devc,
- unsigned int input_mask);
- static int vnc_private_ioctl(int dev, unsigned int cmd, int __user *arg);
- static void vnc_slider_tick(unsigned long data);
- #endif
- static inline void
- waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
- {
- unsigned int ctlr_port = hw->io_base + CTLR;
- clear = ~clear & inb(ctlr_port);
- outb(clear | set, ctlr_port);
- }
- static inline void
- waveartist_iack(struct wavnc_info *devc)
- {
- unsigned int ctlr_port = devc->hw.io_base + CTLR;
- int old_ctlr;
- old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
- outb(old_ctlr | IRQ_ACK, ctlr_port);
- outb(old_ctlr, ctlr_port);
- }
- static inline int
- waveartist_sleep(int timeout_ms)
- {
- unsigned int timeout = msecs_to_jiffies(timeout_ms*100);
- return schedule_timeout_interruptible(timeout);
- }
- static int
- waveartist_reset(struct wavnc_info *devc)
- {
- struct address_info *hw = &devc->hw;
- unsigned int timeout, res = -1;
- waveartist_set_ctlr(hw, -1, RESET);
- waveartist_sleep(2);
- waveartist_set_ctlr(hw, RESET, 0);
- timeout = 500;
- do {
- mdelay(2);
- if (inb(hw->io_base + STATR) & CMD_RF) {
- res = inw(hw->io_base + CMDR);
- if (res == 0x55aa)
- break;
- }
- } while (--timeout);
- if (timeout == 0) {
- printk(KERN_WARNING "WaveArtist: reset timeout ");
- if (res != (unsigned int)-1)
- printk("(res=%04X)", res);
- printk("\n");
- return 1;
- }
- return 0;
- }
- static int
- waveartist_cmd(struct wavnc_info *devc,
- int nr_cmd, unsigned int *cmd,
- int nr_resp, unsigned int *resp)
- {
- unsigned int io_base = devc->hw.io_base;
- unsigned int timed_out = 0;
- unsigned int i;
- if (debug_flg & DEBUG_CMD) {
- printk("waveartist_cmd: cmd=");
- for (i = 0; i < nr_cmd; i++)
- printk("%04X ", cmd[i]);
- printk("\n");
- }
- if (inb(io_base + STATR) & CMD_RF) {
- int old_data;
-
- old_data = inw(io_base + CMDR);
- if (debug_flg & DEBUG_CMD)
- printk("flushed %04X...", old_data);
- udelay(10);
- }
- for (i = 0; !timed_out && i < nr_cmd; i++) {
- int count;
- for (count = 5000; count; count--)
- if (inb(io_base + STATR) & CMD_WE)
- break;
- if (!count)
- timed_out = 1;
- else
- outw(cmd[i], io_base + CMDR);
- }
- for (i = 0; !timed_out && i < nr_resp; i++) {
- int count;
- for (count = 5000; count; count--)
- if (inb(io_base + STATR) & CMD_RF)
- break;
- if (!count)
- timed_out = 1;
- else
- resp[i] = inw(io_base + CMDR);
- }
- if (debug_flg & DEBUG_CMD) {
- if (!timed_out) {
- printk("waveartist_cmd: resp=");
- for (i = 0; i < nr_resp; i++)
- printk("%04X ", resp[i]);
- printk("\n");
- } else
- printk("waveartist_cmd: timed out\n");
- }
- return timed_out ? 1 : 0;
- }
- static inline int
- waveartist_cmd1(struct wavnc_info *devc, unsigned int cmd)
- {
- return waveartist_cmd(devc, 1, &cmd, 0, NULL);
- }
- static inline unsigned int
- waveartist_cmd1_r(struct wavnc_info *devc, unsigned int cmd)
- {
- unsigned int ret;
- waveartist_cmd(devc, 1, &cmd, 1, &ret);
- return ret;
- }
- static inline int
- waveartist_cmd2(struct wavnc_info *devc, unsigned int cmd, unsigned int arg)
- {
- unsigned int vals[2];
- vals[0] = cmd;
- vals[1] = arg;
- return waveartist_cmd(devc, 2, vals, 1, vals);
- }
- static inline int
- waveartist_cmd3(struct wavnc_info *devc, unsigned int cmd,
- unsigned int arg1, unsigned int arg2)
- {
- unsigned int vals[3];
- vals[0] = cmd;
- vals[1] = arg1;
- vals[2] = arg2;
- return waveartist_cmd(devc, 3, vals, 0, NULL);
- }
- static int
- waveartist_getrev(struct wavnc_info *devc, char *rev)
- {
- unsigned int temp[2];
- unsigned int cmd = WACMD_GETREV;
- waveartist_cmd(devc, 1, &cmd, 2, temp);
- rev[0] = temp[0] >> 8;
- rev[1] = temp[0] & 255;
- rev[2] = '\0';
- return temp[0];
- }
- static void waveartist_halt_output(int dev);
- static void waveartist_halt_input(int dev);
- static void waveartist_halt(int dev);
- static void waveartist_trigger(int dev, int state);
- static int
- waveartist_open(int dev, int mode)
- {
- struct wavnc_info *devc;
- struct wavnc_port_info *portc;
- unsigned long flags;
- if (dev < 0 || dev >= num_audiodevs)
- return -ENXIO;
- devc = (struct wavnc_info *) audio_devs[dev]->devc;
- portc = (struct wavnc_port_info *) audio_devs[dev]->portc;
- spin_lock_irqsave(&waveartist_lock, flags);
- if (portc->open_mode || (devc->open_mode & mode)) {
- spin_unlock_irqrestore(&waveartist_lock, flags);
- return -EBUSY;
- }
- devc->audio_mode = 0;
- devc->open_mode |= mode;
- portc->open_mode = mode;
- waveartist_trigger(dev, 0);
- if (mode & OPEN_READ)
- devc->record_dev = dev;
- if (mode & OPEN_WRITE)
- devc->playback_dev = dev;
- spin_unlock_irqrestore(&waveartist_lock, flags);
- return 0;
- }
- static void
- waveartist_close(int dev)
- {
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- unsigned long flags;
- spin_lock_irqsave(&waveartist_lock, flags);
- waveartist_halt(dev);
- devc->audio_mode = 0;
- devc->open_mode &= ~portc->open_mode;
- portc->open_mode = 0;
- spin_unlock_irqrestore(&waveartist_lock, flags);
- }
- static void
- waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
- {
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- unsigned long flags;
- unsigned int count = __count;
- if (debug_flg & DEBUG_OUT)
- printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
- buf, count);
-
- if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
- count >>= 1;
- if (portc->channels > 1)
- count >>= 1;
- count -= 1;
- if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
- audio_devs[dev]->flags & DMA_AUTOMODE &&
- intrflag &&
- count == devc->xfer_count) {
- devc->audio_mode |= PCM_ENABLE_OUTPUT;
- return;
- }
- spin_lock_irqsave(&waveartist_lock, flags);
-
- waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
- devc->xfer_count = count;
- devc->audio_mode |= PCM_ENABLE_OUTPUT;
- spin_unlock_irqrestore(&waveartist_lock, flags);
- }
- static void
- waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
- {
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- unsigned long flags;
- unsigned int count = __count;
- if (debug_flg & DEBUG_IN)
- printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
- buf, count);
- if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
- count >>= 1;
- if (portc->channels > 1)
- count >>= 1;
- count -= 1;
- if (devc->audio_mode & PCM_ENABLE_INPUT &&
- audio_devs[dev]->flags & DMA_AUTOMODE &&
- intrflag &&
- count == devc->xfer_count) {
- devc->audio_mode |= PCM_ENABLE_INPUT;
- return;
- }
- spin_lock_irqsave(&waveartist_lock, flags);
-
- waveartist_cmd2(devc, WACMD_INPUTSIZE, count);
- devc->xfer_count = count;
- devc->audio_mode |= PCM_ENABLE_INPUT;
- spin_unlock_irqrestore(&waveartist_lock, flags);
- }
- static int
- waveartist_ioctl(int dev, unsigned int cmd, void __user * arg)
- {
- return -EINVAL;
- }
- static unsigned int
- waveartist_get_speed(struct wavnc_port_info *portc)
- {
- unsigned int speed;
-
- if (portc->speed == 8000)
- speed = 0x2E71;
- else if (portc->speed == 11025)
- speed = 0x4000;
- else if (portc->speed == 22050)
- speed = 0x8000;
- else if (portc->speed == 44100)
- speed = 0x0;
- else {
-
- speed = portc->speed << 16;
- speed = (speed / 44100) & 65535;
- }
- return speed;
- }
- static unsigned int
- waveartist_get_bits(struct wavnc_port_info *portc)
- {
- unsigned int bits;
- if (portc->audio_format == AFMT_S16_LE)
- bits = 1;
- else if (portc->audio_format == AFMT_S8)
- bits = 0;
- else
- bits = 2;
- return bits;
- }
- static int
- waveartist_prepare_for_input(int dev, int bsize, int bcount)
- {
- unsigned long flags;
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- unsigned int speed, bits;
- if (devc->audio_mode)
- return 0;
- speed = waveartist_get_speed(portc);
- bits = waveartist_get_bits(portc);
- spin_lock_irqsave(&waveartist_lock, flags);
- if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
- printk(KERN_WARNING "waveartist: error setting the "
- "record format to %d\n", portc->audio_format);
- if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
- printk(KERN_WARNING "waveartist: error setting record "
- "to %d channels\n", portc->channels);
-
- if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
- printk(KERN_WARNING "waveartist: error setting the record "
- "speed to %dHz.\n", portc->speed);
- if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
- printk(KERN_WARNING "waveartist: error setting the record "
- "data path to 0x%X\n", 1);
- if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
- printk(KERN_WARNING "waveartist: error setting the record "
- "format to %d\n", portc->audio_format);
- devc->xfer_count = 0;
- spin_unlock_irqrestore(&waveartist_lock, flags);
- waveartist_halt_input(dev);
- if (debug_flg & DEBUG_INTR) {
- printk("WA CTLR reg: 0x%02X.\n",
- inb(devc->hw.io_base + CTLR));
- printk("WA STAT reg: 0x%02X.\n",
- inb(devc->hw.io_base + STATR));
- printk("WA IRQS reg: 0x%02X.\n",
- inb(devc->hw.io_base + IRQSTAT));
- }
- return 0;
- }
- static int
- waveartist_prepare_for_output(int dev, int bsize, int bcount)
- {
- unsigned long flags;
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- unsigned int speed, bits;
-
- speed = waveartist_get_speed(portc);
- bits = waveartist_get_bits(portc);
- spin_lock_irqsave(&waveartist_lock, flags);
- if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
- waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
- printk(KERN_WARNING "waveartist: error setting the playback "
- "speed to %dHz.\n", portc->speed);
- if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
- printk(KERN_WARNING "waveartist: error setting the playback "
- "to %d channels\n", portc->channels);
- if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
- printk(KERN_WARNING "waveartist: error setting the playback "
- "data path to 0x%X\n", 0);
- if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
- printk(KERN_WARNING "waveartist: error setting the playback "
- "format to %d\n", portc->audio_format);
- devc->xfer_count = 0;
- spin_unlock_irqrestore(&waveartist_lock, flags);
- waveartist_halt_output(dev);
- if (debug_flg & DEBUG_INTR) {
- printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
- printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
- printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
- }
- return 0;
- }
- static void
- waveartist_halt(int dev)
- {
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- struct wavnc_info *devc;
- if (portc->open_mode & OPEN_WRITE)
- waveartist_halt_output(dev);
- if (portc->open_mode & OPEN_READ)
- waveartist_halt_input(dev);
- devc = (struct wavnc_info *) audio_devs[dev]->devc;
- devc->audio_mode = 0;
- }
- static void
- waveartist_halt_input(int dev)
- {
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- unsigned long flags;
- spin_lock_irqsave(&waveartist_lock, flags);
-
- waveartist_cmd1(devc, WACMD_INPUTSTOP);
- devc->audio_mode &= ~PCM_ENABLE_INPUT;
-
- if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
- waveartist_iack(devc);
- spin_unlock_irqrestore(&waveartist_lock, flags);
- }
- static void
- waveartist_halt_output(int dev)
- {
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- unsigned long flags;
- spin_lock_irqsave(&waveartist_lock, flags);
- waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
- devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
-
- if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
- waveartist_iack(devc);
- spin_unlock_irqrestore(&waveartist_lock, flags);
- }
- static void
- waveartist_trigger(int dev, int state)
- {
- struct wavnc_info *devc = (struct wavnc_info *)
- audio_devs[dev]->devc;
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- unsigned long flags;
- if (debug_flg & DEBUG_TRIGGER) {
- printk("wavnc: audio trigger ");
- if (state & PCM_ENABLE_INPUT)
- printk("in ");
- if (state & PCM_ENABLE_OUTPUT)
- printk("out");
- printk("\n");
- }
- spin_lock_irqsave(&waveartist_lock, flags);
- state &= devc->audio_mode;
- if (portc->open_mode & OPEN_READ &&
- state & PCM_ENABLE_INPUT)
-
- waveartist_cmd1(devc, WACMD_INPUTSTART);
- if (portc->open_mode & OPEN_WRITE &&
- state & PCM_ENABLE_OUTPUT)
-
- waveartist_cmd1(devc, WACMD_OUTPUTSTART);
- spin_unlock_irqrestore(&waveartist_lock, flags);
- }
- static int
- waveartist_set_speed(int dev, int arg)
- {
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- if (arg <= 0)
- return portc->speed;
- if (arg < 5000)
- arg = 5000;
- if (arg > 44100)
- arg = 44100;
- portc->speed = arg;
- return portc->speed;
- }
- static short
- waveartist_set_channels(int dev, short arg)
- {
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- if (arg != 1 && arg != 2)
- return portc->channels;
- portc->channels = arg;
- return arg;
- }
- static unsigned int
- waveartist_set_bits(int dev, unsigned int arg)
- {
- struct wavnc_port_info *portc = (struct wavnc_port_info *)
- audio_devs[dev]->portc;
- if (arg == 0)
- return portc->audio_format;
- if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
- arg = AFMT_U8;
- portc->audio_format = arg;
- return arg;
- }
- static struct audio_driver waveartist_audio_driver = {
- .owner = THIS_MODULE,
- .open = waveartist_open,
- .close = waveartist_close,
- .output_block = waveartist_output_block,
- .start_input = waveartist_start_input,
- .ioctl = waveartist_ioctl,
- .prepare_for_input = waveartist_prepare_for_input,
- .prepare_for_output = waveartist_prepare_for_output,
- .halt_io = waveartist_halt,
- .halt_input = waveartist_halt_input,
- .halt_output = waveartist_halt_output,
- .trigger = waveartist_trigger,
- .set_speed = waveartist_set_speed,
- .set_bits = waveartist_set_bits,
- .set_channels = waveartist_set_channels
- };
- static irqreturn_t
- waveartist_intr(int irq, void *dev_id)
- {
- struct wavnc_info *devc = dev_id;
- int irqstatus, status;
- spin_lock(&waveartist_lock);
- irqstatus = inb(devc->hw.io_base + IRQSTAT);
- status = inb(devc->hw.io_base + STATR);
- if (debug_flg & DEBUG_INTR)
- printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
- status, irqstatus);
- if (status & IRQ_REQ)
- waveartist_iack(devc);
- else
- printk(KERN_WARNING "waveartist: unexpected interrupt\n");
- if (irqstatus & 0x01) {
- int temp = 1;
-
- if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
- DMAbuf_outputintr(devc->playback_dev, 1);
- temp = 0;
- }
- if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
- DMAbuf_inputintr(devc->record_dev);
- temp = 0;
- }
- if (temp)
- printk(KERN_WARNING "waveartist: Unknown interrupt\n");
- }
- if (irqstatus & 0x2)
-
- printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
- spin_unlock(&waveartist_lock);
- return IRQ_HANDLED;
- }
- struct mix_ent {
- unsigned char reg_l;
- unsigned char reg_r;
- unsigned char shift;
- unsigned char max;
- };
- static const struct mix_ent mix_devs[SOUND_MIXER_NRDEVICES] = {
- { 2, 6, 1, 7 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 4, 6, 31 },
- { 2, 6, 4, 3 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- #if 0
- { 3, 7, 0, 10 },
- { 0, 0, 0, 0 },
- #else
- { 0, 0, 0, 0 },
- { 3, 7, 0, 7 },
- #endif
- { 0, 0, 0, 0 },
- { 0, 4, 1, 31 },
- { 1, 5, 6, 31 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 },
- { 0, 0, 0, 0 }
- };
- static void
- waveartist_mixer_update(struct wavnc_info *devc, int whichDev)
- {
- unsigned int lev_left, lev_right;
- lev_left = devc->levels[whichDev] & 0xff;
- lev_right = devc->levels[whichDev] >> 8;
- if (lev_left > 100)
- lev_left = 100;
- if (lev_right > 100)
- lev_right = 100;
- #define SCALE(lev,max) ((lev) * (max) / 100)
- if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
- whichDev = SOUND_MIXER_VOLUME;
- if (mix_devs[whichDev].reg_l || mix_devs[whichDev].reg_r) {
- const struct mix_ent *mix = mix_devs + whichDev;
- unsigned int mask, left, right;
- mask = mix->max << mix->shift;
- lev_left = SCALE(lev_left, mix->max) << mix->shift;
- lev_right = SCALE(lev_right, mix->max) << mix->shift;
-
- left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
- mix->reg_l << 8);
-
- right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
- mix->reg_r << 8);
- left = (left & ~mask) | (lev_left & mask);
- right = (right & ~mask) | (lev_right & mask);
-
- waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
- } else {
- switch(whichDev) {
- case SOUND_MIXER_PCM:
- waveartist_cmd3(devc, WACMD_SET_LEVEL,
- SCALE(lev_left, 32767),
- SCALE(lev_right, 32767));
- break;
- case SOUND_MIXER_SYNTH:
- waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
- SCALE(lev_left, 32767),
- SCALE(lev_right, 32767));
- break;
- }
- }
- }
- static void
- waveartist_set_adc_mux(struct wavnc_info *devc, char left_dev,
- char right_dev)
- {
- unsigned int reg_08, reg_09;
- reg_08 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0800);
- reg_09 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0900);
- reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
- waveartist_cmd3(devc, WACMD_SET_MIXER, reg_08, reg_09);
- }
- static unsigned int
- waveartist_select_input(struct wavnc_info *devc, unsigned int recmask,
- unsigned char *dev_l, unsigned char *dev_r)
- {
- unsigned int recdev = ADC_MUX_NONE;
- if (recmask & SOUND_MASK_IMIX) {
- recmask = SOUND_MASK_IMIX;
- recdev = ADC_MUX_MIXER;
- } else if (recmask & SOUND_MASK_LINE2) {
- recmask = SOUND_MASK_LINE2;
- recdev = ADC_MUX_AUX2;
- } else if (recmask & SOUND_MASK_LINE1) {
- recmask = SOUND_MASK_LINE1;
- recdev = ADC_MUX_AUX1;
- } else if (recmask & SOUND_MASK_LINE) {
- recmask = SOUND_MASK_LINE;
- recdev = ADC_MUX_LINE;
- } else if (recmask & SOUND_MASK_MIC) {
- recmask = SOUND_MASK_MIC;
- recdev = ADC_MUX_MIC;
- }
- *dev_l = *dev_r = recdev;
- return recmask;
- }
- static int
- waveartist_decode_mixer(struct wavnc_info *devc, int dev,
- unsigned char lev_l,
- unsigned char lev_r)
- {
- switch (dev) {
- case SOUND_MIXER_VOLUME:
- case SOUND_MIXER_SYNTH:
- case SOUND_MIXER_PCM:
- case SOUND_MIXER_LINE:
- case SOUND_MIXER_MIC:
- case SOUND_MIXER_IGAIN:
- case SOUND_MIXER_LINE1:
- case SOUND_MIXER_LINE2:
- devc->levels[dev] = lev_l | lev_r << 8;
- break;
- case SOUND_MIXER_IMIX:
- break;
- default:
- dev = -EINVAL;
- break;
- }
- return dev;
- }
- static int waveartist_get_mixer(struct wavnc_info *devc, int dev)
- {
- return devc->levels[dev];
- }
- static const struct waveartist_mixer_info waveartist_mixer = {
- .supported_devs = SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN,
- .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
- SOUND_MASK_LINE1 | SOUND_MASK_LINE2 |
- SOUND_MASK_IMIX,
- .stereo_devs = (SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN) & ~
- (SOUND_MASK_SPEAKER | SOUND_MASK_IMIX),
- .select_input = waveartist_select_input,
- .decode_mixer = waveartist_decode_mixer,
- .get_mixer = waveartist_get_mixer,
- };
- static void
- waveartist_set_recmask(struct wavnc_info *devc, unsigned int recmask)
- {
- unsigned char dev_l, dev_r;
- recmask &= devc->mix->recording_devs;
-
- if (hweight32(recmask) > 1)
- recmask &= ~devc->recmask;
-
- devc->recmask = devc->mix->select_input(devc, recmask,
- &dev_l, &dev_r);
- waveartist_set_adc_mux(devc, dev_l, dev_r);
- }
- static int
- waveartist_set_mixer(struct wavnc_info *devc, int dev, unsigned int level)
- {
- unsigned int lev_left = level & 0x00ff;
- unsigned int lev_right = (level & 0xff00) >> 8;
- if (lev_left > 100)
- lev_left = 100;
- if (lev_right > 100)
- lev_right = 100;
-
- if (!(devc->mix->stereo_devs & (1 << dev)))
- lev_right = lev_left;
- dev = devc->mix->decode_mixer(devc, dev, lev_left, lev_right);
- if (dev >= 0)
- waveartist_mixer_update(devc, dev);
- return dev < 0 ? dev : 0;
- }
- static int
- waveartist_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
- {
- struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
- int ret = 0, val, nr;
-
- if (((cmd >> 8) & 255) != 'M')
- return -ENOIOCTLCMD;
- #ifdef CONFIG_ARCH_NETWINDER
- if (machine_is_netwinder()) {
- ret = vnc_private_ioctl(dev, cmd, arg);
- if (ret != -ENOIOCTLCMD)
- return ret;
- else
- ret = 0;
- }
- #endif
- nr = cmd & 0xff;
- if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
- if (get_user(val, (int __user *)arg))
- return -EFAULT;
- switch (nr) {
- case SOUND_MIXER_RECSRC:
- waveartist_set_recmask(devc, val);
- break;
- default:
- ret = -EINVAL;
- if (nr < SOUND_MIXER_NRDEVICES &&
- devc->mix->supported_devs & (1 << nr))
- ret = waveartist_set_mixer(devc, nr, val);
- }
- }
- if (ret == 0 && _SIOC_DIR(cmd) & _SIOC_READ) {
- ret = -EINVAL;
- switch (nr) {
- case SOUND_MIXER_RECSRC:
- ret = devc->recmask;
- break;
- case SOUND_MIXER_DEVMASK:
- ret = devc->mix->supported_devs;
- break;
- case SOUND_MIXER_STEREODEVS:
- ret = devc->mix->stereo_devs;
- break;
- case SOUND_MIXER_RECMASK:
- ret = devc->mix->recording_devs;
- break;
- case SOUND_MIXER_CAPS:
- ret = SOUND_CAP_EXCL_INPUT;
- break;
- default:
- if (nr < SOUND_MIXER_NRDEVICES)
- ret = devc->mix->get_mixer(devc, nr);
- break;
- }
- if (ret >= 0)
- ret = put_user(ret, (int __user *)arg) ? -EFAULT : 0;
- }
- return ret;
- }
- static struct mixer_operations waveartist_mixer_operations =
- {
- .owner = THIS_MODULE,
- .id = "WaveArtist",
- .name = "WaveArtist",
- .ioctl = waveartist_mixer_ioctl
- };
- static void
- waveartist_mixer_reset(struct wavnc_info *devc)
- {
- int i;
- if (debug_flg & DEBUG_MIXER)
- printk("%s: mixer_reset\n", devc->hw.name);
-
- waveartist_cmd1(devc, WACMD_RST_MIXER);
-
- waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
-
- waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
-
- waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
-
- waveartist_set_recmask(devc, 0);
- for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
- waveartist_mixer_update(devc, i);
- }
- static int __init waveartist_init(struct wavnc_info *devc)
- {
- struct wavnc_port_info *portc;
- char rev[3], dev_name[64];
- int my_dev;
- if (waveartist_reset(devc))
- return -ENODEV;
- sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
- if (waveartist_getrev(devc, rev)) {
- strcat(dev_name, " rev. ");
- strcat(dev_name, rev);
- }
- strcat(dev_name, ")");
- conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
- devc->hw.dma, devc->hw.dma2);
- portc = kzalloc(sizeof(struct wavnc_port_info), GFP_KERNEL);
- if (portc == NULL)
- goto nomem;
- my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
- &waveartist_audio_driver, sizeof(struct audio_driver),
- devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
- devc, devc->hw.dma, devc->hw.dma2);
- if (my_dev < 0)
- goto free;
- audio_devs[my_dev]->portc = portc;
- waveartist_mixer_reset(devc);
-
- waveartist_iack(devc);
- if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
- printk(KERN_ERR "%s: IRQ %d in use\n",
- devc->hw.name, devc->hw.irq);
- goto uninstall;
- }
- if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
- printk(KERN_ERR "%s: Can't allocate DMA%d\n",
- devc->hw.name, devc->hw.dma);
- goto uninstall_irq;
- }
- if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
- if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
- printk(KERN_ERR "%s: can't allocate DMA%d\n",
- devc->hw.name, devc->hw.dma2);
- goto uninstall_dma;
- }
- waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
- audio_devs[my_dev]->mixer_dev =
- sound_install_mixer(MIXER_DRIVER_VERSION,
- dev_name,
- &waveartist_mixer_operations,
- sizeof(struct mixer_operations),
- devc);
- return my_dev;
- uninstall_dma:
- sound_free_dma(devc->hw.dma);
- uninstall_irq:
- free_irq(devc->hw.irq, devc);
- uninstall:
- sound_unload_audiodev(my_dev);
- free:
- kfree(portc);
- nomem:
- return -1;
- }
- static int __init probe_waveartist(struct address_info *hw_config)
- {
- struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
- if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
- printk(KERN_WARNING "waveartist: too many audio devices\n");
- return 0;
- }
- if (!request_region(hw_config->io_base, 15, hw_config->name)) {
- printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
- return 0;
- }
- if (hw_config->irq > 15 || hw_config->irq < 0) {
- release_region(hw_config->io_base, 15);
- printk(KERN_WARNING "WaveArtist: Bad IRQ %d\n",
- hw_config->irq);
- return 0;
- }
- if (hw_config->dma != 3) {
- release_region(hw_config->io_base, 15);
- printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
- hw_config->dma);
- return 0;
- }
- hw_config->name = "WaveArtist";
- devc->hw = *hw_config;
- devc->open_mode = 0;
- devc->chip_name = "RWA-010";
- return 1;
- }
- static void __init
- attach_waveartist(struct address_info *hw, const struct waveartist_mixer_info *mix)
- {
- struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
-
- devc->hw = *hw;
- devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
- devc->open_mode = 0;
- devc->playback_dev = 0;
- devc->record_dev = 0;
- devc->audio_flags = DMA_AUTOMODE;
- devc->levels = levels;
- if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
- devc->audio_flags |= DMA_DUPLEX;
- devc->mix = mix;
- devc->dev_no = waveartist_init(devc);
- if (devc->dev_no < 0)
- release_region(hw->io_base, 15);
- else {
- #ifdef CONFIG_ARCH_NETWINDER
- if (machine_is_netwinder()) {
- init_timer(&vnc_timer);
- vnc_timer.function = vnc_slider_tick;
- vnc_timer.expires = jiffies;
- vnc_timer.data = nr_waveartist_devs;
- add_timer(&vnc_timer);
- vnc_configure_mixer(devc, 0);
- devc->no_autoselect = 1;
- }
- #endif
- nr_waveartist_devs += 1;
- }
- }
- static void __exit unload_waveartist(struct address_info *hw)
- {
- struct wavnc_info *devc = NULL;
- int i;
- for (i = 0; i < nr_waveartist_devs; i++)
- if (hw->io_base == adev_info[i].hw.io_base) {
- devc = adev_info + i;
- break;
- }
- if (devc != NULL) {
- int mixer;
- #ifdef CONFIG_ARCH_NETWINDER
- if (machine_is_netwinder())
- del_timer(&vnc_timer);
- #endif
- release_region(devc->hw.io_base, 15);
- waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
- if (devc->hw.irq >= 0)
- free_irq(devc->hw.irq, devc);
- sound_free_dma(devc->hw.dma);
- if (devc->hw.dma != devc->hw.dma2 &&
- devc->hw.dma2 != NO_DMA)
- sound_free_dma(devc->hw.dma2);
- mixer = audio_devs[devc->dev_no]->mixer_dev;
- if (mixer >= 0)
- sound_unload_mixerdev(mixer);
- if (devc->dev_no >= 0)
- sound_unload_audiodev(devc->dev_no);
- nr_waveartist_devs -= 1;
- for (; i < nr_waveartist_devs; i++)
- adev_info[i] = adev_info[i + 1];
- } else
- printk(KERN_WARNING "waveartist: can't find device "
- "to unload\n");
- }
- #ifdef CONFIG_ARCH_NETWINDER
- #include <asm/hardware/dec21285.h>
-
- #define VNC_TIMER_PERIOD (HZ/4)
- #define MIXER_PRIVATE3_RESET 0x53570000
- #define MIXER_PRIVATE3_READ 0x53570001
- #define MIXER_PRIVATE3_WRITE 0x53570002
- #define VNC_MUTE_INTERNAL_SPKR 0x01
- #define VNC_MUTE_LINE_OUT 0x10
- #define VNC_PHONE_DETECT 0x20
- #define VNC_HANDSET_DETECT 0x40
- #define VNC_DISABLE_AUTOSWITCH 0x80
- static inline void
- vnc_mute_spkr(struct wavnc_info *devc)
- {
- unsigned long flags;
- raw_spin_lock_irqsave(&nw_gpio_lock, flags);
- nw_cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
- raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
- }
- static void
- vnc_mute_lout(struct wavnc_info *devc)
- {
- unsigned int left, right;
- left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
- right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
- if (devc->line_mute_state) {
- left &= ~1;
- right &= ~1;
- } else {
- left |= 1;
- right |= 1;
- }
- waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
-
- }
- static int
- vnc_volume_slider(struct wavnc_info *devc)
- {
- static signed int old_slider_volume;
- unsigned long flags;
- signed int volume = 255;
- *CSR_TIMER1_LOAD = 0x00ffffff;
- spin_lock_irqsave(&waveartist_lock, flags);
- outb(0xFF, 0x201);
- *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
- while (volume && (inb(0x201) & 0x01))
- volume--;
- *CSR_TIMER1_CNTL = 0;
- spin_unlock_irqrestore(&waveartist_lock,flags);
-
- volume = 0x00ffffff - *CSR_TIMER1_VALUE;
- #ifndef REVERSE
- volume = 150 - (volume >> 5);
- #else
- volume = (volume >> 6) - 25;
- #endif
- if (volume < 0)
- volume = 0;
- if (volume > 100)
- volume = 100;
-
- if (abs(volume - old_slider_volume) > 7) {
- old_slider_volume = volume;
- if (debug_flg & DEBUG_MIXER)
- printk(KERN_DEBUG "Slider volume: %d.\n", volume);
- }
- return old_slider_volume;
- }
- static unsigned int
- netwinder_select_input(struct wavnc_info *devc, unsigned int recmask,
- unsigned char *dev_l, unsigned char *dev_r)
- {
- unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
- if (recmask & SOUND_MASK_IMIX) {
- recmask = SOUND_MASK_IMIX;
- recdev_l = ADC_MUX_MIXER;
- recdev_r = ADC_MUX_MIXER;
- } else if (recmask & SOUND_MASK_LINE) {
- recmask = SOUND_MASK_LINE;
- recdev_l = ADC_MUX_LINE;
- recdev_r = ADC_MUX_LINE;
- } else if (recmask & SOUND_MASK_LINE1) {
- recmask = SOUND_MASK_LINE1;
- waveartist_cmd1(devc, WACMD_SET_MONO);
- recdev_l = ADC_MUX_MIC;
- recdev_r = ADC_MUX_NONE;
- } else if (recmask & SOUND_MASK_PHONEIN) {
- recmask = SOUND_MASK_PHONEIN;
- waveartist_cmd1(devc, WACMD_SET_MONO);
- recdev_l = ADC_MUX_AUX1;
- recdev_r = ADC_MUX_NONE;
- } else if (recmask & SOUND_MASK_MIC) {
- recmask = SOUND_MASK_MIC;
- waveartist_cmd1(devc, WACMD_SET_MONO | 0x100);
- recdev_l = ADC_MUX_NONE;
- recdev_r = ADC_MUX_MIC;
- }
- *dev_l = recdev_l;
- *dev_r = recdev_r;
- return recmask;
- }
- static int
- netwinder_decode_mixer(struct wavnc_info *devc, int dev, unsigned char lev_l,
- unsigned char lev_r)
- {
- switch (dev) {
- case SOUND_MIXER_VOLUME:
- case SOUND_MIXER_SYNTH:
- case SOUND_MIXER_PCM:
- case SOUND_MIXER_LINE:
- case SOUND_MIXER_IGAIN:
- devc->levels[dev] = lev_l | lev_r << 8;
- break;
- case SOUND_MIXER_MIC:
- devc->levels[SOUND_MIXER_MIC] &= 0xff;
- devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
- break;
- case SOUND_MIXER_LINE1:
- devc->levels[SOUND_MIXER_MIC] &= 0xff00;
- devc->levels[SOUND_MIXER_MIC] |= lev_l;
- dev = SOUND_MIXER_MIC;
- break;
- case SOUND_MIXER_PHONEIN:
- devc->levels[SOUND_MIXER_LINE1] = lev_l;
- dev = SOUND_MIXER_LINE1;
- break;
- case SOUND_MIXER_IMIX:
- case SOUND_MIXER_PHONEOUT:
- break;
- default:
- dev = -EINVAL;
- break;
- }
- return dev;
- }
- static int netwinder_get_mixer(struct wavnc_info *devc, int dev)
- {
- int levels;
- switch (dev) {
- case SOUND_MIXER_VOLUME:
- case SOUND_MIXER_SYNTH:
- case SOUND_MIXER_PCM:
- case SOUND_MIXER_LINE:
- case SOUND_MIXER_IGAIN:
- levels = devc->levels[dev];
- break;
- case SOUND_MIXER_MIC:
- levels = devc->levels[SOUND_MIXER_MIC] >> 8;
- levels |= levels << 8;
- break;
- case SOUND_MIXER_LINE1:
- levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
- levels |= levels << 8;
- break;
- case SOUND_MIXER_PHONEIN:
- levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
- levels |= levels << 8;
- break;
- default:
- levels = 0;
- }
- return levels;
- }
- static const struct waveartist_mixer_info netwinder_mixer = {
- .supported_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
- SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
- SOUND_MASK_LINE | SOUND_MASK_MIC |
- SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
- SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT|
- SOUND_MASK_IGAIN,
- .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
- SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
- SOUND_MASK_PHONEIN,
- .stereo_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
- SOUND_MASK_PCM | SOUND_MASK_LINE |
- SOUND_MASK_IMIX | SOUND_MASK_IGAIN,
- .select_input = netwinder_select_input,
- .decode_mixer = netwinder_decode_mixer,
- .get_mixer = netwinder_get_mixer,
- };
- static void
- vnc_configure_mixer(struct wavnc_info *devc, unsigned int recmask)
- {
- if (!devc->no_autoselect) {
- if (devc->handset_detect) {
- recmask = SOUND_MASK_LINE1;
- devc->spkr_mute_state = devc->line_mute_state = 1;
- } else if (devc->telephone_detect) {
- recmask = SOUND_MASK_PHONEIN;
- devc->spkr_mute_state = devc->line_mute_state = 1;
- } else {
-
- if ((devc->recmask & SOUND_MASK_LINE) == 0)
- devc->recmask = SOUND_MASK_MIC;
- devc->spkr_mute_state = devc->line_mute_state = 0;
- }
- vnc_mute_spkr(devc);
- vnc_mute_lout(devc);
- if (recmask != devc->recmask)
- waveartist_set_recmask(devc, recmask);
- }
- }
- static int
- vnc_slider(struct wavnc_info *devc)
- {
- signed int slider_volume;
- unsigned int temp, old_hs, old_td;
-
- temp = inb(0x201);
- old_hs = devc->handset_detect;
- old_td = devc->telephone_detect;
- devc->handset_detect = !(temp & 0x10);
- devc->telephone_detect = !!(temp & 0x20);
- if (!devc->no_autoselect &&
- (old_hs != devc->handset_detect ||
- old_td != devc->telephone_detect))
- vnc_configure_mixer(devc, devc->recmask);
- slider_volume = vnc_volume_slider(devc);
-
- if (abs(devc->slider_vol - slider_volume) > 20)
- devc->use_slider = 1;
-
- temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
- if (slider_volume != temp && devc->use_slider) {
- devc->slider_vol = slider_volume;
- waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
- slider_volume | slider_volume << 8);
- return 1;
- }
- return 0;
- }
- static void
- vnc_slider_tick(unsigned long data)
- {
- int next_timeout;
- if (vnc_slider(adev_info + data))
- next_timeout = 5;
- else
- next_timeout = VNC_TIMER_PERIOD;
- mod_timer(&vnc_timer, jiffies + next_timeout);
- }
- static int
- vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
- {
- struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
- int val;
- switch (cmd) {
- case SOUND_MIXER_PRIVATE1:
- {
- u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
- int val;
- if (get_user(val, arg))
- return -EFAULT;
-
- if (val & ~(VNC_MUTE_INTERNAL_SPKR |
- VNC_MUTE_LINE_OUT |
- VNC_DISABLE_AUTOSWITCH))
- return -EINVAL;
- prev_auto_state = devc->no_autoselect;
- prev_spkr_mute = devc->spkr_mute_state;
- prev_line_mute = devc->line_mute_state;
- devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
- devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
- devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
- if (prev_spkr_mute != devc->spkr_mute_state)
- vnc_mute_spkr(devc);
- if (prev_line_mute != devc->line_mute_state)
- vnc_mute_lout(devc);
- if (prev_auto_state != devc->no_autoselect)
- vnc_configure_mixer(devc, devc->recmask);
- return 0;
- }
- case SOUND_MIXER_PRIVATE2:
- if (get_user(val, arg))
- return -EFAULT;
- switch (val) {
- #define VNC_SOUND_PAUSE 0x53
- #define VNC_SOUND_RESUME 0x57
- case VNC_SOUND_PAUSE:
- waveartist_cmd1(devc, 0x16);
- break;
- case VNC_SOUND_RESUME:
- waveartist_cmd1(devc, 0x18);
- break;
- default:
- return -EINVAL;
- }
- return 0;
-
- case SOUND_MIXER_PRIVATE3:
- {
- unsigned long flags;
- int mixer_reg[15], i, val;
- if (get_user(val, arg))
- return -EFAULT;
- if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
- return -EFAULT;
- switch (mixer_reg[14]) {
- case MIXER_PRIVATE3_RESET:
- waveartist_mixer_reset(devc);
- break;
- case MIXER_PRIVATE3_WRITE:
- waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
- waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
- waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
- waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
- waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
- waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
- waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
- break;
- case MIXER_PRIVATE3_READ:
- spin_lock_irqsave(&waveartist_lock, flags);
- for (i = 0x30; i < 14 << 8; i += 1 << 8)
- waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
- spin_unlock_irqrestore(&waveartist_lock, flags);
- if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
- return -EFAULT;
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
-
- case SOUND_MIXER_PRIVATE4:
- val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
- (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
- (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
- (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
- (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
- return put_user(val, arg) ? -EFAULT : 0;
- }
- if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
-
- if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
- devc->use_slider = 0;
-
- if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
- unsigned int val, l, r;
- if (get_user(val, arg))
- return -EFAULT;
- l = val & 0x7f;
- r = (val & 0x7f00) >> 8;
- val = (l + r) / 2;
- devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
- devc->spkr_mute_state = (val <= 50);
- vnc_mute_spkr(devc);
- return 0;
- }
- }
- return -ENOIOCTLCMD;
- }
- #endif
- static struct address_info cfg;
- static int attached;
- static int __initdata io = 0;
- static int __initdata irq = 0;
- static int __initdata dma = 0;
- static int __initdata dma2 = 0;
- static int __init init_waveartist(void)
- {
- const struct waveartist_mixer_info *mix;
- if (!io && machine_is_netwinder()) {
-
- io = 0x250;
- irq = 12;
- dma = 3;
- dma2 = 7;
- }
- mix = &waveartist_mixer;
- #ifdef CONFIG_ARCH_NETWINDER
- if (machine_is_netwinder())
- mix = &netwinder_mixer;
- #endif
- cfg.io_base = io;
- cfg.irq = irq;
- cfg.dma = dma;
- cfg.dma2 = dma2;
- if (!probe_waveartist(&cfg))
- return -ENODEV;
- attach_waveartist(&cfg, mix);
- attached = 1;
- return 0;
- }
- static void __exit cleanup_waveartist(void)
- {
- if (attached)
- unload_waveartist(&cfg);
- }
- module_init(init_waveartist);
- module_exit(cleanup_waveartist);
- #ifndef MODULE
- static int __init setup_waveartist(char *str)
- {
-
- int ints[5];
-
- str = get_options(str, ARRAY_SIZE(ints), ints);
-
- io = ints[1];
- irq = ints[2];
- dma = ints[3];
- dma2 = ints[4];
- return 1;
- }
- __setup("waveartist=", setup_waveartist);
- #endif
- MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
- module_param(io, int, 0);
- module_param(irq, int, 0);
- module_param(dma, int, 0);
- module_param(dma2, int, 0);
- MODULE_LICENSE("GPL");
|