0048-bcm2835-add-v4l2-camera-device.patch 214 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338
  1. From 47ada5db4dbd8a4dd751bbd630d4abbd15131c98 Mon Sep 17 00:00:00 2001
  2. From: Vincent Sanders <vincent.sanders@collabora.co.uk>
  3. Date: Wed, 30 Jan 2013 12:45:18 +0000
  4. Subject: [PATCH 048/381] bcm2835: add v4l2 camera device
  5. - Supports raw YUV capture, preview, JPEG and H264.
  6. - Uses videobuf2 for data transfer, using dma_buf.
  7. - Uses 3.6.10 timestamping
  8. - Camera power based on use
  9. - Uses immutable input mode on video encoder
  10. Signed-off-by: Daniel Stone <daniels@collabora.com>
  11. Signed-off-by: Luke Diamand <luked@broadcom.com>
  12. V4L2: Fixes from 6by9
  13. V4L2: Fix EV values. Add manual shutter speed control
  14. V4L2 EV values should be in units of 1/1000. Corrected.
  15. Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
  16. give manual shutter control. Requires manual exposure mode
  17. to be selected first.
  18. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  19. V4L2: Correct JPEG Q-factor range
  20. Should be 1-100, not 0-100
  21. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  22. V4L2: Fix issue of driver jamming if STREAMON failed.
  23. Fix issue where the driver was left in a partially enabled
  24. state if STREAMON failed, and would then reject many IOCTLs
  25. as it thought it was streaming.
  26. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  27. V4L2: Fix ISO controls.
  28. Driver was passing the index to the GPU, and not the desired
  29. ISO value.
  30. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  31. V4L2: Add flicker avoidance controls
  32. Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
  33. avoidance frequencies.
  34. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  35. V4L2: Add support for frame rate control.
  36. Add support for frame rate (or time per frame as V4L2
  37. inverts it) control via s_parm.
  38. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  39. V4L2: Improve G_FBUF handling so we pass conformance
  40. Return some sane numbers for get framebuffer so that
  41. we pass conformance.
  42. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  43. V4L2: Fix information advertised through g_vidfmt
  44. Width and height were being stored based on incorrect
  45. values.
  46. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  47. V4L2: Add support for inline H264 headers
  48. Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
  49. to control H264 inline headers.
  50. Requires firmware fix to work correctly, otherwise format
  51. has to be set to H264 before this parameter is set.
  52. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  53. V4L2: Fix JPEG timestamp issue
  54. JPEG images were coming through from the GPU with timestamp
  55. of 0. Detect this and give current system time instead
  56. of some invalid value.
  57. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  58. V4L2: Fix issue when switching down JPEG resolution.
  59. JPEG buffer size calculation is based on input resolution.
  60. Input resolution was being configured after output port
  61. format. Caused failures if switching from one JPEG resolution
  62. to a smaller one.
  63. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  64. V4L2: Enable MJPEG encoding
  65. Requires GPU firmware update to support MJPEG encoder.
  66. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  67. V4L2: Correct flag settings for compressed formats
  68. Set flags field correctly on enum_fmt_vid_cap for compressed
  69. image formats.
  70. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  71. V4L2: H264 profile & level ctrls, FPS control and auto exp pri
  72. Several control handling updates.
  73. H264 profile and level controls.
  74. Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
  75. select whether AE is allowed to override the framerate specified.
  76. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  77. V4L2: Correct BGR24 to RGB24 in format table
  78. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  79. V4L2: Add additional pixel formats. Correct colourspace
  80. Adds the other flavours of YUYV, and NV12.
  81. Corrects the overlay advertised colourspace.
  82. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  83. V4L2: Drop logging msg from info to debug
  84. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  85. V4L2: Initial pass at scene modes.
  86. Only supports exposure mode and metering modes.
  87. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  88. V4L2: Add manual white balance control.
  89. Adds support for V4L2_CID_RED_BALANCE and
  90. V4L2_CID_BLUE_BALANCE. Only has an effect if
  91. V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
  92. V4L2_WHITE_BALANCE_MANUAL selected.
  93. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  94. config: Enable V4L / MMAL driver
  95. V4L2: Increase the MMAL timeout to 3sec
  96. MJPEG codec flush is now taking longer and results
  97. in a kernel panic if the driver has stopped waiting for
  98. the result when it finally completes.
  99. Increase the timeout value from 1 to 3secs.
  100. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  101. V4L2: Add support for setting H264_I_PERIOD
  102. Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
  103. to set the frequency with which I frames are produced.
  104. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  105. V4L2: Enable GPU function for removing padding from images.
  106. GPU can now support arbitrary strides, although may require
  107. additional processing to achieve it. Enable this feature
  108. so that the images delivered are the size requested.
  109. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  110. V4L2: Add support for V4L2_PIX_FMT_BGR32
  111. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  112. V4L2: Set the colourspace to avoid odd YUV-RGB conversions
  113. Removes the amiguity from the conversion routines and stops
  114. them dropping back to the SD vs HD choice of coeffs.
  115. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  116. V4L2: Make video/still threshold a run-time param
  117. Move the define for at what resolution the driver
  118. switches from a video mode capture to a stills mode
  119. capture to module parameters.
  120. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  121. V4L2: Fix incorrect pool sizing
  122. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  123. V4L2: Add option to disable enum_framesizes.
  124. Gstreamer's handling of a driver that advertises
  125. V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
  126. resolutions is broken. See bug
  127. https://bugzilla.gnome.org/show_bug.cgi?id=726521
  128. Optional parameter of gst_v4l2src_is_broken added.
  129. If non-zero, the driver claims not to support that
  130. ioctl, and gstreamer should be happy again (it
  131. guesses a set of defaults for itself).
  132. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  133. V4L2: Add support for more image formats
  134. Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.
  135. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  136. V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
  137. Request to extend the range from the fairly arbitrary
  138. 1000 frames (33 seconds at 30fps). Extend out to the
  139. max range supported (int32 value).
  140. Also allow 0, which is handled by the codec as only
  141. send an I-frame on the first frame and never again.
  142. There may be an exception if it detects a significant
  143. scene change, but there's no easy way around that.
  144. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  145. bcm2835-camera: stop_streaming now has a void return
  146. BCM2835-V4L2: Fix compliance test failures
  147. VIDIOC_TRY_FMT and VIDIOC_S_FMT tests were faling due
  148. to reporting V4L2_COLORSPACE_JPEG when the colour
  149. format wasn't V4L2_PIX_FMT_JPEG.
  150. Now reports V4L2_COLORSPACE_SMPTE170M for YUV formats.
  151. bcm2835 camera planar/packed stride length
  152. Added a field to the mmal_fmt struct used to compute the bytes per line
  153. when using a particular format. This results in the correct stride being
  154. calculated even when the format is planar.
  155. Signed-off-by: Garrett Wilson <g@floft.net>
  156. bcm2835: camera: check for scene not being found
  157. static analysis by cppcheck detected some potential NULL pointer
  158. dereference issues:
  159. [drivers/media/platform/bcm2835/controls.c:854]: (error) Possible null
  160. pointer dereference: scene
  161. (and lines 858, 859 too)
  162. it is possible that scene is not found because of an invalue ctrl->val
  163. and is therefore NULL and hence causing a null pointer dereference.
  164. Signed-off-by: Colin Ian King <colin.king@canonical.com>
  165. bcm2835: memcpy port data to m rather than rmsg
  166. static analysis by cppcheck detected a memcpy to rmsg which is
  167. not actually initialized at that point. The memcpy should be copying
  168. to variable m instead.
  169. Signed-off-by: Colin Ian King <colin.king@canonical.com>
  170. BCM2835-V4L2: Return buffers to videobuf2 on shutdown
  171. https://github.com/raspberrypi/linux/issues/817
  172. Fixes the kernel warning from videobuf2 as buffers
  173. are now returned as they are being flushed on
  174. stop_streaming.
  175. squash: Fixup bcm2835-camera for changes in kernel 4.4 api
  176. ---
  177. Documentation/video4linux/bcm2835-v4l2.txt | 60 +
  178. drivers/media/platform/Kconfig | 2 +
  179. drivers/media/platform/Makefile | 2 +
  180. drivers/media/platform/bcm2835/Kconfig | 25 +
  181. drivers/media/platform/bcm2835/Makefile | 5 +
  182. drivers/media/platform/bcm2835/bcm2835-camera.c | 1844 +++++++++++++++++++++
  183. drivers/media/platform/bcm2835/bcm2835-camera.h | 126 ++
  184. drivers/media/platform/bcm2835/controls.c | 1324 +++++++++++++++
  185. drivers/media/platform/bcm2835/mmal-common.h | 53 +
  186. drivers/media/platform/bcm2835/mmal-encodings.h | 127 ++
  187. drivers/media/platform/bcm2835/mmal-msg-common.h | 50 +
  188. drivers/media/platform/bcm2835/mmal-msg-format.h | 81 +
  189. drivers/media/platform/bcm2835/mmal-msg-port.h | 107 ++
  190. drivers/media/platform/bcm2835/mmal-msg.h | 404 +++++
  191. drivers/media/platform/bcm2835/mmal-parameters.h | 656 ++++++++
  192. drivers/media/platform/bcm2835/mmal-vchiq.c | 1916 ++++++++++++++++++++++
  193. drivers/media/platform/bcm2835/mmal-vchiq.h | 178 ++
  194. 17 files changed, 6960 insertions(+)
  195. create mode 100644 Documentation/video4linux/bcm2835-v4l2.txt
  196. create mode 100644 drivers/media/platform/bcm2835/Kconfig
  197. create mode 100644 drivers/media/platform/bcm2835/Makefile
  198. create mode 100644 drivers/media/platform/bcm2835/bcm2835-camera.c
  199. create mode 100644 drivers/media/platform/bcm2835/bcm2835-camera.h
  200. create mode 100644 drivers/media/platform/bcm2835/controls.c
  201. create mode 100644 drivers/media/platform/bcm2835/mmal-common.h
  202. create mode 100644 drivers/media/platform/bcm2835/mmal-encodings.h
  203. create mode 100644 drivers/media/platform/bcm2835/mmal-msg-common.h
  204. create mode 100644 drivers/media/platform/bcm2835/mmal-msg-format.h
  205. create mode 100644 drivers/media/platform/bcm2835/mmal-msg-port.h
  206. create mode 100644 drivers/media/platform/bcm2835/mmal-msg.h
  207. create mode 100644 drivers/media/platform/bcm2835/mmal-parameters.h
  208. create mode 100644 drivers/media/platform/bcm2835/mmal-vchiq.c
  209. create mode 100644 drivers/media/platform/bcm2835/mmal-vchiq.h
  210. --- /dev/null
  211. +++ b/Documentation/video4linux/bcm2835-v4l2.txt
  212. @@ -0,0 +1,60 @@
  213. +
  214. +BCM2835 (aka Raspberry Pi) V4L2 driver
  215. +======================================
  216. +
  217. +1. Copyright
  218. +============
  219. +
  220. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  221. +
  222. +2. License
  223. +==========
  224. +
  225. +This program is free software; you can redistribute it and/or modify
  226. +it under the terms of the GNU General Public License as published by
  227. +the Free Software Foundation; either version 2 of the License, or
  228. +(at your option) any later version.
  229. +
  230. +This program is distributed in the hope that it will be useful,
  231. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  232. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  233. +GNU General Public License for more details.
  234. +
  235. +You should have received a copy of the GNU General Public License
  236. +along with this program; if not, write to the Free Software
  237. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  238. +
  239. +3. Quick Start
  240. +==============
  241. +
  242. +You need a version 1.0 or later of v4l2-ctl, available from:
  243. + git://git.linuxtv.org/v4l-utils.git
  244. +
  245. +$ sudo modprobe bcm2835-v4l2
  246. +
  247. +Turn on the overlay:
  248. +
  249. +$ v4l2-ctl --overlay=1
  250. +
  251. +Turn off the overlay:
  252. +
  253. +$ v4l2-ctl --overlay=0
  254. +
  255. +Set the capture format for video:
  256. +
  257. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  258. +
  259. +(Note: 1088 not 1080).
  260. +
  261. +Capture:
  262. +
  263. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  264. +
  265. +Stills capture:
  266. +
  267. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  268. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  269. +
  270. +List of available formats:
  271. +
  272. +$ v4l2-ctl --list-formats
  273. --- a/drivers/media/platform/Kconfig
  274. +++ b/drivers/media/platform/Kconfig
  275. @@ -11,6 +11,8 @@ menuconfig V4L_PLATFORM_DRIVERS
  276. if V4L_PLATFORM_DRIVERS
  277. +source "drivers/media/platform/bcm2835/Kconfig"
  278. +
  279. source "drivers/media/platform/marvell-ccic/Kconfig"
  280. config VIDEO_VIA_CAMERA
  281. --- a/drivers/media/platform/Makefile
  282. +++ b/drivers/media/platform/Makefile
  283. @@ -2,6 +2,8 @@
  284. # Makefile for the video capture/playback device drivers.
  285. #
  286. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  287. +
  288. obj-$(CONFIG_VIDEO_TIMBERDALE) += timblogiw.o
  289. obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
  290. --- /dev/null
  291. +++ b/drivers/media/platform/bcm2835/Kconfig
  292. @@ -0,0 +1,25 @@
  293. +# Broadcom VideoCore IV v4l2 camera support
  294. +
  295. +config VIDEO_BCM2835
  296. + bool "Broadcom BCM2835 camera interface driver"
  297. + depends on VIDEO_V4L2 && (ARCH_BCM2708 || ARCH_BCM2709 || ARCH_BCM2835)
  298. + ---help---
  299. + Say Y here to enable camera host interface devices for
  300. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  301. + to a service running on VideoCore.
  302. +
  303. +
  304. +if VIDEO_BCM2835
  305. +
  306. +config VIDEO_BCM2835_MMAL
  307. + tristate "Broadcom BM2835 MMAL camera interface driver"
  308. + depends on BCM2708_VCHIQ
  309. + select VIDEOBUF2_VMALLOC
  310. + ---help---
  311. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  312. +
  313. + To compile this driver as a module, choose M here: the
  314. + module will be called bcm2835-v4l2.o
  315. +
  316. +
  317. +endif # VIDEO_BM2835
  318. --- /dev/null
  319. +++ b/drivers/media/platform/bcm2835/Makefile
  320. @@ -0,0 +1,5 @@
  321. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  322. +
  323. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  324. +
  325. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  326. --- /dev/null
  327. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
  328. @@ -0,0 +1,1844 @@
  329. +/*
  330. + * Broadcom BM2835 V4L2 driver
  331. + *
  332. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  333. + *
  334. + * This file is subject to the terms and conditions of the GNU General Public
  335. + * License. See the file COPYING in the main directory of this archive
  336. + * for more details.
  337. + *
  338. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  339. + * Dave Stevenson <dsteve@broadcom.com>
  340. + * Simon Mellor <simellor@broadcom.com>
  341. + * Luke Diamand <luked@broadcom.com>
  342. + */
  343. +
  344. +#include <linux/errno.h>
  345. +#include <linux/kernel.h>
  346. +#include <linux/module.h>
  347. +#include <linux/slab.h>
  348. +#include <media/videobuf2-vmalloc.h>
  349. +#include <media/videobuf2-dma-contig.h>
  350. +#include <media/v4l2-device.h>
  351. +#include <media/v4l2-ioctl.h>
  352. +#include <media/v4l2-ctrls.h>
  353. +#include <media/v4l2-fh.h>
  354. +#include <media/v4l2-event.h>
  355. +#include <media/v4l2-common.h>
  356. +#include <linux/delay.h>
  357. +
  358. +#include "mmal-common.h"
  359. +#include "mmal-encodings.h"
  360. +#include "mmal-vchiq.h"
  361. +#include "mmal-msg.h"
  362. +#include "mmal-parameters.h"
  363. +#include "bcm2835-camera.h"
  364. +
  365. +#define BM2835_MMAL_VERSION "0.0.2"
  366. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  367. +#define MIN_WIDTH 16
  368. +#define MIN_HEIGHT 16
  369. +#define MAX_WIDTH 2592
  370. +#define MAX_HEIGHT 1944
  371. +#define MIN_BUFFER_SIZE (80*1024)
  372. +
  373. +#define MAX_VIDEO_MODE_WIDTH 1280
  374. +#define MAX_VIDEO_MODE_HEIGHT 720
  375. +
  376. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  377. +MODULE_AUTHOR("Vincent Sanders");
  378. +MODULE_LICENSE("GPL");
  379. +MODULE_VERSION(BM2835_MMAL_VERSION);
  380. +
  381. +int bcm2835_v4l2_debug;
  382. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  383. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  384. +
  385. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  386. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  387. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  388. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  389. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  390. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  391. +
  392. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  393. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  394. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  395. + * It's happier if we just don't say anything at all, when it then
  396. + * sets up a load of defaults that it thinks might work.
  397. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  398. + * our function table list (actually switch to an alternate set, but same
  399. + * result).
  400. + */
  401. +int gst_v4l2src_is_broken = 0;
  402. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  403. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  404. +
  405. +static struct bm2835_mmal_dev *gdev; /* global device data */
  406. +
  407. +#define FPS_MIN 1
  408. +#define FPS_MAX 90
  409. +
  410. +/* timeperframe: min/max and default */
  411. +static const struct v4l2_fract
  412. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  413. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  414. + tpf_default = {.numerator = 1000, .denominator = 30000};
  415. +
  416. +/* video formats */
  417. +static struct mmal_fmt formats[] = {
  418. + {
  419. + .name = "4:2:0, planar, YUV",
  420. + .fourcc = V4L2_PIX_FMT_YUV420,
  421. + .flags = 0,
  422. + .mmal = MMAL_ENCODING_I420,
  423. + .depth = 12,
  424. + .mmal_component = MMAL_COMPONENT_CAMERA,
  425. + .ybbp = 1,
  426. + },
  427. + {
  428. + .name = "4:2:2, packed, YUYV",
  429. + .fourcc = V4L2_PIX_FMT_YUYV,
  430. + .flags = 0,
  431. + .mmal = MMAL_ENCODING_YUYV,
  432. + .depth = 16,
  433. + .mmal_component = MMAL_COMPONENT_CAMERA,
  434. + .ybbp = 2,
  435. + },
  436. + {
  437. + .name = "RGB24 (LE)",
  438. + .fourcc = V4L2_PIX_FMT_RGB24,
  439. + .flags = 0,
  440. + .mmal = MMAL_ENCODING_BGR24,
  441. + .depth = 24,
  442. + .mmal_component = MMAL_COMPONENT_CAMERA,
  443. + .ybbp = 3,
  444. + },
  445. + {
  446. + .name = "JPEG",
  447. + .fourcc = V4L2_PIX_FMT_JPEG,
  448. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  449. + .mmal = MMAL_ENCODING_JPEG,
  450. + .depth = 8,
  451. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  452. + .ybbp = 0,
  453. + },
  454. + {
  455. + .name = "H264",
  456. + .fourcc = V4L2_PIX_FMT_H264,
  457. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  458. + .mmal = MMAL_ENCODING_H264,
  459. + .depth = 8,
  460. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  461. + .ybbp = 0,
  462. + },
  463. + {
  464. + .name = "MJPEG",
  465. + .fourcc = V4L2_PIX_FMT_MJPEG,
  466. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  467. + .mmal = MMAL_ENCODING_MJPEG,
  468. + .depth = 8,
  469. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  470. + .ybbp = 0,
  471. + },
  472. + {
  473. + .name = "4:2:2, packed, YVYU",
  474. + .fourcc = V4L2_PIX_FMT_YVYU,
  475. + .flags = 0,
  476. + .mmal = MMAL_ENCODING_YVYU,
  477. + .depth = 16,
  478. + .mmal_component = MMAL_COMPONENT_CAMERA,
  479. + .ybbp = 2,
  480. + },
  481. + {
  482. + .name = "4:2:2, packed, VYUY",
  483. + .fourcc = V4L2_PIX_FMT_VYUY,
  484. + .flags = 0,
  485. + .mmal = MMAL_ENCODING_VYUY,
  486. + .depth = 16,
  487. + .mmal_component = MMAL_COMPONENT_CAMERA,
  488. + .ybbp = 2,
  489. + },
  490. + {
  491. + .name = "4:2:2, packed, UYVY",
  492. + .fourcc = V4L2_PIX_FMT_UYVY,
  493. + .flags = 0,
  494. + .mmal = MMAL_ENCODING_UYVY,
  495. + .depth = 16,
  496. + .mmal_component = MMAL_COMPONENT_CAMERA,
  497. + .ybbp = 2,
  498. + },
  499. + {
  500. + .name = "4:2:0, planar, NV12",
  501. + .fourcc = V4L2_PIX_FMT_NV12,
  502. + .flags = 0,
  503. + .mmal = MMAL_ENCODING_NV12,
  504. + .depth = 12,
  505. + .mmal_component = MMAL_COMPONENT_CAMERA,
  506. + .ybbp = 1,
  507. + },
  508. + {
  509. + .name = "RGB24 (BE)",
  510. + .fourcc = V4L2_PIX_FMT_BGR24,
  511. + .flags = 0,
  512. + .mmal = MMAL_ENCODING_RGB24,
  513. + .depth = 24,
  514. + .mmal_component = MMAL_COMPONENT_CAMERA,
  515. + .ybbp = 3,
  516. + },
  517. + {
  518. + .name = "4:2:0, planar, YVU",
  519. + .fourcc = V4L2_PIX_FMT_YVU420,
  520. + .flags = 0,
  521. + .mmal = MMAL_ENCODING_YV12,
  522. + .depth = 12,
  523. + .mmal_component = MMAL_COMPONENT_CAMERA,
  524. + .ybbp = 1,
  525. + },
  526. + {
  527. + .name = "4:2:0, planar, NV21",
  528. + .fourcc = V4L2_PIX_FMT_NV21,
  529. + .flags = 0,
  530. + .mmal = MMAL_ENCODING_NV21,
  531. + .depth = 12,
  532. + .mmal_component = MMAL_COMPONENT_CAMERA,
  533. + .ybbp = 1,
  534. + },
  535. + {
  536. + .name = "RGB32 (BE)",
  537. + .fourcc = V4L2_PIX_FMT_BGR32,
  538. + .flags = 0,
  539. + .mmal = MMAL_ENCODING_BGRA,
  540. + .depth = 32,
  541. + .mmal_component = MMAL_COMPONENT_CAMERA,
  542. + .ybbp = 4,
  543. + },
  544. +};
  545. +
  546. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  547. +{
  548. + struct mmal_fmt *fmt;
  549. + unsigned int k;
  550. +
  551. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  552. + fmt = &formats[k];
  553. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  554. + break;
  555. + }
  556. +
  557. + if (k == ARRAY_SIZE(formats))
  558. + return NULL;
  559. +
  560. + return &formats[k];
  561. +}
  562. +
  563. +/* ------------------------------------------------------------------
  564. + Videobuf queue operations
  565. + ------------------------------------------------------------------*/
  566. +
  567. +static int queue_setup(struct vb2_queue *vq, const void *parg,
  568. + unsigned int *nbuffers, unsigned int *nplanes,
  569. + unsigned int sizes[], void *alloc_ctxs[])
  570. +{
  571. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  572. + unsigned long size;
  573. +
  574. + /* refuse queue setup if port is not configured */
  575. + if (dev->capture.port == NULL) {
  576. + v4l2_err(&dev->v4l2_dev,
  577. + "%s: capture port not configured\n", __func__);
  578. + return -EINVAL;
  579. + }
  580. +
  581. + size = dev->capture.port->current_buffer.size;
  582. + if (size == 0) {
  583. + v4l2_err(&dev->v4l2_dev,
  584. + "%s: capture port buffer size is zero\n", __func__);
  585. + return -EINVAL;
  586. + }
  587. +
  588. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  589. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  590. +
  591. + *nplanes = 1;
  592. +
  593. + sizes[0] = size;
  594. +
  595. + /*
  596. + * videobuf2-vmalloc allocator is context-less so no need to set
  597. + * alloc_ctxs array.
  598. + */
  599. +
  600. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  601. + __func__, dev);
  602. +
  603. + return 0;
  604. +}
  605. +
  606. +static int buffer_prepare(struct vb2_buffer *vb)
  607. +{
  608. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  609. + unsigned long size;
  610. +
  611. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  612. + __func__, dev);
  613. +
  614. + BUG_ON(dev->capture.port == NULL);
  615. + BUG_ON(dev->capture.fmt == NULL);
  616. +
  617. + size = dev->capture.stride * dev->capture.height;
  618. + if (vb2_plane_size(vb, 0) < size) {
  619. + v4l2_err(&dev->v4l2_dev,
  620. + "%s data will not fit into plane (%lu < %lu)\n",
  621. + __func__, vb2_plane_size(vb, 0), size);
  622. + return -EINVAL;
  623. + }
  624. +
  625. + return 0;
  626. +}
  627. +
  628. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  629. +{
  630. + return dev->capture.camera_port ==
  631. + &dev->
  632. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  633. +}
  634. +
  635. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  636. + struct vchiq_mmal_port *port,
  637. + int status,
  638. + struct mmal_buffer *buf,
  639. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  640. +{
  641. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  642. +
  643. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  644. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  645. + __func__, status, buf, length, mmal_flags, pts);
  646. +
  647. + if (status != 0) {
  648. + /* error in transfer */
  649. + if (buf != NULL) {
  650. + /* there was a buffer with the error so return it */
  651. + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  652. + }
  653. + return;
  654. + } else if (length == 0) {
  655. + /* stream ended */
  656. + if (buf != NULL) {
  657. + /* this should only ever happen if the port is
  658. + * disabled and there are buffers still queued
  659. + */
  660. + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  661. + pr_debug("Empty buffer");
  662. + } else if (dev->capture.frame_count) {
  663. + /* grab another frame */
  664. + if (is_capturing(dev)) {
  665. + pr_debug("Grab another frame");
  666. + vchiq_mmal_port_parameter_set(
  667. + instance,
  668. + dev->capture.
  669. + camera_port,
  670. + MMAL_PARAMETER_CAPTURE,
  671. + &dev->capture.
  672. + frame_count,
  673. + sizeof(dev->capture.frame_count));
  674. + }
  675. + } else {
  676. + /* signal frame completion */
  677. + complete(&dev->capture.frame_cmplt);
  678. + }
  679. + } else {
  680. + if (dev->capture.frame_count) {
  681. + if (dev->capture.vc_start_timestamp != -1 &&
  682. + pts != 0) {
  683. + s64 runtime_us = pts -
  684. + dev->capture.vc_start_timestamp;
  685. + u32 div = 0;
  686. + u32 rem = 0;
  687. +
  688. + div =
  689. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  690. + buf->vb.timestamp.tv_sec =
  691. + dev->capture.kernel_start_ts.tv_sec - 1 +
  692. + div;
  693. + buf->vb.timestamp.tv_usec =
  694. + dev->capture.kernel_start_ts.tv_usec + rem;
  695. +
  696. + if (buf->vb.timestamp.tv_usec >=
  697. + USEC_PER_SEC) {
  698. + buf->vb.timestamp.tv_sec++;
  699. + buf->vb.timestamp.tv_usec -=
  700. + USEC_PER_SEC;
  701. + }
  702. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  703. + "Convert start time %d.%06d and %llu "
  704. + "with offset %llu to %d.%06d\n",
  705. + (int)dev->capture.kernel_start_ts.
  706. + tv_sec,
  707. + (int)dev->capture.kernel_start_ts.
  708. + tv_usec,
  709. + dev->capture.vc_start_timestamp, pts,
  710. + (int)buf->vb.timestamp.tv_sec,
  711. + (int)buf->vb.timestamp.
  712. + tv_usec);
  713. + } else {
  714. + v4l2_get_timestamp(&buf->vb.timestamp);
  715. + }
  716. +
  717. + vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
  718. + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
  719. +
  720. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  721. + is_capturing(dev)) {
  722. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  723. + "Grab another frame as buffer has EOS");
  724. + vchiq_mmal_port_parameter_set(
  725. + instance,
  726. + dev->capture.
  727. + camera_port,
  728. + MMAL_PARAMETER_CAPTURE,
  729. + &dev->capture.
  730. + frame_count,
  731. + sizeof(dev->capture.frame_count));
  732. + }
  733. + } else {
  734. + /* signal frame completion */
  735. + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  736. + complete(&dev->capture.frame_cmplt);
  737. + }
  738. + }
  739. +}
  740. +
  741. +static int enable_camera(struct bm2835_mmal_dev *dev)
  742. +{
  743. + int ret;
  744. + if (!dev->camera_use_count) {
  745. + ret = vchiq_mmal_component_enable(
  746. + dev->instance,
  747. + dev->component[MMAL_COMPONENT_CAMERA]);
  748. + if (ret < 0) {
  749. + v4l2_err(&dev->v4l2_dev,
  750. + "Failed enabling camera, ret %d\n", ret);
  751. + return -EINVAL;
  752. + }
  753. + }
  754. + dev->camera_use_count++;
  755. + v4l2_dbg(1, bcm2835_v4l2_debug,
  756. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  757. + dev->camera_use_count);
  758. + return 0;
  759. +}
  760. +
  761. +static int disable_camera(struct bm2835_mmal_dev *dev)
  762. +{
  763. + int ret;
  764. + if (!dev->camera_use_count) {
  765. + v4l2_err(&dev->v4l2_dev,
  766. + "Disabled the camera when already disabled\n");
  767. + return -EINVAL;
  768. + }
  769. + dev->camera_use_count--;
  770. + if (!dev->camera_use_count) {
  771. + unsigned int i = 0xFFFFFFFF;
  772. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  773. + "Disabling camera\n");
  774. + ret =
  775. + vchiq_mmal_component_disable(
  776. + dev->instance,
  777. + dev->component[MMAL_COMPONENT_CAMERA]);
  778. + if (ret < 0) {
  779. + v4l2_err(&dev->v4l2_dev,
  780. + "Failed disabling camera, ret %d\n", ret);
  781. + return -EINVAL;
  782. + }
  783. + vchiq_mmal_port_parameter_set(
  784. + dev->instance,
  785. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  786. + MMAL_PARAMETER_CAMERA_NUM, &i,
  787. + sizeof(i));
  788. + }
  789. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  790. + "Camera refcount now %d\n", dev->camera_use_count);
  791. + return 0;
  792. +}
  793. +
  794. +static void buffer_queue(struct vb2_buffer *vb)
  795. +{
  796. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  797. + struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
  798. + struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
  799. + int ret;
  800. +
  801. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  802. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  803. +
  804. + buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
  805. + buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
  806. +
  807. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  808. + if (ret < 0)
  809. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  810. + __func__);
  811. +}
  812. +
  813. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  814. +{
  815. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  816. + int ret;
  817. + int parameter_size;
  818. +
  819. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  820. + __func__, dev);
  821. +
  822. + /* ensure a format has actually been set */
  823. + if (dev->capture.port == NULL)
  824. + return -EINVAL;
  825. +
  826. + if (enable_camera(dev) < 0) {
  827. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  828. + return -EINVAL;
  829. + }
  830. +
  831. + /*init_completion(&dev->capture.frame_cmplt); */
  832. +
  833. + /* enable frame capture */
  834. + dev->capture.frame_count = 1;
  835. +
  836. + /* if the preview is not already running, wait for a few frames for AGC
  837. + * to settle down.
  838. + */
  839. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  840. + msleep(300);
  841. +
  842. + /* enable the connection from camera to encoder (if applicable) */
  843. + if (dev->capture.camera_port != dev->capture.port
  844. + && dev->capture.camera_port) {
  845. + ret = vchiq_mmal_port_enable(dev->instance,
  846. + dev->capture.camera_port, NULL);
  847. + if (ret) {
  848. + v4l2_err(&dev->v4l2_dev,
  849. + "Failed to enable encode tunnel - error %d\n",
  850. + ret);
  851. + return -1;
  852. + }
  853. + }
  854. +
  855. + /* Get VC timestamp at this point in time */
  856. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  857. + if (vchiq_mmal_port_parameter_get(dev->instance,
  858. + dev->capture.camera_port,
  859. + MMAL_PARAMETER_SYSTEM_TIME,
  860. + &dev->capture.vc_start_timestamp,
  861. + &parameter_size)) {
  862. + v4l2_err(&dev->v4l2_dev,
  863. + "Failed to get VC start time - update your VC f/w\n");
  864. +
  865. + /* Flag to indicate just to rely on kernel timestamps */
  866. + dev->capture.vc_start_timestamp = -1;
  867. + } else
  868. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  869. + "Start time %lld size %d\n",
  870. + dev->capture.vc_start_timestamp, parameter_size);
  871. +
  872. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  873. +
  874. + /* enable the camera port */
  875. + dev->capture.port->cb_ctx = dev;
  876. + ret =
  877. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  878. + if (ret) {
  879. + v4l2_err(&dev->v4l2_dev,
  880. + "Failed to enable capture port - error %d. "
  881. + "Disabling camera port again\n", ret);
  882. +
  883. + vchiq_mmal_port_disable(dev->instance,
  884. + dev->capture.camera_port);
  885. + if (disable_camera(dev) < 0) {
  886. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  887. + return -EINVAL;
  888. + }
  889. + return -1;
  890. + }
  891. +
  892. + /* capture the first frame */
  893. + vchiq_mmal_port_parameter_set(dev->instance,
  894. + dev->capture.camera_port,
  895. + MMAL_PARAMETER_CAPTURE,
  896. + &dev->capture.frame_count,
  897. + sizeof(dev->capture.frame_count));
  898. + return 0;
  899. +}
  900. +
  901. +/* abort streaming and wait for last buffer */
  902. +static void stop_streaming(struct vb2_queue *vq)
  903. +{
  904. + int ret;
  905. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  906. +
  907. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  908. + __func__, dev);
  909. +
  910. + init_completion(&dev->capture.frame_cmplt);
  911. + dev->capture.frame_count = 0;
  912. +
  913. + /* ensure a format has actually been set */
  914. + if (dev->capture.port == NULL) {
  915. + v4l2_err(&dev->v4l2_dev,
  916. + "no capture port - stream not started?\n");
  917. + return;
  918. + }
  919. +
  920. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  921. +
  922. + /* stop capturing frames */
  923. + vchiq_mmal_port_parameter_set(dev->instance,
  924. + dev->capture.camera_port,
  925. + MMAL_PARAMETER_CAPTURE,
  926. + &dev->capture.frame_count,
  927. + sizeof(dev->capture.frame_count));
  928. +
  929. + /* wait for last frame to complete */
  930. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  931. + if (ret <= 0)
  932. + v4l2_err(&dev->v4l2_dev,
  933. + "error %d waiting for frame completion\n", ret);
  934. +
  935. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  936. + "disabling connection\n");
  937. +
  938. + /* disable the connection from camera to encoder */
  939. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  940. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  941. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  942. + "disabling port\n");
  943. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  944. + } else if (dev->capture.camera_port != dev->capture.port) {
  945. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  946. + ret);
  947. + }
  948. +
  949. + if (disable_camera(dev) < 0)
  950. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  951. +}
  952. +
  953. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  954. +{
  955. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  956. + mutex_lock(&dev->mutex);
  957. +}
  958. +
  959. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  960. +{
  961. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  962. + mutex_unlock(&dev->mutex);
  963. +}
  964. +
  965. +static struct vb2_ops bm2835_mmal_video_qops = {
  966. + .queue_setup = queue_setup,
  967. + .buf_prepare = buffer_prepare,
  968. + .buf_queue = buffer_queue,
  969. + .start_streaming = start_streaming,
  970. + .stop_streaming = stop_streaming,
  971. + .wait_prepare = bm2835_mmal_unlock,
  972. + .wait_finish = bm2835_mmal_lock,
  973. +};
  974. +
  975. +/* ------------------------------------------------------------------
  976. + IOCTL operations
  977. + ------------------------------------------------------------------*/
  978. +
  979. +/* overlay ioctl */
  980. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  981. + struct v4l2_fmtdesc *f)
  982. +{
  983. + struct mmal_fmt *fmt;
  984. +
  985. + if (f->index >= ARRAY_SIZE(formats))
  986. + return -EINVAL;
  987. +
  988. + fmt = &formats[f->index];
  989. +
  990. + strlcpy(f->description, fmt->name, sizeof(f->description));
  991. + f->pixelformat = fmt->fourcc;
  992. + f->flags = fmt->flags;
  993. +
  994. + return 0;
  995. +}
  996. +
  997. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  998. + struct v4l2_format *f)
  999. +{
  1000. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1001. +
  1002. + f->fmt.win = dev->overlay;
  1003. +
  1004. + return 0;
  1005. +}
  1006. +
  1007. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  1008. + struct v4l2_format *f)
  1009. +{
  1010. + /* Only support one format so get the current one. */
  1011. + vidioc_g_fmt_vid_overlay(file, priv, f);
  1012. +
  1013. + /* todo: allow the size and/or offset to be changed. */
  1014. + return 0;
  1015. +}
  1016. +
  1017. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  1018. + struct v4l2_format *f)
  1019. +{
  1020. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1021. +
  1022. + vidioc_try_fmt_vid_overlay(file, priv, f);
  1023. +
  1024. + dev->overlay = f->fmt.win;
  1025. +
  1026. + /* todo: program the preview port parameters */
  1027. + return 0;
  1028. +}
  1029. +
  1030. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  1031. +{
  1032. + int ret;
  1033. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1034. + struct vchiq_mmal_port *src;
  1035. + struct vchiq_mmal_port *dst;
  1036. + struct mmal_parameter_displayregion prev_config = {
  1037. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  1038. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  1039. + .layer = PREVIEW_LAYER,
  1040. + .alpha = 255,
  1041. + .fullscreen = 0,
  1042. + .dest_rect = {
  1043. + .x = dev->overlay.w.left,
  1044. + .y = dev->overlay.w.top,
  1045. + .width = dev->overlay.w.width,
  1046. + .height = dev->overlay.w.height,
  1047. + },
  1048. + };
  1049. +
  1050. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  1051. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  1052. + return 0; /* already in requested state */
  1053. +
  1054. + src =
  1055. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1056. + output[MMAL_CAMERA_PORT_PREVIEW];
  1057. +
  1058. + if (!on) {
  1059. + /* disconnect preview ports and disable component */
  1060. + ret = vchiq_mmal_port_disable(dev->instance, src);
  1061. + if (!ret)
  1062. + ret =
  1063. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  1064. + NULL);
  1065. + if (ret >= 0)
  1066. + ret = vchiq_mmal_component_disable(
  1067. + dev->instance,
  1068. + dev->component[MMAL_COMPONENT_PREVIEW]);
  1069. +
  1070. + disable_camera(dev);
  1071. + return ret;
  1072. + }
  1073. +
  1074. + /* set preview port format and connect it to output */
  1075. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  1076. +
  1077. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  1078. + if (ret < 0)
  1079. + goto error;
  1080. +
  1081. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  1082. + MMAL_PARAMETER_DISPLAYREGION,
  1083. + &prev_config, sizeof(prev_config));
  1084. + if (ret < 0)
  1085. + goto error;
  1086. +
  1087. + if (enable_camera(dev) < 0)
  1088. + goto error;
  1089. +
  1090. + ret = vchiq_mmal_component_enable(
  1091. + dev->instance,
  1092. + dev->component[MMAL_COMPONENT_PREVIEW]);
  1093. + if (ret < 0)
  1094. + goto error;
  1095. +
  1096. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  1097. + src, dst);
  1098. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  1099. + if (!ret)
  1100. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  1101. +error:
  1102. + return ret;
  1103. +}
  1104. +
  1105. +static int vidioc_g_fbuf(struct file *file, void *fh,
  1106. + struct v4l2_framebuffer *a)
  1107. +{
  1108. + /* The video overlay must stay within the framebuffer and can't be
  1109. + positioned independently. */
  1110. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1111. + struct vchiq_mmal_port *preview_port =
  1112. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1113. + output[MMAL_CAMERA_PORT_PREVIEW];
  1114. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  1115. + a->fmt.width = preview_port->es.video.width;
  1116. + a->fmt.height = preview_port->es.video.height;
  1117. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  1118. + a->fmt.bytesperline = preview_port->es.video.width;
  1119. + a->fmt.sizeimage = (preview_port->es.video.width *
  1120. + preview_port->es.video.height * 3)>>1;
  1121. + a->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
  1122. +
  1123. + return 0;
  1124. +}
  1125. +
  1126. +/* input ioctls */
  1127. +static int vidioc_enum_input(struct file *file, void *priv,
  1128. + struct v4l2_input *inp)
  1129. +{
  1130. + /* only a single camera input */
  1131. + if (inp->index != 0)
  1132. + return -EINVAL;
  1133. +
  1134. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  1135. + sprintf(inp->name, "Camera %u", inp->index);
  1136. + return 0;
  1137. +}
  1138. +
  1139. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  1140. +{
  1141. + *i = 0;
  1142. + return 0;
  1143. +}
  1144. +
  1145. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  1146. +{
  1147. + if (i != 0)
  1148. + return -EINVAL;
  1149. +
  1150. + return 0;
  1151. +}
  1152. +
  1153. +/* capture ioctls */
  1154. +static int vidioc_querycap(struct file *file, void *priv,
  1155. + struct v4l2_capability *cap)
  1156. +{
  1157. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1158. + u32 major;
  1159. + u32 minor;
  1160. +
  1161. + vchiq_mmal_version(dev->instance, &major, &minor);
  1162. +
  1163. + strcpy(cap->driver, "bm2835 mmal");
  1164. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  1165. + major, minor);
  1166. +
  1167. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  1168. + "platform:%s", dev->v4l2_dev.name);
  1169. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  1170. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  1171. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  1172. +
  1173. + return 0;
  1174. +}
  1175. +
  1176. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  1177. + struct v4l2_fmtdesc *f)
  1178. +{
  1179. + struct mmal_fmt *fmt;
  1180. +
  1181. + if (f->index >= ARRAY_SIZE(formats))
  1182. + return -EINVAL;
  1183. +
  1184. + fmt = &formats[f->index];
  1185. +
  1186. + strlcpy(f->description, fmt->name, sizeof(f->description));
  1187. + f->pixelformat = fmt->fourcc;
  1188. + f->flags = fmt->flags;
  1189. +
  1190. + return 0;
  1191. +}
  1192. +
  1193. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  1194. + struct v4l2_format *f)
  1195. +{
  1196. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1197. +
  1198. + f->fmt.pix.width = dev->capture.width;
  1199. + f->fmt.pix.height = dev->capture.height;
  1200. + f->fmt.pix.field = V4L2_FIELD_NONE;
  1201. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  1202. + f->fmt.pix.bytesperline = dev->capture.stride;
  1203. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  1204. +
  1205. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  1206. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  1207. + else if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG)
  1208. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  1209. + else
  1210. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  1211. + f->fmt.pix.priv = 0;
  1212. +
  1213. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  1214. + __func__);
  1215. + return 0;
  1216. +}
  1217. +
  1218. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  1219. + struct v4l2_format *f)
  1220. +{
  1221. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1222. + struct mmal_fmt *mfmt;
  1223. +
  1224. + mfmt = get_format(f);
  1225. + if (!mfmt) {
  1226. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1227. + "Fourcc format (0x%08x) unknown.\n",
  1228. + f->fmt.pix.pixelformat);
  1229. + f->fmt.pix.pixelformat = formats[0].fourcc;
  1230. + mfmt = get_format(f);
  1231. + }
  1232. +
  1233. + f->fmt.pix.field = V4L2_FIELD_NONE;
  1234. +
  1235. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1236. + "Clipping/aligning %dx%d format %08X\n",
  1237. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  1238. +
  1239. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  1240. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  1241. + f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
  1242. +
  1243. + /* Image buffer has to be padded to allow for alignment, even though
  1244. + * we then remove that padding before delivering the buffer.
  1245. + */
  1246. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  1247. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  1248. +
  1249. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  1250. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  1251. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  1252. +
  1253. + if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24)
  1254. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  1255. + else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
  1256. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  1257. + else
  1258. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  1259. + f->fmt.pix.priv = 0;
  1260. +
  1261. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1262. + "Now %dx%d format %08X\n",
  1263. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  1264. +
  1265. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  1266. + __func__);
  1267. + return 0;
  1268. +}
  1269. +
  1270. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  1271. + struct v4l2_format *f)
  1272. +{
  1273. + int ret;
  1274. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  1275. + struct vchiq_mmal_component *encode_component = NULL;
  1276. + struct mmal_fmt *mfmt = get_format(f);
  1277. +
  1278. + BUG_ON(!mfmt);
  1279. +
  1280. + if (dev->capture.encode_component) {
  1281. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1282. + "vid_cap - disconnect previous tunnel\n");
  1283. +
  1284. + /* Disconnect any previous connection */
  1285. + vchiq_mmal_port_connect_tunnel(dev->instance,
  1286. + dev->capture.camera_port, NULL);
  1287. + dev->capture.camera_port = NULL;
  1288. + ret = vchiq_mmal_component_disable(dev->instance,
  1289. + dev->capture.
  1290. + encode_component);
  1291. + if (ret)
  1292. + v4l2_err(&dev->v4l2_dev,
  1293. + "Failed to disable encode component %d\n",
  1294. + ret);
  1295. +
  1296. + dev->capture.encode_component = NULL;
  1297. + }
  1298. + /* format dependant port setup */
  1299. + switch (mfmt->mmal_component) {
  1300. + case MMAL_COMPONENT_CAMERA:
  1301. + /* Make a further decision on port based on resolution */
  1302. + if (f->fmt.pix.width <= max_video_width
  1303. + && f->fmt.pix.height <= max_video_height)
  1304. + camera_port = port =
  1305. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1306. + output[MMAL_CAMERA_PORT_VIDEO];
  1307. + else
  1308. + camera_port = port =
  1309. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1310. + output[MMAL_CAMERA_PORT_CAPTURE];
  1311. + break;
  1312. + case MMAL_COMPONENT_IMAGE_ENCODE:
  1313. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  1314. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  1315. + camera_port =
  1316. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1317. + output[MMAL_CAMERA_PORT_CAPTURE];
  1318. + break;
  1319. + case MMAL_COMPONENT_VIDEO_ENCODE:
  1320. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  1321. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  1322. + camera_port =
  1323. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1324. + output[MMAL_CAMERA_PORT_VIDEO];
  1325. + break;
  1326. + default:
  1327. + break;
  1328. + }
  1329. +
  1330. + if (!port)
  1331. + return -EINVAL;
  1332. +
  1333. + if (encode_component)
  1334. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  1335. + else
  1336. + camera_port->format.encoding = mfmt->mmal;
  1337. +
  1338. + camera_port->format.encoding_variant = 0;
  1339. + camera_port->es.video.width = f->fmt.pix.width;
  1340. + camera_port->es.video.height = f->fmt.pix.height;
  1341. + camera_port->es.video.crop.x = 0;
  1342. + camera_port->es.video.crop.y = 0;
  1343. + camera_port->es.video.crop.width = f->fmt.pix.width;
  1344. + camera_port->es.video.crop.height = f->fmt.pix.height;
  1345. + camera_port->es.video.frame_rate.num = 0;
  1346. + camera_port->es.video.frame_rate.den = 1;
  1347. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  1348. +
  1349. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  1350. +
  1351. + if (!ret
  1352. + && camera_port ==
  1353. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1354. + output[MMAL_CAMERA_PORT_VIDEO]) {
  1355. + bool overlay_enabled =
  1356. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  1357. + struct vchiq_mmal_port *preview_port =
  1358. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1359. + output[MMAL_CAMERA_PORT_PREVIEW];
  1360. + /* Preview and encode ports need to match on resolution */
  1361. + if (overlay_enabled) {
  1362. + /* Need to disable the overlay before we can update
  1363. + * the resolution
  1364. + */
  1365. + ret =
  1366. + vchiq_mmal_port_disable(dev->instance,
  1367. + preview_port);
  1368. + if (!ret)
  1369. + ret =
  1370. + vchiq_mmal_port_connect_tunnel(
  1371. + dev->instance,
  1372. + preview_port,
  1373. + NULL);
  1374. + }
  1375. + preview_port->es.video.width = f->fmt.pix.width;
  1376. + preview_port->es.video.height = f->fmt.pix.height;
  1377. + preview_port->es.video.crop.x = 0;
  1378. + preview_port->es.video.crop.y = 0;
  1379. + preview_port->es.video.crop.width = f->fmt.pix.width;
  1380. + preview_port->es.video.crop.height = f->fmt.pix.height;
  1381. + preview_port->es.video.frame_rate.num =
  1382. + dev->capture.timeperframe.denominator;
  1383. + preview_port->es.video.frame_rate.den =
  1384. + dev->capture.timeperframe.numerator;
  1385. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  1386. + if (overlay_enabled) {
  1387. + ret = vchiq_mmal_port_connect_tunnel(
  1388. + dev->instance,
  1389. + preview_port,
  1390. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  1391. + if (!ret)
  1392. + ret = vchiq_mmal_port_enable(dev->instance,
  1393. + preview_port,
  1394. + NULL);
  1395. + }
  1396. + }
  1397. +
  1398. + if (ret) {
  1399. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1400. + "%s failed to set format %dx%d %08X\n", __func__,
  1401. + f->fmt.pix.width, f->fmt.pix.height,
  1402. + f->fmt.pix.pixelformat);
  1403. + /* ensure capture is not going to be tried */
  1404. + dev->capture.port = NULL;
  1405. + } else {
  1406. + if (encode_component) {
  1407. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1408. + "vid_cap - set up encode comp\n");
  1409. +
  1410. + /* configure buffering */
  1411. + camera_port->current_buffer.size =
  1412. + camera_port->recommended_buffer.size;
  1413. + camera_port->current_buffer.num =
  1414. + camera_port->recommended_buffer.num;
  1415. +
  1416. + ret =
  1417. + vchiq_mmal_port_connect_tunnel(
  1418. + dev->instance,
  1419. + camera_port,
  1420. + &encode_component->input[0]);
  1421. + if (ret) {
  1422. + v4l2_dbg(1, bcm2835_v4l2_debug,
  1423. + &dev->v4l2_dev,
  1424. + "%s failed to create connection\n",
  1425. + __func__);
  1426. + /* ensure capture is not going to be tried */
  1427. + dev->capture.port = NULL;
  1428. + } else {
  1429. + port->es.video.width = f->fmt.pix.width;
  1430. + port->es.video.height = f->fmt.pix.height;
  1431. + port->es.video.crop.x = 0;
  1432. + port->es.video.crop.y = 0;
  1433. + port->es.video.crop.width = f->fmt.pix.width;
  1434. + port->es.video.crop.height = f->fmt.pix.height;
  1435. + port->es.video.frame_rate.num =
  1436. + dev->capture.timeperframe.denominator;
  1437. + port->es.video.frame_rate.den =
  1438. + dev->capture.timeperframe.numerator;
  1439. +
  1440. + port->format.encoding = mfmt->mmal;
  1441. + port->format.encoding_variant = 0;
  1442. + /* Set any encoding specific parameters */
  1443. + switch (mfmt->mmal_component) {
  1444. + case MMAL_COMPONENT_VIDEO_ENCODE:
  1445. + port->format.bitrate =
  1446. + dev->capture.encode_bitrate;
  1447. + break;
  1448. + case MMAL_COMPONENT_IMAGE_ENCODE:
  1449. + /* Could set EXIF parameters here */
  1450. + break;
  1451. + default:
  1452. + break;
  1453. + }
  1454. + ret = vchiq_mmal_port_set_format(dev->instance,
  1455. + port);
  1456. + if (ret)
  1457. + v4l2_dbg(1, bcm2835_v4l2_debug,
  1458. + &dev->v4l2_dev,
  1459. + "%s failed to set format %dx%d fmt %08X\n",
  1460. + __func__,
  1461. + f->fmt.pix.width,
  1462. + f->fmt.pix.height,
  1463. + f->fmt.pix.pixelformat
  1464. + );
  1465. + }
  1466. +
  1467. + if (!ret) {
  1468. + ret = vchiq_mmal_component_enable(
  1469. + dev->instance,
  1470. + encode_component);
  1471. + if (ret) {
  1472. + v4l2_dbg(1, bcm2835_v4l2_debug,
  1473. + &dev->v4l2_dev,
  1474. + "%s Failed to enable encode components\n",
  1475. + __func__);
  1476. + }
  1477. + }
  1478. + if (!ret) {
  1479. + /* configure buffering */
  1480. + port->current_buffer.num = 1;
  1481. + port->current_buffer.size =
  1482. + f->fmt.pix.sizeimage;
  1483. + if (port->format.encoding ==
  1484. + MMAL_ENCODING_JPEG) {
  1485. + v4l2_dbg(1, bcm2835_v4l2_debug,
  1486. + &dev->v4l2_dev,
  1487. + "JPG - buf size now %d was %d\n",
  1488. + f->fmt.pix.sizeimage,
  1489. + port->current_buffer.size);
  1490. + port->current_buffer.size =
  1491. + (f->fmt.pix.sizeimage <
  1492. + (100 << 10))
  1493. + ? (100 << 10) : f->fmt.pix.
  1494. + sizeimage;
  1495. + }
  1496. + v4l2_dbg(1, bcm2835_v4l2_debug,
  1497. + &dev->v4l2_dev,
  1498. + "vid_cap - cur_buf.size set to %d\n",
  1499. + f->fmt.pix.sizeimage);
  1500. + port->current_buffer.alignment = 0;
  1501. + }
  1502. + } else {
  1503. + /* configure buffering */
  1504. + camera_port->current_buffer.num = 1;
  1505. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  1506. + camera_port->current_buffer.alignment = 0;
  1507. + }
  1508. +
  1509. + if (!ret) {
  1510. + dev->capture.fmt = mfmt;
  1511. + dev->capture.stride = f->fmt.pix.bytesperline;
  1512. + dev->capture.width = camera_port->es.video.crop.width;
  1513. + dev->capture.height = camera_port->es.video.crop.height;
  1514. + dev->capture.buffersize = port->current_buffer.size;
  1515. +
  1516. + /* select port for capture */
  1517. + dev->capture.port = port;
  1518. + dev->capture.camera_port = camera_port;
  1519. + dev->capture.encode_component = encode_component;
  1520. + v4l2_dbg(1, bcm2835_v4l2_debug,
  1521. + &dev->v4l2_dev,
  1522. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  1523. + port->format.encoding,
  1524. + dev->capture.width, dev->capture.height,
  1525. + dev->capture.stride, dev->capture.buffersize);
  1526. + }
  1527. + }
  1528. +
  1529. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  1530. + return ret;
  1531. +}
  1532. +
  1533. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  1534. + struct v4l2_format *f)
  1535. +{
  1536. + int ret;
  1537. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1538. + struct mmal_fmt *mfmt;
  1539. +
  1540. + /* try the format to set valid parameters */
  1541. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  1542. + if (ret) {
  1543. + v4l2_err(&dev->v4l2_dev,
  1544. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  1545. + return ret;
  1546. + }
  1547. +
  1548. + /* if a capture is running refuse to set format */
  1549. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  1550. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  1551. + return -EBUSY;
  1552. + }
  1553. +
  1554. + /* If the format is unsupported v4l2 says we should switch to
  1555. + * a supported one and not return an error. */
  1556. + mfmt = get_format(f);
  1557. + if (!mfmt) {
  1558. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1559. + "Fourcc format (0x%08x) unknown.\n",
  1560. + f->fmt.pix.pixelformat);
  1561. + f->fmt.pix.pixelformat = formats[0].fourcc;
  1562. + mfmt = get_format(f);
  1563. + }
  1564. +
  1565. + ret = mmal_setup_components(dev, f);
  1566. + if (ret != 0) {
  1567. + v4l2_err(&dev->v4l2_dev,
  1568. + "%s: failed to setup mmal components: %d\n",
  1569. + __func__, ret);
  1570. + ret = -EINVAL;
  1571. + }
  1572. +
  1573. + return ret;
  1574. +}
  1575. +
  1576. +int vidioc_enum_framesizes(struct file *file, void *fh,
  1577. + struct v4l2_frmsizeenum *fsize)
  1578. +{
  1579. + static const struct v4l2_frmsize_stepwise sizes = {
  1580. + MIN_WIDTH, MAX_WIDTH, 2,
  1581. + MIN_HEIGHT, MAX_HEIGHT, 2
  1582. + };
  1583. + int i;
  1584. +
  1585. + if (fsize->index)
  1586. + return -EINVAL;
  1587. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  1588. + if (formats[i].fourcc == fsize->pixel_format)
  1589. + break;
  1590. + if (i == ARRAY_SIZE(formats))
  1591. + return -EINVAL;
  1592. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  1593. + fsize->stepwise = sizes;
  1594. + return 0;
  1595. +}
  1596. +
  1597. +/* timeperframe is arbitrary and continous */
  1598. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  1599. + struct v4l2_frmivalenum *fival)
  1600. +{
  1601. + int i;
  1602. +
  1603. + if (fival->index)
  1604. + return -EINVAL;
  1605. +
  1606. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  1607. + if (formats[i].fourcc == fival->pixel_format)
  1608. + break;
  1609. + if (i == ARRAY_SIZE(formats))
  1610. + return -EINVAL;
  1611. +
  1612. + /* regarding width & height - we support any within range */
  1613. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  1614. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  1615. + return -EINVAL;
  1616. +
  1617. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  1618. +
  1619. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  1620. + fival->stepwise.min = tpf_min;
  1621. + fival->stepwise.max = tpf_max;
  1622. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  1623. +
  1624. + return 0;
  1625. +}
  1626. +
  1627. +static int vidioc_g_parm(struct file *file, void *priv,
  1628. + struct v4l2_streamparm *parm)
  1629. +{
  1630. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1631. +
  1632. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1633. + return -EINVAL;
  1634. +
  1635. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  1636. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  1637. + parm->parm.capture.readbuffers = 1;
  1638. + return 0;
  1639. +}
  1640. +
  1641. +#define FRACT_CMP(a, OP, b) \
  1642. + ((u64)(a).numerator * (b).denominator OP \
  1643. + (u64)(b).numerator * (a).denominator)
  1644. +
  1645. +static int vidioc_s_parm(struct file *file, void *priv,
  1646. + struct v4l2_streamparm *parm)
  1647. +{
  1648. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  1649. + struct v4l2_fract tpf;
  1650. + struct mmal_parameter_rational fps_param;
  1651. +
  1652. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1653. + return -EINVAL;
  1654. +
  1655. + tpf = parm->parm.capture.timeperframe;
  1656. +
  1657. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  1658. + tpf = tpf.denominator ? tpf : tpf_default;
  1659. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  1660. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  1661. +
  1662. + dev->capture.timeperframe = tpf;
  1663. + parm->parm.capture.timeperframe = tpf;
  1664. + parm->parm.capture.readbuffers = 1;
  1665. +
  1666. + fps_param.num = 0; /* Select variable fps, and then use
  1667. + * FPS_RANGE to select the actual limits.
  1668. + */
  1669. + fps_param.den = 1;
  1670. + set_framerate_params(dev);
  1671. +
  1672. + return 0;
  1673. +}
  1674. +
  1675. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  1676. + /* overlay */
  1677. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  1678. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  1679. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  1680. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  1681. + .vidioc_overlay = vidioc_overlay,
  1682. + .vidioc_g_fbuf = vidioc_g_fbuf,
  1683. +
  1684. + /* inputs */
  1685. + .vidioc_enum_input = vidioc_enum_input,
  1686. + .vidioc_g_input = vidioc_g_input,
  1687. + .vidioc_s_input = vidioc_s_input,
  1688. +
  1689. + /* capture */
  1690. + .vidioc_querycap = vidioc_querycap,
  1691. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1692. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1693. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1694. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1695. +
  1696. + /* buffer management */
  1697. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  1698. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  1699. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  1700. + .vidioc_querybuf = vb2_ioctl_querybuf,
  1701. + .vidioc_qbuf = vb2_ioctl_qbuf,
  1702. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  1703. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  1704. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  1705. + .vidioc_g_parm = vidioc_g_parm,
  1706. + .vidioc_s_parm = vidioc_s_parm,
  1707. + .vidioc_streamon = vb2_ioctl_streamon,
  1708. + .vidioc_streamoff = vb2_ioctl_streamoff,
  1709. +
  1710. + .vidioc_log_status = v4l2_ctrl_log_status,
  1711. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1712. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1713. +};
  1714. +
  1715. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  1716. + /* overlay */
  1717. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  1718. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  1719. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  1720. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  1721. + .vidioc_overlay = vidioc_overlay,
  1722. + .vidioc_g_fbuf = vidioc_g_fbuf,
  1723. +
  1724. + /* inputs */
  1725. + .vidioc_enum_input = vidioc_enum_input,
  1726. + .vidioc_g_input = vidioc_g_input,
  1727. + .vidioc_s_input = vidioc_s_input,
  1728. +
  1729. + /* capture */
  1730. + .vidioc_querycap = vidioc_querycap,
  1731. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1732. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1733. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1734. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1735. +
  1736. + /* buffer management */
  1737. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  1738. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  1739. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  1740. + .vidioc_querybuf = vb2_ioctl_querybuf,
  1741. + .vidioc_qbuf = vb2_ioctl_qbuf,
  1742. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  1743. + /* Remove this function ptr to fix gstreamer bug
  1744. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  1745. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  1746. + .vidioc_g_parm = vidioc_g_parm,
  1747. + .vidioc_s_parm = vidioc_s_parm,
  1748. + .vidioc_streamon = vb2_ioctl_streamon,
  1749. + .vidioc_streamoff = vb2_ioctl_streamoff,
  1750. +
  1751. + .vidioc_log_status = v4l2_ctrl_log_status,
  1752. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1753. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1754. +};
  1755. +
  1756. +/* ------------------------------------------------------------------
  1757. + Driver init/finalise
  1758. + ------------------------------------------------------------------*/
  1759. +
  1760. +static const struct v4l2_file_operations camera0_fops = {
  1761. + .owner = THIS_MODULE,
  1762. + .open = v4l2_fh_open,
  1763. + .release = vb2_fop_release,
  1764. + .read = vb2_fop_read,
  1765. + .poll = vb2_fop_poll,
  1766. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  1767. + .mmap = vb2_fop_mmap,
  1768. +};
  1769. +
  1770. +static struct video_device vdev_template = {
  1771. + .name = "camera0",
  1772. + .fops = &camera0_fops,
  1773. + .ioctl_ops = &camera0_ioctl_ops,
  1774. + .release = video_device_release_empty,
  1775. +};
  1776. +
  1777. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  1778. + struct vchiq_mmal_component *camera)
  1779. +{
  1780. + int ret;
  1781. + struct mmal_parameter_camera_config cam_config = {
  1782. + .max_stills_w = MAX_WIDTH,
  1783. + .max_stills_h = MAX_HEIGHT,
  1784. + .stills_yuv422 = 1,
  1785. + .one_shot_stills = 1,
  1786. + .max_preview_video_w = (max_video_width > 1920) ?
  1787. + max_video_width : 1920,
  1788. + .max_preview_video_h = (max_video_height > 1088) ?
  1789. + max_video_height : 1088,
  1790. + .num_preview_video_frames = 3,
  1791. + .stills_capture_circular_buffer_height = 0,
  1792. + .fast_preview_resume = 0,
  1793. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  1794. + };
  1795. +
  1796. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  1797. + MMAL_PARAMETER_CAMERA_CONFIG,
  1798. + &cam_config, sizeof(cam_config));
  1799. + return ret;
  1800. +}
  1801. +
  1802. +/* MMAL instance and component init */
  1803. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  1804. +{
  1805. + int ret;
  1806. + struct mmal_es_format *format;
  1807. + u32 bool_true = 1;
  1808. +
  1809. + ret = vchiq_mmal_init(&dev->instance);
  1810. + if (ret < 0)
  1811. + return ret;
  1812. +
  1813. + /* get the camera component ready */
  1814. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  1815. + &dev->component[MMAL_COMPONENT_CAMERA]);
  1816. + if (ret < 0)
  1817. + goto unreg_mmal;
  1818. +
  1819. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  1820. + MMAL_CAMERA_PORT_COUNT) {
  1821. + ret = -EINVAL;
  1822. + goto unreg_camera;
  1823. + }
  1824. +
  1825. + ret = set_camera_parameters(dev->instance,
  1826. + dev->component[MMAL_COMPONENT_CAMERA]);
  1827. + if (ret < 0)
  1828. + goto unreg_camera;
  1829. +
  1830. + format =
  1831. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1832. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  1833. +
  1834. + format->encoding = MMAL_ENCODING_OPAQUE;
  1835. + format->encoding_variant = MMAL_ENCODING_I420;
  1836. +
  1837. + format->es->video.width = 1024;
  1838. + format->es->video.height = 768;
  1839. + format->es->video.crop.x = 0;
  1840. + format->es->video.crop.y = 0;
  1841. + format->es->video.crop.width = 1024;
  1842. + format->es->video.crop.height = 768;
  1843. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  1844. + format->es->video.frame_rate.den = 1;
  1845. +
  1846. + format =
  1847. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1848. + output[MMAL_CAMERA_PORT_VIDEO].format;
  1849. +
  1850. + format->encoding = MMAL_ENCODING_OPAQUE;
  1851. + format->encoding_variant = MMAL_ENCODING_I420;
  1852. +
  1853. + format->es->video.width = 1024;
  1854. + format->es->video.height = 768;
  1855. + format->es->video.crop.x = 0;
  1856. + format->es->video.crop.y = 0;
  1857. + format->es->video.crop.width = 1024;
  1858. + format->es->video.crop.height = 768;
  1859. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  1860. + format->es->video.frame_rate.den = 1;
  1861. +
  1862. + vchiq_mmal_port_parameter_set(dev->instance,
  1863. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1864. + output[MMAL_CAMERA_PORT_VIDEO],
  1865. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  1866. + &bool_true, sizeof(bool_true));
  1867. +
  1868. + format =
  1869. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1870. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  1871. +
  1872. + format->encoding = MMAL_ENCODING_OPAQUE;
  1873. +
  1874. + format->es->video.width = 2592;
  1875. + format->es->video.height = 1944;
  1876. + format->es->video.crop.x = 0;
  1877. + format->es->video.crop.y = 0;
  1878. + format->es->video.crop.width = 2592;
  1879. + format->es->video.crop.height = 1944;
  1880. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  1881. + format->es->video.frame_rate.den = 1;
  1882. +
  1883. + dev->capture.width = format->es->video.width;
  1884. + dev->capture.height = format->es->video.height;
  1885. + dev->capture.fmt = &formats[0];
  1886. + dev->capture.encode_component = NULL;
  1887. + dev->capture.timeperframe = tpf_default;
  1888. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  1889. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  1890. +
  1891. + vchiq_mmal_port_parameter_set(dev->instance,
  1892. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1893. + output[MMAL_CAMERA_PORT_CAPTURE],
  1894. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  1895. + &bool_true, sizeof(bool_true));
  1896. +
  1897. + /* get the preview component ready */
  1898. + ret = vchiq_mmal_component_init(
  1899. + dev->instance, "ril.video_render",
  1900. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  1901. + if (ret < 0)
  1902. + goto unreg_camera;
  1903. +
  1904. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  1905. + ret = -EINVAL;
  1906. + pr_debug("too few input ports %d needed %d\n",
  1907. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  1908. + goto unreg_preview;
  1909. + }
  1910. +
  1911. + /* get the image encoder component ready */
  1912. + ret = vchiq_mmal_component_init(
  1913. + dev->instance, "ril.image_encode",
  1914. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  1915. + if (ret < 0)
  1916. + goto unreg_preview;
  1917. +
  1918. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  1919. + ret = -EINVAL;
  1920. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  1921. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  1922. + 1);
  1923. + goto unreg_image_encoder;
  1924. + }
  1925. +
  1926. + /* get the video encoder component ready */
  1927. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  1928. + &dev->
  1929. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  1930. + if (ret < 0)
  1931. + goto unreg_image_encoder;
  1932. +
  1933. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  1934. + ret = -EINVAL;
  1935. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  1936. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  1937. + 1);
  1938. + goto unreg_vid_encoder;
  1939. + }
  1940. +
  1941. + {
  1942. + struct vchiq_mmal_port *encoder_port =
  1943. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  1944. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  1945. + ret = vchiq_mmal_port_set_format(dev->instance,
  1946. + encoder_port);
  1947. + }
  1948. +
  1949. + {
  1950. + unsigned int enable = 1;
  1951. + vchiq_mmal_port_parameter_set(
  1952. + dev->instance,
  1953. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  1954. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  1955. + &enable, sizeof(enable));
  1956. +
  1957. + vchiq_mmal_port_parameter_set(dev->instance,
  1958. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  1959. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  1960. + &enable,
  1961. + sizeof(enable));
  1962. + }
  1963. + ret = bm2835_mmal_set_all_camera_controls(dev);
  1964. + if (ret < 0)
  1965. + goto unreg_vid_encoder;
  1966. +
  1967. + return 0;
  1968. +
  1969. +unreg_vid_encoder:
  1970. + pr_err("Cleanup: Destroy video encoder\n");
  1971. + vchiq_mmal_component_finalise(
  1972. + dev->instance,
  1973. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  1974. +
  1975. +unreg_image_encoder:
  1976. + pr_err("Cleanup: Destroy image encoder\n");
  1977. + vchiq_mmal_component_finalise(
  1978. + dev->instance,
  1979. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  1980. +
  1981. +unreg_preview:
  1982. + pr_err("Cleanup: Destroy video render\n");
  1983. + vchiq_mmal_component_finalise(dev->instance,
  1984. + dev->component[MMAL_COMPONENT_PREVIEW]);
  1985. +
  1986. +unreg_camera:
  1987. + pr_err("Cleanup: Destroy camera\n");
  1988. + vchiq_mmal_component_finalise(dev->instance,
  1989. + dev->component[MMAL_COMPONENT_CAMERA]);
  1990. +
  1991. +unreg_mmal:
  1992. + vchiq_mmal_finalise(dev->instance);
  1993. + return ret;
  1994. +}
  1995. +
  1996. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  1997. + struct video_device *vfd)
  1998. +{
  1999. + int ret;
  2000. +
  2001. + *vfd = vdev_template;
  2002. + if (gst_v4l2src_is_broken) {
  2003. + v4l2_info(&dev->v4l2_dev,
  2004. + "Work-around for gstreamer issue is active.\n");
  2005. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  2006. + }
  2007. +
  2008. + vfd->v4l2_dev = &dev->v4l2_dev;
  2009. +
  2010. + vfd->lock = &dev->mutex;
  2011. +
  2012. + vfd->queue = &dev->capture.vb_vidq;
  2013. +
  2014. + /* video device needs to be able to access instance data */
  2015. + video_set_drvdata(vfd, dev);
  2016. +
  2017. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  2018. + if (ret < 0)
  2019. + return ret;
  2020. +
  2021. + v4l2_info(vfd->v4l2_dev,
  2022. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  2023. + video_device_node_name(vfd), max_video_width, max_video_height);
  2024. +
  2025. + return 0;
  2026. +}
  2027. +
  2028. +static struct v4l2_format default_v4l2_format = {
  2029. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  2030. + .fmt.pix.width = 1024,
  2031. + .fmt.pix.bytesperline = 1024,
  2032. + .fmt.pix.height = 768,
  2033. + .fmt.pix.sizeimage = 1024*768,
  2034. +};
  2035. +
  2036. +static int __init bm2835_mmal_init(void)
  2037. +{
  2038. + int ret;
  2039. + struct bm2835_mmal_dev *dev;
  2040. + struct vb2_queue *q;
  2041. +
  2042. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  2043. + if (!dev)
  2044. + return -ENOMEM;
  2045. +
  2046. + /* setup device defaults */
  2047. + dev->overlay.w.left = 150;
  2048. + dev->overlay.w.top = 50;
  2049. + dev->overlay.w.width = 1024;
  2050. + dev->overlay.w.height = 768;
  2051. + dev->overlay.clipcount = 0;
  2052. + dev->overlay.field = V4L2_FIELD_NONE;
  2053. +
  2054. + dev->capture.fmt = &formats[3]; /* JPEG */
  2055. +
  2056. + /* v4l device registration */
  2057. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  2058. + "%s", BM2835_MMAL_MODULE_NAME);
  2059. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  2060. + if (ret)
  2061. + goto free_dev;
  2062. +
  2063. + /* setup v4l controls */
  2064. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  2065. + if (ret < 0)
  2066. + goto unreg_dev;
  2067. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  2068. +
  2069. + /* mmal init */
  2070. + ret = mmal_init(dev);
  2071. + if (ret < 0)
  2072. + goto unreg_dev;
  2073. +
  2074. + /* initialize queue */
  2075. + q = &dev->capture.vb_vidq;
  2076. + memset(q, 0, sizeof(*q));
  2077. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  2078. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  2079. + q->drv_priv = dev;
  2080. + q->buf_struct_size = sizeof(struct mmal_buffer);
  2081. + q->ops = &bm2835_mmal_video_qops;
  2082. + q->mem_ops = &vb2_vmalloc_memops;
  2083. + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  2084. + ret = vb2_queue_init(q);
  2085. + if (ret < 0)
  2086. + goto unreg_dev;
  2087. +
  2088. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  2089. + mutex_init(&dev->mutex);
  2090. +
  2091. + /* initialise video devices */
  2092. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  2093. + if (ret < 0)
  2094. + goto unreg_dev;
  2095. +
  2096. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  2097. + * format, but currently the APIs don't join up.
  2098. + */
  2099. + ret = mmal_setup_components(dev, &default_v4l2_format);
  2100. + if (ret < 0) {
  2101. + v4l2_err(&dev->v4l2_dev,
  2102. + "%s: could not setup components\n", __func__);
  2103. + goto unreg_dev;
  2104. + }
  2105. +
  2106. + v4l2_info(&dev->v4l2_dev,
  2107. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  2108. + BM2835_MMAL_VERSION);
  2109. +
  2110. + gdev = dev;
  2111. + return 0;
  2112. +
  2113. +unreg_dev:
  2114. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  2115. + v4l2_device_unregister(&dev->v4l2_dev);
  2116. +
  2117. +free_dev:
  2118. + kfree(dev);
  2119. +
  2120. + v4l2_err(&dev->v4l2_dev,
  2121. + "%s: error %d while loading driver\n",
  2122. + BM2835_MMAL_MODULE_NAME, ret);
  2123. +
  2124. + return ret;
  2125. +}
  2126. +
  2127. +static void __exit bm2835_mmal_exit(void)
  2128. +{
  2129. + if (!gdev)
  2130. + return;
  2131. +
  2132. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  2133. + video_device_node_name(&gdev->vdev));
  2134. +
  2135. + video_unregister_device(&gdev->vdev);
  2136. +
  2137. + if (gdev->capture.encode_component) {
  2138. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  2139. + "mmal_exit - disconnect tunnel\n");
  2140. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  2141. + gdev->capture.camera_port, NULL);
  2142. + vchiq_mmal_component_disable(gdev->instance,
  2143. + gdev->capture.encode_component);
  2144. + }
  2145. + vchiq_mmal_component_disable(gdev->instance,
  2146. + gdev->component[MMAL_COMPONENT_CAMERA]);
  2147. +
  2148. + vchiq_mmal_component_finalise(gdev->instance,
  2149. + gdev->
  2150. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  2151. +
  2152. + vchiq_mmal_component_finalise(gdev->instance,
  2153. + gdev->
  2154. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  2155. +
  2156. + vchiq_mmal_component_finalise(gdev->instance,
  2157. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  2158. +
  2159. + vchiq_mmal_component_finalise(gdev->instance,
  2160. + gdev->component[MMAL_COMPONENT_CAMERA]);
  2161. +
  2162. + vchiq_mmal_finalise(gdev->instance);
  2163. +
  2164. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  2165. +
  2166. + v4l2_device_unregister(&gdev->v4l2_dev);
  2167. +
  2168. + kfree(gdev);
  2169. +}
  2170. +
  2171. +module_init(bm2835_mmal_init);
  2172. +module_exit(bm2835_mmal_exit);
  2173. --- /dev/null
  2174. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
  2175. @@ -0,0 +1,126 @@
  2176. +/*
  2177. + * Broadcom BM2835 V4L2 driver
  2178. + *
  2179. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  2180. + *
  2181. + * This file is subject to the terms and conditions of the GNU General Public
  2182. + * License. See the file COPYING in the main directory of this archive
  2183. + * for more details.
  2184. + *
  2185. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  2186. + * Dave Stevenson <dsteve@broadcom.com>
  2187. + * Simon Mellor <simellor@broadcom.com>
  2188. + * Luke Diamand <luked@broadcom.com>
  2189. + *
  2190. + * core driver device
  2191. + */
  2192. +
  2193. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  2194. +
  2195. +enum {
  2196. + MMAL_COMPONENT_CAMERA = 0,
  2197. + MMAL_COMPONENT_PREVIEW,
  2198. + MMAL_COMPONENT_IMAGE_ENCODE,
  2199. + MMAL_COMPONENT_VIDEO_ENCODE,
  2200. + MMAL_COMPONENT_COUNT
  2201. +};
  2202. +
  2203. +enum {
  2204. + MMAL_CAMERA_PORT_PREVIEW = 0,
  2205. + MMAL_CAMERA_PORT_VIDEO,
  2206. + MMAL_CAMERA_PORT_CAPTURE,
  2207. + MMAL_CAMERA_PORT_COUNT
  2208. +};
  2209. +
  2210. +#define PREVIEW_LAYER 2
  2211. +
  2212. +extern int bcm2835_v4l2_debug;
  2213. +
  2214. +struct bm2835_mmal_dev {
  2215. + /* v4l2 devices */
  2216. + struct v4l2_device v4l2_dev;
  2217. + struct video_device vdev;
  2218. + struct mutex mutex;
  2219. +
  2220. + /* controls */
  2221. + struct v4l2_ctrl_handler ctrl_handler;
  2222. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  2223. + enum v4l2_scene_mode scene_mode;
  2224. + struct mmal_colourfx colourfx;
  2225. + int hflip;
  2226. + int vflip;
  2227. + int red_gain;
  2228. + int blue_gain;
  2229. + enum mmal_parameter_exposuremode exposure_mode_user;
  2230. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  2231. + /* active exposure mode may differ if selected via a scene mode */
  2232. + enum mmal_parameter_exposuremode exposure_mode_active;
  2233. + enum mmal_parameter_exposuremeteringmode metering_mode;
  2234. + unsigned int manual_shutter_speed;
  2235. + bool exp_auto_priority;
  2236. +
  2237. + /* allocated mmal instance and components */
  2238. + struct vchiq_mmal_instance *instance;
  2239. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  2240. + int camera_use_count;
  2241. +
  2242. + struct v4l2_window overlay;
  2243. +
  2244. + struct {
  2245. + unsigned int width; /* width */
  2246. + unsigned int height; /* height */
  2247. + unsigned int stride; /* stride */
  2248. + unsigned int buffersize; /* buffer size with padding */
  2249. + struct mmal_fmt *fmt;
  2250. + struct v4l2_fract timeperframe;
  2251. +
  2252. + /* H264 encode bitrate */
  2253. + int encode_bitrate;
  2254. + /* H264 bitrate mode. CBR/VBR */
  2255. + int encode_bitrate_mode;
  2256. + /* H264 profile */
  2257. + enum v4l2_mpeg_video_h264_profile enc_profile;
  2258. + /* H264 level */
  2259. + enum v4l2_mpeg_video_h264_level enc_level;
  2260. + /* JPEG Q-factor */
  2261. + int q_factor;
  2262. +
  2263. + struct vb2_queue vb_vidq;
  2264. +
  2265. + /* VC start timestamp for streaming */
  2266. + s64 vc_start_timestamp;
  2267. + /* Kernel start timestamp for streaming */
  2268. + struct timeval kernel_start_ts;
  2269. +
  2270. + struct vchiq_mmal_port *port; /* port being used for capture */
  2271. + /* camera port being used for capture */
  2272. + struct vchiq_mmal_port *camera_port;
  2273. + /* component being used for encode */
  2274. + struct vchiq_mmal_component *encode_component;
  2275. + /* number of frames remaining which driver should capture */
  2276. + unsigned int frame_count;
  2277. + /* last frame completion */
  2278. + struct completion frame_cmplt;
  2279. +
  2280. + } capture;
  2281. +
  2282. +};
  2283. +
  2284. +int bm2835_mmal_init_controls(
  2285. + struct bm2835_mmal_dev *dev,
  2286. + struct v4l2_ctrl_handler *hdl);
  2287. +
  2288. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  2289. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  2290. +
  2291. +/* Debug helpers */
  2292. +
  2293. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  2294. +{ \
  2295. + v4l2_dbg(level, debug, dev, \
  2296. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  2297. + desc == NULL ? "" : desc, \
  2298. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  2299. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  2300. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  2301. +}
  2302. --- /dev/null
  2303. +++ b/drivers/media/platform/bcm2835/controls.c
  2304. @@ -0,0 +1,1324 @@
  2305. +/*
  2306. + * Broadcom BM2835 V4L2 driver
  2307. + *
  2308. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  2309. + *
  2310. + * This file is subject to the terms and conditions of the GNU General Public
  2311. + * License. See the file COPYING in the main directory of this archive
  2312. + * for more details.
  2313. + *
  2314. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  2315. + * Dave Stevenson <dsteve@broadcom.com>
  2316. + * Simon Mellor <simellor@broadcom.com>
  2317. + * Luke Diamand <luked@broadcom.com>
  2318. + */
  2319. +
  2320. +#include <linux/errno.h>
  2321. +#include <linux/kernel.h>
  2322. +#include <linux/module.h>
  2323. +#include <linux/slab.h>
  2324. +#include <media/videobuf2-vmalloc.h>
  2325. +#include <media/v4l2-device.h>
  2326. +#include <media/v4l2-ioctl.h>
  2327. +#include <media/v4l2-ctrls.h>
  2328. +#include <media/v4l2-fh.h>
  2329. +#include <media/v4l2-event.h>
  2330. +#include <media/v4l2-common.h>
  2331. +
  2332. +#include "mmal-common.h"
  2333. +#include "mmal-vchiq.h"
  2334. +#include "mmal-parameters.h"
  2335. +#include "bcm2835-camera.h"
  2336. +
  2337. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  2338. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  2339. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  2340. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  2341. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  2342. + * -4 to +4
  2343. + */
  2344. +static const s64 ev_bias_qmenu[] = {
  2345. + -4000, -3667, -3333,
  2346. + -3000, -2667, -2333,
  2347. + -2000, -1667, -1333,
  2348. + -1000, -667, -333,
  2349. + 0, 333, 667,
  2350. + 1000, 1333, 1667,
  2351. + 2000, 2333, 2667,
  2352. + 3000, 3333, 3667,
  2353. + 4000
  2354. +};
  2355. +
  2356. +/* Supported ISO values
  2357. + * ISOO = auto ISO
  2358. + */
  2359. +static const s64 iso_qmenu[] = {
  2360. + 0, 100, 200, 400, 800,
  2361. +};
  2362. +
  2363. +static const s64 mains_freq_qmenu[] = {
  2364. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  2365. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  2366. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  2367. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  2368. +};
  2369. +
  2370. +/* Supported video encode modes */
  2371. +static const s64 bitrate_mode_qmenu[] = {
  2372. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  2373. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  2374. +};
  2375. +
  2376. +enum bm2835_mmal_ctrl_type {
  2377. + MMAL_CONTROL_TYPE_STD,
  2378. + MMAL_CONTROL_TYPE_STD_MENU,
  2379. + MMAL_CONTROL_TYPE_INT_MENU,
  2380. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  2381. +};
  2382. +
  2383. +struct bm2835_mmal_v4l2_ctrl;
  2384. +
  2385. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  2386. + struct bm2835_mmal_dev *dev,
  2387. + struct v4l2_ctrl *ctrl,
  2388. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  2389. +
  2390. +struct bm2835_mmal_v4l2_ctrl {
  2391. + u32 id; /* v4l2 control identifier */
  2392. + enum bm2835_mmal_ctrl_type type;
  2393. + /* control minimum value or
  2394. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  2395. + s32 min;
  2396. + s32 max; /* maximum value of control */
  2397. + s32 def; /* default value of control */
  2398. + s32 step; /* step size of the control */
  2399. + const s64 *imenu; /* integer menu array */
  2400. + u32 mmal_id; /* mmal parameter id */
  2401. + bm2835_mmal_v4l2_ctrl_cb *setter;
  2402. + bool ignore_errors;
  2403. +};
  2404. +
  2405. +struct v4l2_to_mmal_effects_setting {
  2406. + u32 v4l2_effect;
  2407. + u32 mmal_effect;
  2408. + s32 col_fx_enable;
  2409. + s32 col_fx_fixed_cbcr;
  2410. + u32 u;
  2411. + u32 v;
  2412. + u32 num_effect_params;
  2413. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  2414. +};
  2415. +
  2416. +static const struct v4l2_to_mmal_effects_setting
  2417. + v4l2_to_mmal_effects_values[] = {
  2418. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  2419. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2420. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  2421. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  2422. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  2423. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  2424. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  2425. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2426. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  2427. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2428. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  2429. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2430. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  2431. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2432. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  2433. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2434. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  2435. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2436. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  2437. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2438. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  2439. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  2440. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  2441. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2442. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  2443. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  2444. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  2445. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  2446. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  2447. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  2448. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  2449. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  2450. +};
  2451. +
  2452. +struct v4l2_mmal_scene_config {
  2453. + enum v4l2_scene_mode v4l2_scene;
  2454. + enum mmal_parameter_exposuremode exposure_mode;
  2455. + enum mmal_parameter_exposuremeteringmode metering_mode;
  2456. +};
  2457. +
  2458. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  2459. + /* V4L2_SCENE_MODE_NONE automatically added */
  2460. + {
  2461. + V4L2_SCENE_MODE_NIGHT,
  2462. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  2463. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  2464. + },
  2465. + {
  2466. + V4L2_SCENE_MODE_SPORTS,
  2467. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  2468. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  2469. + },
  2470. +};
  2471. +
  2472. +/* control handlers*/
  2473. +
  2474. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  2475. + struct v4l2_ctrl *ctrl,
  2476. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2477. +{
  2478. + struct mmal_parameter_rational rational_value;
  2479. + struct vchiq_mmal_port *control;
  2480. +
  2481. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2482. +
  2483. + rational_value.num = ctrl->val;
  2484. + rational_value.den = 100;
  2485. +
  2486. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2487. + mmal_ctrl->mmal_id,
  2488. + &rational_value,
  2489. + sizeof(rational_value));
  2490. +}
  2491. +
  2492. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  2493. + struct v4l2_ctrl *ctrl,
  2494. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2495. +{
  2496. + u32 u32_value;
  2497. + struct vchiq_mmal_port *control;
  2498. +
  2499. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2500. +
  2501. + u32_value = ctrl->val;
  2502. +
  2503. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2504. + mmal_ctrl->mmal_id,
  2505. + &u32_value, sizeof(u32_value));
  2506. +}
  2507. +
  2508. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  2509. + struct v4l2_ctrl *ctrl,
  2510. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2511. +{
  2512. + u32 u32_value;
  2513. + struct vchiq_mmal_port *control;
  2514. +
  2515. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  2516. + return 1;
  2517. +
  2518. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2519. +
  2520. + u32_value = mmal_ctrl->imenu[ctrl->val];
  2521. +
  2522. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2523. + mmal_ctrl->mmal_id,
  2524. + &u32_value, sizeof(u32_value));
  2525. +}
  2526. +
  2527. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  2528. + struct v4l2_ctrl *ctrl,
  2529. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2530. +{
  2531. + s32 s32_value;
  2532. + struct vchiq_mmal_port *control;
  2533. +
  2534. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2535. +
  2536. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  2537. +
  2538. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2539. + mmal_ctrl->mmal_id,
  2540. + &s32_value, sizeof(s32_value));
  2541. +}
  2542. +
  2543. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  2544. + struct v4l2_ctrl *ctrl,
  2545. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2546. +{
  2547. + int ret;
  2548. + u32 u32_value;
  2549. + struct vchiq_mmal_component *camera;
  2550. +
  2551. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  2552. +
  2553. + u32_value = ((ctrl->val % 360) / 90) * 90;
  2554. +
  2555. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  2556. + mmal_ctrl->mmal_id,
  2557. + &u32_value, sizeof(u32_value));
  2558. + if (ret < 0)
  2559. + return ret;
  2560. +
  2561. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  2562. + mmal_ctrl->mmal_id,
  2563. + &u32_value, sizeof(u32_value));
  2564. + if (ret < 0)
  2565. + return ret;
  2566. +
  2567. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  2568. + mmal_ctrl->mmal_id,
  2569. + &u32_value, sizeof(u32_value));
  2570. +
  2571. + return ret;
  2572. +}
  2573. +
  2574. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  2575. + struct v4l2_ctrl *ctrl,
  2576. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2577. +{
  2578. + int ret;
  2579. + u32 u32_value;
  2580. + struct vchiq_mmal_component *camera;
  2581. +
  2582. + if (ctrl->id == V4L2_CID_HFLIP)
  2583. + dev->hflip = ctrl->val;
  2584. + else
  2585. + dev->vflip = ctrl->val;
  2586. +
  2587. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  2588. +
  2589. + if (dev->hflip && dev->vflip)
  2590. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  2591. + else if (dev->hflip)
  2592. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  2593. + else if (dev->vflip)
  2594. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  2595. + else
  2596. + u32_value = MMAL_PARAM_MIRROR_NONE;
  2597. +
  2598. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  2599. + mmal_ctrl->mmal_id,
  2600. + &u32_value, sizeof(u32_value));
  2601. + if (ret < 0)
  2602. + return ret;
  2603. +
  2604. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  2605. + mmal_ctrl->mmal_id,
  2606. + &u32_value, sizeof(u32_value));
  2607. + if (ret < 0)
  2608. + return ret;
  2609. +
  2610. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  2611. + mmal_ctrl->mmal_id,
  2612. + &u32_value, sizeof(u32_value));
  2613. +
  2614. + return ret;
  2615. +
  2616. +}
  2617. +
  2618. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  2619. + struct v4l2_ctrl *ctrl,
  2620. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2621. +{
  2622. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  2623. + u32 shutter_speed = 0;
  2624. + struct vchiq_mmal_port *control;
  2625. + int ret = 0;
  2626. +
  2627. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2628. +
  2629. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  2630. + /* V4L2 is in 100usec increments.
  2631. + * MMAL is 1usec.
  2632. + */
  2633. + dev->manual_shutter_speed = ctrl->val * 100;
  2634. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  2635. + switch (ctrl->val) {
  2636. + case V4L2_EXPOSURE_AUTO:
  2637. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  2638. + break;
  2639. +
  2640. + case V4L2_EXPOSURE_MANUAL:
  2641. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  2642. + break;
  2643. + }
  2644. + dev->exposure_mode_user = exp_mode;
  2645. + dev->exposure_mode_v4l2_user = ctrl->val;
  2646. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  2647. + dev->exp_auto_priority = ctrl->val;
  2648. + }
  2649. +
  2650. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  2651. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  2652. + shutter_speed = dev->manual_shutter_speed;
  2653. +
  2654. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  2655. + control,
  2656. + MMAL_PARAMETER_SHUTTER_SPEED,
  2657. + &shutter_speed,
  2658. + sizeof(shutter_speed));
  2659. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  2660. + control,
  2661. + MMAL_PARAMETER_EXPOSURE_MODE,
  2662. + &exp_mode,
  2663. + sizeof(u32));
  2664. + dev->exposure_mode_active = exp_mode;
  2665. + }
  2666. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  2667. + * always apply irrespective of scene mode.
  2668. + */
  2669. + ret += set_framerate_params(dev);
  2670. +
  2671. + return ret;
  2672. +}
  2673. +
  2674. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  2675. + struct v4l2_ctrl *ctrl,
  2676. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2677. +{
  2678. + switch (ctrl->val) {
  2679. + case V4L2_EXPOSURE_METERING_AVERAGE:
  2680. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  2681. + break;
  2682. +
  2683. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  2684. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  2685. + break;
  2686. +
  2687. + case V4L2_EXPOSURE_METERING_SPOT:
  2688. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  2689. + break;
  2690. +
  2691. + /* todo matrix weighting not added to Linux API till 3.9
  2692. + case V4L2_EXPOSURE_METERING_MATRIX:
  2693. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  2694. + break;
  2695. + */
  2696. +
  2697. + }
  2698. +
  2699. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  2700. + struct vchiq_mmal_port *control;
  2701. + u32 u32_value = dev->metering_mode;
  2702. +
  2703. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2704. +
  2705. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2706. + mmal_ctrl->mmal_id,
  2707. + &u32_value, sizeof(u32_value));
  2708. + } else
  2709. + return 0;
  2710. +}
  2711. +
  2712. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  2713. + struct v4l2_ctrl *ctrl,
  2714. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2715. +{
  2716. + u32 u32_value;
  2717. + struct vchiq_mmal_port *control;
  2718. +
  2719. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2720. +
  2721. + switch (ctrl->val) {
  2722. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  2723. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  2724. + break;
  2725. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  2726. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  2727. + break;
  2728. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  2729. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  2730. + break;
  2731. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  2732. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  2733. + break;
  2734. + }
  2735. +
  2736. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2737. + mmal_ctrl->mmal_id,
  2738. + &u32_value, sizeof(u32_value));
  2739. +}
  2740. +
  2741. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  2742. + struct v4l2_ctrl *ctrl,
  2743. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2744. +{
  2745. + u32 u32_value;
  2746. + struct vchiq_mmal_port *control;
  2747. +
  2748. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2749. +
  2750. + switch (ctrl->val) {
  2751. + case V4L2_WHITE_BALANCE_MANUAL:
  2752. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  2753. + break;
  2754. +
  2755. + case V4L2_WHITE_BALANCE_AUTO:
  2756. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  2757. + break;
  2758. +
  2759. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  2760. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  2761. + break;
  2762. +
  2763. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  2764. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  2765. + break;
  2766. +
  2767. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  2768. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  2769. + break;
  2770. +
  2771. + case V4L2_WHITE_BALANCE_HORIZON:
  2772. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  2773. + break;
  2774. +
  2775. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  2776. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  2777. + break;
  2778. +
  2779. + case V4L2_WHITE_BALANCE_FLASH:
  2780. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  2781. + break;
  2782. +
  2783. + case V4L2_WHITE_BALANCE_CLOUDY:
  2784. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  2785. + break;
  2786. +
  2787. + case V4L2_WHITE_BALANCE_SHADE:
  2788. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  2789. + break;
  2790. +
  2791. + }
  2792. +
  2793. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2794. + mmal_ctrl->mmal_id,
  2795. + &u32_value, sizeof(u32_value));
  2796. +}
  2797. +
  2798. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  2799. + struct v4l2_ctrl *ctrl,
  2800. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2801. +{
  2802. + struct vchiq_mmal_port *control;
  2803. + struct mmal_parameter_awbgains gains;
  2804. +
  2805. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2806. +
  2807. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  2808. + dev->red_gain = ctrl->val;
  2809. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  2810. + dev->blue_gain = ctrl->val;
  2811. +
  2812. + gains.r_gain.num = dev->red_gain;
  2813. + gains.b_gain.num = dev->blue_gain;
  2814. + gains.r_gain.den = gains.b_gain.den = 1000;
  2815. +
  2816. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  2817. + mmal_ctrl->mmal_id,
  2818. + &gains, sizeof(gains));
  2819. +}
  2820. +
  2821. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  2822. + struct v4l2_ctrl *ctrl,
  2823. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2824. +{
  2825. + int ret = -EINVAL;
  2826. + int i, j;
  2827. + struct vchiq_mmal_port *control;
  2828. + struct mmal_parameter_imagefx_parameters imagefx;
  2829. +
  2830. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  2831. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  2832. +
  2833. + imagefx.effect =
  2834. + v4l2_to_mmal_effects_values[i].mmal_effect;
  2835. + imagefx.num_effect_params =
  2836. + v4l2_to_mmal_effects_values[i].num_effect_params;
  2837. +
  2838. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  2839. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  2840. +
  2841. + for (j = 0; j < imagefx.num_effect_params; j++)
  2842. + imagefx.effect_parameter[j] =
  2843. + v4l2_to_mmal_effects_values[i].effect_params[j];
  2844. +
  2845. + dev->colourfx.enable =
  2846. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  2847. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  2848. + dev->colourfx.u =
  2849. + v4l2_to_mmal_effects_values[i].u;
  2850. + dev->colourfx.v =
  2851. + v4l2_to_mmal_effects_values[i].v;
  2852. + }
  2853. +
  2854. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2855. +
  2856. + ret = vchiq_mmal_port_parameter_set(
  2857. + dev->instance, control,
  2858. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  2859. + &imagefx, sizeof(imagefx));
  2860. + if (ret)
  2861. + goto exit;
  2862. +
  2863. + ret = vchiq_mmal_port_parameter_set(
  2864. + dev->instance, control,
  2865. + MMAL_PARAMETER_COLOUR_EFFECT,
  2866. + &dev->colourfx, sizeof(dev->colourfx));
  2867. + }
  2868. + }
  2869. +
  2870. +exit:
  2871. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  2872. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  2873. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  2874. + dev->colourfx.enable ? "true" : "false",
  2875. + dev->colourfx.u, dev->colourfx.v,
  2876. + ret, (ret == 0 ? 0 : -EINVAL));
  2877. + return (ret == 0 ? 0 : EINVAL);
  2878. +}
  2879. +
  2880. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  2881. + struct v4l2_ctrl *ctrl,
  2882. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2883. +{
  2884. + int ret = -EINVAL;
  2885. + struct vchiq_mmal_port *control;
  2886. +
  2887. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  2888. +
  2889. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  2890. + dev->colourfx.enable = ctrl->val & 0xff;
  2891. +
  2892. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  2893. + MMAL_PARAMETER_COLOUR_EFFECT,
  2894. + &dev->colourfx, sizeof(dev->colourfx));
  2895. +
  2896. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  2897. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  2898. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  2899. + (ret == 0 ? 0 : -EINVAL));
  2900. + return (ret == 0 ? 0 : EINVAL);
  2901. +}
  2902. +
  2903. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  2904. + struct v4l2_ctrl *ctrl,
  2905. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2906. +{
  2907. + int ret;
  2908. + struct vchiq_mmal_port *encoder_out;
  2909. +
  2910. + dev->capture.encode_bitrate = ctrl->val;
  2911. +
  2912. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  2913. +
  2914. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  2915. + mmal_ctrl->mmal_id,
  2916. + &ctrl->val, sizeof(ctrl->val));
  2917. + ret = 0;
  2918. + return ret;
  2919. +}
  2920. +
  2921. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  2922. + struct v4l2_ctrl *ctrl,
  2923. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2924. +{
  2925. + u32 bitrate_mode;
  2926. + struct vchiq_mmal_port *encoder_out;
  2927. +
  2928. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  2929. +
  2930. + dev->capture.encode_bitrate_mode = ctrl->val;
  2931. + switch (ctrl->val) {
  2932. + default:
  2933. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  2934. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  2935. + break;
  2936. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  2937. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  2938. + break;
  2939. + }
  2940. +
  2941. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  2942. + mmal_ctrl->mmal_id,
  2943. + &bitrate_mode,
  2944. + sizeof(bitrate_mode));
  2945. + return 0;
  2946. +}
  2947. +
  2948. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  2949. + struct v4l2_ctrl *ctrl,
  2950. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2951. +{
  2952. + u32 u32_value;
  2953. + struct vchiq_mmal_port *jpeg_out;
  2954. +
  2955. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  2956. +
  2957. + u32_value = ctrl->val;
  2958. +
  2959. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  2960. + mmal_ctrl->mmal_id,
  2961. + &u32_value, sizeof(u32_value));
  2962. +}
  2963. +
  2964. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  2965. + struct v4l2_ctrl *ctrl,
  2966. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2967. +{
  2968. + u32 u32_value;
  2969. + struct vchiq_mmal_port *vid_enc_ctl;
  2970. +
  2971. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  2972. +
  2973. + u32_value = ctrl->val;
  2974. +
  2975. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  2976. + mmal_ctrl->mmal_id,
  2977. + &u32_value, sizeof(u32_value));
  2978. +}
  2979. +
  2980. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  2981. + struct v4l2_ctrl *ctrl,
  2982. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  2983. +{
  2984. + struct mmal_parameter_video_profile param;
  2985. + int ret = 0;
  2986. +
  2987. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  2988. + switch (ctrl->val) {
  2989. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  2990. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  2991. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  2992. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  2993. + dev->capture.enc_profile = ctrl->val;
  2994. + break;
  2995. + default:
  2996. + ret = -EINVAL;
  2997. + break;
  2998. + }
  2999. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  3000. + switch (ctrl->val) {
  3001. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  3002. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  3003. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  3004. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  3005. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  3006. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  3007. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  3008. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  3009. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  3010. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  3011. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  3012. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  3013. + dev->capture.enc_level = ctrl->val;
  3014. + break;
  3015. + default:
  3016. + ret = -EINVAL;
  3017. + break;
  3018. + }
  3019. + }
  3020. +
  3021. + if (!ret) {
  3022. + switch (dev->capture.enc_profile) {
  3023. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  3024. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  3025. + break;
  3026. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  3027. + param.profile =
  3028. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  3029. + break;
  3030. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  3031. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  3032. + break;
  3033. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  3034. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  3035. + break;
  3036. + default:
  3037. + /* Should never get here */
  3038. + break;
  3039. + }
  3040. +
  3041. + switch (dev->capture.enc_level) {
  3042. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  3043. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  3044. + break;
  3045. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  3046. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  3047. + break;
  3048. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  3049. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  3050. + break;
  3051. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  3052. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  3053. + break;
  3054. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  3055. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  3056. + break;
  3057. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  3058. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  3059. + break;
  3060. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  3061. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  3062. + break;
  3063. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  3064. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  3065. + break;
  3066. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  3067. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  3068. + break;
  3069. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  3070. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  3071. + break;
  3072. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  3073. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  3074. + break;
  3075. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  3076. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  3077. + break;
  3078. + default:
  3079. + /* Should never get here */
  3080. + break;
  3081. + }
  3082. +
  3083. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  3084. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  3085. + mmal_ctrl->mmal_id,
  3086. + &param, sizeof(param));
  3087. + }
  3088. + return ret;
  3089. +}
  3090. +
  3091. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  3092. + struct v4l2_ctrl *ctrl,
  3093. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  3094. +{
  3095. + int ret = 0;
  3096. + int shutter_speed;
  3097. + struct vchiq_mmal_port *control;
  3098. +
  3099. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3100. + "scene mode selected %d, was %d\n", ctrl->val,
  3101. + dev->scene_mode);
  3102. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  3103. +
  3104. + if (ctrl->val == dev->scene_mode)
  3105. + return 0;
  3106. +
  3107. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  3108. + /* Restore all user selections */
  3109. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  3110. +
  3111. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  3112. + shutter_speed = dev->manual_shutter_speed;
  3113. + else
  3114. + shutter_speed = 0;
  3115. +
  3116. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3117. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  3118. + __func__, shutter_speed, dev->exposure_mode_user,
  3119. + dev->metering_mode);
  3120. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  3121. + control,
  3122. + MMAL_PARAMETER_SHUTTER_SPEED,
  3123. + &shutter_speed,
  3124. + sizeof(shutter_speed));
  3125. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  3126. + control,
  3127. + MMAL_PARAMETER_EXPOSURE_MODE,
  3128. + &dev->exposure_mode_user,
  3129. + sizeof(u32));
  3130. + dev->exposure_mode_active = dev->exposure_mode_user;
  3131. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  3132. + control,
  3133. + MMAL_PARAMETER_EXP_METERING_MODE,
  3134. + &dev->metering_mode,
  3135. + sizeof(u32));
  3136. + ret += set_framerate_params(dev);
  3137. + } else {
  3138. + /* Set up scene mode */
  3139. + int i;
  3140. + const struct v4l2_mmal_scene_config *scene = NULL;
  3141. + int shutter_speed;
  3142. + enum mmal_parameter_exposuremode exposure_mode;
  3143. + enum mmal_parameter_exposuremeteringmode metering_mode;
  3144. +
  3145. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  3146. + if (scene_configs[i].v4l2_scene ==
  3147. + ctrl->val) {
  3148. + scene = &scene_configs[i];
  3149. + break;
  3150. + }
  3151. + }
  3152. + if (!scene)
  3153. + return -EINVAL;
  3154. + if (i >= ARRAY_SIZE(scene_configs))
  3155. + return -EINVAL;
  3156. +
  3157. + /* Set all the values */
  3158. + dev->scene_mode = ctrl->val;
  3159. +
  3160. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  3161. + shutter_speed = dev->manual_shutter_speed;
  3162. + else
  3163. + shutter_speed = 0;
  3164. + exposure_mode = scene->exposure_mode;
  3165. + metering_mode = scene->metering_mode;
  3166. +
  3167. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3168. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  3169. + __func__, shutter_speed, exposure_mode, metering_mode);
  3170. +
  3171. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  3172. + MMAL_PARAMETER_SHUTTER_SPEED,
  3173. + &shutter_speed,
  3174. + sizeof(shutter_speed));
  3175. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  3176. + control,
  3177. + MMAL_PARAMETER_EXPOSURE_MODE,
  3178. + &exposure_mode,
  3179. + sizeof(u32));
  3180. + dev->exposure_mode_active = exposure_mode;
  3181. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  3182. + MMAL_PARAMETER_EXPOSURE_MODE,
  3183. + &exposure_mode,
  3184. + sizeof(u32));
  3185. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  3186. + MMAL_PARAMETER_EXP_METERING_MODE,
  3187. + &metering_mode,
  3188. + sizeof(u32));
  3189. + ret += set_framerate_params(dev);
  3190. + }
  3191. + if (ret) {
  3192. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3193. + "%s: Setting scene to %d, ret=%d\n",
  3194. + __func__, ctrl->val, ret);
  3195. + ret = -EINVAL;
  3196. + }
  3197. + return 0;
  3198. +}
  3199. +
  3200. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  3201. +{
  3202. + struct bm2835_mmal_dev *dev =
  3203. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  3204. + ctrl_handler);
  3205. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  3206. + int ret;
  3207. +
  3208. + if ((mmal_ctrl == NULL) ||
  3209. + (mmal_ctrl->id != ctrl->id) ||
  3210. + (mmal_ctrl->setter == NULL)) {
  3211. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  3212. + return -EINVAL;
  3213. + }
  3214. +
  3215. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  3216. + if (ret)
  3217. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  3218. + ctrl->id, mmal_ctrl->mmal_id, ret);
  3219. + if (mmal_ctrl->ignore_errors)
  3220. + ret = 0;
  3221. + return ret;
  3222. +}
  3223. +
  3224. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  3225. + .s_ctrl = bm2835_mmal_s_ctrl,
  3226. +};
  3227. +
  3228. +
  3229. +
  3230. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  3231. + {
  3232. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  3233. + -100, 100, 0, 1, NULL,
  3234. + MMAL_PARAMETER_SATURATION,
  3235. + &ctrl_set_rational,
  3236. + false
  3237. + },
  3238. + {
  3239. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  3240. + -100, 100, 0, 1, NULL,
  3241. + MMAL_PARAMETER_SHARPNESS,
  3242. + &ctrl_set_rational,
  3243. + false
  3244. + },
  3245. + {
  3246. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  3247. + -100, 100, 0, 1, NULL,
  3248. + MMAL_PARAMETER_CONTRAST,
  3249. + &ctrl_set_rational,
  3250. + false
  3251. + },
  3252. + {
  3253. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  3254. + 0, 100, 50, 1, NULL,
  3255. + MMAL_PARAMETER_BRIGHTNESS,
  3256. + &ctrl_set_rational,
  3257. + false
  3258. + },
  3259. + {
  3260. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  3261. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  3262. + MMAL_PARAMETER_ISO,
  3263. + &ctrl_set_value_menu,
  3264. + false
  3265. + },
  3266. + {
  3267. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  3268. + 0, 1, 0, 1, NULL,
  3269. + MMAL_PARAMETER_VIDEO_STABILISATION,
  3270. + &ctrl_set_value,
  3271. + false
  3272. + },
  3273. +/* {
  3274. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  3275. + }, */
  3276. + {
  3277. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  3278. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  3279. + MMAL_PARAMETER_EXPOSURE_MODE,
  3280. + &ctrl_set_exposure,
  3281. + false
  3282. + },
  3283. +/* todo this needs mixing in with set exposure
  3284. + {
  3285. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  3286. + },
  3287. + */
  3288. + {
  3289. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  3290. + /* Units of 100usecs */
  3291. + 1, 1*1000*10, 100*10, 1, NULL,
  3292. + MMAL_PARAMETER_SHUTTER_SPEED,
  3293. + &ctrl_set_exposure,
  3294. + false
  3295. + },
  3296. + {
  3297. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  3298. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  3299. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  3300. + MMAL_PARAMETER_EXPOSURE_COMP,
  3301. + &ctrl_set_value_ev,
  3302. + false
  3303. + },
  3304. + {
  3305. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  3306. + 0, 1,
  3307. + 0, 1, NULL,
  3308. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  3309. + &ctrl_set_exposure,
  3310. + false
  3311. + },
  3312. + {
  3313. + V4L2_CID_EXPOSURE_METERING,
  3314. + MMAL_CONTROL_TYPE_STD_MENU,
  3315. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  3316. + MMAL_PARAMETER_EXP_METERING_MODE,
  3317. + &ctrl_set_metering_mode,
  3318. + false
  3319. + },
  3320. + {
  3321. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  3322. + MMAL_CONTROL_TYPE_STD_MENU,
  3323. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  3324. + MMAL_PARAMETER_AWB_MODE,
  3325. + &ctrl_set_awb_mode,
  3326. + false
  3327. + },
  3328. + {
  3329. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  3330. + 1, 7999, 1000, 1, NULL,
  3331. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  3332. + &ctrl_set_awb_gains,
  3333. + false
  3334. + },
  3335. + {
  3336. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  3337. + 1, 7999, 1000, 1, NULL,
  3338. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  3339. + &ctrl_set_awb_gains,
  3340. + false
  3341. + },
  3342. + {
  3343. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  3344. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  3345. + MMAL_PARAMETER_IMAGE_EFFECT,
  3346. + &ctrl_set_image_effect,
  3347. + false
  3348. + },
  3349. + {
  3350. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  3351. + 0, 0xffff, 0x8080, 1, NULL,
  3352. + MMAL_PARAMETER_COLOUR_EFFECT,
  3353. + &ctrl_set_colfx,
  3354. + false
  3355. + },
  3356. + {
  3357. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  3358. + 0, 360, 0, 90, NULL,
  3359. + MMAL_PARAMETER_ROTATION,
  3360. + &ctrl_set_rotate,
  3361. + false
  3362. + },
  3363. + {
  3364. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  3365. + 0, 1, 0, 1, NULL,
  3366. + MMAL_PARAMETER_MIRROR,
  3367. + &ctrl_set_flip,
  3368. + false
  3369. + },
  3370. + {
  3371. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  3372. + 0, 1, 0, 1, NULL,
  3373. + MMAL_PARAMETER_MIRROR,
  3374. + &ctrl_set_flip,
  3375. + false
  3376. + },
  3377. + {
  3378. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  3379. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  3380. + 0, 0, bitrate_mode_qmenu,
  3381. + MMAL_PARAMETER_RATECONTROL,
  3382. + &ctrl_set_bitrate_mode,
  3383. + false
  3384. + },
  3385. + {
  3386. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  3387. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  3388. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  3389. + &ctrl_set_bitrate,
  3390. + false
  3391. + },
  3392. + {
  3393. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  3394. + 1, 100,
  3395. + 30, 1, NULL,
  3396. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  3397. + &ctrl_set_image_encode_output,
  3398. + false
  3399. + },
  3400. + {
  3401. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  3402. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  3403. + 1, 1, NULL,
  3404. + MMAL_PARAMETER_FLICKER_AVOID,
  3405. + &ctrl_set_flicker_avoidance,
  3406. + false
  3407. + },
  3408. + {
  3409. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  3410. + 0, 1,
  3411. + 0, 1, NULL,
  3412. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  3413. + &ctrl_set_video_encode_param_output,
  3414. + true /* Errors ignored as requires latest firmware to work */
  3415. + },
  3416. + {
  3417. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  3418. + MMAL_CONTROL_TYPE_STD_MENU,
  3419. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  3420. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  3421. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  3422. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  3423. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  3424. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  3425. + MMAL_PARAMETER_PROFILE,
  3426. + &ctrl_set_video_encode_profile_level,
  3427. + false
  3428. + },
  3429. + {
  3430. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  3431. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  3432. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  3433. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  3434. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  3435. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  3436. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  3437. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  3438. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  3439. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  3440. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  3441. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  3442. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  3443. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  3444. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  3445. + MMAL_PARAMETER_PROFILE,
  3446. + &ctrl_set_video_encode_profile_level,
  3447. + false
  3448. + },
  3449. + {
  3450. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  3451. + -1, /* Min is computed at runtime */
  3452. + V4L2_SCENE_MODE_TEXT,
  3453. + V4L2_SCENE_MODE_NONE, 1, NULL,
  3454. + MMAL_PARAMETER_PROFILE,
  3455. + &ctrl_set_scene_mode,
  3456. + false
  3457. + },
  3458. + {
  3459. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  3460. + 0, 0x7FFFFFFF, 60, 1, NULL,
  3461. + MMAL_PARAMETER_INTRAPERIOD,
  3462. + &ctrl_set_video_encode_param_output,
  3463. + false
  3464. + },
  3465. +};
  3466. +
  3467. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  3468. +{
  3469. + int c;
  3470. + int ret = 0;
  3471. +
  3472. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  3473. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  3474. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  3475. + &v4l2_ctrls[c]);
  3476. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  3477. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3478. + "Failed when setting default values for ctrl %d\n",
  3479. + c);
  3480. + break;
  3481. + }
  3482. + }
  3483. + }
  3484. + return ret;
  3485. +}
  3486. +
  3487. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  3488. +{
  3489. + struct mmal_parameter_fps_range fps_range;
  3490. + int ret;
  3491. +
  3492. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  3493. + (dev->exp_auto_priority)) {
  3494. + /* Variable FPS. Define min FPS as 1fps.
  3495. + * Max as max defined FPS.
  3496. + */
  3497. + fps_range.fps_low.num = 1;
  3498. + fps_range.fps_low.den = 1;
  3499. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  3500. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  3501. + } else {
  3502. + /* Fixed FPS - set min and max to be the same */
  3503. + fps_range.fps_low.num = fps_range.fps_high.num =
  3504. + dev->capture.timeperframe.denominator;
  3505. + fps_range.fps_low.den = fps_range.fps_high.den =
  3506. + dev->capture.timeperframe.numerator;
  3507. + }
  3508. +
  3509. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3510. + "Set fps range to %d/%d to %d/%d\n",
  3511. + fps_range.fps_low.num,
  3512. + fps_range.fps_low.den,
  3513. + fps_range.fps_high.num,
  3514. + fps_range.fps_high.den
  3515. + );
  3516. +
  3517. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  3518. + &dev->component[MMAL_COMPONENT_CAMERA]->
  3519. + output[MMAL_CAMERA_PORT_PREVIEW],
  3520. + MMAL_PARAMETER_FPS_RANGE,
  3521. + &fps_range, sizeof(fps_range));
  3522. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  3523. + &dev->component[MMAL_COMPONENT_CAMERA]->
  3524. + output[MMAL_CAMERA_PORT_VIDEO],
  3525. + MMAL_PARAMETER_FPS_RANGE,
  3526. + &fps_range, sizeof(fps_range));
  3527. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  3528. + &dev->component[MMAL_COMPONENT_CAMERA]->
  3529. + output[MMAL_CAMERA_PORT_CAPTURE],
  3530. + MMAL_PARAMETER_FPS_RANGE,
  3531. + &fps_range, sizeof(fps_range));
  3532. + if (ret)
  3533. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  3534. + "Failed to set fps ret %d\n",
  3535. + ret);
  3536. +
  3537. + return ret;
  3538. +
  3539. +}
  3540. +
  3541. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  3542. + struct v4l2_ctrl_handler *hdl)
  3543. +{
  3544. + int c;
  3545. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  3546. +
  3547. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  3548. +
  3549. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  3550. + ctrl = &v4l2_ctrls[c];
  3551. +
  3552. + switch (ctrl->type) {
  3553. + case MMAL_CONTROL_TYPE_STD:
  3554. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  3555. + &bm2835_mmal_ctrl_ops, ctrl->id,
  3556. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  3557. + break;
  3558. +
  3559. + case MMAL_CONTROL_TYPE_STD_MENU:
  3560. + {
  3561. + int mask = ctrl->min;
  3562. +
  3563. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  3564. + /* Special handling to work out the mask
  3565. + * value based on the scene_configs array
  3566. + * at runtime. Reduces the chance of
  3567. + * mismatches.
  3568. + */
  3569. + int i;
  3570. + mask = 1<<V4L2_SCENE_MODE_NONE;
  3571. + for (i = 0;
  3572. + i < ARRAY_SIZE(scene_configs);
  3573. + i++) {
  3574. + mask |= 1<<scene_configs[i].v4l2_scene;
  3575. + }
  3576. + mask = ~mask;
  3577. + }
  3578. +
  3579. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  3580. + &bm2835_mmal_ctrl_ops, ctrl->id,
  3581. + ctrl->max, mask, ctrl->def);
  3582. + break;
  3583. + }
  3584. +
  3585. + case MMAL_CONTROL_TYPE_INT_MENU:
  3586. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  3587. + &bm2835_mmal_ctrl_ops, ctrl->id,
  3588. + ctrl->max, ctrl->def, ctrl->imenu);
  3589. + break;
  3590. +
  3591. + case MMAL_CONTROL_TYPE_CLUSTER:
  3592. + /* skip this entry when constructing controls */
  3593. + continue;
  3594. + }
  3595. +
  3596. + if (hdl->error)
  3597. + break;
  3598. +
  3599. + dev->ctrls[c]->priv = (void *)ctrl;
  3600. + }
  3601. +
  3602. + if (hdl->error) {
  3603. + pr_err("error adding control %d/%d id 0x%x\n", c,
  3604. + V4L2_CTRL_COUNT, ctrl->id);
  3605. + return hdl->error;
  3606. + }
  3607. +
  3608. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  3609. + ctrl = &v4l2_ctrls[c];
  3610. +
  3611. + switch (ctrl->type) {
  3612. + case MMAL_CONTROL_TYPE_CLUSTER:
  3613. + v4l2_ctrl_auto_cluster(ctrl->min,
  3614. + &dev->ctrls[c+1],
  3615. + ctrl->max,
  3616. + ctrl->def);
  3617. + break;
  3618. +
  3619. + case MMAL_CONTROL_TYPE_STD:
  3620. + case MMAL_CONTROL_TYPE_STD_MENU:
  3621. + case MMAL_CONTROL_TYPE_INT_MENU:
  3622. + break;
  3623. + }
  3624. +
  3625. + }
  3626. +
  3627. + return 0;
  3628. +}
  3629. --- /dev/null
  3630. +++ b/drivers/media/platform/bcm2835/mmal-common.h
  3631. @@ -0,0 +1,53 @@
  3632. +/*
  3633. + * Broadcom BM2835 V4L2 driver
  3634. + *
  3635. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  3636. + *
  3637. + * This file is subject to the terms and conditions of the GNU General Public
  3638. + * License. See the file COPYING in the main directory of this archive
  3639. + * for more details.
  3640. + *
  3641. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  3642. + * Dave Stevenson <dsteve@broadcom.com>
  3643. + * Simon Mellor <simellor@broadcom.com>
  3644. + * Luke Diamand <luked@broadcom.com>
  3645. + *
  3646. + * MMAL structures
  3647. + *
  3648. + */
  3649. +
  3650. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  3651. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  3652. +
  3653. +/** Special value signalling that time is not known */
  3654. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  3655. +
  3656. +/* mapping between v4l and mmal video modes */
  3657. +struct mmal_fmt {
  3658. + char *name;
  3659. + u32 fourcc; /* v4l2 format id */
  3660. + int flags; /* v4l2 flags field */
  3661. + u32 mmal;
  3662. + int depth;
  3663. + u32 mmal_component; /* MMAL component index to be used to encode */
  3664. + u32 ybbp; /* depth of first Y plane for planar formats */
  3665. +};
  3666. +
  3667. +/* buffer for one video frame */
  3668. +struct mmal_buffer {
  3669. + /* v4l buffer data -- must be first */
  3670. + struct vb2_v4l2_buffer vb;
  3671. +
  3672. + /* list of buffers available */
  3673. + struct list_head list;
  3674. +
  3675. + void *buffer; /* buffer pointer */
  3676. + unsigned long buffer_size; /* size of allocated buffer */
  3677. +};
  3678. +
  3679. +/* */
  3680. +struct mmal_colourfx {
  3681. + s32 enable;
  3682. + u32 u;
  3683. + u32 v;
  3684. +};
  3685. --- /dev/null
  3686. +++ b/drivers/media/platform/bcm2835/mmal-encodings.h
  3687. @@ -0,0 +1,127 @@
  3688. +/*
  3689. + * Broadcom BM2835 V4L2 driver
  3690. + *
  3691. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  3692. + *
  3693. + * This file is subject to the terms and conditions of the GNU General Public
  3694. + * License. See the file COPYING in the main directory of this archive
  3695. + * for more details.
  3696. + *
  3697. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  3698. + * Dave Stevenson <dsteve@broadcom.com>
  3699. + * Simon Mellor <simellor@broadcom.com>
  3700. + * Luke Diamand <luked@broadcom.com>
  3701. + */
  3702. +#ifndef MMAL_ENCODINGS_H
  3703. +#define MMAL_ENCODINGS_H
  3704. +
  3705. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  3706. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  3707. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  3708. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  3709. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  3710. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  3711. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  3712. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  3713. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  3714. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  3715. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  3716. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  3717. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  3718. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  3719. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  3720. +
  3721. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  3722. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  3723. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  3724. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  3725. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  3726. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  3727. +
  3728. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  3729. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  3730. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  3731. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  3732. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  3733. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  3734. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  3735. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  3736. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  3737. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  3738. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  3739. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  3740. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  3741. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  3742. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  3743. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  3744. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  3745. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  3746. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  3747. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  3748. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  3749. +
  3750. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  3751. + * This format is *not* opaque - if requested you will receive full frames
  3752. + * of YUV_UV video.
  3753. + */
  3754. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  3755. +
  3756. +/** VideoCore opaque image format, image handles are returned to
  3757. + * the host but not the actual image data.
  3758. + */
  3759. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  3760. +
  3761. +/** An EGL image handle
  3762. + */
  3763. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  3764. +
  3765. +/* }@ */
  3766. +
  3767. +/** \name Pre-defined audio encodings */
  3768. +/* @{ */
  3769. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  3770. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  3771. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  3772. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  3773. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  3774. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  3775. +
  3776. +/* Pre-defined H264 encoding variants */
  3777. +
  3778. +/** ISO 14496-10 Annex B byte stream format */
  3779. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  3780. +/** ISO 14496-15 AVC stream format */
  3781. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  3782. +/** Implicitly delineated NAL units without emulation prevention */
  3783. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  3784. +
  3785. +
  3786. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  3787. + * This defines a list of common color spaces. This list isn't exhaustive and
  3788. + * is only provided as a convenience to avoid clients having to use FourCC
  3789. + * codes directly. However components are allowed to define and use their own
  3790. + * FourCC codes.
  3791. + */
  3792. +/* @{ */
  3793. +
  3794. +/** Unknown color space */
  3795. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  3796. +/** ITU-R BT.601-5 [SDTV] */
  3797. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  3798. +/** ITU-R BT.709-3 [HDTV] */
  3799. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  3800. +/** JPEG JFIF */
  3801. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  3802. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  3803. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  3804. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  3805. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  3806. +/** ITU-R BT.470-2 System M */
  3807. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  3808. +/** ITU-R BT.470-2 System BG */
  3809. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  3810. +/** JPEG JFIF, but with 16..255 luma */
  3811. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  3812. +/* @} MmalColorSpace List */
  3813. +
  3814. +#endif /* MMAL_ENCODINGS_H */
  3815. --- /dev/null
  3816. +++ b/drivers/media/platform/bcm2835/mmal-msg-common.h
  3817. @@ -0,0 +1,50 @@
  3818. +/*
  3819. + * Broadcom BM2835 V4L2 driver
  3820. + *
  3821. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  3822. + *
  3823. + * This file is subject to the terms and conditions of the GNU General Public
  3824. + * License. See the file COPYING in the main directory of this archive
  3825. + * for more details.
  3826. + *
  3827. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  3828. + * Dave Stevenson <dsteve@broadcom.com>
  3829. + * Simon Mellor <simellor@broadcom.com>
  3830. + * Luke Diamand <luked@broadcom.com>
  3831. + */
  3832. +
  3833. +#ifndef MMAL_MSG_COMMON_H
  3834. +#define MMAL_MSG_COMMON_H
  3835. +
  3836. +enum mmal_msg_status {
  3837. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  3838. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  3839. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  3840. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  3841. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  3842. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  3843. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  3844. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  3845. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  3846. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  3847. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  3848. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  3849. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  3850. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  3851. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  3852. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  3853. +};
  3854. +
  3855. +struct mmal_rect {
  3856. + s32 x; /**< x coordinate (from left) */
  3857. + s32 y; /**< y coordinate (from top) */
  3858. + s32 width; /**< width */
  3859. + s32 height; /**< height */
  3860. +};
  3861. +
  3862. +struct mmal_rational {
  3863. + s32 num; /**< Numerator */
  3864. + s32 den; /**< Denominator */
  3865. +};
  3866. +
  3867. +#endif /* MMAL_MSG_COMMON_H */
  3868. --- /dev/null
  3869. +++ b/drivers/media/platform/bcm2835/mmal-msg-format.h
  3870. @@ -0,0 +1,81 @@
  3871. +/*
  3872. + * Broadcom BM2835 V4L2 driver
  3873. + *
  3874. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  3875. + *
  3876. + * This file is subject to the terms and conditions of the GNU General Public
  3877. + * License. See the file COPYING in the main directory of this archive
  3878. + * for more details.
  3879. + *
  3880. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  3881. + * Dave Stevenson <dsteve@broadcom.com>
  3882. + * Simon Mellor <simellor@broadcom.com>
  3883. + * Luke Diamand <luked@broadcom.com>
  3884. + */
  3885. +
  3886. +#ifndef MMAL_MSG_FORMAT_H
  3887. +#define MMAL_MSG_FORMAT_H
  3888. +
  3889. +#include "mmal-msg-common.h"
  3890. +
  3891. +/* MMAL_ES_FORMAT_T */
  3892. +
  3893. +
  3894. +struct mmal_audio_format {
  3895. + u32 channels; /**< Number of audio channels */
  3896. + u32 sample_rate; /**< Sample rate */
  3897. +
  3898. + u32 bits_per_sample; /**< Bits per sample */
  3899. + u32 block_align; /**< Size of a block of data */
  3900. +};
  3901. +
  3902. +struct mmal_video_format {
  3903. + u32 width; /**< Width of frame in pixels */
  3904. + u32 height; /**< Height of frame in rows of pixels */
  3905. + struct mmal_rect crop; /**< Visible region of the frame */
  3906. + struct mmal_rational frame_rate; /**< Frame rate */
  3907. + struct mmal_rational par; /**< Pixel aspect ratio */
  3908. +
  3909. + /* FourCC specifying the color space of the video stream. See the
  3910. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  3911. + */
  3912. + u32 color_space;
  3913. +};
  3914. +
  3915. +struct mmal_subpicture_format {
  3916. + u32 x_offset;
  3917. + u32 y_offset;
  3918. +};
  3919. +
  3920. +union mmal_es_specific_format {
  3921. + struct mmal_audio_format audio;
  3922. + struct mmal_video_format video;
  3923. + struct mmal_subpicture_format subpicture;
  3924. +};
  3925. +
  3926. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  3927. +struct mmal_es_format {
  3928. + u32 type; /* enum mmal_es_type */
  3929. +
  3930. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  3931. + u32 encoding_variant; /* FourCC specifying the specific
  3932. + * encoding variant of the elementary
  3933. + * stream.
  3934. + */
  3935. +
  3936. + union mmal_es_specific_format *es; /* TODO: pointers in
  3937. + * message serialisation?!?
  3938. + */
  3939. + /* Type specific
  3940. + * information for the
  3941. + * elementary stream
  3942. + */
  3943. +
  3944. + u32 bitrate; /**< Bitrate in bits per second */
  3945. + u32 flags; /**< Flags describing properties of the elementary stream. */
  3946. +
  3947. + u32 extradata_size; /**< Size of the codec specific data */
  3948. + u8 *extradata; /**< Codec specific data */
  3949. +};
  3950. +
  3951. +#endif /* MMAL_MSG_FORMAT_H */
  3952. --- /dev/null
  3953. +++ b/drivers/media/platform/bcm2835/mmal-msg-port.h
  3954. @@ -0,0 +1,107 @@
  3955. +/*
  3956. + * Broadcom BM2835 V4L2 driver
  3957. + *
  3958. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  3959. + *
  3960. + * This file is subject to the terms and conditions of the GNU General Public
  3961. + * License. See the file COPYING in the main directory of this archive
  3962. + * for more details.
  3963. + *
  3964. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  3965. + * Dave Stevenson <dsteve@broadcom.com>
  3966. + * Simon Mellor <simellor@broadcom.com>
  3967. + * Luke Diamand <luked@broadcom.com>
  3968. + */
  3969. +
  3970. +/* MMAL_PORT_TYPE_T */
  3971. +enum mmal_port_type {
  3972. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  3973. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  3974. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  3975. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  3976. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  3977. +};
  3978. +
  3979. +/** The port is pass-through and doesn't need buffer headers allocated */
  3980. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  3981. +/** The port wants to allocate the buffer payloads.
  3982. + * This signals a preference that payload allocation should be done
  3983. + * on this port for efficiency reasons. */
  3984. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  3985. +/** The port supports format change events.
  3986. + * This applies to input ports and is used to let the client know
  3987. + * whether the port supports being reconfigured via a format
  3988. + * change event (i.e. without having to disable the port). */
  3989. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  3990. +
  3991. +/* mmal port structure (MMAL_PORT_T)
  3992. + *
  3993. + * most elements are informational only, the pointer values for
  3994. + * interogation messages are generally provided as additional
  3995. + * strucures within the message. When used to set values only teh
  3996. + * buffer_num, buffer_size and userdata parameters are writable.
  3997. + */
  3998. +struct mmal_port {
  3999. + void *priv; /* Private member used by the framework */
  4000. + const char *name; /* Port name. Used for debugging purposes (RO) */
  4001. +
  4002. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  4003. + u16 index; /* Index of the port in its type list (RO) */
  4004. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  4005. +
  4006. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  4007. + struct mmal_es_format *format; /* Format of the elementary stream */
  4008. +
  4009. + u32 buffer_num_min; /* Minimum number of buffers the port
  4010. + * requires (RO). This is set by the
  4011. + * component.
  4012. + */
  4013. +
  4014. + u32 buffer_size_min; /* Minimum size of buffers the port
  4015. + * requires (RO). This is set by the
  4016. + * component.
  4017. + */
  4018. +
  4019. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  4020. + * the buffers (RO). A value of
  4021. + * zero means no special alignment
  4022. + * requirements. This is set by the
  4023. + * component.
  4024. + */
  4025. +
  4026. + u32 buffer_num_recommended; /* Number of buffers the port
  4027. + * recommends for optimal
  4028. + * performance (RO). A value of
  4029. + * zero means no special
  4030. + * recommendation. This is set
  4031. + * by the component.
  4032. + */
  4033. +
  4034. + u32 buffer_size_recommended; /* Size of buffers the port
  4035. + * recommends for optimal
  4036. + * performance (RO). A value of
  4037. + * zero means no special
  4038. + * recommendation. This is set
  4039. + * by the component.
  4040. + */
  4041. +
  4042. + u32 buffer_num; /* Actual number of buffers the port will use.
  4043. + * This is set by the client.
  4044. + */
  4045. +
  4046. + u32 buffer_size; /* Actual maximum size of the buffers that
  4047. + * will be sent to the port. This is set by
  4048. + * the client.
  4049. + */
  4050. +
  4051. + void *component; /* Component this port belongs to (Read Only) */
  4052. +
  4053. + void *userdata; /* Field reserved for use by the client */
  4054. +
  4055. + u32 capabilities; /* Flags describing the capabilities of a
  4056. + * port (RO). Bitwise combination of \ref
  4057. + * portcapabilities "Port capabilities"
  4058. + * values.
  4059. + */
  4060. +
  4061. +};
  4062. --- /dev/null
  4063. +++ b/drivers/media/platform/bcm2835/mmal-msg.h
  4064. @@ -0,0 +1,404 @@
  4065. +/*
  4066. + * Broadcom BM2835 V4L2 driver
  4067. + *
  4068. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  4069. + *
  4070. + * This file is subject to the terms and conditions of the GNU General Public
  4071. + * License. See the file COPYING in the main directory of this archive
  4072. + * for more details.
  4073. + *
  4074. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  4075. + * Dave Stevenson <dsteve@broadcom.com>
  4076. + * Simon Mellor <simellor@broadcom.com>
  4077. + * Luke Diamand <luked@broadcom.com>
  4078. + */
  4079. +
  4080. +/* all the data structures which serialise the MMAL protocol. note
  4081. + * these are directly mapped onto the recived message data.
  4082. + *
  4083. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  4084. + * structure padding!
  4085. + *
  4086. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  4087. + * than assigning values to enums to force their size the
  4088. + * implementation uses fixed size types and not the enums (though the
  4089. + * comments have the actual enum type
  4090. + */
  4091. +
  4092. +#define VC_MMAL_VER 15
  4093. +#define VC_MMAL_MIN_VER 10
  4094. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  4095. +
  4096. +/* max total message size is 512 bytes */
  4097. +#define MMAL_MSG_MAX_SIZE 512
  4098. +/* with six 32bit header elements max payload is therefore 488 bytes */
  4099. +#define MMAL_MSG_MAX_PAYLOAD 488
  4100. +
  4101. +#include "mmal-msg-common.h"
  4102. +#include "mmal-msg-format.h"
  4103. +#include "mmal-msg-port.h"
  4104. +
  4105. +enum mmal_msg_type {
  4106. + MMAL_MSG_TYPE_QUIT = 1,
  4107. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  4108. + MMAL_MSG_TYPE_GET_VERSION,
  4109. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  4110. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  4111. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  4112. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  4113. + MMAL_MSG_TYPE_PORT_INFO_GET,
  4114. + MMAL_MSG_TYPE_PORT_INFO_SET,
  4115. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  4116. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  4117. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  4118. + MMAL_MSG_TYPE_GET_STATS,
  4119. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  4120. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  4121. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  4122. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  4123. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  4124. + MMAL_MSG_TYPE_CONSUME_MEM,
  4125. + MMAL_MSG_TYPE_LMK, /* 20 */
  4126. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  4127. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  4128. + MMAL_MSG_TYPE_DRM_GET_TIME,
  4129. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  4130. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  4131. + MMAL_MSG_TYPE_HOST_LOG,
  4132. + MMAL_MSG_TYPE_MSG_LAST
  4133. +};
  4134. +
  4135. +/* port action request messages differ depending on the action type */
  4136. +enum mmal_msg_port_action_type {
  4137. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  4138. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  4139. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  4140. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  4141. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  4142. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  4143. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  4144. +};
  4145. +
  4146. +struct mmal_msg_header {
  4147. + u32 magic;
  4148. + u32 type; /** enum mmal_msg_type */
  4149. +
  4150. + /* Opaque handle to the control service */
  4151. + struct mmal_control_service *control_service;
  4152. +
  4153. + struct mmal_msg_context *context; /** a u32 per message context */
  4154. + u32 status; /** The status of the vchiq operation */
  4155. + u32 padding;
  4156. +};
  4157. +
  4158. +/* Send from VC to host to report version */
  4159. +struct mmal_msg_version {
  4160. + u32 flags;
  4161. + u32 major;
  4162. + u32 minor;
  4163. + u32 minimum;
  4164. +};
  4165. +
  4166. +/* request to VC to create component */
  4167. +struct mmal_msg_component_create {
  4168. + void *client_component; /* component context */
  4169. + char name[128];
  4170. + u32 pid; /* For debug */
  4171. +};
  4172. +
  4173. +/* reply from VC to component creation request */
  4174. +struct mmal_msg_component_create_reply {
  4175. + u32 status; /** enum mmal_msg_status - how does this differ to
  4176. + * the one in the header?
  4177. + */
  4178. + u32 component_handle; /* VideoCore handle for component */
  4179. + u32 input_num; /* Number of input ports */
  4180. + u32 output_num; /* Number of output ports */
  4181. + u32 clock_num; /* Number of clock ports */
  4182. +};
  4183. +
  4184. +/* request to VC to destroy a component */
  4185. +struct mmal_msg_component_destroy {
  4186. + u32 component_handle;
  4187. +};
  4188. +
  4189. +struct mmal_msg_component_destroy_reply {
  4190. + u32 status; /** The component destruction status */
  4191. +};
  4192. +
  4193. +
  4194. +/* request and reply to VC to enable a component */
  4195. +struct mmal_msg_component_enable {
  4196. + u32 component_handle;
  4197. +};
  4198. +
  4199. +struct mmal_msg_component_enable_reply {
  4200. + u32 status; /** The component enable status */
  4201. +};
  4202. +
  4203. +
  4204. +/* request and reply to VC to disable a component */
  4205. +struct mmal_msg_component_disable {
  4206. + u32 component_handle;
  4207. +};
  4208. +
  4209. +struct mmal_msg_component_disable_reply {
  4210. + u32 status; /** The component disable status */
  4211. +};
  4212. +
  4213. +/* request to VC to get port information */
  4214. +struct mmal_msg_port_info_get {
  4215. + u32 component_handle; /* component handle port is associated with */
  4216. + u32 port_type; /* enum mmal_msg_port_type */
  4217. + u32 index; /* port index to query */
  4218. +};
  4219. +
  4220. +/* reply from VC to get port info request */
  4221. +struct mmal_msg_port_info_get_reply {
  4222. + u32 status; /** enum mmal_msg_status */
  4223. + u32 component_handle; /* component handle port is associated with */
  4224. + u32 port_type; /* enum mmal_msg_port_type */
  4225. + u32 port_index; /* port indexed in query */
  4226. + s32 found; /* unused */
  4227. + u32 port_handle; /**< Handle to use for this port */
  4228. + struct mmal_port port;
  4229. + struct mmal_es_format format; /* elementry stream format */
  4230. + union mmal_es_specific_format es; /* es type specific data */
  4231. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  4232. +};
  4233. +
  4234. +/* request to VC to set port information */
  4235. +struct mmal_msg_port_info_set {
  4236. + u32 component_handle;
  4237. + u32 port_type; /* enum mmal_msg_port_type */
  4238. + u32 port_index; /* port indexed in query */
  4239. + struct mmal_port port;
  4240. + struct mmal_es_format format;
  4241. + union mmal_es_specific_format es;
  4242. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  4243. +};
  4244. +
  4245. +/* reply from VC to port info set request */
  4246. +struct mmal_msg_port_info_set_reply {
  4247. + u32 status;
  4248. + u32 component_handle; /* component handle port is associated with */
  4249. + u32 port_type; /* enum mmal_msg_port_type */
  4250. + u32 index; /* port indexed in query */
  4251. + s32 found; /* unused */
  4252. + u32 port_handle; /**< Handle to use for this port */
  4253. + struct mmal_port port;
  4254. + struct mmal_es_format format;
  4255. + union mmal_es_specific_format es;
  4256. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  4257. +};
  4258. +
  4259. +
  4260. +/* port action requests that take a mmal_port as a parameter */
  4261. +struct mmal_msg_port_action_port {
  4262. + u32 component_handle;
  4263. + u32 port_handle;
  4264. + u32 action; /* enum mmal_msg_port_action_type */
  4265. + struct mmal_port port;
  4266. +};
  4267. +
  4268. +/* port action requests that take handles as a parameter */
  4269. +struct mmal_msg_port_action_handle {
  4270. + u32 component_handle;
  4271. + u32 port_handle;
  4272. + u32 action; /* enum mmal_msg_port_action_type */
  4273. + u32 connect_component_handle;
  4274. + u32 connect_port_handle;
  4275. +};
  4276. +
  4277. +struct mmal_msg_port_action_reply {
  4278. + u32 status; /** The port action operation status */
  4279. +};
  4280. +
  4281. +
  4282. +
  4283. +
  4284. +/* MMAL buffer transfer */
  4285. +
  4286. +/** Size of space reserved in a buffer message for short messages. */
  4287. +#define MMAL_VC_SHORT_DATA 128
  4288. +
  4289. +/** Signals that the current payload is the end of the stream of data */
  4290. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  4291. +/** Signals that the start of the current payload starts a frame */
  4292. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  4293. +/** Signals that the end of the current payload ends a frame */
  4294. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  4295. +/** Signals that the current payload contains only complete frames (>1) */
  4296. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  4297. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  4298. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  4299. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  4300. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  4301. + * Can be used for instance by a decoder to reset its state */
  4302. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  4303. +/** Signals a buffer containing some kind of config data for the component
  4304. + * (e.g. codec config data) */
  4305. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  4306. +/** Signals an encrypted payload */
  4307. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  4308. +/** Signals a buffer containing side information */
  4309. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  4310. +/** Signals a buffer which is the snapshot/postview image from a stills
  4311. + * capture
  4312. + */
  4313. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  4314. +/** Signals a buffer which contains data known to be corrupted */
  4315. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  4316. +/** Signals that a buffer failed to be transmitted */
  4317. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  4318. +
  4319. +struct mmal_driver_buffer {
  4320. + u32 magic;
  4321. + u32 component_handle;
  4322. + u32 port_handle;
  4323. + void *client_context;
  4324. +};
  4325. +
  4326. +/* buffer header */
  4327. +struct mmal_buffer_header {
  4328. + struct mmal_buffer_header *next; /* next header */
  4329. + void *priv; /* framework private data */
  4330. + u32 cmd;
  4331. + void *data;
  4332. + u32 alloc_size;
  4333. + u32 length;
  4334. + u32 offset;
  4335. + u32 flags;
  4336. + s64 pts;
  4337. + s64 dts;
  4338. + void *type;
  4339. + void *user_data;
  4340. +};
  4341. +
  4342. +struct mmal_buffer_header_type_specific {
  4343. + union {
  4344. + struct {
  4345. + u32 planes;
  4346. + u32 offset[4];
  4347. + u32 pitch[4];
  4348. + u32 flags;
  4349. + } video;
  4350. + } u;
  4351. +};
  4352. +
  4353. +struct mmal_msg_buffer_from_host {
  4354. + /* The front 32 bytes of the buffer header are copied
  4355. + * back to us in the reply to allow for context. This
  4356. + * area is used to store two mmal_driver_buffer structures to
  4357. + * allow for multiple concurrent service users.
  4358. + */
  4359. + /* control data */
  4360. + struct mmal_driver_buffer drvbuf;
  4361. +
  4362. + /* referenced control data for passthrough buffer management */
  4363. + struct mmal_driver_buffer drvbuf_ref;
  4364. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  4365. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  4366. + s32 is_zero_copy;
  4367. + s32 has_reference;
  4368. +
  4369. + /** allows short data to be xfered in control message */
  4370. + u32 payload_in_message;
  4371. + u8 short_data[MMAL_VC_SHORT_DATA];
  4372. +};
  4373. +
  4374. +
  4375. +/* port parameter setting */
  4376. +
  4377. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  4378. +
  4379. +struct mmal_msg_port_parameter_set {
  4380. + u32 component_handle; /* component */
  4381. + u32 port_handle; /* port */
  4382. + u32 id; /* Parameter ID */
  4383. + u32 size; /* Parameter size */
  4384. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  4385. +};
  4386. +
  4387. +struct mmal_msg_port_parameter_set_reply {
  4388. + u32 status; /** enum mmal_msg_status todo: how does this
  4389. + * differ to the one in the header?
  4390. + */
  4391. +};
  4392. +
  4393. +/* port parameter getting */
  4394. +
  4395. +struct mmal_msg_port_parameter_get {
  4396. + u32 component_handle; /* component */
  4397. + u32 port_handle; /* port */
  4398. + u32 id; /* Parameter ID */
  4399. + u32 size; /* Parameter size */
  4400. +};
  4401. +
  4402. +struct mmal_msg_port_parameter_get_reply {
  4403. + u32 status; /* Status of mmal_port_parameter_get call */
  4404. + u32 id; /* Parameter ID */
  4405. + u32 size; /* Parameter size */
  4406. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  4407. +};
  4408. +
  4409. +/* event messages */
  4410. +#define MMAL_WORKER_EVENT_SPACE 256
  4411. +
  4412. +struct mmal_msg_event_to_host {
  4413. + void *client_component; /* component context */
  4414. +
  4415. + u32 port_type;
  4416. + u32 port_num;
  4417. +
  4418. + u32 cmd;
  4419. + u32 length;
  4420. + u8 data[MMAL_WORKER_EVENT_SPACE];
  4421. + struct mmal_buffer_header *delayed_buffer;
  4422. +};
  4423. +
  4424. +/* all mmal messages are serialised through this structure */
  4425. +struct mmal_msg {
  4426. + /* header */
  4427. + struct mmal_msg_header h;
  4428. + /* payload */
  4429. + union {
  4430. + struct mmal_msg_version version;
  4431. +
  4432. + struct mmal_msg_component_create component_create;
  4433. + struct mmal_msg_component_create_reply component_create_reply;
  4434. +
  4435. + struct mmal_msg_component_destroy component_destroy;
  4436. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  4437. +
  4438. + struct mmal_msg_component_enable component_enable;
  4439. + struct mmal_msg_component_enable_reply component_enable_reply;
  4440. +
  4441. + struct mmal_msg_component_disable component_disable;
  4442. + struct mmal_msg_component_disable_reply component_disable_reply;
  4443. +
  4444. + struct mmal_msg_port_info_get port_info_get;
  4445. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  4446. +
  4447. + struct mmal_msg_port_info_set port_info_set;
  4448. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  4449. +
  4450. + struct mmal_msg_port_action_port port_action_port;
  4451. + struct mmal_msg_port_action_handle port_action_handle;
  4452. + struct mmal_msg_port_action_reply port_action_reply;
  4453. +
  4454. + struct mmal_msg_buffer_from_host buffer_from_host;
  4455. +
  4456. + struct mmal_msg_port_parameter_set port_parameter_set;
  4457. + struct mmal_msg_port_parameter_set_reply
  4458. + port_parameter_set_reply;
  4459. + struct mmal_msg_port_parameter_get
  4460. + port_parameter_get;
  4461. + struct mmal_msg_port_parameter_get_reply
  4462. + port_parameter_get_reply;
  4463. +
  4464. + struct mmal_msg_event_to_host event_to_host;
  4465. +
  4466. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  4467. + } u;
  4468. +};
  4469. --- /dev/null
  4470. +++ b/drivers/media/platform/bcm2835/mmal-parameters.h
  4471. @@ -0,0 +1,656 @@
  4472. +/*
  4473. + * Broadcom BM2835 V4L2 driver
  4474. + *
  4475. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  4476. + *
  4477. + * This file is subject to the terms and conditions of the GNU General Public
  4478. + * License. See the file COPYING in the main directory of this archive
  4479. + * for more details.
  4480. + *
  4481. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  4482. + * Dave Stevenson <dsteve@broadcom.com>
  4483. + * Simon Mellor <simellor@broadcom.com>
  4484. + * Luke Diamand <luked@broadcom.com>
  4485. + */
  4486. +
  4487. +/* common parameters */
  4488. +
  4489. +/** @name Parameter groups
  4490. + * Parameters are divided into groups, and then allocated sequentially within
  4491. + * a group using an enum.
  4492. + * @{
  4493. + */
  4494. +
  4495. +/** Common parameter ID group, used with many types of component. */
  4496. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  4497. +/** Camera-specific parameter ID group. */
  4498. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  4499. +/** Video-specific parameter ID group. */
  4500. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  4501. +/** Audio-specific parameter ID group. */
  4502. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  4503. +/** Clock-specific parameter ID group. */
  4504. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  4505. +/** Miracast-specific parameter ID group. */
  4506. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  4507. +
  4508. +/* Common parameters */
  4509. +enum mmal_parameter_common_type {
  4510. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  4511. + = MMAL_PARAMETER_GROUP_COMMON,
  4512. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  4513. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  4514. +
  4515. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  4516. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  4517. +
  4518. + /** MMAL_PARAMETER_BOOLEAN_T */
  4519. + MMAL_PARAMETER_ZERO_COPY,
  4520. +
  4521. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  4522. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  4523. +
  4524. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  4525. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  4526. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  4527. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  4528. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  4529. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  4530. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  4531. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  4532. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  4533. +};
  4534. +
  4535. +/* camera parameters */
  4536. +
  4537. +enum mmal_parameter_camera_type {
  4538. + /* 0 */
  4539. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  4540. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  4541. + = MMAL_PARAMETER_GROUP_CAMERA,
  4542. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  4543. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  4544. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4545. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  4546. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  4547. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  4548. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  4549. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  4550. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  4551. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  4552. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  4553. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  4554. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  4555. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  4556. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  4557. +
  4558. + /* 0x10 */
  4559. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  4560. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4561. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  4562. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  4563. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  4564. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  4565. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  4566. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  4567. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4568. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  4569. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  4570. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  4571. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  4572. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4573. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  4574. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4575. +
  4576. + /* 0x20 */
  4577. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  4578. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4579. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4580. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  4581. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  4582. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  4583. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  4584. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  4585. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  4586. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4587. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  4588. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  4589. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  4590. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  4591. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  4592. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  4593. +
  4594. + /* 0x30 */
  4595. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  4596. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4597. +
  4598. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  4599. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  4600. +
  4601. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4602. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  4603. +
  4604. + /** @ref MMAL_PARAMETER_UINT32_T */
  4605. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  4606. +
  4607. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  4608. + MMAL_PARAMETER_CAMERA_USE_CASE,
  4609. +
  4610. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4611. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  4612. +
  4613. + /** @ref MMAL_PARAMETER_UINT32_T */
  4614. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  4615. +
  4616. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4617. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  4618. +
  4619. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4620. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  4621. +
  4622. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  4623. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  4624. +
  4625. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  4626. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  4627. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4628. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  4629. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  4630. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  4631. +
  4632. + /* 0x40 */
  4633. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4634. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4635. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4636. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  4637. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  4638. +};
  4639. +
  4640. +struct mmal_parameter_rational {
  4641. + s32 num; /**< Numerator */
  4642. + s32 den; /**< Denominator */
  4643. +};
  4644. +
  4645. +enum mmal_parameter_camera_config_timestamp_mode {
  4646. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  4647. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  4648. + * for the frame timestamp
  4649. + */
  4650. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  4651. + * but subtract the
  4652. + * timestamp of the first
  4653. + * frame sent to give a
  4654. + * zero based timestamp.
  4655. + */
  4656. +};
  4657. +
  4658. +struct mmal_parameter_fps_range {
  4659. + /**< Low end of the permitted framerate range */
  4660. + struct mmal_parameter_rational fps_low;
  4661. + /**< High end of the permitted framerate range */
  4662. + struct mmal_parameter_rational fps_high;
  4663. +};
  4664. +
  4665. +
  4666. +/* camera configuration parameter */
  4667. +struct mmal_parameter_camera_config {
  4668. + /* Parameters for setting up the image pools */
  4669. + u32 max_stills_w; /* Max size of stills capture */
  4670. + u32 max_stills_h;
  4671. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  4672. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  4673. +
  4674. + u32 max_preview_video_w; /* Max size of the preview or video
  4675. + * capture frames
  4676. + */
  4677. + u32 max_preview_video_h;
  4678. + u32 num_preview_video_frames;
  4679. +
  4680. + /** Sets the height of the circular buffer for stills capture. */
  4681. + u32 stills_capture_circular_buffer_height;
  4682. +
  4683. + /** Allows preview/encode to resume as fast as possible after the stills
  4684. + * input frame has been received, and then processes the still frame in
  4685. + * the background whilst preview/encode has resumed.
  4686. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  4687. + */
  4688. + u32 fast_preview_resume;
  4689. +
  4690. + /** Selects algorithm for timestamping frames if
  4691. + * there is no clock component connected.
  4692. + * enum mmal_parameter_camera_config_timestamp_mode
  4693. + */
  4694. + s32 use_stc_timestamp;
  4695. +};
  4696. +
  4697. +
  4698. +enum mmal_parameter_exposuremode {
  4699. + MMAL_PARAM_EXPOSUREMODE_OFF,
  4700. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  4701. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  4702. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  4703. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  4704. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  4705. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  4706. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  4707. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  4708. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  4709. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  4710. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  4711. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  4712. +};
  4713. +
  4714. +enum mmal_parameter_exposuremeteringmode {
  4715. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  4716. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  4717. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  4718. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  4719. +};
  4720. +
  4721. +enum mmal_parameter_awbmode {
  4722. + MMAL_PARAM_AWBMODE_OFF,
  4723. + MMAL_PARAM_AWBMODE_AUTO,
  4724. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  4725. + MMAL_PARAM_AWBMODE_CLOUDY,
  4726. + MMAL_PARAM_AWBMODE_SHADE,
  4727. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  4728. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  4729. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  4730. + MMAL_PARAM_AWBMODE_FLASH,
  4731. + MMAL_PARAM_AWBMODE_HORIZON,
  4732. +};
  4733. +
  4734. +enum mmal_parameter_imagefx {
  4735. + MMAL_PARAM_IMAGEFX_NONE,
  4736. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  4737. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  4738. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  4739. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  4740. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  4741. + MMAL_PARAM_IMAGEFX_SKETCH,
  4742. + MMAL_PARAM_IMAGEFX_DENOISE,
  4743. + MMAL_PARAM_IMAGEFX_EMBOSS,
  4744. + MMAL_PARAM_IMAGEFX_OILPAINT,
  4745. + MMAL_PARAM_IMAGEFX_HATCH,
  4746. + MMAL_PARAM_IMAGEFX_GPEN,
  4747. + MMAL_PARAM_IMAGEFX_PASTEL,
  4748. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  4749. + MMAL_PARAM_IMAGEFX_FILM,
  4750. + MMAL_PARAM_IMAGEFX_BLUR,
  4751. + MMAL_PARAM_IMAGEFX_SATURATION,
  4752. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  4753. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  4754. + MMAL_PARAM_IMAGEFX_POSTERISE,
  4755. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  4756. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  4757. + MMAL_PARAM_IMAGEFX_CARTOON,
  4758. +};
  4759. +
  4760. +enum MMAL_PARAM_FLICKERAVOID_T {
  4761. + MMAL_PARAM_FLICKERAVOID_OFF,
  4762. + MMAL_PARAM_FLICKERAVOID_AUTO,
  4763. + MMAL_PARAM_FLICKERAVOID_50HZ,
  4764. + MMAL_PARAM_FLICKERAVOID_60HZ,
  4765. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  4766. +};
  4767. +
  4768. +struct mmal_parameter_awbgains {
  4769. + struct mmal_parameter_rational r_gain; /**< Red gain */
  4770. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  4771. +};
  4772. +
  4773. +/** Manner of video rate control */
  4774. +enum mmal_parameter_rate_control_mode {
  4775. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  4776. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  4777. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  4778. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  4779. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  4780. +};
  4781. +
  4782. +enum mmal_video_profile {
  4783. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  4784. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  4785. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  4786. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  4787. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  4788. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  4789. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  4790. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  4791. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  4792. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  4793. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  4794. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  4795. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  4796. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  4797. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  4798. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  4799. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  4800. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  4801. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  4802. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  4803. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  4804. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  4805. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  4806. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  4807. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  4808. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  4809. + MMAL_VIDEO_PROFILE_H264_MAIN,
  4810. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  4811. + MMAL_VIDEO_PROFILE_H264_HIGH,
  4812. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  4813. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  4814. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  4815. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  4816. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  4817. +};
  4818. +
  4819. +enum mmal_video_level {
  4820. + MMAL_VIDEO_LEVEL_H263_10,
  4821. + MMAL_VIDEO_LEVEL_H263_20,
  4822. + MMAL_VIDEO_LEVEL_H263_30,
  4823. + MMAL_VIDEO_LEVEL_H263_40,
  4824. + MMAL_VIDEO_LEVEL_H263_45,
  4825. + MMAL_VIDEO_LEVEL_H263_50,
  4826. + MMAL_VIDEO_LEVEL_H263_60,
  4827. + MMAL_VIDEO_LEVEL_H263_70,
  4828. + MMAL_VIDEO_LEVEL_MP4V_0,
  4829. + MMAL_VIDEO_LEVEL_MP4V_0b,
  4830. + MMAL_VIDEO_LEVEL_MP4V_1,
  4831. + MMAL_VIDEO_LEVEL_MP4V_2,
  4832. + MMAL_VIDEO_LEVEL_MP4V_3,
  4833. + MMAL_VIDEO_LEVEL_MP4V_4,
  4834. + MMAL_VIDEO_LEVEL_MP4V_4a,
  4835. + MMAL_VIDEO_LEVEL_MP4V_5,
  4836. + MMAL_VIDEO_LEVEL_MP4V_6,
  4837. + MMAL_VIDEO_LEVEL_H264_1,
  4838. + MMAL_VIDEO_LEVEL_H264_1b,
  4839. + MMAL_VIDEO_LEVEL_H264_11,
  4840. + MMAL_VIDEO_LEVEL_H264_12,
  4841. + MMAL_VIDEO_LEVEL_H264_13,
  4842. + MMAL_VIDEO_LEVEL_H264_2,
  4843. + MMAL_VIDEO_LEVEL_H264_21,
  4844. + MMAL_VIDEO_LEVEL_H264_22,
  4845. + MMAL_VIDEO_LEVEL_H264_3,
  4846. + MMAL_VIDEO_LEVEL_H264_31,
  4847. + MMAL_VIDEO_LEVEL_H264_32,
  4848. + MMAL_VIDEO_LEVEL_H264_4,
  4849. + MMAL_VIDEO_LEVEL_H264_41,
  4850. + MMAL_VIDEO_LEVEL_H264_42,
  4851. + MMAL_VIDEO_LEVEL_H264_5,
  4852. + MMAL_VIDEO_LEVEL_H264_51,
  4853. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  4854. +};
  4855. +
  4856. +struct mmal_parameter_video_profile {
  4857. + enum mmal_video_profile profile;
  4858. + enum mmal_video_level level;
  4859. +};
  4860. +
  4861. +/* video parameters */
  4862. +
  4863. +enum mmal_parameter_video_type {
  4864. + /** @ref MMAL_DISPLAYREGION_T */
  4865. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  4866. +
  4867. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  4868. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  4869. +
  4870. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  4871. + MMAL_PARAMETER_PROFILE,
  4872. +
  4873. + /** @ref MMAL_PARAMETER_UINT32_T */
  4874. + MMAL_PARAMETER_INTRAPERIOD,
  4875. +
  4876. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  4877. + MMAL_PARAMETER_RATECONTROL,
  4878. +
  4879. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  4880. + MMAL_PARAMETER_NALUNITFORMAT,
  4881. +
  4882. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4883. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  4884. +
  4885. + /** @ref MMAL_PARAMETER_UINT32_T.
  4886. + * Setting the value to zero resets to the default (one slice per frame).
  4887. + */
  4888. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  4889. +
  4890. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  4891. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  4892. +
  4893. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  4894. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  4895. +
  4896. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  4897. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  4898. +
  4899. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  4900. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  4901. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  4902. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  4903. +
  4904. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  4905. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  4906. +
  4907. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  4908. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  4909. +
  4910. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  4911. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  4912. +
  4913. + /** @ref MMAL_PARAMETER_UINT32_T. */
  4914. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  4915. +
  4916. + /** @ref MMAL_PARAMETER_UINT32_T. */
  4917. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  4918. +
  4919. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  4920. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  4921. +
  4922. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  4923. + /** @ref MMAL_PARAMETER_UINT32_T.
  4924. + * Changing this parameter from the default can reduce frame rate
  4925. + * because image buffers need to be re-pitched.
  4926. + */
  4927. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  4928. +
  4929. + /** @ref MMAL_PARAMETER_UINT32_T.
  4930. + * Changing this parameter from the default can reduce frame rate
  4931. + * because image buffers need to be re-pitched.
  4932. + */
  4933. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  4934. +
  4935. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  4936. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  4937. +
  4938. + /** @ref MMAL_PARAMETER_UINT32_T. */
  4939. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  4940. +
  4941. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  4942. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  4943. +
  4944. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  4945. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  4946. +
  4947. + /** @ref MMAL_PARAMETER_UINT32_T */
  4948. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  4949. +
  4950. + /** @ref MMAL_PARAMETER_UINT32_T. */
  4951. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  4952. +
  4953. + /* H264 specific parameters */
  4954. +
  4955. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  4956. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  4957. +
  4958. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  4959. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  4960. +
  4961. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  4962. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  4963. +
  4964. + /** @ref MMAL_PARAMETER_UINT32_T. */
  4965. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  4966. +
  4967. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  4968. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  4969. +
  4970. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4971. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  4972. +
  4973. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4974. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  4975. +
  4976. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  4977. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  4978. +
  4979. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4980. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  4981. +
  4982. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  4983. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  4984. +
  4985. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  4986. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  4987. +
  4988. + /** @ref MMAL_PARAMETER_BYTES_T */
  4989. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  4990. +
  4991. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4992. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  4993. +
  4994. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4995. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  4996. +
  4997. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  4998. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  4999. +};
  5000. +
  5001. +/** Valid mirror modes */
  5002. +enum mmal_parameter_mirror {
  5003. + MMAL_PARAM_MIRROR_NONE,
  5004. + MMAL_PARAM_MIRROR_VERTICAL,
  5005. + MMAL_PARAM_MIRROR_HORIZONTAL,
  5006. + MMAL_PARAM_MIRROR_BOTH,
  5007. +};
  5008. +
  5009. +enum mmal_parameter_displaytransform {
  5010. + MMAL_DISPLAY_ROT0 = 0,
  5011. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  5012. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  5013. + MMAL_DISPLAY_ROT180 = 3,
  5014. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  5015. + MMAL_DISPLAY_ROT270 = 5,
  5016. + MMAL_DISPLAY_ROT90 = 6,
  5017. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  5018. +};
  5019. +
  5020. +enum mmal_parameter_displaymode {
  5021. + MMAL_DISPLAY_MODE_FILL = 0,
  5022. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  5023. +};
  5024. +
  5025. +enum mmal_parameter_displayset {
  5026. + MMAL_DISPLAY_SET_NONE = 0,
  5027. + MMAL_DISPLAY_SET_NUM = 1,
  5028. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  5029. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  5030. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  5031. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  5032. + MMAL_DISPLAY_SET_MODE = 0x20,
  5033. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  5034. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  5035. + MMAL_DISPLAY_SET_LAYER = 0x100,
  5036. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  5037. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  5038. +};
  5039. +
  5040. +struct mmal_parameter_displayregion {
  5041. + /** Bitfield that indicates which fields are set and should be
  5042. + * used. All other fields will maintain their current value.
  5043. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  5044. + * combined.
  5045. + */
  5046. + u32 set;
  5047. +
  5048. + /** Describes the display output device, with 0 typically
  5049. + * being a directly connected LCD display. The actual values
  5050. + * will depend on the hardware. Code using hard-wired numbers
  5051. + * (e.g. 2) is certain to fail.
  5052. + */
  5053. +
  5054. + u32 display_num;
  5055. + /** Indicates that we are using the full device screen area,
  5056. + * rather than a window of the display. If zero, then
  5057. + * dest_rect is used to specify a region of the display to
  5058. + * use.
  5059. + */
  5060. +
  5061. + s32 fullscreen;
  5062. + /** Indicates any rotation or flipping used to map frames onto
  5063. + * the natural display orientation.
  5064. + */
  5065. + u32 transform; /* enum mmal_parameter_displaytransform */
  5066. +
  5067. + /** Where to display the frame within the screen, if
  5068. + * fullscreen is zero.
  5069. + */
  5070. + struct vchiq_mmal_rect dest_rect;
  5071. +
  5072. + /** Indicates which area of the frame to display. If all
  5073. + * values are zero, the whole frame will be used.
  5074. + */
  5075. + struct vchiq_mmal_rect src_rect;
  5076. +
  5077. + /** If set to non-zero, indicates that any display scaling
  5078. + * should disregard the aspect ratio of the frame region being
  5079. + * displayed.
  5080. + */
  5081. + s32 noaspect;
  5082. +
  5083. + /** Indicates how the image should be scaled to fit the
  5084. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  5085. + * that the image should fill the screen by potentially
  5086. + * cropping the frames. Setting \code mode \endcode to \code
  5087. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  5088. + * source region should be displayed and black bars added if
  5089. + * necessary.
  5090. + */
  5091. + u32 mode; /* enum mmal_parameter_displaymode */
  5092. +
  5093. + /** If non-zero, defines the width of a source pixel relative
  5094. + * to \code pixel_y \endcode. If zero, then pixels default to
  5095. + * being square.
  5096. + */
  5097. + u32 pixel_x;
  5098. +
  5099. + /** If non-zero, defines the height of a source pixel relative
  5100. + * to \code pixel_x \endcode. If zero, then pixels default to
  5101. + * being square.
  5102. + */
  5103. + u32 pixel_y;
  5104. +
  5105. + /** Sets the relative depth of the images, with greater values
  5106. + * being in front of smaller values.
  5107. + */
  5108. + u32 layer;
  5109. +
  5110. + /** Set to non-zero to ensure copy protection is used on
  5111. + * output.
  5112. + */
  5113. + s32 copyprotect_required;
  5114. +
  5115. + /** Level of opacity of the layer, where zero is fully
  5116. + * transparent and 255 is fully opaque.
  5117. + */
  5118. + u32 alpha;
  5119. +};
  5120. +
  5121. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  5122. +
  5123. +struct mmal_parameter_imagefx_parameters {
  5124. + enum mmal_parameter_imagefx effect;
  5125. + u32 num_effect_params;
  5126. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  5127. +};
  5128. --- /dev/null
  5129. +++ b/drivers/media/platform/bcm2835/mmal-vchiq.c
  5130. @@ -0,0 +1,1916 @@
  5131. +/*
  5132. + * Broadcom BM2835 V4L2 driver
  5133. + *
  5134. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  5135. + *
  5136. + * This file is subject to the terms and conditions of the GNU General Public
  5137. + * License. See the file COPYING in the main directory of this archive
  5138. + * for more details.
  5139. + *
  5140. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  5141. + * Dave Stevenson <dsteve@broadcom.com>
  5142. + * Simon Mellor <simellor@broadcom.com>
  5143. + * Luke Diamand <luked@broadcom.com>
  5144. + *
  5145. + * V4L2 driver MMAL vchiq interface code
  5146. + */
  5147. +
  5148. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  5149. +
  5150. +#include <linux/errno.h>
  5151. +#include <linux/kernel.h>
  5152. +#include <linux/mutex.h>
  5153. +#include <linux/mm.h>
  5154. +#include <linux/slab.h>
  5155. +#include <linux/completion.h>
  5156. +#include <linux/vmalloc.h>
  5157. +#include <asm/cacheflush.h>
  5158. +#include <media/videobuf2-vmalloc.h>
  5159. +
  5160. +#include "mmal-common.h"
  5161. +#include "mmal-vchiq.h"
  5162. +#include "mmal-msg.h"
  5163. +
  5164. +#define USE_VCHIQ_ARM
  5165. +#include "interface/vchi/vchi.h"
  5166. +
  5167. +/* maximum number of components supported */
  5168. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  5169. +
  5170. +/*#define FULL_MSG_DUMP 1*/
  5171. +
  5172. +#ifdef DEBUG
  5173. +static const char *const msg_type_names[] = {
  5174. + "UNKNOWN",
  5175. + "QUIT",
  5176. + "SERVICE_CLOSED",
  5177. + "GET_VERSION",
  5178. + "COMPONENT_CREATE",
  5179. + "COMPONENT_DESTROY",
  5180. + "COMPONENT_ENABLE",
  5181. + "COMPONENT_DISABLE",
  5182. + "PORT_INFO_GET",
  5183. + "PORT_INFO_SET",
  5184. + "PORT_ACTION",
  5185. + "BUFFER_FROM_HOST",
  5186. + "BUFFER_TO_HOST",
  5187. + "GET_STATS",
  5188. + "PORT_PARAMETER_SET",
  5189. + "PORT_PARAMETER_GET",
  5190. + "EVENT_TO_HOST",
  5191. + "GET_CORE_STATS_FOR_PORT",
  5192. + "OPAQUE_ALLOCATOR",
  5193. + "CONSUME_MEM",
  5194. + "LMK",
  5195. + "OPAQUE_ALLOCATOR_DESC",
  5196. + "DRM_GET_LHS32",
  5197. + "DRM_GET_TIME",
  5198. + "BUFFER_FROM_HOST_ZEROLEN",
  5199. + "PORT_FLUSH",
  5200. + "HOST_LOG",
  5201. +};
  5202. +#endif
  5203. +
  5204. +static const char *const port_action_type_names[] = {
  5205. + "UNKNOWN",
  5206. + "ENABLE",
  5207. + "DISABLE",
  5208. + "FLUSH",
  5209. + "CONNECT",
  5210. + "DISCONNECT",
  5211. + "SET_REQUIREMENTS",
  5212. +};
  5213. +
  5214. +#if defined(DEBUG)
  5215. +#if defined(FULL_MSG_DUMP)
  5216. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  5217. + do { \
  5218. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  5219. + msg_type_names[(MSG)->h.type], \
  5220. + (MSG)->h.type, (MSG_LEN)); \
  5221. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  5222. + 16, 4, (MSG), \
  5223. + sizeof(struct mmal_msg_header), 1); \
  5224. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  5225. + 16, 4, \
  5226. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  5227. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  5228. + } while (0)
  5229. +#else
  5230. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  5231. + { \
  5232. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  5233. + msg_type_names[(MSG)->h.type], \
  5234. + (MSG)->h.type, (MSG_LEN)); \
  5235. + }
  5236. +#endif
  5237. +#else
  5238. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  5239. +#endif
  5240. +
  5241. +/* normal message context */
  5242. +struct mmal_msg_context {
  5243. + union {
  5244. + struct {
  5245. + /* work struct for defered callback - must come first */
  5246. + struct work_struct work;
  5247. + /* mmal instance */
  5248. + struct vchiq_mmal_instance *instance;
  5249. + /* mmal port */
  5250. + struct vchiq_mmal_port *port;
  5251. + /* actual buffer used to store bulk reply */
  5252. + struct mmal_buffer *buffer;
  5253. + /* amount of buffer used */
  5254. + unsigned long buffer_used;
  5255. + /* MMAL buffer flags */
  5256. + u32 mmal_flags;
  5257. + /* Presentation and Decode timestamps */
  5258. + s64 pts;
  5259. + s64 dts;
  5260. +
  5261. + int status; /* context status */
  5262. +
  5263. + } bulk; /* bulk data */
  5264. +
  5265. + struct {
  5266. + /* message handle to release */
  5267. + VCHI_HELD_MSG_T msg_handle;
  5268. + /* pointer to received message */
  5269. + struct mmal_msg *msg;
  5270. + /* received message length */
  5271. + u32 msg_len;
  5272. + /* completion upon reply */
  5273. + struct completion cmplt;
  5274. + } sync; /* synchronous response */
  5275. + } u;
  5276. +
  5277. +};
  5278. +
  5279. +struct vchiq_mmal_instance {
  5280. + VCHI_SERVICE_HANDLE_T handle;
  5281. +
  5282. + /* ensure serialised access to service */
  5283. + struct mutex vchiq_mutex;
  5284. +
  5285. + /* ensure serialised access to bulk operations */
  5286. + struct mutex bulk_mutex;
  5287. +
  5288. + /* vmalloc page to receive scratch bulk xfers into */
  5289. + void *bulk_scratch;
  5290. +
  5291. + /* component to use next */
  5292. + int component_idx;
  5293. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  5294. +};
  5295. +
  5296. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  5297. + *instance)
  5298. +{
  5299. + struct mmal_msg_context *msg_context;
  5300. +
  5301. + /* todo: should this be allocated from a pool to avoid kmalloc */
  5302. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  5303. + memset(msg_context, 0, sizeof(*msg_context));
  5304. +
  5305. + return msg_context;
  5306. +}
  5307. +
  5308. +static void release_msg_context(struct mmal_msg_context *msg_context)
  5309. +{
  5310. + kfree(msg_context);
  5311. +}
  5312. +
  5313. +/* deals with receipt of event to host message */
  5314. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  5315. + struct mmal_msg *msg, u32 msg_len)
  5316. +{
  5317. + pr_debug("unhandled event\n");
  5318. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  5319. + msg->u.event_to_host.client_component,
  5320. + msg->u.event_to_host.port_type,
  5321. + msg->u.event_to_host.port_num,
  5322. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  5323. +}
  5324. +
  5325. +/* workqueue scheduled callback
  5326. + *
  5327. + * we do this because it is important we do not call any other vchiq
  5328. + * sync calls from witin the message delivery thread
  5329. + */
  5330. +static void buffer_work_cb(struct work_struct *work)
  5331. +{
  5332. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  5333. +
  5334. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  5335. + msg_context->u.bulk.port,
  5336. + msg_context->u.bulk.status,
  5337. + msg_context->u.bulk.buffer,
  5338. + msg_context->u.bulk.buffer_used,
  5339. + msg_context->u.bulk.mmal_flags,
  5340. + msg_context->u.bulk.dts,
  5341. + msg_context->u.bulk.pts);
  5342. +
  5343. + /* release message context */
  5344. + release_msg_context(msg_context);
  5345. +}
  5346. +
  5347. +/* enqueue a bulk receive for a given message context */
  5348. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  5349. + struct mmal_msg *msg,
  5350. + struct mmal_msg_context *msg_context)
  5351. +{
  5352. + unsigned long rd_len;
  5353. + unsigned long flags = 0;
  5354. + int ret;
  5355. +
  5356. + /* bulk mutex stops other bulk operations while we have a
  5357. + * receive in progress - released in callback
  5358. + */
  5359. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  5360. + if (ret != 0)
  5361. + return ret;
  5362. +
  5363. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  5364. +
  5365. + /* take buffer from queue */
  5366. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  5367. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  5368. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  5369. + pr_err("buffer list empty trying to submit bulk receive\n");
  5370. +
  5371. + /* todo: this is a serious error, we should never have
  5372. + * commited a buffer_to_host operation to the mmal
  5373. + * port without the buffer to back it up (underflow
  5374. + * handling) and there is no obvious way to deal with
  5375. + * this - how is the mmal servie going to react when
  5376. + * we fail to do the xfer and reschedule a buffer when
  5377. + * it arrives? perhaps a starved flag to indicate a
  5378. + * waiting bulk receive?
  5379. + */
  5380. +
  5381. + mutex_unlock(&instance->bulk_mutex);
  5382. +
  5383. + return -EINVAL;
  5384. + }
  5385. +
  5386. + msg_context->u.bulk.buffer =
  5387. + list_entry(msg_context->u.bulk.port->buffers.next,
  5388. + struct mmal_buffer, list);
  5389. + list_del(&msg_context->u.bulk.buffer->list);
  5390. +
  5391. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  5392. +
  5393. + /* ensure we do not overrun the available buffer */
  5394. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  5395. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  5396. + pr_warn("short read as not enough receive buffer space\n");
  5397. + /* todo: is this the correct response, what happens to
  5398. + * the rest of the message data?
  5399. + */
  5400. + }
  5401. +
  5402. + /* store length */
  5403. + msg_context->u.bulk.buffer_used = rd_len;
  5404. + msg_context->u.bulk.mmal_flags =
  5405. + msg->u.buffer_from_host.buffer_header.flags;
  5406. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  5407. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  5408. +
  5409. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  5410. + // cache.
  5411. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  5412. +
  5413. + /* queue the bulk submission */
  5414. + vchi_service_use(instance->handle);
  5415. + ret = vchi_bulk_queue_receive(instance->handle,
  5416. + msg_context->u.bulk.buffer->buffer,
  5417. + /* Actual receive needs to be a multiple
  5418. + * of 4 bytes
  5419. + */
  5420. + (rd_len + 3) & ~3,
  5421. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  5422. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  5423. + msg_context);
  5424. +
  5425. + vchi_service_release(instance->handle);
  5426. +
  5427. + if (ret != 0) {
  5428. + /* callback will not be clearing the mutex */
  5429. + mutex_unlock(&instance->bulk_mutex);
  5430. + }
  5431. +
  5432. + return ret;
  5433. +}
  5434. +
  5435. +/* enque a dummy bulk receive for a given message context */
  5436. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  5437. + struct mmal_msg_context *msg_context)
  5438. +{
  5439. + int ret;
  5440. +
  5441. + /* bulk mutex stops other bulk operations while we have a
  5442. + * receive in progress - released in callback
  5443. + */
  5444. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  5445. + if (ret != 0)
  5446. + return ret;
  5447. +
  5448. + /* zero length indicates this was a dummy transfer */
  5449. + msg_context->u.bulk.buffer_used = 0;
  5450. +
  5451. + /* queue the bulk submission */
  5452. + vchi_service_use(instance->handle);
  5453. +
  5454. + ret = vchi_bulk_queue_receive(instance->handle,
  5455. + instance->bulk_scratch,
  5456. + 8,
  5457. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  5458. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  5459. + msg_context);
  5460. +
  5461. + vchi_service_release(instance->handle);
  5462. +
  5463. + if (ret != 0) {
  5464. + /* callback will not be clearing the mutex */
  5465. + mutex_unlock(&instance->bulk_mutex);
  5466. + }
  5467. +
  5468. + return ret;
  5469. +}
  5470. +
  5471. +/* data in message, memcpy from packet into output buffer */
  5472. +static int inline_receive(struct vchiq_mmal_instance *instance,
  5473. + struct mmal_msg *msg,
  5474. + struct mmal_msg_context *msg_context)
  5475. +{
  5476. + unsigned long flags = 0;
  5477. +
  5478. + /* take buffer from queue */
  5479. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  5480. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  5481. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  5482. + pr_err("buffer list empty trying to receive inline\n");
  5483. +
  5484. + /* todo: this is a serious error, we should never have
  5485. + * commited a buffer_to_host operation to the mmal
  5486. + * port without the buffer to back it up (with
  5487. + * underflow handling) and there is no obvious way to
  5488. + * deal with this. Less bad than the bulk case as we
  5489. + * can just drop this on the floor but...unhelpful
  5490. + */
  5491. + return -EINVAL;
  5492. + }
  5493. +
  5494. + msg_context->u.bulk.buffer =
  5495. + list_entry(msg_context->u.bulk.port->buffers.next,
  5496. + struct mmal_buffer, list);
  5497. + list_del(&msg_context->u.bulk.buffer->list);
  5498. +
  5499. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  5500. +
  5501. + memcpy(msg_context->u.bulk.buffer->buffer,
  5502. + msg->u.buffer_from_host.short_data,
  5503. + msg->u.buffer_from_host.payload_in_message);
  5504. +
  5505. + msg_context->u.bulk.buffer_used =
  5506. + msg->u.buffer_from_host.payload_in_message;
  5507. +
  5508. + return 0;
  5509. +}
  5510. +
  5511. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  5512. +static int
  5513. +buffer_from_host(struct vchiq_mmal_instance *instance,
  5514. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  5515. +{
  5516. + struct mmal_msg_context *msg_context;
  5517. + struct mmal_msg m;
  5518. + int ret;
  5519. +
  5520. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  5521. +
  5522. + /* bulk mutex stops other bulk operations while we
  5523. + * have a receive in progress
  5524. + */
  5525. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  5526. + return -EINTR;
  5527. +
  5528. + /* get context */
  5529. + msg_context = get_msg_context(instance);
  5530. + if (msg_context == NULL)
  5531. + return -ENOMEM;
  5532. +
  5533. + /* store bulk message context for when data arrives */
  5534. + msg_context->u.bulk.instance = instance;
  5535. + msg_context->u.bulk.port = port;
  5536. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  5537. + msg_context->u.bulk.buffer_used = 0;
  5538. +
  5539. + /* initialise work structure ready to schedule callback */
  5540. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  5541. +
  5542. + /* prep the buffer from host message */
  5543. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  5544. +
  5545. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  5546. + m.h.magic = MMAL_MAGIC;
  5547. + m.h.context = msg_context;
  5548. + m.h.status = 0;
  5549. +
  5550. + /* drvbuf is our private data passed back */
  5551. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  5552. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  5553. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  5554. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  5555. +
  5556. + /* buffer header */
  5557. + m.u.buffer_from_host.buffer_header.cmd = 0;
  5558. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  5559. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  5560. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  5561. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  5562. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  5563. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  5564. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  5565. +
  5566. + /* clear buffer type sepecific data */
  5567. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  5568. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  5569. +
  5570. + /* no payload in message */
  5571. + m.u.buffer_from_host.payload_in_message = 0;
  5572. +
  5573. + vchi_service_use(instance->handle);
  5574. +
  5575. + ret = vchi_msg_queue(instance->handle, &m,
  5576. + sizeof(struct mmal_msg_header) +
  5577. + sizeof(m.u.buffer_from_host),
  5578. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  5579. +
  5580. + if (ret != 0) {
  5581. + release_msg_context(msg_context);
  5582. + /* todo: is this correct error value? */
  5583. + }
  5584. +
  5585. + vchi_service_release(instance->handle);
  5586. +
  5587. + mutex_unlock(&instance->bulk_mutex);
  5588. +
  5589. + return ret;
  5590. +}
  5591. +
  5592. +/* submit a buffer to the mmal sevice
  5593. + *
  5594. + * the buffer_from_host uses size data from the ports next available
  5595. + * mmal_buffer and deals with there being no buffer available by
  5596. + * incrementing the underflow for later
  5597. + */
  5598. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  5599. + struct vchiq_mmal_port *port)
  5600. +{
  5601. + int ret;
  5602. + struct mmal_buffer *buf;
  5603. + unsigned long flags = 0;
  5604. +
  5605. + if (!port->enabled)
  5606. + return -EINVAL;
  5607. +
  5608. + /* peek buffer from queue */
  5609. + spin_lock_irqsave(&port->slock, flags);
  5610. + if (list_empty(&port->buffers)) {
  5611. + port->buffer_underflow++;
  5612. + spin_unlock_irqrestore(&port->slock, flags);
  5613. + return -ENOSPC;
  5614. + }
  5615. +
  5616. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  5617. +
  5618. + spin_unlock_irqrestore(&port->slock, flags);
  5619. +
  5620. + /* issue buffer to mmal service */
  5621. + ret = buffer_from_host(instance, port, buf);
  5622. + if (ret) {
  5623. + pr_err("adding buffer header failed\n");
  5624. + /* todo: how should this be dealt with */
  5625. + }
  5626. +
  5627. + return ret;
  5628. +}
  5629. +
  5630. +/* deals with receipt of buffer to host message */
  5631. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  5632. + struct mmal_msg *msg, u32 msg_len)
  5633. +{
  5634. + struct mmal_msg_context *msg_context;
  5635. +
  5636. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  5637. + instance, msg, msg_len);
  5638. +
  5639. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  5640. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  5641. + } else {
  5642. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  5643. + return;
  5644. + }
  5645. +
  5646. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  5647. + /* message reception had an error */
  5648. + pr_warn("error %d in reply\n", msg->h.status);
  5649. +
  5650. + msg_context->u.bulk.status = msg->h.status;
  5651. +
  5652. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  5653. + /* empty buffer */
  5654. + if (msg->u.buffer_from_host.buffer_header.flags &
  5655. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  5656. + msg_context->u.bulk.status =
  5657. + dummy_bulk_receive(instance, msg_context);
  5658. + if (msg_context->u.bulk.status == 0)
  5659. + return; /* successful bulk submission, bulk
  5660. + * completion will trigger callback
  5661. + */
  5662. + } else {
  5663. + /* do callback with empty buffer - not EOS though */
  5664. + msg_context->u.bulk.status = 0;
  5665. + msg_context->u.bulk.buffer_used = 0;
  5666. + }
  5667. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  5668. + /* data is not in message, queue a bulk receive */
  5669. + msg_context->u.bulk.status =
  5670. + bulk_receive(instance, msg, msg_context);
  5671. + if (msg_context->u.bulk.status == 0)
  5672. + return; /* successful bulk submission, bulk
  5673. + * completion will trigger callback
  5674. + */
  5675. +
  5676. + /* failed to submit buffer, this will end badly */
  5677. + pr_err("error %d on bulk submission\n",
  5678. + msg_context->u.bulk.status);
  5679. +
  5680. + } else if (msg->u.buffer_from_host.payload_in_message <=
  5681. + MMAL_VC_SHORT_DATA) {
  5682. + /* data payload within message */
  5683. + msg_context->u.bulk.status = inline_receive(instance, msg,
  5684. + msg_context);
  5685. + } else {
  5686. + pr_err("message with invalid short payload\n");
  5687. +
  5688. + /* signal error */
  5689. + msg_context->u.bulk.status = -EINVAL;
  5690. + msg_context->u.bulk.buffer_used =
  5691. + msg->u.buffer_from_host.payload_in_message;
  5692. + }
  5693. +
  5694. + /* replace the buffer header */
  5695. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  5696. +
  5697. + /* schedule the port callback */
  5698. + schedule_work(&msg_context->u.bulk.work);
  5699. +}
  5700. +
  5701. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  5702. + struct mmal_msg_context *msg_context)
  5703. +{
  5704. + /* bulk receive operation complete */
  5705. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  5706. +
  5707. + /* replace the buffer header */
  5708. + port_buffer_from_host(msg_context->u.bulk.instance,
  5709. + msg_context->u.bulk.port);
  5710. +
  5711. + msg_context->u.bulk.status = 0;
  5712. +
  5713. + /* schedule the port callback */
  5714. + schedule_work(&msg_context->u.bulk.work);
  5715. +}
  5716. +
  5717. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  5718. + struct mmal_msg_context *msg_context)
  5719. +{
  5720. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  5721. +
  5722. + /* bulk receive operation complete */
  5723. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  5724. +
  5725. + /* replace the buffer header */
  5726. + port_buffer_from_host(msg_context->u.bulk.instance,
  5727. + msg_context->u.bulk.port);
  5728. +
  5729. + msg_context->u.bulk.status = -EINTR;
  5730. +
  5731. + schedule_work(&msg_context->u.bulk.work);
  5732. +}
  5733. +
  5734. +/* incoming event service callback */
  5735. +static void service_callback(void *param,
  5736. + const VCHI_CALLBACK_REASON_T reason,
  5737. + void *bulk_ctx)
  5738. +{
  5739. + struct vchiq_mmal_instance *instance = param;
  5740. + int status;
  5741. + u32 msg_len;
  5742. + struct mmal_msg *msg;
  5743. + VCHI_HELD_MSG_T msg_handle;
  5744. +
  5745. + if (!instance) {
  5746. + pr_err("Message callback passed NULL instance\n");
  5747. + return;
  5748. + }
  5749. +
  5750. + switch (reason) {
  5751. + case VCHI_CALLBACK_MSG_AVAILABLE:
  5752. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  5753. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  5754. + if (status) {
  5755. + pr_err("Unable to dequeue a message (%d)\n", status);
  5756. + break;
  5757. + }
  5758. +
  5759. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  5760. +
  5761. + /* handling is different for buffer messages */
  5762. + switch (msg->h.type) {
  5763. +
  5764. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  5765. + vchi_held_msg_release(&msg_handle);
  5766. + break;
  5767. +
  5768. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  5769. + event_to_host_cb(instance, msg, msg_len);
  5770. + vchi_held_msg_release(&msg_handle);
  5771. +
  5772. + break;
  5773. +
  5774. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  5775. + buffer_to_host_cb(instance, msg, msg_len);
  5776. + vchi_held_msg_release(&msg_handle);
  5777. + break;
  5778. +
  5779. + default:
  5780. + /* messages dependant on header context to complete */
  5781. +
  5782. + /* todo: the msg.context really ought to be sanity
  5783. + * checked before we just use it, afaict it comes back
  5784. + * and is used raw from the videocore. Perhaps it
  5785. + * should be verified the address lies in the kernel
  5786. + * address space.
  5787. + */
  5788. + if (msg->h.context == NULL) {
  5789. + pr_err("received message context was null!\n");
  5790. + vchi_held_msg_release(&msg_handle);
  5791. + break;
  5792. + }
  5793. +
  5794. + /* fill in context values */
  5795. + msg->h.context->u.sync.msg_handle = msg_handle;
  5796. + msg->h.context->u.sync.msg = msg;
  5797. + msg->h.context->u.sync.msg_len = msg_len;
  5798. +
  5799. + /* todo: should this check (completion_done()
  5800. + * == 1) for no one waiting? or do we need a
  5801. + * flag to tell us the completion has been
  5802. + * interrupted so we can free the message and
  5803. + * its context. This probably also solves the
  5804. + * message arriving after interruption todo
  5805. + * below
  5806. + */
  5807. +
  5808. + /* complete message so caller knows it happened */
  5809. + complete(&msg->h.context->u.sync.cmplt);
  5810. + break;
  5811. + }
  5812. +
  5813. + break;
  5814. +
  5815. + case VCHI_CALLBACK_BULK_RECEIVED:
  5816. + bulk_receive_cb(instance, bulk_ctx);
  5817. + break;
  5818. +
  5819. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  5820. + bulk_abort_cb(instance, bulk_ctx);
  5821. + break;
  5822. +
  5823. + case VCHI_CALLBACK_SERVICE_CLOSED:
  5824. + /* TODO: consider if this requires action if received when
  5825. + * driver is not explicitly closing the service
  5826. + */
  5827. + break;
  5828. +
  5829. + default:
  5830. + pr_err("Received unhandled message reason %d\n", reason);
  5831. + break;
  5832. + }
  5833. +}
  5834. +
  5835. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  5836. + struct mmal_msg *msg,
  5837. + unsigned int payload_len,
  5838. + struct mmal_msg **msg_out,
  5839. + VCHI_HELD_MSG_T *msg_handle_out)
  5840. +{
  5841. + struct mmal_msg_context msg_context;
  5842. + int ret;
  5843. +
  5844. + /* payload size must not cause message to exceed max size */
  5845. + if (payload_len >
  5846. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  5847. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  5848. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  5849. + return -EINVAL;
  5850. + }
  5851. +
  5852. + init_completion(&msg_context.u.sync.cmplt);
  5853. +
  5854. + msg->h.magic = MMAL_MAGIC;
  5855. + msg->h.context = &msg_context;
  5856. + msg->h.status = 0;
  5857. +
  5858. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  5859. + ">>> sync message");
  5860. +
  5861. + vchi_service_use(instance->handle);
  5862. +
  5863. + ret = vchi_msg_queue(instance->handle,
  5864. + msg,
  5865. + sizeof(struct mmal_msg_header) + payload_len,
  5866. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  5867. +
  5868. + vchi_service_release(instance->handle);
  5869. +
  5870. + if (ret) {
  5871. + pr_err("error %d queuing message\n", ret);
  5872. + return ret;
  5873. + }
  5874. +
  5875. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  5876. + if (ret <= 0) {
  5877. + pr_err("error %d waiting for sync completion\n", ret);
  5878. + if (ret == 0)
  5879. + ret = -ETIME;
  5880. + /* todo: what happens if the message arrives after aborting */
  5881. + return ret;
  5882. + }
  5883. +
  5884. + *msg_out = msg_context.u.sync.msg;
  5885. + *msg_handle_out = msg_context.u.sync.msg_handle;
  5886. +
  5887. + return 0;
  5888. +}
  5889. +
  5890. +static void dump_port_info(struct vchiq_mmal_port *port)
  5891. +{
  5892. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  5893. +
  5894. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  5895. + port->minimum_buffer.num,
  5896. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  5897. +
  5898. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  5899. + port->recommended_buffer.num,
  5900. + port->recommended_buffer.size,
  5901. + port->recommended_buffer.alignment);
  5902. +
  5903. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  5904. + port->current_buffer.num,
  5905. + port->current_buffer.size, port->current_buffer.alignment);
  5906. +
  5907. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  5908. + port->format.type,
  5909. + port->format.encoding, port->format.encoding_variant);
  5910. +
  5911. + pr_debug(" bitrate:%d flags:0x%x\n",
  5912. + port->format.bitrate, port->format.flags);
  5913. +
  5914. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  5915. + pr_debug
  5916. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  5917. + port->es.video.width, port->es.video.height,
  5918. + port->es.video.color_space);
  5919. +
  5920. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  5921. + port->es.video.crop.x,
  5922. + port->es.video.crop.y,
  5923. + port->es.video.crop.width, port->es.video.crop.height);
  5924. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  5925. + port->es.video.frame_rate.num,
  5926. + port->es.video.frame_rate.den,
  5927. + port->es.video.par.num, port->es.video.par.den);
  5928. + }
  5929. +}
  5930. +
  5931. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  5932. +{
  5933. +
  5934. + /* todo do readonly fields need setting at all? */
  5935. + p->type = port->type;
  5936. + p->index = port->index;
  5937. + p->index_all = 0;
  5938. + p->is_enabled = port->enabled;
  5939. + p->buffer_num_min = port->minimum_buffer.num;
  5940. + p->buffer_size_min = port->minimum_buffer.size;
  5941. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  5942. + p->buffer_num_recommended = port->recommended_buffer.num;
  5943. + p->buffer_size_recommended = port->recommended_buffer.size;
  5944. +
  5945. + /* only three writable fields in a port */
  5946. + p->buffer_num = port->current_buffer.num;
  5947. + p->buffer_size = port->current_buffer.size;
  5948. + p->userdata = port;
  5949. +}
  5950. +
  5951. +static int port_info_set(struct vchiq_mmal_instance *instance,
  5952. + struct vchiq_mmal_port *port)
  5953. +{
  5954. + int ret;
  5955. + struct mmal_msg m;
  5956. + struct mmal_msg *rmsg;
  5957. + VCHI_HELD_MSG_T rmsg_handle;
  5958. +
  5959. + pr_debug("setting port info port %p\n", port);
  5960. + if (!port)
  5961. + return -1;
  5962. + dump_port_info(port);
  5963. +
  5964. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  5965. +
  5966. + m.u.port_info_set.component_handle = port->component->handle;
  5967. + m.u.port_info_set.port_type = port->type;
  5968. + m.u.port_info_set.port_index = port->index;
  5969. +
  5970. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  5971. +
  5972. + /* elementry stream format setup */
  5973. + m.u.port_info_set.format.type = port->format.type;
  5974. + m.u.port_info_set.format.encoding = port->format.encoding;
  5975. + m.u.port_info_set.format.encoding_variant =
  5976. + port->format.encoding_variant;
  5977. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  5978. + m.u.port_info_set.format.flags = port->format.flags;
  5979. +
  5980. + memcpy(&m.u.port_info_set.es, &port->es,
  5981. + sizeof(union mmal_es_specific_format));
  5982. +
  5983. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  5984. + memcpy(&m.u.port_info_set.extradata, port->format.extradata,
  5985. + port->format.extradata_size);
  5986. +
  5987. + ret = send_synchronous_mmal_msg(instance, &m,
  5988. + sizeof(m.u.port_info_set),
  5989. + &rmsg, &rmsg_handle);
  5990. + if (ret)
  5991. + return ret;
  5992. +
  5993. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  5994. + /* got an unexpected message type in reply */
  5995. + ret = -EINVAL;
  5996. + goto release_msg;
  5997. + }
  5998. +
  5999. + /* return operation status */
  6000. + ret = -rmsg->u.port_info_get_reply.status;
  6001. +
  6002. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  6003. + port->component->handle, port->handle);
  6004. +
  6005. +release_msg:
  6006. + vchi_held_msg_release(&rmsg_handle);
  6007. +
  6008. + return ret;
  6009. +
  6010. +}
  6011. +
  6012. +/* use port info get message to retrive port information */
  6013. +static int port_info_get(struct vchiq_mmal_instance *instance,
  6014. + struct vchiq_mmal_port *port)
  6015. +{
  6016. + int ret;
  6017. + struct mmal_msg m;
  6018. + struct mmal_msg *rmsg;
  6019. + VCHI_HELD_MSG_T rmsg_handle;
  6020. +
  6021. + /* port info time */
  6022. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  6023. + m.u.port_info_get.component_handle = port->component->handle;
  6024. + m.u.port_info_get.port_type = port->type;
  6025. + m.u.port_info_get.index = port->index;
  6026. +
  6027. + ret = send_synchronous_mmal_msg(instance, &m,
  6028. + sizeof(m.u.port_info_get),
  6029. + &rmsg, &rmsg_handle);
  6030. + if (ret)
  6031. + return ret;
  6032. +
  6033. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  6034. + /* got an unexpected message type in reply */
  6035. + ret = -EINVAL;
  6036. + goto release_msg;
  6037. + }
  6038. +
  6039. + /* return operation status */
  6040. + ret = -rmsg->u.port_info_get_reply.status;
  6041. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  6042. + goto release_msg;
  6043. +
  6044. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  6045. + port->enabled = false;
  6046. + else
  6047. + port->enabled = true;
  6048. +
  6049. + /* copy the values out of the message */
  6050. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  6051. +
  6052. + /* port type and index cached to use on port info set becuase
  6053. + * it does not use a port handle
  6054. + */
  6055. + port->type = rmsg->u.port_info_get_reply.port_type;
  6056. + port->index = rmsg->u.port_info_get_reply.port_index;
  6057. +
  6058. + port->minimum_buffer.num =
  6059. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  6060. + port->minimum_buffer.size =
  6061. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  6062. + port->minimum_buffer.alignment =
  6063. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  6064. +
  6065. + port->recommended_buffer.alignment =
  6066. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  6067. + port->recommended_buffer.num =
  6068. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  6069. +
  6070. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  6071. + port->current_buffer.size =
  6072. + rmsg->u.port_info_get_reply.port.buffer_size;
  6073. +
  6074. + /* stream format */
  6075. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  6076. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  6077. + port->format.encoding_variant =
  6078. + rmsg->u.port_info_get_reply.format.encoding_variant;
  6079. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  6080. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  6081. +
  6082. + /* elementry stream format */
  6083. + memcpy(&port->es,
  6084. + &rmsg->u.port_info_get_reply.es,
  6085. + sizeof(union mmal_es_specific_format));
  6086. + port->format.es = &port->es;
  6087. +
  6088. + port->format.extradata_size =
  6089. + rmsg->u.port_info_get_reply.format.extradata_size;
  6090. + memcpy(port->format.extradata,
  6091. + rmsg->u.port_info_get_reply.extradata,
  6092. + port->format.extradata_size);
  6093. +
  6094. + pr_debug("received port info\n");
  6095. + dump_port_info(port);
  6096. +
  6097. +release_msg:
  6098. +
  6099. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  6100. + __func__, ret, port->component->handle, port->handle);
  6101. +
  6102. + vchi_held_msg_release(&rmsg_handle);
  6103. +
  6104. + return ret;
  6105. +}
  6106. +
  6107. +/* create comonent on vc */
  6108. +static int create_component(struct vchiq_mmal_instance *instance,
  6109. + struct vchiq_mmal_component *component,
  6110. + const char *name)
  6111. +{
  6112. + int ret;
  6113. + struct mmal_msg m;
  6114. + struct mmal_msg *rmsg;
  6115. + VCHI_HELD_MSG_T rmsg_handle;
  6116. +
  6117. + /* build component create message */
  6118. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  6119. + m.u.component_create.client_component = component;
  6120. + strncpy(m.u.component_create.name, name,
  6121. + sizeof(m.u.component_create.name));
  6122. +
  6123. + ret = send_synchronous_mmal_msg(instance, &m,
  6124. + sizeof(m.u.component_create),
  6125. + &rmsg, &rmsg_handle);
  6126. + if (ret)
  6127. + return ret;
  6128. +
  6129. + if (rmsg->h.type != m.h.type) {
  6130. + /* got an unexpected message type in reply */
  6131. + ret = -EINVAL;
  6132. + goto release_msg;
  6133. + }
  6134. +
  6135. + ret = -rmsg->u.component_create_reply.status;
  6136. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  6137. + goto release_msg;
  6138. +
  6139. + /* a valid component response received */
  6140. + component->handle = rmsg->u.component_create_reply.component_handle;
  6141. + component->inputs = rmsg->u.component_create_reply.input_num;
  6142. + component->outputs = rmsg->u.component_create_reply.output_num;
  6143. + component->clocks = rmsg->u.component_create_reply.clock_num;
  6144. +
  6145. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  6146. + component->handle,
  6147. + component->inputs, component->outputs, component->clocks);
  6148. +
  6149. +release_msg:
  6150. + vchi_held_msg_release(&rmsg_handle);
  6151. +
  6152. + return ret;
  6153. +}
  6154. +
  6155. +/* destroys a component on vc */
  6156. +static int destroy_component(struct vchiq_mmal_instance *instance,
  6157. + struct vchiq_mmal_component *component)
  6158. +{
  6159. + int ret;
  6160. + struct mmal_msg m;
  6161. + struct mmal_msg *rmsg;
  6162. + VCHI_HELD_MSG_T rmsg_handle;
  6163. +
  6164. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  6165. + m.u.component_destroy.component_handle = component->handle;
  6166. +
  6167. + ret = send_synchronous_mmal_msg(instance, &m,
  6168. + sizeof(m.u.component_destroy),
  6169. + &rmsg, &rmsg_handle);
  6170. + if (ret)
  6171. + return ret;
  6172. +
  6173. + if (rmsg->h.type != m.h.type) {
  6174. + /* got an unexpected message type in reply */
  6175. + ret = -EINVAL;
  6176. + goto release_msg;
  6177. + }
  6178. +
  6179. + ret = -rmsg->u.component_destroy_reply.status;
  6180. +
  6181. +release_msg:
  6182. +
  6183. + vchi_held_msg_release(&rmsg_handle);
  6184. +
  6185. + return ret;
  6186. +}
  6187. +
  6188. +/* enable a component on vc */
  6189. +static int enable_component(struct vchiq_mmal_instance *instance,
  6190. + struct vchiq_mmal_component *component)
  6191. +{
  6192. + int ret;
  6193. + struct mmal_msg m;
  6194. + struct mmal_msg *rmsg;
  6195. + VCHI_HELD_MSG_T rmsg_handle;
  6196. +
  6197. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  6198. + m.u.component_enable.component_handle = component->handle;
  6199. +
  6200. + ret = send_synchronous_mmal_msg(instance, &m,
  6201. + sizeof(m.u.component_enable),
  6202. + &rmsg, &rmsg_handle);
  6203. + if (ret)
  6204. + return ret;
  6205. +
  6206. + if (rmsg->h.type != m.h.type) {
  6207. + /* got an unexpected message type in reply */
  6208. + ret = -EINVAL;
  6209. + goto release_msg;
  6210. + }
  6211. +
  6212. + ret = -rmsg->u.component_enable_reply.status;
  6213. +
  6214. +release_msg:
  6215. + vchi_held_msg_release(&rmsg_handle);
  6216. +
  6217. + return ret;
  6218. +}
  6219. +
  6220. +/* disable a component on vc */
  6221. +static int disable_component(struct vchiq_mmal_instance *instance,
  6222. + struct vchiq_mmal_component *component)
  6223. +{
  6224. + int ret;
  6225. + struct mmal_msg m;
  6226. + struct mmal_msg *rmsg;
  6227. + VCHI_HELD_MSG_T rmsg_handle;
  6228. +
  6229. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  6230. + m.u.component_disable.component_handle = component->handle;
  6231. +
  6232. + ret = send_synchronous_mmal_msg(instance, &m,
  6233. + sizeof(m.u.component_disable),
  6234. + &rmsg, &rmsg_handle);
  6235. + if (ret)
  6236. + return ret;
  6237. +
  6238. + if (rmsg->h.type != m.h.type) {
  6239. + /* got an unexpected message type in reply */
  6240. + ret = -EINVAL;
  6241. + goto release_msg;
  6242. + }
  6243. +
  6244. + ret = -rmsg->u.component_disable_reply.status;
  6245. +
  6246. +release_msg:
  6247. +
  6248. + vchi_held_msg_release(&rmsg_handle);
  6249. +
  6250. + return ret;
  6251. +}
  6252. +
  6253. +/* get version of mmal implementation */
  6254. +static int get_version(struct vchiq_mmal_instance *instance,
  6255. + u32 *major_out, u32 *minor_out)
  6256. +{
  6257. + int ret;
  6258. + struct mmal_msg m;
  6259. + struct mmal_msg *rmsg;
  6260. + VCHI_HELD_MSG_T rmsg_handle;
  6261. +
  6262. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  6263. +
  6264. + ret = send_synchronous_mmal_msg(instance, &m,
  6265. + sizeof(m.u.version),
  6266. + &rmsg, &rmsg_handle);
  6267. + if (ret)
  6268. + return ret;
  6269. +
  6270. + if (rmsg->h.type != m.h.type) {
  6271. + /* got an unexpected message type in reply */
  6272. + ret = -EINVAL;
  6273. + goto release_msg;
  6274. + }
  6275. +
  6276. + *major_out = rmsg->u.version.major;
  6277. + *minor_out = rmsg->u.version.minor;
  6278. +
  6279. +release_msg:
  6280. + vchi_held_msg_release(&rmsg_handle);
  6281. +
  6282. + return ret;
  6283. +}
  6284. +
  6285. +/* do a port action with a port as a parameter */
  6286. +static int port_action_port(struct vchiq_mmal_instance *instance,
  6287. + struct vchiq_mmal_port *port,
  6288. + enum mmal_msg_port_action_type action_type)
  6289. +{
  6290. + int ret;
  6291. + struct mmal_msg m;
  6292. + struct mmal_msg *rmsg;
  6293. + VCHI_HELD_MSG_T rmsg_handle;
  6294. +
  6295. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  6296. + m.u.port_action_port.component_handle = port->component->handle;
  6297. + m.u.port_action_port.port_handle = port->handle;
  6298. + m.u.port_action_port.action = action_type;
  6299. +
  6300. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  6301. +
  6302. + ret = send_synchronous_mmal_msg(instance, &m,
  6303. + sizeof(m.u.port_action_port),
  6304. + &rmsg, &rmsg_handle);
  6305. + if (ret)
  6306. + return ret;
  6307. +
  6308. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  6309. + /* got an unexpected message type in reply */
  6310. + ret = -EINVAL;
  6311. + goto release_msg;
  6312. + }
  6313. +
  6314. + ret = -rmsg->u.port_action_reply.status;
  6315. +
  6316. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  6317. + __func__,
  6318. + ret, port->component->handle, port->handle,
  6319. + port_action_type_names[action_type], action_type);
  6320. +
  6321. +release_msg:
  6322. + vchi_held_msg_release(&rmsg_handle);
  6323. +
  6324. + return ret;
  6325. +}
  6326. +
  6327. +/* do a port action with handles as parameters */
  6328. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  6329. + struct vchiq_mmal_port *port,
  6330. + enum mmal_msg_port_action_type action_type,
  6331. + u32 connect_component_handle,
  6332. + u32 connect_port_handle)
  6333. +{
  6334. + int ret;
  6335. + struct mmal_msg m;
  6336. + struct mmal_msg *rmsg;
  6337. + VCHI_HELD_MSG_T rmsg_handle;
  6338. +
  6339. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  6340. +
  6341. + m.u.port_action_handle.component_handle = port->component->handle;
  6342. + m.u.port_action_handle.port_handle = port->handle;
  6343. + m.u.port_action_handle.action = action_type;
  6344. +
  6345. + m.u.port_action_handle.connect_component_handle =
  6346. + connect_component_handle;
  6347. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  6348. +
  6349. + ret = send_synchronous_mmal_msg(instance, &m,
  6350. + sizeof(m.u.port_action_handle),
  6351. + &rmsg, &rmsg_handle);
  6352. + if (ret)
  6353. + return ret;
  6354. +
  6355. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  6356. + /* got an unexpected message type in reply */
  6357. + ret = -EINVAL;
  6358. + goto release_msg;
  6359. + }
  6360. +
  6361. + ret = -rmsg->u.port_action_reply.status;
  6362. +
  6363. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  6364. + " connect component:0x%x connect port:%d\n",
  6365. + __func__,
  6366. + ret, port->component->handle, port->handle,
  6367. + port_action_type_names[action_type],
  6368. + action_type, connect_component_handle, connect_port_handle);
  6369. +
  6370. +release_msg:
  6371. + vchi_held_msg_release(&rmsg_handle);
  6372. +
  6373. + return ret;
  6374. +}
  6375. +
  6376. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  6377. + struct vchiq_mmal_port *port,
  6378. + u32 parameter_id, void *value, u32 value_size)
  6379. +{
  6380. + int ret;
  6381. + struct mmal_msg m;
  6382. + struct mmal_msg *rmsg;
  6383. + VCHI_HELD_MSG_T rmsg_handle;
  6384. +
  6385. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  6386. +
  6387. + m.u.port_parameter_set.component_handle = port->component->handle;
  6388. + m.u.port_parameter_set.port_handle = port->handle;
  6389. + m.u.port_parameter_set.id = parameter_id;
  6390. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  6391. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  6392. +
  6393. + ret = send_synchronous_mmal_msg(instance, &m,
  6394. + (4 * sizeof(u32)) + value_size,
  6395. + &rmsg, &rmsg_handle);
  6396. + if (ret)
  6397. + return ret;
  6398. +
  6399. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  6400. + /* got an unexpected message type in reply */
  6401. + ret = -EINVAL;
  6402. + goto release_msg;
  6403. + }
  6404. +
  6405. + ret = -rmsg->u.port_parameter_set_reply.status;
  6406. +
  6407. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  6408. + __func__,
  6409. + ret, port->component->handle, port->handle, parameter_id);
  6410. +
  6411. +release_msg:
  6412. + vchi_held_msg_release(&rmsg_handle);
  6413. +
  6414. + return ret;
  6415. +}
  6416. +
  6417. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  6418. + struct vchiq_mmal_port *port,
  6419. + u32 parameter_id, void *value, u32 *value_size)
  6420. +{
  6421. + int ret;
  6422. + struct mmal_msg m;
  6423. + struct mmal_msg *rmsg;
  6424. + VCHI_HELD_MSG_T rmsg_handle;
  6425. +
  6426. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  6427. +
  6428. + m.u.port_parameter_get.component_handle = port->component->handle;
  6429. + m.u.port_parameter_get.port_handle = port->handle;
  6430. + m.u.port_parameter_get.id = parameter_id;
  6431. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  6432. +
  6433. + ret = send_synchronous_mmal_msg(instance, &m,
  6434. + sizeof(struct
  6435. + mmal_msg_port_parameter_get),
  6436. + &rmsg, &rmsg_handle);
  6437. + if (ret)
  6438. + return ret;
  6439. +
  6440. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  6441. + /* got an unexpected message type in reply */
  6442. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  6443. + ret = -EINVAL;
  6444. + goto release_msg;
  6445. + }
  6446. +
  6447. + ret = -rmsg->u.port_parameter_get_reply.status;
  6448. + if (ret) {
  6449. + /* Copy only as much as we have space for
  6450. + * but report true size of parameter
  6451. + */
  6452. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  6453. + *value_size);
  6454. + *value_size = rmsg->u.port_parameter_get_reply.size;
  6455. + } else
  6456. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  6457. + rmsg->u.port_parameter_get_reply.size);
  6458. +
  6459. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  6460. + ret, port->component->handle, port->handle, parameter_id);
  6461. +
  6462. +release_msg:
  6463. + vchi_held_msg_release(&rmsg_handle);
  6464. +
  6465. + return ret;
  6466. +}
  6467. +
  6468. +/* disables a port and drains buffers from it */
  6469. +static int port_disable(struct vchiq_mmal_instance *instance,
  6470. + struct vchiq_mmal_port *port)
  6471. +{
  6472. + int ret;
  6473. + struct list_head *q, *buf_head;
  6474. + unsigned long flags = 0;
  6475. +
  6476. + if (!port->enabled)
  6477. + return 0;
  6478. +
  6479. + port->enabled = false;
  6480. +
  6481. + ret = port_action_port(instance, port,
  6482. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  6483. + if (ret == 0) {
  6484. +
  6485. + /* drain all queued buffers on port */
  6486. + spin_lock_irqsave(&port->slock, flags);
  6487. +
  6488. + list_for_each_safe(buf_head, q, &port->buffers) {
  6489. + struct mmal_buffer *mmalbuf;
  6490. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  6491. + list);
  6492. + list_del(buf_head);
  6493. + if (port->buffer_cb)
  6494. + port->buffer_cb(instance,
  6495. + port, 0, mmalbuf, 0, 0,
  6496. + MMAL_TIME_UNKNOWN,
  6497. + MMAL_TIME_UNKNOWN);
  6498. + }
  6499. +
  6500. + spin_unlock_irqrestore(&port->slock, flags);
  6501. +
  6502. + ret = port_info_get(instance, port);
  6503. + }
  6504. +
  6505. + return ret;
  6506. +}
  6507. +
  6508. +/* enable a port */
  6509. +static int port_enable(struct vchiq_mmal_instance *instance,
  6510. + struct vchiq_mmal_port *port)
  6511. +{
  6512. + unsigned int hdr_count;
  6513. + struct list_head *buf_head;
  6514. + int ret;
  6515. +
  6516. + if (port->enabled)
  6517. + return 0;
  6518. +
  6519. + /* ensure there are enough buffers queued to cover the buffer headers */
  6520. + if (port->buffer_cb != NULL) {
  6521. + hdr_count = 0;
  6522. + list_for_each(buf_head, &port->buffers) {
  6523. + hdr_count++;
  6524. + }
  6525. + if (hdr_count < port->current_buffer.num)
  6526. + return -ENOSPC;
  6527. + }
  6528. +
  6529. + ret = port_action_port(instance, port,
  6530. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  6531. + if (ret)
  6532. + goto done;
  6533. +
  6534. + port->enabled = true;
  6535. +
  6536. + if (port->buffer_cb) {
  6537. + /* send buffer headers to videocore */
  6538. + hdr_count = 1;
  6539. + list_for_each(buf_head, &port->buffers) {
  6540. + struct mmal_buffer *mmalbuf;
  6541. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  6542. + list);
  6543. + ret = buffer_from_host(instance, port, mmalbuf);
  6544. + if (ret)
  6545. + goto done;
  6546. +
  6547. + hdr_count++;
  6548. + if (hdr_count > port->current_buffer.num)
  6549. + break;
  6550. + }
  6551. + }
  6552. +
  6553. + ret = port_info_get(instance, port);
  6554. +
  6555. +done:
  6556. + return ret;
  6557. +}
  6558. +
  6559. +/* ------------------------------------------------------------------
  6560. + * Exported API
  6561. + *------------------------------------------------------------------*/
  6562. +
  6563. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  6564. + struct vchiq_mmal_port *port)
  6565. +{
  6566. + int ret;
  6567. +
  6568. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6569. + return -EINTR;
  6570. +
  6571. + ret = port_info_set(instance, port);
  6572. + if (ret)
  6573. + goto release_unlock;
  6574. +
  6575. + /* read what has actually been set */
  6576. + ret = port_info_get(instance, port);
  6577. +
  6578. +release_unlock:
  6579. + mutex_unlock(&instance->vchiq_mutex);
  6580. +
  6581. + return ret;
  6582. +
  6583. +}
  6584. +
  6585. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  6586. + struct vchiq_mmal_port *port,
  6587. + u32 parameter, void *value, u32 value_size)
  6588. +{
  6589. + int ret;
  6590. +
  6591. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6592. + return -EINTR;
  6593. +
  6594. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  6595. +
  6596. + mutex_unlock(&instance->vchiq_mutex);
  6597. +
  6598. + return ret;
  6599. +}
  6600. +
  6601. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  6602. + struct vchiq_mmal_port *port,
  6603. + u32 parameter, void *value, u32 *value_size)
  6604. +{
  6605. + int ret;
  6606. +
  6607. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6608. + return -EINTR;
  6609. +
  6610. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  6611. +
  6612. + mutex_unlock(&instance->vchiq_mutex);
  6613. +
  6614. + return ret;
  6615. +}
  6616. +
  6617. +/* enable a port
  6618. + *
  6619. + * enables a port and queues buffers for satisfying callbacks if we
  6620. + * provide a callback handler
  6621. + */
  6622. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  6623. + struct vchiq_mmal_port *port,
  6624. + vchiq_mmal_buffer_cb buffer_cb)
  6625. +{
  6626. + int ret;
  6627. +
  6628. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6629. + return -EINTR;
  6630. +
  6631. + /* already enabled - noop */
  6632. + if (port->enabled) {
  6633. + ret = 0;
  6634. + goto unlock;
  6635. + }
  6636. +
  6637. + port->buffer_cb = buffer_cb;
  6638. +
  6639. + ret = port_enable(instance, port);
  6640. +
  6641. +unlock:
  6642. + mutex_unlock(&instance->vchiq_mutex);
  6643. +
  6644. + return ret;
  6645. +}
  6646. +
  6647. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  6648. + struct vchiq_mmal_port *port)
  6649. +{
  6650. + int ret;
  6651. +
  6652. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6653. + return -EINTR;
  6654. +
  6655. + if (!port->enabled) {
  6656. + mutex_unlock(&instance->vchiq_mutex);
  6657. + return 0;
  6658. + }
  6659. +
  6660. + ret = port_disable(instance, port);
  6661. +
  6662. + mutex_unlock(&instance->vchiq_mutex);
  6663. +
  6664. + return ret;
  6665. +}
  6666. +
  6667. +/* ports will be connected in a tunneled manner so data buffers
  6668. + * are not handled by client.
  6669. + */
  6670. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  6671. + struct vchiq_mmal_port *src,
  6672. + struct vchiq_mmal_port *dst)
  6673. +{
  6674. + int ret;
  6675. +
  6676. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6677. + return -EINTR;
  6678. +
  6679. + /* disconnect ports if connected */
  6680. + if (src->connected != NULL) {
  6681. + ret = port_disable(instance, src);
  6682. + if (ret) {
  6683. + pr_err("failed disabling src port(%d)\n", ret);
  6684. + goto release_unlock;
  6685. + }
  6686. +
  6687. + /* do not need to disable the destination port as they
  6688. + * are connected and it is done automatically
  6689. + */
  6690. +
  6691. + ret = port_action_handle(instance, src,
  6692. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  6693. + src->connected->component->handle,
  6694. + src->connected->handle);
  6695. + if (ret < 0) {
  6696. + pr_err("failed disconnecting src port\n");
  6697. + goto release_unlock;
  6698. + }
  6699. + src->connected->enabled = false;
  6700. + src->connected = NULL;
  6701. + }
  6702. +
  6703. + if (dst == NULL) {
  6704. + /* do not make new connection */
  6705. + ret = 0;
  6706. + pr_debug("not making new connection\n");
  6707. + goto release_unlock;
  6708. + }
  6709. +
  6710. + /* copy src port format to dst */
  6711. + dst->format.encoding = src->format.encoding;
  6712. + dst->es.video.width = src->es.video.width;
  6713. + dst->es.video.height = src->es.video.height;
  6714. + dst->es.video.crop.x = src->es.video.crop.x;
  6715. + dst->es.video.crop.y = src->es.video.crop.y;
  6716. + dst->es.video.crop.width = src->es.video.crop.width;
  6717. + dst->es.video.crop.height = src->es.video.crop.height;
  6718. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  6719. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  6720. +
  6721. + /* set new format */
  6722. + ret = port_info_set(instance, dst);
  6723. + if (ret) {
  6724. + pr_debug("setting port info failed\n");
  6725. + goto release_unlock;
  6726. + }
  6727. +
  6728. + /* read what has actually been set */
  6729. + ret = port_info_get(instance, dst);
  6730. + if (ret) {
  6731. + pr_debug("read back port info failed\n");
  6732. + goto release_unlock;
  6733. + }
  6734. +
  6735. + /* connect two ports together */
  6736. + ret = port_action_handle(instance, src,
  6737. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  6738. + dst->component->handle, dst->handle);
  6739. + if (ret < 0) {
  6740. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  6741. + src->component->handle, src->handle,
  6742. + dst->component->handle, dst->handle);
  6743. + goto release_unlock;
  6744. + }
  6745. + src->connected = dst;
  6746. +
  6747. +release_unlock:
  6748. +
  6749. + mutex_unlock(&instance->vchiq_mutex);
  6750. +
  6751. + return ret;
  6752. +}
  6753. +
  6754. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  6755. + struct vchiq_mmal_port *port,
  6756. + struct mmal_buffer *buffer)
  6757. +{
  6758. + unsigned long flags = 0;
  6759. +
  6760. + spin_lock_irqsave(&port->slock, flags);
  6761. + list_add_tail(&buffer->list, &port->buffers);
  6762. + spin_unlock_irqrestore(&port->slock, flags);
  6763. +
  6764. + /* the port previously underflowed because it was missing a
  6765. + * mmal_buffer which has just been added, submit that buffer
  6766. + * to the mmal service.
  6767. + */
  6768. + if (port->buffer_underflow) {
  6769. + port_buffer_from_host(instance, port);
  6770. + port->buffer_underflow--;
  6771. + }
  6772. +
  6773. + return 0;
  6774. +}
  6775. +
  6776. +/* Initialise a mmal component and its ports
  6777. + *
  6778. + */
  6779. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  6780. + const char *name,
  6781. + struct vchiq_mmal_component **component_out)
  6782. +{
  6783. + int ret;
  6784. + int idx; /* port index */
  6785. + struct vchiq_mmal_component *component;
  6786. +
  6787. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6788. + return -EINTR;
  6789. +
  6790. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  6791. + ret = -EINVAL; /* todo is this correct error? */
  6792. + goto unlock;
  6793. + }
  6794. +
  6795. + component = &instance->component[instance->component_idx];
  6796. +
  6797. + ret = create_component(instance, component, name);
  6798. + if (ret < 0)
  6799. + goto unlock;
  6800. +
  6801. + /* ports info needs gathering */
  6802. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  6803. + component->control.index = 0;
  6804. + component->control.component = component;
  6805. + spin_lock_init(&component->control.slock);
  6806. + INIT_LIST_HEAD(&component->control.buffers);
  6807. + ret = port_info_get(instance, &component->control);
  6808. + if (ret < 0)
  6809. + goto release_component;
  6810. +
  6811. + for (idx = 0; idx < component->inputs; idx++) {
  6812. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  6813. + component->input[idx].index = idx;
  6814. + component->input[idx].component = component;
  6815. + spin_lock_init(&component->input[idx].slock);
  6816. + INIT_LIST_HEAD(&component->input[idx].buffers);
  6817. + ret = port_info_get(instance, &component->input[idx]);
  6818. + if (ret < 0)
  6819. + goto release_component;
  6820. + }
  6821. +
  6822. + for (idx = 0; idx < component->outputs; idx++) {
  6823. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  6824. + component->output[idx].index = idx;
  6825. + component->output[idx].component = component;
  6826. + spin_lock_init(&component->output[idx].slock);
  6827. + INIT_LIST_HEAD(&component->output[idx].buffers);
  6828. + ret = port_info_get(instance, &component->output[idx]);
  6829. + if (ret < 0)
  6830. + goto release_component;
  6831. + }
  6832. +
  6833. + for (idx = 0; idx < component->clocks; idx++) {
  6834. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  6835. + component->clock[idx].index = idx;
  6836. + component->clock[idx].component = component;
  6837. + spin_lock_init(&component->clock[idx].slock);
  6838. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  6839. + ret = port_info_get(instance, &component->clock[idx]);
  6840. + if (ret < 0)
  6841. + goto release_component;
  6842. + }
  6843. +
  6844. + instance->component_idx++;
  6845. +
  6846. + *component_out = component;
  6847. +
  6848. + mutex_unlock(&instance->vchiq_mutex);
  6849. +
  6850. + return 0;
  6851. +
  6852. +release_component:
  6853. + destroy_component(instance, component);
  6854. +unlock:
  6855. + mutex_unlock(&instance->vchiq_mutex);
  6856. +
  6857. + return ret;
  6858. +}
  6859. +
  6860. +/*
  6861. + * cause a mmal component to be destroyed
  6862. + */
  6863. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  6864. + struct vchiq_mmal_component *component)
  6865. +{
  6866. + int ret;
  6867. +
  6868. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6869. + return -EINTR;
  6870. +
  6871. + if (component->enabled)
  6872. + ret = disable_component(instance, component);
  6873. +
  6874. + ret = destroy_component(instance, component);
  6875. +
  6876. + mutex_unlock(&instance->vchiq_mutex);
  6877. +
  6878. + return ret;
  6879. +}
  6880. +
  6881. +/*
  6882. + * cause a mmal component to be enabled
  6883. + */
  6884. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  6885. + struct vchiq_mmal_component *component)
  6886. +{
  6887. + int ret;
  6888. +
  6889. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6890. + return -EINTR;
  6891. +
  6892. + if (component->enabled) {
  6893. + mutex_unlock(&instance->vchiq_mutex);
  6894. + return 0;
  6895. + }
  6896. +
  6897. + ret = enable_component(instance, component);
  6898. + if (ret == 0)
  6899. + component->enabled = true;
  6900. +
  6901. + mutex_unlock(&instance->vchiq_mutex);
  6902. +
  6903. + return ret;
  6904. +}
  6905. +
  6906. +/*
  6907. + * cause a mmal component to be enabled
  6908. + */
  6909. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  6910. + struct vchiq_mmal_component *component)
  6911. +{
  6912. + int ret;
  6913. +
  6914. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6915. + return -EINTR;
  6916. +
  6917. + if (!component->enabled) {
  6918. + mutex_unlock(&instance->vchiq_mutex);
  6919. + return 0;
  6920. + }
  6921. +
  6922. + ret = disable_component(instance, component);
  6923. + if (ret == 0)
  6924. + component->enabled = false;
  6925. +
  6926. + mutex_unlock(&instance->vchiq_mutex);
  6927. +
  6928. + return ret;
  6929. +}
  6930. +
  6931. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  6932. + u32 *major_out, u32 *minor_out)
  6933. +{
  6934. + int ret;
  6935. +
  6936. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6937. + return -EINTR;
  6938. +
  6939. + ret = get_version(instance, major_out, minor_out);
  6940. +
  6941. + mutex_unlock(&instance->vchiq_mutex);
  6942. +
  6943. + return ret;
  6944. +}
  6945. +
  6946. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  6947. +{
  6948. + int status = 0;
  6949. +
  6950. + if (instance == NULL)
  6951. + return -EINVAL;
  6952. +
  6953. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  6954. + return -EINTR;
  6955. +
  6956. + vchi_service_use(instance->handle);
  6957. +
  6958. + status = vchi_service_close(instance->handle);
  6959. + if (status != 0)
  6960. + pr_err("mmal-vchiq: VCHIQ close failed");
  6961. +
  6962. + mutex_unlock(&instance->vchiq_mutex);
  6963. +
  6964. + vfree(instance->bulk_scratch);
  6965. +
  6966. + kfree(instance);
  6967. +
  6968. + return status;
  6969. +}
  6970. +
  6971. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  6972. +{
  6973. + int status;
  6974. + struct vchiq_mmal_instance *instance;
  6975. + static VCHI_CONNECTION_T *vchi_connection;
  6976. + static VCHI_INSTANCE_T vchi_instance;
  6977. + SERVICE_CREATION_T params = {
  6978. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  6979. + VC_MMAL_SERVER_NAME,
  6980. + vchi_connection,
  6981. + 0, /* rx fifo size (unused) */
  6982. + 0, /* tx fifo size (unused) */
  6983. + service_callback,
  6984. + NULL, /* service callback parameter */
  6985. + 1, /* unaligned bulk receives */
  6986. + 1, /* unaligned bulk transmits */
  6987. + 0 /* want crc check on bulk transfers */
  6988. + };
  6989. +
  6990. + /* compile time checks to ensure structure size as they are
  6991. + * directly (de)serialised from memory.
  6992. + */
  6993. +
  6994. + /* ensure the header structure has packed to the correct size */
  6995. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  6996. +
  6997. + /* ensure message structure does not exceed maximum length */
  6998. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  6999. +
  7000. + /* mmal port struct is correct size */
  7001. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  7002. +
  7003. + /* create a vchi instance */
  7004. + status = vchi_initialise(&vchi_instance);
  7005. + if (status) {
  7006. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  7007. + status);
  7008. + return -EIO;
  7009. + }
  7010. +
  7011. + status = vchi_connect(NULL, 0, vchi_instance);
  7012. + if (status) {
  7013. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  7014. + return -EIO;
  7015. + }
  7016. +
  7017. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  7018. + memset(instance, 0, sizeof(*instance));
  7019. +
  7020. + mutex_init(&instance->vchiq_mutex);
  7021. + mutex_init(&instance->bulk_mutex);
  7022. +
  7023. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  7024. +
  7025. + params.callback_param = instance;
  7026. +
  7027. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  7028. + if (status) {
  7029. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  7030. + status);
  7031. + goto err_close_services;
  7032. + }
  7033. +
  7034. + vchi_service_release(instance->handle);
  7035. +
  7036. + *out_instance = instance;
  7037. +
  7038. + return 0;
  7039. +
  7040. +err_close_services:
  7041. +
  7042. + vchi_service_close(instance->handle);
  7043. + vfree(instance->bulk_scratch);
  7044. + kfree(instance);
  7045. + return -ENODEV;
  7046. +}
  7047. --- /dev/null
  7048. +++ b/drivers/media/platform/bcm2835/mmal-vchiq.h
  7049. @@ -0,0 +1,178 @@
  7050. +/*
  7051. + * Broadcom BM2835 V4L2 driver
  7052. + *
  7053. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  7054. + *
  7055. + * This file is subject to the terms and conditions of the GNU General Public
  7056. + * License. See the file COPYING in the main directory of this archive
  7057. + * for more details.
  7058. + *
  7059. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  7060. + * Dave Stevenson <dsteve@broadcom.com>
  7061. + * Simon Mellor <simellor@broadcom.com>
  7062. + * Luke Diamand <luked@broadcom.com>
  7063. + *
  7064. + * MMAL interface to VCHIQ message passing
  7065. + */
  7066. +
  7067. +#ifndef MMAL_VCHIQ_H
  7068. +#define MMAL_VCHIQ_H
  7069. +
  7070. +#include "mmal-msg-format.h"
  7071. +
  7072. +#define MAX_PORT_COUNT 4
  7073. +
  7074. +/* Maximum size of the format extradata. */
  7075. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  7076. +
  7077. +struct vchiq_mmal_instance;
  7078. +
  7079. +enum vchiq_mmal_es_type {
  7080. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  7081. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  7082. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  7083. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  7084. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  7085. +};
  7086. +
  7087. +/* rectangle, used lots so it gets its own struct */
  7088. +struct vchiq_mmal_rect {
  7089. + s32 x;
  7090. + s32 y;
  7091. + s32 width;
  7092. + s32 height;
  7093. +};
  7094. +
  7095. +struct vchiq_mmal_port_buffer {
  7096. + unsigned int num; /* number of buffers */
  7097. + u32 size; /* size of buffers */
  7098. + u32 alignment; /* alignment of buffers */
  7099. +};
  7100. +
  7101. +struct vchiq_mmal_port;
  7102. +
  7103. +typedef void (*vchiq_mmal_buffer_cb)(
  7104. + struct vchiq_mmal_instance *instance,
  7105. + struct vchiq_mmal_port *port,
  7106. + int status, struct mmal_buffer *buffer,
  7107. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  7108. +
  7109. +struct vchiq_mmal_port {
  7110. + bool enabled;
  7111. + u32 handle;
  7112. + u32 type; /* port type, cached to use on port info set */
  7113. + u32 index; /* port index, cached to use on port info set */
  7114. +
  7115. + /* component port belongs to, allows simple deref */
  7116. + struct vchiq_mmal_component *component;
  7117. +
  7118. + struct vchiq_mmal_port *connected; /* port conencted to */
  7119. +
  7120. + /* buffer info */
  7121. + struct vchiq_mmal_port_buffer minimum_buffer;
  7122. + struct vchiq_mmal_port_buffer recommended_buffer;
  7123. + struct vchiq_mmal_port_buffer current_buffer;
  7124. +
  7125. + /* stream format */
  7126. + struct mmal_es_format format;
  7127. + /* elementry stream format */
  7128. + union mmal_es_specific_format es;
  7129. +
  7130. + /* data buffers to fill */
  7131. + struct list_head buffers;
  7132. + /* lock to serialise adding and removing buffers from list */
  7133. + spinlock_t slock;
  7134. + /* count of how many buffer header refils have failed because
  7135. + * there was no buffer to satisfy them
  7136. + */
  7137. + int buffer_underflow;
  7138. + /* callback on buffer completion */
  7139. + vchiq_mmal_buffer_cb buffer_cb;
  7140. + /* callback context */
  7141. + void *cb_ctx;
  7142. +};
  7143. +
  7144. +struct vchiq_mmal_component {
  7145. + bool enabled;
  7146. + u32 handle; /* VideoCore handle for component */
  7147. + u32 inputs; /* Number of input ports */
  7148. + u32 outputs; /* Number of output ports */
  7149. + u32 clocks; /* Number of clock ports */
  7150. + struct vchiq_mmal_port control; /* control port */
  7151. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  7152. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  7153. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  7154. +};
  7155. +
  7156. +
  7157. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  7158. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  7159. +
  7160. +/* Initialise a mmal component and its ports
  7161. +*
  7162. +*/
  7163. +int vchiq_mmal_component_init(
  7164. + struct vchiq_mmal_instance *instance,
  7165. + const char *name,
  7166. + struct vchiq_mmal_component **component_out);
  7167. +
  7168. +int vchiq_mmal_component_finalise(
  7169. + struct vchiq_mmal_instance *instance,
  7170. + struct vchiq_mmal_component *component);
  7171. +
  7172. +int vchiq_mmal_component_enable(
  7173. + struct vchiq_mmal_instance *instance,
  7174. + struct vchiq_mmal_component *component);
  7175. +
  7176. +int vchiq_mmal_component_disable(
  7177. + struct vchiq_mmal_instance *instance,
  7178. + struct vchiq_mmal_component *component);
  7179. +
  7180. +
  7181. +
  7182. +/* enable a mmal port
  7183. + *
  7184. + * enables a port and if a buffer callback provided enque buffer
  7185. + * headers as apropriate for the port.
  7186. + */
  7187. +int vchiq_mmal_port_enable(
  7188. + struct vchiq_mmal_instance *instance,
  7189. + struct vchiq_mmal_port *port,
  7190. + vchiq_mmal_buffer_cb buffer_cb);
  7191. +
  7192. +/* disable a port
  7193. + *
  7194. + * disable a port will dequeue any pending buffers
  7195. + */
  7196. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  7197. + struct vchiq_mmal_port *port);
  7198. +
  7199. +
  7200. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  7201. + struct vchiq_mmal_port *port,
  7202. + u32 parameter,
  7203. + void *value,
  7204. + u32 value_size);
  7205. +
  7206. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  7207. + struct vchiq_mmal_port *port,
  7208. + u32 parameter,
  7209. + void *value,
  7210. + u32 *value_size);
  7211. +
  7212. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  7213. + struct vchiq_mmal_port *port);
  7214. +
  7215. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  7216. + struct vchiq_mmal_port *src,
  7217. + struct vchiq_mmal_port *dst);
  7218. +
  7219. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  7220. + u32 *major_out,
  7221. + u32 *minor_out);
  7222. +
  7223. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  7224. + struct vchiq_mmal_port *port,
  7225. + struct mmal_buffer *buf);
  7226. +
  7227. +#endif /* MMAL_VCHIQ_H */