12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292 |
- /*
- * Driver for the VINO (Video In No Out) system found in SGI Indys.
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License version 2 as published by the Free Software Foundation.
- *
- * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
- *
- * Based on the previous version of the driver for 2.4 kernels by:
- * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
- */
- /*
- * TODO:
- * - remove "hacks" from memory allocation code and implement nopage()
- * - check decimation, calculating and reporting image size when
- * using decimation
- * - check vino_acquire_input(), vino_set_input() and channel
- * ownership handling
- * - report VINO error-interrupts via ioctls ?
- * - implement picture controls (all implemented?)
- * - use macros for boolean values (?)
- * - implement user mode buffers and overlay (?)
- */
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/delay.h>
- #include <linux/errno.h>
- #include <linux/fs.h>
- #include <linux/kernel.h>
- #include <linux/mm.h>
- #include <linux/interrupt.h>
- #include <linux/dma-mapping.h>
- #include <linux/time.h>
- #include <linux/moduleparam.h>
- #ifdef CONFIG_KMOD
- #include <linux/kmod.h>
- #endif
- #include <linux/i2c.h>
- #include <linux/i2c-algo-sgi.h>
- #include <linux/videodev.h>
- #include <linux/videodev2.h>
- #include <linux/video_decoder.h>
- #include <asm/paccess.h>
- #include <asm/io.h>
- #include <asm/sgi/ip22.h>
- #include <asm/sgi/mc.h>
- #include "vino.h"
- #include "saa7191.h"
- #include "indycam.h"
- /* Uncomment the following line to get lots and lots of (mostly useless)
- * debug info.
- * Note that the debug output also slows down the driver significantly */
- // #define VINO_DEBUG
- #define VINO_MODULE_VERSION "0.0.3"
- #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 3)
- MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
- MODULE_VERSION(VINO_MODULE_VERSION);
- MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
- MODULE_LICENSE("GPL");
- #define mem_map_reserve(p) set_bit(PG_reserved, &((p)->flags))
- #define mem_map_unreserve(p) clear_bit(PG_reserved, &((p)->flags))
- #ifdef VINO_DEBUG
- #define dprintk(x...) printk("VINO: " x);
- #else
- #define dprintk(x...)
- #endif
- #define VINO_NO_CHANNEL 0
- #define VINO_CHANNEL_A 1
- #define VINO_CHANNEL_B 2
- #define VINO_PAL_WIDTH 768
- #define VINO_PAL_HEIGHT 576
- #define VINO_NTSC_WIDTH 640
- #define VINO_NTSC_HEIGHT 480
- #define VINO_MIN_WIDTH 32
- #define VINO_MIN_HEIGHT 32
- #define VINO_CLIPPING_START_ODD_D1 1
- #define VINO_CLIPPING_START_ODD_PAL 1
- #define VINO_CLIPPING_START_ODD_NTSC 1
- #define VINO_CLIPPING_START_EVEN_D1 2
- #define VINO_CLIPPING_START_EVEN_PAL 2
- #define VINO_CLIPPING_START_EVEN_NTSC 2
- #define VINO_INPUT_CHANNEL_COUNT 3
- #define VINO_INPUT_NONE -1
- #define VINO_INPUT_COMPOSITE 0
- #define VINO_INPUT_SVIDEO 1
- #define VINO_INPUT_D1 2
- #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
- #define VINO_FIFO_THRESHOLD_DEFAULT 512
- /*#define VINO_FRAMEBUFFER_SIZE (VINO_PAL_WIDTH * VINO_PAL_HEIGHT * 4 \
- + 2 * PAGE_SIZE)*/
- #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
- * VINO_PAL_HEIGHT * 4 \
- + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
- #define VINO_FRAMEBUFFER_MAX_COUNT 8
- #define VINO_FRAMEBUFFER_UNUSED 0
- #define VINO_FRAMEBUFFER_IN_USE 1
- #define VINO_FRAMEBUFFER_READY 2
- #define VINO_QUEUE_ERROR -1
- #define VINO_QUEUE_MAGIC 0x20050125
- #define VINO_MEMORY_NONE 0
- #define VINO_MEMORY_MMAP 1
- #define VINO_MEMORY_USERPTR 2
- #define VINO_DUMMY_DESC_COUNT 4
- #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
- /* the number is the index for vino_data_formats */
- #define VINO_DATA_FMT_NONE -1
- #define VINO_DATA_FMT_GREY 0
- #define VINO_DATA_FMT_RGB332 1
- #define VINO_DATA_FMT_RGB32 2
- #define VINO_DATA_FMT_YUV 3
- //#define VINO_DATA_FMT_RGB24 4
- #define VINO_DATA_FMT_COUNT 4
- #define VINO_DATA_NORM_NONE -1
- #define VINO_DATA_NORM_NTSC 0
- #define VINO_DATA_NORM_PAL 1
- #define VINO_DATA_NORM_SECAM 2
- #define VINO_DATA_NORM_D1 3
- /* The following is a special entry that can be used to
- * autodetect the norm. */
- #define VINO_DATA_NORM_AUTO 0xff
- #define VINO_DATA_NORM_COUNT 4
- /* Internal data structure definitions */
- struct vino_input {
- char *name;
- v4l2_std_id std;
- };
- struct vino_clipping {
- unsigned int left, right, top, bottom;
- };
- struct vino_data_format {
- /* the description */
- char *description;
- /* bytes per pixel */
- unsigned int bpp;
- /* V4L2 fourcc code */
- __u32 pixelformat;
- /* V4L2 colorspace (duh!) */
- enum v4l2_colorspace colorspace;
- };
- struct vino_data_norm {
- char *description;
- unsigned int width, height;
- struct vino_clipping odd;
- struct vino_clipping even;
- v4l2_std_id std;
- unsigned int fps_min, fps_max;
- __u32 framelines;
- };
- struct vino_descriptor_table {
- /* the number of PAGE_SIZE sized pages in the buffer */
- unsigned int page_count;
- /* virtual (kmalloc'd) pointers to the actual data
- * (in PAGE_SIZE chunks, used with mmap streaming) */
- unsigned long *virtual;
- /* cpu address for the VINO descriptor table
- * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
- unsigned long *dma_cpu;
- /* dma address for the VINO descriptor table
- * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
- dma_addr_t dma;
- };
- struct vino_framebuffer {
- /* identifier nubmer */
- unsigned int id;
- /* the length of the whole buffer */
- unsigned int size;
- /* the length of actual data in buffer */
- unsigned int data_size;
- /* the data format */
- unsigned int data_format;
- /* the state of buffer data */
- unsigned int state;
- /* is the buffer mapped in user space? */
- unsigned int map_count;
- /* memory offset for mmap() */
- unsigned int offset;
- /* frame counter */
- unsigned int frame_counter;
- /* timestamp (written when image capture finishes) */
- struct timeval timestamp;
- struct vino_descriptor_table desc_table;
- spinlock_t state_lock;
- };
- struct vino_framebuffer_fifo {
- unsigned int length;
- unsigned int used;
- unsigned int head;
- unsigned int tail;
- unsigned int data[VINO_FRAMEBUFFER_MAX_COUNT];
- };
- struct vino_framebuffer_queue {
- unsigned int magic;
- /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
- unsigned int type;
- unsigned int length;
- /* data field of in and out contain index numbers for buffer */
- struct vino_framebuffer_fifo in;
- struct vino_framebuffer_fifo out;
- struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_MAX_COUNT];
- spinlock_t queue_lock;
- struct semaphore queue_sem;
- wait_queue_head_t frame_wait_queue;
- };
- struct vino_channel_settings {
- unsigned int channel;
- int input;
- unsigned int data_format;
- unsigned int data_norm;
- struct vino_clipping clipping;
- unsigned int decimation;
- unsigned int line_size;
- unsigned int alpha;
- unsigned int fps;
- unsigned int framert_reg;
- unsigned int fifo_threshold;
- struct vino_framebuffer_queue fb_queue;
- /* number of the current field */
- unsigned int field;
- /* read in progress */
- int reading;
- /* streaming is active */
- int streaming;
- /* the driver is currently processing the queue */
- int capturing;
- struct semaphore sem;
- spinlock_t capture_lock;
- unsigned int users;
- /* V4L support */
- struct video_device *v4l_device;
- };
- struct vino_client {
- /* the channel which owns this client:
- * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
- unsigned int owner;
- struct i2c_client *driver;
- };
- struct vino_settings {
- struct vino_channel_settings a;
- struct vino_channel_settings b;
- struct vino_client decoder;
- struct vino_client camera;
- /* a lock for vino register access */
- spinlock_t vino_lock;
- /* a lock for channel input changes */
- spinlock_t input_lock;
- unsigned long dummy_page;
- struct vino_descriptor_table dummy_desc_table;
- };
- /* Module parameters */
- /*
- * Using vino_pixel_conversion the ARGB32-format pixels supplied
- * by the VINO chip can be converted to more common formats
- * like RGBA32 (or probably RGB24 in the future). This way we
- * can give out data that can be specified correctly with
- * the V4L2-definitions.
- *
- * The pixel format is specified as RGBA32 when no conversion
- * is used.
- *
- * Note that this only affects the 32-bit bit depth.
- *
- * Use non-zero value to enable conversion.
- */
- static int vino_pixel_conversion = 0;
- module_param_named(pixelconv, vino_pixel_conversion, int, 0);
- MODULE_PARM_DESC(pixelconv,
- "enable pixel conversion (non-zero value enables)");
- /* Internal data structures */
- static struct sgi_vino *vino;
- static struct vino_settings *vino_drvdata;
- static const char *vino_driver_name = "vino";
- static const char *vino_driver_description = "SGI VINO";
- static const char *vino_bus_name = "GIO64 bus";
- static const char *vino_v4l_device_name_a = "SGI VINO Channel A";
- static const char *vino_v4l_device_name_b = "SGI VINO Channel B";
- static const struct vino_input vino_inputs[] = {
- {
- .name = "Composite",
- .std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
- },{
- .name = "S-Video",
- .std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
- },{
- .name = "D1 (IndyCam)",
- .std = V4L2_STD_NTSC,
- }
- };
- static const struct vino_data_format vino_data_formats[] = {
- {
- .description = "8-bit greyscale",
- .bpp = 1,
- .pixelformat = V4L2_PIX_FMT_GREY,
- .colorspace = V4L2_COLORSPACE_SMPTE170M,
- },{
- .description = "8-bit dithered RGB 3-3-2",
- .bpp = 1,
- .pixelformat = V4L2_PIX_FMT_RGB332,
- .colorspace = V4L2_COLORSPACE_SRGB,
- },{
- .description = "32-bit RGB",
- .bpp = 4,
- .pixelformat = V4L2_PIX_FMT_RGB32,
- .colorspace = V4L2_COLORSPACE_SRGB,
- },{
- .description = "YUV 4:2:2",
- .bpp = 4,
- .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
- .colorspace = V4L2_COLORSPACE_SMPTE170M,
- }/*,{
- .description = "24-bit RGB",
- .bpp = 3,
- .pixelformat = V4L2_PIX_FMT_RGB24,
- .colorspace = V4L2_COLORSPACE_SRGB,
- }*/
- };
- static const struct vino_data_norm vino_data_norms[] = {
- {
- .description = "NTSC",
- .std = V4L2_STD_NTSC,
- .fps_min = 6,
- .fps_max = 30,
- .framelines = 525,
- .width = VINO_NTSC_WIDTH,
- .height = VINO_NTSC_HEIGHT,
- .odd = {
- .top = VINO_CLIPPING_START_ODD_NTSC,
- .left = 0,
- .bottom = VINO_CLIPPING_START_ODD_NTSC
- + VINO_NTSC_HEIGHT / 2 - 1,
- .right = VINO_NTSC_WIDTH,
- },
- .even = {
- .top = VINO_CLIPPING_START_EVEN_NTSC,
- .left = 0,
- .bottom = VINO_CLIPPING_START_EVEN_NTSC
- + VINO_NTSC_HEIGHT / 2 - 1,
- .right = VINO_NTSC_WIDTH,
- },
- },{
- .description = "PAL",
- .std = V4L2_STD_PAL,
- .fps_min = 5,
- .fps_max = 25,
- .framelines = 625,
- .width = VINO_PAL_WIDTH,
- .height = VINO_PAL_HEIGHT,
- .odd = {
- .top = VINO_CLIPPING_START_ODD_PAL,
- .left = 0,
- .bottom = VINO_CLIPPING_START_ODD_PAL
- + VINO_PAL_HEIGHT / 2 - 1,
- .right = VINO_PAL_WIDTH,
- },
- .even = {
- .top = VINO_CLIPPING_START_EVEN_PAL,
- .left = 0,
- .bottom = VINO_CLIPPING_START_EVEN_PAL
- + VINO_PAL_HEIGHT / 2 - 1,
- .right = VINO_PAL_WIDTH,
- },
- },{
- .description = "SECAM",
- .std = V4L2_STD_SECAM,
- .fps_min = 5,
- .fps_max = 25,
- .framelines = 625,
- .width = VINO_PAL_WIDTH,
- .height = VINO_PAL_HEIGHT,
- .odd = {
- .top = VINO_CLIPPING_START_ODD_PAL,
- .left = 0,
- .bottom = VINO_CLIPPING_START_ODD_PAL
- + VINO_PAL_HEIGHT / 2 - 1,
- .right = VINO_PAL_WIDTH,
- },
- .even = {
- .top = VINO_CLIPPING_START_EVEN_PAL,
- .left = 0,
- .bottom = VINO_CLIPPING_START_EVEN_PAL
- + VINO_PAL_HEIGHT / 2 - 1,
- .right = VINO_PAL_WIDTH,
- },
- },{
- .description = "NTSC (D1 input)",
- .std = V4L2_STD_NTSC,
- .fps_min = 6,
- .fps_max = 30,
- .framelines = 525,
- .width = VINO_NTSC_WIDTH,
- .height = VINO_NTSC_HEIGHT,
- .odd = {
- .top = VINO_CLIPPING_START_ODD_D1,
- .left = 0,
- .bottom = VINO_CLIPPING_START_ODD_D1
- + VINO_NTSC_HEIGHT / 2 - 1,
- .right = VINO_NTSC_WIDTH,
- },
- .even = {
- .top = VINO_CLIPPING_START_EVEN_D1,
- .left = 0,
- .bottom = VINO_CLIPPING_START_EVEN_D1
- + VINO_NTSC_HEIGHT / 2 - 1,
- .right = VINO_NTSC_WIDTH,
- },
- }
- };
- #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
- struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
- {
- .id = V4L2_CID_AUTOGAIN,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Automatic Gain Control",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = INDYCAM_AGC_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_AUTO_WHITE_BALANCE,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Automatic White Balance",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = INDYCAM_AWB_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_GAIN,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Gain",
- .minimum = INDYCAM_GAIN_MIN,
- .maximum = INDYCAM_GAIN_MAX,
- .step = 1,
- .default_value = INDYCAM_GAIN_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_PRIVATE_BASE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Red Saturation",
- .minimum = INDYCAM_RED_SATURATION_MIN,
- .maximum = INDYCAM_RED_SATURATION_MAX,
- .step = 1,
- .default_value = INDYCAM_RED_SATURATION_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_PRIVATE_BASE + 1,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Blue Saturation",
- .minimum = INDYCAM_BLUE_SATURATION_MIN,
- .maximum = INDYCAM_BLUE_SATURATION_MAX,
- .step = 1,
- .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_RED_BALANCE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Red Balance",
- .minimum = INDYCAM_RED_BALANCE_MIN,
- .maximum = INDYCAM_RED_BALANCE_MAX,
- .step = 1,
- .default_value = INDYCAM_RED_BALANCE_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_BLUE_BALANCE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Blue Balance",
- .minimum = INDYCAM_BLUE_BALANCE_MIN,
- .maximum = INDYCAM_BLUE_BALANCE_MAX,
- .step = 1,
- .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_EXPOSURE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Shutter Control",
- .minimum = INDYCAM_SHUTTER_MIN,
- .maximum = INDYCAM_SHUTTER_MAX,
- .step = 1,
- .default_value = INDYCAM_SHUTTER_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_GAMMA,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Gamma",
- .minimum = INDYCAM_GAMMA_MIN,
- .maximum = INDYCAM_GAMMA_MAX,
- .step = 1,
- .default_value = INDYCAM_GAMMA_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- }
- };
- #define VINO_SAA7191_V4L2_CONTROL_COUNT 2
- struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
- {
- .id = V4L2_CID_HUE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Hue",
- .minimum = SAA7191_HUE_MIN,
- .maximum = SAA7191_HUE_MAX,
- .step = 1,
- .default_value = SAA7191_HUE_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- },{
- .id = V4L2_CID_PRIVATE_BASE,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "VTR Time Constant",
- .minimum = SAA7191_VTRC_MIN,
- .maximum = SAA7191_VTRC_MAX,
- .step = 1,
- .default_value = SAA7191_VTRC_DEFAULT,
- .flags = 0,
- .reserved = { 0, 0 },
- }
- };
- /* VINO I2C bus functions */
- unsigned i2c_vino_getctrl(void *data)
- {
- return vino->i2c_control;
- }
- void i2c_vino_setctrl(void *data, unsigned val)
- {
- vino->i2c_control = val;
- }
- unsigned i2c_vino_rdata(void *data)
- {
- return vino->i2c_data;
- }
- void i2c_vino_wdata(void *data, unsigned val)
- {
- vino->i2c_data = val;
- }
- static struct i2c_algo_sgi_data i2c_sgi_vino_data =
- {
- .getctrl = &i2c_vino_getctrl,
- .setctrl = &i2c_vino_setctrl,
- .rdata = &i2c_vino_rdata,
- .wdata = &i2c_vino_wdata,
- .xfer_timeout = 200,
- .ack_timeout = 1000,
- };
- /*
- * There are two possible clients on VINO I2C bus, so we limit usage only
- * to them.
- */
- static int i2c_vino_client_reg(struct i2c_client *client)
- {
- int ret = 0;
- spin_lock(&vino_drvdata->input_lock);
- switch (client->driver->id) {
- case I2C_DRIVERID_SAA7191:
- if (vino_drvdata->decoder.driver)
- ret = -EBUSY;
- else
- vino_drvdata->decoder.driver = client;
- break;
- case I2C_DRIVERID_INDYCAM:
- if (vino_drvdata->camera.driver)
- ret = -EBUSY;
- else
- vino_drvdata->camera.driver = client;
- break;
- default:
- ret = -ENODEV;
- }
- spin_unlock(&vino_drvdata->input_lock);
- return ret;
- }
- static int i2c_vino_client_unreg(struct i2c_client *client)
- {
- int ret = 0;
- spin_lock(&vino_drvdata->input_lock);
- if (client == vino_drvdata->decoder.driver) {
- if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL)
- ret = -EBUSY;
- else
- vino_drvdata->decoder.driver = NULL;
- } else if (client == vino_drvdata->camera.driver) {
- if (vino_drvdata->camera.owner != VINO_NO_CHANNEL)
- ret = -EBUSY;
- else
- vino_drvdata->camera.driver = NULL;
- }
- spin_unlock(&vino_drvdata->input_lock);
- return ret;
- }
- static struct i2c_adapter vino_i2c_adapter =
- {
- .name = "VINO I2C bus",
- .id = I2C_HW_SGI_VINO,
- .algo_data = &i2c_sgi_vino_data,
- .client_register = &i2c_vino_client_reg,
- .client_unregister = &i2c_vino_client_unreg,
- };
- static int vino_i2c_add_bus(void)
- {
- return i2c_sgi_add_bus(&vino_i2c_adapter);
- }
- static int vino_i2c_del_bus(void)
- {
- return i2c_sgi_del_bus(&vino_i2c_adapter);
- }
- static int i2c_camera_command(unsigned int cmd, void *arg)
- {
- return vino_drvdata->camera.driver->
- driver->command(vino_drvdata->camera.driver,
- cmd, arg);
- }
- static int i2c_decoder_command(unsigned int cmd, void *arg)
- {
- return vino_drvdata->decoder.driver->
- driver->command(vino_drvdata->decoder.driver,
- cmd, arg);
- }
- /* VINO framebuffer/DMA descriptor management */
- static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
- unsigned int count)
- {
- unsigned int i;
- dprintk("vino_free_buffer_with_count(): count = %d\n", count);
- for (i = 0; i < count; i++) {
- mem_map_unreserve(virt_to_page(fb->desc_table.virtual[i]));
- dma_unmap_single(NULL,
- fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
- PAGE_SIZE, DMA_FROM_DEVICE);
- free_page(fb->desc_table.virtual[i]);
- }
- dma_free_coherent(NULL,
- VINO_PAGE_RATIO * (fb->desc_table.page_count + 4) *
- sizeof(dma_addr_t), (void *)fb->desc_table.dma_cpu,
- fb->desc_table.dma);
- kfree(fb->desc_table.virtual);
- memset(fb, 0, sizeof(struct vino_framebuffer));
- }
- static void vino_free_buffer(struct vino_framebuffer *fb)
- {
- vino_free_buffer_with_count(fb, fb->desc_table.page_count);
- }
- static int vino_allocate_buffer(struct vino_framebuffer *fb,
- unsigned int size)
- {
- unsigned int count, i, j;
- int ret = 0;
- dprintk("vino_allocate_buffer():\n");
- if (size < 1)
- return -EINVAL;
- memset(fb, 0, sizeof(struct vino_framebuffer));
- count = ((size / PAGE_SIZE) + 4) & ~3;
- dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
- size, count);
- /* allocate memory for table with virtual (page) addresses */
- fb->desc_table.virtual = (unsigned long *)
- kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
- if (!fb->desc_table.virtual)
- return -ENOMEM;
- /* allocate memory for table with dma addresses
- * (has space for four extra descriptors) */
- fb->desc_table.dma_cpu =
- dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
- sizeof(dma_addr_t), &fb->desc_table.dma,
- GFP_KERNEL | GFP_DMA);
- if (!fb->desc_table.dma_cpu) {
- ret = -ENOMEM;
- goto out_free_virtual;
- }
- /* allocate pages for the buffer and acquire the according
- * dma addresses */
- for (i = 0; i < count; i++) {
- dma_addr_t dma_data_addr;
- fb->desc_table.virtual[i] =
- get_zeroed_page(GFP_KERNEL | GFP_DMA);
- if (!fb->desc_table.virtual[i]) {
- ret = -ENOBUFS;
- break;
- }
- dma_data_addr =
- dma_map_single(NULL,
- (void *)fb->desc_table.virtual[i],
- PAGE_SIZE, DMA_FROM_DEVICE);
- for (j = 0; j < VINO_PAGE_RATIO; j++) {
- fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
- dma_data_addr + VINO_PAGE_SIZE * j;
- }
- mem_map_reserve(virt_to_page(fb->desc_table.virtual[i]));
- }
- /* page_count needs to be set anyway, because the descriptor table has
- * been allocated according to this number */
- fb->desc_table.page_count = count;
- if (ret) {
- /* the descriptor with index i doesn't contain
- * a valid address yet */
- vino_free_buffer_with_count(fb, i);
- return ret;
- }
- //fb->size = size;
- fb->size = count * PAGE_SIZE;
- fb->data_format = VINO_DATA_FMT_NONE;
- /* set the dma stop-bit for the last (count+1)th descriptor */
- fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
- return 0;
- out_free_virtual:
- kfree(fb->desc_table.virtual);
- return ret;
- }
- #if 0
- /* user buffers not fully implemented yet */
- static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
- void *user,
- unsigned int size)
- {
- unsigned int count, i, j;
- int ret = 0;
- dprintk("vino_prepare_user_buffer():\n");
- if (size < 1)
- return -EINVAL;
- memset(fb, 0, sizeof(struct vino_framebuffer));
- count = ((size / PAGE_SIZE)) & ~3;
- dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
- size, count);
- /* allocate memory for table with virtual (page) addresses */
- fb->desc_table.virtual = (unsigned long *)
- kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
- if (!fb->desc_table.virtual)
- return -ENOMEM;
- /* allocate memory for table with dma addresses
- * (has space for four extra descriptors) */
- fb->desc_table.dma_cpu =
- dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
- sizeof(dma_addr_t), &fb->desc_table.dma,
- GFP_KERNEL | GFP_DMA);
- if (!fb->desc_table.dma_cpu) {
- ret = -ENOMEM;
- goto out_free_virtual;
- }
- /* allocate pages for the buffer and acquire the according
- * dma addresses */
- for (i = 0; i < count; i++) {
- dma_addr_t dma_data_addr;
- fb->desc_table.virtual[i] =
- get_zeroed_page(GFP_KERNEL | GFP_DMA);
- if (!fb->desc_table.virtual[i]) {
- ret = -ENOBUFS;
- break;
- }
- dma_data_addr =
- dma_map_single(NULL,
- (void *)fb->desc_table.virtual[i],
- PAGE_SIZE, DMA_FROM_DEVICE);
- for (j = 0; j < VINO_PAGE_RATIO; j++) {
- fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
- dma_data_addr + VINO_PAGE_SIZE * j;
- }
- mem_map_reserve(virt_to_page(fb->desc_table.virtual[i]));
- }
- /* page_count needs to be set anyway, because the descriptor table has
- * been allocated according to this number */
- fb->desc_table.page_count = count;
- if (ret) {
- /* the descriptor with index i doesn't contain
- * a valid address yet */
- vino_free_buffer_with_count(fb, i);
- return ret;
- }
- //fb->size = size;
- fb->size = count * PAGE_SIZE;
- /* set the dma stop-bit for the last (count+1)th descriptor */
- fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
- return 0;
- out_free_virtual:
- kfree(fb->desc_table.virtual);
- return ret;
- }
- #endif
- static void vino_sync_buffer(struct vino_framebuffer *fb)
- {
- int i;
- dprintk("vino_sync_buffer():\n");
- for (i = 0; i < fb->desc_table.page_count; i++)
- dma_sync_single(NULL,
- fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
- PAGE_SIZE, DMA_FROM_DEVICE);
- }
- /* Framebuffer fifo functions (need to be locked externally) */
- static void vino_fifo_init(struct vino_framebuffer_fifo *f,
- unsigned int length)
- {
- f->length = 0;
- f->used = 0;
- f->head = 0;
- f->tail = 0;
- if (length > VINO_FRAMEBUFFER_MAX_COUNT)
- length = VINO_FRAMEBUFFER_MAX_COUNT;
- f->length = length;
- }
- /* returns true/false */
- static int vino_fifo_has_id(struct vino_framebuffer_fifo *f, unsigned int id)
- {
- unsigned int i;
- for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) {
- if (f->data[i] == id)
- return 1;
- }
- return 0;
- }
- /* returns true/false */
- static int vino_fifo_full(struct vino_framebuffer_fifo *f)
- {
- return (f->used == f->length);
- }
- static unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f)
- {
- return f->used;
- }
- static int vino_fifo_enqueue(struct vino_framebuffer_fifo *f, unsigned int id)
- {
- if (id >= f->length) {
- return VINO_QUEUE_ERROR;
- }
- if (vino_fifo_has_id(f, id)) {
- return VINO_QUEUE_ERROR;
- }
- if (f->used < f->length) {
- f->data[f->tail] = id;
- f->tail = (f->tail + 1) % f->length;
- f->used++;
- } else {
- return VINO_QUEUE_ERROR;
- }
- return 0;
- }
- static int vino_fifo_peek(struct vino_framebuffer_fifo *f, unsigned int *id)
- {
- if (f->used > 0) {
- *id = f->data[f->head];
- } else {
- return VINO_QUEUE_ERROR;
- }
- return 0;
- }
- static int vino_fifo_dequeue(struct vino_framebuffer_fifo *f, unsigned int *id)
- {
- if (f->used > 0) {
- *id = f->data[f->head];
- f->head = (f->head + 1) % f->length;
- f->used--;
- } else {
- return VINO_QUEUE_ERROR;
- }
- return 0;
- }
- /* Framebuffer queue functions */
- /* execute with queue_lock locked */
- static void vino_queue_free_with_count(struct vino_framebuffer_queue *q,
- unsigned int length)
- {
- unsigned int i;
- q->length = 0;
- memset(&q->in, 0, sizeof(struct vino_framebuffer_fifo));
- memset(&q->out, 0, sizeof(struct vino_framebuffer_fifo));
- for (i = 0; i < length; i++) {
- dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
- i);
- vino_free_buffer(q->buffer[i]);
- kfree(q->buffer[i]);
- }
- q->type = VINO_MEMORY_NONE;
- q->magic = 0;
- }
- static void vino_queue_free(struct vino_framebuffer_queue *q)
- {
- dprintk("vino_queue_free():\n");
- if (q->magic != VINO_QUEUE_MAGIC)
- return;
- if (q->type != VINO_MEMORY_MMAP)
- return;
- down(&q->queue_sem);
- vino_queue_free_with_count(q, q->length);
- up(&q->queue_sem);
- }
- static int vino_queue_init(struct vino_framebuffer_queue *q,
- unsigned int *length)
- {
- unsigned int i;
- int ret = 0;
- dprintk("vino_queue_init(): length = %d\n", *length);
- if (q->magic == VINO_QUEUE_MAGIC) {
- dprintk("vino_queue_init(): queue already initialized!\n");
- return -EINVAL;
- }
- if (q->type != VINO_MEMORY_NONE) {
- dprintk("vino_queue_init(): queue already initialized!\n");
- return -EINVAL;
- }
- if (*length < 1)
- return -EINVAL;
- down(&q->queue_sem);
- if (*length > VINO_FRAMEBUFFER_MAX_COUNT)
- *length = VINO_FRAMEBUFFER_MAX_COUNT;
- q->length = 0;
- for (i = 0; i < *length; i++) {
- dprintk("vino_queue_init(): allocating buffer %d\n", i);
- q->buffer[i] = kmalloc(sizeof(struct vino_framebuffer),
- GFP_KERNEL);
- if (!q->buffer[i]) {
- dprintk("vino_queue_init(): kmalloc() failed\n");
- ret = -ENOMEM;
- break;
- }
- ret = vino_allocate_buffer(q->buffer[i],
- VINO_FRAMEBUFFER_SIZE);
- if (ret) {
- kfree(q->buffer[i]);
- dprintk("vino_queue_init(): "
- "vino_allocate_buffer() failed\n");
- break;
- }
- q->buffer[i]->id = i;
- if (i > 0) {
- q->buffer[i]->offset = q->buffer[i - 1]->offset +
- q->buffer[i - 1]->size;
- } else {
- q->buffer[i]->offset = 0;
- }
- spin_lock_init(&q->buffer[i]->state_lock);
- dprintk("vino_queue_init(): buffer = %d, offset = %d, "
- "size = %d\n", i, q->buffer[i]->offset,
- q->buffer[i]->size);
- }
- if (ret) {
- vino_queue_free_with_count(q, i);
- *length = 0;
- } else {
- q->length = *length;
- vino_fifo_init(&q->in, q->length);
- vino_fifo_init(&q->out, q->length);
- q->type = VINO_MEMORY_MMAP;
- q->magic = VINO_QUEUE_MAGIC;
- }
- up(&q->queue_sem);
- return ret;
- }
- static struct vino_framebuffer *vino_queue_add(struct
- vino_framebuffer_queue *q,
- unsigned int id)
- {
- struct vino_framebuffer *ret = NULL;
- unsigned int total;
- unsigned long flags;
- dprintk("vino_queue_add(): id = %d\n", id);
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- if (id >= q->length)
- goto out;
- /* not needed?: if (vino_fifo_full(&q->out)) {
- goto out;
- }*/
- /* check that outgoing queue isn't already full
- * (or that it won't become full) */
- total = vino_fifo_get_used(&q->in) +
- vino_fifo_get_used(&q->out);
- if (total >= q->length)
- goto out;
- if (vino_fifo_enqueue(&q->in, id))
- goto out;
- ret = q->buffer[id];
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static struct vino_framebuffer *vino_queue_transfer(struct
- vino_framebuffer_queue *q)
- {
- struct vino_framebuffer *ret = NULL;
- struct vino_framebuffer *fb;
- int id;
- unsigned long flags;
- dprintk("vino_queue_transfer():\n");
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- // now this actually removes an entry from the incoming queue
- if (vino_fifo_dequeue(&q->in, &id)) {
- goto out;
- }
- dprintk("vino_queue_transfer(): id = %d\n", id);
- fb = q->buffer[id];
- // we have already checked that the outgoing queue is not full, but...
- if (vino_fifo_enqueue(&q->out, id)) {
- printk(KERN_ERR "vino_queue_transfer(): "
- "outgoing queue is full, this shouldn't happen!\n");
- goto out;
- }
- ret = fb;
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- /* returns true/false */
- static int vino_queue_incoming_contains(struct vino_framebuffer_queue *q,
- unsigned int id)
- {
- int ret = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- ret = vino_fifo_has_id(&q->in, id);
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- /* returns true/false */
- static int vino_queue_outgoing_contains(struct vino_framebuffer_queue *q,
- unsigned int id)
- {
- int ret = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- ret = vino_fifo_has_id(&q->out, id);
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static int vino_queue_get_incoming(struct vino_framebuffer_queue *q,
- unsigned int *used)
- {
- int ret = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return VINO_QUEUE_ERROR;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0) {
- ret = VINO_QUEUE_ERROR;
- goto out;
- }
- *used = vino_fifo_get_used(&q->in);
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static int vino_queue_get_outgoing(struct vino_framebuffer_queue *q,
- unsigned int *used)
- {
- int ret = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return VINO_QUEUE_ERROR;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0) {
- ret = VINO_QUEUE_ERROR;
- goto out;
- }
- *used = vino_fifo_get_used(&q->out);
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static int vino_queue_get_total(struct vino_framebuffer_queue *q,
- unsigned int *total)
- {
- int ret = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return VINO_QUEUE_ERROR;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0) {
- ret = VINO_QUEUE_ERROR;
- goto out;
- }
- *total = vino_fifo_get_used(&q->in) +
- vino_fifo_get_used(&q->out);
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static struct vino_framebuffer *vino_queue_peek(struct
- vino_framebuffer_queue *q,
- unsigned int *id)
- {
- struct vino_framebuffer *ret = NULL;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- if (vino_fifo_peek(&q->in, id)) {
- goto out;
- }
- ret = q->buffer[*id];
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static struct vino_framebuffer *vino_queue_remove(struct
- vino_framebuffer_queue *q,
- unsigned int *id)
- {
- struct vino_framebuffer *ret = NULL;
- unsigned long flags;
- dprintk("vino_queue_remove():\n");
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- if (vino_fifo_dequeue(&q->out, id)) {
- goto out;
- }
- dprintk("vino_queue_remove(): id = %d\n", *id);
- ret = q->buffer[*id];
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static struct
- vino_framebuffer *vino_queue_get_buffer(struct vino_framebuffer_queue *q,
- unsigned int id)
- {
- struct vino_framebuffer *ret = NULL;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- if (q->length == 0)
- goto out;
- if (id >= q->length)
- goto out;
- ret = q->buffer[id];
- out:
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- static unsigned int vino_queue_get_length(struct vino_framebuffer_queue *q)
- {
- unsigned int length = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return length;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- length = q->length;
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return length;
- }
- static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue *q)
- {
- unsigned int i;
- int ret = 0;
- unsigned long flags;
- if (q->magic != VINO_QUEUE_MAGIC) {
- return ret;
- }
- spin_lock_irqsave(&q->queue_lock, flags);
- for (i = 0; i < q->length; i++) {
- if (q->buffer[i]->map_count > 0) {
- ret = 1;
- break;
- }
- }
- spin_unlock_irqrestore(&q->queue_lock, flags);
- return ret;
- }
- /* VINO functions */
- /* execute with input_lock locked */
- static void vino_update_line_size(struct vino_channel_settings *vcs)
- {
- unsigned int w = vcs->clipping.right - vcs->clipping.left;
- unsigned int d = vcs->decimation;
- unsigned int bpp = vino_data_formats[vcs->data_format].bpp;
- unsigned int lsize;
- dprintk("update_line_size(): before: w = %d, d = %d, "
- "line_size = %d\n", w, d, vcs->line_size);
- /* line size must be multiple of 8 bytes */
- lsize = (bpp * (w / d)) & ~7;
- w = (lsize / bpp) * d;
- vcs->clipping.right = vcs->clipping.left + w;
- vcs->line_size = lsize;
- dprintk("update_line_size(): after: w = %d, d = %d, "
- "line_size = %d\n", w, d, vcs->line_size);
- }
- /* execute with input_lock locked */
- static void vino_set_clipping(struct vino_channel_settings *vcs,
- unsigned int x, unsigned int y,
- unsigned int w, unsigned int h)
- {
- unsigned int maxwidth, maxheight;
- unsigned int d;
- maxwidth = vino_data_norms[vcs->data_norm].width;
- maxheight = vino_data_norms[vcs->data_norm].height;
- d = vcs->decimation;
- y &= ~1; /* odd/even fields */
- if (x > maxwidth) {
- x = 0;
- }
- if (y > maxheight) {
- y = 0;
- }
- if (((w / d) < VINO_MIN_WIDTH)
- || ((h / d) < VINO_MIN_HEIGHT)) {
- w = VINO_MIN_WIDTH * d;
- h = VINO_MIN_HEIGHT * d;
- }
- if ((x + w) > maxwidth) {
- w = maxwidth - x;
- if ((w / d) < VINO_MIN_WIDTH)
- x = maxwidth - VINO_MIN_WIDTH * d;
- }
- if ((y + h) > maxheight) {
- h = maxheight - y;
- if ((h / d) < VINO_MIN_HEIGHT)
- y = maxheight - VINO_MIN_HEIGHT * d;
- }
- vcs->clipping.left = x;
- vcs->clipping.top = y;
- vcs->clipping.right = x + w;
- vcs->clipping.bottom = y + h;
- vino_update_line_size(vcs);
- dprintk("clipping %d, %d, %d, %d / %d - %d\n",
- vcs->clipping.left, vcs->clipping.top, vcs->clipping.right,
- vcs->clipping.bottom, vcs->decimation, vcs->line_size);
- }
- /* execute with input_lock locked */
- static void vino_set_default_clipping(struct vino_channel_settings *vcs)
- {
- vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width,
- vino_data_norms[vcs->data_norm].height);
- }
- /* execute with input_lock locked */
- static void vino_set_scaling(struct vino_channel_settings *vcs,
- unsigned int w, unsigned int h)
- {
- unsigned int x, y, curw, curh, d;
- x = vcs->clipping.left;
- y = vcs->clipping.top;
- curw = vcs->clipping.right - vcs->clipping.left;
- curh = vcs->clipping.bottom - vcs->clipping.top;
- d = max(curw / w, curh / h);
- dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
- w, h, curw, curh, d);
- if (d < 1) {
- d = 1;
- }
- if (d > 8) {
- d = 8;
- }
- vcs->decimation = d;
- vino_set_clipping(vcs, x, y, w * d, h * d);
- dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs->clipping.left,
- vcs->clipping.top, vcs->clipping.right, vcs->clipping.bottom,
- vcs->decimation, vcs->line_size);
- }
- /* execute with input_lock locked */
- static void vino_reset_scaling(struct vino_channel_settings *vcs)
- {
- vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left,
- vcs->clipping.bottom - vcs->clipping.top);
- }
- /* execute with input_lock locked */
- static void vino_set_framerate(struct vino_channel_settings *vcs,
- unsigned int fps)
- {
- unsigned int mask;
- switch (vcs->data_norm) {
- case VINO_DATA_NORM_NTSC:
- case VINO_DATA_NORM_D1:
- fps = (unsigned int)(fps / 6) * 6; // FIXME: round!
- if (fps < vino_data_norms[vcs->data_norm].fps_min)
- fps = vino_data_norms[vcs->data_norm].fps_min;
- if (fps > vino_data_norms[vcs->data_norm].fps_max)
- fps = vino_data_norms[vcs->data_norm].fps_max;
- switch (fps) {
- case 6:
- mask = 0x003;
- break;
- case 12:
- mask = 0x0c3;
- break;
- case 18:
- mask = 0x333;
- break;
- case 24:
- mask = 0x3ff;
- break;
- case 30:
- mask = 0xfff;
- break;
- default:
- mask = VINO_FRAMERT_FULL;
- }
- vcs->framert_reg = VINO_FRAMERT_RT(mask);
- break;
- case VINO_DATA_NORM_PAL:
- case VINO_DATA_NORM_SECAM:
- fps = (unsigned int)(fps / 5) * 5; // FIXME: round!
- if (fps < vino_data_norms[vcs->data_norm].fps_min)
- fps = vino_data_norms[vcs->data_norm].fps_min;
- if (fps > vino_data_norms[vcs->data_norm].fps_max)
- fps = vino_data_norms[vcs->data_norm].fps_max;
- switch (fps) {
- case 5:
- mask = 0x003;
- break;
- case 10:
- mask = 0x0c3;
- break;
- case 15:
- mask = 0x333;
- break;
- case 20:
- mask = 0x0ff;
- break;
- case 25:
- mask = 0x3ff;
- break;
- default:
- mask = VINO_FRAMERT_FULL;
- }
- vcs->framert_reg = VINO_FRAMERT_RT(mask) | VINO_FRAMERT_PAL;
- break;
- }
- vcs->fps = fps;
- }
- /* execute with input_lock locked */
- static void vino_set_default_framerate(struct vino_channel_settings *vcs)
- {
- vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
- }
- /*
- * Prepare VINO for DMA transfer...
- * (execute only with vino_lock and input_lock locked)
- */
- static int vino_dma_setup(struct vino_channel_settings *vcs,
- struct vino_framebuffer *fb)
- {
- u32 ctrl, intr;
- struct sgi_vino_channel *ch;
- const struct vino_data_norm *norm;
- dprintk("vino_dma_setup():\n");
- vcs->field = 0;
- fb->frame_counter = 0;
- ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
- norm = &vino_data_norms[vcs->data_norm];
- ch->page_index = 0;
- ch->line_count = 0;
- /* VINO line size register is set 8 bytes less than actual */
- ch->line_size = vcs->line_size - 8;
- /* let VINO know where to transfer data */
- ch->start_desc_tbl = fb->desc_table.dma;
- ch->next_4_desc = fb->desc_table.dma;
- /* give vino time to fetch the first four descriptors, 5 usec
- * should be more than enough time */
- udelay(VINO_DESC_FETCH_DELAY);
- /* set the alpha register */
- ch->alpha = vcs->alpha;
- /* set clipping registers */
- ch->clip_start = VINO_CLIP_ODD(norm->odd.top + vcs->clipping.top / 2) |
- VINO_CLIP_EVEN(norm->even.top +
- vcs->clipping.top / 2) |
- VINO_CLIP_X(vcs->clipping.left);
- ch->clip_end = VINO_CLIP_ODD(norm->odd.top +
- vcs->clipping.bottom / 2 - 1) |
- VINO_CLIP_EVEN(norm->even.top +
- vcs->clipping.bottom / 2 - 1) |
- VINO_CLIP_X(vcs->clipping.right);
- /* FIXME: end-of-field bug workaround
- VINO_CLIP_X(VINO_PAL_WIDTH);
- */
- /* set the size of actual content in the buffer (DECIMATION !) */
- fb->data_size = ((vcs->clipping.right - vcs->clipping.left) /
- vcs->decimation) *
- ((vcs->clipping.bottom - vcs->clipping.top) /
- vcs->decimation) *
- vino_data_formats[vcs->data_format].bpp;
- ch->frame_rate = vcs->framert_reg;
- ctrl = vino->control;
- intr = vino->intr_status;
- if (vcs->channel == VINO_CHANNEL_A) {
- /* All interrupt conditions for this channel was cleared
- * so clear the interrupt status register and enable
- * interrupts */
- intr &= ~VINO_INTSTAT_A;
- ctrl |= VINO_CTRL_A_INT;
- /* enable synchronization */
- ctrl |= VINO_CTRL_A_SYNC_ENBL;
- /* enable frame assembly */
- ctrl |= VINO_CTRL_A_INTERLEAVE_ENBL;
- /* set decimation used */
- if (vcs->decimation < 2)
- ctrl &= ~VINO_CTRL_A_DEC_ENBL;
- else {
- ctrl |= VINO_CTRL_A_DEC_ENBL;
- ctrl &= ~VINO_CTRL_A_DEC_SCALE_MASK;
- ctrl |= (vcs->decimation - 1) <<
- VINO_CTRL_A_DEC_SCALE_SHIFT;
- }
- /* select input interface */
- if (vcs->input == VINO_INPUT_D1)
- ctrl |= VINO_CTRL_A_SELECT;
- else
- ctrl &= ~VINO_CTRL_A_SELECT;
- /* palette */
- ctrl &= ~(VINO_CTRL_A_LUMA_ONLY | VINO_CTRL_A_RGB |
- VINO_CTRL_A_DITHER);
- } else {
- intr &= ~VINO_INTSTAT_B;
- ctrl |= VINO_CTRL_B_INT;
- ctrl |= VINO_CTRL_B_SYNC_ENBL;
- ctrl |= VINO_CTRL_B_INTERLEAVE_ENBL;
- if (vcs->decimation < 2)
- ctrl &= ~VINO_CTRL_B_DEC_ENBL;
- else {
- ctrl |= VINO_CTRL_B_DEC_ENBL;
- ctrl &= ~VINO_CTRL_B_DEC_SCALE_MASK;
- ctrl |= (vcs->decimation - 1) <<
- VINO_CTRL_B_DEC_SCALE_SHIFT;
- }
- if (vcs->input == VINO_INPUT_D1)
- ctrl |= VINO_CTRL_B_SELECT;
- else
- ctrl &= ~VINO_CTRL_B_SELECT;
- ctrl &= ~(VINO_CTRL_B_LUMA_ONLY | VINO_CTRL_B_RGB |
- VINO_CTRL_B_DITHER);
- }
- /* set palette */
- fb->data_format = vcs->data_format;
- switch (vcs->data_format) {
- case VINO_DATA_FMT_GREY:
- ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
- VINO_CTRL_A_LUMA_ONLY : VINO_CTRL_B_LUMA_ONLY;
- break;
- case VINO_DATA_FMT_RGB32:
- ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
- VINO_CTRL_A_RGB : VINO_CTRL_B_RGB;
- break;
- case VINO_DATA_FMT_YUV:
- /* nothing needs to be done */
- break;
- case VINO_DATA_FMT_RGB332:
- ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
- VINO_CTRL_A_RGB | VINO_CTRL_A_DITHER :
- VINO_CTRL_B_RGB | VINO_CTRL_B_DITHER;
- break;
- }
- vino->intr_status = intr;
- vino->control = ctrl;
- return 0;
- }
- /* (execute only with vino_lock locked) */
- static void vino_dma_start(struct vino_channel_settings *vcs)
- {
- u32 ctrl = vino->control;
- dprintk("vino_dma_start():\n");
- ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
- VINO_CTRL_A_DMA_ENBL : VINO_CTRL_B_DMA_ENBL;
- vino->control = ctrl;
- }
- /* (execute only with vino_lock locked) */
- static void vino_dma_stop(struct vino_channel_settings *vcs)
- {
- u32 ctrl = vino->control;
- ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
- ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL;
- vino->control = ctrl;
- dprintk("vino_dma_stop():\n");
- }
- /*
- * Load dummy page to descriptor registers. This prevents generating of
- * spurious interrupts. (execute only with vino_lock locked)
- */
- static void vino_clear_interrupt(struct vino_channel_settings *vcs)
- {
- struct sgi_vino_channel *ch;
- ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
- ch->page_index = 0;
- ch->line_count = 0;
- ch->start_desc_tbl = vino_drvdata->dummy_desc_table.dma;
- ch->next_4_desc = vino_drvdata->dummy_desc_table.dma;
- udelay(VINO_DESC_FETCH_DELAY);
- dprintk("channel %c clear interrupt condition\n",
- (vcs->channel == VINO_CHANNEL_A) ? 'A':'B');
- }
- static int vino_capture(struct vino_channel_settings *vcs,
- struct vino_framebuffer *fb)
- {
- int err = 0;
- unsigned long flags, flags2;
- spin_lock_irqsave(&fb->state_lock, flags);
- if (fb->state == VINO_FRAMEBUFFER_IN_USE)
- err = -EBUSY;
- fb->state = VINO_FRAMEBUFFER_IN_USE;
- spin_unlock_irqrestore(&fb->state_lock, flags);
- if (err)
- return err;
- spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
- spin_lock_irqsave(&vino_drvdata->input_lock, flags2);
- vino_dma_setup(vcs, fb);
- vino_dma_start(vcs);
- spin_unlock_irqrestore(&vino_drvdata->input_lock, flags2);
- spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
- return err;
- }
- static
- struct vino_framebuffer *vino_capture_enqueue(struct
- vino_channel_settings *vcs,
- unsigned int index)
- {
- struct vino_framebuffer *fb;
- unsigned long flags;
- dprintk("vino_capture_enqueue():\n");
- spin_lock_irqsave(&vcs->capture_lock, flags);
- fb = vino_queue_add(&vcs->fb_queue, index);
- if (fb == NULL) {
- dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
- "queue full?\n");
- goto out;
- }
- out:
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- return fb;
- }
- static int vino_capture_next(struct vino_channel_settings *vcs, int start)
- {
- struct vino_framebuffer *fb;
- unsigned int incoming, id;
- int err = 0;
- unsigned long flags, flags2;
- dprintk("vino_capture_next():\n");
- spin_lock_irqsave(&vcs->capture_lock, flags);
- if (start) {
- /* start capture only if capture isn't in progress already */
- if (vcs->capturing) {
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- return 0;
- }
- } else {
- /* capture next frame:
- * stop capture if capturing is not set */
- if (!vcs->capturing) {
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- return 0;
- }
- }
- err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
- if (err) {
- dprintk("vino_capture_next(): vino_queue_get_incoming() "
- "failed\n");
- err = -EINVAL;
- goto out;
- }
- if (incoming == 0) {
- dprintk("vino_capture_next(): no buffers available\n");
- goto out;
- }
- fb = vino_queue_peek(&vcs->fb_queue, &id);
- if (fb == NULL) {
- dprintk("vino_capture_next(): vino_queue_peek() failed\n");
- err = -EINVAL;
- goto out;
- }
- spin_lock_irqsave(&fb->state_lock, flags2);
- fb->state = VINO_FRAMEBUFFER_UNUSED;
- spin_unlock_irqrestore(&fb->state_lock, flags2);
- if (start) {
- vcs->capturing = 1;
- }
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- err = vino_capture(vcs, fb);
- return err;
- out:
- vcs->capturing = 0;
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- return err;
- }
- static int vino_is_capturing(struct vino_channel_settings *vcs)
- {
- int ret;
- unsigned long flags;
- spin_lock_irqsave(&vcs->capture_lock, flags);
- ret = vcs->capturing;
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- return ret;
- }
- /* waits until a frame is captured */
- static int vino_wait_for_frame(struct vino_channel_settings *vcs)
- {
- wait_queue_t wait;
- int err = 0;
- dprintk("vino_wait_for_frame():\n");
- init_waitqueue_entry(&wait, current);
- /* add ourselves into wait queue */
- add_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
- /* and set current state */
- set_current_state(TASK_INTERRUPTIBLE);
- /* to ensure that schedule_timeout will return immediately
- * if VINO interrupt was triggred meanwhile */
- schedule_timeout(HZ / 10);
- if (signal_pending(current))
- err = -EINTR;
- remove_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
- dprintk("vino_wait_for_frame(): waiting for frame %s\n",
- err ? "failed" : "ok");
- return err;
- }
- /* the function assumes that PAGE_SIZE % 4 == 0 */
- static void vino_convert_to_rgba(struct vino_framebuffer *fb) {
- unsigned char *pageptr;
- unsigned int page, i;
- unsigned char a;
- for (page = 0; page < fb->desc_table.page_count; page++) {
- pageptr = (unsigned char *)fb->desc_table.virtual[page];
- for (i = 0; i < PAGE_SIZE; i += 4) {
- a = pageptr[0];
- pageptr[0] = pageptr[3];
- pageptr[1] = pageptr[2];
- pageptr[2] = pageptr[1];
- pageptr[3] = a;
- pageptr += 4;
- }
- }
- }
- /* checks if the buffer is in correct state and syncs data */
- static int vino_check_buffer(struct vino_channel_settings *vcs,
- struct vino_framebuffer *fb)
- {
- int err = 0;
- unsigned long flags;
- dprintk("vino_check_buffer():\n");
- spin_lock_irqsave(&fb->state_lock, flags);
- switch (fb->state) {
- case VINO_FRAMEBUFFER_IN_USE:
- err = -EIO;
- break;
- case VINO_FRAMEBUFFER_READY:
- vino_sync_buffer(fb);
- fb->state = VINO_FRAMEBUFFER_UNUSED;
- break;
- default:
- err = -EINVAL;
- }
- spin_unlock_irqrestore(&fb->state_lock, flags);
- if (!err) {
- if (vino_pixel_conversion
- && (fb->data_format == VINO_DATA_FMT_RGB32)) {
- vino_convert_to_rgba(fb);
- }
- } else if (err && (err != -EINVAL)) {
- dprintk("vino_check_buffer(): buffer not ready\n");
- spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
- vino_dma_stop(vcs);
- vino_clear_interrupt(vcs);
- spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
- }
- return err;
- }
- /* forcefully terminates capture */
- static void vino_capture_stop(struct vino_channel_settings *vcs)
- {
- unsigned int incoming = 0, outgoing = 0, id;
- unsigned long flags, flags2;
- dprintk("vino_capture_stop():\n");
- spin_lock_irqsave(&vcs->capture_lock, flags);
- /* unset capturing to stop queue processing */
- vcs->capturing = 0;
- spin_lock_irqsave(&vino_drvdata->vino_lock, flags2);
- vino_dma_stop(vcs);
- vino_clear_interrupt(vcs);
- spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags2);
- /* remove all items from the queue */
- if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
- dprintk("vino_capture_stop(): "
- "vino_queue_get_incoming() failed\n");
- goto out;
- }
- while (incoming > 0) {
- vino_queue_transfer(&vcs->fb_queue);
- if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
- dprintk("vino_capture_stop(): "
- "vino_queue_get_incoming() failed\n");
- goto out;
- }
- }
- if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
- dprintk("vino_capture_stop(): "
- "vino_queue_get_outgoing() failed\n");
- goto out;
- }
- while (outgoing > 0) {
- vino_queue_remove(&vcs->fb_queue, &id);
- if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
- dprintk("vino_capture_stop(): "
- "vino_queue_get_outgoing() failed\n");
- goto out;
- }
- }
- out:
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- }
- static int vino_capture_failed(struct vino_channel_settings *vcs)
- {
- struct vino_framebuffer *fb;
- unsigned long flags;
- unsigned int i;
- int ret;
- dprintk("vino_capture_failed():\n");
- spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
- vino_dma_stop(vcs);
- vino_clear_interrupt(vcs);
- spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
- ret = vino_queue_get_incoming(&vcs->fb_queue, &i);
- if (ret == VINO_QUEUE_ERROR) {
- dprintk("vino_queue_get_incoming() failed\n");
- return -EINVAL;
- }
- if (i == 0) {
- /* no buffers to process */
- return 0;
- }
- fb = vino_queue_peek(&vcs->fb_queue, &i);
- if (fb == NULL) {
- dprintk("vino_queue_peek() failed\n");
- return -EINVAL;
- }
- spin_lock_irqsave(&fb->state_lock, flags);
- if (fb->state == VINO_FRAMEBUFFER_IN_USE) {
- fb->state = VINO_FRAMEBUFFER_UNUSED;
- vino_queue_transfer(&vcs->fb_queue);
- vino_queue_remove(&vcs->fb_queue, &i);
- /* we should actually discard the newest frame,
- * but who cares ... */
- }
- spin_unlock_irqrestore(&fb->state_lock, flags);
- return 0;
- }
- static void vino_frame_done(struct vino_channel_settings *vcs,
- unsigned int fc)
- {
- struct vino_framebuffer *fb;
- unsigned long flags;
- spin_lock_irqsave(&vcs->capture_lock, flags);
- fb = vino_queue_transfer(&vcs->fb_queue);
- if (!fb) {
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
- return;
- }
- spin_unlock_irqrestore(&vcs->capture_lock, flags);
- fb->frame_counter = fc;
- do_gettimeofday(&fb->timestamp);
- spin_lock_irqsave(&fb->state_lock, flags);
- if (fb->state == VINO_FRAMEBUFFER_IN_USE)
- fb->state = VINO_FRAMEBUFFER_READY;
- spin_unlock_irqrestore(&fb->state_lock, flags);
- wake_up(&vcs->fb_queue.frame_wait_queue);
- vino_capture_next(vcs, 0);
- }
- static irqreturn_t vino_interrupt(int irq, void *dev_id, struct pt_regs *regs)
- {
- u32 intr;
- unsigned int fc_a, fc_b;
- int done_a = 0;
- int done_b = 0;
- spin_lock(&vino_drvdata->vino_lock);
- intr = vino->intr_status;
- fc_a = vino->a.field_counter / 2;
- fc_b = vino->b.field_counter / 2;
- // TODO: handle error-interrupts in some special way ?
- if (intr & VINO_INTSTAT_A) {
- if (intr & VINO_INTSTAT_A_EOF) {
- vino_drvdata->a.field++;
- if (vino_drvdata->a.field > 1) {
- vino_dma_stop(&vino_drvdata->a);
- vino_clear_interrupt(&vino_drvdata->a);
- vino_drvdata->a.field = 0;
- done_a = 1;
- }
- dprintk("intr: channel A end-of-field interrupt: "
- "%04x\n", intr);
- } else {
- vino_dma_stop(&vino_drvdata->a);
- vino_clear_interrupt(&vino_drvdata->a);
- done_a = 1;
- dprintk("channel A error interrupt: %04x\n", intr);
- }
- }
- if (intr & VINO_INTSTAT_B) {
- if (intr & VINO_INTSTAT_B_EOF) {
- vino_drvdata->b.field++;
- if (vino_drvdata->b.field > 1) {
- vino_dma_stop(&vino_drvdata->b);
- vino_clear_interrupt(&vino_drvdata->b);
- vino_drvdata->b.field = 0;
- done_b = 1;
- }
- dprintk("intr: channel B end-of-field interrupt: "
- "%04x\n", intr);
- } else {
- vino_dma_stop(&vino_drvdata->b);
- vino_clear_interrupt(&vino_drvdata->b);
- done_b = 1;
- dprintk("channel B error interrupt: %04x\n", intr);
- }
- }
- /* always remember to clear interrupt status */
- vino->intr_status = ~intr;
- spin_unlock(&vino_drvdata->vino_lock);
- if (done_a) {
- vino_frame_done(&vino_drvdata->a, fc_a);
- dprintk("channel A frame done, interrupt: %d\n", intr);
- }
- if (done_b) {
- vino_frame_done(&vino_drvdata->b, fc_b);
- dprintk("channel B frame done, interrupt: %d\n", intr);
- }
- return IRQ_HANDLED;
- }
- /* VINO video input management */
- static int vino_get_saa7191_input(int input)
- {
- switch (input) {
- case VINO_INPUT_COMPOSITE:
- return SAA7191_INPUT_COMPOSITE;
- case VINO_INPUT_SVIDEO:
- return SAA7191_INPUT_SVIDEO;
- default:
- printk(KERN_ERR "VINO: vino_get_saa7191_input(): "
- "invalid input!\n");
- return -1;
- }
- }
- static int vino_get_saa7191_norm(int norm)
- {
- switch (norm) {
- case VINO_DATA_NORM_AUTO:
- return SAA7191_NORM_AUTO;
- case VINO_DATA_NORM_PAL:
- return SAA7191_NORM_PAL;
- case VINO_DATA_NORM_NTSC:
- return SAA7191_NORM_NTSC;
- case VINO_DATA_NORM_SECAM:
- return SAA7191_NORM_SECAM;
- default:
- printk(KERN_ERR "VINO: vino_get_saa7191_norm(): "
- "invalid norm!\n");
- return -1;
- }
- }
- /* execute with input_lock locked */
- static int vino_is_input_owner(struct vino_channel_settings *vcs)
- {
- switch(vcs->input) {
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- return (vino_drvdata->decoder.owner == vcs->channel);
- case VINO_INPUT_D1:
- return (vino_drvdata->camera.owner == vcs->channel);
- default:
- return 0;
- }
- }
- static int vino_acquire_input(struct vino_channel_settings *vcs)
- {
- int ret = 0;
- dprintk("vino_acquire_input():\n");
- spin_lock(&vino_drvdata->input_lock);
- /* First try D1 and then SAA7191 */
- if (vino_drvdata->camera.driver
- && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) {
- if (i2c_use_client(vino_drvdata->camera.driver)) {
- ret = -ENODEV;
- goto out;
- }
- vino_drvdata->camera.owner = vcs->channel;
- vcs->input = VINO_INPUT_D1;
- vcs->data_norm = VINO_DATA_NORM_D1;
- } else if (vino_drvdata->decoder.driver
- && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) {
- int saa7191_input;
- int saa7191_norm;
- if (i2c_use_client(vino_drvdata->decoder.driver)) {
- ret = -ENODEV;
- goto out;
- }
- vino_drvdata->decoder.owner = vcs->channel;
- vcs->input = VINO_INPUT_COMPOSITE;
- vcs->data_norm = VINO_DATA_NORM_PAL;
- saa7191_input = vino_get_saa7191_input(vcs->input);
- i2c_decoder_command(DECODER_SET_INPUT, &saa7191_input);
- saa7191_norm = vino_get_saa7191_norm(vcs->data_norm);
- i2c_decoder_command(DECODER_SAA7191_SET_NORM, &saa7191_norm);
- } else {
- vcs->input = (vcs->channel == VINO_CHANNEL_A) ?
- vino_drvdata->b.input : vino_drvdata->a.input;
- vcs->data_norm = (vcs->channel == VINO_CHANNEL_A) ?
- vino_drvdata->b.data_norm : vino_drvdata->a.data_norm;
- }
- if (vcs->input == VINO_INPUT_NONE) {
- ret = -ENODEV;
- goto out;
- }
- if (vino_is_input_owner(vcs)) {
- vino_set_default_clipping(vcs);
- vino_set_default_framerate(vcs);
- }
- dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name);
- out:
- spin_unlock(&vino_drvdata->input_lock);
- return ret;
- }
- static int vino_set_input(struct vino_channel_settings *vcs, int input)
- {
- struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
- &vino_drvdata->b : &vino_drvdata->a;
- int ret = 0;
- dprintk("vino_set_input():\n");
- spin_lock(&vino_drvdata->input_lock);
- if (vcs->input == input)
- goto out;
- switch(input) {
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- if (!vino_drvdata->decoder.driver) {
- ret = -EINVAL;
- goto out;
- }
- if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) {
- if (i2c_use_client(vino_drvdata->decoder.driver)) {
- ret = -ENODEV;
- goto out;
- }
- vino_drvdata->decoder.owner = vcs->channel;
- }
- if (vino_drvdata->decoder.owner == vcs->channel) {
- int saa7191_input;
- int saa7191_norm;
- vcs->input = input;
- vcs->data_norm = VINO_DATA_NORM_PAL;
- saa7191_input = vino_get_saa7191_input(vcs->input);
- i2c_decoder_command(DECODER_SET_INPUT, &saa7191_input);
- saa7191_norm = vino_get_saa7191_norm(vcs->data_norm);
- i2c_decoder_command(DECODER_SAA7191_SET_NORM,
- &saa7191_norm);
- } else {
- if (vcs2->input != input) {
- ret = -EBUSY;
- goto out;
- }
- vcs->input = input;
- vcs->data_norm = vcs2->data_norm;
- }
- if (vino_drvdata->camera.owner == vcs->channel) {
- /* Transfer the ownership or release the input */
- if (vcs2->input == VINO_INPUT_D1) {
- vino_drvdata->camera.owner = vcs2->channel;
- } else {
- i2c_release_client(vino_drvdata->
- camera.driver);
- vino_drvdata->camera.owner = VINO_NO_CHANNEL;
- }
- }
- break;
- case VINO_INPUT_D1:
- if (!vino_drvdata->camera.driver) {
- ret = -EINVAL;
- goto out;
- }
- if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) {
- if (i2c_use_client(vino_drvdata->camera.driver)) {
- ret = -ENODEV;
- goto out;
- }
- vino_drvdata->camera.owner = vcs->channel;
- }
- if (vino_drvdata->decoder.owner == vcs->channel) {
- /* Transfer the ownership or release the input */
- if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
- (vcs2->input == VINO_INPUT_SVIDEO)) {
- vino_drvdata->decoder.owner = vcs2->channel;
- } else {
- i2c_release_client(vino_drvdata->
- decoder.driver);
- vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
- }
- }
- vcs->input = input;
- vcs->data_norm = VINO_DATA_NORM_D1;
- break;
- default:
- ret = -EINVAL;
- goto out;
- }
- vino_set_default_clipping(vcs);
- vino_set_default_framerate(vcs);
- dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name);
- out:
- spin_unlock(&vino_drvdata->input_lock);
- return ret;
- }
- static void vino_release_input(struct vino_channel_settings *vcs)
- {
- struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
- &vino_drvdata->b : &vino_drvdata->a;
- dprintk("vino_release_input():\n");
- spin_lock(&vino_drvdata->input_lock);
- /* Release ownership of the channel
- * and if the other channel takes input from
- * the same source, transfer the ownership */
- if (vino_drvdata->camera.owner == vcs->channel) {
- if (vcs2->input == VINO_INPUT_D1) {
- vino_drvdata->camera.owner = vcs2->channel;
- } else {
- i2c_release_client(vino_drvdata->camera.driver);
- vino_drvdata->camera.owner = VINO_NO_CHANNEL;
- }
- } else if (vino_drvdata->decoder.owner == vcs->channel) {
- if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
- (vcs2->input == VINO_INPUT_SVIDEO)) {
- vino_drvdata->decoder.owner = vcs2->channel;
- } else {
- i2c_release_client(vino_drvdata->decoder.driver);
- vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
- }
- }
- vcs->input = VINO_INPUT_NONE;
- spin_unlock(&vino_drvdata->input_lock);
- }
- /* execute with input_lock locked */
- static int vino_set_data_norm(struct vino_channel_settings *vcs,
- unsigned int data_norm)
- {
- int saa7191_norm;
- switch (vcs->input) {
- case VINO_INPUT_D1:
- /* only one "norm" supported */
- if (data_norm != VINO_DATA_NORM_D1)
- return -EINVAL;
- break;
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- saa7191_norm = vino_get_saa7191_norm(data_norm);
- i2c_decoder_command(DECODER_SAA7191_SET_NORM, &saa7191_norm);
- vcs->data_norm = data_norm;
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- /* V4L2 helper functions */
- static int vino_find_data_format(__u32 pixelformat)
- {
- int i;
- for (i = 0; i < VINO_DATA_FMT_COUNT; i++) {
- if (vino_data_formats[i].pixelformat == pixelformat)
- return i;
- }
- return VINO_DATA_FMT_NONE;
- }
- static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
- {
- int data_norm = VINO_DATA_NORM_NONE;
- spin_lock(&vino_drvdata->input_lock);
- switch(vcs->input) {
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- if (index == 0) {
- data_norm = VINO_DATA_NORM_PAL;
- } else if (index == 1) {
- data_norm = VINO_DATA_NORM_NTSC;
- } else if (index == 2) {
- data_norm = VINO_DATA_NORM_SECAM;
- }
- break;
- case VINO_INPUT_D1:
- if (index == 0) {
- data_norm = VINO_DATA_NORM_D1;
- }
- break;
- }
- spin_unlock(&vino_drvdata->input_lock);
- return data_norm;
- }
- static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
- {
- int input = VINO_INPUT_NONE;
- spin_lock(&vino_drvdata->input_lock);
- if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
- switch (index) {
- case 0:
- input = VINO_INPUT_COMPOSITE;
- break;
- case 1:
- input = VINO_INPUT_SVIDEO;
- break;
- case 2:
- input = VINO_INPUT_D1;
- break;
- }
- } else if (vino_drvdata->decoder.driver) {
- switch (index) {
- case 0:
- input = VINO_INPUT_COMPOSITE;
- break;
- case 1:
- input = VINO_INPUT_SVIDEO;
- break;
- }
- } else if (vino_drvdata->camera.driver) {
- switch (index) {
- case 0:
- input = VINO_INPUT_D1;
- break;
- }
- }
- spin_unlock(&vino_drvdata->input_lock);
- return input;
- }
- /* execute with input_lock locked */
- static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
- {
- __u32 index = 0;
- // FIXME: detect when no inputs available
- if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
- switch (vcs->input) {
- case VINO_INPUT_COMPOSITE:
- index = 0;
- break;
- case VINO_INPUT_SVIDEO:
- index = 1;
- break;
- case VINO_INPUT_D1:
- index = 2;
- break;
- }
- } else if (vino_drvdata->decoder.driver) {
- switch (vcs->input) {
- case VINO_INPUT_COMPOSITE:
- index = 0;
- break;
- case VINO_INPUT_SVIDEO:
- index = 1;
- break;
- }
- } else if (vino_drvdata->camera.driver) {
- switch (vcs->input) {
- case VINO_INPUT_D1:
- index = 0;
- break;
- }
- }
- return index;
- }
- /* V4L2 ioctls */
- static void vino_v4l2_querycap(struct v4l2_capability *cap)
- {
- memset(cap, 0, sizeof(struct v4l2_capability));
- strcpy(cap->driver, vino_driver_name);
- strcpy(cap->card, vino_driver_description);
- strcpy(cap->bus_info, vino_bus_name);
- cap->version = VINO_VERSION_CODE;
- cap->capabilities =
- V4L2_CAP_VIDEO_CAPTURE |
- V4L2_CAP_STREAMING;
- // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
- }
- static int vino_v4l2_enuminput(struct vino_channel_settings *vcs,
- struct v4l2_input *i)
- {
- __u32 index = i->index;
- int input;
- dprintk("requested index = %d\n", index);
- input = vino_enum_input(vcs, index);
- if (input == VINO_INPUT_NONE)
- return -EINVAL;
- memset(i, 0, sizeof(struct v4l2_input));
- i->index = index;
- i->type = V4L2_INPUT_TYPE_CAMERA;
- i->std = vino_inputs[input].std;
- strcpy(i->name, vino_inputs[input].name);
- if ((input == VINO_INPUT_COMPOSITE)
- || (input == VINO_INPUT_SVIDEO)) {
- struct saa7191_status status;
- i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
- i->status |= status.signal ? 0 : V4L2_IN_ST_NO_SIGNAL;
- i->status |= status.color ? 0 : V4L2_IN_ST_NO_COLOR;
- }
- return 0;
- }
- static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
- struct v4l2_input *i)
- {
- __u32 index;
- int input;
- spin_lock(&vino_drvdata->input_lock);
- input = vcs->input;
- index = vino_find_input_index(vcs);
- spin_unlock(&vino_drvdata->input_lock);
- dprintk("input = %d\n", input);
- if (input == VINO_INPUT_NONE) {
- return -EINVAL;
- }
- memset(i, 0, sizeof(struct v4l2_input));
- i->index = index;
- i->type = V4L2_INPUT_TYPE_CAMERA;
- i->std = vino_inputs[input].std;
- strcpy(i->name, vino_inputs[input].name);
- return 0;
- }
- static int vino_v4l2_s_input(struct vino_channel_settings *vcs,
- struct v4l2_input *i)
- {
- int input;
- dprintk("requested input = %d\n", i->index);
- input = vino_enum_input(vcs, i->index);
- if (input == VINO_INPUT_NONE)
- return -EINVAL;
- return vino_set_input(vcs, input);
- }
- static int vino_v4l2_enumstd(struct vino_channel_settings *vcs,
- struct v4l2_standard *s)
- {
- int index = s->index;
- int data_norm = vino_enum_data_norm(vcs, index);
- dprintk("standard index = %d\n", index);
- if (data_norm == VINO_DATA_NORM_NONE)
- return -EINVAL;
- dprintk("standard name = %s\n",
- vino_data_norms[data_norm].description);
- memset(s, 0, sizeof(struct v4l2_standard));
- s->index = index;
- s->id = vino_data_norms[data_norm].std;
- s->frameperiod.numerator = 1;
- s->frameperiod.denominator =
- vino_data_norms[data_norm].fps_max;
- s->framelines =
- vino_data_norms[data_norm].framelines;
- strcpy(s->name,
- vino_data_norms[data_norm].description);
- return 0;
- }
- static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
- v4l2_std_id *std)
- {
- spin_lock(&vino_drvdata->input_lock);
- dprintk("current standard = %d\n", vcs->data_norm);
- *std = vino_data_norms[vcs->data_norm].std;
- spin_unlock(&vino_drvdata->input_lock);
- return 0;
- }
- static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
- v4l2_std_id *std)
- {
- int ret = 0;
- spin_lock(&vino_drvdata->input_lock);
- /* check if the standard is valid for the current input */
- if (vino_is_input_owner(vcs)
- && (vino_inputs[vcs->input].std & (*std))) {
- dprintk("standard accepted\n");
- /* change the video norm for SAA7191
- * and accept NTSC for D1 (do nothing) */
- if (vcs->input == VINO_INPUT_D1)
- goto out;
- if ((*std) & V4L2_STD_PAL) {
- vino_set_data_norm(vcs, VINO_DATA_NORM_PAL);
- vcs->data_norm = VINO_DATA_NORM_PAL;
- } else if ((*std) & V4L2_STD_NTSC) {
- vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC);
- vcs->data_norm = VINO_DATA_NORM_NTSC;
- } else if ((*std) & V4L2_STD_SECAM) {
- vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM);
- vcs->data_norm = VINO_DATA_NORM_SECAM;
- } else {
- ret = -EINVAL;
- }
- } else {
- ret = -EINVAL;
- }
- out:
- spin_unlock(&vino_drvdata->input_lock);
- return ret;
- }
- static int vino_v4l2_enum_fmt(struct vino_channel_settings *vcs,
- struct v4l2_fmtdesc *fd)
- {
- enum v4l2_buf_type type = fd->type;
- int index = fd->index;
- dprintk("format index = %d\n", index);
- switch (fd->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- if ((fd->index < 0) ||
- (fd->index >= VINO_DATA_FMT_COUNT))
- return -EINVAL;
- dprintk("format name = %s\n",
- vino_data_formats[index].description);
- memset(fd, 0, sizeof(struct v4l2_fmtdesc));
- fd->index = index;
- fd->type = type;
- fd->pixelformat = vino_data_formats[index].pixelformat;
- strcpy(fd->description, vino_data_formats[index].description);
- break;
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
- struct v4l2_format *f)
- {
- struct vino_channel_settings tempvcs;
- switch (f->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct v4l2_pix_format *pf = &f->fmt.pix;
- dprintk("requested: w = %d, h = %d\n",
- pf->width, pf->height);
- spin_lock(&vino_drvdata->input_lock);
- memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
- spin_unlock(&vino_drvdata->input_lock);
- tempvcs.data_format = vino_find_data_format(pf->pixelformat);
- if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
- tempvcs.data_format = VINO_DATA_FMT_RGB32;
- pf->pixelformat =
- vino_data_formats[tempvcs.data_format].
- pixelformat;
- }
- /* data format must be set before clipping/scaling */
- vino_set_scaling(&tempvcs, pf->width, pf->height);
- dprintk("data format = %s\n",
- vino_data_formats[tempvcs.data_format].description);
- pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) /
- tempvcs.decimation;
- pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
- tempvcs.decimation;
- pf->field = V4L2_FIELD_INTERLACED;
- pf->bytesperline = tempvcs.line_size;
- pf->sizeimage = tempvcs.line_size *
- (tempvcs.clipping.bottom - tempvcs.clipping.top) /
- tempvcs.decimation;
- pf->colorspace =
- vino_data_formats[tempvcs.data_format].colorspace;
- pf->priv = 0;
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs,
- struct v4l2_format *f)
- {
- switch (f->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct v4l2_pix_format *pf = &f->fmt.pix;
- spin_lock(&vino_drvdata->input_lock);
- pf->width = (vcs->clipping.right - vcs->clipping.left) /
- vcs->decimation;
- pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
- vcs->decimation;
- pf->pixelformat =
- vino_data_formats[vcs->data_format].pixelformat;
- pf->field = V4L2_FIELD_INTERLACED;
- pf->bytesperline = vcs->line_size;
- pf->sizeimage = vcs->line_size *
- (vcs->clipping.bottom - vcs->clipping.top) /
- vcs->decimation;
- pf->colorspace =
- vino_data_formats[vcs->data_format].colorspace;
- pf->priv = 0;
- spin_unlock(&vino_drvdata->input_lock);
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs,
- struct v4l2_format *f)
- {
- int data_format;
- switch (f->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct v4l2_pix_format *pf = &f->fmt.pix;
- spin_lock(&vino_drvdata->input_lock);
- if (!vino_is_input_owner(vcs)) {
- spin_unlock(&vino_drvdata->input_lock);
- return -EINVAL;
- }
- data_format = vino_find_data_format(pf->pixelformat);
- if (data_format == VINO_DATA_FMT_NONE) {
- vcs->data_format = VINO_DATA_FMT_RGB32;
- pf->pixelformat =
- vino_data_formats[vcs->data_format].
- pixelformat;
- } else {
- vcs->data_format = data_format;
- }
- /* data format must be set before clipping/scaling */
- vino_set_scaling(vcs, pf->width, pf->height);
- dprintk("data format = %s\n",
- vino_data_formats[vcs->data_format].description);
- pf->width = vcs->clipping.right - vcs->clipping.left;
- pf->height = vcs->clipping.bottom - vcs->clipping.top;
- pf->field = V4L2_FIELD_INTERLACED;
- pf->bytesperline = vcs->line_size;
- pf->sizeimage = vcs->line_size *
- (vcs->clipping.bottom - vcs->clipping.top) /
- vcs->decimation;
- pf->colorspace =
- vino_data_formats[vcs->data_format].colorspace;
- pf->priv = 0;
- spin_unlock(&vino_drvdata->input_lock);
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
- struct v4l2_cropcap *ccap)
- {
- const struct vino_data_norm *norm;
- switch (ccap->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- spin_lock(&vino_drvdata->input_lock);
- norm = &vino_data_norms[vcs->data_norm];
- spin_unlock(&vino_drvdata->input_lock);
- ccap->bounds.left = 0;
- ccap->bounds.top = 0;
- ccap->bounds.width = norm->width;
- ccap->bounds.height = norm->height;
- memcpy(&ccap->defrect, &ccap->bounds,
- sizeof(struct v4l2_rect));
- ccap->pixelaspect.numerator = 1;
- ccap->pixelaspect.denominator = 1;
- break;
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
- struct v4l2_crop *c)
- {
- switch (c->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- spin_lock(&vino_drvdata->input_lock);
- c->c.left = vcs->clipping.left;
- c->c.top = vcs->clipping.top;
- c->c.width = vcs->clipping.right - vcs->clipping.left;
- c->c.height = vcs->clipping.bottom - vcs->clipping.top;
- spin_unlock(&vino_drvdata->input_lock);
- break;
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
- struct v4l2_crop *c)
- {
- switch (c->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- spin_lock(&vino_drvdata->input_lock);
- if (!vino_is_input_owner(vcs)) {
- spin_unlock(&vino_drvdata->input_lock);
- return -EINVAL;
- }
- vino_set_clipping(vcs, c->c.left, c->c.top,
- c->c.width, c->c.height);
- spin_unlock(&vino_drvdata->input_lock);
- break;
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
- struct v4l2_streamparm *sp)
- {
- switch (sp->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct v4l2_captureparm *cp = &sp->parm.capture;
- memset(cp, 0, sizeof(struct v4l2_captureparm));
- cp->capability = V4L2_CAP_TIMEPERFRAME;
- cp->timeperframe.numerator = 1;
- spin_lock(&vino_drvdata->input_lock);
- cp->timeperframe.denominator = vcs->fps;
- spin_unlock(&vino_drvdata->input_lock);
- // TODO: cp->readbuffers = xxx;
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_s_parm(struct vino_channel_settings *vcs,
- struct v4l2_streamparm *sp)
- {
- switch (sp->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct v4l2_captureparm *cp = &sp->parm.capture;
- spin_lock(&vino_drvdata->input_lock);
- if (!vino_is_input_owner(vcs)) {
- spin_unlock(&vino_drvdata->input_lock);
- return -EINVAL;
- }
- if ((cp->timeperframe.numerator == 0) ||
- (cp->timeperframe.denominator == 0)) {
- /* reset framerate */
- vino_set_default_framerate(vcs);
- } else {
- vino_set_framerate(vcs, cp->timeperframe.denominator /
- cp->timeperframe.numerator);
- }
- spin_unlock(&vino_drvdata->input_lock);
- // TODO: set buffers according to cp->readbuffers
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_reqbufs(struct vino_channel_settings *vcs,
- struct v4l2_requestbuffers *rb)
- {
- if (vcs->reading)
- return -EBUSY;
- switch (rb->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- // TODO: check queue type
- if (rb->memory != V4L2_MEMORY_MMAP) {
- dprintk("type not mmap\n");
- return -EINVAL;
- }
- if (vino_is_capturing(vcs)) {
- dprintk("busy, capturing\n");
- return -EBUSY;
- }
- dprintk("count = %d\n", rb->count);
- if (rb->count > 0) {
- if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
- dprintk("busy, buffers still mapped\n");
- return -EBUSY;
- } else {
- vino_queue_free(&vcs->fb_queue);
- vino_queue_init(&vcs->fb_queue, &rb->count);
- }
- } else {
- vino_capture_stop(vcs);
- vino_queue_free(&vcs->fb_queue);
- }
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
- struct vino_framebuffer *fb,
- struct v4l2_buffer *b)
- {
- if (vino_queue_outgoing_contains(&vcs->fb_queue,
- fb->id)) {
- b->flags &= ~V4L2_BUF_FLAG_QUEUED;
- b->flags |= V4L2_BUF_FLAG_DONE;
- } else if (vino_queue_incoming_contains(&vcs->fb_queue,
- fb->id)) {
- b->flags &= ~V4L2_BUF_FLAG_DONE;
- b->flags |= V4L2_BUF_FLAG_QUEUED;
- } else {
- b->flags &= ~(V4L2_BUF_FLAG_DONE |
- V4L2_BUF_FLAG_QUEUED);
- }
- b->flags &= ~(V4L2_BUF_FLAG_TIMECODE);
- if (fb->map_count > 0)
- b->flags |= V4L2_BUF_FLAG_MAPPED;
- b->index = fb->id;
- b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ?
- V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
- b->m.offset = fb->offset;
- b->bytesused = fb->data_size;
- b->length = fb->size;
- b->field = V4L2_FIELD_INTERLACED;
- b->sequence = fb->frame_counter;
- memcpy(&b->timestamp, &fb->timestamp,
- sizeof(struct timeval));
- // b->input ?
- dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
- fb->id, fb->size, fb->data_size, fb->offset);
- }
- static int vino_v4l2_querybuf(struct vino_channel_settings *vcs,
- struct v4l2_buffer *b)
- {
- if (vcs->reading)
- return -EBUSY;
- switch (b->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct vino_framebuffer *fb;
- // TODO: check queue type
- if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
- dprintk("invalid index = %d\n",
- b->index);
- return -EINVAL;
- }
- fb = vino_queue_get_buffer(&vcs->fb_queue,
- b->index);
- if (fb == NULL) {
- dprintk("vino_queue_get_buffer() failed");
- return -EINVAL;
- }
- vino_v4l2_get_buffer_status(vcs, fb, b);
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_qbuf(struct vino_channel_settings *vcs,
- struct v4l2_buffer *b)
- {
- if (vcs->reading)
- return -EBUSY;
- switch (b->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct vino_framebuffer *fb;
- int ret;
- // TODO: check queue type
- if (b->memory != V4L2_MEMORY_MMAP) {
- dprintk("type not mmap\n");
- return -EINVAL;
- }
- fb = vino_capture_enqueue(vcs, b->index);
- if (fb == NULL)
- return -EINVAL;
- vino_v4l2_get_buffer_status(vcs, fb, b);
- if (vcs->streaming) {
- ret = vino_capture_next(vcs, 1);
- if (ret)
- return ret;
- }
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
- struct v4l2_buffer *b,
- unsigned int nonblocking)
- {
- if (vcs->reading)
- return -EBUSY;
- switch (b->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
- struct vino_framebuffer *fb;
- unsigned int incoming, outgoing;
- int err;
- // TODO: check queue type
- err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
- if (err) {
- dprintk("vino_queue_get_incoming() failed\n");
- return -EIO;
- }
- err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
- if (err) {
- dprintk("vino_queue_get_outgoing() failed\n");
- return -EIO;
- }
- dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
- if (outgoing == 0) {
- if (incoming == 0) {
- dprintk("no incoming or outgoing buffers\n");
- return -EINVAL;
- }
- if (nonblocking) {
- dprintk("non-blocking I/O was selected and "
- "there are no buffers to dequeue\n");
- return -EAGAIN;
- }
- err = vino_wait_for_frame(vcs);
- if (err) {
- err = vino_wait_for_frame(vcs);
- if (err) {
- /* interrupted */
- vino_capture_failed(vcs);
- return -EIO;
- }
- }
- }
- fb = vino_queue_remove(&vcs->fb_queue, &b->index);
- if (fb == NULL) {
- dprintk("vino_queue_remove() failed\n");
- return -EINVAL;
- }
- err = vino_check_buffer(vcs, fb);
- if (err)
- return -EIO;
- vino_v4l2_get_buffer_status(vcs, fb, b);
- break;
- }
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int vino_v4l2_streamon(struct vino_channel_settings *vcs)
- {
- unsigned int incoming;
- int ret;
- if (vcs->reading)
- return -EBUSY;
- if (vcs->streaming)
- return 0;
- // TODO: check queue type
- if (vino_queue_get_length(&vcs->fb_queue) < 1) {
- dprintk("no buffers allocated\n");
- return -EINVAL;
- }
- ret = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
- if (ret) {
- dprintk("vino_queue_get_incoming() failed\n");
- return -EINVAL;
- }
- vcs->streaming = 1;
- if (incoming > 0) {
- ret = vino_capture_next(vcs, 1);
- if (ret) {
- vcs->streaming = 0;
- dprintk("couldn't start capture\n");
- return -EINVAL;
- }
- }
- return 0;
- }
- static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
- {
- if (vcs->reading)
- return -EBUSY;
- if (!vcs->streaming)
- return 0;
- vino_capture_stop(vcs);
- vcs->streaming = 0;
- return 0;
- }
- static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
- struct v4l2_queryctrl *queryctrl)
- {
- int i;
- int err = 0;
- spin_lock(&vino_drvdata->input_lock);
- switch (vcs->input) {
- case VINO_INPUT_D1:
- for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
- if (vino_indycam_v4l2_controls[i].id ==
- queryctrl->id) {
- memcpy(queryctrl,
- &vino_indycam_v4l2_controls[i],
- sizeof(struct v4l2_queryctrl));
- goto found;
- }
- }
- err = -EINVAL;
- break;
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
- if (vino_saa7191_v4l2_controls[i].id ==
- queryctrl->id) {
- memcpy(queryctrl,
- &vino_saa7191_v4l2_controls[i],
- sizeof(struct v4l2_queryctrl));
- goto found;
- }
- }
- err = -EINVAL;
- break;
- default:
- err = -EINVAL;
- }
- found:
- spin_unlock(&vino_drvdata->input_lock);
- return err;
- }
- static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
- struct v4l2_control *control)
- {
- struct indycam_control indycam_ctrl;
- struct saa7191_control saa7191_ctrl;
- int err = 0;
- spin_lock(&vino_drvdata->input_lock);
- switch (vcs->input) {
- case VINO_INPUT_D1:
- i2c_camera_command(DECODER_INDYCAM_GET_CONTROLS,
- &indycam_ctrl);
- switch(control->id) {
- case V4L2_CID_AUTOGAIN:
- control->value = indycam_ctrl.agc;
- break;
- case V4L2_CID_AUTO_WHITE_BALANCE:
- control->value = indycam_ctrl.awb;
- break;
- case V4L2_CID_GAIN:
- control->value = indycam_ctrl.gain;
- break;
- case V4L2_CID_PRIVATE_BASE:
- control->value = indycam_ctrl.red_saturation;
- break;
- case V4L2_CID_PRIVATE_BASE + 1:
- control->value = indycam_ctrl.blue_saturation;
- break;
- case V4L2_CID_RED_BALANCE:
- control->value = indycam_ctrl.red_balance;
- break;
- case V4L2_CID_BLUE_BALANCE:
- control->value = indycam_ctrl.blue_balance;
- break;
- case V4L2_CID_EXPOSURE:
- control->value = indycam_ctrl.shutter;
- break;
- case V4L2_CID_GAMMA:
- control->value = indycam_ctrl.gamma;
- break;
- default:
- err = -EINVAL;
- }
- break;
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- i2c_decoder_command(DECODER_SAA7191_GET_CONTROLS,
- &saa7191_ctrl);
- switch(control->id) {
- case V4L2_CID_HUE:
- control->value = saa7191_ctrl.hue;
- break;
- case V4L2_CID_PRIVATE_BASE:
- control->value = saa7191_ctrl.vtrc;
- break;
- default:
- err = -EINVAL;
- }
- break;
- default:
- err = -EINVAL;
- }
- spin_unlock(&vino_drvdata->input_lock);
- return err;
- }
- static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
- struct v4l2_control *control)
- {
- struct indycam_control indycam_ctrl;
- struct saa7191_control saa7191_ctrl;
- int i;
- int err = 0;
- spin_lock(&vino_drvdata->input_lock);
- switch (vcs->input) {
- case VINO_INPUT_D1:
- for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
- if (vino_indycam_v4l2_controls[i].id ==
- control->id) {
- if ((control->value >=
- vino_indycam_v4l2_controls[i].minimum)
- && (control->value <=
- vino_indycam_v4l2_controls[i].
- maximum)) {
- goto ok1;
- } else {
- err = -ERANGE;
- goto error;
- }
- }
- }
- err = -EINVAL;
- goto error;
- ok1:
- indycam_ctrl.agc = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.awb = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.shutter = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.gain = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.red_balance = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.blue_balance = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.red_saturation = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.blue_saturation = INDYCAM_VALUE_UNCHANGED;
- indycam_ctrl.gamma = INDYCAM_VALUE_UNCHANGED;
- switch(control->id) {
- case V4L2_CID_AUTOGAIN:
- indycam_ctrl.agc = control->value;
- break;
- case V4L2_CID_AUTO_WHITE_BALANCE:
- indycam_ctrl.awb = control->value;
- break;
- case V4L2_CID_GAIN:
- indycam_ctrl.gain = control->value;
- break;
- case V4L2_CID_PRIVATE_BASE:
- indycam_ctrl.red_saturation = control->value;
- break;
- case V4L2_CID_PRIVATE_BASE + 1:
- indycam_ctrl.blue_saturation = control->value;
- break;
- case V4L2_CID_RED_BALANCE:
- indycam_ctrl.red_balance = control->value;
- break;
- case V4L2_CID_BLUE_BALANCE:
- indycam_ctrl.blue_balance = control->value;
- break;
- case V4L2_CID_EXPOSURE:
- indycam_ctrl.shutter = control->value;
- break;
- case V4L2_CID_GAMMA:
- indycam_ctrl.gamma = control->value;
- break;
- default:
- err = -EINVAL;
- }
- if (!err)
- i2c_camera_command(DECODER_INDYCAM_SET_CONTROLS,
- &indycam_ctrl);
- break;
- case VINO_INPUT_COMPOSITE:
- case VINO_INPUT_SVIDEO:
- for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
- if (vino_saa7191_v4l2_controls[i].id ==
- control->id) {
- if ((control->value >=
- vino_saa7191_v4l2_controls[i].minimum)
- && (control->value <=
- vino_saa7191_v4l2_controls[i].
- maximum)) {
- goto ok2;
- } else {
- err = -ERANGE;
- goto error;
- }
- }
- }
- err = -EINVAL;
- goto error;
- ok2:
- saa7191_ctrl.hue = SAA7191_VALUE_UNCHANGED;
- saa7191_ctrl.vtrc = SAA7191_VALUE_UNCHANGED;
- switch(control->id) {
- case V4L2_CID_HUE:
- saa7191_ctrl.hue = control->value;
- break;
- case V4L2_CID_PRIVATE_BASE:
- saa7191_ctrl.vtrc = control->value;
- break;
- default:
- err = -EINVAL;
- }
- if (!err)
- i2c_decoder_command(DECODER_SAA7191_SET_CONTROLS,
- &saa7191_ctrl);
- break;
- default:
- err = -EINVAL;
- }
- error:
- spin_unlock(&vino_drvdata->input_lock);
- return err;
- }
- /* File operations */
- static int vino_open(struct inode *inode, struct file *file)
- {
- struct video_device *dev = video_devdata(file);
- struct vino_channel_settings *vcs = video_get_drvdata(dev);
- int ret = 0;
- dprintk("open(): channel = %c\n",
- (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
- down(&vcs->sem);
- if (vcs->users) {
- dprintk("open(): driver busy\n");
- ret = -EBUSY;
- goto out;
- }
- ret = vino_acquire_input(vcs);
- if (ret) {
- dprintk("open(): vino_acquire_input() failed\n");
- goto out;
- }
- vcs->users++;
- out:
- up(&vcs->sem);
- dprintk("open(): %s!\n", ret ? "failed" : "complete");
- return ret;
- }
- static int vino_close(struct inode *inode, struct file *file)
- {
- struct video_device *dev = video_devdata(file);
- struct vino_channel_settings *vcs = video_get_drvdata(dev);
- dprintk("close():\n");
- down(&vcs->sem);
- vcs->users--;
- if (!vcs->users) {
- vino_release_input(vcs);
- /* stop DMA and free buffers */
- vino_capture_stop(vcs);
- vino_queue_free(&vcs->fb_queue);
- }
- up(&vcs->sem);
- return 0;
- }
- static void vino_vm_open(struct vm_area_struct *vma)
- {
- struct vino_framebuffer *fb = vma->vm_private_data;
- fb->map_count++;
- dprintk("vino_vm_open(): count = %d\n", fb->map_count);
- }
- static void vino_vm_close(struct vm_area_struct *vma)
- {
- struct vino_framebuffer *fb = vma->vm_private_data;
- fb->map_count--;
- dprintk("vino_vm_close(): count = %d\n", fb->map_count);
- }
- static struct vm_operations_struct vino_vm_ops = {
- .open = vino_vm_open,
- .close = vino_vm_close,
- };
- static int vino_mmap(struct file *file, struct vm_area_struct *vma)
- {
- struct video_device *dev = video_devdata(file);
- struct vino_channel_settings *vcs = video_get_drvdata(dev);
- unsigned long start = vma->vm_start;
- unsigned long size = vma->vm_end - vma->vm_start;
- unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
- struct vino_framebuffer *fb = NULL;
- unsigned int i, length;
- int ret = 0;
- dprintk("mmap():\n");
- // TODO: reject mmap if already mapped
- if (down_interruptible(&vcs->sem))
- return -EINTR;
- if (vcs->reading) {
- ret = -EBUSY;
- goto out;
- }
- // TODO: check queue type
- if (!(vma->vm_flags & VM_WRITE)) {
- dprintk("mmap(): app bug: PROT_WRITE please\n");
- ret = -EINVAL;
- goto out;
- }
- if (!(vma->vm_flags & VM_SHARED)) {
- dprintk("mmap(): app bug: MAP_SHARED please\n");
- ret = -EINVAL;
- goto out;
- }
- /* find the correct buffer using offset */
- length = vino_queue_get_length(&vcs->fb_queue);
- if (length == 0) {
- dprintk("mmap(): queue not initialized\n");
- ret = -EINVAL;
- goto out;
- }
- for (i = 0; i < length; i++) {
- fb = vino_queue_get_buffer(&vcs->fb_queue, i);
- if (fb == NULL) {
- dprintk("mmap(): vino_queue_get_buffer() failed\n");
- ret = -EINVAL;
- goto out;
- }
- if (fb->offset == offset)
- goto found;
- }
- dprintk("mmap(): invalid offset = %lu\n", offset);
- ret = -EINVAL;
- goto out;
- found:
- dprintk("mmap(): buffer = %d\n", i);
- if (size > (fb->desc_table.page_count * PAGE_SIZE)) {
- dprintk("mmap(): failed: size = %lu > %lu\n",
- size, fb->desc_table.page_count * PAGE_SIZE);
- ret = -EINVAL;
- goto out;
- }
- for (i = 0; i < fb->desc_table.page_count; i++) {
- unsigned long pfn =
- virt_to_phys((void *)fb->desc_table.virtual[i]) >>
- PAGE_SHIFT;
- if (size < PAGE_SIZE)
- break;
- // protection was: PAGE_READONLY
- if (remap_pfn_range(vma, start, pfn, PAGE_SIZE,
- vma->vm_page_prot)) {
- dprintk("mmap(): remap_pfn_range() failed\n");
- ret = -EAGAIN;
- goto out;
- }
- start += PAGE_SIZE;
- size -= PAGE_SIZE;
- }
- fb->map_count = 1;
- vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
- vma->vm_flags &= ~VM_IO;
- vma->vm_private_data = fb;
- vma->vm_file = file;
- vma->vm_ops = &vino_vm_ops;
- out:
- up(&vcs->sem);
- return ret;
- }
- static unsigned int vino_poll(struct file *file, poll_table *pt)
- {
- struct video_device *dev = video_devdata(file);
- struct vino_channel_settings *vcs = video_get_drvdata(dev);
- unsigned int outgoing;
- unsigned int ret = 0;
- // lock mutex (?)
- // TODO: this has to be corrected for different read modes
- dprintk("poll():\n");
- if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
- dprintk("poll(): vino_queue_get_outgoing() failed\n");
- ret = POLLERR;
- goto error;
- }
- if (outgoing > 0)
- goto over;
- poll_wait(file, &vcs->fb_queue.frame_wait_queue, pt);
- if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
- dprintk("poll(): vino_queue_get_outgoing() failed\n");
- ret = POLLERR;
- goto error;
- }
- over:
- dprintk("poll(): data %savailable\n",
- (outgoing > 0) ? "" : "not ");
- if (outgoing > 0) {
- ret = POLLIN | POLLRDNORM;
- }
- error:
- return ret;
- }
- static int vino_do_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, void *arg)
- {
- struct video_device *dev = video_devdata(file);
- struct vino_channel_settings *vcs = video_get_drvdata(dev);
- switch (_IOC_TYPE(cmd)) {
- case 'v':
- dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd);
- break;
- case 'V':
- dprintk("ioctl(): V4L2 %s (0x%08x)\n",
- v4l2_ioctl_names[_IOC_NR(cmd)], cmd);
- break;
- default:
- dprintk("ioctl(): unsupported command 0x%08x\n", cmd);
- }
- switch (cmd) {
- /* TODO: V4L1 interface (use compatibility layer?) */
- /* V4L2 interface */
- case VIDIOC_QUERYCAP: {
- vino_v4l2_querycap(arg);
- break;
- }
- case VIDIOC_ENUMINPUT: {
- return vino_v4l2_enuminput(vcs, arg);
- }
- case VIDIOC_G_INPUT: {
- return vino_v4l2_g_input(vcs, arg);
- }
- case VIDIOC_S_INPUT: {
- return vino_v4l2_s_input(vcs, arg);
- }
- case VIDIOC_ENUMSTD: {
- return vino_v4l2_enumstd(vcs, arg);
- }
- case VIDIOC_G_STD: {
- return vino_v4l2_g_std(vcs, arg);
- }
- case VIDIOC_S_STD: {
- return vino_v4l2_s_std(vcs, arg);
- }
- case VIDIOC_ENUM_FMT: {
- return vino_v4l2_enum_fmt(vcs, arg);
- }
- case VIDIOC_TRY_FMT: {
- return vino_v4l2_try_fmt(vcs, arg);
- }
- case VIDIOC_G_FMT: {
- return vino_v4l2_g_fmt(vcs, arg);
- }
- case VIDIOC_S_FMT: {
- return vino_v4l2_s_fmt(vcs, arg);
- }
- case VIDIOC_CROPCAP: {
- return vino_v4l2_cropcap(vcs, arg);
- }
- case VIDIOC_G_CROP: {
- return vino_v4l2_g_crop(vcs, arg);
- }
- case VIDIOC_S_CROP: {
- return vino_v4l2_s_crop(vcs, arg);
- }
- case VIDIOC_G_PARM: {
- return vino_v4l2_g_parm(vcs, arg);
- }
- case VIDIOC_S_PARM: {
- return vino_v4l2_s_parm(vcs, arg);
- }
- case VIDIOC_REQBUFS: {
- return vino_v4l2_reqbufs(vcs, arg);
- }
- case VIDIOC_QUERYBUF: {
- return vino_v4l2_querybuf(vcs, arg);
- }
- case VIDIOC_QBUF: {
- return vino_v4l2_qbuf(vcs, arg);
- }
- case VIDIOC_DQBUF: {
- return vino_v4l2_dqbuf(vcs, arg, file->f_flags & O_NONBLOCK);
- }
- case VIDIOC_STREAMON: {
- return vino_v4l2_streamon(vcs);
- }
- case VIDIOC_STREAMOFF: {
- return vino_v4l2_streamoff(vcs);
- }
- case VIDIOC_QUERYCTRL: {
- return vino_v4l2_queryctrl(vcs, arg);
- }
- case VIDIOC_G_CTRL: {
- return vino_v4l2_g_ctrl(vcs, arg);
- }
- case VIDIOC_S_CTRL: {
- return vino_v4l2_s_ctrl(vcs, arg);
- }
- default:
- return -ENOIOCTLCMD;
- }
- return 0;
- }
- static int vino_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
- {
- struct video_device *dev = video_devdata(file);
- struct vino_channel_settings *vcs = video_get_drvdata(dev);
- int ret;
- if (down_interruptible(&vcs->sem))
- return -EINTR;
- ret = video_usercopy(inode, file, cmd, arg, vino_do_ioctl);
- up(&vcs->sem);
- return ret;
- }
- /* Initialization and cleanup */
- // __initdata
- static int vino_init_stage = 0;
- static struct file_operations vino_fops = {
- .owner = THIS_MODULE,
- .open = vino_open,
- .release = vino_close,
- .ioctl = vino_ioctl,
- .mmap = vino_mmap,
- .poll = vino_poll,
- .llseek = no_llseek,
- };
- static struct video_device v4l_device_template = {
- .name = "NOT SET",
- //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE |
- // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY
- .hardware = VID_HARDWARE_VINO,
- .fops = &vino_fops,
- .minor = -1,
- };
- static void vino_module_cleanup(int stage)
- {
- switch(stage) {
- case 10:
- video_unregister_device(vino_drvdata->b.v4l_device);
- vino_drvdata->b.v4l_device = NULL;
- case 9:
- video_unregister_device(vino_drvdata->a.v4l_device);
- vino_drvdata->a.v4l_device = NULL;
- case 8:
- vino_i2c_del_bus();
- case 7:
- free_irq(SGI_VINO_IRQ, NULL);
- case 6:
- if (vino_drvdata->b.v4l_device) {
- video_device_release(vino_drvdata->b.v4l_device);
- vino_drvdata->b.v4l_device = NULL;
- }
- case 5:
- if (vino_drvdata->a.v4l_device) {
- video_device_release(vino_drvdata->a.v4l_device);
- vino_drvdata->a.v4l_device = NULL;
- }
- case 4:
- /* all entries in dma_cpu dummy table have the same address */
- dma_unmap_single(NULL,
- vino_drvdata->dummy_desc_table.dma_cpu[0],
- PAGE_SIZE, DMA_FROM_DEVICE);
- dma_free_coherent(NULL, VINO_DUMMY_DESC_COUNT
- * sizeof(dma_addr_t),
- (void *)vino_drvdata->
- dummy_desc_table.dma_cpu,
- vino_drvdata->dummy_desc_table.dma);
- case 3:
- free_page(vino_drvdata->dummy_page);
- case 2:
- kfree(vino_drvdata);
- case 1:
- iounmap(vino);
- case 0:
- break;
- default:
- dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
- stage);
- }
- }
- static int vino_probe(void)
- {
- unsigned long rev_id;
- if (ip22_is_fullhouse()) {
- printk(KERN_ERR "VINO doesn't exist in IP22 Fullhouse\n");
- return -ENODEV;
- }
- if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
- printk(KERN_ERR "VINO is not found (EISA BUS not present)\n");
- return -ENODEV;
- }
- vino = (struct sgi_vino *)ioremap(VINO_BASE, sizeof(struct sgi_vino));
- if (!vino) {
- printk(KERN_ERR "VINO: ioremap() failed\n");
- return -EIO;
- }
- vino_init_stage++;
- if (get_dbe(rev_id, &(vino->rev_id))) {
- printk(KERN_ERR "Failed to read VINO revision register\n");
- vino_module_cleanup(vino_init_stage);
- return -ENODEV;
- }
- if (VINO_ID_VALUE(rev_id) != VINO_CHIP_ID) {
- printk(KERN_ERR "Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
- rev_id);
- vino_module_cleanup(vino_init_stage);
- return -ENODEV;
- }
- printk(KERN_INFO "VINO with chip ID %ld, revision %ld found\n",
- VINO_ID_VALUE(rev_id), VINO_REV_NUM(rev_id));
- return 0;
- }
- static int vino_init(void)
- {
- dma_addr_t dma_dummy_address;
- int i;
- vino_drvdata = (struct vino_settings *)
- kmalloc(sizeof(struct vino_settings), GFP_KERNEL);
- if (!vino_drvdata) {
- vino_module_cleanup(vino_init_stage);
- return -ENOMEM;
- }
- memset(vino_drvdata, 0, sizeof(struct vino_settings));
- vino_init_stage++;
- /* create a dummy dma descriptor */
- vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
- if (!vino_drvdata->dummy_page) {
- vino_module_cleanup(vino_init_stage);
- return -ENOMEM;
- }
- vino_init_stage++;
- // TODO: use page_count in dummy_desc_table
- vino_drvdata->dummy_desc_table.dma_cpu =
- dma_alloc_coherent(NULL,
- VINO_DUMMY_DESC_COUNT * sizeof(dma_addr_t),
- &vino_drvdata->dummy_desc_table.dma,
- GFP_KERNEL | GFP_DMA);
- if (!vino_drvdata->dummy_desc_table.dma_cpu) {
- vino_module_cleanup(vino_init_stage);
- return -ENOMEM;
- }
- vino_init_stage++;
- dma_dummy_address = dma_map_single(NULL,
- (void *)vino_drvdata->dummy_page,
- PAGE_SIZE, DMA_FROM_DEVICE);
- for (i = 0; i < VINO_DUMMY_DESC_COUNT; i++) {
- vino_drvdata->dummy_desc_table.dma_cpu[i] = dma_dummy_address;
- }
- /* initialize VINO */
- vino->control = 0;
- vino->a.next_4_desc = vino_drvdata->dummy_desc_table.dma;
- vino->b.next_4_desc = vino_drvdata->dummy_desc_table.dma;
- udelay(VINO_DESC_FETCH_DELAY);
- vino->intr_status = 0;
- vino->a.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
- vino->b.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
- return 0;
- }
- static int vino_init_channel_settings(struct vino_channel_settings *vcs,
- unsigned int channel, const char *name)
- {
- vcs->channel = channel;
- vcs->input = VINO_INPUT_NONE;
- vcs->alpha = 0;
- vcs->users = 0;
- vcs->data_format = VINO_DATA_FMT_GREY;
- vcs->data_norm = VINO_DATA_NORM_NTSC;
- vcs->decimation = 1;
- vino_set_default_clipping(vcs);
- vino_set_default_framerate(vcs);
- vcs->capturing = 0;
- init_MUTEX(&vcs->sem);
- spin_lock_init(&vcs->capture_lock);
- init_MUTEX(&vcs->fb_queue.queue_sem);
- spin_lock_init(&vcs->fb_queue.queue_lock);
- init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
- vcs->v4l_device = video_device_alloc();
- if (!vcs->v4l_device) {
- vino_module_cleanup(vino_init_stage);
- return -ENOMEM;
- }
- vino_init_stage++;
- memcpy(vcs->v4l_device, &v4l_device_template,
- sizeof(struct video_device));
- strcpy(vcs->v4l_device->name, name);
- vcs->v4l_device->release = video_device_release;
- video_set_drvdata(vcs->v4l_device, vcs);
- return 0;
- }
- static int __init vino_module_init(void)
- {
- int ret;
- printk(KERN_INFO "SGI VINO driver version %s\n",
- VINO_MODULE_VERSION);
- ret = vino_probe();
- if (ret)
- return ret;
- ret = vino_init();
- if (ret)
- return ret;
- /* initialize data structures */
- spin_lock_init(&vino_drvdata->vino_lock);
- spin_lock_init(&vino_drvdata->input_lock);
- ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A,
- vino_v4l_device_name_a);
- if (ret)
- return ret;
- ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B,
- vino_v4l_device_name_b);
- if (ret)
- return ret;
- /* initialize hardware and register V4L devices */
- ret = request_irq(SGI_VINO_IRQ, vino_interrupt, 0,
- vino_driver_description, NULL);
- if (ret) {
- printk(KERN_ERR "VINO: requesting IRQ %02d failed\n",
- SGI_VINO_IRQ);
- vino_module_cleanup(vino_init_stage);
- return -EAGAIN;
- }
- vino_init_stage++;
- ret = vino_i2c_add_bus();
- if (ret) {
- printk(KERN_ERR "VINO I2C bus registration failed\n");
- vino_module_cleanup(vino_init_stage);
- return ret;
- }
- vino_init_stage++;
- ret = video_register_device(vino_drvdata->a.v4l_device,
- VFL_TYPE_GRABBER, -1);
- if (ret < 0) {
- printk(KERN_ERR "VINO channel A Video4Linux-device "
- "registration failed\n");
- vino_module_cleanup(vino_init_stage);
- return -EINVAL;
- }
- vino_init_stage++;
- ret = video_register_device(vino_drvdata->b.v4l_device,
- VFL_TYPE_GRABBER, -1);
- if (ret < 0) {
- printk(KERN_ERR "VINO channel B Video4Linux-device "
- "registration failed\n");
- vino_module_cleanup(vino_init_stage);
- return -EINVAL;
- }
- vino_init_stage++;
- #if defined(CONFIG_KMOD) && defined(MODULE)
- request_module("saa7191");
- request_module("indycam");
- #endif
- dprintk("init complete!\n");
- return 0;
- }
- static void __exit vino_module_exit(void)
- {
- dprintk("exiting, stage = %d ...\n", vino_init_stage);
- vino_module_cleanup(vino_init_stage);
- dprintk("cleanup complete, exit!\n");
- }
- module_init(vino_module_init);
- module_exit(vino_module_exit);
|