1
0

raspberry-pi.patch 3.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472
  1. diff -Nur linux-3.10.33/arch/arm/configs/bcmrpi_cutdown_defconfig linux-raspberry-pi/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.10.33/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-raspberry-pi/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-03-13 12:46:12.312043485 +0100
  4. @@ -0,0 +1,504 @@
  5. +CONFIG_EXPERIMENTAL=y
  6. +# CONFIG_LOCALVERSION_AUTO is not set
  7. +CONFIG_SYSVIPC=y
  8. +CONFIG_POSIX_MQUEUE=y
  9. +CONFIG_IKCONFIG=y
  10. +CONFIG_IKCONFIG_PROC=y
  11. +# CONFIG_UID16 is not set
  12. +# CONFIG_KALLSYMS is not set
  13. +CONFIG_EMBEDDED=y
  14. +# CONFIG_VM_EVENT_COUNTERS is not set
  15. +# CONFIG_COMPAT_BRK is not set
  16. +CONFIG_SLAB=y
  17. +CONFIG_MODULES=y
  18. +CONFIG_MODULE_UNLOAD=y
  19. +CONFIG_MODVERSIONS=y
  20. +CONFIG_MODULE_SRCVERSION_ALL=y
  21. +# CONFIG_BLK_DEV_BSG is not set
  22. +CONFIG_ARCH_BCM2708=y
  23. +CONFIG_NO_HZ=y
  24. +CONFIG_HIGH_RES_TIMERS=y
  25. +CONFIG_AEABI=y
  26. +CONFIG_ZBOOT_ROM_TEXT=0x0
  27. +CONFIG_ZBOOT_ROM_BSS=0x0
  28. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  29. +CONFIG_CPU_IDLE=y
  30. +CONFIG_VFP=y
  31. +CONFIG_BINFMT_MISC=m
  32. +CONFIG_NET=y
  33. +CONFIG_PACKET=y
  34. +CONFIG_UNIX=y
  35. +CONFIG_XFRM_USER=y
  36. +CONFIG_NET_KEY=m
  37. +CONFIG_INET=y
  38. +CONFIG_IP_MULTICAST=y
  39. +CONFIG_IP_PNP=y
  40. +CONFIG_IP_PNP_DHCP=y
  41. +CONFIG_IP_PNP_RARP=y
  42. +CONFIG_SYN_COOKIES=y
  43. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  44. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  45. +# CONFIG_INET_XFRM_MODE_BEET is not set
  46. +# CONFIG_INET_LRO is not set
  47. +# CONFIG_INET_DIAG is not set
  48. +# CONFIG_IPV6 is not set
  49. +CONFIG_NET_PKTGEN=m
  50. +CONFIG_IRDA=m
  51. +CONFIG_IRLAN=m
  52. +CONFIG_IRCOMM=m
  53. +CONFIG_IRDA_ULTRA=y
  54. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  55. +CONFIG_IRDA_FAST_RR=y
  56. +CONFIG_IRTTY_SIR=m
  57. +CONFIG_KINGSUN_DONGLE=m
  58. +CONFIG_KSDAZZLE_DONGLE=m
  59. +CONFIG_KS959_DONGLE=m
  60. +CONFIG_USB_IRDA=m
  61. +CONFIG_SIGMATEL_FIR=m
  62. +CONFIG_MCS_FIR=m
  63. +CONFIG_BT=m
  64. +CONFIG_BT_L2CAP=y
  65. +CONFIG_BT_SCO=y
  66. +CONFIG_BT_RFCOMM=m
  67. +CONFIG_BT_RFCOMM_TTY=y
  68. +CONFIG_BT_BNEP=m
  69. +CONFIG_BT_BNEP_MC_FILTER=y
  70. +CONFIG_BT_BNEP_PROTO_FILTER=y
  71. +CONFIG_BT_HIDP=m
  72. +CONFIG_BT_HCIBTUSB=m
  73. +CONFIG_BT_HCIBCM203X=m
  74. +CONFIG_BT_HCIBPA10X=m
  75. +CONFIG_BT_HCIBFUSB=m
  76. +CONFIG_BT_HCIVHCI=m
  77. +CONFIG_BT_MRVL=m
  78. +CONFIG_BT_MRVL_SDIO=m
  79. +CONFIG_BT_ATH3K=m
  80. +CONFIG_CFG80211=m
  81. +CONFIG_MAC80211=m
  82. +CONFIG_MAC80211_RC_PID=y
  83. +CONFIG_MAC80211_MESH=y
  84. +CONFIG_WIMAX=m
  85. +CONFIG_NET_9P=m
  86. +CONFIG_NFC=m
  87. +CONFIG_NFC_PN533=m
  88. +CONFIG_DEVTMPFS=y
  89. +CONFIG_BLK_DEV_LOOP=y
  90. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  91. +CONFIG_BLK_DEV_NBD=m
  92. +CONFIG_BLK_DEV_RAM=y
  93. +CONFIG_CDROM_PKTCDVD=m
  94. +CONFIG_MISC_DEVICES=y
  95. +CONFIG_SCSI=y
  96. +# CONFIG_SCSI_PROC_FS is not set
  97. +CONFIG_BLK_DEV_SD=m
  98. +CONFIG_BLK_DEV_SR=m
  99. +CONFIG_SCSI_MULTI_LUN=y
  100. +# CONFIG_SCSI_LOWLEVEL is not set
  101. +CONFIG_NETDEVICES=y
  102. +CONFIG_TUN=m
  103. +CONFIG_PHYLIB=m
  104. +CONFIG_MDIO_BITBANG=m
  105. +CONFIG_NET_ETHERNET=y
  106. +# CONFIG_NETDEV_1000 is not set
  107. +# CONFIG_NETDEV_10000 is not set
  108. +CONFIG_LIBERTAS_THINFIRM=m
  109. +CONFIG_LIBERTAS_THINFIRM_USB=m
  110. +CONFIG_AT76C50X_USB=m
  111. +CONFIG_USB_ZD1201=m
  112. +CONFIG_USB_NET_RNDIS_WLAN=m
  113. +CONFIG_RTL8187=m
  114. +CONFIG_MAC80211_HWSIM=m
  115. +CONFIG_ATH_COMMON=m
  116. +CONFIG_ATH9K=m
  117. +CONFIG_ATH9K_HTC=m
  118. +CONFIG_CARL9170=m
  119. +CONFIG_B43=m
  120. +CONFIG_B43LEGACY=m
  121. +CONFIG_HOSTAP=m
  122. +CONFIG_IWM=m
  123. +CONFIG_LIBERTAS=m
  124. +CONFIG_LIBERTAS_USB=m
  125. +CONFIG_LIBERTAS_SDIO=m
  126. +CONFIG_P54_COMMON=m
  127. +CONFIG_P54_USB=m
  128. +CONFIG_RT2X00=m
  129. +CONFIG_RT2500USB=m
  130. +CONFIG_RT73USB=m
  131. +CONFIG_RT2800USB=m
  132. +CONFIG_RT2800USB_RT53XX=y
  133. +CONFIG_RTL8192CU=m
  134. +CONFIG_WL1251=m
  135. +CONFIG_WL12XX_MENU=m
  136. +CONFIG_ZD1211RW=m
  137. +CONFIG_MWIFIEX=m
  138. +CONFIG_MWIFIEX_SDIO=m
  139. +CONFIG_WIMAX_I2400M_USB=m
  140. +CONFIG_USB_CATC=m
  141. +CONFIG_USB_KAWETH=m
  142. +CONFIG_USB_PEGASUS=m
  143. +CONFIG_USB_RTL8150=m
  144. +CONFIG_USB_USBNET=y
  145. +CONFIG_USB_NET_AX8817X=m
  146. +CONFIG_USB_NET_CDCETHER=m
  147. +CONFIG_USB_NET_CDC_EEM=m
  148. +CONFIG_USB_NET_DM9601=m
  149. +CONFIG_USB_NET_SMSC75XX=m
  150. +CONFIG_USB_NET_SMSC95XX=y
  151. +CONFIG_USB_NET_GL620A=m
  152. +CONFIG_USB_NET_NET1080=m
  153. +CONFIG_USB_NET_PLUSB=m
  154. +CONFIG_USB_NET_MCS7830=m
  155. +CONFIG_USB_NET_CDC_SUBSET=m
  156. +CONFIG_USB_ALI_M5632=y
  157. +CONFIG_USB_AN2720=y
  158. +CONFIG_USB_KC2190=y
  159. +# CONFIG_USB_NET_ZAURUS is not set
  160. +CONFIG_USB_NET_CX82310_ETH=m
  161. +CONFIG_USB_NET_KALMIA=m
  162. +CONFIG_USB_NET_INT51X1=m
  163. +CONFIG_USB_IPHETH=m
  164. +CONFIG_USB_SIERRA_NET=m
  165. +CONFIG_USB_VL600=m
  166. +CONFIG_PPP=m
  167. +CONFIG_PPP_ASYNC=m
  168. +CONFIG_PPP_SYNC_TTY=m
  169. +CONFIG_PPP_DEFLATE=m
  170. +CONFIG_PPP_BSDCOMP=m
  171. +CONFIG_SLIP=m
  172. +CONFIG_SLIP_COMPRESSED=y
  173. +CONFIG_NETCONSOLE=m
  174. +CONFIG_INPUT_POLLDEV=m
  175. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  176. +CONFIG_INPUT_JOYDEV=m
  177. +CONFIG_INPUT_EVDEV=m
  178. +# CONFIG_INPUT_KEYBOARD is not set
  179. +# CONFIG_INPUT_MOUSE is not set
  180. +CONFIG_INPUT_MISC=y
  181. +CONFIG_INPUT_AD714X=m
  182. +CONFIG_INPUT_ATI_REMOTE=m
  183. +CONFIG_INPUT_ATI_REMOTE2=m
  184. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  185. +CONFIG_INPUT_POWERMATE=m
  186. +CONFIG_INPUT_YEALINK=m
  187. +CONFIG_INPUT_CM109=m
  188. +CONFIG_INPUT_UINPUT=m
  189. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  190. +CONFIG_INPUT_ADXL34X=m
  191. +CONFIG_INPUT_CMA3000=m
  192. +CONFIG_SERIO=m
  193. +CONFIG_SERIO_RAW=m
  194. +CONFIG_GAMEPORT=m
  195. +CONFIG_GAMEPORT_NS558=m
  196. +CONFIG_GAMEPORT_L4=m
  197. +CONFIG_VT_HW_CONSOLE_BINDING=y
  198. +# CONFIG_LEGACY_PTYS is not set
  199. +# CONFIG_DEVKMEM is not set
  200. +CONFIG_SERIAL_AMBA_PL011=y
  201. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  202. +# CONFIG_HW_RANDOM is not set
  203. +CONFIG_RAW_DRIVER=y
  204. +CONFIG_GPIO_SYSFS=y
  205. +# CONFIG_HWMON is not set
  206. +CONFIG_WATCHDOG=y
  207. +CONFIG_BCM2708_WDT=m
  208. +# CONFIG_MFD_SUPPORT is not set
  209. +CONFIG_FB=y
  210. +CONFIG_FB_BCM2708=y
  211. +CONFIG_FRAMEBUFFER_CONSOLE=y
  212. +CONFIG_LOGO=y
  213. +# CONFIG_LOGO_LINUX_MONO is not set
  214. +# CONFIG_LOGO_LINUX_VGA16 is not set
  215. +CONFIG_SOUND=y
  216. +CONFIG_SND=m
  217. +CONFIG_SND_SEQUENCER=m
  218. +CONFIG_SND_SEQ_DUMMY=m
  219. +CONFIG_SND_MIXER_OSS=m
  220. +CONFIG_SND_PCM_OSS=m
  221. +CONFIG_SND_SEQUENCER_OSS=y
  222. +CONFIG_SND_HRTIMER=m
  223. +CONFIG_SND_DUMMY=m
  224. +CONFIG_SND_ALOOP=m
  225. +CONFIG_SND_VIRMIDI=m
  226. +CONFIG_SND_MTPAV=m
  227. +CONFIG_SND_SERIAL_U16550=m
  228. +CONFIG_SND_MPU401=m
  229. +CONFIG_SND_BCM2835=m
  230. +CONFIG_SND_USB_AUDIO=m
  231. +CONFIG_SND_USB_UA101=m
  232. +CONFIG_SND_USB_CAIAQ=m
  233. +CONFIG_SND_USB_6FIRE=m
  234. +CONFIG_SOUND_PRIME=m
  235. +CONFIG_HID_PID=y
  236. +CONFIG_USB_HIDDEV=y
  237. +CONFIG_HID_A4TECH=m
  238. +CONFIG_HID_ACRUX=m
  239. +CONFIG_HID_APPLE=m
  240. +CONFIG_HID_BELKIN=m
  241. +CONFIG_HID_CHERRY=m
  242. +CONFIG_HID_CHICONY=m
  243. +CONFIG_HID_CYPRESS=m
  244. +CONFIG_HID_DRAGONRISE=m
  245. +CONFIG_HID_EMS_FF=m
  246. +CONFIG_HID_ELECOM=m
  247. +CONFIG_HID_EZKEY=m
  248. +CONFIG_HID_HOLTEK=m
  249. +CONFIG_HID_KEYTOUCH=m
  250. +CONFIG_HID_KYE=m
  251. +CONFIG_HID_UCLOGIC=m
  252. +CONFIG_HID_WALTOP=m
  253. +CONFIG_HID_GYRATION=m
  254. +CONFIG_HID_TWINHAN=m
  255. +CONFIG_HID_KENSINGTON=m
  256. +CONFIG_HID_LCPOWER=m
  257. +CONFIG_HID_LOGITECH=m
  258. +CONFIG_HID_MAGICMOUSE=m
  259. +CONFIG_HID_MICROSOFT=m
  260. +CONFIG_HID_MONTEREY=m
  261. +CONFIG_HID_MULTITOUCH=m
  262. +CONFIG_HID_NTRIG=m
  263. +CONFIG_HID_ORTEK=m
  264. +CONFIG_HID_PANTHERLORD=m
  265. +CONFIG_HID_PETALYNX=m
  266. +CONFIG_HID_PICOLCD=m
  267. +CONFIG_HID_QUANTA=m
  268. +CONFIG_HID_ROCCAT=m
  269. +CONFIG_HID_SAMSUNG=m
  270. +CONFIG_HID_SONY=m
  271. +CONFIG_HID_SPEEDLINK=m
  272. +CONFIG_HID_SUNPLUS=m
  273. +CONFIG_HID_GREENASIA=m
  274. +CONFIG_HID_SMARTJOYPLUS=m
  275. +CONFIG_HID_TOPSEED=m
  276. +CONFIG_HID_THRUSTMASTER=m
  277. +CONFIG_HID_WACOM=m
  278. +CONFIG_HID_WIIMOTE=m
  279. +CONFIG_HID_ZEROPLUS=m
  280. +CONFIG_HID_ZYDACRON=m
  281. +CONFIG_USB=y
  282. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  283. +CONFIG_USB_MON=m
  284. +CONFIG_USB_DWCOTG=y
  285. +CONFIG_USB_STORAGE=y
  286. +CONFIG_USB_STORAGE_REALTEK=m
  287. +CONFIG_USB_STORAGE_DATAFAB=m
  288. +CONFIG_USB_STORAGE_FREECOM=m
  289. +CONFIG_USB_STORAGE_ISD200=m
  290. +CONFIG_USB_STORAGE_USBAT=m
  291. +CONFIG_USB_STORAGE_SDDR09=m
  292. +CONFIG_USB_STORAGE_SDDR55=m
  293. +CONFIG_USB_STORAGE_JUMPSHOT=m
  294. +CONFIG_USB_STORAGE_ALAUDA=m
  295. +CONFIG_USB_STORAGE_ONETOUCH=m
  296. +CONFIG_USB_STORAGE_KARMA=m
  297. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  298. +CONFIG_USB_STORAGE_ENE_UB6250=m
  299. +CONFIG_USB_UAS=m
  300. +CONFIG_USB_LIBUSUAL=y
  301. +CONFIG_USB_MDC800=m
  302. +CONFIG_USB_MICROTEK=m
  303. +CONFIG_USB_SERIAL=m
  304. +CONFIG_USB_SERIAL_GENERIC=y
  305. +CONFIG_USB_SERIAL_AIRCABLE=m
  306. +CONFIG_USB_SERIAL_ARK3116=m
  307. +CONFIG_USB_SERIAL_BELKIN=m
  308. +CONFIG_USB_SERIAL_CH341=m
  309. +CONFIG_USB_SERIAL_WHITEHEAT=m
  310. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  311. +CONFIG_USB_SERIAL_CP210X=m
  312. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  313. +CONFIG_USB_SERIAL_EMPEG=m
  314. +CONFIG_USB_SERIAL_FTDI_SIO=m
  315. +CONFIG_USB_SERIAL_FUNSOFT=m
  316. +CONFIG_USB_SERIAL_VISOR=m
  317. +CONFIG_USB_SERIAL_IPAQ=m
  318. +CONFIG_USB_SERIAL_IR=m
  319. +CONFIG_USB_SERIAL_EDGEPORT=m
  320. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  321. +CONFIG_USB_SERIAL_GARMIN=m
  322. +CONFIG_USB_SERIAL_IPW=m
  323. +CONFIG_USB_SERIAL_IUU=m
  324. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  325. +CONFIG_USB_SERIAL_KEYSPAN=m
  326. +CONFIG_USB_SERIAL_KLSI=m
  327. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  328. +CONFIG_USB_SERIAL_MCT_U232=m
  329. +CONFIG_USB_SERIAL_MOS7720=m
  330. +CONFIG_USB_SERIAL_MOS7840=m
  331. +CONFIG_USB_SERIAL_MOTOROLA=m
  332. +CONFIG_USB_SERIAL_NAVMAN=m
  333. +CONFIG_USB_SERIAL_PL2303=m
  334. +CONFIG_USB_SERIAL_OTI6858=m
  335. +CONFIG_USB_SERIAL_QCAUX=m
  336. +CONFIG_USB_SERIAL_QUALCOMM=m
  337. +CONFIG_USB_SERIAL_SPCP8X5=m
  338. +CONFIG_USB_SERIAL_HP4X=m
  339. +CONFIG_USB_SERIAL_SAFE=m
  340. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  341. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  342. +CONFIG_USB_SERIAL_SYMBOL=m
  343. +CONFIG_USB_SERIAL_TI=m
  344. +CONFIG_USB_SERIAL_CYBERJACK=m
  345. +CONFIG_USB_SERIAL_XIRCOM=m
  346. +CONFIG_USB_SERIAL_OPTION=m
  347. +CONFIG_USB_SERIAL_OMNINET=m
  348. +CONFIG_USB_SERIAL_OPTICON=m
  349. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  350. +CONFIG_USB_SERIAL_ZIO=m
  351. +CONFIG_USB_SERIAL_SSU100=m
  352. +CONFIG_USB_SERIAL_DEBUG=m
  353. +CONFIG_USB_EMI62=m
  354. +CONFIG_USB_EMI26=m
  355. +CONFIG_USB_ADUTUX=m
  356. +CONFIG_USB_SEVSEG=m
  357. +CONFIG_USB_RIO500=m
  358. +CONFIG_USB_LEGOTOWER=m
  359. +CONFIG_USB_LCD=m
  360. +CONFIG_USB_LED=m
  361. +CONFIG_USB_CYPRESS_CY7C63=m
  362. +CONFIG_USB_CYTHERM=m
  363. +CONFIG_USB_IDMOUSE=m
  364. +CONFIG_USB_FTDI_ELAN=m
  365. +CONFIG_USB_APPLEDISPLAY=m
  366. +CONFIG_USB_LD=m
  367. +CONFIG_USB_TRANCEVIBRATOR=m
  368. +CONFIG_USB_IOWARRIOR=m
  369. +CONFIG_USB_TEST=m
  370. +CONFIG_USB_ISIGHTFW=m
  371. +CONFIG_USB_YUREX=m
  372. +CONFIG_MMC=y
  373. +CONFIG_MMC_SDHCI=y
  374. +CONFIG_MMC_SDHCI_PLTFM=y
  375. +CONFIG_MMC_SDHCI_BCM2708=y
  376. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  377. +CONFIG_LEDS_GPIO=y
  378. +CONFIG_LEDS_TRIGGER_TIMER=m
  379. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  380. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  381. +CONFIG_UIO=m
  382. +CONFIG_UIO_PDRV=m
  383. +CONFIG_UIO_PDRV_GENIRQ=m
  384. +# CONFIG_IOMMU_SUPPORT is not set
  385. +CONFIG_EXT4_FS=y
  386. +CONFIG_EXT4_FS_POSIX_ACL=y
  387. +CONFIG_EXT4_FS_SECURITY=y
  388. +CONFIG_REISERFS_FS=m
  389. +CONFIG_REISERFS_FS_XATTR=y
  390. +CONFIG_REISERFS_FS_POSIX_ACL=y
  391. +CONFIG_REISERFS_FS_SECURITY=y
  392. +CONFIG_JFS_FS=m
  393. +CONFIG_JFS_POSIX_ACL=y
  394. +CONFIG_JFS_SECURITY=y
  395. +CONFIG_XFS_FS=m
  396. +CONFIG_XFS_QUOTA=y
  397. +CONFIG_XFS_POSIX_ACL=y
  398. +CONFIG_XFS_RT=y
  399. +CONFIG_GFS2_FS=m
  400. +CONFIG_OCFS2_FS=m
  401. +CONFIG_BTRFS_FS=m
  402. +CONFIG_BTRFS_FS_POSIX_ACL=y
  403. +CONFIG_NILFS2_FS=m
  404. +CONFIG_AUTOFS4_FS=y
  405. +CONFIG_FUSE_FS=m
  406. +CONFIG_CUSE=m
  407. +CONFIG_FSCACHE=y
  408. +CONFIG_CACHEFILES=y
  409. +CONFIG_ISO9660_FS=m
  410. +CONFIG_JOLIET=y
  411. +CONFIG_ZISOFS=y
  412. +CONFIG_UDF_FS=m
  413. +CONFIG_MSDOS_FS=y
  414. +CONFIG_VFAT_FS=y
  415. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  416. +CONFIG_NTFS_FS=m
  417. +CONFIG_TMPFS=y
  418. +CONFIG_TMPFS_POSIX_ACL=y
  419. +CONFIG_CONFIGFS_FS=y
  420. +CONFIG_SQUASHFS=m
  421. +CONFIG_SQUASHFS_XATTR=y
  422. +CONFIG_SQUASHFS_LZO=y
  423. +CONFIG_SQUASHFS_XZ=y
  424. +CONFIG_NFS_FS=y
  425. +CONFIG_NFS_V3=y
  426. +CONFIG_NFS_V3_ACL=y
  427. +CONFIG_NFS_V4=y
  428. +CONFIG_ROOT_NFS=y
  429. +CONFIG_NFS_FSCACHE=y
  430. +CONFIG_CIFS=m
  431. +CONFIG_CIFS_WEAK_PW_HASH=y
  432. +CONFIG_CIFS_XATTR=y
  433. +CONFIG_CIFS_POSIX=y
  434. +CONFIG_9P_FS=m
  435. +CONFIG_PARTITION_ADVANCED=y
  436. +CONFIG_MAC_PARTITION=y
  437. +CONFIG_EFI_PARTITION=y
  438. +CONFIG_NLS_DEFAULT="utf8"
  439. +CONFIG_NLS_CODEPAGE_437=y
  440. +CONFIG_NLS_CODEPAGE_737=m
  441. +CONFIG_NLS_CODEPAGE_775=m
  442. +CONFIG_NLS_CODEPAGE_850=m
  443. +CONFIG_NLS_CODEPAGE_852=m
  444. +CONFIG_NLS_CODEPAGE_855=m
  445. +CONFIG_NLS_CODEPAGE_857=m
  446. +CONFIG_NLS_CODEPAGE_860=m
  447. +CONFIG_NLS_CODEPAGE_861=m
  448. +CONFIG_NLS_CODEPAGE_862=m
  449. +CONFIG_NLS_CODEPAGE_863=m
  450. +CONFIG_NLS_CODEPAGE_864=m
  451. +CONFIG_NLS_CODEPAGE_865=m
  452. +CONFIG_NLS_CODEPAGE_866=m
  453. +CONFIG_NLS_CODEPAGE_869=m
  454. +CONFIG_NLS_CODEPAGE_936=m
  455. +CONFIG_NLS_CODEPAGE_950=m
  456. +CONFIG_NLS_CODEPAGE_932=m
  457. +CONFIG_NLS_CODEPAGE_949=m
  458. +CONFIG_NLS_CODEPAGE_874=m
  459. +CONFIG_NLS_ISO8859_8=m
  460. +CONFIG_NLS_CODEPAGE_1250=m
  461. +CONFIG_NLS_CODEPAGE_1251=m
  462. +CONFIG_NLS_ASCII=y
  463. +CONFIG_NLS_ISO8859_1=m
  464. +CONFIG_NLS_ISO8859_2=m
  465. +CONFIG_NLS_ISO8859_3=m
  466. +CONFIG_NLS_ISO8859_4=m
  467. +CONFIG_NLS_ISO8859_5=m
  468. +CONFIG_NLS_ISO8859_6=m
  469. +CONFIG_NLS_ISO8859_7=m
  470. +CONFIG_NLS_ISO8859_9=m
  471. +CONFIG_NLS_ISO8859_13=m
  472. +CONFIG_NLS_ISO8859_14=m
  473. +CONFIG_NLS_ISO8859_15=m
  474. +CONFIG_NLS_KOI8_R=m
  475. +CONFIG_NLS_KOI8_U=m
  476. +CONFIG_NLS_UTF8=m
  477. +# CONFIG_SCHED_DEBUG is not set
  478. +# CONFIG_DEBUG_BUGVERBOSE is not set
  479. +# CONFIG_FTRACE is not set
  480. +# CONFIG_ARM_UNWIND is not set
  481. +CONFIG_CRYPTO_AUTHENC=m
  482. +CONFIG_CRYPTO_SEQIV=m
  483. +CONFIG_CRYPTO_CBC=y
  484. +CONFIG_CRYPTO_HMAC=y
  485. +CONFIG_CRYPTO_XCBC=m
  486. +CONFIG_CRYPTO_MD5=y
  487. +CONFIG_CRYPTO_SHA1=y
  488. +CONFIG_CRYPTO_SHA256=m
  489. +CONFIG_CRYPTO_SHA512=m
  490. +CONFIG_CRYPTO_TGR192=m
  491. +CONFIG_CRYPTO_WP512=m
  492. +CONFIG_CRYPTO_CAST5=m
  493. +CONFIG_CRYPTO_DES=y
  494. +CONFIG_CRYPTO_DEFLATE=m
  495. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  496. +# CONFIG_CRYPTO_HW is not set
  497. +CONFIG_CRC_ITU_T=y
  498. +CONFIG_LIBCRC32C=y
  499. +CONFIG_I2C=y
  500. +CONFIG_I2C_BOARDINFO=y
  501. +CONFIG_I2C_COMPAT=y
  502. +CONFIG_I2C_CHARDEV=m
  503. +CONFIG_I2C_HELPER_AUTO=y
  504. +CONFIG_I2C_BCM2708=m
  505. +CONFIG_SPI=y
  506. +CONFIG_SPI_MASTER=y
  507. +CONFIG_SPI_BCM2708=m
  508. +
  509. diff -Nur linux-3.10.33/arch/arm/configs/bcmrpi_defconfig linux-raspberry-pi/arch/arm/configs/bcmrpi_defconfig
  510. --- linux-3.10.33/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  511. +++ linux-raspberry-pi/arch/arm/configs/bcmrpi_defconfig 2014-03-13 12:46:12.312043485 +0100
  512. @@ -0,0 +1,1093 @@
  513. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  514. +# CONFIG_LOCALVERSION_AUTO is not set
  515. +CONFIG_SYSVIPC=y
  516. +CONFIG_POSIX_MQUEUE=y
  517. +CONFIG_FHANDLE=y
  518. +CONFIG_AUDIT=y
  519. +CONFIG_NO_HZ=y
  520. +CONFIG_HIGH_RES_TIMERS=y
  521. +CONFIG_BSD_PROCESS_ACCT=y
  522. +CONFIG_BSD_PROCESS_ACCT_V3=y
  523. +CONFIG_TASKSTATS=y
  524. +CONFIG_TASK_DELAY_ACCT=y
  525. +CONFIG_TASK_XACCT=y
  526. +CONFIG_TASK_IO_ACCOUNTING=y
  527. +CONFIG_IKCONFIG=y
  528. +CONFIG_IKCONFIG_PROC=y
  529. +CONFIG_CGROUP_FREEZER=y
  530. +CONFIG_CGROUP_DEVICE=y
  531. +CONFIG_CGROUP_CPUACCT=y
  532. +CONFIG_RESOURCE_COUNTERS=y
  533. +CONFIG_MEMCG=y
  534. +CONFIG_BLK_CGROUP=y
  535. +CONFIG_NAMESPACES=y
  536. +CONFIG_SCHED_AUTOGROUP=y
  537. +CONFIG_RELAY=y
  538. +CONFIG_BLK_DEV_INITRD=y
  539. +CONFIG_EMBEDDED=y
  540. +# CONFIG_COMPAT_BRK is not set
  541. +CONFIG_PROFILING=y
  542. +CONFIG_OPROFILE=m
  543. +CONFIG_KPROBES=y
  544. +CONFIG_JUMP_LABEL=y
  545. +CONFIG_MODULES=y
  546. +CONFIG_MODULE_UNLOAD=y
  547. +CONFIG_MODVERSIONS=y
  548. +CONFIG_MODULE_SRCVERSION_ALL=y
  549. +CONFIG_BLK_DEV_THROTTLING=y
  550. +CONFIG_PARTITION_ADVANCED=y
  551. +CONFIG_MAC_PARTITION=y
  552. +CONFIG_CFQ_GROUP_IOSCHED=y
  553. +CONFIG_ARCH_BCM2708=y
  554. +CONFIG_PREEMPT=y
  555. +CONFIG_AEABI=y
  556. +CONFIG_CLEANCACHE=y
  557. +CONFIG_FRONTSWAP=y
  558. +CONFIG_UACCESS_WITH_MEMCPY=y
  559. +CONFIG_SECCOMP=y
  560. +CONFIG_CC_STACKPROTECTOR=y
  561. +CONFIG_ZBOOT_ROM_TEXT=0x0
  562. +CONFIG_ZBOOT_ROM_BSS=0x0
  563. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  564. +CONFIG_KEXEC=y
  565. +CONFIG_CPU_FREQ=y
  566. +CONFIG_CPU_FREQ_STAT=m
  567. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  568. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  569. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  570. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  571. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  572. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  573. +CONFIG_CPU_IDLE=y
  574. +CONFIG_VFP=y
  575. +CONFIG_BINFMT_MISC=m
  576. +CONFIG_NET=y
  577. +CONFIG_PACKET=y
  578. +CONFIG_UNIX=y
  579. +CONFIG_XFRM_USER=y
  580. +CONFIG_NET_KEY=m
  581. +CONFIG_INET=y
  582. +CONFIG_IP_MULTICAST=y
  583. +CONFIG_IP_ADVANCED_ROUTER=y
  584. +CONFIG_IP_MULTIPLE_TABLES=y
  585. +CONFIG_IP_ROUTE_MULTIPATH=y
  586. +CONFIG_IP_ROUTE_VERBOSE=y
  587. +CONFIG_IP_PNP=y
  588. +CONFIG_IP_PNP_DHCP=y
  589. +CONFIG_IP_PNP_RARP=y
  590. +CONFIG_NET_IPIP=m
  591. +CONFIG_NET_IPGRE_DEMUX=m
  592. +CONFIG_NET_IPGRE=m
  593. +CONFIG_IP_MROUTE=y
  594. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  595. +CONFIG_IP_PIMSM_V1=y
  596. +CONFIG_IP_PIMSM_V2=y
  597. +CONFIG_SYN_COOKIES=y
  598. +CONFIG_INET_AH=m
  599. +CONFIG_INET_ESP=m
  600. +CONFIG_INET_IPCOMP=m
  601. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  602. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  603. +CONFIG_INET_XFRM_MODE_BEET=m
  604. +CONFIG_INET_LRO=m
  605. +CONFIG_INET_DIAG=m
  606. +CONFIG_IPV6_PRIVACY=y
  607. +CONFIG_INET6_AH=m
  608. +CONFIG_INET6_ESP=m
  609. +CONFIG_INET6_IPCOMP=m
  610. +CONFIG_IPV6_TUNNEL=m
  611. +CONFIG_IPV6_MULTIPLE_TABLES=y
  612. +CONFIG_IPV6_MROUTE=y
  613. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  614. +CONFIG_IPV6_PIMSM_V2=y
  615. +CONFIG_NETFILTER=y
  616. +CONFIG_NF_CONNTRACK=m
  617. +CONFIG_NF_CONNTRACK_ZONES=y
  618. +CONFIG_NF_CONNTRACK_EVENTS=y
  619. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  620. +CONFIG_NF_CT_PROTO_DCCP=m
  621. +CONFIG_NF_CT_PROTO_UDPLITE=m
  622. +CONFIG_NF_CONNTRACK_AMANDA=m
  623. +CONFIG_NF_CONNTRACK_FTP=m
  624. +CONFIG_NF_CONNTRACK_H323=m
  625. +CONFIG_NF_CONNTRACK_IRC=m
  626. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  627. +CONFIG_NF_CONNTRACK_SNMP=m
  628. +CONFIG_NF_CONNTRACK_PPTP=m
  629. +CONFIG_NF_CONNTRACK_SANE=m
  630. +CONFIG_NF_CONNTRACK_SIP=m
  631. +CONFIG_NF_CONNTRACK_TFTP=m
  632. +CONFIG_NF_CT_NETLINK=m
  633. +CONFIG_NETFILTER_TPROXY=m
  634. +CONFIG_NETFILTER_XT_SET=m
  635. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  636. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  637. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  638. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  639. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  640. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  641. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  642. +CONFIG_NETFILTER_XT_TARGET_LED=m
  643. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  644. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  645. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  646. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  647. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  648. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  649. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  650. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  651. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  652. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  653. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  654. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  655. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  656. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  657. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  658. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  659. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  660. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  661. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  662. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  663. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  664. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  665. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  666. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  667. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  668. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  669. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  670. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  671. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  672. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  673. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  674. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  675. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  676. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  677. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  678. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  679. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  680. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  681. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  682. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  683. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  684. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  685. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  686. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  687. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  688. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  689. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  690. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  691. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  692. +CONFIG_NETFILTER_XT_MATCH_U32=m
  693. +CONFIG_IP_SET=m
  694. +CONFIG_IP_SET_BITMAP_IP=m
  695. +CONFIG_IP_SET_BITMAP_IPMAC=m
  696. +CONFIG_IP_SET_BITMAP_PORT=m
  697. +CONFIG_IP_SET_HASH_IP=m
  698. +CONFIG_IP_SET_HASH_IPPORT=m
  699. +CONFIG_IP_SET_HASH_IPPORTIP=m
  700. +CONFIG_IP_SET_HASH_IPPORTNET=m
  701. +CONFIG_IP_SET_HASH_NET=m
  702. +CONFIG_IP_SET_HASH_NETPORT=m
  703. +CONFIG_IP_SET_HASH_NETIFACE=m
  704. +CONFIG_IP_SET_LIST_SET=m
  705. +CONFIG_IP_VS=m
  706. +CONFIG_IP_VS_PROTO_TCP=y
  707. +CONFIG_IP_VS_PROTO_UDP=y
  708. +CONFIG_IP_VS_PROTO_ESP=y
  709. +CONFIG_IP_VS_PROTO_AH=y
  710. +CONFIG_IP_VS_PROTO_SCTP=y
  711. +CONFIG_IP_VS_RR=m
  712. +CONFIG_IP_VS_WRR=m
  713. +CONFIG_IP_VS_LC=m
  714. +CONFIG_IP_VS_WLC=m
  715. +CONFIG_IP_VS_LBLC=m
  716. +CONFIG_IP_VS_LBLCR=m
  717. +CONFIG_IP_VS_DH=m
  718. +CONFIG_IP_VS_SH=m
  719. +CONFIG_IP_VS_SED=m
  720. +CONFIG_IP_VS_NQ=m
  721. +CONFIG_IP_VS_FTP=m
  722. +CONFIG_IP_VS_PE_SIP=m
  723. +CONFIG_NF_CONNTRACK_IPV4=m
  724. +CONFIG_IP_NF_IPTABLES=m
  725. +CONFIG_IP_NF_MATCH_AH=m
  726. +CONFIG_IP_NF_MATCH_ECN=m
  727. +CONFIG_IP_NF_MATCH_TTL=m
  728. +CONFIG_IP_NF_FILTER=m
  729. +CONFIG_IP_NF_TARGET_REJECT=m
  730. +CONFIG_IP_NF_TARGET_ULOG=m
  731. +CONFIG_NF_NAT_IPV4=m
  732. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  733. +CONFIG_IP_NF_TARGET_NETMAP=m
  734. +CONFIG_IP_NF_TARGET_REDIRECT=m
  735. +CONFIG_IP_NF_MANGLE=m
  736. +CONFIG_IP_NF_TARGET_ECN=m
  737. +CONFIG_IP_NF_TARGET_TTL=m
  738. +CONFIG_IP_NF_RAW=m
  739. +CONFIG_IP_NF_ARPTABLES=m
  740. +CONFIG_IP_NF_ARPFILTER=m
  741. +CONFIG_IP_NF_ARP_MANGLE=m
  742. +CONFIG_NF_CONNTRACK_IPV6=m
  743. +CONFIG_IP6_NF_IPTABLES=m
  744. +CONFIG_IP6_NF_MATCH_AH=m
  745. +CONFIG_IP6_NF_MATCH_EUI64=m
  746. +CONFIG_IP6_NF_MATCH_FRAG=m
  747. +CONFIG_IP6_NF_MATCH_OPTS=m
  748. +CONFIG_IP6_NF_MATCH_HL=m
  749. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  750. +CONFIG_IP6_NF_MATCH_MH=m
  751. +CONFIG_IP6_NF_MATCH_RT=m
  752. +CONFIG_IP6_NF_TARGET_HL=m
  753. +CONFIG_IP6_NF_FILTER=m
  754. +CONFIG_IP6_NF_TARGET_REJECT=m
  755. +CONFIG_IP6_NF_MANGLE=m
  756. +CONFIG_IP6_NF_RAW=m
  757. +CONFIG_NF_NAT_IPV6=m
  758. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  759. +CONFIG_IP6_NF_TARGET_NPT=m
  760. +CONFIG_BRIDGE_NF_EBTABLES=m
  761. +CONFIG_BRIDGE_EBT_BROUTE=m
  762. +CONFIG_BRIDGE_EBT_T_FILTER=m
  763. +CONFIG_BRIDGE_EBT_T_NAT=m
  764. +CONFIG_BRIDGE_EBT_802_3=m
  765. +CONFIG_BRIDGE_EBT_AMONG=m
  766. +CONFIG_BRIDGE_EBT_ARP=m
  767. +CONFIG_BRIDGE_EBT_IP=m
  768. +CONFIG_BRIDGE_EBT_IP6=m
  769. +CONFIG_BRIDGE_EBT_LIMIT=m
  770. +CONFIG_BRIDGE_EBT_MARK=m
  771. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  772. +CONFIG_BRIDGE_EBT_STP=m
  773. +CONFIG_BRIDGE_EBT_VLAN=m
  774. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  775. +CONFIG_BRIDGE_EBT_DNAT=m
  776. +CONFIG_BRIDGE_EBT_MARK_T=m
  777. +CONFIG_BRIDGE_EBT_REDIRECT=m
  778. +CONFIG_BRIDGE_EBT_SNAT=m
  779. +CONFIG_BRIDGE_EBT_LOG=m
  780. +CONFIG_BRIDGE_EBT_ULOG=m
  781. +CONFIG_BRIDGE_EBT_NFLOG=m
  782. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  783. +CONFIG_L2TP=m
  784. +CONFIG_BRIDGE=m
  785. +CONFIG_VLAN_8021Q=m
  786. +CONFIG_VLAN_8021Q_GVRP=y
  787. +CONFIG_ATALK=m
  788. +CONFIG_NET_SCHED=y
  789. +CONFIG_NET_SCH_CBQ=m
  790. +CONFIG_NET_SCH_HTB=m
  791. +CONFIG_NET_SCH_HFSC=m
  792. +CONFIG_NET_SCH_PRIO=m
  793. +CONFIG_NET_SCH_MULTIQ=m
  794. +CONFIG_NET_SCH_RED=m
  795. +CONFIG_NET_SCH_SFB=m
  796. +CONFIG_NET_SCH_SFQ=m
  797. +CONFIG_NET_SCH_TEQL=m
  798. +CONFIG_NET_SCH_TBF=m
  799. +CONFIG_NET_SCH_GRED=m
  800. +CONFIG_NET_SCH_DSMARK=m
  801. +CONFIG_NET_SCH_NETEM=m
  802. +CONFIG_NET_SCH_DRR=m
  803. +CONFIG_NET_SCH_MQPRIO=m
  804. +CONFIG_NET_SCH_CHOKE=m
  805. +CONFIG_NET_SCH_QFQ=m
  806. +CONFIG_NET_SCH_CODEL=m
  807. +CONFIG_NET_SCH_FQ_CODEL=m
  808. +CONFIG_NET_SCH_INGRESS=m
  809. +CONFIG_NET_SCH_PLUG=m
  810. +CONFIG_NET_CLS_BASIC=m
  811. +CONFIG_NET_CLS_TCINDEX=m
  812. +CONFIG_NET_CLS_ROUTE4=m
  813. +CONFIG_NET_CLS_FW=m
  814. +CONFIG_NET_CLS_U32=m
  815. +CONFIG_CLS_U32_MARK=y
  816. +CONFIG_NET_CLS_RSVP=m
  817. +CONFIG_NET_CLS_RSVP6=m
  818. +CONFIG_NET_CLS_FLOW=m
  819. +CONFIG_NET_CLS_CGROUP=m
  820. +CONFIG_NET_EMATCH=y
  821. +CONFIG_NET_EMATCH_CMP=m
  822. +CONFIG_NET_EMATCH_NBYTE=m
  823. +CONFIG_NET_EMATCH_U32=m
  824. +CONFIG_NET_EMATCH_META=m
  825. +CONFIG_NET_EMATCH_TEXT=m
  826. +CONFIG_NET_EMATCH_IPSET=m
  827. +CONFIG_NET_CLS_ACT=y
  828. +CONFIG_NET_ACT_POLICE=m
  829. +CONFIG_NET_ACT_GACT=m
  830. +CONFIG_GACT_PROB=y
  831. +CONFIG_NET_ACT_MIRRED=m
  832. +CONFIG_NET_ACT_IPT=m
  833. +CONFIG_NET_ACT_NAT=m
  834. +CONFIG_NET_ACT_PEDIT=m
  835. +CONFIG_NET_ACT_SIMP=m
  836. +CONFIG_NET_ACT_SKBEDIT=m
  837. +CONFIG_NET_ACT_CSUM=m
  838. +CONFIG_BATMAN_ADV=m
  839. +CONFIG_OPENVSWITCH=m
  840. +CONFIG_NET_PKTGEN=m
  841. +CONFIG_HAMRADIO=y
  842. +CONFIG_AX25=m
  843. +CONFIG_NETROM=m
  844. +CONFIG_ROSE=m
  845. +CONFIG_MKISS=m
  846. +CONFIG_6PACK=m
  847. +CONFIG_BPQETHER=m
  848. +CONFIG_BAYCOM_SER_FDX=m
  849. +CONFIG_BAYCOM_SER_HDX=m
  850. +CONFIG_YAM=m
  851. +CONFIG_IRDA=m
  852. +CONFIG_IRLAN=m
  853. +CONFIG_IRNET=m
  854. +CONFIG_IRCOMM=m
  855. +CONFIG_IRDA_ULTRA=y
  856. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  857. +CONFIG_IRDA_FAST_RR=y
  858. +CONFIG_IRTTY_SIR=m
  859. +CONFIG_KINGSUN_DONGLE=m
  860. +CONFIG_KSDAZZLE_DONGLE=m
  861. +CONFIG_KS959_DONGLE=m
  862. +CONFIG_USB_IRDA=m
  863. +CONFIG_SIGMATEL_FIR=m
  864. +CONFIG_MCS_FIR=m
  865. +CONFIG_BT=m
  866. +CONFIG_BT_RFCOMM=m
  867. +CONFIG_BT_RFCOMM_TTY=y
  868. +CONFIG_BT_BNEP=m
  869. +CONFIG_BT_BNEP_MC_FILTER=y
  870. +CONFIG_BT_BNEP_PROTO_FILTER=y
  871. +CONFIG_BT_HIDP=m
  872. +CONFIG_BT_HCIBTUSB=m
  873. +CONFIG_BT_HCIBCM203X=m
  874. +CONFIG_BT_HCIBPA10X=m
  875. +CONFIG_BT_HCIBFUSB=m
  876. +CONFIG_BT_HCIVHCI=m
  877. +CONFIG_BT_MRVL=m
  878. +CONFIG_BT_MRVL_SDIO=m
  879. +CONFIG_BT_ATH3K=m
  880. +CONFIG_BT_WILINK=m
  881. +CONFIG_CFG80211=m
  882. +CONFIG_CFG80211_WEXT=y
  883. +CONFIG_MAC80211=m
  884. +CONFIG_MAC80211_RC_PID=y
  885. +CONFIG_MAC80211_MESH=y
  886. +CONFIG_WIMAX=m
  887. +CONFIG_RFKILL=m
  888. +CONFIG_RFKILL_INPUT=y
  889. +CONFIG_NET_9P=m
  890. +CONFIG_NFC=m
  891. +CONFIG_NFC_PN533=m
  892. +CONFIG_DEVTMPFS=y
  893. +CONFIG_DEVTMPFS_MOUNT=y
  894. +CONFIG_CMA=y
  895. +CONFIG_BLK_DEV_LOOP=y
  896. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  897. +CONFIG_BLK_DEV_DRBD=m
  898. +CONFIG_BLK_DEV_NBD=m
  899. +CONFIG_BLK_DEV_RAM=y
  900. +CONFIG_CDROM_PKTCDVD=m
  901. +CONFIG_SCSI=y
  902. +# CONFIG_SCSI_PROC_FS is not set
  903. +CONFIG_BLK_DEV_SD=y
  904. +CONFIG_CHR_DEV_ST=m
  905. +CONFIG_CHR_DEV_OSST=m
  906. +CONFIG_BLK_DEV_SR=m
  907. +CONFIG_CHR_DEV_SG=m
  908. +CONFIG_SCSI_MULTI_LUN=y
  909. +CONFIG_SCSI_ISCSI_ATTRS=y
  910. +CONFIG_ISCSI_TCP=m
  911. +CONFIG_ISCSI_BOOT_SYSFS=m
  912. +CONFIG_MD=y
  913. +CONFIG_MD_LINEAR=m
  914. +CONFIG_MD_RAID0=m
  915. +CONFIG_BCACHE=m
  916. +CONFIG_BLK_DEV_DM=m
  917. +CONFIG_DM_CRYPT=m
  918. +CONFIG_DM_SNAPSHOT=m
  919. +CONFIG_DM_MIRROR=m
  920. +CONFIG_DM_RAID=m
  921. +CONFIG_DM_LOG_USERSPACE=m
  922. +CONFIG_DM_ZERO=m
  923. +CONFIG_DM_DELAY=m
  924. +CONFIG_NETDEVICES=y
  925. +CONFIG_BONDING=m
  926. +CONFIG_DUMMY=m
  927. +CONFIG_IFB=m
  928. +CONFIG_MACVLAN=m
  929. +CONFIG_NETCONSOLE=m
  930. +CONFIG_TUN=m
  931. +CONFIG_MDIO_BITBANG=m
  932. +CONFIG_PPP=m
  933. +CONFIG_PPP_BSDCOMP=m
  934. +CONFIG_PPP_DEFLATE=m
  935. +CONFIG_PPP_FILTER=y
  936. +CONFIG_PPP_MPPE=m
  937. +CONFIG_PPP_MULTILINK=y
  938. +CONFIG_PPPOE=m
  939. +CONFIG_PPPOL2TP=m
  940. +CONFIG_PPP_ASYNC=m
  941. +CONFIG_PPP_SYNC_TTY=m
  942. +CONFIG_SLIP=m
  943. +CONFIG_SLIP_COMPRESSED=y
  944. +CONFIG_SLIP_SMART=y
  945. +CONFIG_USB_CATC=m
  946. +CONFIG_USB_KAWETH=m
  947. +CONFIG_USB_PEGASUS=m
  948. +CONFIG_USB_RTL8150=m
  949. +CONFIG_USB_RTL8152=m
  950. +CONFIG_USB_USBNET=y
  951. +CONFIG_USB_NET_AX8817X=m
  952. +CONFIG_USB_NET_AX88179_178A=m
  953. +CONFIG_USB_NET_CDCETHER=m
  954. +CONFIG_USB_NET_CDC_EEM=m
  955. +CONFIG_USB_NET_CDC_NCM=m
  956. +CONFIG_USB_NET_CDC_MBIM=m
  957. +CONFIG_USB_NET_DM9601=m
  958. +CONFIG_USB_NET_SMSC75XX=m
  959. +CONFIG_USB_NET_SMSC95XX=y
  960. +CONFIG_USB_NET_GL620A=m
  961. +CONFIG_USB_NET_NET1080=m
  962. +CONFIG_USB_NET_PLUSB=m
  963. +CONFIG_USB_NET_MCS7830=m
  964. +CONFIG_USB_NET_CDC_SUBSET=m
  965. +CONFIG_USB_ALI_M5632=y
  966. +CONFIG_USB_AN2720=y
  967. +CONFIG_USB_EPSON2888=y
  968. +CONFIG_USB_KC2190=y
  969. +CONFIG_USB_NET_ZAURUS=m
  970. +CONFIG_USB_NET_CX82310_ETH=m
  971. +CONFIG_USB_NET_KALMIA=m
  972. +CONFIG_USB_NET_QMI_WWAN=m
  973. +CONFIG_USB_NET_INT51X1=m
  974. +CONFIG_USB_IPHETH=m
  975. +CONFIG_USB_SIERRA_NET=m
  976. +CONFIG_USB_VL600=m
  977. +CONFIG_LIBERTAS_THINFIRM=m
  978. +CONFIG_LIBERTAS_THINFIRM_USB=m
  979. +CONFIG_AT76C50X_USB=m
  980. +CONFIG_USB_ZD1201=m
  981. +CONFIG_USB_NET_RNDIS_WLAN=m
  982. +CONFIG_RTL8187=m
  983. +CONFIG_MAC80211_HWSIM=m
  984. +CONFIG_ATH_CARDS=m
  985. +CONFIG_ATH9K=m
  986. +CONFIG_ATH9K_HTC=m
  987. +CONFIG_CARL9170=m
  988. +CONFIG_ATH6KL=m
  989. +CONFIG_ATH6KL_USB=m
  990. +CONFIG_AR5523=m
  991. +CONFIG_B43=m
  992. +CONFIG_B43LEGACY=m
  993. +CONFIG_HOSTAP=m
  994. +CONFIG_LIBERTAS=m
  995. +CONFIG_LIBERTAS_USB=m
  996. +CONFIG_LIBERTAS_SDIO=m
  997. +CONFIG_P54_COMMON=m
  998. +CONFIG_P54_USB=m
  999. +CONFIG_RT2X00=m
  1000. +CONFIG_RT2500USB=m
  1001. +CONFIG_RT73USB=m
  1002. +CONFIG_RT2800USB=m
  1003. +CONFIG_RT2800USB_RT53XX=y
  1004. +CONFIG_RT2800USB_RT55XX=y
  1005. +CONFIG_RT2800USB_UNKNOWN=y
  1006. +CONFIG_ZD1211RW=m
  1007. +CONFIG_MWIFIEX=m
  1008. +CONFIG_MWIFIEX_SDIO=m
  1009. +CONFIG_RTL8192CU=m
  1010. +CONFIG_WIMAX_I2400M_USB=m
  1011. +CONFIG_INPUT_POLLDEV=m
  1012. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1013. +CONFIG_INPUT_JOYDEV=m
  1014. +CONFIG_INPUT_EVDEV=m
  1015. +# CONFIG_INPUT_KEYBOARD is not set
  1016. +# CONFIG_INPUT_MOUSE is not set
  1017. +CONFIG_INPUT_JOYSTICK=y
  1018. +CONFIG_JOYSTICK_IFORCE=m
  1019. +CONFIG_JOYSTICK_IFORCE_USB=y
  1020. +CONFIG_JOYSTICK_XPAD=m
  1021. +CONFIG_JOYSTICK_XPAD_FF=y
  1022. +CONFIG_INPUT_MISC=y
  1023. +CONFIG_INPUT_AD714X=m
  1024. +CONFIG_INPUT_ATI_REMOTE2=m
  1025. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1026. +CONFIG_INPUT_POWERMATE=m
  1027. +CONFIG_INPUT_YEALINK=m
  1028. +CONFIG_INPUT_CM109=m
  1029. +CONFIG_INPUT_UINPUT=m
  1030. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1031. +CONFIG_INPUT_ADXL34X=m
  1032. +CONFIG_INPUT_CMA3000=m
  1033. +CONFIG_SERIO=m
  1034. +CONFIG_SERIO_RAW=m
  1035. +CONFIG_GAMEPORT=m
  1036. +CONFIG_GAMEPORT_NS558=m
  1037. +CONFIG_GAMEPORT_L4=m
  1038. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1039. +# CONFIG_LEGACY_PTYS is not set
  1040. +# CONFIG_DEVKMEM is not set
  1041. +CONFIG_SERIAL_AMBA_PL011=y
  1042. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1043. +CONFIG_TTY_PRINTK=y
  1044. +CONFIG_HW_RANDOM=y
  1045. +CONFIG_HW_RANDOM_BCM2708=m
  1046. +CONFIG_RAW_DRIVER=y
  1047. +CONFIG_BRCM_CHAR_DRIVERS=y
  1048. +CONFIG_BCM_VC_CMA=y
  1049. +CONFIG_I2C=y
  1050. +CONFIG_I2C_CHARDEV=m
  1051. +CONFIG_I2C_BCM2708=m
  1052. +CONFIG_SPI=y
  1053. +CONFIG_SPI_BCM2708=m
  1054. +CONFIG_SPI_SPIDEV=y
  1055. +CONFIG_GPIO_SYSFS=y
  1056. +CONFIG_W1=m
  1057. +CONFIG_W1_MASTER_DS2490=m
  1058. +CONFIG_W1_MASTER_DS2482=m
  1059. +CONFIG_W1_MASTER_DS1WM=m
  1060. +CONFIG_W1_MASTER_GPIO=m
  1061. +CONFIG_W1_SLAVE_THERM=m
  1062. +CONFIG_W1_SLAVE_SMEM=m
  1063. +CONFIG_W1_SLAVE_DS2408=m
  1064. +CONFIG_W1_SLAVE_DS2413=m
  1065. +CONFIG_W1_SLAVE_DS2423=m
  1066. +CONFIG_W1_SLAVE_DS2431=m
  1067. +CONFIG_W1_SLAVE_DS2433=m
  1068. +CONFIG_W1_SLAVE_DS2760=m
  1069. +CONFIG_W1_SLAVE_DS2780=m
  1070. +CONFIG_W1_SLAVE_DS2781=m
  1071. +CONFIG_W1_SLAVE_DS28E04=m
  1072. +CONFIG_W1_SLAVE_BQ27000=m
  1073. +CONFIG_BATTERY_DS2760=m
  1074. +# CONFIG_HWMON is not set
  1075. +CONFIG_THERMAL=y
  1076. +CONFIG_THERMAL_BCM2835=y
  1077. +CONFIG_WATCHDOG=y
  1078. +CONFIG_BCM2708_WDT=m
  1079. +CONFIG_MEDIA_SUPPORT=m
  1080. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1081. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1082. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1083. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1084. +CONFIG_MEDIA_RC_SUPPORT=y
  1085. +CONFIG_MEDIA_CONTROLLER=y
  1086. +CONFIG_LIRC=m
  1087. +CONFIG_RC_DEVICES=y
  1088. +CONFIG_RC_ATI_REMOTE=m
  1089. +CONFIG_IR_IMON=m
  1090. +CONFIG_IR_MCEUSB=m
  1091. +CONFIG_IR_REDRAT3=m
  1092. +CONFIG_IR_STREAMZAP=m
  1093. +CONFIG_IR_IGUANA=m
  1094. +CONFIG_IR_TTUSBIR=m
  1095. +CONFIG_RC_LOOPBACK=m
  1096. +CONFIG_IR_GPIO_CIR=m
  1097. +CONFIG_MEDIA_USB_SUPPORT=y
  1098. +CONFIG_USB_VIDEO_CLASS=m
  1099. +CONFIG_USB_M5602=m
  1100. +CONFIG_USB_STV06XX=m
  1101. +CONFIG_USB_GL860=m
  1102. +CONFIG_USB_GSPCA_BENQ=m
  1103. +CONFIG_USB_GSPCA_CONEX=m
  1104. +CONFIG_USB_GSPCA_CPIA1=m
  1105. +CONFIG_USB_GSPCA_ETOMS=m
  1106. +CONFIG_USB_GSPCA_FINEPIX=m
  1107. +CONFIG_USB_GSPCA_JEILINJ=m
  1108. +CONFIG_USB_GSPCA_JL2005BCD=m
  1109. +CONFIG_USB_GSPCA_KINECT=m
  1110. +CONFIG_USB_GSPCA_KONICA=m
  1111. +CONFIG_USB_GSPCA_MARS=m
  1112. +CONFIG_USB_GSPCA_MR97310A=m
  1113. +CONFIG_USB_GSPCA_NW80X=m
  1114. +CONFIG_USB_GSPCA_OV519=m
  1115. +CONFIG_USB_GSPCA_OV534=m
  1116. +CONFIG_USB_GSPCA_OV534_9=m
  1117. +CONFIG_USB_GSPCA_PAC207=m
  1118. +CONFIG_USB_GSPCA_PAC7302=m
  1119. +CONFIG_USB_GSPCA_PAC7311=m
  1120. +CONFIG_USB_GSPCA_SE401=m
  1121. +CONFIG_USB_GSPCA_SN9C2028=m
  1122. +CONFIG_USB_GSPCA_SN9C20X=m
  1123. +CONFIG_USB_GSPCA_SONIXB=m
  1124. +CONFIG_USB_GSPCA_SONIXJ=m
  1125. +CONFIG_USB_GSPCA_SPCA500=m
  1126. +CONFIG_USB_GSPCA_SPCA501=m
  1127. +CONFIG_USB_GSPCA_SPCA505=m
  1128. +CONFIG_USB_GSPCA_SPCA506=m
  1129. +CONFIG_USB_GSPCA_SPCA508=m
  1130. +CONFIG_USB_GSPCA_SPCA561=m
  1131. +CONFIG_USB_GSPCA_SPCA1528=m
  1132. +CONFIG_USB_GSPCA_SQ905=m
  1133. +CONFIG_USB_GSPCA_SQ905C=m
  1134. +CONFIG_USB_GSPCA_SQ930X=m
  1135. +CONFIG_USB_GSPCA_STK014=m
  1136. +CONFIG_USB_GSPCA_STV0680=m
  1137. +CONFIG_USB_GSPCA_SUNPLUS=m
  1138. +CONFIG_USB_GSPCA_T613=m
  1139. +CONFIG_USB_GSPCA_TOPRO=m
  1140. +CONFIG_USB_GSPCA_TV8532=m
  1141. +CONFIG_USB_GSPCA_VC032X=m
  1142. +CONFIG_USB_GSPCA_VICAM=m
  1143. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1144. +CONFIG_USB_GSPCA_ZC3XX=m
  1145. +CONFIG_USB_PWC=m
  1146. +CONFIG_VIDEO_CPIA2=m
  1147. +CONFIG_USB_ZR364XX=m
  1148. +CONFIG_USB_STKWEBCAM=m
  1149. +CONFIG_USB_S2255=m
  1150. +CONFIG_USB_SN9C102=m
  1151. +CONFIG_VIDEO_PVRUSB2=m
  1152. +CONFIG_VIDEO_HDPVR=m
  1153. +CONFIG_VIDEO_TLG2300=m
  1154. +CONFIG_VIDEO_USBVISION=m
  1155. +CONFIG_VIDEO_STK1160=m
  1156. +CONFIG_VIDEO_STK1160_AC97=y
  1157. +CONFIG_VIDEO_AU0828=m
  1158. +CONFIG_VIDEO_CX231XX=m
  1159. +CONFIG_VIDEO_CX231XX_ALSA=m
  1160. +CONFIG_VIDEO_CX231XX_DVB=m
  1161. +CONFIG_VIDEO_TM6000=m
  1162. +CONFIG_VIDEO_TM6000_ALSA=m
  1163. +CONFIG_VIDEO_TM6000_DVB=m
  1164. +CONFIG_DVB_USB=m
  1165. +CONFIG_DVB_USB_A800=m
  1166. +CONFIG_DVB_USB_DIBUSB_MB=m
  1167. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1168. +CONFIG_DVB_USB_DIBUSB_MC=m
  1169. +CONFIG_DVB_USB_DIB0700=m
  1170. +CONFIG_DVB_USB_UMT_010=m
  1171. +CONFIG_DVB_USB_CXUSB=m
  1172. +CONFIG_DVB_USB_M920X=m
  1173. +CONFIG_DVB_USB_DIGITV=m
  1174. +CONFIG_DVB_USB_VP7045=m
  1175. +CONFIG_DVB_USB_VP702X=m
  1176. +CONFIG_DVB_USB_GP8PSK=m
  1177. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1178. +CONFIG_DVB_USB_TTUSB2=m
  1179. +CONFIG_DVB_USB_DTT200U=m
  1180. +CONFIG_DVB_USB_OPERA1=m
  1181. +CONFIG_DVB_USB_AF9005=m
  1182. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1183. +CONFIG_DVB_USB_PCTV452E=m
  1184. +CONFIG_DVB_USB_DW2102=m
  1185. +CONFIG_DVB_USB_CINERGY_T2=m
  1186. +CONFIG_DVB_USB_DTV5100=m
  1187. +CONFIG_DVB_USB_FRIIO=m
  1188. +CONFIG_DVB_USB_AZ6027=m
  1189. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1190. +CONFIG_DVB_USB_V2=m
  1191. +CONFIG_DVB_USB_AF9015=m
  1192. +CONFIG_DVB_USB_AF9035=m
  1193. +CONFIG_DVB_USB_ANYSEE=m
  1194. +CONFIG_DVB_USB_AU6610=m
  1195. +CONFIG_DVB_USB_AZ6007=m
  1196. +CONFIG_DVB_USB_CE6230=m
  1197. +CONFIG_DVB_USB_EC168=m
  1198. +CONFIG_DVB_USB_GL861=m
  1199. +CONFIG_DVB_USB_IT913X=m
  1200. +CONFIG_DVB_USB_LME2510=m
  1201. +CONFIG_DVB_USB_MXL111SF=m
  1202. +CONFIG_DVB_USB_RTL28XXU=m
  1203. +CONFIG_SMS_USB_DRV=m
  1204. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1205. +CONFIG_VIDEO_EM28XX=m
  1206. +CONFIG_VIDEO_EM28XX_ALSA=m
  1207. +CONFIG_VIDEO_EM28XX_DVB=m
  1208. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1209. +CONFIG_VIDEO_BCM2835=y
  1210. +CONFIG_VIDEO_BCM2835_MMAL=m
  1211. +CONFIG_RADIO_SI470X=y
  1212. +CONFIG_USB_SI470X=m
  1213. +CONFIG_I2C_SI470X=m
  1214. +CONFIG_USB_MR800=m
  1215. +CONFIG_USB_DSBR=m
  1216. +CONFIG_RADIO_SHARK=m
  1217. +CONFIG_RADIO_SHARK2=m
  1218. +CONFIG_RADIO_SI4713=m
  1219. +CONFIG_USB_KEENE=m
  1220. +CONFIG_USB_MA901=m
  1221. +CONFIG_RADIO_TEA5764=m
  1222. +CONFIG_RADIO_SAA7706H=m
  1223. +CONFIG_RADIO_TEF6862=m
  1224. +CONFIG_RADIO_WL1273=m
  1225. +CONFIG_RADIO_WL128X=m
  1226. +CONFIG_FB=y
  1227. +CONFIG_FB_BCM2708=y
  1228. +# CONFIG_BACKLIGHT_GENERIC is not set
  1229. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1230. +CONFIG_LOGO=y
  1231. +# CONFIG_LOGO_LINUX_MONO is not set
  1232. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1233. +CONFIG_SOUND=y
  1234. +CONFIG_SND=m
  1235. +CONFIG_SND_SEQUENCER=m
  1236. +CONFIG_SND_SEQ_DUMMY=m
  1237. +CONFIG_SND_MIXER_OSS=m
  1238. +CONFIG_SND_PCM_OSS=m
  1239. +CONFIG_SND_SEQUENCER_OSS=y
  1240. +CONFIG_SND_HRTIMER=m
  1241. +CONFIG_SND_DUMMY=m
  1242. +CONFIG_SND_ALOOP=m
  1243. +CONFIG_SND_VIRMIDI=m
  1244. +CONFIG_SND_MTPAV=m
  1245. +CONFIG_SND_SERIAL_U16550=m
  1246. +CONFIG_SND_MPU401=m
  1247. +CONFIG_SND_BCM2835=m
  1248. +CONFIG_SND_USB_AUDIO=m
  1249. +CONFIG_SND_USB_UA101=m
  1250. +CONFIG_SND_USB_CAIAQ=m
  1251. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1252. +CONFIG_SND_USB_6FIRE=m
  1253. +CONFIG_SND_SOC=m
  1254. +CONFIG_SND_BCM2708_SOC_I2S=m
  1255. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1256. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1257. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1258. +CONFIG_SOUND_PRIME=m
  1259. +CONFIG_HIDRAW=y
  1260. +CONFIG_HID_A4TECH=m
  1261. +CONFIG_HID_ACRUX=m
  1262. +CONFIG_HID_APPLE=m
  1263. +CONFIG_HID_BELKIN=m
  1264. +CONFIG_HID_CHERRY=m
  1265. +CONFIG_HID_CHICONY=m
  1266. +CONFIG_HID_CYPRESS=m
  1267. +CONFIG_HID_DRAGONRISE=m
  1268. +CONFIG_HID_EMS_FF=m
  1269. +CONFIG_HID_ELECOM=m
  1270. +CONFIG_HID_EZKEY=m
  1271. +CONFIG_HID_HOLTEK=m
  1272. +CONFIG_HID_KEYTOUCH=m
  1273. +CONFIG_HID_KYE=m
  1274. +CONFIG_HID_UCLOGIC=m
  1275. +CONFIG_HID_WALTOP=m
  1276. +CONFIG_HID_GYRATION=m
  1277. +CONFIG_HID_TWINHAN=m
  1278. +CONFIG_HID_KENSINGTON=m
  1279. +CONFIG_HID_LCPOWER=m
  1280. +CONFIG_HID_LOGITECH=m
  1281. +CONFIG_HID_MAGICMOUSE=m
  1282. +CONFIG_HID_MICROSOFT=m
  1283. +CONFIG_HID_MONTEREY=m
  1284. +CONFIG_HID_MULTITOUCH=m
  1285. +CONFIG_HID_NTRIG=m
  1286. +CONFIG_HID_ORTEK=m
  1287. +CONFIG_HID_PANTHERLORD=m
  1288. +CONFIG_HID_PETALYNX=m
  1289. +CONFIG_HID_PICOLCD=m
  1290. +CONFIG_HID_ROCCAT=m
  1291. +CONFIG_HID_SAMSUNG=m
  1292. +CONFIG_HID_SONY=m
  1293. +CONFIG_HID_SPEEDLINK=m
  1294. +CONFIG_HID_SUNPLUS=m
  1295. +CONFIG_HID_GREENASIA=m
  1296. +CONFIG_HID_SMARTJOYPLUS=m
  1297. +CONFIG_HID_TOPSEED=m
  1298. +CONFIG_HID_THINGM=m
  1299. +CONFIG_HID_THRUSTMASTER=m
  1300. +CONFIG_HID_WACOM=m
  1301. +CONFIG_HID_WIIMOTE=m
  1302. +CONFIG_HID_ZEROPLUS=m
  1303. +CONFIG_HID_ZYDACRON=m
  1304. +CONFIG_HID_PID=y
  1305. +CONFIG_USB_HIDDEV=y
  1306. +CONFIG_USB=y
  1307. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1308. +CONFIG_USB_MON=m
  1309. +CONFIG_USB_DWCOTG=y
  1310. +CONFIG_USB_PRINTER=m
  1311. +CONFIG_USB_STORAGE=y
  1312. +CONFIG_USB_STORAGE_REALTEK=m
  1313. +CONFIG_USB_STORAGE_DATAFAB=m
  1314. +CONFIG_USB_STORAGE_FREECOM=m
  1315. +CONFIG_USB_STORAGE_ISD200=m
  1316. +CONFIG_USB_STORAGE_USBAT=m
  1317. +CONFIG_USB_STORAGE_SDDR09=m
  1318. +CONFIG_USB_STORAGE_SDDR55=m
  1319. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1320. +CONFIG_USB_STORAGE_ALAUDA=m
  1321. +CONFIG_USB_STORAGE_ONETOUCH=m
  1322. +CONFIG_USB_STORAGE_KARMA=m
  1323. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1324. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1325. +CONFIG_USB_MDC800=m
  1326. +CONFIG_USB_MICROTEK=m
  1327. +CONFIG_USB_SERIAL=m
  1328. +CONFIG_USB_SERIAL_GENERIC=y
  1329. +CONFIG_USB_SERIAL_AIRCABLE=m
  1330. +CONFIG_USB_SERIAL_ARK3116=m
  1331. +CONFIG_USB_SERIAL_BELKIN=m
  1332. +CONFIG_USB_SERIAL_CH341=m
  1333. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1334. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1335. +CONFIG_USB_SERIAL_CP210X=m
  1336. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1337. +CONFIG_USB_SERIAL_EMPEG=m
  1338. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1339. +CONFIG_USB_SERIAL_FUNSOFT=m
  1340. +CONFIG_USB_SERIAL_VISOR=m
  1341. +CONFIG_USB_SERIAL_IPAQ=m
  1342. +CONFIG_USB_SERIAL_IR=m
  1343. +CONFIG_USB_SERIAL_EDGEPORT=m
  1344. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1345. +CONFIG_USB_SERIAL_F81232=m
  1346. +CONFIG_USB_SERIAL_GARMIN=m
  1347. +CONFIG_USB_SERIAL_IPW=m
  1348. +CONFIG_USB_SERIAL_IUU=m
  1349. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1350. +CONFIG_USB_SERIAL_KEYSPAN=m
  1351. +CONFIG_USB_SERIAL_KLSI=m
  1352. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1353. +CONFIG_USB_SERIAL_MCT_U232=m
  1354. +CONFIG_USB_SERIAL_METRO=m
  1355. +CONFIG_USB_SERIAL_MOS7720=m
  1356. +CONFIG_USB_SERIAL_MOS7840=m
  1357. +CONFIG_USB_SERIAL_MOTOROLA=m
  1358. +CONFIG_USB_SERIAL_NAVMAN=m
  1359. +CONFIG_USB_SERIAL_PL2303=m
  1360. +CONFIG_USB_SERIAL_OTI6858=m
  1361. +CONFIG_USB_SERIAL_QCAUX=m
  1362. +CONFIG_USB_SERIAL_QUALCOMM=m
  1363. +CONFIG_USB_SERIAL_SPCP8X5=m
  1364. +CONFIG_USB_SERIAL_HP4X=m
  1365. +CONFIG_USB_SERIAL_SAFE=m
  1366. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1367. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1368. +CONFIG_USB_SERIAL_SYMBOL=m
  1369. +CONFIG_USB_SERIAL_TI=m
  1370. +CONFIG_USB_SERIAL_CYBERJACK=m
  1371. +CONFIG_USB_SERIAL_XIRCOM=m
  1372. +CONFIG_USB_SERIAL_OPTION=m
  1373. +CONFIG_USB_SERIAL_OMNINET=m
  1374. +CONFIG_USB_SERIAL_OPTICON=m
  1375. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1376. +CONFIG_USB_SERIAL_XSENS_MT=m
  1377. +CONFIG_USB_SERIAL_ZIO=m
  1378. +CONFIG_USB_SERIAL_WISHBONE=m
  1379. +CONFIG_USB_SERIAL_ZTE=m
  1380. +CONFIG_USB_SERIAL_SSU100=m
  1381. +CONFIG_USB_SERIAL_QT2=m
  1382. +CONFIG_USB_SERIAL_DEBUG=m
  1383. +CONFIG_USB_EMI62=m
  1384. +CONFIG_USB_EMI26=m
  1385. +CONFIG_USB_ADUTUX=m
  1386. +CONFIG_USB_SEVSEG=m
  1387. +CONFIG_USB_RIO500=m
  1388. +CONFIG_USB_LEGOTOWER=m
  1389. +CONFIG_USB_LCD=m
  1390. +CONFIG_USB_LED=m
  1391. +CONFIG_USB_CYPRESS_CY7C63=m
  1392. +CONFIG_USB_CYTHERM=m
  1393. +CONFIG_USB_IDMOUSE=m
  1394. +CONFIG_USB_FTDI_ELAN=m
  1395. +CONFIG_USB_APPLEDISPLAY=m
  1396. +CONFIG_USB_LD=m
  1397. +CONFIG_USB_TRANCEVIBRATOR=m
  1398. +CONFIG_USB_IOWARRIOR=m
  1399. +CONFIG_USB_TEST=m
  1400. +CONFIG_USB_ISIGHTFW=m
  1401. +CONFIG_USB_YUREX=m
  1402. +CONFIG_MMC=y
  1403. +CONFIG_MMC_BLOCK_MINORS=32
  1404. +CONFIG_MMC_SDHCI=y
  1405. +CONFIG_MMC_SDHCI_PLTFM=y
  1406. +CONFIG_MMC_SDHCI_BCM2708=y
  1407. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1408. +CONFIG_MMC_SPI=m
  1409. +CONFIG_LEDS_GPIO=m
  1410. +CONFIG_LEDS_TRIGGER_TIMER=y
  1411. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1412. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1413. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1414. +CONFIG_LEDS_TRIGGER_CPU=y
  1415. +CONFIG_LEDS_TRIGGER_GPIO=y
  1416. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1417. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1418. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1419. +CONFIG_RTC_CLASS=y
  1420. +# CONFIG_RTC_HCTOSYS is not set
  1421. +CONFIG_RTC_DRV_DS1307=m
  1422. +CONFIG_RTC_DRV_DS1374=m
  1423. +CONFIG_RTC_DRV_DS1672=m
  1424. +CONFIG_RTC_DRV_DS3232=m
  1425. +CONFIG_RTC_DRV_MAX6900=m
  1426. +CONFIG_RTC_DRV_RS5C372=m
  1427. +CONFIG_RTC_DRV_ISL1208=m
  1428. +CONFIG_RTC_DRV_ISL12022=m
  1429. +CONFIG_RTC_DRV_X1205=m
  1430. +CONFIG_RTC_DRV_PCF8523=m
  1431. +CONFIG_RTC_DRV_PCF8563=m
  1432. +CONFIG_RTC_DRV_PCF8583=m
  1433. +CONFIG_RTC_DRV_M41T80=m
  1434. +CONFIG_RTC_DRV_BQ32K=m
  1435. +CONFIG_RTC_DRV_S35390A=m
  1436. +CONFIG_RTC_DRV_FM3130=m
  1437. +CONFIG_RTC_DRV_RX8581=m
  1438. +CONFIG_RTC_DRV_RX8025=m
  1439. +CONFIG_RTC_DRV_EM3027=m
  1440. +CONFIG_RTC_DRV_RV3029C2=m
  1441. +CONFIG_RTC_DRV_M41T93=m
  1442. +CONFIG_RTC_DRV_M41T94=m
  1443. +CONFIG_RTC_DRV_DS1305=m
  1444. +CONFIG_RTC_DRV_DS1390=m
  1445. +CONFIG_RTC_DRV_MAX6902=m
  1446. +CONFIG_RTC_DRV_R9701=m
  1447. +CONFIG_RTC_DRV_RS5C348=m
  1448. +CONFIG_RTC_DRV_DS3234=m
  1449. +CONFIG_RTC_DRV_PCF2123=m
  1450. +CONFIG_RTC_DRV_RX4581=m
  1451. +CONFIG_DMADEVICES=y
  1452. +CONFIG_DMA_BCM2708=m
  1453. +CONFIG_UIO=m
  1454. +CONFIG_UIO_PDRV=m
  1455. +CONFIG_UIO_PDRV_GENIRQ=m
  1456. +CONFIG_STAGING=y
  1457. +CONFIG_W35UND=m
  1458. +CONFIG_PRISM2_USB=m
  1459. +CONFIG_R8712U=m
  1460. +CONFIG_VT6656=m
  1461. +CONFIG_SPEAKUP=m
  1462. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1463. +CONFIG_STAGING_MEDIA=y
  1464. +CONFIG_DVB_AS102=m
  1465. +CONFIG_LIRC_STAGING=y
  1466. +CONFIG_LIRC_IGORPLUGUSB=m
  1467. +CONFIG_LIRC_IMON=m
  1468. +CONFIG_LIRC_RPI=m
  1469. +CONFIG_LIRC_SASEM=m
  1470. +CONFIG_LIRC_SERIAL=m
  1471. +# CONFIG_IOMMU_SUPPORT is not set
  1472. +CONFIG_EXT4_FS=y
  1473. +CONFIG_EXT4_FS_POSIX_ACL=y
  1474. +CONFIG_EXT4_FS_SECURITY=y
  1475. +CONFIG_REISERFS_FS=m
  1476. +CONFIG_REISERFS_FS_XATTR=y
  1477. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1478. +CONFIG_REISERFS_FS_SECURITY=y
  1479. +CONFIG_JFS_FS=m
  1480. +CONFIG_JFS_POSIX_ACL=y
  1481. +CONFIG_JFS_SECURITY=y
  1482. +CONFIG_JFS_STATISTICS=y
  1483. +CONFIG_XFS_FS=m
  1484. +CONFIG_XFS_QUOTA=y
  1485. +CONFIG_XFS_POSIX_ACL=y
  1486. +CONFIG_XFS_RT=y
  1487. +CONFIG_GFS2_FS=m
  1488. +CONFIG_OCFS2_FS=m
  1489. +CONFIG_BTRFS_FS=m
  1490. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1491. +CONFIG_NILFS2_FS=m
  1492. +CONFIG_FANOTIFY=y
  1493. +CONFIG_QFMT_V1=m
  1494. +CONFIG_QFMT_V2=m
  1495. +CONFIG_AUTOFS4_FS=y
  1496. +CONFIG_FUSE_FS=m
  1497. +CONFIG_CUSE=m
  1498. +CONFIG_FSCACHE=y
  1499. +CONFIG_FSCACHE_STATS=y
  1500. +CONFIG_FSCACHE_HISTOGRAM=y
  1501. +CONFIG_CACHEFILES=y
  1502. +CONFIG_ISO9660_FS=m
  1503. +CONFIG_JOLIET=y
  1504. +CONFIG_ZISOFS=y
  1505. +CONFIG_UDF_FS=m
  1506. +CONFIG_MSDOS_FS=y
  1507. +CONFIG_VFAT_FS=y
  1508. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1509. +CONFIG_NTFS_FS=m
  1510. +CONFIG_NTFS_RW=y
  1511. +CONFIG_TMPFS=y
  1512. +CONFIG_TMPFS_POSIX_ACL=y
  1513. +CONFIG_CONFIGFS_FS=y
  1514. +CONFIG_ECRYPT_FS=m
  1515. +CONFIG_HFS_FS=m
  1516. +CONFIG_HFSPLUS_FS=m
  1517. +CONFIG_SQUASHFS=m
  1518. +CONFIG_SQUASHFS_XATTR=y
  1519. +CONFIG_SQUASHFS_LZO=y
  1520. +CONFIG_SQUASHFS_XZ=y
  1521. +CONFIG_F2FS_FS=y
  1522. +CONFIG_NFS_FS=y
  1523. +CONFIG_NFS_V3_ACL=y
  1524. +CONFIG_NFS_V4=y
  1525. +CONFIG_ROOT_NFS=y
  1526. +CONFIG_NFS_FSCACHE=y
  1527. +CONFIG_NFSD=m
  1528. +CONFIG_NFSD_V3_ACL=y
  1529. +CONFIG_NFSD_V4=y
  1530. +CONFIG_CIFS=m
  1531. +CONFIG_CIFS_WEAK_PW_HASH=y
  1532. +CONFIG_CIFS_XATTR=y
  1533. +CONFIG_CIFS_POSIX=y
  1534. +CONFIG_9P_FS=m
  1535. +CONFIG_9P_FS_POSIX_ACL=y
  1536. +CONFIG_NLS_DEFAULT="utf8"
  1537. +CONFIG_NLS_CODEPAGE_437=y
  1538. +CONFIG_NLS_CODEPAGE_737=m
  1539. +CONFIG_NLS_CODEPAGE_775=m
  1540. +CONFIG_NLS_CODEPAGE_850=m
  1541. +CONFIG_NLS_CODEPAGE_852=m
  1542. +CONFIG_NLS_CODEPAGE_855=m
  1543. +CONFIG_NLS_CODEPAGE_857=m
  1544. +CONFIG_NLS_CODEPAGE_860=m
  1545. +CONFIG_NLS_CODEPAGE_861=m
  1546. +CONFIG_NLS_CODEPAGE_862=m
  1547. +CONFIG_NLS_CODEPAGE_863=m
  1548. +CONFIG_NLS_CODEPAGE_864=m
  1549. +CONFIG_NLS_CODEPAGE_865=m
  1550. +CONFIG_NLS_CODEPAGE_866=m
  1551. +CONFIG_NLS_CODEPAGE_869=m
  1552. +CONFIG_NLS_CODEPAGE_936=m
  1553. +CONFIG_NLS_CODEPAGE_950=m
  1554. +CONFIG_NLS_CODEPAGE_932=m
  1555. +CONFIG_NLS_CODEPAGE_949=m
  1556. +CONFIG_NLS_CODEPAGE_874=m
  1557. +CONFIG_NLS_ISO8859_8=m
  1558. +CONFIG_NLS_CODEPAGE_1250=m
  1559. +CONFIG_NLS_CODEPAGE_1251=m
  1560. +CONFIG_NLS_ASCII=y
  1561. +CONFIG_NLS_ISO8859_1=m
  1562. +CONFIG_NLS_ISO8859_2=m
  1563. +CONFIG_NLS_ISO8859_3=m
  1564. +CONFIG_NLS_ISO8859_4=m
  1565. +CONFIG_NLS_ISO8859_5=m
  1566. +CONFIG_NLS_ISO8859_6=m
  1567. +CONFIG_NLS_ISO8859_7=m
  1568. +CONFIG_NLS_ISO8859_9=m
  1569. +CONFIG_NLS_ISO8859_13=m
  1570. +CONFIG_NLS_ISO8859_14=m
  1571. +CONFIG_NLS_ISO8859_15=m
  1572. +CONFIG_NLS_KOI8_R=m
  1573. +CONFIG_NLS_KOI8_U=m
  1574. +CONFIG_DLM=m
  1575. +CONFIG_PRINTK_TIME=y
  1576. +CONFIG_DEBUG_FS=y
  1577. +CONFIG_DETECT_HUNG_TASK=y
  1578. +CONFIG_TIMER_STATS=y
  1579. +# CONFIG_DEBUG_PREEMPT is not set
  1580. +CONFIG_DEBUG_MEMORY_INIT=y
  1581. +CONFIG_BOOT_PRINTK_DELAY=y
  1582. +CONFIG_LATENCYTOP=y
  1583. +# CONFIG_KPROBE_EVENT is not set
  1584. +CONFIG_KGDB=y
  1585. +CONFIG_KGDB_KDB=y
  1586. +CONFIG_KDB_KEYBOARD=y
  1587. +CONFIG_STRICT_DEVMEM=y
  1588. +CONFIG_CRYPTO_USER=m
  1589. +CONFIG_CRYPTO_NULL=m
  1590. +CONFIG_CRYPTO_CRYPTD=m
  1591. +CONFIG_CRYPTO_SEQIV=m
  1592. +CONFIG_CRYPTO_CBC=y
  1593. +CONFIG_CRYPTO_XTS=m
  1594. +CONFIG_CRYPTO_XCBC=m
  1595. +CONFIG_CRYPTO_SHA1_ARM=m
  1596. +CONFIG_CRYPTO_SHA512=m
  1597. +CONFIG_CRYPTO_TGR192=m
  1598. +CONFIG_CRYPTO_WP512=m
  1599. +CONFIG_CRYPTO_AES_ARM=m
  1600. +CONFIG_CRYPTO_CAST5=m
  1601. +CONFIG_CRYPTO_DES=y
  1602. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1603. +# CONFIG_CRYPTO_HW is not set
  1604. +CONFIG_CRC_ITU_T=y
  1605. +CONFIG_LIBCRC32C=y
  1606. diff -Nur linux-3.10.33/arch/arm/configs/bcmrpi_emergency_defconfig linux-raspberry-pi/arch/arm/configs/bcmrpi_emergency_defconfig
  1607. --- linux-3.10.33/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1608. +++ linux-raspberry-pi/arch/arm/configs/bcmrpi_emergency_defconfig 2014-03-13 12:46:12.312043485 +0100
  1609. @@ -0,0 +1,532 @@
  1610. +CONFIG_EXPERIMENTAL=y
  1611. +# CONFIG_LOCALVERSION_AUTO is not set
  1612. +CONFIG_SYSVIPC=y
  1613. +CONFIG_POSIX_MQUEUE=y
  1614. +CONFIG_BSD_PROCESS_ACCT=y
  1615. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1616. +CONFIG_FHANDLE=y
  1617. +CONFIG_AUDIT=y
  1618. +CONFIG_IKCONFIG=y
  1619. +CONFIG_IKCONFIG_PROC=y
  1620. +CONFIG_BLK_DEV_INITRD=y
  1621. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1622. +CONFIG_CGROUP_FREEZER=y
  1623. +CONFIG_CGROUP_DEVICE=y
  1624. +CONFIG_CGROUP_CPUACCT=y
  1625. +CONFIG_RESOURCE_COUNTERS=y
  1626. +CONFIG_BLK_CGROUP=y
  1627. +CONFIG_NAMESPACES=y
  1628. +CONFIG_SCHED_AUTOGROUP=y
  1629. +CONFIG_EMBEDDED=y
  1630. +# CONFIG_COMPAT_BRK is not set
  1631. +CONFIG_SLAB=y
  1632. +CONFIG_PROFILING=y
  1633. +CONFIG_OPROFILE=m
  1634. +CONFIG_KPROBES=y
  1635. +CONFIG_MODULES=y
  1636. +CONFIG_MODULE_UNLOAD=y
  1637. +CONFIG_MODVERSIONS=y
  1638. +CONFIG_MODULE_SRCVERSION_ALL=y
  1639. +# CONFIG_BLK_DEV_BSG is not set
  1640. +CONFIG_BLK_DEV_THROTTLING=y
  1641. +CONFIG_CFQ_GROUP_IOSCHED=y
  1642. +CONFIG_ARCH_BCM2708=y
  1643. +CONFIG_NO_HZ=y
  1644. +CONFIG_HIGH_RES_TIMERS=y
  1645. +CONFIG_AEABI=y
  1646. +CONFIG_SECCOMP=y
  1647. +CONFIG_CC_STACKPROTECTOR=y
  1648. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1649. +CONFIG_ZBOOT_ROM_BSS=0x0
  1650. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1651. +CONFIG_KEXEC=y
  1652. +CONFIG_CPU_IDLE=y
  1653. +CONFIG_VFP=y
  1654. +CONFIG_BINFMT_MISC=m
  1655. +CONFIG_NET=y
  1656. +CONFIG_PACKET=y
  1657. +CONFIG_UNIX=y
  1658. +CONFIG_XFRM_USER=y
  1659. +CONFIG_NET_KEY=m
  1660. +CONFIG_INET=y
  1661. +CONFIG_IP_MULTICAST=y
  1662. +CONFIG_IP_PNP=y
  1663. +CONFIG_IP_PNP_DHCP=y
  1664. +CONFIG_IP_PNP_RARP=y
  1665. +CONFIG_SYN_COOKIES=y
  1666. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1667. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1668. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1669. +# CONFIG_INET_LRO is not set
  1670. +# CONFIG_INET_DIAG is not set
  1671. +# CONFIG_IPV6 is not set
  1672. +CONFIG_NET_PKTGEN=m
  1673. +CONFIG_IRDA=m
  1674. +CONFIG_IRLAN=m
  1675. +CONFIG_IRCOMM=m
  1676. +CONFIG_IRDA_ULTRA=y
  1677. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1678. +CONFIG_IRDA_FAST_RR=y
  1679. +CONFIG_IRTTY_SIR=m
  1680. +CONFIG_KINGSUN_DONGLE=m
  1681. +CONFIG_KSDAZZLE_DONGLE=m
  1682. +CONFIG_KS959_DONGLE=m
  1683. +CONFIG_USB_IRDA=m
  1684. +CONFIG_SIGMATEL_FIR=m
  1685. +CONFIG_MCS_FIR=m
  1686. +CONFIG_BT=m
  1687. +CONFIG_BT_L2CAP=y
  1688. +CONFIG_BT_SCO=y
  1689. +CONFIG_BT_RFCOMM=m
  1690. +CONFIG_BT_RFCOMM_TTY=y
  1691. +CONFIG_BT_BNEP=m
  1692. +CONFIG_BT_BNEP_MC_FILTER=y
  1693. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1694. +CONFIG_BT_HIDP=m
  1695. +CONFIG_BT_HCIBTUSB=m
  1696. +CONFIG_BT_HCIBCM203X=m
  1697. +CONFIG_BT_HCIBPA10X=m
  1698. +CONFIG_BT_HCIBFUSB=m
  1699. +CONFIG_BT_HCIVHCI=m
  1700. +CONFIG_BT_MRVL=m
  1701. +CONFIG_BT_MRVL_SDIO=m
  1702. +CONFIG_BT_ATH3K=m
  1703. +CONFIG_CFG80211=m
  1704. +CONFIG_MAC80211=m
  1705. +CONFIG_MAC80211_RC_PID=y
  1706. +CONFIG_MAC80211_MESH=y
  1707. +CONFIG_WIMAX=m
  1708. +CONFIG_NET_9P=m
  1709. +CONFIG_NFC=m
  1710. +CONFIG_NFC_PN533=m
  1711. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1712. +CONFIG_BLK_DEV_LOOP=y
  1713. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1714. +CONFIG_BLK_DEV_NBD=m
  1715. +CONFIG_BLK_DEV_RAM=y
  1716. +CONFIG_CDROM_PKTCDVD=m
  1717. +CONFIG_MISC_DEVICES=y
  1718. +CONFIG_SCSI=y
  1719. +# CONFIG_SCSI_PROC_FS is not set
  1720. +CONFIG_BLK_DEV_SD=y
  1721. +CONFIG_BLK_DEV_SR=m
  1722. +CONFIG_SCSI_MULTI_LUN=y
  1723. +# CONFIG_SCSI_LOWLEVEL is not set
  1724. +CONFIG_MD=y
  1725. +CONFIG_NETDEVICES=y
  1726. +CONFIG_TUN=m
  1727. +CONFIG_PHYLIB=m
  1728. +CONFIG_MDIO_BITBANG=m
  1729. +CONFIG_NET_ETHERNET=y
  1730. +# CONFIG_NETDEV_1000 is not set
  1731. +# CONFIG_NETDEV_10000 is not set
  1732. +CONFIG_LIBERTAS_THINFIRM=m
  1733. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1734. +CONFIG_AT76C50X_USB=m
  1735. +CONFIG_USB_ZD1201=m
  1736. +CONFIG_USB_NET_RNDIS_WLAN=m
  1737. +CONFIG_RTL8187=m
  1738. +CONFIG_MAC80211_HWSIM=m
  1739. +CONFIG_ATH_COMMON=m
  1740. +CONFIG_ATH9K=m
  1741. +CONFIG_ATH9K_HTC=m
  1742. +CONFIG_CARL9170=m
  1743. +CONFIG_B43=m
  1744. +CONFIG_B43LEGACY=m
  1745. +CONFIG_HOSTAP=m
  1746. +CONFIG_IWM=m
  1747. +CONFIG_LIBERTAS=m
  1748. +CONFIG_LIBERTAS_USB=m
  1749. +CONFIG_LIBERTAS_SDIO=m
  1750. +CONFIG_P54_COMMON=m
  1751. +CONFIG_P54_USB=m
  1752. +CONFIG_RT2X00=m
  1753. +CONFIG_RT2500USB=m
  1754. +CONFIG_RT73USB=m
  1755. +CONFIG_RT2800USB=m
  1756. +CONFIG_RT2800USB_RT53XX=y
  1757. +CONFIG_RTL8192CU=m
  1758. +CONFIG_WL1251=m
  1759. +CONFIG_WL12XX_MENU=m
  1760. +CONFIG_ZD1211RW=m
  1761. +CONFIG_MWIFIEX=m
  1762. +CONFIG_MWIFIEX_SDIO=m
  1763. +CONFIG_WIMAX_I2400M_USB=m
  1764. +CONFIG_USB_CATC=m
  1765. +CONFIG_USB_KAWETH=m
  1766. +CONFIG_USB_PEGASUS=m
  1767. +CONFIG_USB_RTL8150=m
  1768. +CONFIG_USB_USBNET=y
  1769. +CONFIG_USB_NET_AX8817X=m
  1770. +CONFIG_USB_NET_CDCETHER=m
  1771. +CONFIG_USB_NET_CDC_EEM=m
  1772. +CONFIG_USB_NET_DM9601=m
  1773. +CONFIG_USB_NET_SMSC75XX=m
  1774. +CONFIG_USB_NET_SMSC95XX=y
  1775. +CONFIG_USB_NET_GL620A=m
  1776. +CONFIG_USB_NET_NET1080=m
  1777. +CONFIG_USB_NET_PLUSB=m
  1778. +CONFIG_USB_NET_MCS7830=m
  1779. +CONFIG_USB_NET_CDC_SUBSET=m
  1780. +CONFIG_USB_ALI_M5632=y
  1781. +CONFIG_USB_AN2720=y
  1782. +CONFIG_USB_KC2190=y
  1783. +# CONFIG_USB_NET_ZAURUS is not set
  1784. +CONFIG_USB_NET_CX82310_ETH=m
  1785. +CONFIG_USB_NET_KALMIA=m
  1786. +CONFIG_USB_NET_INT51X1=m
  1787. +CONFIG_USB_IPHETH=m
  1788. +CONFIG_USB_SIERRA_NET=m
  1789. +CONFIG_USB_VL600=m
  1790. +CONFIG_PPP=m
  1791. +CONFIG_PPP_ASYNC=m
  1792. +CONFIG_PPP_SYNC_TTY=m
  1793. +CONFIG_PPP_DEFLATE=m
  1794. +CONFIG_PPP_BSDCOMP=m
  1795. +CONFIG_SLIP=m
  1796. +CONFIG_SLIP_COMPRESSED=y
  1797. +CONFIG_NETCONSOLE=m
  1798. +CONFIG_INPUT_POLLDEV=m
  1799. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1800. +CONFIG_INPUT_JOYDEV=m
  1801. +CONFIG_INPUT_EVDEV=m
  1802. +# CONFIG_INPUT_KEYBOARD is not set
  1803. +# CONFIG_INPUT_MOUSE is not set
  1804. +CONFIG_INPUT_MISC=y
  1805. +CONFIG_INPUT_AD714X=m
  1806. +CONFIG_INPUT_ATI_REMOTE=m
  1807. +CONFIG_INPUT_ATI_REMOTE2=m
  1808. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1809. +CONFIG_INPUT_POWERMATE=m
  1810. +CONFIG_INPUT_YEALINK=m
  1811. +CONFIG_INPUT_CM109=m
  1812. +CONFIG_INPUT_UINPUT=m
  1813. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1814. +CONFIG_INPUT_ADXL34X=m
  1815. +CONFIG_INPUT_CMA3000=m
  1816. +CONFIG_SERIO=m
  1817. +CONFIG_SERIO_RAW=m
  1818. +CONFIG_GAMEPORT=m
  1819. +CONFIG_GAMEPORT_NS558=m
  1820. +CONFIG_GAMEPORT_L4=m
  1821. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1822. +# CONFIG_LEGACY_PTYS is not set
  1823. +# CONFIG_DEVKMEM is not set
  1824. +CONFIG_SERIAL_AMBA_PL011=y
  1825. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1826. +# CONFIG_HW_RANDOM is not set
  1827. +CONFIG_RAW_DRIVER=y
  1828. +CONFIG_GPIO_SYSFS=y
  1829. +# CONFIG_HWMON is not set
  1830. +CONFIG_WATCHDOG=y
  1831. +CONFIG_BCM2708_WDT=m
  1832. +# CONFIG_MFD_SUPPORT is not set
  1833. +CONFIG_FB=y
  1834. +CONFIG_FB_BCM2708=y
  1835. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1836. +CONFIG_LOGO=y
  1837. +# CONFIG_LOGO_LINUX_MONO is not set
  1838. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1839. +CONFIG_SOUND=y
  1840. +CONFIG_SND=m
  1841. +CONFIG_SND_SEQUENCER=m
  1842. +CONFIG_SND_SEQ_DUMMY=m
  1843. +CONFIG_SND_MIXER_OSS=m
  1844. +CONFIG_SND_PCM_OSS=m
  1845. +CONFIG_SND_SEQUENCER_OSS=y
  1846. +CONFIG_SND_HRTIMER=m
  1847. +CONFIG_SND_DUMMY=m
  1848. +CONFIG_SND_ALOOP=m
  1849. +CONFIG_SND_VIRMIDI=m
  1850. +CONFIG_SND_MTPAV=m
  1851. +CONFIG_SND_SERIAL_U16550=m
  1852. +CONFIG_SND_MPU401=m
  1853. +CONFIG_SND_BCM2835=m
  1854. +CONFIG_SND_USB_AUDIO=m
  1855. +CONFIG_SND_USB_UA101=m
  1856. +CONFIG_SND_USB_CAIAQ=m
  1857. +CONFIG_SND_USB_6FIRE=m
  1858. +CONFIG_SOUND_PRIME=m
  1859. +CONFIG_HID_PID=y
  1860. +CONFIG_USB_HIDDEV=y
  1861. +CONFIG_HID_A4TECH=m
  1862. +CONFIG_HID_ACRUX=m
  1863. +CONFIG_HID_APPLE=m
  1864. +CONFIG_HID_BELKIN=m
  1865. +CONFIG_HID_CHERRY=m
  1866. +CONFIG_HID_CHICONY=m
  1867. +CONFIG_HID_CYPRESS=m
  1868. +CONFIG_HID_DRAGONRISE=m
  1869. +CONFIG_HID_EMS_FF=m
  1870. +CONFIG_HID_ELECOM=m
  1871. +CONFIG_HID_EZKEY=m
  1872. +CONFIG_HID_HOLTEK=m
  1873. +CONFIG_HID_KEYTOUCH=m
  1874. +CONFIG_HID_KYE=m
  1875. +CONFIG_HID_UCLOGIC=m
  1876. +CONFIG_HID_WALTOP=m
  1877. +CONFIG_HID_GYRATION=m
  1878. +CONFIG_HID_TWINHAN=m
  1879. +CONFIG_HID_KENSINGTON=m
  1880. +CONFIG_HID_LCPOWER=m
  1881. +CONFIG_HID_LOGITECH=m
  1882. +CONFIG_HID_MAGICMOUSE=m
  1883. +CONFIG_HID_MICROSOFT=m
  1884. +CONFIG_HID_MONTEREY=m
  1885. +CONFIG_HID_MULTITOUCH=m
  1886. +CONFIG_HID_NTRIG=m
  1887. +CONFIG_HID_ORTEK=m
  1888. +CONFIG_HID_PANTHERLORD=m
  1889. +CONFIG_HID_PETALYNX=m
  1890. +CONFIG_HID_PICOLCD=m
  1891. +CONFIG_HID_QUANTA=m
  1892. +CONFIG_HID_ROCCAT=m
  1893. +CONFIG_HID_SAMSUNG=m
  1894. +CONFIG_HID_SONY=m
  1895. +CONFIG_HID_SPEEDLINK=m
  1896. +CONFIG_HID_SUNPLUS=m
  1897. +CONFIG_HID_GREENASIA=m
  1898. +CONFIG_HID_SMARTJOYPLUS=m
  1899. +CONFIG_HID_TOPSEED=m
  1900. +CONFIG_HID_THRUSTMASTER=m
  1901. +CONFIG_HID_WACOM=m
  1902. +CONFIG_HID_WIIMOTE=m
  1903. +CONFIG_HID_ZEROPLUS=m
  1904. +CONFIG_HID_ZYDACRON=m
  1905. +CONFIG_USB=y
  1906. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1907. +CONFIG_USB_MON=m
  1908. +CONFIG_USB_DWCOTG=y
  1909. +CONFIG_USB_STORAGE=y
  1910. +CONFIG_USB_STORAGE_REALTEK=m
  1911. +CONFIG_USB_STORAGE_DATAFAB=m
  1912. +CONFIG_USB_STORAGE_FREECOM=m
  1913. +CONFIG_USB_STORAGE_ISD200=m
  1914. +CONFIG_USB_STORAGE_USBAT=m
  1915. +CONFIG_USB_STORAGE_SDDR09=m
  1916. +CONFIG_USB_STORAGE_SDDR55=m
  1917. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1918. +CONFIG_USB_STORAGE_ALAUDA=m
  1919. +CONFIG_USB_STORAGE_ONETOUCH=m
  1920. +CONFIG_USB_STORAGE_KARMA=m
  1921. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1922. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1923. +CONFIG_USB_UAS=y
  1924. +CONFIG_USB_LIBUSUAL=y
  1925. +CONFIG_USB_MDC800=m
  1926. +CONFIG_USB_MICROTEK=m
  1927. +CONFIG_USB_SERIAL=m
  1928. +CONFIG_USB_SERIAL_GENERIC=y
  1929. +CONFIG_USB_SERIAL_AIRCABLE=m
  1930. +CONFIG_USB_SERIAL_ARK3116=m
  1931. +CONFIG_USB_SERIAL_BELKIN=m
  1932. +CONFIG_USB_SERIAL_CH341=m
  1933. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1934. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1935. +CONFIG_USB_SERIAL_CP210X=m
  1936. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1937. +CONFIG_USB_SERIAL_EMPEG=m
  1938. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1939. +CONFIG_USB_SERIAL_FUNSOFT=m
  1940. +CONFIG_USB_SERIAL_VISOR=m
  1941. +CONFIG_USB_SERIAL_IPAQ=m
  1942. +CONFIG_USB_SERIAL_IR=m
  1943. +CONFIG_USB_SERIAL_EDGEPORT=m
  1944. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1945. +CONFIG_USB_SERIAL_GARMIN=m
  1946. +CONFIG_USB_SERIAL_IPW=m
  1947. +CONFIG_USB_SERIAL_IUU=m
  1948. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1949. +CONFIG_USB_SERIAL_KEYSPAN=m
  1950. +CONFIG_USB_SERIAL_KLSI=m
  1951. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1952. +CONFIG_USB_SERIAL_MCT_U232=m
  1953. +CONFIG_USB_SERIAL_MOS7720=m
  1954. +CONFIG_USB_SERIAL_MOS7840=m
  1955. +CONFIG_USB_SERIAL_MOTOROLA=m
  1956. +CONFIG_USB_SERIAL_NAVMAN=m
  1957. +CONFIG_USB_SERIAL_PL2303=m
  1958. +CONFIG_USB_SERIAL_OTI6858=m
  1959. +CONFIG_USB_SERIAL_QCAUX=m
  1960. +CONFIG_USB_SERIAL_QUALCOMM=m
  1961. +CONFIG_USB_SERIAL_SPCP8X5=m
  1962. +CONFIG_USB_SERIAL_HP4X=m
  1963. +CONFIG_USB_SERIAL_SAFE=m
  1964. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1965. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1966. +CONFIG_USB_SERIAL_SYMBOL=m
  1967. +CONFIG_USB_SERIAL_TI=m
  1968. +CONFIG_USB_SERIAL_CYBERJACK=m
  1969. +CONFIG_USB_SERIAL_XIRCOM=m
  1970. +CONFIG_USB_SERIAL_OPTION=m
  1971. +CONFIG_USB_SERIAL_OMNINET=m
  1972. +CONFIG_USB_SERIAL_OPTICON=m
  1973. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1974. +CONFIG_USB_SERIAL_ZIO=m
  1975. +CONFIG_USB_SERIAL_SSU100=m
  1976. +CONFIG_USB_SERIAL_DEBUG=m
  1977. +CONFIG_USB_EMI62=m
  1978. +CONFIG_USB_EMI26=m
  1979. +CONFIG_USB_ADUTUX=m
  1980. +CONFIG_USB_SEVSEG=m
  1981. +CONFIG_USB_RIO500=m
  1982. +CONFIG_USB_LEGOTOWER=m
  1983. +CONFIG_USB_LCD=m
  1984. +CONFIG_USB_LED=m
  1985. +CONFIG_USB_CYPRESS_CY7C63=m
  1986. +CONFIG_USB_CYTHERM=m
  1987. +CONFIG_USB_IDMOUSE=m
  1988. +CONFIG_USB_FTDI_ELAN=m
  1989. +CONFIG_USB_APPLEDISPLAY=m
  1990. +CONFIG_USB_LD=m
  1991. +CONFIG_USB_TRANCEVIBRATOR=m
  1992. +CONFIG_USB_IOWARRIOR=m
  1993. +CONFIG_USB_TEST=m
  1994. +CONFIG_USB_ISIGHTFW=m
  1995. +CONFIG_USB_YUREX=m
  1996. +CONFIG_MMC=y
  1997. +CONFIG_MMC_SDHCI=y
  1998. +CONFIG_MMC_SDHCI_PLTFM=y
  1999. +CONFIG_MMC_SDHCI_BCM2708=y
  2000. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2001. +CONFIG_LEDS_GPIO=y
  2002. +CONFIG_LEDS_TRIGGER_TIMER=m
  2003. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2004. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2005. +CONFIG_UIO=m
  2006. +CONFIG_UIO_PDRV=m
  2007. +CONFIG_UIO_PDRV_GENIRQ=m
  2008. +# CONFIG_IOMMU_SUPPORT is not set
  2009. +CONFIG_EXT4_FS=y
  2010. +CONFIG_EXT4_FS_POSIX_ACL=y
  2011. +CONFIG_EXT4_FS_SECURITY=y
  2012. +CONFIG_REISERFS_FS=m
  2013. +CONFIG_REISERFS_FS_XATTR=y
  2014. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2015. +CONFIG_REISERFS_FS_SECURITY=y
  2016. +CONFIG_JFS_FS=m
  2017. +CONFIG_JFS_POSIX_ACL=y
  2018. +CONFIG_JFS_SECURITY=y
  2019. +CONFIG_JFS_STATISTICS=y
  2020. +CONFIG_XFS_FS=m
  2021. +CONFIG_XFS_QUOTA=y
  2022. +CONFIG_XFS_POSIX_ACL=y
  2023. +CONFIG_XFS_RT=y
  2024. +CONFIG_GFS2_FS=m
  2025. +CONFIG_OCFS2_FS=m
  2026. +CONFIG_BTRFS_FS=m
  2027. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2028. +CONFIG_NILFS2_FS=m
  2029. +CONFIG_FANOTIFY=y
  2030. +CONFIG_AUTOFS4_FS=y
  2031. +CONFIG_FUSE_FS=m
  2032. +CONFIG_CUSE=m
  2033. +CONFIG_FSCACHE=y
  2034. +CONFIG_FSCACHE_STATS=y
  2035. +CONFIG_FSCACHE_HISTOGRAM=y
  2036. +CONFIG_CACHEFILES=y
  2037. +CONFIG_ISO9660_FS=m
  2038. +CONFIG_JOLIET=y
  2039. +CONFIG_ZISOFS=y
  2040. +CONFIG_UDF_FS=m
  2041. +CONFIG_MSDOS_FS=y
  2042. +CONFIG_VFAT_FS=y
  2043. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2044. +CONFIG_NTFS_FS=m
  2045. +CONFIG_TMPFS=y
  2046. +CONFIG_TMPFS_POSIX_ACL=y
  2047. +CONFIG_CONFIGFS_FS=y
  2048. +CONFIG_SQUASHFS=m
  2049. +CONFIG_SQUASHFS_XATTR=y
  2050. +CONFIG_SQUASHFS_LZO=y
  2051. +CONFIG_SQUASHFS_XZ=y
  2052. +CONFIG_NFS_FS=y
  2053. +CONFIG_NFS_V3=y
  2054. +CONFIG_NFS_V3_ACL=y
  2055. +CONFIG_NFS_V4=y
  2056. +CONFIG_ROOT_NFS=y
  2057. +CONFIG_NFS_FSCACHE=y
  2058. +CONFIG_CIFS=m
  2059. +CONFIG_CIFS_WEAK_PW_HASH=y
  2060. +CONFIG_CIFS_XATTR=y
  2061. +CONFIG_CIFS_POSIX=y
  2062. +CONFIG_9P_FS=m
  2063. +CONFIG_9P_FS_POSIX_ACL=y
  2064. +CONFIG_PARTITION_ADVANCED=y
  2065. +CONFIG_MAC_PARTITION=y
  2066. +CONFIG_EFI_PARTITION=y
  2067. +CONFIG_NLS_DEFAULT="utf8"
  2068. +CONFIG_NLS_CODEPAGE_437=y
  2069. +CONFIG_NLS_CODEPAGE_737=m
  2070. +CONFIG_NLS_CODEPAGE_775=m
  2071. +CONFIG_NLS_CODEPAGE_850=m
  2072. +CONFIG_NLS_CODEPAGE_852=m
  2073. +CONFIG_NLS_CODEPAGE_855=m
  2074. +CONFIG_NLS_CODEPAGE_857=m
  2075. +CONFIG_NLS_CODEPAGE_860=m
  2076. +CONFIG_NLS_CODEPAGE_861=m
  2077. +CONFIG_NLS_CODEPAGE_862=m
  2078. +CONFIG_NLS_CODEPAGE_863=m
  2079. +CONFIG_NLS_CODEPAGE_864=m
  2080. +CONFIG_NLS_CODEPAGE_865=m
  2081. +CONFIG_NLS_CODEPAGE_866=m
  2082. +CONFIG_NLS_CODEPAGE_869=m
  2083. +CONFIG_NLS_CODEPAGE_936=m
  2084. +CONFIG_NLS_CODEPAGE_950=m
  2085. +CONFIG_NLS_CODEPAGE_932=m
  2086. +CONFIG_NLS_CODEPAGE_949=m
  2087. +CONFIG_NLS_CODEPAGE_874=m
  2088. +CONFIG_NLS_ISO8859_8=m
  2089. +CONFIG_NLS_CODEPAGE_1250=m
  2090. +CONFIG_NLS_CODEPAGE_1251=m
  2091. +CONFIG_NLS_ASCII=y
  2092. +CONFIG_NLS_ISO8859_1=m
  2093. +CONFIG_NLS_ISO8859_2=m
  2094. +CONFIG_NLS_ISO8859_3=m
  2095. +CONFIG_NLS_ISO8859_4=m
  2096. +CONFIG_NLS_ISO8859_5=m
  2097. +CONFIG_NLS_ISO8859_6=m
  2098. +CONFIG_NLS_ISO8859_7=m
  2099. +CONFIG_NLS_ISO8859_9=m
  2100. +CONFIG_NLS_ISO8859_13=m
  2101. +CONFIG_NLS_ISO8859_14=m
  2102. +CONFIG_NLS_ISO8859_15=m
  2103. +CONFIG_NLS_KOI8_R=m
  2104. +CONFIG_NLS_KOI8_U=m
  2105. +CONFIG_NLS_UTF8=m
  2106. +CONFIG_PRINTK_TIME=y
  2107. +CONFIG_DETECT_HUNG_TASK=y
  2108. +CONFIG_TIMER_STATS=y
  2109. +CONFIG_DEBUG_STACK_USAGE=y
  2110. +CONFIG_DEBUG_INFO=y
  2111. +CONFIG_DEBUG_MEMORY_INIT=y
  2112. +CONFIG_BOOT_PRINTK_DELAY=y
  2113. +CONFIG_LATENCYTOP=y
  2114. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2115. +CONFIG_IRQSOFF_TRACER=y
  2116. +CONFIG_SCHED_TRACER=y
  2117. +CONFIG_STACK_TRACER=y
  2118. +CONFIG_BLK_DEV_IO_TRACE=y
  2119. +CONFIG_FUNCTION_PROFILER=y
  2120. +CONFIG_KGDB=y
  2121. +CONFIG_KGDB_KDB=y
  2122. +CONFIG_KDB_KEYBOARD=y
  2123. +CONFIG_STRICT_DEVMEM=y
  2124. +CONFIG_CRYPTO_AUTHENC=m
  2125. +CONFIG_CRYPTO_SEQIV=m
  2126. +CONFIG_CRYPTO_CBC=y
  2127. +CONFIG_CRYPTO_HMAC=y
  2128. +CONFIG_CRYPTO_XCBC=m
  2129. +CONFIG_CRYPTO_MD5=y
  2130. +CONFIG_CRYPTO_SHA1=y
  2131. +CONFIG_CRYPTO_SHA256=m
  2132. +CONFIG_CRYPTO_SHA512=m
  2133. +CONFIG_CRYPTO_TGR192=m
  2134. +CONFIG_CRYPTO_WP512=m
  2135. +CONFIG_CRYPTO_CAST5=m
  2136. +CONFIG_CRYPTO_DES=y
  2137. +CONFIG_CRYPTO_DEFLATE=m
  2138. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2139. +# CONFIG_CRYPTO_HW is not set
  2140. +CONFIG_CRC_ITU_T=y
  2141. +CONFIG_LIBCRC32C=y
  2142. diff -Nur linux-3.10.33/arch/arm/configs/bcmrpi_quick_defconfig linux-raspberry-pi/arch/arm/configs/bcmrpi_quick_defconfig
  2143. --- linux-3.10.33/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2144. +++ linux-raspberry-pi/arch/arm/configs/bcmrpi_quick_defconfig 2014-03-13 12:46:12.312043485 +0100
  2145. @@ -0,0 +1,197 @@
  2146. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2147. +CONFIG_LOCALVERSION="-quick"
  2148. +# CONFIG_LOCALVERSION_AUTO is not set
  2149. +# CONFIG_SWAP is not set
  2150. +CONFIG_SYSVIPC=y
  2151. +CONFIG_POSIX_MQUEUE=y
  2152. +CONFIG_NO_HZ=y
  2153. +CONFIG_HIGH_RES_TIMERS=y
  2154. +CONFIG_IKCONFIG=y
  2155. +CONFIG_IKCONFIG_PROC=y
  2156. +CONFIG_KALLSYMS_ALL=y
  2157. +CONFIG_EMBEDDED=y
  2158. +CONFIG_PERF_EVENTS=y
  2159. +# CONFIG_COMPAT_BRK is not set
  2160. +CONFIG_SLAB=y
  2161. +CONFIG_MODULES=y
  2162. +CONFIG_MODULE_UNLOAD=y
  2163. +CONFIG_MODVERSIONS=y
  2164. +CONFIG_MODULE_SRCVERSION_ALL=y
  2165. +# CONFIG_BLK_DEV_BSG is not set
  2166. +CONFIG_ARCH_BCM2708=y
  2167. +CONFIG_PREEMPT=y
  2168. +CONFIG_AEABI=y
  2169. +CONFIG_UACCESS_WITH_MEMCPY=y
  2170. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2171. +CONFIG_ZBOOT_ROM_BSS=0x0
  2172. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2173. +CONFIG_CPU_FREQ=y
  2174. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2175. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2176. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2177. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2178. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2179. +CONFIG_CPU_IDLE=y
  2180. +CONFIG_VFP=y
  2181. +CONFIG_BINFMT_MISC=y
  2182. +CONFIG_NET=y
  2183. +CONFIG_PACKET=y
  2184. +CONFIG_UNIX=y
  2185. +CONFIG_INET=y
  2186. +CONFIG_IP_MULTICAST=y
  2187. +CONFIG_IP_PNP=y
  2188. +CONFIG_IP_PNP_DHCP=y
  2189. +CONFIG_IP_PNP_RARP=y
  2190. +CONFIG_SYN_COOKIES=y
  2191. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2192. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2193. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2194. +# CONFIG_INET_LRO is not set
  2195. +# CONFIG_INET_DIAG is not set
  2196. +# CONFIG_IPV6 is not set
  2197. +# CONFIG_WIRELESS is not set
  2198. +CONFIG_DEVTMPFS=y
  2199. +CONFIG_DEVTMPFS_MOUNT=y
  2200. +CONFIG_BLK_DEV_LOOP=y
  2201. +CONFIG_BLK_DEV_RAM=y
  2202. +CONFIG_SCSI=y
  2203. +# CONFIG_SCSI_PROC_FS is not set
  2204. +# CONFIG_SCSI_LOWLEVEL is not set
  2205. +CONFIG_NETDEVICES=y
  2206. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2207. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2208. +# CONFIG_NET_VENDOR_FARADAY is not set
  2209. +# CONFIG_NET_VENDOR_INTEL is not set
  2210. +# CONFIG_NET_VENDOR_MARVELL is not set
  2211. +# CONFIG_NET_VENDOR_MICREL is not set
  2212. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2213. +# CONFIG_NET_VENDOR_SEEQ is not set
  2214. +# CONFIG_NET_VENDOR_STMICRO is not set
  2215. +# CONFIG_NET_VENDOR_WIZNET is not set
  2216. +CONFIG_USB_USBNET=y
  2217. +# CONFIG_USB_NET_AX8817X is not set
  2218. +# CONFIG_USB_NET_CDCETHER is not set
  2219. +# CONFIG_USB_NET_CDC_NCM is not set
  2220. +CONFIG_USB_NET_SMSC95XX=y
  2221. +# CONFIG_USB_NET_NET1080 is not set
  2222. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2223. +# CONFIG_USB_NET_ZAURUS is not set
  2224. +# CONFIG_WLAN is not set
  2225. +# CONFIG_INPUT_MOUSEDEV is not set
  2226. +CONFIG_INPUT_EVDEV=y
  2227. +# CONFIG_INPUT_KEYBOARD is not set
  2228. +# CONFIG_INPUT_MOUSE is not set
  2229. +# CONFIG_SERIO is not set
  2230. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2231. +# CONFIG_LEGACY_PTYS is not set
  2232. +# CONFIG_DEVKMEM is not set
  2233. +CONFIG_SERIAL_AMBA_PL011=y
  2234. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2235. +CONFIG_TTY_PRINTK=y
  2236. +CONFIG_HW_RANDOM=y
  2237. +CONFIG_HW_RANDOM_BCM2708=y
  2238. +CONFIG_RAW_DRIVER=y
  2239. +CONFIG_THERMAL=y
  2240. +CONFIG_THERMAL_BCM2835=y
  2241. +CONFIG_WATCHDOG=y
  2242. +CONFIG_BCM2708_WDT=y
  2243. +CONFIG_REGULATOR=y
  2244. +CONFIG_REGULATOR_DEBUG=y
  2245. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2246. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2247. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2248. +CONFIG_FB=y
  2249. +CONFIG_FB_BCM2708=y
  2250. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2251. +CONFIG_LOGO=y
  2252. +# CONFIG_LOGO_LINUX_MONO is not set
  2253. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2254. +CONFIG_SOUND=y
  2255. +CONFIG_SND=y
  2256. +CONFIG_SND_BCM2835=y
  2257. +# CONFIG_SND_USB is not set
  2258. +CONFIG_USB=y
  2259. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2260. +CONFIG_USB_DWCOTG=y
  2261. +CONFIG_MMC=y
  2262. +CONFIG_MMC_SDHCI=y
  2263. +CONFIG_MMC_SDHCI_PLTFM=y
  2264. +CONFIG_MMC_SDHCI_BCM2708=y
  2265. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2266. +CONFIG_NEW_LEDS=y
  2267. +CONFIG_LEDS_CLASS=y
  2268. +CONFIG_LEDS_TRIGGERS=y
  2269. +# CONFIG_IOMMU_SUPPORT is not set
  2270. +CONFIG_EXT4_FS=y
  2271. +CONFIG_EXT4_FS_POSIX_ACL=y
  2272. +CONFIG_EXT4_FS_SECURITY=y
  2273. +CONFIG_AUTOFS4_FS=y
  2274. +CONFIG_FSCACHE=y
  2275. +CONFIG_CACHEFILES=y
  2276. +CONFIG_MSDOS_FS=y
  2277. +CONFIG_VFAT_FS=y
  2278. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2279. +CONFIG_TMPFS=y
  2280. +CONFIG_TMPFS_POSIX_ACL=y
  2281. +CONFIG_CONFIGFS_FS=y
  2282. +# CONFIG_MISC_FILESYSTEMS is not set
  2283. +CONFIG_NFS_FS=y
  2284. +CONFIG_NFS_V3_ACL=y
  2285. +CONFIG_NFS_V4=y
  2286. +CONFIG_ROOT_NFS=y
  2287. +CONFIG_NFS_FSCACHE=y
  2288. +CONFIG_NLS_DEFAULT="utf8"
  2289. +CONFIG_NLS_CODEPAGE_437=y
  2290. +CONFIG_NLS_CODEPAGE_737=y
  2291. +CONFIG_NLS_CODEPAGE_775=y
  2292. +CONFIG_NLS_CODEPAGE_850=y
  2293. +CONFIG_NLS_CODEPAGE_852=y
  2294. +CONFIG_NLS_CODEPAGE_855=y
  2295. +CONFIG_NLS_CODEPAGE_857=y
  2296. +CONFIG_NLS_CODEPAGE_860=y
  2297. +CONFIG_NLS_CODEPAGE_861=y
  2298. +CONFIG_NLS_CODEPAGE_862=y
  2299. +CONFIG_NLS_CODEPAGE_863=y
  2300. +CONFIG_NLS_CODEPAGE_864=y
  2301. +CONFIG_NLS_CODEPAGE_865=y
  2302. +CONFIG_NLS_CODEPAGE_866=y
  2303. +CONFIG_NLS_CODEPAGE_869=y
  2304. +CONFIG_NLS_CODEPAGE_936=y
  2305. +CONFIG_NLS_CODEPAGE_950=y
  2306. +CONFIG_NLS_CODEPAGE_932=y
  2307. +CONFIG_NLS_CODEPAGE_949=y
  2308. +CONFIG_NLS_CODEPAGE_874=y
  2309. +CONFIG_NLS_ISO8859_8=y
  2310. +CONFIG_NLS_CODEPAGE_1250=y
  2311. +CONFIG_NLS_CODEPAGE_1251=y
  2312. +CONFIG_NLS_ASCII=y
  2313. +CONFIG_NLS_ISO8859_1=y
  2314. +CONFIG_NLS_ISO8859_2=y
  2315. +CONFIG_NLS_ISO8859_3=y
  2316. +CONFIG_NLS_ISO8859_4=y
  2317. +CONFIG_NLS_ISO8859_5=y
  2318. +CONFIG_NLS_ISO8859_6=y
  2319. +CONFIG_NLS_ISO8859_7=y
  2320. +CONFIG_NLS_ISO8859_9=y
  2321. +CONFIG_NLS_ISO8859_13=y
  2322. +CONFIG_NLS_ISO8859_14=y
  2323. +CONFIG_NLS_ISO8859_15=y
  2324. +CONFIG_NLS_UTF8=y
  2325. +CONFIG_PRINTK_TIME=y
  2326. +CONFIG_DEBUG_FS=y
  2327. +CONFIG_DETECT_HUNG_TASK=y
  2328. +# CONFIG_DEBUG_PREEMPT is not set
  2329. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2330. +# CONFIG_FTRACE is not set
  2331. +CONFIG_KGDB=y
  2332. +CONFIG_KGDB_KDB=y
  2333. +# CONFIG_ARM_UNWIND is not set
  2334. +CONFIG_CRYPTO_CBC=y
  2335. +CONFIG_CRYPTO_HMAC=y
  2336. +CONFIG_CRYPTO_MD5=y
  2337. +CONFIG_CRYPTO_SHA1=y
  2338. +CONFIG_CRYPTO_DES=y
  2339. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2340. +# CONFIG_CRYPTO_HW is not set
  2341. +CONFIG_CRC_ITU_T=y
  2342. +CONFIG_LIBCRC32C=y
  2343. diff -Nur linux-3.10.33/arch/arm/include/asm/fiq.h linux-raspberry-pi/arch/arm/include/asm/fiq.h
  2344. --- linux-3.10.33/arch/arm/include/asm/fiq.h 2014-03-07 06:58:45.000000000 +0100
  2345. +++ linux-raspberry-pi/arch/arm/include/asm/fiq.h 2014-03-13 12:46:12.344043549 +0100
  2346. @@ -42,6 +42,7 @@
  2347. /* helpers defined in fiqasm.S: */
  2348. extern void __set_fiq_regs(unsigned long const *regs);
  2349. extern void __get_fiq_regs(unsigned long *regs);
  2350. +extern void __FIQ_Branch(unsigned long *regs);
  2351. static inline void set_fiq_regs(struct pt_regs const *regs)
  2352. {
  2353. diff -Nur linux-3.10.33/arch/arm/Kconfig linux-raspberry-pi/arch/arm/Kconfig
  2354. --- linux-3.10.33/arch/arm/Kconfig 2014-03-07 06:58:45.000000000 +0100
  2355. +++ linux-raspberry-pi/arch/arm/Kconfig 2014-03-13 12:46:12.260043381 +0100
  2356. @@ -361,6 +361,24 @@
  2357. This enables support for systems based on Atmel
  2358. AT91RM9200 and AT91SAM9* processors.
  2359. +config ARCH_BCM2708
  2360. + bool "Broadcom BCM2708 family"
  2361. + select CPU_V6
  2362. + select ARM_AMBA
  2363. + select HAVE_CLK
  2364. + select HAVE_SCHED_CLOCK
  2365. + select NEED_MACH_GPIO_H
  2366. + select NEED_MACH_MEMORY_H
  2367. + select CLKDEV_LOOKUP
  2368. + select ARCH_HAS_CPUFREQ
  2369. + select GENERIC_CLOCKEVENTS
  2370. + select ARM_ERRATA_411920
  2371. + select MACH_BCM2708
  2372. + select VC4
  2373. + select FIQ
  2374. + help
  2375. + This enables support for Broadcom BCM2708 boards.
  2376. +
  2377. config ARCH_CLPS711X
  2378. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2379. select ARCH_REQUIRE_GPIOLIB
  2380. @@ -1025,6 +1043,7 @@
  2381. source "arch/arm/mach-vt8500/Kconfig"
  2382. source "arch/arm/mach-w90x900/Kconfig"
  2383. +source "arch/arm/mach-bcm2708/Kconfig"
  2384. source "arch/arm/mach-zynq/Kconfig"
  2385. diff -Nur linux-3.10.33/arch/arm/Kconfig.debug linux-raspberry-pi/arch/arm/Kconfig.debug
  2386. --- linux-3.10.33/arch/arm/Kconfig.debug 2014-03-07 06:58:45.000000000 +0100
  2387. +++ linux-raspberry-pi/arch/arm/Kconfig.debug 2014-03-13 12:46:12.260043381 +0100
  2388. @@ -519,6 +519,14 @@
  2389. For more details about semihosting, please see
  2390. chapter 8 of DUI0203I_rvct_developer_guide.pdf from ARM Ltd.
  2391. + config DEBUG_BCM2708_UART0
  2392. + bool "Broadcom BCM2708 UART0 (PL011)"
  2393. + depends on MACH_BCM2708
  2394. + help
  2395. + Say Y here if you want the debug print routines to direct
  2396. + their output to UART 0. The port must have been initialised
  2397. + by the boot-loader before use.
  2398. +
  2399. endchoice
  2400. config DEBUG_EXYNOS_UART
  2401. diff -Nur linux-3.10.33/arch/arm/kernel/armksyms.c linux-raspberry-pi/arch/arm/kernel/armksyms.c
  2402. --- linux-3.10.33/arch/arm/kernel/armksyms.c 2014-03-07 06:58:45.000000000 +0100
  2403. +++ linux-raspberry-pi/arch/arm/kernel/armksyms.c 2014-03-13 12:46:12.372043605 +0100
  2404. @@ -156,3 +156,7 @@
  2405. #ifdef CONFIG_ARM_PATCH_PHYS_VIRT
  2406. EXPORT_SYMBOL(__pv_phys_offset);
  2407. #endif
  2408. +
  2409. +extern void v6wbi_flush_kern_tlb_range(void);
  2410. +EXPORT_SYMBOL(v6wbi_flush_kern_tlb_range);
  2411. +
  2412. diff -Nur linux-3.10.33/arch/arm/kernel/fiqasm.S linux-raspberry-pi/arch/arm/kernel/fiqasm.S
  2413. --- linux-3.10.33/arch/arm/kernel/fiqasm.S 2014-03-07 06:58:45.000000000 +0100
  2414. +++ linux-raspberry-pi/arch/arm/kernel/fiqasm.S 2014-03-13 12:46:12.376043613 +0100
  2415. @@ -25,6 +25,9 @@
  2416. ENTRY(__set_fiq_regs)
  2417. mov r2, #PSR_I_BIT | PSR_F_BIT | FIQ_MODE
  2418. mrs r1, cpsr
  2419. +@@@@@@@@@@@@@@@ hack: enable the fiq here to keep usb driver happy
  2420. + and r1, #~PSR_F_BIT
  2421. +@@@@@@@@@@@@@@@ endhack: (need to find better place for this to happen)
  2422. msr cpsr_c, r2 @ select FIQ mode
  2423. mov r0, r0 @ avoid hazard prior to ARMv4
  2424. ldmia r0!, {r8 - r12}
  2425. @@ -47,3 +50,7 @@
  2426. mov r0, r0 @ avoid hazard prior to ARMv4
  2427. mov pc, lr
  2428. ENDPROC(__get_fiq_regs)
  2429. +
  2430. +ENTRY(__FIQ_Branch)
  2431. + mov pc, r8
  2432. +ENDPROC(__FIQ_Branch)
  2433. diff -Nur linux-3.10.33/arch/arm/kernel/fiq.c linux-raspberry-pi/arch/arm/kernel/fiq.c
  2434. --- linux-3.10.33/arch/arm/kernel/fiq.c 2014-03-07 06:58:45.000000000 +0100
  2435. +++ linux-raspberry-pi/arch/arm/kernel/fiq.c 2014-03-13 12:46:12.376043613 +0100
  2436. @@ -84,17 +84,14 @@
  2437. void set_fiq_handler(void *start, unsigned int length)
  2438. {
  2439. -#if defined(CONFIG_CPU_USE_DOMAINS)
  2440. - void *base = (void *)0xffff0000;
  2441. -#else
  2442. void *base = vectors_page;
  2443. -#endif
  2444. unsigned offset = FIQ_OFFSET;
  2445. memcpy(base + offset, start, length);
  2446. + if (!cache_is_vipt_nonaliasing())
  2447. + flush_icache_range((unsigned long)base + offset, offset +
  2448. + length);
  2449. flush_icache_range(0xffff0000 + offset, 0xffff0000 + offset + length);
  2450. - if (!vectors_high())
  2451. - flush_icache_range(offset, offset + length);
  2452. }
  2453. int claim_fiq(struct fiq_handler *f)
  2454. @@ -145,6 +142,7 @@
  2455. EXPORT_SYMBOL(set_fiq_handler);
  2456. EXPORT_SYMBOL(__set_fiq_regs); /* defined in fiqasm.S */
  2457. EXPORT_SYMBOL(__get_fiq_regs); /* defined in fiqasm.S */
  2458. +EXPORT_SYMBOL(__FIQ_Branch); /* defined in fiqasm.S */
  2459. EXPORT_SYMBOL(claim_fiq);
  2460. EXPORT_SYMBOL(release_fiq);
  2461. EXPORT_SYMBOL(enable_fiq);
  2462. diff -Nur linux-3.10.33/arch/arm/kernel/process.c linux-raspberry-pi/arch/arm/kernel/process.c
  2463. --- linux-3.10.33/arch/arm/kernel/process.c 2014-03-07 06:58:45.000000000 +0100
  2464. +++ linux-raspberry-pi/arch/arm/kernel/process.c 2014-03-13 12:46:12.380043621 +0100
  2465. @@ -174,7 +174,7 @@
  2466. default_idle();
  2467. }
  2468. -static char reboot_mode = 'h';
  2469. +char reboot_mode = 'h';
  2470. int __init reboot_setup(char *str)
  2471. {
  2472. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/armctrl.c linux-raspberry-pi/arch/arm/mach-bcm2708/armctrl.c
  2473. --- linux-3.10.33/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2474. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/armctrl.c 2014-03-13 12:46:12.432043725 +0100
  2475. @@ -0,0 +1,219 @@
  2476. +/*
  2477. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2478. + *
  2479. + * Copyright (C) 2010 Broadcom
  2480. + *
  2481. + * This program is free software; you can redistribute it and/or modify
  2482. + * it under the terms of the GNU General Public License as published by
  2483. + * the Free Software Foundation; either version 2 of the License, or
  2484. + * (at your option) any later version.
  2485. + *
  2486. + * This program is distributed in the hope that it will be useful,
  2487. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2488. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2489. + * GNU General Public License for more details.
  2490. + *
  2491. + * You should have received a copy of the GNU General Public License
  2492. + * along with this program; if not, write to the Free Software
  2493. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2494. + */
  2495. +#include <linux/init.h>
  2496. +#include <linux/list.h>
  2497. +#include <linux/io.h>
  2498. +#include <linux/version.h>
  2499. +#include <linux/syscore_ops.h>
  2500. +#include <linux/interrupt.h>
  2501. +
  2502. +#include <asm/mach/irq.h>
  2503. +#include <mach/hardware.h>
  2504. +#include "armctrl.h"
  2505. +
  2506. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2507. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2508. + INTERRUPT_VC_JPEG,
  2509. + INTERRUPT_VC_USB,
  2510. + INTERRUPT_VC_3D,
  2511. + INTERRUPT_VC_DMA2,
  2512. + INTERRUPT_VC_DMA3,
  2513. + INTERRUPT_VC_I2C,
  2514. + INTERRUPT_VC_SPI,
  2515. + INTERRUPT_VC_I2SPCM,
  2516. + INTERRUPT_VC_SDIO,
  2517. + INTERRUPT_VC_UART,
  2518. + INTERRUPT_VC_ARASANSDIO
  2519. +};
  2520. +
  2521. +static void armctrl_mask_irq(struct irq_data *d)
  2522. +{
  2523. + static const unsigned int disables[4] = {
  2524. + ARM_IRQ_DIBL1,
  2525. + ARM_IRQ_DIBL2,
  2526. + ARM_IRQ_DIBL3,
  2527. + 0
  2528. + };
  2529. +
  2530. + if (d->irq >= FIQ_START) {
  2531. + writel(0, __io_address(ARM_IRQ_FAST));
  2532. + } else {
  2533. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2534. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2535. + }
  2536. +}
  2537. +
  2538. +static void armctrl_unmask_irq(struct irq_data *d)
  2539. +{
  2540. + static const unsigned int enables[4] = {
  2541. + ARM_IRQ_ENBL1,
  2542. + ARM_IRQ_ENBL2,
  2543. + ARM_IRQ_ENBL3,
  2544. + 0
  2545. + };
  2546. +
  2547. + if (d->irq >= FIQ_START) {
  2548. + unsigned int data =
  2549. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2550. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2551. + } else {
  2552. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2553. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2554. + }
  2555. +}
  2556. +
  2557. +#if defined(CONFIG_PM)
  2558. +
  2559. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2560. +
  2561. +/* Static defines
  2562. + * struct armctrl_device - VIC PM device (< 3.xx)
  2563. + * @sysdev: The system device which is registered. (< 3.xx)
  2564. + * @irq: The IRQ number for the base of the VIC.
  2565. + * @base: The register base for the VIC.
  2566. + * @resume_sources: A bitmask of interrupts for resume.
  2567. + * @resume_irqs: The IRQs enabled for resume.
  2568. + * @int_select: Save for VIC_INT_SELECT.
  2569. + * @int_enable: Save for VIC_INT_ENABLE.
  2570. + * @soft_int: Save for VIC_INT_SOFT.
  2571. + * @protect: Save for VIC_PROTECT.
  2572. + */
  2573. +struct armctrl_info {
  2574. + void __iomem *base;
  2575. + int irq;
  2576. + u32 resume_sources;
  2577. + u32 resume_irqs;
  2578. + u32 int_select;
  2579. + u32 int_enable;
  2580. + u32 soft_int;
  2581. + u32 protect;
  2582. +} armctrl;
  2583. +
  2584. +static int armctrl_suspend(void)
  2585. +{
  2586. + return 0;
  2587. +}
  2588. +
  2589. +static void armctrl_resume(void)
  2590. +{
  2591. + return;
  2592. +}
  2593. +
  2594. +/**
  2595. + * armctrl_pm_register - Register a VIC for later power management control
  2596. + * @base: The base address of the VIC.
  2597. + * @irq: The base IRQ for the VIC.
  2598. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2599. + *
  2600. + * For older kernels (< 3.xx) do -
  2601. + * Register the VIC with the system device tree so that it can be notified
  2602. + * of suspend and resume requests and ensure that the correct actions are
  2603. + * taken to re-instate the settings on resume.
  2604. + */
  2605. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2606. + u32 resume_sources)
  2607. +{
  2608. + armctrl.base = base;
  2609. + armctrl.resume_sources = resume_sources;
  2610. + armctrl.irq = irq;
  2611. +}
  2612. +
  2613. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2614. +{
  2615. + unsigned int off = d->irq & 31;
  2616. + u32 bit = 1 << off;
  2617. +
  2618. + if (!(bit & armctrl.resume_sources))
  2619. + return -EINVAL;
  2620. +
  2621. + if (on)
  2622. + armctrl.resume_irqs |= bit;
  2623. + else
  2624. + armctrl.resume_irqs &= ~bit;
  2625. +
  2626. + return 0;
  2627. +}
  2628. +
  2629. +#else
  2630. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2631. + u32 arg1)
  2632. +{
  2633. +}
  2634. +
  2635. +#define armctrl_suspend NULL
  2636. +#define armctrl_resume NULL
  2637. +#define armctrl_set_wake NULL
  2638. +#endif /* CONFIG_PM */
  2639. +
  2640. +static struct syscore_ops armctrl_syscore_ops = {
  2641. + .suspend = armctrl_suspend,
  2642. + .resume = armctrl_resume,
  2643. +};
  2644. +
  2645. +/**
  2646. + * armctrl_syscore_init - initicall to register VIC pm functions
  2647. + *
  2648. + * This is called via late_initcall() to register
  2649. + * the resources for the VICs due to the early
  2650. + * nature of the VIC's registration.
  2651. +*/
  2652. +static int __init armctrl_syscore_init(void)
  2653. +{
  2654. + register_syscore_ops(&armctrl_syscore_ops);
  2655. + return 0;
  2656. +}
  2657. +
  2658. +late_initcall(armctrl_syscore_init);
  2659. +
  2660. +static struct irq_chip armctrl_chip = {
  2661. + .name = "ARMCTRL",
  2662. + .irq_ack = armctrl_mask_irq,
  2663. + .irq_mask = armctrl_mask_irq,
  2664. + .irq_unmask = armctrl_unmask_irq,
  2665. + .irq_set_wake = armctrl_set_wake,
  2666. +};
  2667. +
  2668. +/**
  2669. + * armctrl_init - initialise a vectored interrupt controller
  2670. + * @base: iomem base address
  2671. + * @irq_start: starting interrupt number, must be muliple of 32
  2672. + * @armctrl_sources: bitmask of interrupt sources to allow
  2673. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2674. + */
  2675. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2676. + u32 armctrl_sources, u32 resume_sources)
  2677. +{
  2678. + unsigned int irq;
  2679. +
  2680. + for (irq = 0; irq < NR_IRQS; irq++) {
  2681. + unsigned int data = irq;
  2682. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2683. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2684. +
  2685. + irq_set_chip(irq, &armctrl_chip);
  2686. + irq_set_chip_data(irq, (void *)data);
  2687. + irq_set_handler(irq, handle_level_irq);
  2688. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2689. + }
  2690. +
  2691. + armctrl_pm_register(base, irq_start, resume_sources);
  2692. + init_FIQ(FIQ_START);
  2693. + return 0;
  2694. +}
  2695. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/armctrl.h linux-raspberry-pi/arch/arm/mach-bcm2708/armctrl.h
  2696. --- linux-3.10.33/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2697. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/armctrl.h 2014-03-13 12:46:12.432043725 +0100
  2698. @@ -0,0 +1,27 @@
  2699. +/*
  2700. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2701. + *
  2702. + * Copyright (C) 2010 Broadcom
  2703. + *
  2704. + * This program is free software; you can redistribute it and/or modify
  2705. + * it under the terms of the GNU General Public License as published by
  2706. + * the Free Software Foundation; either version 2 of the License, or
  2707. + * (at your option) any later version.
  2708. + *
  2709. + * This program is distributed in the hope that it will be useful,
  2710. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2711. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2712. + * GNU General Public License for more details.
  2713. + *
  2714. + * You should have received a copy of the GNU General Public License
  2715. + * along with this program; if not, write to the Free Software
  2716. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2717. + */
  2718. +
  2719. +#ifndef __BCM2708_ARMCTRL_H
  2720. +#define __BCM2708_ARMCTRL_H
  2721. +
  2722. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2723. + u32 armctrl_sources, u32 resume_sources);
  2724. +
  2725. +#endif
  2726. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/bcm2708.c linux-raspberry-pi/arch/arm/mach-bcm2708/bcm2708.c
  2727. --- linux-3.10.33/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2728. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/bcm2708.c 2014-03-13 12:46:12.432043725 +0100
  2729. @@ -0,0 +1,1014 @@
  2730. +/*
  2731. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2732. + *
  2733. + * Copyright (C) 2010 Broadcom
  2734. + *
  2735. + * This program is free software; you can redistribute it and/or modify
  2736. + * it under the terms of the GNU General Public License as published by
  2737. + * the Free Software Foundation; either version 2 of the License, or
  2738. + * (at your option) any later version.
  2739. + *
  2740. + * This program is distributed in the hope that it will be useful,
  2741. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2742. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2743. + * GNU General Public License for more details.
  2744. + *
  2745. + * You should have received a copy of the GNU General Public License
  2746. + * along with this program; if not, write to the Free Software
  2747. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2748. + */
  2749. +
  2750. +#include <linux/init.h>
  2751. +#include <linux/device.h>
  2752. +#include <linux/dma-mapping.h>
  2753. +#include <linux/serial_8250.h>
  2754. +#include <linux/platform_device.h>
  2755. +#include <linux/syscore_ops.h>
  2756. +#include <linux/interrupt.h>
  2757. +#include <linux/amba/bus.h>
  2758. +#include <linux/amba/clcd.h>
  2759. +#include <linux/clockchips.h>
  2760. +#include <linux/cnt32_to_63.h>
  2761. +#include <linux/io.h>
  2762. +#include <linux/module.h>
  2763. +#include <linux/spi/spi.h>
  2764. +#include <linux/w1-gpio.h>
  2765. +
  2766. +#include <linux/version.h>
  2767. +#include <linux/clkdev.h>
  2768. +#include <asm/system.h>
  2769. +#include <mach/hardware.h>
  2770. +#include <asm/irq.h>
  2771. +#include <linux/leds.h>
  2772. +#include <asm/mach-types.h>
  2773. +#include <asm/sched_clock.h>
  2774. +
  2775. +#include <asm/mach/arch.h>
  2776. +#include <asm/mach/flash.h>
  2777. +#include <asm/mach/irq.h>
  2778. +#include <asm/mach/time.h>
  2779. +#include <asm/mach/map.h>
  2780. +
  2781. +#include <mach/timex.h>
  2782. +#include <mach/dma.h>
  2783. +#include <mach/vcio.h>
  2784. +#include <mach/system.h>
  2785. +
  2786. +#include <linux/delay.h>
  2787. +
  2788. +#include "bcm2708.h"
  2789. +#include "armctrl.h"
  2790. +#include "clock.h"
  2791. +
  2792. +#ifdef CONFIG_BCM_VC_CMA
  2793. +#include <linux/broadcom/vc_cma.h>
  2794. +#endif
  2795. +
  2796. +
  2797. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2798. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2799. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2800. + * we're not going to use addresses outside this range (they're not in real
  2801. + * memory) so we don't bother.
  2802. + *
  2803. + * In the future we might include code to use this IOMMU to remap other
  2804. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2805. + * more legitimate.
  2806. + */
  2807. +#define DMA_MASK_BITS_COMMON 32
  2808. +
  2809. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2810. +#define W1_GPIO 4
  2811. +
  2812. +/* command line parameters */
  2813. +static unsigned boardrev, serial;
  2814. +static unsigned uart_clock;
  2815. +static unsigned disk_led_gpio = 16;
  2816. +static unsigned disk_led_active_low = 1;
  2817. +static unsigned reboot_part = 0;
  2818. +static unsigned w1_gpio_pin = W1_GPIO;
  2819. +
  2820. +static void __init bcm2708_init_led(void);
  2821. +
  2822. +void __init bcm2708_init_irq(void)
  2823. +{
  2824. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2825. +}
  2826. +
  2827. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2828. + {
  2829. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2830. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2831. + .length = SZ_4K,
  2832. + .type = MT_DEVICE},
  2833. + {
  2834. + .virtual = IO_ADDRESS(UART0_BASE),
  2835. + .pfn = __phys_to_pfn(UART0_BASE),
  2836. + .length = SZ_4K,
  2837. + .type = MT_DEVICE},
  2838. + {
  2839. + .virtual = IO_ADDRESS(UART1_BASE),
  2840. + .pfn = __phys_to_pfn(UART1_BASE),
  2841. + .length = SZ_4K,
  2842. + .type = MT_DEVICE},
  2843. + {
  2844. + .virtual = IO_ADDRESS(DMA_BASE),
  2845. + .pfn = __phys_to_pfn(DMA_BASE),
  2846. + .length = SZ_4K,
  2847. + .type = MT_DEVICE},
  2848. + {
  2849. + .virtual = IO_ADDRESS(MCORE_BASE),
  2850. + .pfn = __phys_to_pfn(MCORE_BASE),
  2851. + .length = SZ_4K,
  2852. + .type = MT_DEVICE},
  2853. + {
  2854. + .virtual = IO_ADDRESS(ST_BASE),
  2855. + .pfn = __phys_to_pfn(ST_BASE),
  2856. + .length = SZ_4K,
  2857. + .type = MT_DEVICE},
  2858. + {
  2859. + .virtual = IO_ADDRESS(USB_BASE),
  2860. + .pfn = __phys_to_pfn(USB_BASE),
  2861. + .length = SZ_128K,
  2862. + .type = MT_DEVICE},
  2863. + {
  2864. + .virtual = IO_ADDRESS(PM_BASE),
  2865. + .pfn = __phys_to_pfn(PM_BASE),
  2866. + .length = SZ_4K,
  2867. + .type = MT_DEVICE},
  2868. + {
  2869. + .virtual = IO_ADDRESS(GPIO_BASE),
  2870. + .pfn = __phys_to_pfn(GPIO_BASE),
  2871. + .length = SZ_4K,
  2872. + .type = MT_DEVICE}
  2873. +};
  2874. +
  2875. +void __init bcm2708_map_io(void)
  2876. +{
  2877. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2878. +}
  2879. +
  2880. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2881. +#define STC_FREQ_HZ 1000000
  2882. +
  2883. +static inline uint32_t timer_read(void)
  2884. +{
  2885. + /* STC: a free running counter that increments at the rate of 1MHz */
  2886. + return readl(__io_address(ST_BASE + 0x04));
  2887. +}
  2888. +
  2889. +static unsigned long bcm2708_read_current_timer(void)
  2890. +{
  2891. + return timer_read();
  2892. +}
  2893. +
  2894. +static u32 notrace bcm2708_read_sched_clock(void)
  2895. +{
  2896. + return timer_read();
  2897. +}
  2898. +
  2899. +static cycle_t clksrc_read(struct clocksource *cs)
  2900. +{
  2901. + return timer_read();
  2902. +}
  2903. +
  2904. +static struct clocksource clocksource_stc = {
  2905. + .name = "stc",
  2906. + .rating = 300,
  2907. + .read = clksrc_read,
  2908. + .mask = CLOCKSOURCE_MASK(32),
  2909. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2910. +};
  2911. +
  2912. +unsigned long frc_clock_ticks32(void)
  2913. +{
  2914. + return timer_read();
  2915. +}
  2916. +
  2917. +static void __init bcm2708_clocksource_init(void)
  2918. +{
  2919. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2920. + printk(KERN_ERR "timer: failed to initialize clock "
  2921. + "source %s\n", clocksource_stc.name);
  2922. + }
  2923. +}
  2924. +
  2925. +
  2926. +/*
  2927. + * These are fixed clocks.
  2928. + */
  2929. +static struct clk ref24_clk = {
  2930. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2931. +};
  2932. +
  2933. +static struct clk osc_clk = {
  2934. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2935. + .rate = 27000000,
  2936. +#else
  2937. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2938. +#endif
  2939. +};
  2940. +
  2941. +/* warning - the USB needs a clock > 34MHz */
  2942. +
  2943. +static struct clk sdhost_clk = {
  2944. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2945. + .rate = 4000000, /* 4MHz */
  2946. +#else
  2947. + .rate = 250000000, /* 250MHz */
  2948. +#endif
  2949. +};
  2950. +
  2951. +static struct clk_lookup lookups[] = {
  2952. + { /* UART0 */
  2953. + .dev_id = "dev:f1",
  2954. + .clk = &ref24_clk,
  2955. + },
  2956. + { /* USB */
  2957. + .dev_id = "bcm2708_usb",
  2958. + .clk = &osc_clk,
  2959. + }, { /* SPI */
  2960. + .dev_id = "bcm2708_spi.0",
  2961. + .clk = &sdhost_clk,
  2962. + }, { /* BSC0 */
  2963. + .dev_id = "bcm2708_i2c.0",
  2964. + .clk = &sdhost_clk,
  2965. + }, { /* BSC1 */
  2966. + .dev_id = "bcm2708_i2c.1",
  2967. + .clk = &sdhost_clk,
  2968. + }
  2969. +};
  2970. +
  2971. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2972. +#define UART0_DMA { 15, 14 }
  2973. +
  2974. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2975. +
  2976. +static struct amba_device *amba_devs[] __initdata = {
  2977. + &uart0_device,
  2978. +};
  2979. +
  2980. +static struct resource bcm2708_dmaman_resources[] = {
  2981. + {
  2982. + .start = DMA_BASE,
  2983. + .end = DMA_BASE + SZ_4K - 1,
  2984. + .flags = IORESOURCE_MEM,
  2985. + }
  2986. +};
  2987. +
  2988. +static struct platform_device bcm2708_dmaman_device = {
  2989. + .name = BCM_DMAMAN_DRIVER_NAME,
  2990. + .id = 0, /* first bcm2708_dma */
  2991. + .resource = bcm2708_dmaman_resources,
  2992. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2993. +};
  2994. +
  2995. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2996. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2997. + .pin = W1_GPIO,
  2998. + .is_open_drain = 0,
  2999. +};
  3000. +
  3001. +static struct platform_device w1_device = {
  3002. + .name = "w1-gpio",
  3003. + .id = -1,
  3004. + .dev.platform_data = &w1_gpio_pdata,
  3005. +};
  3006. +#endif
  3007. +
  3008. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3009. +
  3010. +static struct platform_device bcm2708_fb_device = {
  3011. + .name = "bcm2708_fb",
  3012. + .id = -1, /* only one bcm2708_fb */
  3013. + .resource = NULL,
  3014. + .num_resources = 0,
  3015. + .dev = {
  3016. + .dma_mask = &fb_dmamask,
  3017. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3018. + },
  3019. +};
  3020. +
  3021. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  3022. + {
  3023. + .mapbase = UART1_BASE + 0x40,
  3024. + .irq = IRQ_AUX,
  3025. + .uartclk = 125000000,
  3026. + .regshift = 2,
  3027. + .iotype = UPIO_MEM,
  3028. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3029. + .type = PORT_8250,
  3030. + },
  3031. + {},
  3032. +};
  3033. +
  3034. +static struct platform_device bcm2708_uart1_device = {
  3035. + .name = "serial8250",
  3036. + .id = PLAT8250_DEV_PLATFORM,
  3037. + .dev = {
  3038. + .platform_data = bcm2708_uart1_platform_data,
  3039. + },
  3040. +};
  3041. +
  3042. +static struct resource bcm2708_usb_resources[] = {
  3043. + [0] = {
  3044. + .start = USB_BASE,
  3045. + .end = USB_BASE + SZ_128K - 1,
  3046. + .flags = IORESOURCE_MEM,
  3047. + },
  3048. + [1] = {
  3049. + .start = MPHI_BASE,
  3050. + .end = MPHI_BASE + SZ_4K - 1,
  3051. + .flags = IORESOURCE_MEM,
  3052. + },
  3053. + [2] = {
  3054. + .start = IRQ_HOSTPORT,
  3055. + .end = IRQ_HOSTPORT,
  3056. + .flags = IORESOURCE_IRQ,
  3057. + },
  3058. +};
  3059. +
  3060. +bool fiq_fix_enable = true;
  3061. +
  3062. +static struct resource bcm2708_usb_resources_no_fiq_fix[] = {
  3063. + [0] = {
  3064. + .start = USB_BASE,
  3065. + .end = USB_BASE + SZ_128K - 1,
  3066. + .flags = IORESOURCE_MEM,
  3067. + },
  3068. + [1] = {
  3069. + .start = IRQ_USB,
  3070. + .end = IRQ_USB,
  3071. + .flags = IORESOURCE_IRQ,
  3072. + },
  3073. +};
  3074. +
  3075. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3076. +
  3077. +static struct platform_device bcm2708_usb_device = {
  3078. + .name = "bcm2708_usb",
  3079. + .id = -1, /* only one bcm2708_usb */
  3080. + .resource = bcm2708_usb_resources,
  3081. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3082. + .dev = {
  3083. + .dma_mask = &usb_dmamask,
  3084. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3085. + },
  3086. +};
  3087. +
  3088. +static struct resource bcm2708_vcio_resources[] = {
  3089. + [0] = { /* mailbox/semaphore/doorbell access */
  3090. + .start = MCORE_BASE,
  3091. + .end = MCORE_BASE + SZ_4K - 1,
  3092. + .flags = IORESOURCE_MEM,
  3093. + },
  3094. +};
  3095. +
  3096. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3097. +
  3098. +static struct platform_device bcm2708_vcio_device = {
  3099. + .name = BCM_VCIO_DRIVER_NAME,
  3100. + .id = -1, /* only one VideoCore I/O area */
  3101. + .resource = bcm2708_vcio_resources,
  3102. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3103. + .dev = {
  3104. + .dma_mask = &vcio_dmamask,
  3105. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3106. + },
  3107. +};
  3108. +
  3109. +#ifdef CONFIG_BCM2708_GPIO
  3110. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3111. +
  3112. +static struct resource bcm2708_gpio_resources[] = {
  3113. + [0] = { /* general purpose I/O */
  3114. + .start = GPIO_BASE,
  3115. + .end = GPIO_BASE + SZ_4K - 1,
  3116. + .flags = IORESOURCE_MEM,
  3117. + },
  3118. +};
  3119. +
  3120. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3121. +
  3122. +static struct platform_device bcm2708_gpio_device = {
  3123. + .name = BCM_GPIO_DRIVER_NAME,
  3124. + .id = -1, /* only one VideoCore I/O area */
  3125. + .resource = bcm2708_gpio_resources,
  3126. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3127. + .dev = {
  3128. + .dma_mask = &gpio_dmamask,
  3129. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3130. + },
  3131. +};
  3132. +#endif
  3133. +
  3134. +static struct resource bcm2708_systemtimer_resources[] = {
  3135. + [0] = { /* system timer access */
  3136. + .start = ST_BASE,
  3137. + .end = ST_BASE + SZ_4K - 1,
  3138. + .flags = IORESOURCE_MEM,
  3139. + },
  3140. + {
  3141. + .start = IRQ_TIMER3,
  3142. + .end = IRQ_TIMER3,
  3143. + .flags = IORESOURCE_IRQ,
  3144. + }
  3145. +
  3146. +};
  3147. +
  3148. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3149. +
  3150. +static struct platform_device bcm2708_systemtimer_device = {
  3151. + .name = "bcm2708_systemtimer",
  3152. + .id = -1, /* only one VideoCore I/O area */
  3153. + .resource = bcm2708_systemtimer_resources,
  3154. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3155. + .dev = {
  3156. + .dma_mask = &systemtimer_dmamask,
  3157. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3158. + },
  3159. +};
  3160. +
  3161. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3162. +static struct resource bcm2708_emmc_resources[] = {
  3163. + [0] = {
  3164. + .start = EMMC_BASE,
  3165. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3166. + /* the memory map actually makes SZ_4K available */
  3167. + .flags = IORESOURCE_MEM,
  3168. + },
  3169. + [1] = {
  3170. + .start = IRQ_ARASANSDIO,
  3171. + .end = IRQ_ARASANSDIO,
  3172. + .flags = IORESOURCE_IRQ,
  3173. + },
  3174. +};
  3175. +
  3176. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3177. +
  3178. +struct platform_device bcm2708_emmc_device = {
  3179. + .name = "bcm2708_sdhci",
  3180. + .id = 0,
  3181. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3182. + .resource = bcm2708_emmc_resources,
  3183. + .dev = {
  3184. + .dma_mask = &bcm2708_emmc_dmamask,
  3185. + .coherent_dma_mask = 0xffffffffUL},
  3186. +};
  3187. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3188. +
  3189. +static struct resource bcm2708_powerman_resources[] = {
  3190. + [0] = {
  3191. + .start = PM_BASE,
  3192. + .end = PM_BASE + SZ_256 - 1,
  3193. + .flags = IORESOURCE_MEM,
  3194. + },
  3195. +};
  3196. +
  3197. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3198. +
  3199. +struct platform_device bcm2708_powerman_device = {
  3200. + .name = "bcm2708_powerman",
  3201. + .id = 0,
  3202. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3203. + .resource = bcm2708_powerman_resources,
  3204. + .dev = {
  3205. + .dma_mask = &powerman_dmamask,
  3206. + .coherent_dma_mask = 0xffffffffUL},
  3207. +};
  3208. +
  3209. +
  3210. +static struct platform_device bcm2708_alsa_devices[] = {
  3211. + [0] = {
  3212. + .name = "bcm2835_AUD0",
  3213. + .id = 0, /* first audio device */
  3214. + .resource = 0,
  3215. + .num_resources = 0,
  3216. + },
  3217. + [1] = {
  3218. + .name = "bcm2835_AUD1",
  3219. + .id = 1, /* second audio device */
  3220. + .resource = 0,
  3221. + .num_resources = 0,
  3222. + },
  3223. + [2] = {
  3224. + .name = "bcm2835_AUD2",
  3225. + .id = 2, /* third audio device */
  3226. + .resource = 0,
  3227. + .num_resources = 0,
  3228. + },
  3229. + [3] = {
  3230. + .name = "bcm2835_AUD3",
  3231. + .id = 3, /* forth audio device */
  3232. + .resource = 0,
  3233. + .num_resources = 0,
  3234. + },
  3235. + [4] = {
  3236. + .name = "bcm2835_AUD4",
  3237. + .id = 4, /* fifth audio device */
  3238. + .resource = 0,
  3239. + .num_resources = 0,
  3240. + },
  3241. + [5] = {
  3242. + .name = "bcm2835_AUD5",
  3243. + .id = 5, /* sixth audio device */
  3244. + .resource = 0,
  3245. + .num_resources = 0,
  3246. + },
  3247. + [6] = {
  3248. + .name = "bcm2835_AUD6",
  3249. + .id = 6, /* seventh audio device */
  3250. + .resource = 0,
  3251. + .num_resources = 0,
  3252. + },
  3253. + [7] = {
  3254. + .name = "bcm2835_AUD7",
  3255. + .id = 7, /* eighth audio device */
  3256. + .resource = 0,
  3257. + .num_resources = 0,
  3258. + },
  3259. +};
  3260. +
  3261. +static struct resource bcm2708_spi_resources[] = {
  3262. + {
  3263. + .start = SPI0_BASE,
  3264. + .end = SPI0_BASE + SZ_256 - 1,
  3265. + .flags = IORESOURCE_MEM,
  3266. + }, {
  3267. + .start = IRQ_SPI,
  3268. + .end = IRQ_SPI,
  3269. + .flags = IORESOURCE_IRQ,
  3270. + }
  3271. +};
  3272. +
  3273. +
  3274. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3275. +static struct platform_device bcm2708_spi_device = {
  3276. + .name = "bcm2708_spi",
  3277. + .id = 0,
  3278. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3279. + .resource = bcm2708_spi_resources,
  3280. + .dev = {
  3281. + .dma_mask = &bcm2708_spi_dmamask,
  3282. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3283. +};
  3284. +
  3285. +#ifdef CONFIG_BCM2708_SPIDEV
  3286. +static struct spi_board_info bcm2708_spi_devices[] = {
  3287. +#ifdef CONFIG_SPI_SPIDEV
  3288. + {
  3289. + .modalias = "spidev",
  3290. + .max_speed_hz = 500000,
  3291. + .bus_num = 0,
  3292. + .chip_select = 0,
  3293. + .mode = SPI_MODE_0,
  3294. + }, {
  3295. + .modalias = "spidev",
  3296. + .max_speed_hz = 500000,
  3297. + .bus_num = 0,
  3298. + .chip_select = 1,
  3299. + .mode = SPI_MODE_0,
  3300. + }
  3301. +#endif
  3302. +};
  3303. +#endif
  3304. +
  3305. +static struct resource bcm2708_bsc0_resources[] = {
  3306. + {
  3307. + .start = BSC0_BASE,
  3308. + .end = BSC0_BASE + SZ_256 - 1,
  3309. + .flags = IORESOURCE_MEM,
  3310. + }, {
  3311. + .start = INTERRUPT_I2C,
  3312. + .end = INTERRUPT_I2C,
  3313. + .flags = IORESOURCE_IRQ,
  3314. + }
  3315. +};
  3316. +
  3317. +static struct platform_device bcm2708_bsc0_device = {
  3318. + .name = "bcm2708_i2c",
  3319. + .id = 0,
  3320. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3321. + .resource = bcm2708_bsc0_resources,
  3322. +};
  3323. +
  3324. +
  3325. +static struct resource bcm2708_bsc1_resources[] = {
  3326. + {
  3327. + .start = BSC1_BASE,
  3328. + .end = BSC1_BASE + SZ_256 - 1,
  3329. + .flags = IORESOURCE_MEM,
  3330. + }, {
  3331. + .start = INTERRUPT_I2C,
  3332. + .end = INTERRUPT_I2C,
  3333. + .flags = IORESOURCE_IRQ,
  3334. + }
  3335. +};
  3336. +
  3337. +static struct platform_device bcm2708_bsc1_device = {
  3338. + .name = "bcm2708_i2c",
  3339. + .id = 1,
  3340. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3341. + .resource = bcm2708_bsc1_resources,
  3342. +};
  3343. +
  3344. +static struct platform_device bcm2835_hwmon_device = {
  3345. + .name = "bcm2835_hwmon",
  3346. +};
  3347. +
  3348. +static struct platform_device bcm2835_thermal_device = {
  3349. + .name = "bcm2835_thermal",
  3350. +};
  3351. +
  3352. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3353. +static struct resource bcm2708_i2s_resources[] = {
  3354. + {
  3355. + .start = I2S_BASE,
  3356. + .end = I2S_BASE + 0x20,
  3357. + .flags = IORESOURCE_MEM,
  3358. + },
  3359. + {
  3360. + .start = PCM_CLOCK_BASE,
  3361. + .end = PCM_CLOCK_BASE + 0x02,
  3362. + .flags = IORESOURCE_MEM,
  3363. + }
  3364. +};
  3365. +
  3366. +static struct platform_device bcm2708_i2s_device = {
  3367. + .name = "bcm2708-i2s",
  3368. + .id = 0,
  3369. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3370. + .resource = bcm2708_i2s_resources,
  3371. +};
  3372. +#endif
  3373. +
  3374. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3375. +static struct platform_device snd_hifiberry_dac_device = {
  3376. + .name = "snd-hifiberry-dac",
  3377. + .id = 0,
  3378. + .num_resources = 0,
  3379. +};
  3380. +
  3381. +static struct platform_device snd_pcm5102a_codec_device = {
  3382. + .name = "pcm5102a-codec",
  3383. + .id = -1,
  3384. + .num_resources = 0,
  3385. +};
  3386. +#endif
  3387. +
  3388. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3389. +static struct platform_device snd_hifiberry_digi_device = {
  3390. + .name = "snd-hifiberry-digi",
  3391. + .id = 0,
  3392. + .num_resources = 0,
  3393. +};
  3394. +
  3395. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3396. + {
  3397. + I2C_BOARD_INFO("wm8804", 0x3b)
  3398. + },
  3399. +};
  3400. +
  3401. +#endif
  3402. +
  3403. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3404. +static struct platform_device snd_rpi_dac_device = {
  3405. + .name = "snd-rpi-dac",
  3406. + .id = 0,
  3407. + .num_resources = 0,
  3408. +};
  3409. +
  3410. +static struct platform_device snd_pcm1794a_codec_device = {
  3411. + .name = "pcm1794a-codec",
  3412. + .id = -1,
  3413. + .num_resources = 0,
  3414. +};
  3415. +#endif
  3416. +
  3417. +int __init bcm_register_device(struct platform_device *pdev)
  3418. +{
  3419. + int ret;
  3420. +
  3421. + ret = platform_device_register(pdev);
  3422. + if (ret)
  3423. + pr_debug("Unable to register platform device '%s': %d\n",
  3424. + pdev->name, ret);
  3425. +
  3426. + return ret;
  3427. +}
  3428. +
  3429. +int calc_rsts(int partition)
  3430. +{
  3431. + return PM_PASSWORD |
  3432. + ((partition & (1 << 0)) << 0) |
  3433. + ((partition & (1 << 1)) << 1) |
  3434. + ((partition & (1 << 2)) << 2) |
  3435. + ((partition & (1 << 3)) << 3) |
  3436. + ((partition & (1 << 4)) << 4) |
  3437. + ((partition & (1 << 5)) << 5);
  3438. +}
  3439. +
  3440. +static void bcm2708_restart(char mode, const char *cmd)
  3441. +{
  3442. + uint32_t pm_rstc, pm_wdog;
  3443. + uint32_t timeout = 10;
  3444. + uint32_t pm_rsts = 0;
  3445. +
  3446. + if(mode == 'q')
  3447. + {
  3448. + // NOOBS < 1.3 booting with reboot=q
  3449. + pm_rsts = readl(__io_address(PM_RSTS));
  3450. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3451. + }
  3452. + else if(mode == 'p')
  3453. + {
  3454. + // NOOBS < 1.3 halting
  3455. + pm_rsts = readl(__io_address(PM_RSTS));
  3456. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3457. + }
  3458. + else
  3459. + {
  3460. + pm_rsts = calc_rsts(reboot_part);
  3461. + }
  3462. +
  3463. + writel(pm_rsts, __io_address(PM_RSTS));
  3464. +
  3465. + /* Setup watchdog for reset */
  3466. + pm_rstc = readl(__io_address(PM_RSTC));
  3467. +
  3468. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3469. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3470. +
  3471. + writel(pm_wdog, __io_address(PM_WDOG));
  3472. + writel(pm_rstc, __io_address(PM_RSTC));
  3473. +}
  3474. +
  3475. +/* We can't really power off, but if we do the normal reset scheme, and indicate to bootcode.bin not to reboot, then most of the chip will be powered off */
  3476. +static void bcm2708_power_off(void)
  3477. +{
  3478. + extern char reboot_mode;
  3479. +
  3480. + if(reboot_mode == 'q')
  3481. + {
  3482. + // NOOBS < v1.3
  3483. + bcm2708_restart('p', "");
  3484. + }
  3485. + else
  3486. + {
  3487. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3488. + reboot_part = 63;
  3489. + /* continue with normal reset mechanism */
  3490. + bcm2708_restart(0, "");
  3491. + }
  3492. +}
  3493. +
  3494. +void __init bcm2708_init(void)
  3495. +{
  3496. + int i;
  3497. +
  3498. +#if defined(CONFIG_BCM_VC_CMA)
  3499. + vc_cma_early_init();
  3500. +#endif
  3501. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3502. + pm_power_off = bcm2708_power_off;
  3503. +
  3504. + if (uart_clock)
  3505. + lookups[0].clk->rate = uart_clock;
  3506. +
  3507. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3508. + clkdev_add(&lookups[i]);
  3509. +
  3510. + bcm_register_device(&bcm2708_dmaman_device);
  3511. + bcm_register_device(&bcm2708_vcio_device);
  3512. +#ifdef CONFIG_BCM2708_GPIO
  3513. + bcm_register_device(&bcm2708_gpio_device);
  3514. +#endif
  3515. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3516. + w1_gpio_pdata.pin = w1_gpio_pin;
  3517. + platform_device_register(&w1_device);
  3518. +#endif
  3519. + bcm_register_device(&bcm2708_systemtimer_device);
  3520. + bcm_register_device(&bcm2708_fb_device);
  3521. + if (!fiq_fix_enable)
  3522. + {
  3523. + bcm2708_usb_device.resource = bcm2708_usb_resources_no_fiq_fix;
  3524. + bcm2708_usb_device.num_resources = ARRAY_SIZE(bcm2708_usb_resources_no_fiq_fix);
  3525. + }
  3526. + bcm_register_device(&bcm2708_usb_device);
  3527. + bcm_register_device(&bcm2708_uart1_device);
  3528. + bcm_register_device(&bcm2708_powerman_device);
  3529. +
  3530. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3531. + bcm_register_device(&bcm2708_emmc_device);
  3532. +#endif
  3533. + bcm2708_init_led();
  3534. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3535. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3536. +
  3537. + bcm_register_device(&bcm2708_spi_device);
  3538. + bcm_register_device(&bcm2708_bsc0_device);
  3539. + bcm_register_device(&bcm2708_bsc1_device);
  3540. +
  3541. + bcm_register_device(&bcm2835_hwmon_device);
  3542. + bcm_register_device(&bcm2835_thermal_device);
  3543. +
  3544. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3545. + bcm_register_device(&bcm2708_i2s_device);
  3546. +#endif
  3547. +
  3548. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3549. + bcm_register_device(&snd_hifiberry_dac_device);
  3550. + bcm_register_device(&snd_pcm5102a_codec_device);
  3551. +#endif
  3552. +
  3553. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3554. + bcm_register_device(&snd_hifiberry_digi_device);
  3555. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3556. +#endif
  3557. +
  3558. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3559. + bcm_register_device(&snd_rpi_dac_device);
  3560. + bcm_register_device(&snd_pcm1794a_codec_device);
  3561. +#endif
  3562. +
  3563. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3564. + struct amba_device *d = amba_devs[i];
  3565. + amba_device_register(d, &iomem_resource);
  3566. + }
  3567. + system_rev = boardrev;
  3568. + system_serial_low = serial;
  3569. +
  3570. +#ifdef CONFIG_BCM2708_SPIDEV
  3571. + spi_register_board_info(bcm2708_spi_devices,
  3572. + ARRAY_SIZE(bcm2708_spi_devices));
  3573. +#endif
  3574. +}
  3575. +
  3576. +static void timer_set_mode(enum clock_event_mode mode,
  3577. + struct clock_event_device *clk)
  3578. +{
  3579. + switch (mode) {
  3580. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3581. + case CLOCK_EVT_MODE_SHUTDOWN:
  3582. + break;
  3583. + case CLOCK_EVT_MODE_PERIODIC:
  3584. +
  3585. + case CLOCK_EVT_MODE_UNUSED:
  3586. + case CLOCK_EVT_MODE_RESUME:
  3587. +
  3588. + default:
  3589. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3590. + (int)mode);
  3591. + break;
  3592. + }
  3593. +
  3594. +}
  3595. +
  3596. +static int timer_set_next_event(unsigned long cycles,
  3597. + struct clock_event_device *unused)
  3598. +{
  3599. + unsigned long stc;
  3600. +
  3601. + stc = readl(__io_address(ST_BASE + 0x04));
  3602. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3603. + return 0;
  3604. +}
  3605. +
  3606. +static struct clock_event_device timer0_clockevent = {
  3607. + .name = "timer0",
  3608. + .shift = 32,
  3609. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3610. + .set_mode = timer_set_mode,
  3611. + .set_next_event = timer_set_next_event,
  3612. +};
  3613. +
  3614. +/*
  3615. + * IRQ handler for the timer
  3616. + */
  3617. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3618. +{
  3619. + struct clock_event_device *evt = &timer0_clockevent;
  3620. +
  3621. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3622. +
  3623. + evt->event_handler(evt);
  3624. +
  3625. + return IRQ_HANDLED;
  3626. +}
  3627. +
  3628. +static struct irqaction bcm2708_timer_irq = {
  3629. + .name = "BCM2708 Timer Tick",
  3630. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3631. + .handler = bcm2708_timer_interrupt,
  3632. +};
  3633. +
  3634. +/*
  3635. + * Set up timer interrupt, and return the current time in seconds.
  3636. + */
  3637. +
  3638. +static struct delay_timer bcm2708_delay_timer = {
  3639. + .read_current_timer = bcm2708_read_current_timer,
  3640. + .freq = STC_FREQ_HZ,
  3641. +};
  3642. +
  3643. +static void __init bcm2708_timer_init(void)
  3644. +{
  3645. + /* init high res timer */
  3646. + bcm2708_clocksource_init();
  3647. +
  3648. + /*
  3649. + * Initialise to a known state (all timers off)
  3650. + */
  3651. + writel(0, __io_address(ARM_T_CONTROL));
  3652. + /*
  3653. + * Make irqs happen for the system timer
  3654. + */
  3655. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3656. +
  3657. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3658. +
  3659. + timer0_clockevent.mult =
  3660. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3661. + timer0_clockevent.max_delta_ns =
  3662. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3663. + timer0_clockevent.min_delta_ns =
  3664. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3665. +
  3666. + timer0_clockevent.cpumask = cpumask_of(0);
  3667. + clockevents_register_device(&timer0_clockevent);
  3668. +
  3669. + register_current_timer_delay(&bcm2708_delay_timer);
  3670. +}
  3671. +
  3672. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3673. +#include <linux/leds.h>
  3674. +
  3675. +static struct gpio_led bcm2708_leds[] = {
  3676. + [0] = {
  3677. + .gpio = 16,
  3678. + .name = "led0",
  3679. + .default_trigger = "mmc0",
  3680. + .active_low = 1,
  3681. + },
  3682. +};
  3683. +
  3684. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3685. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3686. + .leds = bcm2708_leds,
  3687. +};
  3688. +
  3689. +static struct platform_device bcm2708_led_device = {
  3690. + .name = "leds-gpio",
  3691. + .id = -1,
  3692. + .dev = {
  3693. + .platform_data = &bcm2708_led_pdata,
  3694. + },
  3695. +};
  3696. +
  3697. +static void __init bcm2708_init_led(void)
  3698. +{
  3699. + bcm2708_leds[0].gpio = disk_led_gpio;
  3700. + bcm2708_leds[0].active_low = disk_led_active_low;
  3701. + platform_device_register(&bcm2708_led_device);
  3702. +}
  3703. +#else
  3704. +static inline void bcm2708_init_led(void)
  3705. +{
  3706. +}
  3707. +#endif
  3708. +
  3709. +void __init bcm2708_init_early(void)
  3710. +{
  3711. + /*
  3712. + * Some devices allocate their coherent buffers from atomic
  3713. + * context. Increase size of atomic coherent pool to make sure such
  3714. + * the allocations won't fail.
  3715. + */
  3716. + init_dma_coherent_pool_size(SZ_4M);
  3717. +}
  3718. +
  3719. +static void __init board_reserve(void)
  3720. +{
  3721. +#if defined(CONFIG_BCM_VC_CMA)
  3722. + vc_cma_reserve();
  3723. +#endif
  3724. +}
  3725. +
  3726. +MACHINE_START(BCM2708, "BCM2708")
  3727. + /* Maintainer: Broadcom Europe Ltd. */
  3728. + .map_io = bcm2708_map_io,
  3729. + .init_irq = bcm2708_init_irq,
  3730. + .init_time = bcm2708_timer_init,
  3731. + .init_machine = bcm2708_init,
  3732. + .init_early = bcm2708_init_early,
  3733. + .restart = bcm2708_restart,
  3734. + .reserve = board_reserve,
  3735. +MACHINE_END
  3736. +
  3737. +module_param(boardrev, uint, 0644);
  3738. +module_param(serial, uint, 0644);
  3739. +module_param(uart_clock, uint, 0644);
  3740. +module_param(disk_led_gpio, uint, 0644);
  3741. +module_param(disk_led_active_low, uint, 0644);
  3742. +module_param(reboot_part, uint, 0644);
  3743. +module_param(w1_gpio_pin, uint, 0644);
  3744. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-raspberry-pi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3745. --- linux-3.10.33/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3746. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-03-13 12:46:12.432043725 +0100
  3747. @@ -0,0 +1,361 @@
  3748. +/*
  3749. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3750. + *
  3751. + * Copyright (C) 2010 Broadcom
  3752. + *
  3753. + * This program is free software; you can redistribute it and/or modify
  3754. + * it under the terms of the GNU General Public License version 2 as
  3755. + * published by the Free Software Foundation.
  3756. + *
  3757. + */
  3758. +
  3759. +#include <linux/spinlock.h>
  3760. +#include <linux/module.h>
  3761. +#include <linux/list.h>
  3762. +#include <linux/io.h>
  3763. +#include <linux/irq.h>
  3764. +#include <linux/interrupt.h>
  3765. +#include <linux/slab.h>
  3766. +#include <mach/gpio.h>
  3767. +#include <linux/gpio.h>
  3768. +#include <linux/platform_device.h>
  3769. +#include <mach/platform.h>
  3770. +
  3771. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3772. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3773. +#define BCM_GPIO_USE_IRQ 1
  3774. +
  3775. +#define GPIOFSEL(x) (0x00+(x)*4)
  3776. +#define GPIOSET(x) (0x1c+(x)*4)
  3777. +#define GPIOCLR(x) (0x28+(x)*4)
  3778. +#define GPIOLEV(x) (0x34+(x)*4)
  3779. +#define GPIOEDS(x) (0x40+(x)*4)
  3780. +#define GPIOREN(x) (0x4c+(x)*4)
  3781. +#define GPIOFEN(x) (0x58+(x)*4)
  3782. +#define GPIOHEN(x) (0x64+(x)*4)
  3783. +#define GPIOLEN(x) (0x70+(x)*4)
  3784. +#define GPIOAREN(x) (0x7c+(x)*4)
  3785. +#define GPIOAFEN(x) (0x88+(x)*4)
  3786. +#define GPIOUD(x) (0x94+(x)*4)
  3787. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3788. +
  3789. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3790. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3791. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3792. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3793. +};
  3794. +
  3795. + /* Each of the two spinlocks protects a different set of hardware
  3796. + * regiters and data structurs. This decouples the code of the IRQ from
  3797. + * the GPIO code. This also makes the case of a GPIO routine call from
  3798. + * the IRQ code simpler.
  3799. + */
  3800. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3801. +
  3802. +struct bcm2708_gpio {
  3803. + struct list_head list;
  3804. + void __iomem *base;
  3805. + struct gpio_chip gc;
  3806. + unsigned long rising;
  3807. + unsigned long falling;
  3808. + unsigned long high;
  3809. + unsigned long low;
  3810. +};
  3811. +
  3812. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3813. + int function)
  3814. +{
  3815. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3816. + unsigned long flags;
  3817. + unsigned gpiodir;
  3818. + unsigned gpio_bank = offset / 10;
  3819. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3820. +
  3821. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3822. + if (offset >= ARCH_NR_GPIOS)
  3823. + return -EINVAL;
  3824. +
  3825. + spin_lock_irqsave(&lock, flags);
  3826. +
  3827. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3828. + gpiodir &= ~(7 << gpio_field_offset);
  3829. + gpiodir |= function << gpio_field_offset;
  3830. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3831. + spin_unlock_irqrestore(&lock, flags);
  3832. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3833. +
  3834. + return 0;
  3835. +}
  3836. +
  3837. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3838. +{
  3839. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3840. +}
  3841. +
  3842. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3843. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3844. + int value)
  3845. +{
  3846. + int ret;
  3847. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3848. + if (ret >= 0)
  3849. + bcm2708_gpio_set(gc, offset, value);
  3850. + return ret;
  3851. +}
  3852. +
  3853. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3854. +{
  3855. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3856. + unsigned gpio_bank = offset / 32;
  3857. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3858. + unsigned lev;
  3859. +
  3860. + if (offset >= ARCH_NR_GPIOS)
  3861. + return 0;
  3862. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3863. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3864. + return 0x1 & (lev >> gpio_field_offset);
  3865. +}
  3866. +
  3867. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3868. +{
  3869. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3870. + unsigned gpio_bank = offset / 32;
  3871. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3872. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3873. + if (offset >= ARCH_NR_GPIOS)
  3874. + return;
  3875. + if (value)
  3876. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3877. + else
  3878. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3879. +}
  3880. +
  3881. +/*************************************************************************************************************************
  3882. + * bcm2708 GPIO IRQ
  3883. + */
  3884. +
  3885. +#if BCM_GPIO_USE_IRQ
  3886. +
  3887. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3888. +{
  3889. + return gpio_to_irq(gpio);
  3890. +}
  3891. +
  3892. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3893. +{
  3894. + unsigned irq = d->irq;
  3895. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3896. +
  3897. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3898. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3899. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3900. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3901. +
  3902. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3903. + return -EINVAL;
  3904. +
  3905. + if (type & IRQ_TYPE_EDGE_RISING)
  3906. + gpio->rising |= (1 << irq_to_gpio(irq));
  3907. + if (type & IRQ_TYPE_EDGE_FALLING)
  3908. + gpio->falling |= (1 << irq_to_gpio(irq));
  3909. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3910. + gpio->high |= (1 << irq_to_gpio(irq));
  3911. + if (type & IRQ_TYPE_LEVEL_LOW)
  3912. + gpio->low |= (1 << irq_to_gpio(irq));
  3913. + return 0;
  3914. +}
  3915. +
  3916. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3917. +{
  3918. + unsigned irq = d->irq;
  3919. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3920. + unsigned gn = irq_to_gpio(irq);
  3921. + unsigned gb = gn / 32;
  3922. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3923. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3924. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3925. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3926. +
  3927. + gn = gn % 32;
  3928. +
  3929. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3930. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3931. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3932. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3933. +}
  3934. +
  3935. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3936. +{
  3937. + unsigned irq = d->irq;
  3938. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3939. + unsigned gn = irq_to_gpio(irq);
  3940. + unsigned gb = gn / 32;
  3941. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3942. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3943. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3944. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3945. +
  3946. + gn = gn % 32;
  3947. +
  3948. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3949. +
  3950. + if (gpio->rising & (1 << gn)) {
  3951. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3952. + } else {
  3953. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3954. + }
  3955. +
  3956. + if (gpio->falling & (1 << gn)) {
  3957. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3958. + } else {
  3959. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3960. + }
  3961. +
  3962. + if (gpio->high & (1 << gn)) {
  3963. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  3964. + } else {
  3965. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3966. + }
  3967. +
  3968. + if (gpio->low & (1 << gn)) {
  3969. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  3970. + } else {
  3971. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3972. + }
  3973. +}
  3974. +
  3975. +static struct irq_chip bcm2708_irqchip = {
  3976. + .name = "GPIO",
  3977. + .irq_enable = bcm2708_gpio_irq_unmask,
  3978. + .irq_disable = bcm2708_gpio_irq_mask,
  3979. + .irq_unmask = bcm2708_gpio_irq_unmask,
  3980. + .irq_mask = bcm2708_gpio_irq_mask,
  3981. + .irq_set_type = bcm2708_gpio_irq_set_type,
  3982. +};
  3983. +
  3984. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  3985. +{
  3986. + unsigned long edsr;
  3987. + unsigned bank;
  3988. + int i;
  3989. + unsigned gpio;
  3990. + for (bank = 0; bank <= 1; bank++) {
  3991. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  3992. + for_each_set_bit(i, &edsr, 32) {
  3993. + gpio = i + bank * 32;
  3994. + generic_handle_irq(gpio_to_irq(gpio));
  3995. + }
  3996. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  3997. + }
  3998. + return IRQ_HANDLED;
  3999. +}
  4000. +
  4001. +static struct irqaction bcm2708_gpio_irq = {
  4002. + .name = "BCM2708 GPIO catchall handler",
  4003. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  4004. + .handler = bcm2708_gpio_interrupt,
  4005. +};
  4006. +
  4007. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4008. +{
  4009. + unsigned irq;
  4010. +
  4011. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  4012. +
  4013. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  4014. + irq_set_chip_data(irq, ucb);
  4015. + irq_set_chip(irq, &bcm2708_irqchip);
  4016. + set_irq_flags(irq, IRQF_VALID);
  4017. + }
  4018. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  4019. +}
  4020. +
  4021. +#else
  4022. +
  4023. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4024. +{
  4025. +}
  4026. +
  4027. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4028. +
  4029. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4030. +{
  4031. + struct bcm2708_gpio *ucb;
  4032. + struct resource *res;
  4033. + int err = 0;
  4034. +
  4035. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4036. +
  4037. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4038. + if (NULL == ucb) {
  4039. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4040. + "mailbox memory\n");
  4041. + err = -ENOMEM;
  4042. + goto err;
  4043. + }
  4044. +
  4045. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4046. +
  4047. + platform_set_drvdata(dev, ucb);
  4048. + ucb->base = __io_address(GPIO_BASE);
  4049. +
  4050. + ucb->gc.label = "bcm2708_gpio";
  4051. + ucb->gc.base = 0;
  4052. + ucb->gc.ngpio = ARCH_NR_GPIOS;
  4053. + ucb->gc.owner = THIS_MODULE;
  4054. +
  4055. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4056. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4057. + ucb->gc.get = bcm2708_gpio_get;
  4058. + ucb->gc.set = bcm2708_gpio_set;
  4059. + ucb->gc.can_sleep = 0;
  4060. +
  4061. + bcm2708_gpio_irq_init(ucb);
  4062. +
  4063. + err = gpiochip_add(&ucb->gc);
  4064. + if (err)
  4065. + goto err;
  4066. +
  4067. +err:
  4068. + return err;
  4069. +
  4070. +}
  4071. +
  4072. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4073. +{
  4074. + int err = 0;
  4075. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4076. +
  4077. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4078. +
  4079. + err = gpiochip_remove(&ucb->gc);
  4080. +
  4081. + platform_set_drvdata(dev, NULL);
  4082. + kfree(ucb);
  4083. +
  4084. + return err;
  4085. +}
  4086. +
  4087. +static struct platform_driver bcm2708_gpio_driver = {
  4088. + .probe = bcm2708_gpio_probe,
  4089. + .remove = bcm2708_gpio_remove,
  4090. + .driver = {
  4091. + .name = "bcm2708_gpio"},
  4092. +};
  4093. +
  4094. +static int __init bcm2708_gpio_init(void)
  4095. +{
  4096. + return platform_driver_register(&bcm2708_gpio_driver);
  4097. +}
  4098. +
  4099. +static void __exit bcm2708_gpio_exit(void)
  4100. +{
  4101. + platform_driver_unregister(&bcm2708_gpio_driver);
  4102. +}
  4103. +
  4104. +module_init(bcm2708_gpio_init);
  4105. +module_exit(bcm2708_gpio_exit);
  4106. +
  4107. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4108. +MODULE_LICENSE("GPL");
  4109. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/bcm2708.h linux-raspberry-pi/arch/arm/mach-bcm2708/bcm2708.h
  4110. --- linux-3.10.33/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4111. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/bcm2708.h 2014-03-13 12:46:12.432043725 +0100
  4112. @@ -0,0 +1,51 @@
  4113. +/*
  4114. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4115. + *
  4116. + * BCM2708 machine support header
  4117. + *
  4118. + * Copyright (C) 2010 Broadcom
  4119. + *
  4120. + * This program is free software; you can redistribute it and/or modify
  4121. + * it under the terms of the GNU General Public License as published by
  4122. + * the Free Software Foundation; either version 2 of the License, or
  4123. + * (at your option) any later version.
  4124. + *
  4125. + * This program is distributed in the hope that it will be useful,
  4126. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4127. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4128. + * GNU General Public License for more details.
  4129. + *
  4130. + * You should have received a copy of the GNU General Public License
  4131. + * along with this program; if not, write to the Free Software
  4132. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4133. + */
  4134. +
  4135. +#ifndef __BCM2708_BCM2708_H
  4136. +#define __BCM2708_BCM2708_H
  4137. +
  4138. +#include <linux/amba/bus.h>
  4139. +
  4140. +extern void __init bcm2708_init(void);
  4141. +extern void __init bcm2708_init_irq(void);
  4142. +extern void __init bcm2708_map_io(void);
  4143. +extern struct sys_timer bcm2708_timer;
  4144. +extern unsigned int mmc_status(struct device *dev);
  4145. +
  4146. +#define AMBA_DEVICE(name, busid, base, plat) \
  4147. +static struct amba_device name##_device = { \
  4148. + .dev = { \
  4149. + .coherent_dma_mask = ~0, \
  4150. + .init_name = busid, \
  4151. + .platform_data = plat, \
  4152. + }, \
  4153. + .res = { \
  4154. + .start = base##_BASE, \
  4155. + .end = (base##_BASE) + SZ_4K - 1,\
  4156. + .flags = IORESOURCE_MEM, \
  4157. + }, \
  4158. + .dma_mask = ~0, \
  4159. + .irq = base##_IRQ, \
  4160. + /* .dma = base##_DMA,*/ \
  4161. +}
  4162. +
  4163. +#endif
  4164. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/clock.c linux-raspberry-pi/arch/arm/mach-bcm2708/clock.c
  4165. --- linux-3.10.33/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4166. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/clock.c 2014-03-13 12:46:12.432043725 +0100
  4167. @@ -0,0 +1,61 @@
  4168. +/*
  4169. + * linux/arch/arm/mach-bcm2708/clock.c
  4170. + *
  4171. + * Copyright (C) 2010 Broadcom
  4172. + *
  4173. + * This program is free software; you can redistribute it and/or modify
  4174. + * it under the terms of the GNU General Public License as published by
  4175. + * the Free Software Foundation; either version 2 of the License, or
  4176. + * (at your option) any later version.
  4177. + *
  4178. + * This program is distributed in the hope that it will be useful,
  4179. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4180. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4181. + * GNU General Public License for more details.
  4182. + *
  4183. + * You should have received a copy of the GNU General Public License
  4184. + * along with this program; if not, write to the Free Software
  4185. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4186. + */
  4187. +#include <linux/module.h>
  4188. +#include <linux/kernel.h>
  4189. +#include <linux/device.h>
  4190. +#include <linux/list.h>
  4191. +#include <linux/errno.h>
  4192. +#include <linux/err.h>
  4193. +#include <linux/string.h>
  4194. +#include <linux/clk.h>
  4195. +#include <linux/mutex.h>
  4196. +
  4197. +#include <asm/clkdev.h>
  4198. +
  4199. +#include "clock.h"
  4200. +
  4201. +int clk_enable(struct clk *clk)
  4202. +{
  4203. + return 0;
  4204. +}
  4205. +EXPORT_SYMBOL(clk_enable);
  4206. +
  4207. +void clk_disable(struct clk *clk)
  4208. +{
  4209. +}
  4210. +EXPORT_SYMBOL(clk_disable);
  4211. +
  4212. +unsigned long clk_get_rate(struct clk *clk)
  4213. +{
  4214. + return clk->rate;
  4215. +}
  4216. +EXPORT_SYMBOL(clk_get_rate);
  4217. +
  4218. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4219. +{
  4220. + return clk->rate;
  4221. +}
  4222. +EXPORT_SYMBOL(clk_round_rate);
  4223. +
  4224. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4225. +{
  4226. + return -EIO;
  4227. +}
  4228. +EXPORT_SYMBOL(clk_set_rate);
  4229. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/clock.h linux-raspberry-pi/arch/arm/mach-bcm2708/clock.h
  4230. --- linux-3.10.33/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4231. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/clock.h 2014-03-13 12:46:12.432043725 +0100
  4232. @@ -0,0 +1,24 @@
  4233. +/*
  4234. + * linux/arch/arm/mach-bcm2708/clock.h
  4235. + *
  4236. + * Copyright (C) 2010 Broadcom
  4237. + *
  4238. + * This program is free software; you can redistribute it and/or modify
  4239. + * it under the terms of the GNU General Public License as published by
  4240. + * the Free Software Foundation; either version 2 of the License, or
  4241. + * (at your option) any later version.
  4242. + *
  4243. + * This program is distributed in the hope that it will be useful,
  4244. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4245. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4246. + * GNU General Public License for more details.
  4247. + *
  4248. + * You should have received a copy of the GNU General Public License
  4249. + * along with this program; if not, write to the Free Software
  4250. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4251. + */
  4252. +struct module;
  4253. +
  4254. +struct clk {
  4255. + unsigned long rate;
  4256. +};
  4257. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/dma.c linux-raspberry-pi/arch/arm/mach-bcm2708/dma.c
  4258. --- linux-3.10.33/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4259. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/dma.c 2014-03-13 12:46:12.432043725 +0100
  4260. @@ -0,0 +1,407 @@
  4261. +/*
  4262. + * linux/arch/arm/mach-bcm2708/dma.c
  4263. + *
  4264. + * Copyright (C) 2010 Broadcom
  4265. + *
  4266. + * This program is free software; you can redistribute it and/or modify
  4267. + * it under the terms of the GNU General Public License version 2 as
  4268. + * published by the Free Software Foundation.
  4269. + */
  4270. +
  4271. +#include <linux/slab.h>
  4272. +#include <linux/device.h>
  4273. +#include <linux/platform_device.h>
  4274. +#include <linux/module.h>
  4275. +#include <linux/scatterlist.h>
  4276. +
  4277. +#include <mach/dma.h>
  4278. +#include <mach/irqs.h>
  4279. +
  4280. +/*****************************************************************************\
  4281. + * *
  4282. + * Configuration *
  4283. + * *
  4284. +\*****************************************************************************/
  4285. +
  4286. +#define CACHE_LINE_MASK 31
  4287. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4288. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4289. +
  4290. +/* valid only for channels 0 - 14, 15 has its own base address */
  4291. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4292. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4293. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4294. +
  4295. +
  4296. +/*****************************************************************************\
  4297. + * *
  4298. + * DMA Auxilliary Functions *
  4299. + * *
  4300. +\*****************************************************************************/
  4301. +
  4302. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4303. + section inside the DMA buffer and another section outside it.
  4304. + Even if we flush DMA buffers from the cache there is always the chance that
  4305. + during a DMA someone will access the part of a cache line that is outside
  4306. + the DMA buffer - which will then bring in unwelcome data.
  4307. + Without being able to dictate our own buffer pools we must insist that
  4308. + DMA buffers consist of a whole number of cache lines.
  4309. +*/
  4310. +
  4311. +extern int
  4312. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4313. +{
  4314. + int i;
  4315. +
  4316. + for (i = 0; i < sg_len; i++) {
  4317. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4318. + sg_ptr[i].length & CACHE_LINE_MASK)
  4319. + return 0;
  4320. + }
  4321. +
  4322. + return 1;
  4323. +}
  4324. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4325. +
  4326. +extern void
  4327. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4328. +{
  4329. + dsb(); /* ARM data synchronization (push) operation */
  4330. +
  4331. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4332. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4333. +}
  4334. +
  4335. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4336. +{
  4337. + dsb();
  4338. +
  4339. + /* ugly busy wait only option for now */
  4340. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4341. + cpu_relax();
  4342. +}
  4343. +
  4344. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4345. +
  4346. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4347. +{
  4348. + dsb();
  4349. +
  4350. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4351. +}
  4352. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4353. +
  4354. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4355. + Does nothing if there is no DMA in progress.
  4356. + This routine waits for the current AXI transfer to complete before
  4357. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4358. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4359. + case the routine times out and return a non-zero error code.
  4360. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4361. + does not produce an interrupt.
  4362. +*/
  4363. +extern int
  4364. +bcm_dma_abort(void __iomem *dma_chan_base)
  4365. +{
  4366. + unsigned long int cs;
  4367. + int rc = 0;
  4368. +
  4369. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4370. +
  4371. + if (BCM2708_DMA_ACTIVE & cs) {
  4372. + long int timeout = 10000;
  4373. +
  4374. + /* write 0 to the active bit - pause the DMA */
  4375. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4376. +
  4377. + /* wait for any current AXI transfer to complete */
  4378. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4379. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4380. +
  4381. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4382. + /* we'll un-pause when we set of our next DMA */
  4383. + rc = -ETIMEDOUT;
  4384. +
  4385. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4386. + /* terminate the control block chain */
  4387. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4388. +
  4389. + /* abort the whole DMA */
  4390. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4391. + dma_chan_base + BCM2708_DMA_CS);
  4392. + }
  4393. + }
  4394. +
  4395. + return rc;
  4396. +}
  4397. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4398. +
  4399. +
  4400. +/***************************************************************************** \
  4401. + * *
  4402. + * DMA Manager Device Methods *
  4403. + * *
  4404. +\*****************************************************************************/
  4405. +
  4406. +struct vc_dmaman {
  4407. + void __iomem *dma_base;
  4408. + u32 chan_available; /* bitmap of available channels */
  4409. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4410. +};
  4411. +
  4412. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4413. + u32 chans_available)
  4414. +{
  4415. + dmaman->dma_base = dma_base;
  4416. + dmaman->chan_available = chans_available;
  4417. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4418. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4419. +}
  4420. +
  4421. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4422. + unsigned preferred_feature_set)
  4423. +{
  4424. + u32 chans;
  4425. + int feature;
  4426. +
  4427. + chans = dmaman->chan_available;
  4428. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4429. + /* select the subset of available channels with the desired
  4430. + feature so long as some of the candidate channels have that
  4431. + feature */
  4432. + if ((preferred_feature_set & (1 << feature)) &&
  4433. + (chans & dmaman->has_feature[feature]))
  4434. + chans &= dmaman->has_feature[feature];
  4435. +
  4436. + if (chans) {
  4437. + int chan = 0;
  4438. + /* return the ordinal of the first channel in the bitmap */
  4439. + while (chans != 0 && (chans & 1) == 0) {
  4440. + chans >>= 1;
  4441. + chan++;
  4442. + }
  4443. + /* claim the channel */
  4444. + dmaman->chan_available &= ~(1 << chan);
  4445. + return chan;
  4446. + } else
  4447. + return -ENOMEM;
  4448. +}
  4449. +
  4450. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4451. +{
  4452. + if (chan < 0)
  4453. + return -EINVAL;
  4454. + else if ((1 << chan) & dmaman->chan_available)
  4455. + return -EIDRM;
  4456. + else {
  4457. + dmaman->chan_available |= (1 << chan);
  4458. + return 0;
  4459. + }
  4460. +}
  4461. +
  4462. +/*****************************************************************************\
  4463. + * *
  4464. + * DMA IRQs *
  4465. + * *
  4466. +\*****************************************************************************/
  4467. +
  4468. +static unsigned char bcm_dma_irqs[] = {
  4469. + IRQ_DMA0,
  4470. + IRQ_DMA1,
  4471. + IRQ_DMA2,
  4472. + IRQ_DMA3,
  4473. + IRQ_DMA4,
  4474. + IRQ_DMA5,
  4475. + IRQ_DMA6,
  4476. + IRQ_DMA7,
  4477. + IRQ_DMA8,
  4478. + IRQ_DMA9,
  4479. + IRQ_DMA10,
  4480. + IRQ_DMA11,
  4481. + IRQ_DMA12
  4482. +};
  4483. +
  4484. +
  4485. +/***************************************************************************** \
  4486. + * *
  4487. + * DMA Manager Monitor *
  4488. + * *
  4489. +\*****************************************************************************/
  4490. +
  4491. +static struct device *dmaman_dev; /* we assume there's only one! */
  4492. +
  4493. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4494. + void __iomem **out_dma_base, int *out_dma_irq)
  4495. +{
  4496. + if (!dmaman_dev)
  4497. + return -ENODEV;
  4498. + else {
  4499. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4500. + int rc;
  4501. +
  4502. + device_lock(dmaman_dev);
  4503. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4504. + if (rc >= 0) {
  4505. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4506. + rc);
  4507. + *out_dma_irq = bcm_dma_irqs[rc];
  4508. + }
  4509. + device_unlock(dmaman_dev);
  4510. +
  4511. + return rc;
  4512. + }
  4513. +}
  4514. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4515. +
  4516. +extern int bcm_dma_chan_free(int channel)
  4517. +{
  4518. + if (dmaman_dev) {
  4519. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4520. + int rc;
  4521. +
  4522. + device_lock(dmaman_dev);
  4523. + rc = vc_dmaman_chan_free(dmaman, channel);
  4524. + device_unlock(dmaman_dev);
  4525. +
  4526. + return rc;
  4527. + } else
  4528. + return -ENODEV;
  4529. +}
  4530. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4531. +
  4532. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4533. +{
  4534. + int rc = dmaman_dev ? -EINVAL : 0;
  4535. + dmaman_dev = dev;
  4536. + return rc;
  4537. +}
  4538. +
  4539. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4540. +{
  4541. + dmaman_dev = NULL;
  4542. +}
  4543. +
  4544. +/*****************************************************************************\
  4545. + * *
  4546. + * DMA Device *
  4547. + * *
  4548. +\*****************************************************************************/
  4549. +
  4550. +static int dmachans = -1; /* module parameter */
  4551. +
  4552. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4553. +{
  4554. + int ret = 0;
  4555. + struct vc_dmaman *dmaman;
  4556. + struct resource *dma_res = NULL;
  4557. + void __iomem *dma_base = NULL;
  4558. + int have_dma_region = 0;
  4559. +
  4560. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4561. + if (NULL == dmaman) {
  4562. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4563. + "DMA management memory\n");
  4564. + ret = -ENOMEM;
  4565. + } else {
  4566. +
  4567. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4568. + if (dma_res == NULL) {
  4569. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4570. + "resource\n");
  4571. + ret = -ENODEV;
  4572. + } else if (!request_mem_region(dma_res->start,
  4573. + resource_size(dma_res),
  4574. + DRIVER_NAME)) {
  4575. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4576. + ret = -EBUSY;
  4577. + } else {
  4578. + have_dma_region = 1;
  4579. + dma_base = ioremap(dma_res->start,
  4580. + resource_size(dma_res));
  4581. + if (!dma_base) {
  4582. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4583. + ret = -ENOMEM;
  4584. + } else {
  4585. + /* use module parameter if one was provided */
  4586. + if (dmachans > 0)
  4587. + vc_dmaman_init(dmaman, dma_base,
  4588. + dmachans);
  4589. + else
  4590. + vc_dmaman_init(dmaman, dma_base,
  4591. + DEFAULT_DMACHAN_BITMAP);
  4592. +
  4593. + platform_set_drvdata(pdev, dmaman);
  4594. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4595. +
  4596. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4597. + "at %p\n", dma_base);
  4598. + }
  4599. + }
  4600. + }
  4601. + if (ret != 0) {
  4602. + if (dma_base)
  4603. + iounmap(dma_base);
  4604. + if (dma_res && have_dma_region)
  4605. + release_mem_region(dma_res->start,
  4606. + resource_size(dma_res));
  4607. + if (dmaman)
  4608. + kfree(dmaman);
  4609. + }
  4610. + return ret;
  4611. +}
  4612. +
  4613. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4614. +{
  4615. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4616. +
  4617. + platform_set_drvdata(pdev, NULL);
  4618. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4619. + kfree(dmaman);
  4620. +
  4621. + return 0;
  4622. +}
  4623. +
  4624. +static struct platform_driver bcm_dmaman_driver = {
  4625. + .probe = bcm_dmaman_probe,
  4626. + .remove = bcm_dmaman_remove,
  4627. +
  4628. + .driver = {
  4629. + .name = DRIVER_NAME,
  4630. + .owner = THIS_MODULE,
  4631. + },
  4632. +};
  4633. +
  4634. +/*****************************************************************************\
  4635. + * *
  4636. + * Driver init/exit *
  4637. + * *
  4638. +\*****************************************************************************/
  4639. +
  4640. +static int __init bcm_dmaman_drv_init(void)
  4641. +{
  4642. + int ret;
  4643. +
  4644. + ret = platform_driver_register(&bcm_dmaman_driver);
  4645. + if (ret != 0) {
  4646. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4647. + "on platform\n");
  4648. + }
  4649. +
  4650. + return ret;
  4651. +}
  4652. +
  4653. +static void __exit bcm_dmaman_drv_exit(void)
  4654. +{
  4655. + platform_driver_unregister(&bcm_dmaman_driver);
  4656. +}
  4657. +
  4658. +module_init(bcm_dmaman_drv_init);
  4659. +module_exit(bcm_dmaman_drv_exit);
  4660. +
  4661. +module_param(dmachans, int, 0644);
  4662. +
  4663. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4664. +MODULE_DESCRIPTION("DMA channel manager driver");
  4665. +MODULE_LICENSE("GPL");
  4666. +
  4667. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4668. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/dmaer.c linux-raspberry-pi/arch/arm/mach-bcm2708/dmaer.c
  4669. --- linux-3.10.33/arch/arm/mach-bcm2708/dmaer.c 1970-01-01 01:00:00.000000000 +0100
  4670. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/dmaer.c 2014-03-13 12:46:12.432043725 +0100
  4671. @@ -0,0 +1,887 @@
  4672. +#include <linux/init.h>
  4673. +#include <linux/sched.h>
  4674. +#include <linux/module.h>
  4675. +#include <linux/types.h>
  4676. +#include <linux/kdev_t.h>
  4677. +#include <linux/fs.h>
  4678. +#include <linux/cdev.h>
  4679. +#include <linux/mm.h>
  4680. +#include <linux/slab.h>
  4681. +#include <linux/pagemap.h>
  4682. +#include <linux/device.h>
  4683. +#include <linux/jiffies.h>
  4684. +#include <linux/timex.h>
  4685. +#include <linux/dma-mapping.h>
  4686. +
  4687. +#include <asm/uaccess.h>
  4688. +#include <asm/atomic.h>
  4689. +#include <asm/cacheflush.h>
  4690. +#include <asm/io.h>
  4691. +
  4692. +#include <mach/dma.h>
  4693. +#include <mach/vc_support.h>
  4694. +
  4695. +#ifdef ECLIPSE_IGNORE
  4696. +
  4697. +#define __user
  4698. +#define __init
  4699. +#define __exit
  4700. +#define __iomem
  4701. +#define KERN_DEBUG
  4702. +#define KERN_ERR
  4703. +#define KERN_WARNING
  4704. +#define KERN_INFO
  4705. +#define _IOWR(a, b, c) b
  4706. +#define _IOW(a, b, c) b
  4707. +#define _IO(a, b) b
  4708. +
  4709. +#endif
  4710. +
  4711. +//#define inline
  4712. +
  4713. +#define PRINTK(args...) printk(args)
  4714. +//#define PRINTK_VERBOSE(args...) printk(args)
  4715. +//#define PRINTK(args...)
  4716. +#define PRINTK_VERBOSE(args...)
  4717. +
  4718. +/***** TYPES ****/
  4719. +#define PAGES_PER_LIST 500
  4720. +struct PageList
  4721. +{
  4722. + struct page *m_pPages[PAGES_PER_LIST];
  4723. + unsigned int m_used;
  4724. + struct PageList *m_pNext;
  4725. +};
  4726. +
  4727. +struct VmaPageList
  4728. +{
  4729. + //each vma has a linked list of pages associated with it
  4730. + struct PageList *m_pPageHead;
  4731. + struct PageList *m_pPageTail;
  4732. + unsigned int m_refCount;
  4733. +};
  4734. +
  4735. +struct DmaControlBlock
  4736. +{
  4737. + unsigned int m_transferInfo;
  4738. + void __user *m_pSourceAddr;
  4739. + void __user *m_pDestAddr;
  4740. + unsigned int m_xferLen;
  4741. + unsigned int m_tdStride;
  4742. + struct DmaControlBlock *m_pNext;
  4743. + unsigned int m_blank1, m_blank2;
  4744. +};
  4745. +
  4746. +/***** DEFINES ******/
  4747. +//magic number defining the module
  4748. +#define DMA_MAGIC 0xdd
  4749. +
  4750. +//do user virtual to physical translation of the CB chain
  4751. +#define DMA_PREPARE _IOWR(DMA_MAGIC, 0, struct DmaControlBlock *)
  4752. +
  4753. +//kick the pre-prepared CB chain
  4754. +#define DMA_KICK _IOW(DMA_MAGIC, 1, struct DmaControlBlock *)
  4755. +
  4756. +//prepare it, kick it, wait for it
  4757. +#define DMA_PREPARE_KICK_WAIT _IOWR(DMA_MAGIC, 2, struct DmaControlBlock *)
  4758. +
  4759. +//prepare it, kick it, don't wait for it
  4760. +#define DMA_PREPARE_KICK _IOWR(DMA_MAGIC, 3, struct DmaControlBlock *)
  4761. +
  4762. +//not currently implemented
  4763. +#define DMA_WAIT_ONE _IO(DMA_MAGIC, 4, struct DmaControlBlock *)
  4764. +
  4765. +//wait on all kicked CB chains
  4766. +#define DMA_WAIT_ALL _IO(DMA_MAGIC, 5)
  4767. +
  4768. +//in order to discover the largest AXI burst that should be programmed into the transfer params
  4769. +#define DMA_MAX_BURST _IO(DMA_MAGIC, 6)
  4770. +
  4771. +//set the address range through which the user address is assumed to already by a physical address
  4772. +#define DMA_SET_MIN_PHYS _IOW(DMA_MAGIC, 7, unsigned long)
  4773. +#define DMA_SET_MAX_PHYS _IOW(DMA_MAGIC, 8, unsigned long)
  4774. +#define DMA_SET_PHYS_OFFSET _IOW(DMA_MAGIC, 9, unsigned long)
  4775. +
  4776. +//used to define the size for the CMA-based allocation *in pages*, can only be done once once the file is opened
  4777. +#define DMA_CMA_SET_SIZE _IOW(DMA_MAGIC, 10, unsigned long)
  4778. +
  4779. +//used to get the version of the module, to test for a capability
  4780. +#define DMA_GET_VERSION _IO(DMA_MAGIC, 99)
  4781. +
  4782. +#define VERSION_NUMBER 1
  4783. +
  4784. +#define VIRT_TO_BUS_CACHE_SIZE 8
  4785. +
  4786. +/***** FILE OPS *****/
  4787. +static int Open(struct inode *pInode, struct file *pFile);
  4788. +static int Release(struct inode *pInode, struct file *pFile);
  4789. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg);
  4790. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp);
  4791. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma);
  4792. +
  4793. +/***** VMA OPS ****/
  4794. +static void VmaOpen4k(struct vm_area_struct *pVma);
  4795. +static void VmaClose4k(struct vm_area_struct *pVma);
  4796. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf);
  4797. +
  4798. +/**** DMA PROTOTYPES */
  4799. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError);
  4800. +static int DmaKick(struct DmaControlBlock __user *pUserCB);
  4801. +static void DmaWaitAll(void);
  4802. +
  4803. +/**** GENERIC ****/
  4804. +static int __init dmaer_init(void);
  4805. +static void __exit dmaer_exit(void);
  4806. +
  4807. +/*** OPS ***/
  4808. +static struct vm_operations_struct g_vmOps4k = {
  4809. + .open = VmaOpen4k,
  4810. + .close = VmaClose4k,
  4811. + .fault = VmaFault4k,
  4812. +};
  4813. +
  4814. +static struct file_operations g_fOps = {
  4815. + .owner = THIS_MODULE,
  4816. + .llseek = 0,
  4817. + .read = Read,
  4818. + .write = 0,
  4819. + .unlocked_ioctl = Ioctl,
  4820. + .open = Open,
  4821. + .release = Release,
  4822. + .mmap = Mmap,
  4823. +};
  4824. +
  4825. +/***** GLOBALS ******/
  4826. +static dev_t g_majorMinor;
  4827. +
  4828. +//tracking usage of the two files
  4829. +static atomic_t g_oneLock4k = ATOMIC_INIT(1);
  4830. +
  4831. +//device operations
  4832. +static struct cdev g_cDev;
  4833. +static int g_trackedPages = 0;
  4834. +
  4835. +//dma control
  4836. +static unsigned int *g_pDmaChanBase;
  4837. +static int g_dmaIrq;
  4838. +static int g_dmaChan;
  4839. +
  4840. +//cma allocation
  4841. +static int g_cmaHandle;
  4842. +
  4843. +//user virtual to bus address translation acceleration
  4844. +static unsigned long g_virtAddr[VIRT_TO_BUS_CACHE_SIZE];
  4845. +static unsigned long g_busAddr[VIRT_TO_BUS_CACHE_SIZE];
  4846. +static unsigned long g_cbVirtAddr;
  4847. +static unsigned long g_cbBusAddr;
  4848. +static int g_cacheInsertAt;
  4849. +static int g_cacheHit, g_cacheMiss;
  4850. +
  4851. +//off by default
  4852. +static void __user *g_pMinPhys;
  4853. +static void __user *g_pMaxPhys;
  4854. +static unsigned long g_physOffset;
  4855. +
  4856. +/****** CACHE OPERATIONS ********/
  4857. +static inline void FlushAddrCache(void)
  4858. +{
  4859. + int count = 0;
  4860. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  4861. + g_virtAddr[count] = 0xffffffff; //never going to match as we always chop the bottom bits anyway
  4862. +
  4863. + g_cbVirtAddr = 0xffffffff;
  4864. +
  4865. + g_cacheInsertAt = 0;
  4866. +}
  4867. +
  4868. +//translate from a user virtual address to a bus address by mapping the page
  4869. +//NB this won't lock a page in memory, so to avoid potential paging issues using kernel logical addresses
  4870. +static inline void __iomem *UserVirtualToBus(void __user *pUser)
  4871. +{
  4872. + int mapped;
  4873. + struct page *pPage;
  4874. + void *phys;
  4875. +
  4876. + //map it (requiring that the pointer points to something that does not hang off the page boundary)
  4877. + mapped = get_user_pages(current, current->mm,
  4878. + (unsigned long)pUser, 1,
  4879. + 1, 0,
  4880. + &pPage,
  4881. + 0);
  4882. +
  4883. + if (mapped <= 0) //error
  4884. + return 0;
  4885. +
  4886. + PRINTK_VERBOSE(KERN_DEBUG "user virtual %p arm phys %p bus %p\n",
  4887. + pUser, page_address(pPage), (void __iomem *)__virt_to_bus(page_address(pPage)));
  4888. +
  4889. + //get the arm physical address
  4890. + phys = page_address(pPage) + offset_in_page(pUser);
  4891. + page_cache_release(pPage);
  4892. +
  4893. + //and now the bus address
  4894. + return (void __iomem *)__virt_to_bus(phys);
  4895. +}
  4896. +
  4897. +static inline void __iomem *UserVirtualToBusViaCbCache(void __user *pUser)
  4898. +{
  4899. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  4900. + unsigned long page_offset = (unsigned long)pUser & 4095;
  4901. + unsigned long bus_addr;
  4902. +
  4903. + if (g_cbVirtAddr == virtual_page)
  4904. + {
  4905. + bus_addr = g_cbBusAddr + page_offset;
  4906. + g_cacheHit++;
  4907. + return (void __iomem *)bus_addr;
  4908. + }
  4909. + else
  4910. + {
  4911. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  4912. +
  4913. + if (!bus_addr)
  4914. + return 0;
  4915. +
  4916. + g_cbVirtAddr = virtual_page;
  4917. + g_cbBusAddr = bus_addr & ~4095;
  4918. + g_cacheMiss++;
  4919. +
  4920. + return (void __iomem *)bus_addr;
  4921. + }
  4922. +}
  4923. +
  4924. +//do the same as above, by query our virt->bus cache
  4925. +static inline void __iomem *UserVirtualToBusViaCache(void __user *pUser)
  4926. +{
  4927. + int count;
  4928. + //get the page and its offset
  4929. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  4930. + unsigned long page_offset = (unsigned long)pUser & 4095;
  4931. + unsigned long bus_addr;
  4932. +
  4933. + if (pUser >= g_pMinPhys && pUser < g_pMaxPhys)
  4934. + {
  4935. + PRINTK_VERBOSE(KERN_DEBUG "user->phys passthrough on %p\n", pUser);
  4936. + return (void __iomem *)((unsigned long)pUser + g_physOffset);
  4937. + }
  4938. +
  4939. + //check the cache for our entry
  4940. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  4941. + if (g_virtAddr[count] == virtual_page)
  4942. + {
  4943. + bus_addr = g_busAddr[count] + page_offset;
  4944. + g_cacheHit++;
  4945. + return (void __iomem *)bus_addr;
  4946. + }
  4947. +
  4948. + //not found, look up manually and then insert its page address
  4949. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  4950. +
  4951. + if (!bus_addr)
  4952. + return 0;
  4953. +
  4954. + g_virtAddr[g_cacheInsertAt] = virtual_page;
  4955. + g_busAddr[g_cacheInsertAt] = bus_addr & ~4095;
  4956. +
  4957. + //round robin
  4958. + g_cacheInsertAt++;
  4959. + if (g_cacheInsertAt == VIRT_TO_BUS_CACHE_SIZE)
  4960. + g_cacheInsertAt = 0;
  4961. +
  4962. + g_cacheMiss++;
  4963. +
  4964. + return (void __iomem *)bus_addr;
  4965. +}
  4966. +
  4967. +/***** FILE OPERATIONS ****/
  4968. +static int Open(struct inode *pInode, struct file *pFile)
  4969. +{
  4970. + PRINTK(KERN_DEBUG "file opening: %d/%d\n", imajor(pInode), iminor(pInode));
  4971. +
  4972. + //check which device we are
  4973. + if (iminor(pInode) == 0) //4k
  4974. + {
  4975. + //only one at a time
  4976. + if (!atomic_dec_and_test(&g_oneLock4k))
  4977. + {
  4978. + atomic_inc(&g_oneLock4k);
  4979. + return -EBUSY;
  4980. + }
  4981. + }
  4982. + else
  4983. + return -EINVAL;
  4984. +
  4985. + //todo there will be trouble if two different processes open the files
  4986. +
  4987. + //reset after any file is opened
  4988. + g_pMinPhys = (void __user *)-1;
  4989. + g_pMaxPhys = (void __user *)0;
  4990. + g_physOffset = 0;
  4991. + g_cmaHandle = 0;
  4992. +
  4993. + return 0;
  4994. +}
  4995. +
  4996. +static int Release(struct inode *pInode, struct file *pFile)
  4997. +{
  4998. + PRINTK(KERN_DEBUG "file closing, %d pages tracked\n", g_trackedPages);
  4999. + if (g_trackedPages)
  5000. + PRINTK(KERN_ERR "we\'re leaking memory!\n");
  5001. +
  5002. + //wait for any dmas to finish
  5003. + DmaWaitAll();
  5004. +
  5005. + //free this memory on the application closing the file or it crashing (implicitly closing the file)
  5006. + if (g_cmaHandle)
  5007. + {
  5008. + PRINTK(KERN_DEBUG "unlocking vc memory\n");
  5009. + if (UnlockVcMemory(g_cmaHandle))
  5010. + PRINTK(KERN_ERR "uh-oh, unable to unlock vc memory!\n");
  5011. + PRINTK(KERN_DEBUG "releasing vc memory\n");
  5012. + if (ReleaseVcMemory(g_cmaHandle))
  5013. + PRINTK(KERN_ERR "uh-oh, unable to release vc memory!\n");
  5014. + }
  5015. +
  5016. + if (iminor(pInode) == 0)
  5017. + atomic_inc(&g_oneLock4k);
  5018. + else
  5019. + return -EINVAL;
  5020. +
  5021. + return 0;
  5022. +}
  5023. +
  5024. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError)
  5025. +{
  5026. + struct DmaControlBlock kernCB;
  5027. + struct DmaControlBlock __user *pUNext;
  5028. + void __iomem *pSourceBus, __iomem *pDestBus;
  5029. +
  5030. + //get the control block into kernel memory so we can work on it
  5031. + if (copy_from_user(&kernCB, pUserCB, sizeof(struct DmaControlBlock)) != 0)
  5032. + {
  5033. + PRINTK(KERN_ERR "copy_from_user failed for user cb %p\n", pUserCB);
  5034. + *pError = 1;
  5035. + return 0;
  5036. + }
  5037. +
  5038. + if (kernCB.m_pSourceAddr == 0 || kernCB.m_pDestAddr == 0)
  5039. + {
  5040. + PRINTK(KERN_ERR "faulty source (%p) dest (%p) addresses for user cb %p\n",
  5041. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr, pUserCB);
  5042. + *pError = 1;
  5043. + return 0;
  5044. + }
  5045. +
  5046. + pSourceBus = UserVirtualToBusViaCache(kernCB.m_pSourceAddr);
  5047. + pDestBus = UserVirtualToBusViaCache(kernCB.m_pDestAddr);
  5048. +
  5049. + if (!pSourceBus || !pDestBus)
  5050. + {
  5051. + PRINTK(KERN_ERR "virtual to bus translation failure for source/dest %p/%p->%p/%p\n",
  5052. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr,
  5053. + pSourceBus, pDestBus);
  5054. + *pError = 1;
  5055. + return 0;
  5056. + }
  5057. +
  5058. + //update the user structure with the new bus addresses
  5059. + kernCB.m_pSourceAddr = pSourceBus;
  5060. + kernCB.m_pDestAddr = pDestBus;
  5061. +
  5062. + PRINTK_VERBOSE(KERN_DEBUG "final source %p dest %p\n", kernCB.m_pSourceAddr, kernCB.m_pDestAddr);
  5063. +
  5064. + //sort out the bus address for the next block
  5065. + pUNext = kernCB.m_pNext;
  5066. +
  5067. + if (kernCB.m_pNext)
  5068. + {
  5069. + void __iomem *pNextBus;
  5070. + pNextBus = UserVirtualToBusViaCbCache(kernCB.m_pNext);
  5071. +
  5072. + if (!pNextBus)
  5073. + {
  5074. + PRINTK(KERN_ERR "virtual to bus translation failure for m_pNext\n");
  5075. + *pError = 1;
  5076. + return 0;
  5077. + }
  5078. +
  5079. + //update the pointer with the bus address
  5080. + kernCB.m_pNext = pNextBus;
  5081. + }
  5082. +
  5083. + //write it back to user space
  5084. + if (copy_to_user(pUserCB, &kernCB, sizeof(struct DmaControlBlock)) != 0)
  5085. + {
  5086. + PRINTK(KERN_ERR "copy_to_user failed for cb %p\n", pUserCB);
  5087. + *pError = 1;
  5088. + return 0;
  5089. + }
  5090. +
  5091. + __cpuc_flush_dcache_area(pUserCB, 32);
  5092. +
  5093. + *pError = 0;
  5094. + return pUNext;
  5095. +}
  5096. +
  5097. +static int DmaKick(struct DmaControlBlock __user *pUserCB)
  5098. +{
  5099. + void __iomem *pBusCB;
  5100. +
  5101. + pBusCB = UserVirtualToBusViaCbCache(pUserCB);
  5102. + if (!pBusCB)
  5103. + {
  5104. + PRINTK(KERN_ERR "virtual to bus translation failure for cb\n");
  5105. + return 1;
  5106. + }
  5107. +
  5108. + //flush_cache_all();
  5109. +
  5110. + bcm_dma_start(g_pDmaChanBase, (dma_addr_t)pBusCB);
  5111. +
  5112. + return 0;
  5113. +}
  5114. +
  5115. +static void DmaWaitAll(void)
  5116. +{
  5117. + int counter = 0;
  5118. + volatile int inner_count;
  5119. + volatile unsigned int cs;
  5120. + unsigned long time_before, time_after;
  5121. +
  5122. + time_before = jiffies;
  5123. + //bcm_dma_wait_idle(g_pDmaChanBase);
  5124. + dsb();
  5125. +
  5126. + cs = readl(g_pDmaChanBase);
  5127. +
  5128. + while ((cs & 1) == 1)
  5129. + {
  5130. + cs = readl(g_pDmaChanBase);
  5131. + counter++;
  5132. +
  5133. + for (inner_count = 0; inner_count < 32; inner_count++);
  5134. +
  5135. + asm volatile ("MCR p15,0,r0,c7,c0,4 \n");
  5136. + //cpu_do_idle();
  5137. + if (counter >= 1000000)
  5138. + {
  5139. + PRINTK(KERN_WARNING "DMA failed to finish in a timely fashion\n");
  5140. + break;
  5141. + }
  5142. + }
  5143. + time_after = jiffies;
  5144. + PRINTK_VERBOSE(KERN_DEBUG "done, counter %d, cs %08x", counter, cs);
  5145. + PRINTK_VERBOSE(KERN_DEBUG "took %ld jiffies, %d HZ\n", time_after - time_before, HZ);
  5146. +}
  5147. +
  5148. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg)
  5149. +{
  5150. + int error = 0;
  5151. + PRINTK_VERBOSE(KERN_DEBUG "ioctl cmd %x arg %lx\n", cmd, arg);
  5152. +
  5153. + switch (cmd)
  5154. + {
  5155. + case DMA_PREPARE:
  5156. + case DMA_PREPARE_KICK:
  5157. + case DMA_PREPARE_KICK_WAIT:
  5158. + {
  5159. + struct DmaControlBlock __user *pUCB = (struct DmaControlBlock *)arg;
  5160. + int steps = 0;
  5161. + unsigned long start_time = jiffies;
  5162. + (void)start_time;
  5163. +
  5164. + //flush our address cache
  5165. + FlushAddrCache();
  5166. +
  5167. + PRINTK_VERBOSE(KERN_DEBUG "dma prepare\n");
  5168. +
  5169. + //do virtual to bus translation for each entry
  5170. + do
  5171. + {
  5172. + pUCB = DmaPrepare(pUCB, &error);
  5173. + } while (error == 0 && ++steps && pUCB);
  5174. + PRINTK_VERBOSE(KERN_DEBUG "prepare done in %d steps, %ld\n", steps, jiffies - start_time);
  5175. +
  5176. + //carry straight on if we want to kick too
  5177. + if (cmd == DMA_PREPARE || error)
  5178. + {
  5179. + PRINTK_VERBOSE(KERN_DEBUG "falling out\n");
  5180. + return error ? -EINVAL : 0;
  5181. + }
  5182. + }
  5183. + case DMA_KICK:
  5184. + PRINTK_VERBOSE(KERN_DEBUG "dma begin\n");
  5185. +
  5186. + if (cmd == DMA_KICK)
  5187. + FlushAddrCache();
  5188. +
  5189. + DmaKick((struct DmaControlBlock __user *)arg);
  5190. +
  5191. + if (cmd != DMA_PREPARE_KICK_WAIT)
  5192. + break;
  5193. +/* case DMA_WAIT_ONE:
  5194. + //PRINTK(KERN_DEBUG "dma wait one\n");
  5195. + break;*/
  5196. + case DMA_WAIT_ALL:
  5197. + //PRINTK(KERN_DEBUG "dma wait all\n");
  5198. + DmaWaitAll();
  5199. + break;
  5200. + case DMA_MAX_BURST:
  5201. + if (g_dmaChan == 0)
  5202. + return 10;
  5203. + else
  5204. + return 5;
  5205. + case DMA_SET_MIN_PHYS:
  5206. + g_pMinPhys = (void __user *)arg;
  5207. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  5208. + break;
  5209. + case DMA_SET_MAX_PHYS:
  5210. + g_pMaxPhys = (void __user *)arg;
  5211. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  5212. + break;
  5213. + case DMA_SET_PHYS_OFFSET:
  5214. + g_physOffset = arg;
  5215. + PRINTK(KERN_DEBUG "user/phys bypass offset set to %ld\n", g_physOffset);
  5216. + break;
  5217. + case DMA_CMA_SET_SIZE:
  5218. + {
  5219. + unsigned int pBusAddr;
  5220. +
  5221. + if (g_cmaHandle)
  5222. + {
  5223. + PRINTK(KERN_ERR "memory has already been allocated (handle %d)\n", g_cmaHandle);
  5224. + return -EINVAL;
  5225. + }
  5226. +
  5227. + PRINTK(KERN_INFO "allocating %ld bytes of VC memory\n", arg * 4096);
  5228. +
  5229. + //get the memory
  5230. + if (AllocateVcMemory(&g_cmaHandle, arg * 4096, 4096, MEM_FLAG_L1_NONALLOCATING | MEM_FLAG_NO_INIT | MEM_FLAG_HINT_PERMALOCK))
  5231. + {
  5232. + PRINTK(KERN_ERR "failed to allocate %ld bytes of VC memory\n", arg * 4096);
  5233. + g_cmaHandle = 0;
  5234. + return -EINVAL;
  5235. + }
  5236. +
  5237. + //get an address for it
  5238. + PRINTK(KERN_INFO "trying to map VC memory\n");
  5239. +
  5240. + if (LockVcMemory(&pBusAddr, g_cmaHandle))
  5241. + {
  5242. + PRINTK(KERN_ERR "failed to map CMA handle %d, releasing memory\n", g_cmaHandle);
  5243. + ReleaseVcMemory(g_cmaHandle);
  5244. + g_cmaHandle = 0;
  5245. + }
  5246. +
  5247. + PRINTK(KERN_INFO "bus address for CMA memory is %x\n", pBusAddr);
  5248. + return pBusAddr;
  5249. + }
  5250. + case DMA_GET_VERSION:
  5251. + PRINTK(KERN_DEBUG "returning version number, %d\n", VERSION_NUMBER);
  5252. + return VERSION_NUMBER;
  5253. + default:
  5254. + PRINTK(KERN_DEBUG "unknown ioctl: %d\n", cmd);
  5255. + return -EINVAL;
  5256. + }
  5257. +
  5258. + return 0;
  5259. +}
  5260. +
  5261. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp)
  5262. +{
  5263. + return -EIO;
  5264. +}
  5265. +
  5266. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma)
  5267. +{
  5268. + struct PageList *pPages;
  5269. + struct VmaPageList *pVmaList;
  5270. +
  5271. + PRINTK_VERBOSE(KERN_DEBUG "MMAP vma %p, length %ld (%s %d)\n",
  5272. + pVma, pVma->vm_end - pVma->vm_start,
  5273. + current->comm, current->pid);
  5274. + PRINTK_VERBOSE(KERN_DEBUG "MMAP %p %d (tracked %d)\n", pVma, current->pid, g_trackedPages);
  5275. +
  5276. + //make a new page list
  5277. + pPages = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  5278. + if (!pPages)
  5279. + {
  5280. + PRINTK(KERN_ERR "couldn\'t allocate a new page list (%s %d)\n",
  5281. + current->comm, current->pid);
  5282. + return -ENOMEM;
  5283. + }
  5284. +
  5285. + //clear the page list
  5286. + pPages->m_used = 0;
  5287. + pPages->m_pNext = 0;
  5288. +
  5289. + //insert our vma and new page list somewhere
  5290. + if (!pVma->vm_private_data)
  5291. + {
  5292. + struct VmaPageList *pList;
  5293. +
  5294. + PRINTK_VERBOSE(KERN_DEBUG "new vma list, making new one (%s %d)\n",
  5295. + current->comm, current->pid);
  5296. +
  5297. + //make a new vma list
  5298. + pList = (struct VmaPageList *)kmalloc(sizeof(struct VmaPageList), GFP_KERNEL);
  5299. + if (!pList)
  5300. + {
  5301. + PRINTK(KERN_ERR "couldn\'t allocate vma page list (%s %d)\n",
  5302. + current->comm, current->pid);
  5303. + kfree(pPages);
  5304. + return -ENOMEM;
  5305. + }
  5306. +
  5307. + //clear this list
  5308. + pVma->vm_private_data = (void *)pList;
  5309. + pList->m_refCount = 0;
  5310. + }
  5311. +
  5312. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5313. +
  5314. + //add it to the vma list
  5315. + pVmaList->m_pPageHead = pPages;
  5316. + pVmaList->m_pPageTail = pPages;
  5317. +
  5318. + pVma->vm_ops = &g_vmOps4k;
  5319. + pVma->vm_flags |= VM_IO;
  5320. +
  5321. + VmaOpen4k(pVma);
  5322. +
  5323. + return 0;
  5324. +}
  5325. +
  5326. +/****** VMA OPERATIONS ******/
  5327. +
  5328. +static void VmaOpen4k(struct vm_area_struct *pVma)
  5329. +{
  5330. + struct VmaPageList *pVmaList;
  5331. +
  5332. + PRINTK_VERBOSE(KERN_DEBUG "vma open %p private %p (%s %d), %d live pages\n", pVma, pVma->vm_private_data, current->comm, current->pid, g_trackedPages);
  5333. + PRINTK_VERBOSE(KERN_DEBUG "OPEN %p %d %ld pages (tracked pages %d)\n",
  5334. + pVma, current->pid, (pVma->vm_end - pVma->vm_start) >> 12,
  5335. + g_trackedPages);
  5336. +
  5337. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5338. +
  5339. + if (pVmaList)
  5340. + {
  5341. + pVmaList->m_refCount++;
  5342. + PRINTK_VERBOSE(KERN_DEBUG "ref count is now %d\n", pVmaList->m_refCount);
  5343. + }
  5344. + else
  5345. + {
  5346. + PRINTK_VERBOSE(KERN_DEBUG "err, open but no vma page list\n");
  5347. + }
  5348. +}
  5349. +
  5350. +static void VmaClose4k(struct vm_area_struct *pVma)
  5351. +{
  5352. + struct VmaPageList *pVmaList;
  5353. + int freed = 0;
  5354. +
  5355. + PRINTK_VERBOSE(KERN_DEBUG "vma close %p private %p (%s %d)\n", pVma, pVma->vm_private_data, current->comm, current->pid);
  5356. +
  5357. + //wait for any dmas to finish
  5358. + DmaWaitAll();
  5359. +
  5360. + //find our vma in the list
  5361. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5362. +
  5363. + //may be a fork
  5364. + if (pVmaList)
  5365. + {
  5366. + struct PageList *pPages;
  5367. +
  5368. + pVmaList->m_refCount--;
  5369. +
  5370. + if (pVmaList->m_refCount == 0)
  5371. + {
  5372. + PRINTK_VERBOSE(KERN_DEBUG "found vma, freeing pages (%s %d)\n",
  5373. + current->comm, current->pid);
  5374. +
  5375. + pPages = pVmaList->m_pPageHead;
  5376. +
  5377. + if (!pPages)
  5378. + {
  5379. + PRINTK(KERN_ERR "no page list (%s %d)!\n",
  5380. + current->comm, current->pid);
  5381. + return;
  5382. + }
  5383. +
  5384. + while (pPages)
  5385. + {
  5386. + struct PageList *next;
  5387. + int count;
  5388. +
  5389. + PRINTK_VERBOSE(KERN_DEBUG "page list (%s %d)\n",
  5390. + current->comm, current->pid);
  5391. +
  5392. + next = pPages->m_pNext;
  5393. + for (count = 0; count < pPages->m_used; count++)
  5394. + {
  5395. + PRINTK_VERBOSE(KERN_DEBUG "freeing page %p (%s %d)\n",
  5396. + pPages->m_pPages[count],
  5397. + current->comm, current->pid);
  5398. + __free_pages(pPages->m_pPages[count], 0);
  5399. + g_trackedPages--;
  5400. + freed++;
  5401. + }
  5402. +
  5403. + PRINTK_VERBOSE(KERN_DEBUG "freeing page list (%s %d)\n",
  5404. + current->comm, current->pid);
  5405. + kfree(pPages);
  5406. + pPages = next;
  5407. + }
  5408. +
  5409. + //remove our vma from the list
  5410. + kfree(pVmaList);
  5411. + pVma->vm_private_data = 0;
  5412. + }
  5413. + else
  5414. + {
  5415. + PRINTK_VERBOSE(KERN_DEBUG "ref count is %d, not closing\n", pVmaList->m_refCount);
  5416. + }
  5417. + }
  5418. + else
  5419. + {
  5420. + PRINTK_VERBOSE(KERN_ERR "uh-oh, vma %p not found (%s %d)!\n", pVma, current->comm, current->pid);
  5421. + PRINTK_VERBOSE(KERN_ERR "CLOSE ERR\n");
  5422. + }
  5423. +
  5424. + PRINTK_VERBOSE(KERN_DEBUG "CLOSE %p %d %d pages (tracked pages %d)",
  5425. + pVma, current->pid, freed, g_trackedPages);
  5426. +
  5427. + PRINTK_VERBOSE(KERN_DEBUG "%d pages open\n", g_trackedPages);
  5428. +}
  5429. +
  5430. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf)
  5431. +{
  5432. + PRINTK_VERBOSE(KERN_DEBUG "vma fault for vma %p private %p at offset %ld (%s %d)\n", pVma, pVma->vm_private_data, pVmf->pgoff,
  5433. + current->comm, current->pid);
  5434. + PRINTK_VERBOSE(KERN_DEBUG "FAULT\n");
  5435. + pVmf->page = alloc_page(GFP_KERNEL);
  5436. +
  5437. + if (pVmf->page)
  5438. + {
  5439. + PRINTK_VERBOSE(KERN_DEBUG "alloc page virtual %p\n", page_address(pVmf->page));
  5440. + }
  5441. +
  5442. + if (!pVmf->page)
  5443. + {
  5444. + PRINTK(KERN_ERR "vma fault oom (%s %d)\n", current->comm, current->pid);
  5445. + return VM_FAULT_OOM;
  5446. + }
  5447. + else
  5448. + {
  5449. + struct VmaPageList *pVmaList;
  5450. +
  5451. + get_page(pVmf->page);
  5452. + g_trackedPages++;
  5453. +
  5454. + //find our vma in the list
  5455. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5456. +
  5457. + if (pVmaList)
  5458. + {
  5459. + PRINTK_VERBOSE(KERN_DEBUG "vma found (%s %d)\n", current->comm, current->pid);
  5460. +
  5461. + if (pVmaList->m_pPageTail->m_used == PAGES_PER_LIST)
  5462. + {
  5463. + PRINTK_VERBOSE(KERN_DEBUG "making new page list (%s %d)\n", current->comm, current->pid);
  5464. + //making a new page list
  5465. + pVmaList->m_pPageTail->m_pNext = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  5466. + if (!pVmaList->m_pPageTail->m_pNext)
  5467. + return -ENOMEM;
  5468. +
  5469. + //update the tail pointer
  5470. + pVmaList->m_pPageTail = pVmaList->m_pPageTail->m_pNext;
  5471. + pVmaList->m_pPageTail->m_used = 0;
  5472. + pVmaList->m_pPageTail->m_pNext = 0;
  5473. + }
  5474. +
  5475. + PRINTK_VERBOSE(KERN_DEBUG "adding page to list (%s %d)\n", current->comm, current->pid);
  5476. +
  5477. + pVmaList->m_pPageTail->m_pPages[pVmaList->m_pPageTail->m_used] = pVmf->page;
  5478. + pVmaList->m_pPageTail->m_used++;
  5479. + }
  5480. + else
  5481. + PRINTK(KERN_ERR "returned page for vma we don\'t know %p (%s %d)\n", pVma, current->comm, current->pid);
  5482. +
  5483. + return 0;
  5484. + }
  5485. +}
  5486. +
  5487. +/****** GENERIC FUNCTIONS ******/
  5488. +static int __init dmaer_init(void)
  5489. +{
  5490. + int result = alloc_chrdev_region(&g_majorMinor, 0, 1, "dmaer");
  5491. + if (result < 0)
  5492. + {
  5493. + PRINTK(KERN_ERR "unable to get major device number\n");
  5494. + return result;
  5495. + }
  5496. + else
  5497. + PRINTK(KERN_DEBUG "major device number %d\n", MAJOR(g_majorMinor));
  5498. +
  5499. + PRINTK(KERN_DEBUG "vma list size %d, page list size %d, page size %ld\n",
  5500. + sizeof(struct VmaPageList), sizeof(struct PageList), PAGE_SIZE);
  5501. +
  5502. + //get a dma channel to work with
  5503. + result = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST, (void **)&g_pDmaChanBase, &g_dmaIrq);
  5504. +
  5505. + //uncomment to force to channel 0
  5506. + //result = 0;
  5507. + //g_pDmaChanBase = 0xce808000;
  5508. +
  5509. + if (result < 0)
  5510. + {
  5511. + PRINTK(KERN_ERR "failed to allocate dma channel\n");
  5512. + cdev_del(&g_cDev);
  5513. + unregister_chrdev_region(g_majorMinor, 1);
  5514. + }
  5515. +
  5516. + //reset the channel
  5517. + PRINTK(KERN_DEBUG "allocated dma channel %d (%p), initial state %08x\n", result, g_pDmaChanBase, *g_pDmaChanBase);
  5518. + *g_pDmaChanBase = 1 << 31;
  5519. + PRINTK(KERN_DEBUG "post-reset %08x\n", *g_pDmaChanBase);
  5520. +
  5521. + g_dmaChan = result;
  5522. +
  5523. + //clear the cache stats
  5524. + g_cacheHit = 0;
  5525. + g_cacheMiss = 0;
  5526. +
  5527. + //register our device - after this we are go go go
  5528. + cdev_init(&g_cDev, &g_fOps);
  5529. + g_cDev.owner = THIS_MODULE;
  5530. + g_cDev.ops = &g_fOps;
  5531. +
  5532. + result = cdev_add(&g_cDev, g_majorMinor, 1);
  5533. + if (result < 0)
  5534. + {
  5535. + PRINTK(KERN_ERR "failed to add character device\n");
  5536. + unregister_chrdev_region(g_majorMinor, 1);
  5537. + bcm_dma_chan_free(g_dmaChan);
  5538. + return result;
  5539. + }
  5540. +
  5541. + return 0;
  5542. +}
  5543. +
  5544. +static void __exit dmaer_exit(void)
  5545. +{
  5546. + PRINTK(KERN_INFO "closing dmaer device, cache stats: %d hits %d misses\n", g_cacheHit, g_cacheMiss);
  5547. + //unregister the device
  5548. + cdev_del(&g_cDev);
  5549. + unregister_chrdev_region(g_majorMinor, 1);
  5550. + //free the dma channel
  5551. + bcm_dma_chan_free(g_dmaChan);
  5552. +}
  5553. +
  5554. +MODULE_LICENSE("Dual BSD/GPL");
  5555. +MODULE_AUTHOR("Simon Hall");
  5556. +module_init(dmaer_init);
  5557. +module_exit(dmaer_exit);
  5558. +
  5559. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  5560. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  5561. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-03-13 12:46:12.432043725 +0100
  5562. @@ -0,0 +1,419 @@
  5563. +/*
  5564. + * linux/arch/arm/mach-bcm2708/arm_control.h
  5565. + *
  5566. + * Copyright (C) 2010 Broadcom
  5567. + *
  5568. + * This program is free software; you can redistribute it and/or modify
  5569. + * it under the terms of the GNU General Public License as published by
  5570. + * the Free Software Foundation; either version 2 of the License, or
  5571. + * (at your option) any later version.
  5572. + *
  5573. + * This program is distributed in the hope that it will be useful,
  5574. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5575. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5576. + * GNU General Public License for more details.
  5577. + *
  5578. + * You should have received a copy of the GNU General Public License
  5579. + * along with this program; if not, write to the Free Software
  5580. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5581. + */
  5582. +
  5583. +#ifndef __BCM2708_ARM_CONTROL_H
  5584. +#define __BCM2708_ARM_CONTROL_H
  5585. +
  5586. +/*
  5587. + * Definitions and addresses for the ARM CONTROL logic
  5588. + * This file is manually generated.
  5589. + */
  5590. +
  5591. +#define ARM_BASE 0x7E00B000
  5592. +
  5593. +/* Basic configuration */
  5594. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  5595. +#define ARM_C0_SIZ128M 0x00000000
  5596. +#define ARM_C0_SIZ256M 0x00000001
  5597. +#define ARM_C0_SIZ512M 0x00000002
  5598. +#define ARM_C0_SIZ1G 0x00000003
  5599. +#define ARM_C0_BRESP0 0x00000000
  5600. +#define ARM_C0_BRESP1 0x00000004
  5601. +#define ARM_C0_BRESP2 0x00000008
  5602. +#define ARM_C0_BOOTHI 0x00000010
  5603. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  5604. +#define ARM_C0_FULLPERI 0x00000040
  5605. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  5606. +#define ARM_C0_JTAGMASK 0x00000E00
  5607. +#define ARM_C0_JTAGOFF 0x00000000
  5608. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  5609. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  5610. +#define ARM_C0_APROTMSK 0x0000F000
  5611. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  5612. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  5613. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  5614. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  5615. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  5616. +#define ARM_C0_PRIO_L2 0x0F000000
  5617. +#define ARM_C0_PRIO_UC 0xF0000000
  5618. +
  5619. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  5620. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  5621. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  5622. +
  5623. +
  5624. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  5625. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  5626. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  5627. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  5628. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  5629. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  5630. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  5631. +
  5632. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  5633. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  5634. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  5635. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  5636. +
  5637. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  5638. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  5639. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  5640. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  5641. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  5642. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  5643. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  5644. +
  5645. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  5646. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  5647. +#define ARM_IDVAL 0x364D5241
  5648. +
  5649. +/* Translation memory */
  5650. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  5651. +/* 32 locations: 0x100.. 0x17F */
  5652. +/* 32 spare means we CAN go to 64 pages.... */
  5653. +
  5654. +
  5655. +/* Interrupts */
  5656. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  5657. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  5658. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  5659. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  5660. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  5661. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  5662. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  5663. +
  5664. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  5665. +/* todo: all I1_interrupt sources */
  5666. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  5667. +/* todo: all I2_interrupt sources */
  5668. +
  5669. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  5670. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  5671. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  5672. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  5673. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  5674. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  5675. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  5676. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  5677. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  5678. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  5679. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  5680. +
  5681. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  5682. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  5683. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  5684. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  5685. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  5686. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  5687. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  5688. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  5689. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  5690. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  5691. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  5692. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  5693. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  5694. +
  5695. +/* Timer */
  5696. +/* For reg. fields see sp804 spec. */
  5697. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  5698. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  5699. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  5700. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  5701. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  5702. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  5703. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  5704. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  5705. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  5706. +
  5707. +#define TIMER_CTRL_ONESHOT (1 << 0)
  5708. +#define TIMER_CTRL_32BIT (1 << 1)
  5709. +#define TIMER_CTRL_DIV1 (0 << 2)
  5710. +#define TIMER_CTRL_DIV16 (1 << 2)
  5711. +#define TIMER_CTRL_DIV256 (2 << 2)
  5712. +#define TIMER_CTRL_IE (1 << 5)
  5713. +#define TIMER_CTRL_PERIODIC (1 << 6)
  5714. +#define TIMER_CTRL_ENABLE (1 << 7)
  5715. +#define TIMER_CTRL_DBGHALT (1 << 8)
  5716. +#define TIMER_CTRL_ENAFREE (1 << 9)
  5717. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  5718. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  5719. +
  5720. +/* Semaphores, Doorbells, Mailboxes */
  5721. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  5722. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  5723. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  5724. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  5725. +
  5726. +/* MAILBOXES
  5727. + * Register flags are common across all
  5728. + * owner registers. See end of this section
  5729. + *
  5730. + * Semaphores, Doorbells, Mailboxes Owner 0
  5731. + *
  5732. + */
  5733. +
  5734. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  5735. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  5736. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  5737. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  5738. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  5739. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  5740. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  5741. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  5742. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  5743. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  5744. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  5745. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  5746. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  5747. +/* MAILBOX 0 access in Owner 0 area */
  5748. +/* Some addresses should ONLY be used by owner 0 */
  5749. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  5750. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  5751. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  5752. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  5753. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  5754. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  5755. +/* MAILBOX 1 access in Owner 0 area */
  5756. +/* Owner 0 should only WRITE to this mailbox */
  5757. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  5758. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  5759. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  5760. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  5761. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  5762. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  5763. +/* General SEM, BELL, MAIL config/status */
  5764. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  5765. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  5766. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  5767. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  5768. +
  5769. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  5770. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  5771. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  5772. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  5773. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  5774. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  5775. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  5776. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  5777. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  5778. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  5779. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  5780. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  5781. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  5782. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  5783. +/* MAILBOX 0 access in Owner 0 area */
  5784. +/* Owner 1 should only WRITE to this mailbox */
  5785. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  5786. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  5787. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  5788. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  5789. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  5790. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  5791. +/* MAILBOX 1 access in Owner 0 area */
  5792. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  5793. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  5794. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  5795. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  5796. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  5797. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  5798. +/* General SEM, BELL, MAIL config/status */
  5799. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  5800. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  5801. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  5802. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  5803. +
  5804. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  5805. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5806. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5807. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  5808. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  5809. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  5810. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  5811. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  5812. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  5813. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  5814. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  5815. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  5816. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  5817. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  5818. +/* MAILBOX 0 access in Owner 2 area */
  5819. +/* Owner 2 should only WRITE to this mailbox */
  5820. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  5821. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  5822. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  5823. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  5824. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  5825. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  5826. +/* MAILBOX 1 access in Owner 2 area */
  5827. +/* Owner 2 should only WRITE to this mailbox */
  5828. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  5829. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  5830. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  5831. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  5832. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  5833. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  5834. +/* General SEM, BELL, MAIL config/status */
  5835. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  5836. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  5837. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  5838. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  5839. +
  5840. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  5841. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5842. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5843. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  5844. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  5845. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  5846. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  5847. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  5848. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  5849. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  5850. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  5851. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  5852. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  5853. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  5854. +/* MAILBOX 0 access in Owner 3 area */
  5855. +/* Owner 3 should only WRITE to this mailbox */
  5856. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  5857. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  5858. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  5859. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  5860. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  5861. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  5862. +/* MAILBOX 1 access in Owner 3 area */
  5863. +/* Owner 3 should only WRITE to this mailbox */
  5864. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  5865. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  5866. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  5867. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  5868. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  5869. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  5870. +/* General SEM, BELL, MAIL config/status */
  5871. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  5872. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  5873. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  5874. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  5875. +
  5876. +
  5877. +
  5878. +/* Mailbox flags. Valid for all owners */
  5879. +
  5880. +/* Mailbox status register (...0x98) */
  5881. +#define ARM_MS_FULL 0x80000000
  5882. +#define ARM_MS_EMPTY 0x40000000
  5883. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  5884. +
  5885. +/* MAILBOX config/status register (...0x9C) */
  5886. +/* ANY write to this register clears the error bits! */
  5887. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  5888. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  5889. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  5890. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  5891. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  5892. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  5893. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5894. +/* Bit 7 is unused */
  5895. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5896. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5897. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5898. +
  5899. +/* Semaphore clear/debug register (...0xE0) */
  5900. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5901. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5902. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5903. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5904. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5905. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5906. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5907. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5908. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5909. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5910. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5911. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5912. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5913. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5914. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5915. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5916. +
  5917. +/* Doorbells clear/debug register (...0xE4) */
  5918. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5919. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5920. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5921. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5922. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5923. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5924. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5925. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5926. +
  5927. +/* MY IRQS register (...0xF8) */
  5928. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5929. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5930. +
  5931. +/* ALL IRQS register (...0xF8) */
  5932. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5933. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5934. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5935. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5936. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5937. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5938. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5939. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5940. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5941. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5942. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5943. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5944. +/* */
  5945. +/* ARM JTAG BASH */
  5946. +/* */
  5947. +#define AJB_BASE 0x7e2000c0
  5948. +
  5949. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5950. +#define AJB_BITS0 0x000000
  5951. +#define AJB_BITS4 0x000004
  5952. +#define AJB_BITS8 0x000008
  5953. +#define AJB_BITS12 0x00000C
  5954. +#define AJB_BITS16 0x000010
  5955. +#define AJB_BITS20 0x000014
  5956. +#define AJB_BITS24 0x000018
  5957. +#define AJB_BITS28 0x00001C
  5958. +#define AJB_BITS32 0x000020
  5959. +#define AJB_BITS34 0x000022
  5960. +#define AJB_OUT_MS 0x000040
  5961. +#define AJB_OUT_LS 0x000000
  5962. +#define AJB_INV_CLK 0x000080
  5963. +#define AJB_D0_RISE 0x000100
  5964. +#define AJB_D0_FALL 0x000000
  5965. +#define AJB_D1_RISE 0x000200
  5966. +#define AJB_D1_FALL 0x000000
  5967. +#define AJB_IN_RISE 0x000400
  5968. +#define AJB_IN_FALL 0x000000
  5969. +#define AJB_ENABLE 0x000800
  5970. +#define AJB_HOLD0 0x000000
  5971. +#define AJB_HOLD1 0x001000
  5972. +#define AJB_HOLD2 0x002000
  5973. +#define AJB_HOLD3 0x003000
  5974. +#define AJB_RESETN 0x004000
  5975. +#define AJB_CLKSHFT 16
  5976. +#define AJB_BUSY 0x80000000
  5977. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5978. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5979. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5980. +
  5981. +#endif
  5982. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5983. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5984. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-03-13 12:46:12.432043725 +0100
  5985. @@ -0,0 +1,60 @@
  5986. +/*
  5987. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5988. + *
  5989. + * Copyright (C) 2010 Broadcom
  5990. + *
  5991. + * This program is free software; you can redistribute it and/or modify
  5992. + * it under the terms of the GNU General Public License as published by
  5993. + * the Free Software Foundation; either version 2 of the License, or
  5994. + * (at your option) any later version.
  5995. + *
  5996. + * This program is distributed in the hope that it will be useful,
  5997. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5998. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5999. + * GNU General Public License for more details.
  6000. + *
  6001. + * You should have received a copy of the GNU General Public License
  6002. + * along with this program; if not, write to the Free Software
  6003. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6004. + */
  6005. +
  6006. +#ifndef _ARM_POWER_H
  6007. +#define _ARM_POWER_H
  6008. +
  6009. +/* Use meaningful names on each side */
  6010. +#ifdef __VIDEOCORE__
  6011. +#define PREFIX(x) ARM_##x
  6012. +#else
  6013. +#define PREFIX(x) BCM_##x
  6014. +#endif
  6015. +
  6016. +enum {
  6017. + PREFIX(POWER_SDCARD_BIT),
  6018. + PREFIX(POWER_UART_BIT),
  6019. + PREFIX(POWER_MINIUART_BIT),
  6020. + PREFIX(POWER_USB_BIT),
  6021. + PREFIX(POWER_I2C0_BIT),
  6022. + PREFIX(POWER_I2C1_BIT),
  6023. + PREFIX(POWER_I2C2_BIT),
  6024. + PREFIX(POWER_SPI_BIT),
  6025. + PREFIX(POWER_CCP2TX_BIT),
  6026. +
  6027. + PREFIX(POWER_MAX)
  6028. +};
  6029. +
  6030. +enum {
  6031. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  6032. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  6033. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  6034. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  6035. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  6036. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  6037. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  6038. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  6039. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  6040. +
  6041. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  6042. + PREFIX(POWER_NONE) = 0
  6043. +};
  6044. +
  6045. +#endif
  6046. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  6047. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  6048. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-03-13 12:46:12.432043725 +0100
  6049. @@ -0,0 +1,7 @@
  6050. +#ifndef __ASM_MACH_CLKDEV_H
  6051. +#define __ASM_MACH_CLKDEV_H
  6052. +
  6053. +#define __clk_get(clk) ({ 1; })
  6054. +#define __clk_put(clk) do { } while (0)
  6055. +
  6056. +#endif
  6057. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  6058. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  6059. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-03-13 12:46:12.432043725 +0100
  6060. @@ -0,0 +1,22 @@
  6061. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  6062. + *
  6063. + * Debugging macro include header
  6064. + *
  6065. + * Copyright (C) 2010 Broadcom
  6066. + * Copyright (C) 1994-1999 Russell King
  6067. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  6068. + *
  6069. + * This program is free software; you can redistribute it and/or modify
  6070. + * it under the terms of the GNU General Public License version 2 as
  6071. + * published by the Free Software Foundation.
  6072. + *
  6073. +*/
  6074. +
  6075. +#include <mach/platform.h>
  6076. +
  6077. + .macro addruart, rp, rv, tmp
  6078. + ldr \rp, =UART0_BASE
  6079. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  6080. + .endm
  6081. +
  6082. +#include <asm/hardware/debug-pl01x.S>
  6083. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/dma.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/dma.h
  6084. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  6085. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/dma.h 2014-03-13 12:46:12.432043725 +0100
  6086. @@ -0,0 +1,90 @@
  6087. +/*
  6088. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  6089. + *
  6090. + * Copyright (C) 2010 Broadcom
  6091. + *
  6092. + * This program is free software; you can redistribute it and/or modify
  6093. + * it under the terms of the GNU General Public License version 2 as
  6094. + * published by the Free Software Foundation.
  6095. + */
  6096. +
  6097. +
  6098. +#ifndef _MACH_BCM2708_DMA_H
  6099. +#define _MACH_BCM2708_DMA_H
  6100. +
  6101. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  6102. +
  6103. +/* DMA CS Control and Status bits */
  6104. +#define BCM2708_DMA_ACTIVE (1 << 0)
  6105. +#define BCM2708_DMA_INT (1 << 2)
  6106. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  6107. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  6108. +#define BCM2708_DMA_ERR (1 << 8)
  6109. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  6110. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  6111. +
  6112. +/* DMA control block "info" field bits */
  6113. +#define BCM2708_DMA_INT_EN (1 << 0)
  6114. +#define BCM2708_DMA_TDMODE (1 << 1)
  6115. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  6116. +#define BCM2708_DMA_D_INC (1 << 4)
  6117. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  6118. +#define BCM2708_DMA_D_DREQ (1 << 6)
  6119. +#define BCM2708_DMA_S_INC (1 << 8)
  6120. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  6121. +#define BCM2708_DMA_S_DREQ (1 << 10)
  6122. +
  6123. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  6124. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  6125. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  6126. +
  6127. +#define BCM2708_DMA_DREQ_EMMC 11
  6128. +#define BCM2708_DMA_DREQ_SDHOST 13
  6129. +
  6130. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  6131. +#define BCM2708_DMA_ADDR 0x04
  6132. +/* the current control block appears in the following registers - read only */
  6133. +#define BCM2708_DMA_INFO 0x08
  6134. +#define BCM2708_DMA_SOURCE_AD 0x0c
  6135. +#define BCM2708_DMA_DEST_AD 0x10
  6136. +#define BCM2708_DMA_NEXTCB 0x1C
  6137. +#define BCM2708_DMA_DEBUG 0x20
  6138. +
  6139. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  6140. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  6141. +
  6142. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  6143. +
  6144. +struct bcm2708_dma_cb {
  6145. + unsigned long info;
  6146. + unsigned long src;
  6147. + unsigned long dst;
  6148. + unsigned long length;
  6149. + unsigned long stride;
  6150. + unsigned long next;
  6151. + unsigned long pad[2];
  6152. +};
  6153. +struct scatterlist;
  6154. +
  6155. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  6156. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  6157. + dma_addr_t control_block);
  6158. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  6159. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  6160. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  6161. +
  6162. +/* When listing features we can ask for when allocating DMA channels give
  6163. + those with higher priority smaller ordinal numbers */
  6164. +#define BCM_DMA_FEATURE_FAST_ORD 0
  6165. +#define BCM_DMA_FEATURE_BULK_ORD 1
  6166. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  6167. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  6168. +#define BCM_DMA_FEATURE_COUNT 2
  6169. +
  6170. +/* return channel no or -ve error */
  6171. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  6172. + void __iomem **out_dma_base, int *out_dma_irq);
  6173. +extern int bcm_dma_chan_free(int channel);
  6174. +
  6175. +
  6176. +#endif /* _MACH_BCM2708_DMA_H */
  6177. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  6178. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  6179. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-03-13 12:46:12.432043725 +0100
  6180. @@ -0,0 +1,69 @@
  6181. +/*
  6182. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  6183. + *
  6184. + * Low-level IRQ helper macros for BCM2708 platforms
  6185. + *
  6186. + * Copyright (C) 2010 Broadcom
  6187. + *
  6188. + * This program is free software; you can redistribute it and/or modify
  6189. + * it under the terms of the GNU General Public License as published by
  6190. + * the Free Software Foundation; either version 2 of the License, or
  6191. + * (at your option) any later version.
  6192. + *
  6193. + * This program is distributed in the hope that it will be useful,
  6194. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6195. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6196. + * GNU General Public License for more details.
  6197. + *
  6198. + * You should have received a copy of the GNU General Public License
  6199. + * along with this program; if not, write to the Free Software
  6200. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6201. + */
  6202. +#include <mach/hardware.h>
  6203. +
  6204. + .macro disable_fiq
  6205. + .endm
  6206. +
  6207. + .macro get_irqnr_preamble, base, tmp
  6208. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  6209. + .endm
  6210. +
  6211. + .macro arch_ret_to_user, tmp1, tmp2
  6212. + .endm
  6213. +
  6214. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  6215. + /* get masked status */
  6216. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  6217. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  6218. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  6219. + /* clear bits 8 and 9, and test */
  6220. + bics \irqstat, \irqstat, #0x300
  6221. + bne 1010f
  6222. +
  6223. + tst \tmp, #0x100
  6224. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  6225. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  6226. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  6227. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  6228. + bicne \irqstat, #((1<<18) | (1<<19))
  6229. + bne 1010f
  6230. +
  6231. + tst \tmp, #0x200
  6232. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  6233. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  6234. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  6235. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  6236. + bicne \irqstat, #((1<<30))
  6237. + beq 1020f
  6238. +
  6239. +1010:
  6240. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  6241. + @ N.B. CLZ is an ARM5 instruction.
  6242. + sub \tmp, \irqstat, #1
  6243. + eor \irqstat, \irqstat, \tmp
  6244. + clz \tmp, \irqstat
  6245. + sub \irqnr, \tmp
  6246. +
  6247. +1020: @ EQ will be set if no irqs pending
  6248. +
  6249. + .endm
  6250. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/frc.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/frc.h
  6251. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  6252. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/frc.h 2014-03-13 12:46:12.432043725 +0100
  6253. @@ -0,0 +1,38 @@
  6254. +/*
  6255. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6256. + *
  6257. + * BCM2708 free running counter (timer)
  6258. + *
  6259. + * Copyright (C) 2010 Broadcom
  6260. + *
  6261. + * This program is free software; you can redistribute it and/or modify
  6262. + * it under the terms of the GNU General Public License as published by
  6263. + * the Free Software Foundation; either version 2 of the License, or
  6264. + * (at your option) any later version.
  6265. + *
  6266. + * This program is distributed in the hope that it will be useful,
  6267. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6268. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6269. + * GNU General Public License for more details.
  6270. + *
  6271. + * You should have received a copy of the GNU General Public License
  6272. + * along with this program; if not, write to the Free Software
  6273. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6274. + */
  6275. +
  6276. +#ifndef _MACH_FRC_H
  6277. +#define _MACH_FRC_H
  6278. +
  6279. +#define FRC_TICK_RATE (1000000)
  6280. +
  6281. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  6282. + (slightly faster than frc_clock_ticks63()
  6283. + */
  6284. +extern unsigned long frc_clock_ticks32(void);
  6285. +
  6286. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  6287. + * Note - top bit should be ignored (see cnt32_to_63)
  6288. + */
  6289. +extern unsigned long long frc_clock_ticks63(void);
  6290. +
  6291. +#endif
  6292. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/gpio.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/gpio.h
  6293. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  6294. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-03-13 12:46:12.432043725 +0100
  6295. @@ -0,0 +1,18 @@
  6296. +/*
  6297. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  6298. + *
  6299. + * This file is licensed under the terms of the GNU General Public
  6300. + * License version 2. This program is licensed "as is" without any
  6301. + * warranty of any kind, whether express or implied.
  6302. + */
  6303. +
  6304. +#ifndef __ASM_ARCH_GPIO_H
  6305. +#define __ASM_ARCH_GPIO_H
  6306. +
  6307. +#define ARCH_NR_GPIOS 54 // number of gpio lines
  6308. +
  6309. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  6310. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  6311. +
  6312. +#endif
  6313. +
  6314. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/hardware.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/hardware.h
  6315. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  6316. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-03-13 12:46:12.432043725 +0100
  6317. @@ -0,0 +1,28 @@
  6318. +/*
  6319. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  6320. + *
  6321. + * This file contains the hardware definitions of the BCM2708 devices.
  6322. + *
  6323. + * Copyright (C) 2010 Broadcom
  6324. + *
  6325. + * This program is free software; you can redistribute it and/or modify
  6326. + * it under the terms of the GNU General Public License as published by
  6327. + * the Free Software Foundation; either version 2 of the License, or
  6328. + * (at your option) any later version.
  6329. + *
  6330. + * This program is distributed in the hope that it will be useful,
  6331. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6332. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6333. + * GNU General Public License for more details.
  6334. + *
  6335. + * You should have received a copy of the GNU General Public License
  6336. + * along with this program; if not, write to the Free Software
  6337. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6338. + */
  6339. +#ifndef __ASM_ARCH_HARDWARE_H
  6340. +#define __ASM_ARCH_HARDWARE_H
  6341. +
  6342. +#include <asm/sizes.h>
  6343. +#include <mach/platform.h>
  6344. +
  6345. +#endif
  6346. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/io.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/io.h
  6347. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  6348. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/io.h 2014-03-13 12:46:12.432043725 +0100
  6349. @@ -0,0 +1,27 @@
  6350. +/*
  6351. + * arch/arm/mach-bcm2708/include/mach/io.h
  6352. + *
  6353. + * Copyright (C) 2003 ARM Limited
  6354. + *
  6355. + * This program is free software; you can redistribute it and/or modify
  6356. + * it under the terms of the GNU General Public License as published by
  6357. + * the Free Software Foundation; either version 2 of the License, or
  6358. + * (at your option) any later version.
  6359. + *
  6360. + * This program is distributed in the hope that it will be useful,
  6361. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6362. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6363. + * GNU General Public License for more details.
  6364. + *
  6365. + * You should have received a copy of the GNU General Public License
  6366. + * along with this program; if not, write to the Free Software
  6367. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6368. + */
  6369. +#ifndef __ASM_ARM_ARCH_IO_H
  6370. +#define __ASM_ARM_ARCH_IO_H
  6371. +
  6372. +#define IO_SPACE_LIMIT 0xffffffff
  6373. +
  6374. +#define __io(a) __typesafe_io(a)
  6375. +
  6376. +#endif
  6377. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/irqs.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/irqs.h
  6378. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  6379. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-03-13 12:46:12.432043725 +0100
  6380. @@ -0,0 +1,199 @@
  6381. +/*
  6382. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  6383. + *
  6384. + * Copyright (C) 2010 Broadcom
  6385. + * Copyright (C) 2003 ARM Limited
  6386. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6387. + *
  6388. + * This program is free software; you can redistribute it and/or modify
  6389. + * it under the terms of the GNU General Public License as published by
  6390. + * the Free Software Foundation; either version 2 of the License, or
  6391. + * (at your option) any later version.
  6392. + *
  6393. + * This program is distributed in the hope that it will be useful,
  6394. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6395. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6396. + * GNU General Public License for more details.
  6397. + *
  6398. + * You should have received a copy of the GNU General Public License
  6399. + * along with this program; if not, write to the Free Software
  6400. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6401. + */
  6402. +
  6403. +#ifndef _BCM2708_IRQS_H_
  6404. +#define _BCM2708_IRQS_H_
  6405. +
  6406. +#include <mach/platform.h>
  6407. +
  6408. +/*
  6409. + * IRQ interrupts definitions are the same as the INT definitions
  6410. + * held within platform.h
  6411. + */
  6412. +#define IRQ_ARMCTRL_START 0
  6413. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  6414. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  6415. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  6416. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  6417. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  6418. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  6419. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  6420. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  6421. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  6422. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  6423. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  6424. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  6425. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  6426. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  6427. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  6428. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  6429. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  6430. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  6431. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  6432. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  6433. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  6434. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  6435. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  6436. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  6437. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  6438. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  6439. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  6440. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  6441. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  6442. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  6443. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  6444. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  6445. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  6446. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  6447. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  6448. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  6449. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  6450. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  6451. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  6452. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  6453. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  6454. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  6455. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  6456. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  6457. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  6458. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  6459. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  6460. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  6461. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  6462. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  6463. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  6464. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  6465. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  6466. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  6467. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  6468. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  6469. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  6470. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  6471. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  6472. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  6473. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  6474. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  6475. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  6476. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  6477. +
  6478. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  6479. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  6480. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  6481. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  6482. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  6483. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  6484. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  6485. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  6486. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  6487. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  6488. +
  6489. +#define FIQ_START HARD_IRQS
  6490. +
  6491. +/*
  6492. + * FIQ interrupts definitions are the same as the INT definitions.
  6493. + */
  6494. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  6495. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  6496. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  6497. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  6498. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  6499. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  6500. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  6501. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  6502. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  6503. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  6504. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  6505. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  6506. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  6507. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  6508. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  6509. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  6510. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  6511. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  6512. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  6513. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  6514. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  6515. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  6516. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  6517. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  6518. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  6519. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  6520. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  6521. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  6522. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  6523. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  6524. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  6525. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  6526. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  6527. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  6528. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  6529. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  6530. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  6531. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  6532. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  6533. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  6534. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  6535. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  6536. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  6537. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  6538. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  6539. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  6540. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  6541. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  6542. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  6543. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  6544. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  6545. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  6546. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  6547. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  6548. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  6549. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  6550. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  6551. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  6552. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  6553. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  6554. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  6555. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  6556. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  6557. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  6558. +
  6559. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  6560. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  6561. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  6562. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  6563. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  6564. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  6565. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  6566. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  6567. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  6568. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  6569. +
  6570. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  6571. +
  6572. +#define HARD_IRQS (64 + 21)
  6573. +#define FIQ_IRQS (64 + 21)
  6574. +#define GPIO_IRQS (32*5)
  6575. +
  6576. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS
  6577. +
  6578. +
  6579. +#endif /* _BCM2708_IRQS_H_ */
  6580. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/memory.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/memory.h
  6581. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  6582. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/memory.h 2014-03-13 12:46:12.432043725 +0100
  6583. @@ -0,0 +1,57 @@
  6584. +/*
  6585. + * arch/arm/mach-bcm2708/include/mach/memory.h
  6586. + *
  6587. + * Copyright (C) 2010 Broadcom
  6588. + *
  6589. + * This program is free software; you can redistribute it and/or modify
  6590. + * it under the terms of the GNU General Public License as published by
  6591. + * the Free Software Foundation; either version 2 of the License, or
  6592. + * (at your option) any later version.
  6593. + *
  6594. + * This program is distributed in the hope that it will be useful,
  6595. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6596. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6597. + * GNU General Public License for more details.
  6598. + *
  6599. + * You should have received a copy of the GNU General Public License
  6600. + * along with this program; if not, write to the Free Software
  6601. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6602. + */
  6603. +#ifndef __ASM_ARCH_MEMORY_H
  6604. +#define __ASM_ARCH_MEMORY_H
  6605. +
  6606. +/* Memory overview:
  6607. +
  6608. + [ARMcore] <--virtual addr-->
  6609. + [ARMmmu] <--physical addr-->
  6610. + [GERTmap] <--bus add-->
  6611. + [VCperiph]
  6612. +
  6613. +*/
  6614. +
  6615. +/*
  6616. + * Physical DRAM offset.
  6617. + */
  6618. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  6619. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  6620. +
  6621. +#ifdef CONFIG_BCM2708_NOL2CACHE
  6622. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  6623. +#else
  6624. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  6625. +#endif
  6626. +
  6627. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  6628. + * will provide the offset into this area as well as setting the bits that
  6629. + * stop the L1 and L2 cache from being used
  6630. + *
  6631. + * WARNING: this only works because the ARM is given memory at a fixed location
  6632. + * (ARMMEM_OFFSET)
  6633. + */
  6634. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  6635. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  6636. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  6637. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  6638. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  6639. +
  6640. +#endif
  6641. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/platform.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/platform.h
  6642. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  6643. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/platform.h 2014-03-13 12:46:12.432043725 +0100
  6644. @@ -0,0 +1,228 @@
  6645. +/*
  6646. + * arch/arm/mach-bcm2708/include/mach/platform.h
  6647. + *
  6648. + * Copyright (C) 2010 Broadcom
  6649. + *
  6650. + * This program is free software; you can redistribute it and/or modify
  6651. + * it under the terms of the GNU General Public License as published by
  6652. + * the Free Software Foundation; either version 2 of the License, or
  6653. + * (at your option) any later version.
  6654. + *
  6655. + * This program is distributed in the hope that it will be useful,
  6656. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6657. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6658. + * GNU General Public License for more details.
  6659. + *
  6660. + * You should have received a copy of the GNU General Public License
  6661. + * along with this program; if not, write to the Free Software
  6662. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6663. + */
  6664. +
  6665. +#ifndef _BCM2708_PLATFORM_H
  6666. +#define _BCM2708_PLATFORM_H
  6667. +
  6668. +
  6669. +/* macros to get at IO space when running virtually */
  6670. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  6671. +
  6672. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  6673. +
  6674. +
  6675. +/*
  6676. + * SDRAM
  6677. + */
  6678. +#define BCM2708_SDRAM_BASE 0x00000000
  6679. +
  6680. +/*
  6681. + * Logic expansion modules
  6682. + *
  6683. + */
  6684. +
  6685. +
  6686. +/* ------------------------------------------------------------------------
  6687. + * BCM2708 ARMCTRL Registers
  6688. + * ------------------------------------------------------------------------
  6689. + */
  6690. +
  6691. +#define HW_REGISTER_RW(addr) (addr)
  6692. +#define HW_REGISTER_RO(addr) (addr)
  6693. +
  6694. +#include "arm_control.h"
  6695. +#undef ARM_BASE
  6696. +
  6697. +/*
  6698. + * Definitions and addresses for the ARM CONTROL logic
  6699. + * This file is manually generated.
  6700. + */
  6701. +
  6702. +#define BCM2708_PERI_BASE 0x20000000
  6703. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  6704. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  6705. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  6706. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  6707. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  6708. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  6709. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  6710. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  6711. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  6712. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  6713. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  6714. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  6715. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  6716. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  6717. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  6718. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  6719. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  6720. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  6721. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  6722. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  6723. +
  6724. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  6725. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  6726. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  6727. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  6728. +
  6729. +
  6730. +/*
  6731. + * Interrupt assignments
  6732. + */
  6733. +
  6734. +#define ARM_IRQ1_BASE 0
  6735. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  6736. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  6737. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  6738. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  6739. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  6740. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  6741. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  6742. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  6743. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  6744. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  6745. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  6746. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  6747. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  6748. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  6749. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  6750. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  6751. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  6752. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  6753. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  6754. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  6755. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  6756. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  6757. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  6758. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  6759. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  6760. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  6761. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  6762. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  6763. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  6764. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  6765. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  6766. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  6767. +
  6768. +#define ARM_IRQ2_BASE 32
  6769. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  6770. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  6771. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  6772. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  6773. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  6774. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  6775. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  6776. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  6777. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  6778. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  6779. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  6780. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  6781. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  6782. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  6783. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  6784. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  6785. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  6786. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  6787. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  6788. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  6789. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  6790. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  6791. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  6792. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  6793. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  6794. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  6795. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  6796. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  6797. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  6798. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  6799. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  6800. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  6801. +
  6802. +#define ARM_IRQ0_BASE 64
  6803. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  6804. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  6805. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  6806. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  6807. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  6808. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  6809. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  6810. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  6811. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  6812. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  6813. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  6814. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  6815. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  6816. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  6817. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  6818. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  6819. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  6820. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  6821. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  6822. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  6823. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  6824. +
  6825. +#define MAXIRQNUM (32 + 32 + 20)
  6826. +#define MAXFIQNUM (32 + 32 + 20)
  6827. +
  6828. +#define MAX_TIMER 2
  6829. +#define MAX_PERIOD 699050
  6830. +#define TICKS_PER_uSEC 1
  6831. +
  6832. +/*
  6833. + * These are useconds NOT ticks.
  6834. + *
  6835. + */
  6836. +#define mSEC_1 1000
  6837. +#define mSEC_5 (mSEC_1 * 5)
  6838. +#define mSEC_10 (mSEC_1 * 10)
  6839. +#define mSEC_25 (mSEC_1 * 25)
  6840. +#define SEC_1 (mSEC_1 * 1000)
  6841. +
  6842. +/*
  6843. + * Watchdog
  6844. + */
  6845. +#define PM_RSTC (PM_BASE+0x1c)
  6846. +#define PM_RSTS (PM_BASE+0x20)
  6847. +#define PM_WDOG (PM_BASE+0x24)
  6848. +
  6849. +#define PM_WDOG_RESET 0000000000
  6850. +#define PM_PASSWORD 0x5a000000
  6851. +#define PM_WDOG_TIME_SET 0x000fffff
  6852. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  6853. +#define PM_RSTC_WRCFG_SET 0x00000030
  6854. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  6855. +#define PM_RSTC_RESET 0x00000102
  6856. +
  6857. +#define PM_RSTS_HADPOR_SET 0x00001000
  6858. +#define PM_RSTS_HADSRH_SET 0x00000400
  6859. +#define PM_RSTS_HADSRF_SET 0x00000200
  6860. +#define PM_RSTS_HADSRQ_SET 0x00000100
  6861. +#define PM_RSTS_HADWRH_SET 0x00000040
  6862. +#define PM_RSTS_HADWRF_SET 0x00000020
  6863. +#define PM_RSTS_HADWRQ_SET 0x00000010
  6864. +#define PM_RSTS_HADDRH_SET 0x00000004
  6865. +#define PM_RSTS_HADDRF_SET 0x00000002
  6866. +#define PM_RSTS_HADDRQ_SET 0x00000001
  6867. +
  6868. +#define UART0_CLOCK 3000000
  6869. +
  6870. +#endif
  6871. +
  6872. +/* END */
  6873. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/power.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/power.h
  6874. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  6875. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/power.h 2014-03-13 12:46:12.432043725 +0100
  6876. @@ -0,0 +1,26 @@
  6877. +/*
  6878. + * linux/arch/arm/mach-bcm2708/power.h
  6879. + *
  6880. + * Copyright (C) 2010 Broadcom
  6881. + *
  6882. + * This program is free software; you can redistribute it and/or modify
  6883. + * it under the terms of the GNU General Public License version 2 as
  6884. + * published by the Free Software Foundation.
  6885. + *
  6886. + * This device provides a shared mechanism for controlling the power to
  6887. + * VideoCore subsystems.
  6888. + */
  6889. +
  6890. +#ifndef _MACH_BCM2708_POWER_H
  6891. +#define _MACH_BCM2708_POWER_H
  6892. +
  6893. +#include <linux/types.h>
  6894. +#include <mach/arm_power.h>
  6895. +
  6896. +typedef unsigned int BCM_POWER_HANDLE_T;
  6897. +
  6898. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6899. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6900. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6901. +
  6902. +#endif
  6903. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/system.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/system.h
  6904. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6905. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/system.h 2014-03-13 12:46:12.432043725 +0100
  6906. @@ -0,0 +1,38 @@
  6907. +/*
  6908. + * arch/arm/mach-bcm2708/include/mach/system.h
  6909. + *
  6910. + * Copyright (C) 2010 Broadcom
  6911. + * Copyright (C) 2003 ARM Limited
  6912. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6913. + *
  6914. + * This program is free software; you can redistribute it and/or modify
  6915. + * it under the terms of the GNU General Public License as published by
  6916. + * the Free Software Foundation; either version 2 of the License, or
  6917. + * (at your option) any later version.
  6918. + *
  6919. + * This program is distributed in the hope that it will be useful,
  6920. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6921. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6922. + * GNU General Public License for more details.
  6923. + *
  6924. + * You should have received a copy of the GNU General Public License
  6925. + * along with this program; if not, write to the Free Software
  6926. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6927. + */
  6928. +#ifndef __ASM_ARCH_SYSTEM_H
  6929. +#define __ASM_ARCH_SYSTEM_H
  6930. +
  6931. +#include <linux/io.h>
  6932. +#include <mach/hardware.h>
  6933. +#include <mach/platform.h>
  6934. +
  6935. +static inline void arch_idle(void)
  6936. +{
  6937. + /*
  6938. + * This should do all the clock switching
  6939. + * and wait for interrupt tricks
  6940. + */
  6941. + cpu_do_idle();
  6942. +}
  6943. +
  6944. +#endif
  6945. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/timex.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/timex.h
  6946. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6947. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/timex.h 2014-03-13 12:46:12.432043725 +0100
  6948. @@ -0,0 +1,23 @@
  6949. +/*
  6950. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6951. + *
  6952. + * BCM2708 sysem clock frequency
  6953. + *
  6954. + * Copyright (C) 2010 Broadcom
  6955. + *
  6956. + * This program is free software; you can redistribute it and/or modify
  6957. + * it under the terms of the GNU General Public License as published by
  6958. + * the Free Software Foundation; either version 2 of the License, or
  6959. + * (at your option) any later version.
  6960. + *
  6961. + * This program is distributed in the hope that it will be useful,
  6962. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6963. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6964. + * GNU General Public License for more details.
  6965. + *
  6966. + * You should have received a copy of the GNU General Public License
  6967. + * along with this program; if not, write to the Free Software
  6968. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6969. + */
  6970. +
  6971. +#define CLOCK_TICK_RATE (1000000)
  6972. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6973. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6974. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-03-13 12:46:12.432043725 +0100
  6975. @@ -0,0 +1,85 @@
  6976. +/*
  6977. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6978. + *
  6979. + * Copyright (C) 2010 Broadcom
  6980. + * Copyright (C) 2003 ARM Limited
  6981. + *
  6982. + * This program is free software; you can redistribute it and/or modify
  6983. + * it under the terms of the GNU General Public License as published by
  6984. + * the Free Software Foundation; either version 2 of the License, or
  6985. + * (at your option) any later version.
  6986. + *
  6987. + * This program is distributed in the hope that it will be useful,
  6988. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6989. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6990. + * GNU General Public License for more details.
  6991. + *
  6992. + * You should have received a copy of the GNU General Public License
  6993. + * along with this program; if not, write to the Free Software
  6994. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6995. + */
  6996. +
  6997. +#include <linux/io.h>
  6998. +#include <linux/amba/serial.h>
  6999. +#include <mach/hardware.h>
  7000. +
  7001. +#define UART_BAUD 115200
  7002. +
  7003. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  7004. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  7005. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  7006. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  7007. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  7008. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  7009. +
  7010. +/*
  7011. + * This does not append a newline
  7012. + */
  7013. +static inline void putc(int c)
  7014. +{
  7015. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  7016. + barrier();
  7017. +
  7018. + __raw_writel(c, BCM2708_UART_DR);
  7019. +}
  7020. +
  7021. +static inline void flush(void)
  7022. +{
  7023. + int fr;
  7024. +
  7025. + do {
  7026. + fr = __raw_readl(BCM2708_UART_FR);
  7027. + barrier();
  7028. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  7029. +}
  7030. +
  7031. +static inline void arch_decomp_setup(void)
  7032. +{
  7033. + int temp, div, rem, frac;
  7034. +
  7035. + temp = 16 * UART_BAUD;
  7036. + div = UART0_CLOCK / temp;
  7037. + rem = UART0_CLOCK % temp;
  7038. + temp = (8 * rem) / UART_BAUD;
  7039. + frac = (temp >> 1) + (temp & 1);
  7040. +
  7041. + /* Make sure the UART is disabled before we start */
  7042. + __raw_writel(0, BCM2708_UART_CR);
  7043. +
  7044. + /* Set the baud rate */
  7045. + __raw_writel(div, BCM2708_UART_IBRD);
  7046. + __raw_writel(frac, BCM2708_UART_FBRD);
  7047. +
  7048. + /* Set the UART to 8n1, FIFO enabled */
  7049. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  7050. +
  7051. + /* Enable the UART */
  7052. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  7053. + BCM2708_UART_CR);
  7054. +}
  7055. +
  7056. +/*
  7057. + * nothing to do
  7058. + */
  7059. +#define arch_decomp_wdog()
  7060. +
  7061. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vcio.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vcio.h
  7062. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  7063. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-03-13 12:46:12.432043725 +0100
  7064. @@ -0,0 +1,141 @@
  7065. +/*
  7066. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  7067. + *
  7068. + * Copyright (C) 2010 Broadcom
  7069. + *
  7070. + * This program is free software; you can redistribute it and/or modify
  7071. + * it under the terms of the GNU General Public License as published by
  7072. + * the Free Software Foundation; either version 2 of the License, or
  7073. + * (at your option) any later version.
  7074. + *
  7075. + * This program is distributed in the hope that it will be useful,
  7076. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7077. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7078. + * GNU General Public License for more details.
  7079. + *
  7080. + * You should have received a copy of the GNU General Public License
  7081. + * along with this program; if not, write to the Free Software
  7082. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7083. + */
  7084. +#ifndef _MACH_BCM2708_VCIO_H
  7085. +#define _MACH_BCM2708_VCIO_H
  7086. +
  7087. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  7088. + * (semaphores, doorbells, mailboxes)
  7089. + */
  7090. +
  7091. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  7092. +
  7093. +/* Constants shared with the ARM identifying separate mailbox channels */
  7094. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  7095. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  7096. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  7097. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  7098. +#define MBOX_CHAN_COUNT 9
  7099. +
  7100. +/* Mailbox property tags */
  7101. +enum {
  7102. + VCMSG_PROPERTY_END = 0x00000000,
  7103. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  7104. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  7105. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  7106. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  7107. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  7108. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  7109. + VCMSG_GET_VC_MEMORY = 0x00020006,
  7110. + VCMSG_GET_CLOCKS = 0x00020007,
  7111. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  7112. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  7113. + VCMSG_GET_POWER_STATE = 0x00020001,
  7114. + VCMSG_GET_TIMING = 0x00020002,
  7115. + VCMSG_SET_POWER_STATE = 0x00028001,
  7116. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  7117. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  7118. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  7119. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  7120. + VCMSG_GET_VOLTAGE = 0x00030003,
  7121. + VCMSG_SET_VOLTAGE = 0x00038003,
  7122. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  7123. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  7124. + VCMSG_GET_TEMPERATURE = 0x00030006,
  7125. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  7126. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  7127. + VCMSG_GET_TURBO = 0x00030009,
  7128. + VCMSG_SET_TURBO = 0x00038009,
  7129. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  7130. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  7131. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  7132. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  7133. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  7134. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  7135. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  7136. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  7137. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  7138. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  7139. + VCMSG_GET_DEPTH = 0x00040005,
  7140. + VCMSG_TST_DEPTH = 0x00044005,
  7141. + VCMSG_SET_DEPTH = 0x00048005,
  7142. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  7143. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  7144. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  7145. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  7146. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  7147. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  7148. + VCMSG_GET_PITCH = 0x00040008,
  7149. + VCMSG_TST_PITCH = 0x00044008,
  7150. + VCMSG_SET_PITCH = 0x00048008,
  7151. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  7152. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  7153. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  7154. + VCMSG_GET_OVERSCAN = 0x0004000a,
  7155. + VCMSG_TST_OVERSCAN = 0x0004400a,
  7156. + VCMSG_SET_OVERSCAN = 0x0004800a,
  7157. + VCMSG_GET_PALETTE = 0x0004000b,
  7158. + VCMSG_TST_PALETTE = 0x0004400b,
  7159. + VCMSG_SET_PALETTE = 0x0004800b,
  7160. + VCMSG_GET_LAYER = 0x0004000c,
  7161. + VCMSG_TST_LAYER = 0x0004400c,
  7162. + VCMSG_SET_LAYER = 0x0004800c,
  7163. + VCMSG_GET_TRANSFORM = 0x0004000d,
  7164. + VCMSG_TST_TRANSFORM = 0x0004400d,
  7165. + VCMSG_SET_TRANSFORM = 0x0004800d,
  7166. +};
  7167. +
  7168. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  7169. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  7170. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  7171. +
  7172. +#include <linux/ioctl.h>
  7173. +
  7174. +/*
  7175. + * The major device number. We can't rely on dynamic
  7176. + * registration any more, because ioctls need to know
  7177. + * it.
  7178. + */
  7179. +#define MAJOR_NUM 100
  7180. +
  7181. +/*
  7182. + * Set the message of the device driver
  7183. + */
  7184. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  7185. +/*
  7186. + * _IOWR means that we're creating an ioctl command
  7187. + * number for passing information from a user process
  7188. + * to the kernel module and from the kernel module to user process
  7189. + *
  7190. + * The first arguments, MAJOR_NUM, is the major device
  7191. + * number we're using.
  7192. + *
  7193. + * The second argument is the number of the command
  7194. + * (there could be several with different meanings).
  7195. + *
  7196. + * The third argument is the type we want to get from
  7197. + * the process to the kernel.
  7198. + */
  7199. +
  7200. +/*
  7201. + * The name of the device file
  7202. + */
  7203. +#define DEVICE_FILE_NAME "char_dev"
  7204. +
  7205. +#endif
  7206. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  7207. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  7208. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-03-13 12:46:12.432043725 +0100
  7209. @@ -0,0 +1,36 @@
  7210. +/*****************************************************************************
  7211. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7212. +*
  7213. +* Unless you and Broadcom execute a separate written software license
  7214. +* agreement governing use of this software, this software is licensed to you
  7215. +* under the terms of the GNU General Public License version 2, available at
  7216. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7217. +*
  7218. +* Notwithstanding the above, under no circumstances may you combine this
  7219. +* software in any way with any other Broadcom software provided under a
  7220. +* license other than the GPL, without Broadcom's express prior written
  7221. +* consent.
  7222. +*****************************************************************************/
  7223. +
  7224. +#if !defined( VC_MEM_H )
  7225. +#define VC_MEM_H
  7226. +
  7227. +#include <linux/ioctl.h>
  7228. +
  7229. +#define VC_MEM_IOC_MAGIC 'v'
  7230. +
  7231. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  7232. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  7233. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  7234. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  7235. +
  7236. +#if defined( __KERNEL__ )
  7237. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  7238. +
  7239. +extern unsigned long mm_vc_mem_phys_addr;
  7240. +extern unsigned int mm_vc_mem_size;
  7241. +extern int vc_mem_get_current_size( void );
  7242. +#endif
  7243. +
  7244. +#endif /* VC_MEM_H */
  7245. +
  7246. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vc_support.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vc_support.h
  7247. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vc_support.h 1970-01-01 01:00:00.000000000 +0100
  7248. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vc_support.h 2014-03-13 12:46:12.432043725 +0100
  7249. @@ -0,0 +1,69 @@
  7250. +#ifndef _VC_SUPPORT_H_
  7251. +#define _VC_SUPPORT_H_
  7252. +
  7253. +/*
  7254. + * vc_support.h
  7255. + *
  7256. + * Created on: 25 Nov 2012
  7257. + * Author: Simon
  7258. + */
  7259. +
  7260. +enum {
  7261. +/*
  7262. + If a MEM_HANDLE_T is discardable, the memory manager may resize it to size
  7263. + 0 at any time when it is not locked or retained.
  7264. + */
  7265. + MEM_FLAG_DISCARDABLE = 1 << 0,
  7266. +
  7267. + /*
  7268. + If a MEM_HANDLE_T is allocating (or normal), its block of memory will be
  7269. + accessed in an allocating fashion through the cache.
  7270. + */
  7271. + MEM_FLAG_NORMAL = 0 << 2,
  7272. + MEM_FLAG_ALLOCATING = MEM_FLAG_NORMAL,
  7273. +
  7274. + /*
  7275. + If a MEM_HANDLE_T is direct, its block of memory will be accessed
  7276. + directly, bypassing the cache.
  7277. + */
  7278. + MEM_FLAG_DIRECT = 1 << 2,
  7279. +
  7280. + /*
  7281. + If a MEM_HANDLE_T is coherent, its block of memory will be accessed in a
  7282. + non-allocating fashion through the cache.
  7283. + */
  7284. + MEM_FLAG_COHERENT = 2 << 2,
  7285. +
  7286. + /*
  7287. + If a MEM_HANDLE_T is L1-nonallocating, its block of memory will be accessed by
  7288. + the VPU in a fashion which is allocating in L2, but only coherent in L1.
  7289. + */
  7290. + MEM_FLAG_L1_NONALLOCATING = (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT),
  7291. +
  7292. + /*
  7293. + If a MEM_HANDLE_T is zero'd, its contents are set to 0 rather than
  7294. + MEM_HANDLE_INVALID on allocation and resize up.
  7295. + */
  7296. + MEM_FLAG_ZERO = 1 << 4,
  7297. +
  7298. + /*
  7299. + If a MEM_HANDLE_T is uninitialised, it will not be reset to a defined value
  7300. + (either zero, or all 1's) on allocation.
  7301. + */
  7302. + MEM_FLAG_NO_INIT = 1 << 5,
  7303. +
  7304. + /*
  7305. + Hints.
  7306. + */
  7307. + MEM_FLAG_HINT_PERMALOCK = 1 << 6, /* Likely to be locked for long periods of time. */
  7308. +};
  7309. +
  7310. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags);
  7311. +unsigned int ReleaseVcMemory(unsigned int handle);
  7312. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle);
  7313. +unsigned int UnlockVcMemory(unsigned int handle);
  7314. +
  7315. +unsigned int ExecuteVcCode(unsigned int code,
  7316. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5);
  7317. +
  7318. +#endif
  7319. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  7320. --- linux-3.10.33/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  7321. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-03-13 12:46:12.432043725 +0100
  7322. @@ -0,0 +1,20 @@
  7323. +/*
  7324. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  7325. + *
  7326. + * Copyright (C) 2010 Broadcom
  7327. + *
  7328. + * This program is free software; you can redistribute it and/or modify
  7329. + * it under the terms of the GNU General Public License as published by
  7330. + * the Free Software Foundation; either version 2 of the License, or
  7331. + * (at your option) any later version.
  7332. + *
  7333. + * This program is distributed in the hope that it will be useful,
  7334. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7335. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7336. + * GNU General Public License for more details.
  7337. + *
  7338. + * You should have received a copy of the GNU General Public License
  7339. + * along with this program; if not, write to the Free Software
  7340. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7341. + */
  7342. +#define VMALLOC_END (0xe8000000)
  7343. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/Kconfig linux-raspberry-pi/arch/arm/mach-bcm2708/Kconfig
  7344. --- linux-3.10.33/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7345. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/Kconfig 2014-03-13 12:46:12.424043709 +0100
  7346. @@ -0,0 +1,49 @@
  7347. +menu "Broadcom BCM2708 Implementations"
  7348. + depends on ARCH_BCM2708
  7349. +
  7350. +config MACH_BCM2708
  7351. + bool "Broadcom BCM2708 Development Platform"
  7352. + select NEED_MACH_MEMORY_H
  7353. + select NEED_MACH_IO_H
  7354. + select CPU_V6
  7355. + help
  7356. + Include support for the Broadcom(R) BCM2708 platform.
  7357. +
  7358. +config BCM2708_GPIO
  7359. + bool "BCM2708 gpio support"
  7360. + depends on MACH_BCM2708
  7361. + select ARCH_REQUIRE_GPIOLIB
  7362. + default y
  7363. + help
  7364. + Include support for the Broadcom(R) BCM2708 gpio.
  7365. +
  7366. +config BCM2708_VCMEM
  7367. + bool "Videocore Memory"
  7368. + depends on MACH_BCM2708
  7369. + default y
  7370. + help
  7371. + Helper for videocore memory access and total size allocation.
  7372. +
  7373. +config BCM2708_NOL2CACHE
  7374. + bool "Videocore L2 cache disable"
  7375. + depends on MACH_BCM2708
  7376. + default n
  7377. + help
  7378. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  7379. +
  7380. +config BCM2708_SPIDEV
  7381. + bool "Bind spidev to SPI0 master"
  7382. + depends on MACH_BCM2708
  7383. + depends on SPI
  7384. + default y
  7385. + help
  7386. + Binds spidev driver to the SPI0 master
  7387. +
  7388. +config BCM2708_DMAER
  7389. + tristate "BCM2708 DMA helper"
  7390. + depends on MACH_BCM2708
  7391. + default n
  7392. + help
  7393. + Enable DMA helper for accelerating X composition
  7394. +
  7395. +endmenu
  7396. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/Makefile linux-raspberry-pi/arch/arm/mach-bcm2708/Makefile
  7397. --- linux-3.10.33/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  7398. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/Makefile 2014-03-13 12:46:12.424043709 +0100
  7399. @@ -0,0 +1,11 @@
  7400. +#
  7401. +# Makefile for the linux kernel.
  7402. +#
  7403. +
  7404. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  7405. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  7406. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  7407. +
  7408. +obj-$(CONFIG_BCM2708_DMAER) += dmaer_master.o
  7409. +dmaer_master-objs := dmaer.o vc_support.o
  7410. +
  7411. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/Makefile.boot linux-raspberry-pi/arch/arm/mach-bcm2708/Makefile.boot
  7412. --- linux-3.10.33/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  7413. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/Makefile.boot 2014-03-13 12:46:12.432043725 +0100
  7414. @@ -0,0 +1,3 @@
  7415. + zreladdr-y := 0x00008000
  7416. +params_phys-y := 0x00000100
  7417. +initrd_phys-y := 0x00800000
  7418. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/power.c linux-raspberry-pi/arch/arm/mach-bcm2708/power.c
  7419. --- linux-3.10.33/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  7420. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/power.c 2014-03-13 12:46:12.432043725 +0100
  7421. @@ -0,0 +1,194 @@
  7422. +/*
  7423. + * linux/arch/arm/mach-bcm2708/power.c
  7424. + *
  7425. + * Copyright (C) 2010 Broadcom
  7426. + *
  7427. + * This program is free software; you can redistribute it and/or modify
  7428. + * it under the terms of the GNU General Public License version 2 as
  7429. + * published by the Free Software Foundation.
  7430. + *
  7431. + * This device provides a shared mechanism for controlling the power to
  7432. + * VideoCore subsystems.
  7433. + */
  7434. +
  7435. +#include <linux/module.h>
  7436. +#include <linux/semaphore.h>
  7437. +#include <linux/bug.h>
  7438. +#include <mach/power.h>
  7439. +#include <mach/vcio.h>
  7440. +#include <mach/arm_power.h>
  7441. +
  7442. +#define DRIVER_NAME "bcm2708_power"
  7443. +
  7444. +#define BCM_POWER_MAXCLIENTS 4
  7445. +#define BCM_POWER_NOCLIENT (1<<31)
  7446. +
  7447. +/* Some drivers expect there devices to be permanently powered */
  7448. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  7449. +
  7450. +#if 1
  7451. +#define DPRINTK printk
  7452. +#else
  7453. +#define DPRINTK if (0) printk
  7454. +#endif
  7455. +
  7456. +struct state_struct {
  7457. + uint32_t global_request;
  7458. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  7459. + struct semaphore client_mutex;
  7460. + struct semaphore mutex;
  7461. +} g_state;
  7462. +
  7463. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  7464. +{
  7465. + BCM_POWER_HANDLE_T i;
  7466. + int ret = -EBUSY;
  7467. +
  7468. + down(&g_state.client_mutex);
  7469. +
  7470. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  7471. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  7472. + g_state.client_request[i] = BCM_POWER_NONE;
  7473. + *handle = i;
  7474. + ret = 0;
  7475. + break;
  7476. + }
  7477. + }
  7478. +
  7479. + up(&g_state.client_mutex);
  7480. +
  7481. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  7482. +
  7483. + return ret;
  7484. +}
  7485. +EXPORT_SYMBOL_GPL(bcm_power_open);
  7486. +
  7487. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  7488. +{
  7489. + int rc = 0;
  7490. +
  7491. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  7492. +
  7493. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  7494. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  7495. + if (down_interruptible(&g_state.mutex) != 0) {
  7496. + DPRINTK("bcm_power_request -> interrupted\n");
  7497. + return -EINTR;
  7498. + }
  7499. +
  7500. + if (request != g_state.client_request[handle]) {
  7501. + uint32_t others_request = 0;
  7502. + uint32_t global_request;
  7503. + BCM_POWER_HANDLE_T i;
  7504. +
  7505. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  7506. + if (i != handle)
  7507. + others_request |=
  7508. + g_state.client_request[i];
  7509. + }
  7510. + others_request &= ~BCM_POWER_NOCLIENT;
  7511. +
  7512. + global_request = request | others_request;
  7513. + if (global_request != g_state.global_request) {
  7514. + uint32_t actual;
  7515. +
  7516. + /* Send a request to VideoCore */
  7517. + bcm_mailbox_write(MBOX_CHAN_POWER,
  7518. + global_request << 4);
  7519. +
  7520. + /* Wait for a response during power-up */
  7521. + if (global_request & ~g_state.global_request) {
  7522. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  7523. + &actual);
  7524. + DPRINTK
  7525. + ("bcm_mailbox_read -> %08x, %d\n",
  7526. + actual, rc);
  7527. + actual >>= 4;
  7528. + } else {
  7529. + rc = 0;
  7530. + actual = global_request;
  7531. + }
  7532. +
  7533. + if (rc == 0) {
  7534. + if (actual != global_request) {
  7535. + printk(KERN_ERR
  7536. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  7537. + __func__,
  7538. + g_state.global_request,
  7539. + global_request, actual, request, others_request);
  7540. + /* A failure */
  7541. + BUG_ON((others_request & actual)
  7542. + != others_request);
  7543. + request &= actual;
  7544. + rc = -EIO;
  7545. + }
  7546. +
  7547. + g_state.global_request = actual;
  7548. + g_state.client_request[handle] =
  7549. + request;
  7550. + }
  7551. + }
  7552. + }
  7553. + up(&g_state.mutex);
  7554. + } else {
  7555. + rc = -EINVAL;
  7556. + }
  7557. + DPRINTK("bcm_power_request -> %d\n", rc);
  7558. + return rc;
  7559. +}
  7560. +EXPORT_SYMBOL_GPL(bcm_power_request);
  7561. +
  7562. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  7563. +{
  7564. + int rc;
  7565. +
  7566. + DPRINTK("bcm_power_close(%d)\n", handle);
  7567. +
  7568. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  7569. + if (rc == 0)
  7570. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  7571. +
  7572. + return rc;
  7573. +}
  7574. +EXPORT_SYMBOL_GPL(bcm_power_close);
  7575. +
  7576. +static int __init bcm_power_init(void)
  7577. +{
  7578. +#if defined(BCM_POWER_ALWAYS_ON)
  7579. + BCM_POWER_HANDLE_T always_on_handle;
  7580. +#endif
  7581. + int rc = 0;
  7582. + int i;
  7583. +
  7584. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  7585. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  7586. +
  7587. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  7588. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  7589. +
  7590. + sema_init(&g_state.client_mutex, 1);
  7591. + sema_init(&g_state.mutex, 1);
  7592. +
  7593. + g_state.global_request = 0;
  7594. +
  7595. +#if defined(BCM_POWER_ALWAYS_ON)
  7596. + if (BCM_POWER_ALWAYS_ON) {
  7597. + bcm_power_open(&always_on_handle);
  7598. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  7599. + }
  7600. +#endif
  7601. +
  7602. + return rc;
  7603. +}
  7604. +
  7605. +static void __exit bcm_power_exit(void)
  7606. +{
  7607. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  7608. +}
  7609. +
  7610. +arch_initcall(bcm_power_init); /* Initialize early */
  7611. +module_exit(bcm_power_exit);
  7612. +
  7613. +MODULE_AUTHOR("Phil Elwell");
  7614. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  7615. +MODULE_LICENSE("GPL");
  7616. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/vcio.c linux-raspberry-pi/arch/arm/mach-bcm2708/vcio.c
  7617. --- linux-3.10.33/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  7618. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/vcio.c 2014-03-13 12:46:12.432043725 +0100
  7619. @@ -0,0 +1,474 @@
  7620. +/*
  7621. + * linux/arch/arm/mach-bcm2708/vcio.c
  7622. + *
  7623. + * Copyright (C) 2010 Broadcom
  7624. + *
  7625. + * This program is free software; you can redistribute it and/or modify
  7626. + * it under the terms of the GNU General Public License version 2 as
  7627. + * published by the Free Software Foundation.
  7628. + *
  7629. + * This device provides a shared mechanism for writing to the mailboxes,
  7630. + * semaphores, doorbells etc. that are shared between the ARM and the
  7631. + * VideoCore processor
  7632. + */
  7633. +
  7634. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  7635. +#define SUPPORT_SYSRQ
  7636. +#endif
  7637. +
  7638. +#include <linux/module.h>
  7639. +#include <linux/console.h>
  7640. +#include <linux/serial_core.h>
  7641. +#include <linux/serial.h>
  7642. +#include <linux/errno.h>
  7643. +#include <linux/device.h>
  7644. +#include <linux/init.h>
  7645. +#include <linux/mm.h>
  7646. +#include <linux/dma-mapping.h>
  7647. +#include <linux/platform_device.h>
  7648. +#include <linux/sysrq.h>
  7649. +#include <linux/delay.h>
  7650. +#include <linux/slab.h>
  7651. +#include <linux/interrupt.h>
  7652. +#include <linux/irq.h>
  7653. +
  7654. +#include <linux/io.h>
  7655. +
  7656. +#include <mach/vcio.h>
  7657. +#include <mach/platform.h>
  7658. +
  7659. +#include <asm/uaccess.h>
  7660. +
  7661. +
  7662. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  7663. +
  7664. +/* ----------------------------------------------------------------------
  7665. + * Mailbox
  7666. + * -------------------------------------------------------------------- */
  7667. +
  7668. +/* offsets from a mail box base address */
  7669. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  7670. +#define MAIL_RD 0x00 /* read - and next 4 words */
  7671. +#define MAIL_POL 0x10 /* read without popping the fifo */
  7672. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  7673. +#define MAIL_STA 0x18 /* status */
  7674. +#define MAIL_CNF 0x1C /* configuration */
  7675. +
  7676. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  7677. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  7678. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  7679. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  7680. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  7681. +
  7682. +#define MBOX_MAGIC 0xd0d0c0de
  7683. +
  7684. +struct vc_mailbox {
  7685. + struct device *dev; /* parent device */
  7686. + void __iomem *status;
  7687. + void __iomem *config;
  7688. + void __iomem *read;
  7689. + void __iomem *write;
  7690. + uint32_t msg[MBOX_CHAN_COUNT];
  7691. + struct semaphore sema[MBOX_CHAN_COUNT];
  7692. + uint32_t magic;
  7693. +};
  7694. +
  7695. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  7696. + uint32_t addr_mbox)
  7697. +{
  7698. + int i;
  7699. +
  7700. + mbox_out->dev = dev;
  7701. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  7702. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  7703. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  7704. + /* Write to the other mailbox */
  7705. + mbox_out->write =
  7706. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  7707. + MAIL_WRT);
  7708. +
  7709. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  7710. + mbox_out->msg[i] = 0;
  7711. + sema_init(&mbox_out->sema[i], 0);
  7712. + }
  7713. +
  7714. + /* Enable the interrupt on data reception */
  7715. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  7716. +
  7717. + mbox_out->magic = MBOX_MAGIC;
  7718. +}
  7719. +
  7720. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  7721. +{
  7722. + int rc;
  7723. +
  7724. + if (mbox->magic != MBOX_MAGIC)
  7725. + rc = -EINVAL;
  7726. + else {
  7727. + /* wait for the mailbox FIFO to have some space in it */
  7728. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  7729. + cpu_relax();
  7730. +
  7731. + writel(MBOX_MSG(chan, data28), mbox->write);
  7732. + rc = 0;
  7733. + }
  7734. + return rc;
  7735. +}
  7736. +
  7737. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  7738. +{
  7739. + int rc;
  7740. +
  7741. + if (mbox->magic != MBOX_MAGIC)
  7742. + rc = -EINVAL;
  7743. + else {
  7744. + down(&mbox->sema[chan]);
  7745. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  7746. + mbox->msg[chan] = 0;
  7747. + rc = 0;
  7748. + }
  7749. + return rc;
  7750. +}
  7751. +
  7752. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  7753. +{
  7754. + /* wait for the mailbox FIFO to have some data in it */
  7755. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  7756. + int status = readl(mbox->status);
  7757. + int ret = IRQ_NONE;
  7758. +
  7759. + while (!(status & ARM_MS_EMPTY)) {
  7760. + uint32_t msg = readl(mbox->read);
  7761. + int chan = MBOX_CHAN(msg);
  7762. + if (chan < MBOX_CHAN_COUNT) {
  7763. + if (mbox->msg[chan]) {
  7764. + /* Overflow */
  7765. + printk(KERN_ERR DRIVER_NAME
  7766. + ": mbox chan %d overflow - drop %08x\n",
  7767. + chan, msg);
  7768. + } else {
  7769. + mbox->msg[chan] = (msg | 0xf);
  7770. + up(&mbox->sema[chan]);
  7771. + }
  7772. + } else {
  7773. + printk(KERN_ERR DRIVER_NAME
  7774. + ": invalid channel selector (msg %08x)\n", msg);
  7775. + }
  7776. + ret = IRQ_HANDLED;
  7777. + status = readl(mbox->status);
  7778. + }
  7779. + return ret;
  7780. +}
  7781. +
  7782. +static struct irqaction mbox_irqaction = {
  7783. + .name = "ARM Mailbox IRQ",
  7784. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  7785. + .handler = mbox_irq,
  7786. +};
  7787. +
  7788. +/* ----------------------------------------------------------------------
  7789. + * Mailbox Methods
  7790. + * -------------------------------------------------------------------- */
  7791. +
  7792. +static struct device *mbox_dev; /* we assume there's only one! */
  7793. +
  7794. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  7795. +{
  7796. + int rc;
  7797. +
  7798. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  7799. + device_lock(dev);
  7800. + rc = mbox_write(mailbox, chan, data28);
  7801. + device_unlock(dev);
  7802. +
  7803. + return rc;
  7804. +}
  7805. +
  7806. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  7807. +{
  7808. + int rc;
  7809. +
  7810. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  7811. + device_lock(dev);
  7812. + rc = mbox_read(mailbox, chan, data28);
  7813. + device_unlock(dev);
  7814. +
  7815. + return rc;
  7816. +}
  7817. +
  7818. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  7819. +{
  7820. + if (mbox_dev)
  7821. + return dev_mbox_write(mbox_dev, chan, data28);
  7822. + else
  7823. + return -ENODEV;
  7824. +}
  7825. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  7826. +
  7827. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  7828. +{
  7829. + if (mbox_dev)
  7830. + return dev_mbox_read(mbox_dev, chan, data28);
  7831. + else
  7832. + return -ENODEV;
  7833. +}
  7834. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  7835. +
  7836. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  7837. +{
  7838. + mbox_dev = dev;
  7839. +}
  7840. +
  7841. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  7842. +{
  7843. + if ( (uint32_t)src < TASK_SIZE)
  7844. + {
  7845. + return copy_from_user(dst, src, size);
  7846. + }
  7847. + else
  7848. + {
  7849. + memcpy( dst, src, size );
  7850. + return 0;
  7851. + }
  7852. +}
  7853. +
  7854. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  7855. +{
  7856. + if ( (uint32_t)dst < TASK_SIZE)
  7857. + {
  7858. + return copy_to_user(dst, src, size);
  7859. + }
  7860. + else
  7861. + {
  7862. + memcpy( dst, src, size );
  7863. + return 0;
  7864. + }
  7865. +}
  7866. +
  7867. +static DEFINE_MUTEX(mailbox_lock);
  7868. +extern int bcm_mailbox_property(void *data, int size)
  7869. +{
  7870. + uint32_t success;
  7871. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  7872. + void *mem_kern; /* the memory address accessed from driver */
  7873. + int s = 0;
  7874. +
  7875. + mutex_lock(&mailbox_lock);
  7876. + /* allocate some memory for the messages communicating with GPU */
  7877. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  7878. + if (mem_kern) {
  7879. + /* create the message */
  7880. + mbox_copy_from_user(mem_kern, data, size);
  7881. +
  7882. + /* send the message */
  7883. + wmb();
  7884. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  7885. + if (s == 0) {
  7886. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  7887. + }
  7888. + if (s == 0) {
  7889. + /* copy the response */
  7890. + rmb();
  7891. + mbox_copy_to_user(data, mem_kern, size);
  7892. + }
  7893. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  7894. + } else {
  7895. + s = -ENOMEM;
  7896. + }
  7897. + if (s != 0)
  7898. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  7899. +
  7900. + mutex_unlock(&mailbox_lock);
  7901. + return s;
  7902. +}
  7903. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  7904. +
  7905. +/* ----------------------------------------------------------------------
  7906. + * Platform Device for Mailbox
  7907. + * -------------------------------------------------------------------- */
  7908. +
  7909. +/*
  7910. + * Is the device open right now? Used to prevent
  7911. + * concurent access into the same device
  7912. + */
  7913. +static int Device_Open = 0;
  7914. +
  7915. +/*
  7916. + * This is called whenever a process attempts to open the device file
  7917. + */
  7918. +static int device_open(struct inode *inode, struct file *file)
  7919. +{
  7920. + /*
  7921. + * We don't want to talk to two processes at the same time
  7922. + */
  7923. + if (Device_Open)
  7924. + return -EBUSY;
  7925. +
  7926. + Device_Open++;
  7927. + /*
  7928. + * Initialize the message
  7929. + */
  7930. + try_module_get(THIS_MODULE);
  7931. + return 0;
  7932. +}
  7933. +
  7934. +static int device_release(struct inode *inode, struct file *file)
  7935. +{
  7936. + /*
  7937. + * We're now ready for our next caller
  7938. + */
  7939. + Device_Open--;
  7940. +
  7941. + module_put(THIS_MODULE);
  7942. + return 0;
  7943. +}
  7944. +
  7945. +/*
  7946. + * This function is called whenever a process tries to do an ioctl on our
  7947. + * device file. We get two extra parameters (additional to the inode and file
  7948. + * structures, which all device functions get): the number of the ioctl called
  7949. + * and the parameter given to the ioctl function.
  7950. + *
  7951. + * If the ioctl is write or read/write (meaning output is returned to the
  7952. + * calling process), the ioctl call returns the output of this function.
  7953. + *
  7954. + */
  7955. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  7956. + unsigned int ioctl_num, /* number and param for ioctl */
  7957. + unsigned long ioctl_param)
  7958. +{
  7959. + unsigned size;
  7960. + /*
  7961. + * Switch according to the ioctl called
  7962. + */
  7963. + switch (ioctl_num) {
  7964. + case IOCTL_MBOX_PROPERTY:
  7965. + /*
  7966. + * Receive a pointer to a message (in user space) and set that
  7967. + * to be the device's message. Get the parameter given to
  7968. + * ioctl by the process.
  7969. + */
  7970. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  7971. + return bcm_mailbox_property((void *)ioctl_param, size);
  7972. + break;
  7973. + default:
  7974. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  7975. + return -EINVAL;
  7976. + }
  7977. +
  7978. + return 0;
  7979. +}
  7980. +
  7981. +/* Module Declarations */
  7982. +
  7983. +/*
  7984. + * This structure will hold the functions to be called
  7985. + * when a process does something to the device we
  7986. + * created. Since a pointer to this structure is kept in
  7987. + * the devices table, it can't be local to
  7988. + * init_module. NULL is for unimplemented functios.
  7989. + */
  7990. +struct file_operations fops = {
  7991. + .unlocked_ioctl = device_ioctl,
  7992. + .open = device_open,
  7993. + .release = device_release, /* a.k.a. close */
  7994. +};
  7995. +
  7996. +static int bcm_vcio_probe(struct platform_device *pdev)
  7997. +{
  7998. + int ret = 0;
  7999. + struct vc_mailbox *mailbox;
  8000. +
  8001. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  8002. + if (NULL == mailbox) {
  8003. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  8004. + "mailbox memory\n");
  8005. + ret = -ENOMEM;
  8006. + } else {
  8007. + struct resource *res;
  8008. +
  8009. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  8010. + if (res == NULL) {
  8011. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  8012. + "resource\n");
  8013. + ret = -ENODEV;
  8014. + kfree(mailbox);
  8015. + } else {
  8016. + /* should be based on the registers from res really */
  8017. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  8018. +
  8019. + platform_set_drvdata(pdev, mailbox);
  8020. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  8021. +
  8022. + mbox_irqaction.dev_id = mailbox;
  8023. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  8024. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  8025. + __io_address(ARM_0_MAIL0_RD));
  8026. + }
  8027. + }
  8028. +
  8029. + if (ret == 0) {
  8030. + /*
  8031. + * Register the character device
  8032. + */
  8033. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  8034. +
  8035. + /*
  8036. + * Negative values signify an error
  8037. + */
  8038. + if (ret < 0) {
  8039. + printk(KERN_ERR DRIVER_NAME
  8040. + "Failed registering the character device %d\n", ret);
  8041. + return ret;
  8042. + }
  8043. + }
  8044. + return ret;
  8045. +}
  8046. +
  8047. +static int bcm_vcio_remove(struct platform_device *pdev)
  8048. +{
  8049. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  8050. +
  8051. + platform_set_drvdata(pdev, NULL);
  8052. + kfree(mailbox);
  8053. +
  8054. + return 0;
  8055. +}
  8056. +
  8057. +static struct platform_driver bcm_mbox_driver = {
  8058. + .probe = bcm_vcio_probe,
  8059. + .remove = bcm_vcio_remove,
  8060. +
  8061. + .driver = {
  8062. + .name = DRIVER_NAME,
  8063. + .owner = THIS_MODULE,
  8064. + },
  8065. +};
  8066. +
  8067. +static int __init bcm_mbox_init(void)
  8068. +{
  8069. + int ret;
  8070. +
  8071. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  8072. +
  8073. + ret = platform_driver_register(&bcm_mbox_driver);
  8074. + if (ret != 0) {
  8075. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  8076. + "on platform\n");
  8077. + }
  8078. +
  8079. + return ret;
  8080. +}
  8081. +
  8082. +static void __exit bcm_mbox_exit(void)
  8083. +{
  8084. + platform_driver_unregister(&bcm_mbox_driver);
  8085. +}
  8086. +
  8087. +arch_initcall(bcm_mbox_init); /* Initialize early */
  8088. +module_exit(bcm_mbox_exit);
  8089. +
  8090. +MODULE_AUTHOR("Gray Girling");
  8091. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  8092. +MODULE_LICENSE("GPL");
  8093. +MODULE_ALIAS("platform:bcm-mbox");
  8094. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/vc_mem.c linux-raspberry-pi/arch/arm/mach-bcm2708/vc_mem.c
  8095. --- linux-3.10.33/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  8096. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/vc_mem.c 2014-03-13 12:46:12.432043725 +0100
  8097. @@ -0,0 +1,432 @@
  8098. +/*****************************************************************************
  8099. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  8100. +*
  8101. +* Unless you and Broadcom execute a separate written software license
  8102. +* agreement governing use of this software, this software is licensed to you
  8103. +* under the terms of the GNU General Public License version 2, available at
  8104. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8105. +*
  8106. +* Notwithstanding the above, under no circumstances may you combine this
  8107. +* software in any way with any other Broadcom software provided under a
  8108. +* license other than the GPL, without Broadcom's express prior written
  8109. +* consent.
  8110. +*****************************************************************************/
  8111. +
  8112. +#include <linux/kernel.h>
  8113. +#include <linux/module.h>
  8114. +#include <linux/fs.h>
  8115. +#include <linux/device.h>
  8116. +#include <linux/cdev.h>
  8117. +#include <linux/mm.h>
  8118. +#include <linux/slab.h>
  8119. +#include <linux/debugfs.h>
  8120. +#include <asm/uaccess.h>
  8121. +#include <linux/dma-mapping.h>
  8122. +
  8123. +#ifdef CONFIG_ARCH_KONA
  8124. +#include <chal/chal_ipc.h>
  8125. +#elif CONFIG_ARCH_BCM2708
  8126. +#else
  8127. +#include <csp/chal_ipc.h>
  8128. +#endif
  8129. +
  8130. +#include "mach/vc_mem.h"
  8131. +#include <mach/vcio.h>
  8132. +
  8133. +#define DRIVER_NAME "vc-mem"
  8134. +
  8135. +// Device (/dev) related variables
  8136. +static dev_t vc_mem_devnum = 0;
  8137. +static struct class *vc_mem_class = NULL;
  8138. +static struct cdev vc_mem_cdev;
  8139. +static int vc_mem_inited = 0;
  8140. +
  8141. +#ifdef CONFIG_DEBUG_FS
  8142. +static struct dentry *vc_mem_debugfs_entry;
  8143. +#endif
  8144. +
  8145. +/*
  8146. + * Videocore memory addresses and size
  8147. + *
  8148. + * Drivers that wish to know the videocore memory addresses and sizes should
  8149. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  8150. + * headers. This allows the other drivers to not be tied down to a a certain
  8151. + * address/size at compile time.
  8152. + *
  8153. + * In the future, the goal is to have the videocore memory virtual address and
  8154. + * size be calculated at boot time rather than at compile time. The decision of
  8155. + * where the videocore memory resides and its size would be in the hands of the
  8156. + * bootloader (and/or kernel). When that happens, the values of these variables
  8157. + * would be calculated and assigned in the init function.
  8158. + */
  8159. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  8160. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  8161. +unsigned int mm_vc_mem_size = 0;
  8162. +unsigned int mm_vc_mem_base = 0;
  8163. +
  8164. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  8165. +EXPORT_SYMBOL(mm_vc_mem_size);
  8166. +EXPORT_SYMBOL(mm_vc_mem_base);
  8167. +
  8168. +static uint phys_addr = 0;
  8169. +static uint mem_size = 0;
  8170. +static uint mem_base = 0;
  8171. +
  8172. +
  8173. +/****************************************************************************
  8174. +*
  8175. +* vc_mem_open
  8176. +*
  8177. +***************************************************************************/
  8178. +
  8179. +static int
  8180. +vc_mem_open(struct inode *inode, struct file *file)
  8181. +{
  8182. + (void) inode;
  8183. + (void) file;
  8184. +
  8185. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  8186. +
  8187. + return 0;
  8188. +}
  8189. +
  8190. +/****************************************************************************
  8191. +*
  8192. +* vc_mem_release
  8193. +*
  8194. +***************************************************************************/
  8195. +
  8196. +static int
  8197. +vc_mem_release(struct inode *inode, struct file *file)
  8198. +{
  8199. + (void) inode;
  8200. + (void) file;
  8201. +
  8202. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  8203. +
  8204. + return 0;
  8205. +}
  8206. +
  8207. +/****************************************************************************
  8208. +*
  8209. +* vc_mem_get_size
  8210. +*
  8211. +***************************************************************************/
  8212. +
  8213. +static void
  8214. +vc_mem_get_size(void)
  8215. +{
  8216. +}
  8217. +
  8218. +/****************************************************************************
  8219. +*
  8220. +* vc_mem_get_base
  8221. +*
  8222. +***************************************************************************/
  8223. +
  8224. +static void
  8225. +vc_mem_get_base(void)
  8226. +{
  8227. +}
  8228. +
  8229. +/****************************************************************************
  8230. +*
  8231. +* vc_mem_get_current_size
  8232. +*
  8233. +***************************************************************************/
  8234. +
  8235. +int
  8236. +vc_mem_get_current_size(void)
  8237. +{
  8238. + return mm_vc_mem_size;
  8239. +}
  8240. +
  8241. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  8242. +
  8243. +/****************************************************************************
  8244. +*
  8245. +* vc_mem_ioctl
  8246. +*
  8247. +***************************************************************************/
  8248. +
  8249. +static long
  8250. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8251. +{
  8252. + int rc = 0;
  8253. +
  8254. + (void) cmd;
  8255. + (void) arg;
  8256. +
  8257. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  8258. +
  8259. + switch (cmd) {
  8260. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  8261. + {
  8262. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  8263. + __func__, (void *) mm_vc_mem_phys_addr);
  8264. +
  8265. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  8266. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  8267. + rc = -EFAULT;
  8268. + }
  8269. + break;
  8270. + }
  8271. + case VC_MEM_IOC_MEM_SIZE:
  8272. + {
  8273. + // Get the videocore memory size first
  8274. + vc_mem_get_size();
  8275. +
  8276. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  8277. + mm_vc_mem_size);
  8278. +
  8279. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  8280. + sizeof (mm_vc_mem_size)) != 0) {
  8281. + rc = -EFAULT;
  8282. + }
  8283. + break;
  8284. + }
  8285. + case VC_MEM_IOC_MEM_BASE:
  8286. + {
  8287. + // Get the videocore memory base
  8288. + vc_mem_get_base();
  8289. +
  8290. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  8291. + mm_vc_mem_base);
  8292. +
  8293. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  8294. + sizeof (mm_vc_mem_base)) != 0) {
  8295. + rc = -EFAULT;
  8296. + }
  8297. + break;
  8298. + }
  8299. + case VC_MEM_IOC_MEM_LOAD:
  8300. + {
  8301. + // Get the videocore memory base
  8302. + vc_mem_get_base();
  8303. +
  8304. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  8305. + mm_vc_mem_base);
  8306. +
  8307. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  8308. + sizeof (mm_vc_mem_base)) != 0) {
  8309. + rc = -EFAULT;
  8310. + }
  8311. + break;
  8312. + }
  8313. + default:
  8314. + {
  8315. + return -ENOTTY;
  8316. + }
  8317. + }
  8318. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  8319. +
  8320. + return rc;
  8321. +}
  8322. +
  8323. +/****************************************************************************
  8324. +*
  8325. +* vc_mem_mmap
  8326. +*
  8327. +***************************************************************************/
  8328. +
  8329. +static int
  8330. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  8331. +{
  8332. + int rc = 0;
  8333. + unsigned long length = vma->vm_end - vma->vm_start;
  8334. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  8335. +
  8336. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  8337. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  8338. + (long) vma->vm_pgoff);
  8339. +
  8340. + if (offset + length > mm_vc_mem_size) {
  8341. + pr_err("%s: length %ld is too big\n", __func__, length);
  8342. + return -EINVAL;
  8343. + }
  8344. + // Do not cache the memory map
  8345. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  8346. +
  8347. + rc = remap_pfn_range(vma, vma->vm_start,
  8348. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  8349. + vma->vm_pgoff, length, vma->vm_page_prot);
  8350. + if (rc != 0) {
  8351. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  8352. + }
  8353. +
  8354. + return rc;
  8355. +}
  8356. +
  8357. +/****************************************************************************
  8358. +*
  8359. +* File Operations for the driver.
  8360. +*
  8361. +***************************************************************************/
  8362. +
  8363. +static const struct file_operations vc_mem_fops = {
  8364. + .owner = THIS_MODULE,
  8365. + .open = vc_mem_open,
  8366. + .release = vc_mem_release,
  8367. + .unlocked_ioctl = vc_mem_ioctl,
  8368. + .mmap = vc_mem_mmap,
  8369. +};
  8370. +
  8371. +#ifdef CONFIG_DEBUG_FS
  8372. +static void vc_mem_debugfs_deinit(void)
  8373. +{
  8374. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  8375. + vc_mem_debugfs_entry = NULL;
  8376. +}
  8377. +
  8378. +
  8379. +static int vc_mem_debugfs_init(
  8380. + struct device *dev)
  8381. +{
  8382. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  8383. + if (!vc_mem_debugfs_entry) {
  8384. + dev_warn(dev, "could not create debugfs entry\n");
  8385. + return -EFAULT;
  8386. + }
  8387. +
  8388. + if (!debugfs_create_x32("vc_mem_phys_addr",
  8389. + 0444,
  8390. + vc_mem_debugfs_entry,
  8391. + (u32 *)&mm_vc_mem_phys_addr)) {
  8392. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  8393. + __func__);
  8394. + goto fail;
  8395. + }
  8396. +
  8397. + if (!debugfs_create_x32("vc_mem_size",
  8398. + 0444,
  8399. + vc_mem_debugfs_entry,
  8400. + (u32 *)&mm_vc_mem_size)) {
  8401. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  8402. + __func__);
  8403. + goto fail;
  8404. + }
  8405. +
  8406. + if (!debugfs_create_x32("vc_mem_base",
  8407. + 0444,
  8408. + vc_mem_debugfs_entry,
  8409. + (u32 *)&mm_vc_mem_base)) {
  8410. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  8411. + __func__);
  8412. + goto fail;
  8413. + }
  8414. +
  8415. + return 0;
  8416. +
  8417. +fail:
  8418. + vc_mem_debugfs_deinit();
  8419. + return -EFAULT;
  8420. +}
  8421. +
  8422. +#endif /* CONFIG_DEBUG_FS */
  8423. +
  8424. +
  8425. +/****************************************************************************
  8426. +*
  8427. +* vc_mem_init
  8428. +*
  8429. +***************************************************************************/
  8430. +
  8431. +static int __init
  8432. +vc_mem_init(void)
  8433. +{
  8434. + int rc = -EFAULT;
  8435. + struct device *dev;
  8436. +
  8437. + pr_debug("%s: called\n", __func__);
  8438. +
  8439. + mm_vc_mem_phys_addr = phys_addr;
  8440. + mm_vc_mem_size = mem_size;
  8441. + mm_vc_mem_base = mem_base;
  8442. +
  8443. + vc_mem_get_size();
  8444. +
  8445. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  8446. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  8447. +
  8448. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  8449. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  8450. + __func__, rc);
  8451. + goto out_err;
  8452. + }
  8453. +
  8454. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  8455. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  8456. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  8457. + goto out_unregister;
  8458. + }
  8459. +
  8460. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  8461. + if (IS_ERR(vc_mem_class)) {
  8462. + rc = PTR_ERR(vc_mem_class);
  8463. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  8464. + goto out_cdev_del;
  8465. + }
  8466. +
  8467. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  8468. + DRIVER_NAME);
  8469. + if (IS_ERR(dev)) {
  8470. + rc = PTR_ERR(dev);
  8471. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  8472. + goto out_class_destroy;
  8473. + }
  8474. +
  8475. +#ifdef CONFIG_DEBUG_FS
  8476. + /* don't fail if the debug entries cannot be created */
  8477. + vc_mem_debugfs_init(dev);
  8478. +#endif
  8479. +
  8480. + vc_mem_inited = 1;
  8481. + return 0;
  8482. +
  8483. + device_destroy(vc_mem_class, vc_mem_devnum);
  8484. +
  8485. + out_class_destroy:
  8486. + class_destroy(vc_mem_class);
  8487. + vc_mem_class = NULL;
  8488. +
  8489. + out_cdev_del:
  8490. + cdev_del(&vc_mem_cdev);
  8491. +
  8492. + out_unregister:
  8493. + unregister_chrdev_region(vc_mem_devnum, 1);
  8494. +
  8495. + out_err:
  8496. + return -1;
  8497. +}
  8498. +
  8499. +/****************************************************************************
  8500. +*
  8501. +* vc_mem_exit
  8502. +*
  8503. +***************************************************************************/
  8504. +
  8505. +static void __exit
  8506. +vc_mem_exit(void)
  8507. +{
  8508. + pr_debug("%s: called\n", __func__);
  8509. +
  8510. + if (vc_mem_inited) {
  8511. +#if CONFIG_DEBUG_FS
  8512. + vc_mem_debugfs_deinit();
  8513. +#endif
  8514. + device_destroy(vc_mem_class, vc_mem_devnum);
  8515. + class_destroy(vc_mem_class);
  8516. + cdev_del(&vc_mem_cdev);
  8517. + unregister_chrdev_region(vc_mem_devnum, 1);
  8518. + }
  8519. +}
  8520. +
  8521. +module_init(vc_mem_init);
  8522. +module_exit(vc_mem_exit);
  8523. +MODULE_LICENSE("GPL");
  8524. +MODULE_AUTHOR("Broadcom Corporation");
  8525. +
  8526. +module_param(phys_addr, uint, 0644);
  8527. +module_param(mem_size, uint, 0644);
  8528. +module_param(mem_base, uint, 0644);
  8529. +
  8530. diff -Nur linux-3.10.33/arch/arm/mach-bcm2708/vc_support.c linux-raspberry-pi/arch/arm/mach-bcm2708/vc_support.c
  8531. --- linux-3.10.33/arch/arm/mach-bcm2708/vc_support.c 1970-01-01 01:00:00.000000000 +0100
  8532. +++ linux-raspberry-pi/arch/arm/mach-bcm2708/vc_support.c 2014-03-13 12:46:12.432043725 +0100
  8533. @@ -0,0 +1,319 @@
  8534. +/*
  8535. + * vc_support.c
  8536. + *
  8537. + * Created on: 25 Nov 2012
  8538. + * Author: Simon
  8539. + */
  8540. +
  8541. +#include <linux/module.h>
  8542. +#include <mach/vcio.h>
  8543. +
  8544. +#ifdef ECLIPSE_IGNORE
  8545. +
  8546. +#define __user
  8547. +#define __init
  8548. +#define __exit
  8549. +#define __iomem
  8550. +#define KERN_DEBUG
  8551. +#define KERN_ERR
  8552. +#define KERN_WARNING
  8553. +#define KERN_INFO
  8554. +#define _IOWR(a, b, c) b
  8555. +#define _IOW(a, b, c) b
  8556. +#define _IO(a, b) b
  8557. +
  8558. +#endif
  8559. +
  8560. +/****** VC MAILBOX FUNCTIONALITY ******/
  8561. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags)
  8562. +{
  8563. + struct vc_msg
  8564. + {
  8565. + unsigned int m_msgSize;
  8566. + unsigned int m_response;
  8567. +
  8568. + struct vc_tag
  8569. + {
  8570. + unsigned int m_tagId;
  8571. + unsigned int m_sendBufferSize;
  8572. + union {
  8573. + unsigned int m_sendDataSize;
  8574. + unsigned int m_recvDataSize;
  8575. + };
  8576. +
  8577. + struct args
  8578. + {
  8579. + union {
  8580. + unsigned int m_size;
  8581. + unsigned int m_handle;
  8582. + };
  8583. + unsigned int m_alignment;
  8584. + unsigned int m_flags;
  8585. + } m_args;
  8586. + } m_tag;
  8587. +
  8588. + unsigned int m_endTag;
  8589. + } msg;
  8590. + int s;
  8591. +
  8592. + msg.m_msgSize = sizeof(msg);
  8593. + msg.m_response = 0;
  8594. + msg.m_endTag = 0;
  8595. +
  8596. + //fill in the tag for the allocation command
  8597. + msg.m_tag.m_tagId = 0x3000c;
  8598. + msg.m_tag.m_sendBufferSize = 12;
  8599. + msg.m_tag.m_sendDataSize = 12;
  8600. +
  8601. + //fill in our args
  8602. + msg.m_tag.m_args.m_size = size;
  8603. + msg.m_tag.m_args.m_alignment = alignment;
  8604. + msg.m_tag.m_args.m_flags = flags;
  8605. +
  8606. + //run the command
  8607. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8608. +
  8609. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8610. + {
  8611. + *pHandle = msg.m_tag.m_args.m_handle;
  8612. + return 0;
  8613. + }
  8614. + else
  8615. + {
  8616. + printk(KERN_ERR "failed to allocate vc memory: s=%d response=%08x recv data size=%08x\n",
  8617. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8618. + return 1;
  8619. + }
  8620. +}
  8621. +
  8622. +unsigned int ReleaseVcMemory(unsigned int handle)
  8623. +{
  8624. + struct vc_msg
  8625. + {
  8626. + unsigned int m_msgSize;
  8627. + unsigned int m_response;
  8628. +
  8629. + struct vc_tag
  8630. + {
  8631. + unsigned int m_tagId;
  8632. + unsigned int m_sendBufferSize;
  8633. + union {
  8634. + unsigned int m_sendDataSize;
  8635. + unsigned int m_recvDataSize;
  8636. + };
  8637. +
  8638. + struct args
  8639. + {
  8640. + union {
  8641. + unsigned int m_handle;
  8642. + unsigned int m_error;
  8643. + };
  8644. + } m_args;
  8645. + } m_tag;
  8646. +
  8647. + unsigned int m_endTag;
  8648. + } msg;
  8649. + int s;
  8650. +
  8651. + msg.m_msgSize = sizeof(msg);
  8652. + msg.m_response = 0;
  8653. + msg.m_endTag = 0;
  8654. +
  8655. + //fill in the tag for the release command
  8656. + msg.m_tag.m_tagId = 0x3000f;
  8657. + msg.m_tag.m_sendBufferSize = 4;
  8658. + msg.m_tag.m_sendDataSize = 4;
  8659. +
  8660. + //pass across the handle
  8661. + msg.m_tag.m_args.m_handle = handle;
  8662. +
  8663. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8664. +
  8665. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  8666. + return 0;
  8667. + else
  8668. + {
  8669. + printk(KERN_ERR "failed to release vc memory: s=%d response=%08x recv data size=%08x error=%08x\n",
  8670. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  8671. + return 1;
  8672. + }
  8673. +}
  8674. +
  8675. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle)
  8676. +{
  8677. + struct vc_msg
  8678. + {
  8679. + unsigned int m_msgSize;
  8680. + unsigned int m_response;
  8681. +
  8682. + struct vc_tag
  8683. + {
  8684. + unsigned int m_tagId;
  8685. + unsigned int m_sendBufferSize;
  8686. + union {
  8687. + unsigned int m_sendDataSize;
  8688. + unsigned int m_recvDataSize;
  8689. + };
  8690. +
  8691. + struct args
  8692. + {
  8693. + union {
  8694. + unsigned int m_handle;
  8695. + unsigned int m_busAddress;
  8696. + };
  8697. + } m_args;
  8698. + } m_tag;
  8699. +
  8700. + unsigned int m_endTag;
  8701. + } msg;
  8702. + int s;
  8703. +
  8704. + msg.m_msgSize = sizeof(msg);
  8705. + msg.m_response = 0;
  8706. + msg.m_endTag = 0;
  8707. +
  8708. + //fill in the tag for the lock command
  8709. + msg.m_tag.m_tagId = 0x3000d;
  8710. + msg.m_tag.m_sendBufferSize = 4;
  8711. + msg.m_tag.m_sendDataSize = 4;
  8712. +
  8713. + //pass across the handle
  8714. + msg.m_tag.m_args.m_handle = handle;
  8715. +
  8716. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8717. +
  8718. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8719. + {
  8720. + //pick out the bus address
  8721. + *pBusAddress = msg.m_tag.m_args.m_busAddress;
  8722. + return 0;
  8723. + }
  8724. + else
  8725. + {
  8726. + printk(KERN_ERR "failed to lock vc memory: s=%d response=%08x recv data size=%08x\n",
  8727. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8728. + return 1;
  8729. + }
  8730. +}
  8731. +
  8732. +unsigned int UnlockVcMemory(unsigned int handle)
  8733. +{
  8734. + struct vc_msg
  8735. + {
  8736. + unsigned int m_msgSize;
  8737. + unsigned int m_response;
  8738. +
  8739. + struct vc_tag
  8740. + {
  8741. + unsigned int m_tagId;
  8742. + unsigned int m_sendBufferSize;
  8743. + union {
  8744. + unsigned int m_sendDataSize;
  8745. + unsigned int m_recvDataSize;
  8746. + };
  8747. +
  8748. + struct args
  8749. + {
  8750. + union {
  8751. + unsigned int m_handle;
  8752. + unsigned int m_error;
  8753. + };
  8754. + } m_args;
  8755. + } m_tag;
  8756. +
  8757. + unsigned int m_endTag;
  8758. + } msg;
  8759. + int s;
  8760. +
  8761. + msg.m_msgSize = sizeof(msg);
  8762. + msg.m_response = 0;
  8763. + msg.m_endTag = 0;
  8764. +
  8765. + //fill in the tag for the unlock command
  8766. + msg.m_tag.m_tagId = 0x3000e;
  8767. + msg.m_tag.m_sendBufferSize = 4;
  8768. + msg.m_tag.m_sendDataSize = 4;
  8769. +
  8770. + //pass across the handle
  8771. + msg.m_tag.m_args.m_handle = handle;
  8772. +
  8773. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8774. +
  8775. + //check the error code too
  8776. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  8777. + return 0;
  8778. + else
  8779. + {
  8780. + printk(KERN_ERR "failed to unlock vc memory: s=%d response=%08x recv data size=%08x error%08x\n",
  8781. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  8782. + return 1;
  8783. + }
  8784. +}
  8785. +
  8786. +unsigned int ExecuteVcCode(unsigned int code,
  8787. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5)
  8788. +{
  8789. + struct vc_msg
  8790. + {
  8791. + unsigned int m_msgSize;
  8792. + unsigned int m_response;
  8793. +
  8794. + struct vc_tag
  8795. + {
  8796. + unsigned int m_tagId;
  8797. + unsigned int m_sendBufferSize;
  8798. + union {
  8799. + unsigned int m_sendDataSize;
  8800. + unsigned int m_recvDataSize;
  8801. + };
  8802. +
  8803. + struct args
  8804. + {
  8805. + union {
  8806. + unsigned int m_pCode;
  8807. + unsigned int m_return;
  8808. + };
  8809. + unsigned int m_r0;
  8810. + unsigned int m_r1;
  8811. + unsigned int m_r2;
  8812. + unsigned int m_r3;
  8813. + unsigned int m_r4;
  8814. + unsigned int m_r5;
  8815. + } m_args;
  8816. + } m_tag;
  8817. +
  8818. + unsigned int m_endTag;
  8819. + } msg;
  8820. + int s;
  8821. +
  8822. + msg.m_msgSize = sizeof(msg);
  8823. + msg.m_response = 0;
  8824. + msg.m_endTag = 0;
  8825. +
  8826. + //fill in the tag for the unlock command
  8827. + msg.m_tag.m_tagId = 0x30010;
  8828. + msg.m_tag.m_sendBufferSize = 28;
  8829. + msg.m_tag.m_sendDataSize = 28;
  8830. +
  8831. + //pass across the handle
  8832. + msg.m_tag.m_args.m_pCode = code;
  8833. + msg.m_tag.m_args.m_r0 = r0;
  8834. + msg.m_tag.m_args.m_r1 = r1;
  8835. + msg.m_tag.m_args.m_r2 = r2;
  8836. + msg.m_tag.m_args.m_r3 = r3;
  8837. + msg.m_tag.m_args.m_r4 = r4;
  8838. + msg.m_tag.m_args.m_r5 = r5;
  8839. +
  8840. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8841. +
  8842. + //check the error code too
  8843. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8844. + return msg.m_tag.m_args.m_return;
  8845. + else
  8846. + {
  8847. + printk(KERN_ERR "failed to execute: s=%d response=%08x recv data size=%08x\n",
  8848. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8849. + return 1;
  8850. + }
  8851. +}
  8852. +
  8853. diff -Nur linux-3.10.33/arch/arm/Makefile linux-raspberry-pi/arch/arm/Makefile
  8854. --- linux-3.10.33/arch/arm/Makefile 2014-03-07 06:58:45.000000000 +0100
  8855. +++ linux-raspberry-pi/arch/arm/Makefile 2014-03-13 12:46:12.260043381 +0100
  8856. @@ -139,6 +139,7 @@
  8857. # by CONFIG_* macro name.
  8858. machine-$(CONFIG_ARCH_AT91) += at91
  8859. machine-$(CONFIG_ARCH_BCM) += bcm
  8860. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  8861. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  8862. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  8863. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  8864. diff -Nur linux-3.10.33/arch/arm/mm/Kconfig linux-raspberry-pi/arch/arm/mm/Kconfig
  8865. --- linux-3.10.33/arch/arm/mm/Kconfig 2014-03-07 06:58:45.000000000 +0100
  8866. +++ linux-raspberry-pi/arch/arm/mm/Kconfig 2014-03-13 12:46:12.764044389 +0100
  8867. @@ -358,7 +358,7 @@
  8868. # ARMv6
  8869. config CPU_V6
  8870. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  8871. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  8872. select CPU_32v6
  8873. select CPU_ABRT_EV6
  8874. select CPU_CACHE_V6
  8875. diff -Nur linux-3.10.33/arch/arm/mm/proc-v6.S linux-raspberry-pi/arch/arm/mm/proc-v6.S
  8876. --- linux-3.10.33/arch/arm/mm/proc-v6.S 2014-03-07 06:58:45.000000000 +0100
  8877. +++ linux-raspberry-pi/arch/arm/mm/proc-v6.S 2014-03-13 12:46:12.772044405 +0100
  8878. @@ -73,10 +73,19 @@
  8879. *
  8880. * IRQs are already disabled.
  8881. */
  8882. +
  8883. +/* See jira SW-5991 for details of this workaround */
  8884. ENTRY(cpu_v6_do_idle)
  8885. - mov r1, #0
  8886. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  8887. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  8888. + .align 5
  8889. + mov r1, #2
  8890. +1: subs r1, #1
  8891. + nop
  8892. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  8893. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  8894. + nop
  8895. + nop
  8896. + nop
  8897. + bne 1b
  8898. mov pc, lr
  8899. ENTRY(cpu_v6_dcache_clean_area)
  8900. diff -Nur linux-3.10.33/arch/arm/tools/mach-types linux-raspberry-pi/arch/arm/tools/mach-types
  8901. --- linux-3.10.33/arch/arm/tools/mach-types 2014-03-07 06:58:45.000000000 +0100
  8902. +++ linux-raspberry-pi/arch/arm/tools/mach-types 2014-03-13 12:46:12.828044517 +0100
  8903. @@ -522,6 +522,7 @@
  8904. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  8905. paz00 MACH_PAZ00 PAZ00 3128
  8906. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  8907. +bcm2708 MACH_BCM2708 BCM2708 3138
  8908. ag5evm MACH_AG5EVM AG5EVM 3189
  8909. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  8910. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  8911. diff -Nur linux-3.10.33/Documentation/video4linux/bcm2835-v4l2.txt linux-raspberry-pi/Documentation/video4linux/bcm2835-v4l2.txt
  8912. --- linux-3.10.33/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  8913. +++ linux-raspberry-pi/Documentation/video4linux/bcm2835-v4l2.txt 2014-03-13 12:46:12.092043045 +0100
  8914. @@ -0,0 +1,60 @@
  8915. +
  8916. +BCM2835 (aka Raspberry Pi) V4L2 driver
  8917. +======================================
  8918. +
  8919. +1. Copyright
  8920. +============
  8921. +
  8922. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  8923. +
  8924. +2. License
  8925. +==========
  8926. +
  8927. +This program is free software; you can redistribute it and/or modify
  8928. +it under the terms of the GNU General Public License as published by
  8929. +the Free Software Foundation; either version 2 of the License, or
  8930. +(at your option) any later version.
  8931. +
  8932. +This program is distributed in the hope that it will be useful,
  8933. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  8934. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8935. +GNU General Public License for more details.
  8936. +
  8937. +You should have received a copy of the GNU General Public License
  8938. +along with this program; if not, write to the Free Software
  8939. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  8940. +
  8941. +3. Quick Start
  8942. +==============
  8943. +
  8944. +You need a version 1.0 or later of v4l2-ctl, available from:
  8945. + git://git.linuxtv.org/v4l-utils.git
  8946. +
  8947. +$ sudo modprobe bcm2835-v4l2
  8948. +
  8949. +Turn on the overlay:
  8950. +
  8951. +$ v4l2-ctl --overlay=1
  8952. +
  8953. +Turn off the overlay:
  8954. +
  8955. +$ v4l2-ctl --overlay=0
  8956. +
  8957. +Set the capture format for video:
  8958. +
  8959. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  8960. +
  8961. +(Note: 1088 not 1080).
  8962. +
  8963. +Capture:
  8964. +
  8965. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  8966. +
  8967. +Stills capture:
  8968. +
  8969. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  8970. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  8971. +
  8972. +List of available formats:
  8973. +
  8974. +$ v4l2-ctl --list-formats
  8975. diff -Nur linux-3.10.33/drivers/char/broadcom/Kconfig linux-raspberry-pi/drivers/char/broadcom/Kconfig
  8976. --- linux-3.10.33/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  8977. +++ linux-raspberry-pi/drivers/char/broadcom/Kconfig 2014-03-13 12:46:15.356049576 +0100
  8978. @@ -0,0 +1,16 @@
  8979. +#
  8980. +# Broadcom char driver config
  8981. +#
  8982. +
  8983. +menuconfig BRCM_CHAR_DRIVERS
  8984. + bool "Broadcom Char Drivers"
  8985. + help
  8986. + Broadcom's char drivers
  8987. +
  8988. +config BCM_VC_CMA
  8989. + bool "Videocore CMA"
  8990. + depends on CMA && BRCM_CHAR_DRIVERS
  8991. + default n
  8992. + help
  8993. + Helper for videocore CMA access.
  8994. +
  8995. diff -Nur linux-3.10.33/drivers/char/broadcom/Makefile linux-raspberry-pi/drivers/char/broadcom/Makefile
  8996. --- linux-3.10.33/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  8997. +++ linux-raspberry-pi/drivers/char/broadcom/Makefile 2014-03-13 12:46:15.356049576 +0100
  8998. @@ -0,0 +1,2 @@
  8999. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  9000. +
  9001. diff -Nur linux-3.10.33/drivers/char/broadcom/vc_cma/Makefile linux-raspberry-pi/drivers/char/broadcom/vc_cma/Makefile
  9002. --- linux-3.10.33/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  9003. +++ linux-raspberry-pi/drivers/char/broadcom/vc_cma/Makefile 2014-03-13 12:46:15.356049576 +0100
  9004. @@ -0,0 +1,14 @@
  9005. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  9006. +ccflags-y += -Werror
  9007. +ccflags-y += -Idrivers/misc/vc04_services
  9008. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  9009. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  9010. +
  9011. +ccflags-y += -D__KERNEL__
  9012. +ccflags-y += -D__linux__
  9013. +ccflags-y += -Werror
  9014. +
  9015. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  9016. +
  9017. +vc-cma-objs := vc_cma.o
  9018. +
  9019. diff -Nur linux-3.10.33/drivers/char/broadcom/vc_cma/vc_cma.c linux-raspberry-pi/drivers/char/broadcom/vc_cma/vc_cma.c
  9020. --- linux-3.10.33/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  9021. +++ linux-raspberry-pi/drivers/char/broadcom/vc_cma/vc_cma.c 2014-03-13 12:46:15.356049576 +0100
  9022. @@ -0,0 +1,1143 @@
  9023. +/**
  9024. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  9025. + *
  9026. + * Redistribution and use in source and binary forms, with or without
  9027. + * modification, are permitted provided that the following conditions
  9028. + * are met:
  9029. + * 1. Redistributions of source code must retain the above copyright
  9030. + * notice, this list of conditions, and the following disclaimer,
  9031. + * without modification.
  9032. + * 2. Redistributions in binary form must reproduce the above copyright
  9033. + * notice, this list of conditions and the following disclaimer in the
  9034. + * documentation and/or other materials provided with the distribution.
  9035. + * 3. The names of the above-listed copyright holders may not be used
  9036. + * to endorse or promote products derived from this software without
  9037. + * specific prior written permission.
  9038. + *
  9039. + * ALTERNATIVELY, this software may be distributed under the terms of the
  9040. + * GNU General Public License ("GPL") version 2, as published by the Free
  9041. + * Software Foundation.
  9042. + *
  9043. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  9044. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  9045. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  9046. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  9047. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  9048. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  9049. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  9050. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  9051. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  9052. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  9053. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9054. + */
  9055. +
  9056. +#include <linux/kernel.h>
  9057. +#include <linux/module.h>
  9058. +#include <linux/kthread.h>
  9059. +#include <linux/fs.h>
  9060. +#include <linux/device.h>
  9061. +#include <linux/cdev.h>
  9062. +#include <linux/mm.h>
  9063. +#include <linux/proc_fs.h>
  9064. +#include <linux/seq_file.h>
  9065. +#include <linux/dma-mapping.h>
  9066. +#include <linux/dma-contiguous.h>
  9067. +#include <linux/platform_device.h>
  9068. +#include <linux/uaccess.h>
  9069. +#include <asm/cacheflush.h>
  9070. +
  9071. +#include <linux/broadcom/vc_cma.h>
  9072. +
  9073. +#include "vchiq_util.h"
  9074. +#include "vchiq_connected.h"
  9075. +//#include "debug_sym.h"
  9076. +//#include "vc_mem.h"
  9077. +
  9078. +#define DRIVER_NAME "vc-cma"
  9079. +
  9080. +#define LOG_DBG(fmt, ...) \
  9081. + if (vc_cma_debug) \
  9082. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  9083. +#define LOG_ERR(fmt, ...) \
  9084. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  9085. +
  9086. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  9087. +#define VC_CMA_VERSION 2
  9088. +
  9089. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  9090. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  9091. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  9092. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  9093. +#define VC_CMA_RESERVE_COUNT_MAX 16
  9094. +
  9095. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  9096. +
  9097. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  9098. +
  9099. +#define loud_error(...) \
  9100. + LOG_ERR("===== " __VA_ARGS__)
  9101. +
  9102. +enum {
  9103. + VC_CMA_MSG_QUIT,
  9104. + VC_CMA_MSG_OPEN,
  9105. + VC_CMA_MSG_TICK,
  9106. + VC_CMA_MSG_ALLOC, /* chunk count */
  9107. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  9108. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  9109. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  9110. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  9111. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  9112. + VC_CMA_MSG_UPDATE_RESERVE,
  9113. + VC_CMA_MSG_MAX
  9114. +};
  9115. +
  9116. +struct cma_msg {
  9117. + unsigned short type;
  9118. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  9119. +};
  9120. +
  9121. +struct vc_cma_reserve_user {
  9122. + unsigned int pid;
  9123. + unsigned int reserve;
  9124. +};
  9125. +
  9126. +/* Device (/dev) related variables */
  9127. +static dev_t vc_cma_devnum;
  9128. +static struct class *vc_cma_class;
  9129. +static struct cdev vc_cma_cdev;
  9130. +static int vc_cma_inited;
  9131. +static int vc_cma_debug;
  9132. +
  9133. +/* Proc entry */
  9134. +static struct proc_dir_entry *vc_cma_proc_entry;
  9135. +
  9136. +phys_addr_t vc_cma_base;
  9137. +struct page *vc_cma_base_page;
  9138. +unsigned int vc_cma_size;
  9139. +EXPORT_SYMBOL(vc_cma_size);
  9140. +unsigned int vc_cma_initial;
  9141. +unsigned int vc_cma_chunks;
  9142. +unsigned int vc_cma_chunks_used;
  9143. +unsigned int vc_cma_chunks_reserved;
  9144. +
  9145. +static int in_loud_error;
  9146. +
  9147. +unsigned int vc_cma_reserve_total;
  9148. +unsigned int vc_cma_reserve_count;
  9149. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  9150. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  9151. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  9152. +
  9153. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  9154. +static struct platform_device vc_cma_device = {
  9155. + .name = "vc-cma",
  9156. + .id = 0,
  9157. + .dev = {
  9158. + .dma_mask = &vc_cma_dma_mask,
  9159. + .coherent_dma_mask = DMA_BIT_MASK(32),
  9160. + },
  9161. +};
  9162. +
  9163. +static VCHIQ_INSTANCE_T cma_instance;
  9164. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  9165. +static VCHIU_QUEUE_T cma_msg_queue;
  9166. +static struct task_struct *cma_worker;
  9167. +
  9168. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  9169. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  9170. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  9171. + VCHIQ_HEADER_T * header,
  9172. + VCHIQ_SERVICE_HANDLE_T service,
  9173. + void *bulk_userdata);
  9174. +static void send_vc_msg(unsigned short type,
  9175. + unsigned short param1, unsigned short param2);
  9176. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  9177. +
  9178. +static int early_vc_cma_mem(char *p)
  9179. +{
  9180. + unsigned int new_size;
  9181. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  9182. + vc_cma_size = memparse(p, &p);
  9183. + vc_cma_initial = vc_cma_size;
  9184. + if (*p == '/')
  9185. + vc_cma_size = memparse(p + 1, &p);
  9186. + if (*p == '@')
  9187. + vc_cma_base = memparse(p + 1, &p);
  9188. +
  9189. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  9190. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9191. + if (new_size > vc_cma_size)
  9192. + vc_cma_size = 0;
  9193. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  9194. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9195. + if (vc_cma_initial > vc_cma_size)
  9196. + vc_cma_initial = vc_cma_size;
  9197. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  9198. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9199. +
  9200. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  9201. + vc_cma_size, (unsigned int)vc_cma_base);
  9202. +
  9203. + return 0;
  9204. +}
  9205. +
  9206. +early_param("vc-cma-mem", early_vc_cma_mem);
  9207. +
  9208. +void vc_cma_early_init(void)
  9209. +{
  9210. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  9211. + if (vc_cma_size) {
  9212. + int rc = platform_device_register(&vc_cma_device);
  9213. + LOG_DBG("platform_device_register -> %d", rc);
  9214. + }
  9215. +}
  9216. +
  9217. +void vc_cma_reserve(void)
  9218. +{
  9219. + /* if vc_cma_size is set, then declare vc CMA area of the same
  9220. + * size from the end of memory
  9221. + */
  9222. + if (vc_cma_size) {
  9223. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  9224. + vc_cma_base, 0) == 0) {
  9225. + } else {
  9226. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  9227. + vc_cma_size, (unsigned int)vc_cma_base);
  9228. + vc_cma_size = 0;
  9229. + }
  9230. + }
  9231. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  9232. +}
  9233. +
  9234. +/****************************************************************************
  9235. +*
  9236. +* vc_cma_open
  9237. +*
  9238. +***************************************************************************/
  9239. +
  9240. +static int vc_cma_open(struct inode *inode, struct file *file)
  9241. +{
  9242. + (void)inode;
  9243. + (void)file;
  9244. +
  9245. + return 0;
  9246. +}
  9247. +
  9248. +/****************************************************************************
  9249. +*
  9250. +* vc_cma_release
  9251. +*
  9252. +***************************************************************************/
  9253. +
  9254. +static int vc_cma_release(struct inode *inode, struct file *file)
  9255. +{
  9256. + (void)inode;
  9257. + (void)file;
  9258. +
  9259. + vc_cma_set_reserve(0, current->tgid);
  9260. +
  9261. + return 0;
  9262. +}
  9263. +
  9264. +/****************************************************************************
  9265. +*
  9266. +* vc_cma_ioctl
  9267. +*
  9268. +***************************************************************************/
  9269. +
  9270. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  9271. +{
  9272. + int rc = 0;
  9273. +
  9274. + (void)cmd;
  9275. + (void)arg;
  9276. +
  9277. + switch (cmd) {
  9278. + case VC_CMA_IOC_RESERVE:
  9279. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  9280. + if (rc >= 0)
  9281. + rc = 0;
  9282. + break;
  9283. + default:
  9284. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  9285. + return -ENOTTY;
  9286. + }
  9287. +
  9288. + return rc;
  9289. +}
  9290. +
  9291. +/****************************************************************************
  9292. +*
  9293. +* File Operations for the driver.
  9294. +*
  9295. +***************************************************************************/
  9296. +
  9297. +static const struct file_operations vc_cma_fops = {
  9298. + .owner = THIS_MODULE,
  9299. + .open = vc_cma_open,
  9300. + .release = vc_cma_release,
  9301. + .unlocked_ioctl = vc_cma_ioctl,
  9302. +};
  9303. +
  9304. +/****************************************************************************
  9305. +*
  9306. +* vc_cma_proc_open
  9307. +*
  9308. +***************************************************************************/
  9309. +
  9310. +static int vc_cma_show_info(struct seq_file *m, void *v)
  9311. +{
  9312. + int i;
  9313. +
  9314. + seq_printf(m, "Videocore CMA:\n");
  9315. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  9316. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  9317. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  9318. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  9319. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  9320. + (int)vc_cma_chunks,
  9321. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  9322. + seq_printf(m, " Used : %4d (%d bytes)\n",
  9323. + (int)vc_cma_chunks_used,
  9324. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  9325. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  9326. + (unsigned int)vc_cma_chunks_reserved,
  9327. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  9328. +
  9329. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9330. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  9331. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  9332. + user->reserve);
  9333. + }
  9334. +
  9335. + seq_printf(m, "\n");
  9336. +
  9337. + return 0;
  9338. +}
  9339. +
  9340. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  9341. +{
  9342. + return single_open(file, vc_cma_show_info, NULL);
  9343. +}
  9344. +
  9345. +/****************************************************************************
  9346. +*
  9347. +* vc_cma_proc_write
  9348. +*
  9349. +***************************************************************************/
  9350. +
  9351. +static int vc_cma_proc_write(struct file *file,
  9352. + const char __user *buffer,
  9353. + size_t size, loff_t *ppos)
  9354. +{
  9355. + int rc = -EFAULT;
  9356. + char input_str[20];
  9357. +
  9358. + memset(input_str, 0, sizeof(input_str));
  9359. +
  9360. + if (size > sizeof(input_str)) {
  9361. + LOG_ERR("%s: input string length too long", __func__);
  9362. + goto out;
  9363. + }
  9364. +
  9365. + if (copy_from_user(input_str, buffer, size - 1)) {
  9366. + LOG_ERR("%s: failed to get input string", __func__);
  9367. + goto out;
  9368. + }
  9369. +#define ALLOC_STR "alloc"
  9370. +#define FREE_STR "free"
  9371. +#define DEBUG_STR "debug"
  9372. +#define RESERVE_STR "reserve"
  9373. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  9374. + int size;
  9375. + char *p = input_str + strlen(ALLOC_STR);
  9376. +
  9377. + while (*p == ' ')
  9378. + p++;
  9379. + size = memparse(p, NULL);
  9380. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  9381. + if (size)
  9382. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  9383. + size / VC_CMA_CHUNK_SIZE, 0);
  9384. + else
  9385. + LOG_ERR("invalid size '%s'", p);
  9386. + rc = size;
  9387. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  9388. + int size;
  9389. + char *p = input_str + strlen(FREE_STR);
  9390. +
  9391. + while (*p == ' ')
  9392. + p++;
  9393. + size = memparse(p, NULL);
  9394. + LOG_ERR("/proc/vc-cma: free %d", size);
  9395. + if (size)
  9396. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  9397. + size / VC_CMA_CHUNK_SIZE, 0);
  9398. + else
  9399. + LOG_ERR("invalid size '%s'", p);
  9400. + rc = size;
  9401. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  9402. + char *p = input_str + strlen(DEBUG_STR);
  9403. + while (*p == ' ')
  9404. + p++;
  9405. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  9406. + vc_cma_debug = 1;
  9407. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  9408. + vc_cma_debug = 0;
  9409. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  9410. + rc = size;
  9411. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  9412. + int size;
  9413. + int reserved;
  9414. + char *p = input_str + strlen(RESERVE_STR);
  9415. + while (*p == ' ')
  9416. + p++;
  9417. + size = memparse(p, NULL);
  9418. +
  9419. + reserved = vc_cma_set_reserve(size, current->tgid);
  9420. + rc = (reserved >= 0) ? size : reserved;
  9421. + }
  9422. +
  9423. +out:
  9424. + return rc;
  9425. +}
  9426. +
  9427. +/****************************************************************************
  9428. +*
  9429. +* File Operations for /proc interface.
  9430. +*
  9431. +***************************************************************************/
  9432. +
  9433. +static const struct file_operations vc_cma_proc_fops = {
  9434. + .open = vc_cma_proc_open,
  9435. + .read = seq_read,
  9436. + .write = vc_cma_proc_write,
  9437. + .llseek = seq_lseek,
  9438. + .release = single_release
  9439. +};
  9440. +
  9441. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  9442. +{
  9443. + struct vc_cma_reserve_user *user = NULL;
  9444. + int delta = 0;
  9445. + int i;
  9446. +
  9447. + if (down_interruptible(&vc_cma_reserve_mutex))
  9448. + return -ERESTARTSYS;
  9449. +
  9450. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9451. + if (pid == vc_cma_reserve_users[i].pid) {
  9452. + user = &vc_cma_reserve_users[i];
  9453. + delta = reserve - user->reserve;
  9454. + if (reserve)
  9455. + user->reserve = reserve;
  9456. + else {
  9457. + /* Remove this entry by copying downwards */
  9458. + while ((i + 1) < vc_cma_reserve_count) {
  9459. + user[0].pid = user[1].pid;
  9460. + user[0].reserve = user[1].reserve;
  9461. + user++;
  9462. + i++;
  9463. + }
  9464. + vc_cma_reserve_count--;
  9465. + user = NULL;
  9466. + }
  9467. + break;
  9468. + }
  9469. + }
  9470. +
  9471. + if (reserve && !user) {
  9472. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  9473. + LOG_ERR("vc-cma: Too many reservations - "
  9474. + "increase CMA_RESERVE_COUNT_MAX");
  9475. + up(&vc_cma_reserve_mutex);
  9476. + return -EBUSY;
  9477. + }
  9478. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  9479. + user->pid = pid;
  9480. + user->reserve = reserve;
  9481. + delta = reserve;
  9482. + vc_cma_reserve_count++;
  9483. + }
  9484. +
  9485. + vc_cma_reserve_total += delta;
  9486. +
  9487. + send_vc_msg(VC_CMA_MSG_RESERVE,
  9488. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  9489. +
  9490. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  9491. +
  9492. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  9493. + reserve, pid, vc_cma_reserve_total);
  9494. +
  9495. + up(&vc_cma_reserve_mutex);
  9496. +
  9497. + return vc_cma_reserve_total;
  9498. +}
  9499. +
  9500. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  9501. + VCHIQ_HEADER_T * header,
  9502. + VCHIQ_SERVICE_HANDLE_T service,
  9503. + void *bulk_userdata)
  9504. +{
  9505. + switch (reason) {
  9506. + case VCHIQ_MESSAGE_AVAILABLE:
  9507. + if (!send_worker_msg(header))
  9508. + return VCHIQ_RETRY;
  9509. + break;
  9510. + case VCHIQ_SERVICE_CLOSED:
  9511. + LOG_DBG("CMA service closed");
  9512. + break;
  9513. + default:
  9514. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  9515. + break;
  9516. + }
  9517. + return VCHIQ_SUCCESS;
  9518. +}
  9519. +
  9520. +static void send_vc_msg(unsigned short type,
  9521. + unsigned short param1, unsigned short param2)
  9522. +{
  9523. + unsigned short msg[] = { type, param1, param2 };
  9524. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  9525. + VCHIQ_STATUS_T ret;
  9526. + vchiq_use_service(cma_service);
  9527. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9528. + vchiq_release_service(cma_service);
  9529. + if (ret != VCHIQ_SUCCESS)
  9530. + LOG_ERR("vchiq_queue_message returned %x", ret);
  9531. +}
  9532. +
  9533. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  9534. +{
  9535. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  9536. + return false;
  9537. + vchiu_queue_push(&cma_msg_queue, msg);
  9538. + up(&vc_cma_worker_queue_push_mutex);
  9539. + return true;
  9540. +}
  9541. +
  9542. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  9543. +{
  9544. + int i;
  9545. + for (i = 0; i < num_chunks; i++) {
  9546. + struct page *chunk;
  9547. + unsigned int chunk_num;
  9548. + uint8_t *chunk_addr;
  9549. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  9550. +
  9551. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  9552. + PAGES_PER_CHUNK,
  9553. + VC_CMA_CHUNK_ORDER);
  9554. + if (!chunk)
  9555. + break;
  9556. +
  9557. + chunk_addr = page_address(chunk);
  9558. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  9559. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  9560. + chunk_size);
  9561. +
  9562. + chunk_num =
  9563. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  9564. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  9565. + VC_CMA_CHUNK_SIZE) != 0);
  9566. + if (chunk_num >= vc_cma_chunks) {
  9567. + LOG_ERR("%s: ===============================",
  9568. + __func__);
  9569. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  9570. + "bad SPARSEMEM configuration?",
  9571. + __func__, (unsigned int)page_to_phys(chunk),
  9572. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  9573. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  9574. + vc_cma_device.dev.cma_area);
  9575. + LOG_ERR("%s: ===============================",
  9576. + __func__);
  9577. + break;
  9578. + }
  9579. + reply->params[i] = chunk_num;
  9580. + vc_cma_chunks_used++;
  9581. + }
  9582. +
  9583. + if (i < num_chunks) {
  9584. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  9585. + "for %x bytes (alloc %d of %d, %d free)",
  9586. + __func__, VC_CMA_CHUNK_SIZE, i,
  9587. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  9588. + num_chunks = i;
  9589. + }
  9590. +
  9591. + LOG_DBG("CMA allocated %d chunks -> %d used",
  9592. + num_chunks, vc_cma_chunks_used);
  9593. + reply->type = VC_CMA_MSG_ALLOCATED;
  9594. +
  9595. + {
  9596. + VCHIQ_ELEMENT_T elem = {
  9597. + reply,
  9598. + offsetof(struct cma_msg, params[0]) +
  9599. + num_chunks * sizeof(reply->params[0])
  9600. + };
  9601. + VCHIQ_STATUS_T ret;
  9602. + vchiq_use_service(cma_service);
  9603. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9604. + vchiq_release_service(cma_service);
  9605. + if (ret != VCHIQ_SUCCESS)
  9606. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  9607. + }
  9608. +
  9609. + return num_chunks;
  9610. +}
  9611. +
  9612. +static int cma_worker_proc(void *param)
  9613. +{
  9614. + static struct cma_msg reply;
  9615. + (void)param;
  9616. +
  9617. + while (1) {
  9618. + VCHIQ_HEADER_T *msg;
  9619. + static struct cma_msg msg_copy;
  9620. + struct cma_msg *cma_msg = &msg_copy;
  9621. + int type, msg_size;
  9622. +
  9623. + msg = vchiu_queue_pop(&cma_msg_queue);
  9624. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  9625. + msg_size = msg->size;
  9626. + memcpy(&msg_copy, msg->data, msg_size);
  9627. + type = cma_msg->type;
  9628. + vchiq_release_message(cma_service, msg);
  9629. + } else {
  9630. + msg_size = 0;
  9631. + type = (int)msg;
  9632. + if (type == VC_CMA_MSG_QUIT)
  9633. + break;
  9634. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  9635. + msg = NULL;
  9636. + cma_msg = NULL;
  9637. + } else {
  9638. + BUG();
  9639. + continue;
  9640. + }
  9641. + }
  9642. +
  9643. + switch (type) {
  9644. + case VC_CMA_MSG_ALLOC:{
  9645. + int num_chunks, free_chunks;
  9646. + num_chunks = cma_msg->params[0];
  9647. + free_chunks =
  9648. + vc_cma_chunks - vc_cma_chunks_used;
  9649. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  9650. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  9651. + LOG_ERR
  9652. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9653. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  9654. + num_chunks,
  9655. + VC_CMA_MAX_PARAMS_PER_MSG);
  9656. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  9657. + }
  9658. +
  9659. + if (num_chunks > free_chunks) {
  9660. + LOG_ERR
  9661. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9662. + "exceeds free chunks (%d)",
  9663. + num_chunks, free_chunks);
  9664. + num_chunks = free_chunks;
  9665. + }
  9666. +
  9667. + vc_cma_alloc_chunks(num_chunks, &reply);
  9668. + }
  9669. + break;
  9670. +
  9671. + case VC_CMA_MSG_FREE:{
  9672. + int chunk_count =
  9673. + (msg_size -
  9674. + offsetof(struct cma_msg,
  9675. + params)) /
  9676. + sizeof(cma_msg->params[0]);
  9677. + int i;
  9678. + BUG_ON(chunk_count <= 0);
  9679. +
  9680. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  9681. + chunk_count, cma_msg->params[0]);
  9682. + for (i = 0; i < chunk_count; i++) {
  9683. + int chunk_num = cma_msg->params[i];
  9684. + struct page *page = vc_cma_base_page +
  9685. + chunk_num * PAGES_PER_CHUNK;
  9686. + if (chunk_num >= vc_cma_chunks) {
  9687. + LOG_ERR
  9688. + ("CMA_MSG_FREE - chunk %d of %d"
  9689. + " (value %x) exceeds maximum "
  9690. + "(%x)", i, chunk_count,
  9691. + chunk_num,
  9692. + vc_cma_chunks - 1);
  9693. + break;
  9694. + }
  9695. +
  9696. + if (!dma_release_from_contiguous
  9697. + (NULL /*&vc_cma_device.dev*/, page,
  9698. + PAGES_PER_CHUNK)) {
  9699. + LOG_ERR
  9700. + ("CMA_MSG_FREE - failed to "
  9701. + "release chunk %d (phys %x, "
  9702. + "page %x)", chunk_num,
  9703. + page_to_phys(page),
  9704. + (unsigned int)page);
  9705. + }
  9706. + vc_cma_chunks_used--;
  9707. + }
  9708. + LOG_DBG("CMA released %d chunks -> %d used",
  9709. + i, vc_cma_chunks_used);
  9710. + }
  9711. + break;
  9712. +
  9713. + case VC_CMA_MSG_UPDATE_RESERVE:{
  9714. + int chunks_needed =
  9715. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  9716. + 1)
  9717. + / VC_CMA_CHUNK_SIZE) -
  9718. + vc_cma_chunks_reserved;
  9719. +
  9720. + LOG_DBG
  9721. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  9722. + chunks_needed);
  9723. +
  9724. + /* Cap the reservations to what is available */
  9725. + if (chunks_needed > 0) {
  9726. + if (chunks_needed >
  9727. + (vc_cma_chunks -
  9728. + vc_cma_chunks_used))
  9729. + chunks_needed =
  9730. + (vc_cma_chunks -
  9731. + vc_cma_chunks_used);
  9732. +
  9733. + chunks_needed =
  9734. + vc_cma_alloc_chunks(chunks_needed,
  9735. + &reply);
  9736. + }
  9737. +
  9738. + LOG_DBG
  9739. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  9740. + chunks_needed);
  9741. + vc_cma_chunks_reserved += chunks_needed;
  9742. + }
  9743. + break;
  9744. +
  9745. + default:
  9746. + LOG_ERR("unexpected msg type %d", type);
  9747. + break;
  9748. + }
  9749. + }
  9750. +
  9751. + LOG_DBG("quitting...");
  9752. + return 0;
  9753. +}
  9754. +
  9755. +/****************************************************************************
  9756. +*
  9757. +* vc_cma_connected_init
  9758. +*
  9759. +* This function is called once the videocore has been connected.
  9760. +*
  9761. +***************************************************************************/
  9762. +
  9763. +static void vc_cma_connected_init(void)
  9764. +{
  9765. + VCHIQ_SERVICE_PARAMS_T service_params;
  9766. +
  9767. + LOG_DBG("vc_cma_connected_init");
  9768. +
  9769. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  9770. + LOG_ERR("could not create CMA msg queue");
  9771. + goto fail_queue;
  9772. + }
  9773. +
  9774. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  9775. + goto fail_vchiq_init;
  9776. +
  9777. + vchiq_connect(cma_instance);
  9778. +
  9779. + service_params.fourcc = VC_CMA_FOURCC;
  9780. + service_params.callback = cma_service_callback;
  9781. + service_params.userdata = NULL;
  9782. + service_params.version = VC_CMA_VERSION;
  9783. + service_params.version_min = VC_CMA_VERSION;
  9784. +
  9785. + if (vchiq_open_service(cma_instance, &service_params,
  9786. + &cma_service) != VCHIQ_SUCCESS) {
  9787. + LOG_ERR("failed to open service - already in use?");
  9788. + goto fail_vchiq_open;
  9789. + }
  9790. +
  9791. + vchiq_release_service(cma_service);
  9792. +
  9793. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  9794. + if (!cma_worker) {
  9795. + LOG_ERR("could not create CMA worker thread");
  9796. + goto fail_worker;
  9797. + }
  9798. + set_user_nice(cma_worker, -20);
  9799. + wake_up_process(cma_worker);
  9800. +
  9801. + return;
  9802. +
  9803. +fail_worker:
  9804. + vchiq_close_service(cma_service);
  9805. +fail_vchiq_open:
  9806. + vchiq_shutdown(cma_instance);
  9807. +fail_vchiq_init:
  9808. + vchiu_queue_delete(&cma_msg_queue);
  9809. +fail_queue:
  9810. + return;
  9811. +}
  9812. +
  9813. +void
  9814. +loud_error_header(void)
  9815. +{
  9816. + if (in_loud_error)
  9817. + return;
  9818. +
  9819. + LOG_ERR("============================================================"
  9820. + "================");
  9821. + LOG_ERR("============================================================"
  9822. + "================");
  9823. + LOG_ERR("=====");
  9824. +
  9825. + in_loud_error = 1;
  9826. +}
  9827. +
  9828. +void
  9829. +loud_error_footer(void)
  9830. +{
  9831. + if (!in_loud_error)
  9832. + return;
  9833. +
  9834. + LOG_ERR("=====");
  9835. + LOG_ERR("============================================================"
  9836. + "================");
  9837. + LOG_ERR("============================================================"
  9838. + "================");
  9839. +
  9840. + in_loud_error = 0;
  9841. +}
  9842. +
  9843. +#if 1
  9844. +static int check_cma_config(void) { return 1; }
  9845. +#else
  9846. +static int
  9847. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  9848. + const char *symbol,
  9849. + void *buf, size_t bufsize)
  9850. +{
  9851. + VC_MEM_ADDR_T vcMemAddr;
  9852. + size_t vcMemSize;
  9853. + uint8_t *mapAddr;
  9854. + off_t vcMapAddr;
  9855. +
  9856. + if (!LookupVideoCoreSymbol(handle, symbol,
  9857. + &vcMemAddr,
  9858. + &vcMemSize)) {
  9859. + loud_error_header();
  9860. + loud_error(
  9861. + "failed to find VC symbol \"%s\".",
  9862. + symbol);
  9863. + loud_error_footer();
  9864. + return 0;
  9865. + }
  9866. +
  9867. + if (vcMemSize != bufsize) {
  9868. + loud_error_header();
  9869. + loud_error(
  9870. + "VC symbol \"%s\" is the wrong size.",
  9871. + symbol);
  9872. + loud_error_footer();
  9873. + return 0;
  9874. + }
  9875. +
  9876. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  9877. + vcMapAddr += mm_vc_mem_phys_addr;
  9878. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  9879. + if (mapAddr == 0) {
  9880. + loud_error_header();
  9881. + loud_error(
  9882. + "failed to ioremap \"%s\" @ 0x%x "
  9883. + "(phys: 0x%x, size: %u).",
  9884. + symbol,
  9885. + (unsigned int)vcMapAddr,
  9886. + (unsigned int)vcMemAddr,
  9887. + (unsigned int)vcMemSize);
  9888. + loud_error_footer();
  9889. + return 0;
  9890. + }
  9891. +
  9892. + memcpy(buf, mapAddr, bufsize);
  9893. + iounmap(mapAddr);
  9894. +
  9895. + return 1;
  9896. +}
  9897. +
  9898. +
  9899. +static int
  9900. +check_cma_config(void)
  9901. +{
  9902. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  9903. + VC_MEM_ADDR_T mempool_start;
  9904. + VC_MEM_ADDR_T mempool_end;
  9905. + VC_MEM_ADDR_T mempool_offline_start;
  9906. + VC_MEM_ADDR_T mempool_offline_end;
  9907. + VC_MEM_ADDR_T cam_alloc_base;
  9908. + VC_MEM_ADDR_T cam_alloc_size;
  9909. + VC_MEM_ADDR_T cam_alloc_end;
  9910. + int success = 0;
  9911. +
  9912. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  9913. + goto out;
  9914. +
  9915. + /* Read the relevant VideoCore variables */
  9916. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  9917. + &mempool_start,
  9918. + sizeof(mempool_start)))
  9919. + goto close;
  9920. +
  9921. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  9922. + &mempool_end,
  9923. + sizeof(mempool_end)))
  9924. + goto close;
  9925. +
  9926. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  9927. + &mempool_offline_start,
  9928. + sizeof(mempool_offline_start)))
  9929. + goto close;
  9930. +
  9931. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  9932. + &mempool_offline_end,
  9933. + sizeof(mempool_offline_end)))
  9934. + goto close;
  9935. +
  9936. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  9937. + &cam_alloc_base,
  9938. + sizeof(cam_alloc_base)))
  9939. + goto close;
  9940. +
  9941. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  9942. + &cam_alloc_size,
  9943. + sizeof(cam_alloc_size)))
  9944. + goto close;
  9945. +
  9946. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  9947. +
  9948. + success = 1;
  9949. +
  9950. + /* Now the sanity checks */
  9951. + if (!mempool_offline_start)
  9952. + mempool_offline_start = mempool_start;
  9953. + if (!mempool_offline_end)
  9954. + mempool_offline_end = mempool_end;
  9955. +
  9956. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  9957. + loud_error_header();
  9958. + loud_error(
  9959. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  9960. + "vc_cma_base(%x)",
  9961. + mempool_offline_start,
  9962. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  9963. + vc_cma_base);
  9964. + success = 0;
  9965. + }
  9966. +
  9967. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  9968. + (vc_cma_base + vc_cma_size)) {
  9969. + loud_error_header();
  9970. + loud_error(
  9971. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  9972. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  9973. + mempool_offline_start,
  9974. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  9975. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  9976. + success = 0;
  9977. + }
  9978. +
  9979. + if (mempool_end < mempool_start) {
  9980. + loud_error_header();
  9981. + loud_error(
  9982. + "__MEMPOOL_END(%x) must not be before "
  9983. + "__MEMPOOL_START(%x)",
  9984. + mempool_end,
  9985. + mempool_start);
  9986. + success = 0;
  9987. + }
  9988. +
  9989. + if (mempool_offline_end < mempool_offline_start) {
  9990. + loud_error_header();
  9991. + loud_error(
  9992. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  9993. + "__MEMPOOL_OFFLINE_START(%x)",
  9994. + mempool_offline_end,
  9995. + mempool_offline_start);
  9996. + success = 0;
  9997. + }
  9998. +
  9999. + if (mempool_offline_start < mempool_start) {
  10000. + loud_error_header();
  10001. + loud_error(
  10002. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  10003. + "__MEMPOOL_START(%x)",
  10004. + mempool_offline_start,
  10005. + mempool_start);
  10006. + success = 0;
  10007. + }
  10008. +
  10009. + if (mempool_offline_end > mempool_end) {
  10010. + loud_error_header();
  10011. + loud_error(
  10012. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  10013. + "__MEMPOOL_END(%x)",
  10014. + mempool_offline_end,
  10015. + mempool_end);
  10016. + success = 0;
  10017. + }
  10018. +
  10019. + if ((cam_alloc_base < mempool_end) &&
  10020. + (cam_alloc_end > mempool_start)) {
  10021. + loud_error_header();
  10022. + loud_error(
  10023. + "cam_alloc pool(%x-%x) overlaps "
  10024. + "mempool(%x-%x)",
  10025. + cam_alloc_base, cam_alloc_end,
  10026. + mempool_start, mempool_end);
  10027. + success = 0;
  10028. + }
  10029. +
  10030. + loud_error_footer();
  10031. +
  10032. +close:
  10033. + CloseVideoCoreMemory(mem_hndl);
  10034. +
  10035. +out:
  10036. + return success;
  10037. +}
  10038. +#endif
  10039. +
  10040. +static int vc_cma_init(void)
  10041. +{
  10042. + int rc = -EFAULT;
  10043. + struct device *dev;
  10044. +
  10045. + if (!check_cma_config())
  10046. + goto out_release;
  10047. +
  10048. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  10049. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  10050. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  10051. + vc_cma_size, vc_cma_size / (1024 * 1024));
  10052. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  10053. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  10054. +
  10055. + vc_cma_base_page = phys_to_page(vc_cma_base);
  10056. +
  10057. + if (vc_cma_chunks) {
  10058. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  10059. +
  10060. + for (vc_cma_chunks_used = 0;
  10061. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  10062. + struct page *chunk;
  10063. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  10064. + PAGES_PER_CHUNK,
  10065. + VC_CMA_CHUNK_ORDER);
  10066. + if (!chunk)
  10067. + break;
  10068. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  10069. + VC_CMA_CHUNK_SIZE) != 0);
  10070. + }
  10071. + if (vc_cma_chunks_used != chunks_needed) {
  10072. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  10073. + "bytes, allocation %d of %d)",
  10074. + __func__, VC_CMA_CHUNK_SIZE,
  10075. + vc_cma_chunks_used, chunks_needed);
  10076. + goto out_release;
  10077. + }
  10078. +
  10079. + vchiq_add_connected_callback(vc_cma_connected_init);
  10080. + }
  10081. +
  10082. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  10083. + if (rc < 0) {
  10084. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  10085. + goto out_release;
  10086. + }
  10087. +
  10088. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  10089. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  10090. + if (rc != 0) {
  10091. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  10092. + goto out_unregister;
  10093. + }
  10094. +
  10095. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  10096. + if (IS_ERR(vc_cma_class)) {
  10097. + rc = PTR_ERR(vc_cma_class);
  10098. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  10099. + goto out_cdev_del;
  10100. + }
  10101. +
  10102. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  10103. + DRIVER_NAME);
  10104. + if (IS_ERR(dev)) {
  10105. + rc = PTR_ERR(dev);
  10106. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  10107. + goto out_class_destroy;
  10108. + }
  10109. +
  10110. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  10111. + if (vc_cma_proc_entry == NULL) {
  10112. + rc = -EFAULT;
  10113. + LOG_ERR("%s: proc_create failed", __func__);
  10114. + goto out_device_destroy;
  10115. + }
  10116. +
  10117. + vc_cma_inited = 1;
  10118. + return 0;
  10119. +
  10120. +out_device_destroy:
  10121. + device_destroy(vc_cma_class, vc_cma_devnum);
  10122. +
  10123. +out_class_destroy:
  10124. + class_destroy(vc_cma_class);
  10125. + vc_cma_class = NULL;
  10126. +
  10127. +out_cdev_del:
  10128. + cdev_del(&vc_cma_cdev);
  10129. +
  10130. +out_unregister:
  10131. + unregister_chrdev_region(vc_cma_devnum, 1);
  10132. +
  10133. +out_release:
  10134. + /* It is tempting to try to clean up by calling
  10135. + dma_release_from_contiguous for all allocated chunks, but it isn't
  10136. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  10137. + VideoCore is already using that memory, so giving it back to Linux
  10138. + is likely to be fatal.
  10139. + */
  10140. + return -1;
  10141. +}
  10142. +
  10143. +/****************************************************************************
  10144. +*
  10145. +* vc_cma_exit
  10146. +*
  10147. +***************************************************************************/
  10148. +
  10149. +static void __exit vc_cma_exit(void)
  10150. +{
  10151. + LOG_DBG("%s: called", __func__);
  10152. +
  10153. + if (vc_cma_inited) {
  10154. + remove_proc_entry(DRIVER_NAME, NULL);
  10155. + device_destroy(vc_cma_class, vc_cma_devnum);
  10156. + class_destroy(vc_cma_class);
  10157. + cdev_del(&vc_cma_cdev);
  10158. + unregister_chrdev_region(vc_cma_devnum, 1);
  10159. + }
  10160. +}
  10161. +
  10162. +module_init(vc_cma_init);
  10163. +module_exit(vc_cma_exit);
  10164. +MODULE_LICENSE("GPL");
  10165. +MODULE_AUTHOR("Broadcom Corporation");
  10166. diff -Nur linux-3.10.33/drivers/char/hw_random/bcm2708-rng.c linux-raspberry-pi/drivers/char/hw_random/bcm2708-rng.c
  10167. --- linux-3.10.33/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  10168. +++ linux-raspberry-pi/drivers/char/hw_random/bcm2708-rng.c 2014-03-13 12:46:15.356049576 +0100
  10169. @@ -0,0 +1,117 @@
  10170. +/**
  10171. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  10172. + *
  10173. + * Redistribution and use in source and binary forms, with or without
  10174. + * modification, are permitted provided that the following conditions
  10175. + * are met:
  10176. + * 1. Redistributions of source code must retain the above copyright
  10177. + * notice, this list of conditions, and the following disclaimer,
  10178. + * without modification.
  10179. + * 2. Redistributions in binary form must reproduce the above copyright
  10180. + * notice, this list of conditions and the following disclaimer in the
  10181. + * documentation and/or other materials provided with the distribution.
  10182. + * 3. The names of the above-listed copyright holders may not be used
  10183. + * to endorse or promote products derived from this software without
  10184. + * specific prior written permission.
  10185. + *
  10186. + * ALTERNATIVELY, this software may be distributed under the terms of the
  10187. + * GNU General Public License ("GPL") version 2, as published by the Free
  10188. + * Software Foundation.
  10189. + *
  10190. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  10191. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  10192. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  10193. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  10194. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  10195. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  10196. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  10197. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  10198. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  10199. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  10200. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  10201. + */
  10202. +
  10203. +#include <linux/kernel.h>
  10204. +#include <linux/module.h>
  10205. +#include <linux/init.h>
  10206. +#include <linux/hw_random.h>
  10207. +#include <linux/printk.h>
  10208. +
  10209. +#include <asm/io.h>
  10210. +#include <mach/hardware.h>
  10211. +#include <mach/platform.h>
  10212. +
  10213. +#define RNG_CTRL (0x0)
  10214. +#define RNG_STATUS (0x4)
  10215. +#define RNG_DATA (0x8)
  10216. +#define RNG_FF_THRESHOLD (0xc)
  10217. +
  10218. +/* enable rng */
  10219. +#define RNG_RBGEN 0x1
  10220. +/* double speed, less random mode */
  10221. +#define RNG_RBG2X 0x2
  10222. +
  10223. +/* the initial numbers generated are "less random" so will be discarded */
  10224. +#define RNG_WARMUP_COUNT 0x40000
  10225. +
  10226. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  10227. +{
  10228. + void __iomem *rng_base = (void __iomem *)rng->priv;
  10229. + unsigned words;
  10230. + /* wait for a random number to be in fifo */
  10231. + do {
  10232. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  10233. + }
  10234. + while (words == 0);
  10235. + /* read the random number */
  10236. + *buffer = __raw_readl(rng_base + RNG_DATA);
  10237. + return 4;
  10238. +}
  10239. +
  10240. +static struct hwrng bcm2708_rng_ops = {
  10241. + .name = "bcm2708",
  10242. + .data_read = bcm2708_rng_data_read,
  10243. +};
  10244. +
  10245. +static int __init bcm2708_rng_init(void)
  10246. +{
  10247. + void __iomem *rng_base;
  10248. + int err;
  10249. +
  10250. + /* map peripheral */
  10251. + rng_base = ioremap(RNG_BASE, 0x10);
  10252. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  10253. + if (!rng_base) {
  10254. + pr_err("bcm2708_rng_init failed to ioremap\n");
  10255. + return -ENOMEM;
  10256. + }
  10257. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  10258. + /* register driver */
  10259. + err = hwrng_register(&bcm2708_rng_ops);
  10260. + if (err) {
  10261. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  10262. + iounmap(rng_base);
  10263. + } else {
  10264. + /* set warm-up count & enable */
  10265. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  10266. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  10267. + }
  10268. + return err;
  10269. +}
  10270. +
  10271. +static void __exit bcm2708_rng_exit(void)
  10272. +{
  10273. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  10274. + pr_info("bcm2708_rng_exit\n");
  10275. + /* disable rng hardware */
  10276. + __raw_writel(0, rng_base + RNG_CTRL);
  10277. + /* unregister driver */
  10278. + hwrng_unregister(&bcm2708_rng_ops);
  10279. + iounmap(rng_base);
  10280. +}
  10281. +
  10282. +module_init(bcm2708_rng_init);
  10283. +module_exit(bcm2708_rng_exit);
  10284. +
  10285. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  10286. +MODULE_LICENSE("GPL and additional rights");
  10287. diff -Nur linux-3.10.33/drivers/char/hw_random/Kconfig linux-raspberry-pi/drivers/char/hw_random/Kconfig
  10288. --- linux-3.10.33/drivers/char/hw_random/Kconfig 2014-03-07 06:58:45.000000000 +0100
  10289. +++ linux-raspberry-pi/drivers/char/hw_random/Kconfig 2014-03-13 12:46:15.356049576 +0100
  10290. @@ -314,3 +314,15 @@
  10291. module will be called tpm-rng.
  10292. If unsure, say Y.
  10293. +
  10294. +config HW_RANDOM_BCM2708
  10295. + tristate "BCM2708 generic true random number generator support"
  10296. + depends on HW_RANDOM && ARCH_BCM2708
  10297. + ---help---
  10298. + This driver provides the kernel-side support for the BCM2708 hardware.
  10299. +
  10300. + To compile this driver as a module, choose M here: the
  10301. + module will be called bcm2708-rng.
  10302. +
  10303. + If unsure, say N.
  10304. +
  10305. diff -Nur linux-3.10.33/drivers/char/hw_random/Makefile linux-raspberry-pi/drivers/char/hw_random/Makefile
  10306. --- linux-3.10.33/drivers/char/hw_random/Makefile 2014-03-07 06:58:45.000000000 +0100
  10307. +++ linux-raspberry-pi/drivers/char/hw_random/Makefile 2014-03-13 12:46:15.356049576 +0100
  10308. @@ -27,3 +27,4 @@
  10309. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  10310. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  10311. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  10312. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  10313. diff -Nur linux-3.10.33/drivers/char/Kconfig linux-raspberry-pi/drivers/char/Kconfig
  10314. --- linux-3.10.33/drivers/char/Kconfig 2014-03-07 06:58:45.000000000 +0100
  10315. +++ linux-raspberry-pi/drivers/char/Kconfig 2014-03-13 12:46:15.348049560 +0100
  10316. @@ -586,6 +586,8 @@
  10317. source "drivers/s390/char/Kconfig"
  10318. +source "drivers/char/broadcom/Kconfig"
  10319. +
  10320. config MSM_SMD_PKT
  10321. bool "Enable device interface for some SMD packet ports"
  10322. default n
  10323. diff -Nur linux-3.10.33/drivers/char/Makefile linux-raspberry-pi/drivers/char/Makefile
  10324. --- linux-3.10.33/drivers/char/Makefile 2014-03-07 06:58:45.000000000 +0100
  10325. +++ linux-raspberry-pi/drivers/char/Makefile 2014-03-13 12:46:15.348049560 +0100
  10326. @@ -62,3 +62,6 @@
  10327. js-rtc-y = rtc.o
  10328. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  10329. +
  10330. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  10331. +
  10332. diff -Nur linux-3.10.33/drivers/cpufreq/bcm2835-cpufreq.c linux-raspberry-pi/drivers/cpufreq/bcm2835-cpufreq.c
  10333. --- linux-3.10.33/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  10334. +++ linux-raspberry-pi/drivers/cpufreq/bcm2835-cpufreq.c 2014-03-13 12:46:15.508049881 +0100
  10335. @@ -0,0 +1,239 @@
  10336. +/*****************************************************************************
  10337. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10338. +*
  10339. +* Unless you and Broadcom execute a separate written software license
  10340. +* agreement governing use of this software, this software is licensed to you
  10341. +* under the terms of the GNU General Public License version 2, available at
  10342. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10343. +*
  10344. +* Notwithstanding the above, under no circumstances may you combine this
  10345. +* software in any way with any other Broadcom software provided under a
  10346. +* license other than the GPL, without Broadcom's express prior written
  10347. +* consent.
  10348. +*****************************************************************************/
  10349. +
  10350. +/*****************************************************************************
  10351. +* FILENAME: bcm2835-cpufreq.h
  10352. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  10353. +* processor. Messages are sent to Videocore either setting or requesting the
  10354. +* frequency of the ARM in order to match an appropiate frequency to the current
  10355. +* usage of the processor. The policy which selects the frequency to use is
  10356. +* defined in the kernel .config file, but can be changed during runtime.
  10357. +*****************************************************************************/
  10358. +
  10359. +/* ---------- INCLUDES ---------- */
  10360. +#include <linux/kernel.h>
  10361. +#include <linux/init.h>
  10362. +#include <linux/module.h>
  10363. +#include <linux/cpufreq.h>
  10364. +#include <mach/vcio.h>
  10365. +
  10366. +/* ---------- DEFINES ---------- */
  10367. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  10368. +#define MODULE_NAME "bcm2835-cpufreq"
  10369. +
  10370. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  10371. +
  10372. +/* debug printk macros */
  10373. +#ifdef CPUFREQ_DEBUG_ENABLE
  10374. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10375. +#else
  10376. +#define print_debug(fmt,...)
  10377. +#endif
  10378. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10379. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  10380. +
  10381. +/* tag part of the message */
  10382. +struct vc_msg_tag {
  10383. + uint32_t tag_id; /* the message id */
  10384. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  10385. + uint32_t data_size; /* amount of data being sent or received */
  10386. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  10387. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  10388. +};
  10389. +
  10390. +/* message structure to be sent to videocore */
  10391. +struct vc_msg {
  10392. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10393. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10394. + struct vc_msg_tag tag; /* the tag structure above to make */
  10395. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10396. +};
  10397. +
  10398. +/* ---------- GLOBALS ---------- */
  10399. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  10400. +
  10401. +/*
  10402. + ===============================================
  10403. + clk_rate either gets or sets the clock rates.
  10404. + ===============================================
  10405. +*/
  10406. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  10407. +{
  10408. + int s, actual_rate=0;
  10409. + struct vc_msg msg;
  10410. +
  10411. + /* wipe all previous message data */
  10412. + memset(&msg, 0, sizeof msg);
  10413. +
  10414. + msg.msg_size = sizeof msg;
  10415. +
  10416. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  10417. + msg.tag.buffer_size = 8;
  10418. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  10419. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10420. + msg.tag.val = arm_rate * 1000;
  10421. +
  10422. + /* send the message */
  10423. + s = bcm_mailbox_property(&msg, sizeof msg);
  10424. +
  10425. + /* check if it was all ok and return the rate in KHz */
  10426. + if (s == 0 && (msg.request_code & 0x80000000))
  10427. + actual_rate = msg.tag.val/1000;
  10428. +
  10429. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  10430. + return actual_rate;
  10431. +}
  10432. +
  10433. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  10434. +{
  10435. + int s;
  10436. + int arm_rate = 0;
  10437. + struct vc_msg msg;
  10438. +
  10439. + /* wipe all previous message data */
  10440. + memset(&msg, 0, sizeof msg);
  10441. +
  10442. + msg.msg_size = sizeof msg;
  10443. + msg.tag.tag_id = tag;
  10444. + msg.tag.buffer_size = 8;
  10445. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  10446. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10447. +
  10448. + /* send the message */
  10449. + s = bcm_mailbox_property(&msg, sizeof msg);
  10450. +
  10451. + /* check if it was all ok and return the rate in KHz */
  10452. + if (s == 0 && (msg.request_code & 0x80000000))
  10453. + arm_rate = msg.tag.val/1000;
  10454. +
  10455. + print_debug("%s frequency = %d\n",
  10456. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  10457. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  10458. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  10459. + "Unexpected", arm_rate);
  10460. +
  10461. + return arm_rate;
  10462. +}
  10463. +
  10464. +/*
  10465. + ====================================================
  10466. + Module Initialisation registers the cpufreq driver
  10467. + ====================================================
  10468. +*/
  10469. +static int __init bcm2835_cpufreq_module_init(void)
  10470. +{
  10471. + print_debug("IN\n");
  10472. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  10473. +}
  10474. +
  10475. +/*
  10476. + =============
  10477. + Module exit
  10478. + =============
  10479. +*/
  10480. +static void __exit bcm2835_cpufreq_module_exit(void)
  10481. +{
  10482. + print_debug("IN\n");
  10483. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  10484. + return;
  10485. +}
  10486. +
  10487. +/*
  10488. + ==============================================================
  10489. + Initialisation function sets up the CPU policy for first use
  10490. + ==============================================================
  10491. +*/
  10492. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  10493. +{
  10494. + /* measured value of how long it takes to change frequency */
  10495. + policy->cpuinfo.transition_latency = 355000; /* ns */
  10496. +
  10497. + /* now find out what the maximum and minimum frequencies are */
  10498. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  10499. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  10500. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10501. +
  10502. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  10503. + return 0;
  10504. +}
  10505. +
  10506. +/*
  10507. + =================================================================================
  10508. + Target function chooses the most appropriate frequency from the table to enable
  10509. + =================================================================================
  10510. +*/
  10511. +
  10512. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  10513. +{
  10514. + unsigned int target = target_freq;
  10515. + unsigned int cur = policy->cur;
  10516. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  10517. +
  10518. + /* if we are above min and using ondemand, then just use max */
  10519. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  10520. + target = policy->max;
  10521. + /* if the frequency is the same, just quit */
  10522. + if (target == policy->cur)
  10523. + return 0;
  10524. +
  10525. + /* otherwise were good to set the clock frequency */
  10526. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  10527. +
  10528. + if (!policy->cur)
  10529. + {
  10530. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  10531. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10532. + return -EINVAL;
  10533. + }
  10534. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  10535. + return 0;
  10536. +}
  10537. +
  10538. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  10539. +{
  10540. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10541. + print_debug("cpu=%d\n", actual_rate);
  10542. + return actual_rate;
  10543. +}
  10544. +
  10545. +/*
  10546. + =================================================================================
  10547. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  10548. + =================================================================================
  10549. +*/
  10550. +
  10551. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  10552. +{
  10553. + print_info("switching to governor %s\n", policy->governor->name);
  10554. + return 0;
  10555. +}
  10556. +
  10557. +
  10558. +/* the CPUFreq driver */
  10559. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  10560. + .name = "BCM2835 CPUFreq",
  10561. + .owner = THIS_MODULE,
  10562. + .init = bcm2835_cpufreq_driver_init,
  10563. + .verify = bcm2835_cpufreq_driver_verify,
  10564. + .target = bcm2835_cpufreq_driver_target,
  10565. + .get = bcm2835_cpufreq_driver_get
  10566. +};
  10567. +
  10568. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  10569. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  10570. +MODULE_LICENSE("GPL");
  10571. +
  10572. +module_init(bcm2835_cpufreq_module_init);
  10573. +module_exit(bcm2835_cpufreq_module_exit);
  10574. +
  10575. diff -Nur linux-3.10.33/drivers/cpufreq/Kconfig.arm linux-raspberry-pi/drivers/cpufreq/Kconfig.arm
  10576. --- linux-3.10.33/drivers/cpufreq/Kconfig.arm 2014-03-07 06:58:45.000000000 +0100
  10577. +++ linux-raspberry-pi/drivers/cpufreq/Kconfig.arm 2014-03-13 12:46:15.504049873 +0100
  10578. @@ -150,3 +150,11 @@
  10579. default y
  10580. help
  10581. This adds the CPUFreq driver support for SPEAr SOCs.
  10582. +
  10583. +config ARM_BCM2835_CPUFREQ
  10584. + bool "BCM2835 Driver"
  10585. + default y
  10586. + help
  10587. + This adds the CPUFreq driver for BCM2835
  10588. +
  10589. + If in doubt, say N.
  10590. diff -Nur linux-3.10.33/drivers/cpufreq/Makefile linux-raspberry-pi/drivers/cpufreq/Makefile
  10591. --- linux-3.10.33/drivers/cpufreq/Makefile 2014-03-07 06:58:45.000000000 +0100
  10592. +++ linux-raspberry-pi/drivers/cpufreq/Makefile 2014-03-13 12:46:15.504049873 +0100
  10593. @@ -72,6 +72,7 @@
  10594. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  10595. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  10596. obj-$(CONFIG_ARCH_TEGRA) += tegra-cpufreq.o
  10597. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  10598. ##################################################################################
  10599. # PowerPC platform drivers
  10600. diff -Nur linux-3.10.33/drivers/dma/bcm2708-dmaengine.c linux-raspberry-pi/drivers/dma/bcm2708-dmaengine.c
  10601. --- linux-3.10.33/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  10602. +++ linux-raspberry-pi/drivers/dma/bcm2708-dmaengine.c 2014-03-13 12:46:15.532049928 +0100
  10603. @@ -0,0 +1,588 @@
  10604. +/*
  10605. + * BCM2708 DMA engine support
  10606. + *
  10607. + * This driver only supports cyclic DMA transfers
  10608. + * as needed for the I2S module.
  10609. + *
  10610. + * Author: Florian Meier <florian.meier@koalo.de>
  10611. + * Copyright 2013
  10612. + *
  10613. + * Based on
  10614. + * OMAP DMAengine support by Russell King
  10615. + *
  10616. + * BCM2708 DMA Driver
  10617. + * Copyright (C) 2010 Broadcom
  10618. + *
  10619. + * Raspberry Pi PCM I2S ALSA Driver
  10620. + * Copyright (c) by Phil Poole 2013
  10621. + *
  10622. + * MARVELL MMP Peripheral DMA Driver
  10623. + * Copyright 2012 Marvell International Ltd.
  10624. + *
  10625. + * This program is free software; you can redistribute it and/or modify
  10626. + * it under the terms of the GNU General Public License as published by
  10627. + * the Free Software Foundation; either version 2 of the License, or
  10628. + * (at your option) any later version.
  10629. + *
  10630. + * This program is distributed in the hope that it will be useful,
  10631. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10632. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10633. + * GNU General Public License for more details.
  10634. + */
  10635. +#include <linux/dmaengine.h>
  10636. +#include <linux/dma-mapping.h>
  10637. +#include <linux/err.h>
  10638. +#include <linux/init.h>
  10639. +#include <linux/interrupt.h>
  10640. +#include <linux/list.h>
  10641. +#include <linux/module.h>
  10642. +#include <linux/platform_device.h>
  10643. +#include <linux/slab.h>
  10644. +#include <linux/io.h>
  10645. +#include <linux/spinlock.h>
  10646. +#include <linux/irq.h>
  10647. +
  10648. +#include "virt-dma.h"
  10649. +
  10650. +#include <mach/dma.h>
  10651. +#include <mach/irqs.h>
  10652. +
  10653. +struct bcm2708_dmadev {
  10654. + struct dma_device ddev;
  10655. + spinlock_t lock;
  10656. + void __iomem *base;
  10657. + struct device_dma_parameters dma_parms;
  10658. +};
  10659. +
  10660. +struct bcm2708_chan {
  10661. + struct virt_dma_chan vc;
  10662. + struct list_head node;
  10663. +
  10664. + struct dma_slave_config cfg;
  10665. + bool cyclic;
  10666. +
  10667. + int ch;
  10668. + struct bcm2708_desc *desc;
  10669. +
  10670. + void __iomem *chan_base;
  10671. + int irq_number;
  10672. +};
  10673. +
  10674. +struct bcm2708_desc {
  10675. + struct virt_dma_desc vd;
  10676. + enum dma_transfer_direction dir;
  10677. +
  10678. + unsigned int control_block_size;
  10679. + struct bcm2708_dma_cb *control_block_base;
  10680. + dma_addr_t control_block_base_phys;
  10681. +
  10682. + unsigned frames;
  10683. + size_t size;
  10684. +};
  10685. +
  10686. +#define BCM2708_DMA_DATA_TYPE_S8 1
  10687. +#define BCM2708_DMA_DATA_TYPE_S16 2
  10688. +#define BCM2708_DMA_DATA_TYPE_S32 4
  10689. +#define BCM2708_DMA_DATA_TYPE_S128 16
  10690. +
  10691. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  10692. +{
  10693. + return container_of(d, struct bcm2708_dmadev, ddev);
  10694. +}
  10695. +
  10696. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  10697. +{
  10698. + return container_of(c, struct bcm2708_chan, vc.chan);
  10699. +}
  10700. +
  10701. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  10702. + struct dma_async_tx_descriptor *t)
  10703. +{
  10704. + return container_of(t, struct bcm2708_desc, vd.tx);
  10705. +}
  10706. +
  10707. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  10708. +{
  10709. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  10710. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  10711. + desc->control_block_size,
  10712. + desc->control_block_base,
  10713. + desc->control_block_base_phys);
  10714. + kfree(desc);
  10715. +}
  10716. +
  10717. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  10718. +{
  10719. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  10720. + struct bcm2708_desc *d;
  10721. +
  10722. + if (!vd) {
  10723. + c->desc = NULL;
  10724. + return;
  10725. + }
  10726. +
  10727. + list_del(&vd->node);
  10728. +
  10729. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  10730. +
  10731. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  10732. +}
  10733. +
  10734. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  10735. +{
  10736. + struct bcm2708_chan *c = data;
  10737. + struct bcm2708_desc *d;
  10738. + unsigned long flags;
  10739. +
  10740. + spin_lock_irqsave(&c->vc.lock, flags);
  10741. +
  10742. + /* Acknowledge interrupt */
  10743. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  10744. +
  10745. + d = c->desc;
  10746. +
  10747. + if (d) {
  10748. + /* TODO Only works for cyclic DMA */
  10749. + vchan_cyclic_callback(&d->vd);
  10750. + }
  10751. +
  10752. + /* Keep the DMA engine running */
  10753. + dsb(); /* ARM synchronization barrier */
  10754. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  10755. +
  10756. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10757. +
  10758. + return IRQ_HANDLED;
  10759. +}
  10760. +
  10761. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  10762. +{
  10763. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10764. +
  10765. + return request_irq(c->irq_number,
  10766. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  10767. +}
  10768. +
  10769. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  10770. +{
  10771. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10772. +
  10773. + vchan_free_chan_resources(&c->vc);
  10774. + free_irq(c->irq_number, c);
  10775. +
  10776. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  10777. +}
  10778. +
  10779. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  10780. +{
  10781. + return d->size;
  10782. +}
  10783. +
  10784. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  10785. +{
  10786. + unsigned i;
  10787. + size_t size;
  10788. +
  10789. + for (size = i = 0; i < d->frames; i++) {
  10790. + struct bcm2708_dma_cb *control_block =
  10791. + &d->control_block_base[i];
  10792. + size_t this_size = control_block->length;
  10793. + dma_addr_t dma;
  10794. +
  10795. + if (d->dir == DMA_DEV_TO_MEM)
  10796. + dma = control_block->dst;
  10797. + else
  10798. + dma = control_block->src;
  10799. +
  10800. + if (size)
  10801. + size += this_size;
  10802. + else if (addr >= dma && addr < dma + this_size)
  10803. + size += dma + this_size - addr;
  10804. + }
  10805. +
  10806. + return size;
  10807. +}
  10808. +
  10809. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  10810. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  10811. +{
  10812. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10813. + struct virt_dma_desc *vd;
  10814. + enum dma_status ret;
  10815. + unsigned long flags;
  10816. +
  10817. + ret = dma_cookie_status(chan, cookie, txstate);
  10818. + if (ret == DMA_SUCCESS || !txstate)
  10819. + return ret;
  10820. +
  10821. + spin_lock_irqsave(&c->vc.lock, flags);
  10822. + vd = vchan_find_desc(&c->vc, cookie);
  10823. + if (vd) {
  10824. + txstate->residue =
  10825. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  10826. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  10827. + struct bcm2708_desc *d = c->desc;
  10828. + dma_addr_t pos;
  10829. +
  10830. + if (d->dir == DMA_MEM_TO_DEV)
  10831. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  10832. + else if (d->dir == DMA_DEV_TO_MEM)
  10833. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  10834. + else
  10835. + pos = 0;
  10836. +
  10837. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  10838. + } else {
  10839. + txstate->residue = 0;
  10840. + }
  10841. +
  10842. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10843. +
  10844. + return ret;
  10845. +}
  10846. +
  10847. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  10848. +{
  10849. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10850. + unsigned long flags;
  10851. +
  10852. + c->cyclic = true; /* Nothing else is implemented */
  10853. +
  10854. + spin_lock_irqsave(&c->vc.lock, flags);
  10855. + if (vchan_issue_pending(&c->vc) && !c->desc)
  10856. + bcm2708_dma_start_desc(c);
  10857. +
  10858. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10859. +}
  10860. +
  10861. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  10862. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  10863. + size_t period_len, enum dma_transfer_direction direction,
  10864. + unsigned long flags, void *context)
  10865. +{
  10866. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10867. + enum dma_slave_buswidth dev_width;
  10868. + struct bcm2708_desc *d;
  10869. + dma_addr_t dev_addr;
  10870. + unsigned es, sync_type;
  10871. + unsigned frame;
  10872. +
  10873. + /* Grab configuration */
  10874. + if (direction == DMA_DEV_TO_MEM) {
  10875. + dev_addr = c->cfg.src_addr;
  10876. + dev_width = c->cfg.src_addr_width;
  10877. + sync_type = BCM2708_DMA_S_DREQ;
  10878. + } else if (direction == DMA_MEM_TO_DEV) {
  10879. + dev_addr = c->cfg.dst_addr;
  10880. + dev_width = c->cfg.dst_addr_width;
  10881. + sync_type = BCM2708_DMA_D_DREQ;
  10882. + } else {
  10883. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  10884. + return NULL;
  10885. + }
  10886. +
  10887. + /* Bus width translates to the element size (ES) */
  10888. + switch (dev_width) {
  10889. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  10890. + es = BCM2708_DMA_DATA_TYPE_S32;
  10891. + break;
  10892. + default:
  10893. + return NULL;
  10894. + }
  10895. +
  10896. + /* Now allocate and setup the descriptor. */
  10897. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  10898. + if (!d)
  10899. + return NULL;
  10900. +
  10901. + d->dir = direction;
  10902. + d->frames = buf_len / period_len;
  10903. +
  10904. + /* Allocate memory for control blocks */
  10905. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  10906. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  10907. + d->control_block_size, &d->control_block_base_phys,
  10908. + GFP_NOWAIT);
  10909. +
  10910. + if (!d->control_block_base) {
  10911. + kfree(d);
  10912. + return NULL;
  10913. + }
  10914. +
  10915. + /*
  10916. + * Iterate over all frames, create a control block
  10917. + * for each frame and link them together.
  10918. + */
  10919. + for (frame = 0; frame < d->frames; frame++) {
  10920. + struct bcm2708_dma_cb *control_block =
  10921. + &d->control_block_base[frame];
  10922. +
  10923. + /* Setup adresses */
  10924. + if (d->dir == DMA_DEV_TO_MEM) {
  10925. + control_block->info = BCM2708_DMA_D_INC;
  10926. + control_block->src = dev_addr;
  10927. + control_block->dst = buf_addr + frame * period_len;
  10928. + } else {
  10929. + control_block->info = BCM2708_DMA_S_INC;
  10930. + control_block->src = buf_addr + frame * period_len;
  10931. + control_block->dst = dev_addr;
  10932. + }
  10933. +
  10934. + /* Enable interrupt */
  10935. + control_block->info |= BCM2708_DMA_INT_EN;
  10936. +
  10937. + /* Setup synchronization */
  10938. + if (sync_type != 0)
  10939. + control_block->info |= sync_type;
  10940. +
  10941. + /* Setup DREQ channel */
  10942. + if (c->cfg.slave_id != 0)
  10943. + control_block->info |=
  10944. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  10945. +
  10946. + /* Length of a frame */
  10947. + control_block->length = period_len;
  10948. + d->size += control_block->length;
  10949. +
  10950. + /*
  10951. + * Next block is the next frame.
  10952. + * This DMA engine driver currently only supports cyclic DMA.
  10953. + * Therefore, wrap around at number of frames.
  10954. + */
  10955. + control_block->next = d->control_block_base_phys +
  10956. + sizeof(struct bcm2708_dma_cb)
  10957. + * ((frame + 1) % d->frames);
  10958. + }
  10959. +
  10960. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  10961. +}
  10962. +
  10963. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  10964. + struct dma_slave_config *cfg)
  10965. +{
  10966. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  10967. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10968. + (cfg->direction == DMA_MEM_TO_DEV &&
  10969. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10970. + !is_slave_direction(cfg->direction)) {
  10971. + return -EINVAL;
  10972. + }
  10973. +
  10974. + c->cfg = *cfg;
  10975. +
  10976. + return 0;
  10977. +}
  10978. +
  10979. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  10980. +{
  10981. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  10982. + unsigned long flags;
  10983. + int timeout = 10000;
  10984. + LIST_HEAD(head);
  10985. +
  10986. + spin_lock_irqsave(&c->vc.lock, flags);
  10987. +
  10988. + /* Prevent this channel being scheduled */
  10989. + spin_lock(&d->lock);
  10990. + list_del_init(&c->node);
  10991. + spin_unlock(&d->lock);
  10992. +
  10993. + /*
  10994. + * Stop DMA activity: we assume the callback will not be called
  10995. + * after bcm_dma_abort() returns (even if it does, it will see
  10996. + * c->desc is NULL and exit.)
  10997. + */
  10998. + if (c->desc) {
  10999. + c->desc = NULL;
  11000. + bcm_dma_abort(c->chan_base);
  11001. +
  11002. + /* Wait for stopping */
  11003. + while (timeout > 0) {
  11004. + timeout--;
  11005. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  11006. + BCM2708_DMA_ACTIVE))
  11007. + break;
  11008. +
  11009. + cpu_relax();
  11010. + }
  11011. +
  11012. + if (timeout <= 0)
  11013. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  11014. + }
  11015. +
  11016. + vchan_get_all_descriptors(&c->vc, &head);
  11017. + spin_unlock_irqrestore(&c->vc.lock, flags);
  11018. + vchan_dma_desc_free_list(&c->vc, &head);
  11019. +
  11020. + return 0;
  11021. +}
  11022. +
  11023. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  11024. + unsigned long arg)
  11025. +{
  11026. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  11027. +
  11028. + switch (cmd) {
  11029. + case DMA_SLAVE_CONFIG:
  11030. + return bcm2708_dma_slave_config(c,
  11031. + (struct dma_slave_config *)arg);
  11032. +
  11033. + case DMA_TERMINATE_ALL:
  11034. + return bcm2708_dma_terminate_all(c);
  11035. +
  11036. + default:
  11037. + return -ENXIO;
  11038. + }
  11039. +}
  11040. +
  11041. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  11042. + int chan_id, int irq)
  11043. +{
  11044. + struct bcm2708_chan *c;
  11045. +
  11046. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  11047. + if (!c)
  11048. + return -ENOMEM;
  11049. +
  11050. + c->vc.desc_free = bcm2708_dma_desc_free;
  11051. + vchan_init(&c->vc, &d->ddev);
  11052. + INIT_LIST_HEAD(&c->node);
  11053. +
  11054. + d->ddev.chancnt++;
  11055. +
  11056. + c->chan_base = chan_base;
  11057. + c->ch = chan_id;
  11058. + c->irq_number = irq;
  11059. +
  11060. + return 0;
  11061. +}
  11062. +
  11063. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  11064. +{
  11065. + while (!list_empty(&od->ddev.channels)) {
  11066. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  11067. + struct bcm2708_chan, vc.chan.device_node);
  11068. +
  11069. + list_del(&c->vc.chan.device_node);
  11070. + tasklet_kill(&c->vc.task);
  11071. + }
  11072. +}
  11073. +
  11074. +static int bcm2708_dma_probe(struct platform_device *pdev)
  11075. +{
  11076. + struct bcm2708_dmadev *od;
  11077. + int rc, i;
  11078. +
  11079. + if (!pdev->dev.dma_mask)
  11080. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  11081. +
  11082. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  11083. + if (rc)
  11084. + return rc;
  11085. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  11086. +
  11087. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  11088. + if (!od)
  11089. + return -ENOMEM;
  11090. +
  11091. + pdev->dev.dma_parms = &od->dma_parms;
  11092. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  11093. +
  11094. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  11095. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  11096. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  11097. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  11098. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  11099. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  11100. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  11101. + od->ddev.device_control = bcm2708_dma_control;
  11102. + od->ddev.dev = &pdev->dev;
  11103. + INIT_LIST_HEAD(&od->ddev.channels);
  11104. + spin_lock_init(&od->lock);
  11105. +
  11106. + platform_set_drvdata(pdev, od);
  11107. +
  11108. + for (i = 0; i < 16; i++) {
  11109. + void __iomem* chan_base;
  11110. + int chan_id, irq;
  11111. +
  11112. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  11113. + &chan_base,
  11114. + &irq);
  11115. +
  11116. + if (chan_id < 0)
  11117. + break;
  11118. +
  11119. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  11120. + if (rc) {
  11121. + bcm2708_dma_free(od);
  11122. + return rc;
  11123. + }
  11124. + }
  11125. +
  11126. + rc = dma_async_device_register(&od->ddev);
  11127. + if (rc) {
  11128. + dev_err(&pdev->dev,
  11129. + "Failed to register slave DMA engine device: %d\n", rc);
  11130. + bcm2708_dma_free(od);
  11131. + return rc;
  11132. + }
  11133. +
  11134. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  11135. +
  11136. + return rc;
  11137. +}
  11138. +
  11139. +static int bcm2708_dma_remove(struct platform_device *pdev)
  11140. +{
  11141. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  11142. +
  11143. + dma_async_device_unregister(&od->ddev);
  11144. + bcm2708_dma_free(od);
  11145. +
  11146. + return 0;
  11147. +}
  11148. +
  11149. +static struct platform_driver bcm2708_dma_driver = {
  11150. + .probe = bcm2708_dma_probe,
  11151. + .remove = bcm2708_dma_remove,
  11152. + .driver = {
  11153. + .name = "bcm2708-dmaengine",
  11154. + .owner = THIS_MODULE,
  11155. + },
  11156. +};
  11157. +
  11158. +static struct platform_device *pdev;
  11159. +
  11160. +static const struct platform_device_info bcm2708_dma_dev_info = {
  11161. + .name = "bcm2708-dmaengine",
  11162. + .id = -1,
  11163. +};
  11164. +
  11165. +static int bcm2708_dma_init(void)
  11166. +{
  11167. + int rc = platform_driver_register(&bcm2708_dma_driver);
  11168. +
  11169. + if (rc == 0) {
  11170. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  11171. + if (IS_ERR(pdev)) {
  11172. + platform_driver_unregister(&bcm2708_dma_driver);
  11173. + rc = PTR_ERR(pdev);
  11174. + }
  11175. + }
  11176. +
  11177. + return rc;
  11178. +}
  11179. +subsys_initcall(bcm2708_dma_init);
  11180. +
  11181. +static void __exit bcm2708_dma_exit(void)
  11182. +{
  11183. + platform_device_unregister(pdev);
  11184. + platform_driver_unregister(&bcm2708_dma_driver);
  11185. +}
  11186. +module_exit(bcm2708_dma_exit);
  11187. +
  11188. +MODULE_ALIAS("platform:bcm2708-dma");
  11189. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  11190. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  11191. +MODULE_LICENSE("GPL v2");
  11192. diff -Nur linux-3.10.33/drivers/dma/Kconfig linux-raspberry-pi/drivers/dma/Kconfig
  11193. --- linux-3.10.33/drivers/dma/Kconfig 2014-03-07 06:58:45.000000000 +0100
  11194. +++ linux-raspberry-pi/drivers/dma/Kconfig 2014-03-13 12:46:15.532049928 +0100
  11195. @@ -305,6 +305,12 @@
  11196. select DMA_ENGINE
  11197. select DMA_VIRTUAL_CHANNELS
  11198. +config DMA_BCM2708
  11199. + tristate "BCM2708 DMA engine support"
  11200. + depends on MACH_BCM2708
  11201. + select DMA_ENGINE
  11202. + select DMA_VIRTUAL_CHANNELS
  11203. +
  11204. config MMP_PDMA
  11205. bool "MMP PDMA support"
  11206. depends on (ARCH_MMP || ARCH_PXA)
  11207. diff -Nur linux-3.10.33/drivers/dma/Makefile linux-raspberry-pi/drivers/dma/Makefile
  11208. --- linux-3.10.33/drivers/dma/Makefile 2014-03-07 06:58:45.000000000 +0100
  11209. +++ linux-raspberry-pi/drivers/dma/Makefile 2014-03-13 12:46:15.532049928 +0100
  11210. @@ -37,4 +37,5 @@
  11211. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  11212. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  11213. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  11214. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  11215. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  11216. diff -Nur linux-3.10.33/drivers/hwmon/bcm2835-hwmon.c linux-raspberry-pi/drivers/hwmon/bcm2835-hwmon.c
  11217. --- linux-3.10.33/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  11218. +++ linux-raspberry-pi/drivers/hwmon/bcm2835-hwmon.c 2014-03-13 12:46:16.004050873 +0100
  11219. @@ -0,0 +1,219 @@
  11220. +/*****************************************************************************
  11221. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  11222. +*
  11223. +* Unless you and Broadcom execute a separate written software license
  11224. +* agreement governing use of this software, this software is licensed to you
  11225. +* under the terms of the GNU General Public License version 2, available at
  11226. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  11227. +*
  11228. +* Notwithstanding the above, under no circumstances may you combine this
  11229. +* software in any way with any other Broadcom software provided under a
  11230. +* license other than the GPL, without Broadcom's express prior written
  11231. +* consent.
  11232. +*****************************************************************************/
  11233. +
  11234. +#include <linux/kernel.h>
  11235. +#include <linux/module.h>
  11236. +#include <linux/init.h>
  11237. +#include <linux/hwmon.h>
  11238. +#include <linux/hwmon-sysfs.h>
  11239. +#include <linux/platform_device.h>
  11240. +#include <linux/sysfs.h>
  11241. +#include <mach/vcio.h>
  11242. +#include <linux/slab.h>
  11243. +#include <linux/err.h>
  11244. +
  11245. +#define MODULE_NAME "bcm2835_hwmon"
  11246. +
  11247. +/*#define HWMON_DEBUG_ENABLE*/
  11248. +
  11249. +#ifdef HWMON_DEBUG_ENABLE
  11250. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  11251. +#else
  11252. +#define print_debug(fmt,...)
  11253. +#endif
  11254. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  11255. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  11256. +
  11257. +#define VC_TAG_GET_TEMP 0x00030006
  11258. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  11259. +
  11260. +/* --- STRUCTS --- */
  11261. +struct bcm2835_hwmon_data {
  11262. + struct device *hwmon_dev;
  11263. +};
  11264. +
  11265. +/* tag part of the message */
  11266. +struct vc_msg_tag {
  11267. + uint32_t tag_id; /* the tag ID for the temperature */
  11268. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  11269. + uint32_t request_code; /* identifies message as a request (should be 0) */
  11270. + uint32_t id; /* extra ID field (should be 0) */
  11271. + uint32_t val; /* returned value of the temperature */
  11272. +};
  11273. +
  11274. +/* message structure to be sent to videocore */
  11275. +struct vc_msg {
  11276. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  11277. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  11278. + struct vc_msg_tag tag; /* the tag structure above to make */
  11279. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  11280. +};
  11281. +
  11282. +typedef enum {
  11283. + TEMP,
  11284. + MAX_TEMP,
  11285. +} temp_type;
  11286. +
  11287. +/* --- PROTOTYPES --- */
  11288. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  11289. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  11290. +
  11291. +/* --- GLOBALS --- */
  11292. +
  11293. +static struct bcm2835_hwmon_data *bcm2835_data;
  11294. +static struct platform_driver bcm2835_hwmon_driver;
  11295. +
  11296. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  11297. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  11298. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  11299. +
  11300. +static struct attribute* bcm2835_attributes[] = {
  11301. + &sensor_dev_attr_name.dev_attr.attr,
  11302. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  11303. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  11304. + NULL,
  11305. +};
  11306. +
  11307. +static struct attribute_group bcm2835_attr_group = {
  11308. + .attrs = bcm2835_attributes,
  11309. +};
  11310. +
  11311. +/* --- FUNCTIONS --- */
  11312. +
  11313. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  11314. +{
  11315. + return sprintf(buf,"bcm2835_hwmon\n");
  11316. +}
  11317. +
  11318. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  11319. +{
  11320. + struct vc_msg msg;
  11321. + int result;
  11322. + uint temp = 0;
  11323. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  11324. +
  11325. + print_debug("IN");
  11326. +
  11327. + /* wipe all previous message data */
  11328. + memset(&msg, 0, sizeof msg);
  11329. +
  11330. + /* determine the message type */
  11331. + if(index == TEMP)
  11332. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  11333. + else if (index == MAX_TEMP)
  11334. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  11335. + else
  11336. + {
  11337. + print_debug("Unknown temperature message!");
  11338. + return -EINVAL;
  11339. + }
  11340. +
  11341. + msg.msg_size = sizeof msg;
  11342. + msg.tag.buffer_size = 8;
  11343. +
  11344. + /* send the message */
  11345. + result = bcm_mailbox_property(&msg, sizeof msg);
  11346. +
  11347. + /* check if it was all ok and return the rate in milli degrees C */
  11348. + if (result == 0 && (msg.request_code & 0x80000000))
  11349. + temp = (uint)msg.tag.val;
  11350. + #ifdef HWMON_DEBUG_ENABLE
  11351. + else
  11352. + print_debug("Failed to get temperature!");
  11353. + #endif
  11354. + print_debug("Got temperature as %u",temp);
  11355. + print_debug("OUT");
  11356. + return sprintf(buf, "%u\n", temp);
  11357. +}
  11358. +
  11359. +
  11360. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  11361. +{
  11362. + int err;
  11363. +
  11364. + print_debug("IN");
  11365. + print_debug("HWMON Driver has been probed!");
  11366. +
  11367. + /* check that the device isn't null!*/
  11368. + if(pdev == NULL)
  11369. + {
  11370. + print_debug("Platform device is empty!");
  11371. + return -ENODEV;
  11372. + }
  11373. +
  11374. + /* allocate memory for neccessary data */
  11375. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  11376. + if(!bcm2835_data)
  11377. + {
  11378. + print_debug("Unable to allocate memory for hwmon data!");
  11379. + err = -ENOMEM;
  11380. + goto kzalloc_error;
  11381. + }
  11382. +
  11383. + /* create the sysfs files */
  11384. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  11385. + {
  11386. + print_debug("Unable to create sysfs files!");
  11387. + err = -EFAULT;
  11388. + goto sysfs_error;
  11389. + }
  11390. +
  11391. + /* register the hwmon device */
  11392. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  11393. + if (IS_ERR(bcm2835_data->hwmon_dev))
  11394. + {
  11395. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  11396. + goto hwmon_error;
  11397. + }
  11398. + print_debug("OUT");
  11399. + return 0;
  11400. +
  11401. + /* error goto's */
  11402. + hwmon_error:
  11403. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  11404. +
  11405. + sysfs_error:
  11406. + kfree(bcm2835_data);
  11407. +
  11408. + kzalloc_error:
  11409. +
  11410. + return err;
  11411. +
  11412. +}
  11413. +
  11414. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  11415. +{
  11416. + print_debug("IN");
  11417. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  11418. +
  11419. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  11420. + print_debug("OUT");
  11421. + return 0;
  11422. +}
  11423. +
  11424. +/* Hwmon Driver */
  11425. +static struct platform_driver bcm2835_hwmon_driver = {
  11426. + .probe = bcm2835_hwmon_probe,
  11427. + .remove = bcm2835_hwmon_remove,
  11428. + .driver = {
  11429. + .name = "bcm2835_hwmon",
  11430. + .owner = THIS_MODULE,
  11431. + },
  11432. +};
  11433. +
  11434. +MODULE_LICENSE("GPL");
  11435. +MODULE_AUTHOR("Dorian Peake");
  11436. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  11437. +
  11438. +module_platform_driver(bcm2835_hwmon_driver);
  11439. diff -Nur linux-3.10.33/drivers/hwmon/Kconfig linux-raspberry-pi/drivers/hwmon/Kconfig
  11440. --- linux-3.10.33/drivers/hwmon/Kconfig 2014-03-07 06:58:45.000000000 +0100
  11441. +++ linux-raspberry-pi/drivers/hwmon/Kconfig 2014-03-13 12:46:16.000050865 +0100
  11442. @@ -1528,6 +1528,16 @@
  11443. help
  11444. Support for the A/D converter on MC13783 and MC13892 PMIC.
  11445. +config SENSORS_BCM2835
  11446. + depends on THERMAL_BCM2835=n
  11447. + tristate "Broadcom BCM2835 HWMON Driver"
  11448. + help
  11449. + If you say yes here you get support for the hardware
  11450. + monitoring features of the BCM2835 Chip
  11451. +
  11452. + This driver can also be built as a module. If so, the module
  11453. + will be called bcm2835-hwmon.
  11454. +
  11455. if ACPI
  11456. comment "ACPI drivers"
  11457. diff -Nur linux-3.10.33/drivers/hwmon/Makefile linux-raspberry-pi/drivers/hwmon/Makefile
  11458. --- linux-3.10.33/drivers/hwmon/Makefile 2014-03-07 06:58:45.000000000 +0100
  11459. +++ linux-raspberry-pi/drivers/hwmon/Makefile 2014-03-13 12:46:16.000050865 +0100
  11460. @@ -140,6 +140,7 @@
  11461. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  11462. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  11463. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  11464. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  11465. obj-$(CONFIG_PMBUS) += pmbus/
  11466. diff -Nur linux-3.10.33/drivers/i2c/busses/i2c-bcm2708.c linux-raspberry-pi/drivers/i2c/busses/i2c-bcm2708.c
  11467. --- linux-3.10.33/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  11468. +++ linux-raspberry-pi/drivers/i2c/busses/i2c-bcm2708.c 2014-03-13 12:46:16.092051049 +0100
  11469. @@ -0,0 +1,419 @@
  11470. +/*
  11471. + * Driver for Broadcom BCM2708 BSC Controllers
  11472. + *
  11473. + * Copyright (C) 2012 Chris Boot & Frank Buss
  11474. + *
  11475. + * This driver is inspired by:
  11476. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  11477. + *
  11478. + * This program is free software; you can redistribute it and/or modify
  11479. + * it under the terms of the GNU General Public License as published by
  11480. + * the Free Software Foundation; either version 2 of the License, or
  11481. + * (at your option) any later version.
  11482. + *
  11483. + * This program is distributed in the hope that it will be useful,
  11484. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11485. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11486. + * GNU General Public License for more details.
  11487. + *
  11488. + * You should have received a copy of the GNU General Public License
  11489. + * along with this program; if not, write to the Free Software
  11490. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  11491. + */
  11492. +
  11493. +#include <linux/kernel.h>
  11494. +#include <linux/module.h>
  11495. +#include <linux/spinlock.h>
  11496. +#include <linux/clk.h>
  11497. +#include <linux/err.h>
  11498. +#include <linux/platform_device.h>
  11499. +#include <linux/io.h>
  11500. +#include <linux/slab.h>
  11501. +#include <linux/i2c.h>
  11502. +#include <linux/interrupt.h>
  11503. +#include <linux/sched.h>
  11504. +#include <linux/wait.h>
  11505. +
  11506. +/* BSC register offsets */
  11507. +#define BSC_C 0x00
  11508. +#define BSC_S 0x04
  11509. +#define BSC_DLEN 0x08
  11510. +#define BSC_A 0x0c
  11511. +#define BSC_FIFO 0x10
  11512. +#define BSC_DIV 0x14
  11513. +#define BSC_DEL 0x18
  11514. +#define BSC_CLKT 0x1c
  11515. +
  11516. +/* Bitfields in BSC_C */
  11517. +#define BSC_C_I2CEN 0x00008000
  11518. +#define BSC_C_INTR 0x00000400
  11519. +#define BSC_C_INTT 0x00000200
  11520. +#define BSC_C_INTD 0x00000100
  11521. +#define BSC_C_ST 0x00000080
  11522. +#define BSC_C_CLEAR_1 0x00000020
  11523. +#define BSC_C_CLEAR_2 0x00000010
  11524. +#define BSC_C_READ 0x00000001
  11525. +
  11526. +/* Bitfields in BSC_S */
  11527. +#define BSC_S_CLKT 0x00000200
  11528. +#define BSC_S_ERR 0x00000100
  11529. +#define BSC_S_RXF 0x00000080
  11530. +#define BSC_S_TXE 0x00000040
  11531. +#define BSC_S_RXD 0x00000020
  11532. +#define BSC_S_TXD 0x00000010
  11533. +#define BSC_S_RXR 0x00000008
  11534. +#define BSC_S_TXW 0x00000004
  11535. +#define BSC_S_DONE 0x00000002
  11536. +#define BSC_S_TA 0x00000001
  11537. +
  11538. +#define I2C_TIMEOUT_MS 150
  11539. +
  11540. +#define DRV_NAME "bcm2708_i2c"
  11541. +
  11542. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  11543. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  11544. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  11545. +
  11546. +
  11547. +struct bcm2708_i2c {
  11548. + struct i2c_adapter adapter;
  11549. +
  11550. + spinlock_t lock;
  11551. + void __iomem *base;
  11552. + int irq;
  11553. + struct clk *clk;
  11554. +
  11555. + struct completion done;
  11556. +
  11557. + struct i2c_msg *msg;
  11558. + int pos;
  11559. + int nmsgs;
  11560. + bool error;
  11561. +};
  11562. +
  11563. +/*
  11564. + * This function sets the ALT mode on the I2C pins so that we can use them with
  11565. + * the BSC hardware.
  11566. + *
  11567. + * FIXME: This is a hack. Use pinmux / pinctrl.
  11568. + */
  11569. +static void bcm2708_i2c_init_pinmode(int id)
  11570. +{
  11571. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  11572. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  11573. +
  11574. + int pin;
  11575. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  11576. +
  11577. + BUG_ON(id != 0 && id != 1);
  11578. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  11579. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  11580. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  11581. + INP_GPIO(pin); /* set mode to GPIO input first */
  11582. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  11583. + }
  11584. +
  11585. + iounmap(gpio);
  11586. +
  11587. +#undef INP_GPIO
  11588. +#undef SET_GPIO_ALT
  11589. +}
  11590. +
  11591. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  11592. +{
  11593. + return readl(bi->base + reg);
  11594. +}
  11595. +
  11596. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  11597. +{
  11598. + writel(val, bi->base + reg);
  11599. +}
  11600. +
  11601. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  11602. +{
  11603. + bcm2708_wr(bi, BSC_C, 0);
  11604. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  11605. +}
  11606. +
  11607. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  11608. +{
  11609. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  11610. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  11611. +}
  11612. +
  11613. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  11614. +{
  11615. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  11616. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  11617. +}
  11618. +
  11619. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  11620. +{
  11621. + unsigned long bus_hz;
  11622. + u32 cdiv;
  11623. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  11624. +
  11625. + bus_hz = clk_get_rate(bi->clk);
  11626. + cdiv = bus_hz / baudrate;
  11627. + if (cdiv > 0xffff)
  11628. + cdiv = 0xffff;
  11629. +
  11630. + if (bi->msg->flags & I2C_M_RD)
  11631. + c |= BSC_C_INTR | BSC_C_READ;
  11632. + else
  11633. + c |= BSC_C_INTT;
  11634. +
  11635. + bcm2708_wr(bi, BSC_DIV, cdiv);
  11636. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  11637. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  11638. + bcm2708_wr(bi, BSC_C, c);
  11639. +}
  11640. +
  11641. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  11642. +{
  11643. + struct bcm2708_i2c *bi = dev_id;
  11644. + bool handled = true;
  11645. + u32 s;
  11646. +
  11647. + spin_lock(&bi->lock);
  11648. +
  11649. + /* we may see camera interrupts on the "other" I2C channel
  11650. + Just return if we've not sent anything */
  11651. + if (!bi->nmsgs || !bi->msg )
  11652. + goto early_exit;
  11653. +
  11654. + s = bcm2708_rd(bi, BSC_S);
  11655. +
  11656. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  11657. + bcm2708_bsc_reset(bi);
  11658. + bi->error = true;
  11659. +
  11660. + /* wake up our bh */
  11661. + complete(&bi->done);
  11662. + } else if (s & BSC_S_DONE) {
  11663. + bi->nmsgs--;
  11664. +
  11665. + if (bi->msg->flags & I2C_M_RD)
  11666. + bcm2708_bsc_fifo_drain(bi);
  11667. +
  11668. + bcm2708_bsc_reset(bi);
  11669. +
  11670. + if (bi->nmsgs) {
  11671. + /* advance to next message */
  11672. + bi->msg++;
  11673. + bi->pos = 0;
  11674. + bcm2708_bsc_setup(bi);
  11675. + } else {
  11676. + /* wake up our bh */
  11677. + complete(&bi->done);
  11678. + }
  11679. + } else if (s & BSC_S_TXW) {
  11680. + bcm2708_bsc_fifo_fill(bi);
  11681. + } else if (s & BSC_S_RXR) {
  11682. + bcm2708_bsc_fifo_drain(bi);
  11683. + } else {
  11684. + handled = false;
  11685. + }
  11686. +
  11687. +early_exit:
  11688. + spin_unlock(&bi->lock);
  11689. +
  11690. + return handled ? IRQ_HANDLED : IRQ_NONE;
  11691. +}
  11692. +
  11693. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  11694. + struct i2c_msg *msgs, int num)
  11695. +{
  11696. + struct bcm2708_i2c *bi = adap->algo_data;
  11697. + unsigned long flags;
  11698. + int ret;
  11699. +
  11700. + spin_lock_irqsave(&bi->lock, flags);
  11701. +
  11702. + INIT_COMPLETION(bi->done);
  11703. + bi->msg = msgs;
  11704. + bi->pos = 0;
  11705. + bi->nmsgs = num;
  11706. + bi->error = false;
  11707. +
  11708. + spin_unlock_irqrestore(&bi->lock, flags);
  11709. +
  11710. + bcm2708_bsc_setup(bi);
  11711. +
  11712. + ret = wait_for_completion_timeout(&bi->done,
  11713. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  11714. + if (ret == 0) {
  11715. + dev_err(&adap->dev, "transfer timed out\n");
  11716. + spin_lock_irqsave(&bi->lock, flags);
  11717. + bcm2708_bsc_reset(bi);
  11718. + spin_unlock_irqrestore(&bi->lock, flags);
  11719. + return -ETIMEDOUT;
  11720. + }
  11721. +
  11722. + return bi->error ? -EIO : num;
  11723. +}
  11724. +
  11725. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  11726. +{
  11727. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  11728. +}
  11729. +
  11730. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  11731. + .master_xfer = bcm2708_i2c_master_xfer,
  11732. + .functionality = bcm2708_i2c_functionality,
  11733. +};
  11734. +
  11735. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  11736. +{
  11737. + struct resource *regs;
  11738. + int irq, err = -ENOMEM;
  11739. + struct clk *clk;
  11740. + struct bcm2708_i2c *bi;
  11741. + struct i2c_adapter *adap;
  11742. + unsigned long bus_hz;
  11743. + u32 cdiv;
  11744. +
  11745. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11746. + if (!regs) {
  11747. + dev_err(&pdev->dev, "could not get IO memory\n");
  11748. + return -ENXIO;
  11749. + }
  11750. +
  11751. + irq = platform_get_irq(pdev, 0);
  11752. + if (irq < 0) {
  11753. + dev_err(&pdev->dev, "could not get IRQ\n");
  11754. + return irq;
  11755. + }
  11756. +
  11757. + clk = clk_get(&pdev->dev, NULL);
  11758. + if (IS_ERR(clk)) {
  11759. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  11760. + return PTR_ERR(clk);
  11761. + }
  11762. +
  11763. + bcm2708_i2c_init_pinmode(pdev->id);
  11764. +
  11765. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  11766. + if (!bi)
  11767. + goto out_clk_put;
  11768. +
  11769. + platform_set_drvdata(pdev, bi);
  11770. +
  11771. + adap = &bi->adapter;
  11772. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  11773. + adap->algo = &bcm2708_i2c_algorithm;
  11774. + adap->algo_data = bi;
  11775. + adap->dev.parent = &pdev->dev;
  11776. + adap->nr = pdev->id;
  11777. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  11778. +
  11779. + switch (pdev->id) {
  11780. + case 0:
  11781. + adap->class = I2C_CLASS_HWMON;
  11782. + break;
  11783. + case 1:
  11784. + adap->class = I2C_CLASS_DDC;
  11785. + break;
  11786. + default:
  11787. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  11788. + err = -ENXIO;
  11789. + goto out_free_bi;
  11790. + }
  11791. +
  11792. + spin_lock_init(&bi->lock);
  11793. + init_completion(&bi->done);
  11794. +
  11795. + bi->base = ioremap(regs->start, resource_size(regs));
  11796. + if (!bi->base) {
  11797. + dev_err(&pdev->dev, "could not remap memory\n");
  11798. + goto out_free_bi;
  11799. + }
  11800. +
  11801. + bi->irq = irq;
  11802. + bi->clk = clk;
  11803. +
  11804. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  11805. + dev_name(&pdev->dev), bi);
  11806. + if (err) {
  11807. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  11808. + goto out_iounmap;
  11809. + }
  11810. +
  11811. + bcm2708_bsc_reset(bi);
  11812. +
  11813. + err = i2c_add_numbered_adapter(adap);
  11814. + if (err < 0) {
  11815. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  11816. + goto out_free_irq;
  11817. + }
  11818. +
  11819. + bus_hz = clk_get_rate(bi->clk);
  11820. + cdiv = bus_hz / baudrate;
  11821. + if (cdiv > 0xffff) {
  11822. + cdiv = 0xffff;
  11823. + baudrate = bus_hz / cdiv;
  11824. + }
  11825. +
  11826. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  11827. + pdev->id, (unsigned long)regs->start, irq, baudrate);
  11828. +
  11829. + return 0;
  11830. +
  11831. +out_free_irq:
  11832. + free_irq(bi->irq, bi);
  11833. +out_iounmap:
  11834. + iounmap(bi->base);
  11835. +out_free_bi:
  11836. + kfree(bi);
  11837. +out_clk_put:
  11838. + clk_put(clk);
  11839. + return err;
  11840. +}
  11841. +
  11842. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  11843. +{
  11844. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  11845. +
  11846. + platform_set_drvdata(pdev, NULL);
  11847. +
  11848. + i2c_del_adapter(&bi->adapter);
  11849. + free_irq(bi->irq, bi);
  11850. + iounmap(bi->base);
  11851. + clk_disable(bi->clk);
  11852. + clk_put(bi->clk);
  11853. + kfree(bi);
  11854. +
  11855. + return 0;
  11856. +}
  11857. +
  11858. +static struct platform_driver bcm2708_i2c_driver = {
  11859. + .driver = {
  11860. + .name = DRV_NAME,
  11861. + .owner = THIS_MODULE,
  11862. + },
  11863. + .probe = bcm2708_i2c_probe,
  11864. + .remove = bcm2708_i2c_remove,
  11865. +};
  11866. +
  11867. +// module_platform_driver(bcm2708_i2c_driver);
  11868. +
  11869. +
  11870. +static int __init bcm2708_i2c_init(void)
  11871. +{
  11872. + return platform_driver_register(&bcm2708_i2c_driver);
  11873. +}
  11874. +
  11875. +static void __exit bcm2708_i2c_exit(void)
  11876. +{
  11877. + platform_driver_unregister(&bcm2708_i2c_driver);
  11878. +}
  11879. +
  11880. +module_init(bcm2708_i2c_init);
  11881. +module_exit(bcm2708_i2c_exit);
  11882. +
  11883. +
  11884. +
  11885. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  11886. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  11887. +MODULE_LICENSE("GPL v2");
  11888. +MODULE_ALIAS("platform:" DRV_NAME);
  11889. diff -Nur linux-3.10.33/drivers/i2c/busses/Kconfig linux-raspberry-pi/drivers/i2c/busses/Kconfig
  11890. --- linux-3.10.33/drivers/i2c/busses/Kconfig 2014-03-07 06:58:45.000000000 +0100
  11891. +++ linux-raspberry-pi/drivers/i2c/busses/Kconfig 2014-03-13 12:46:16.092051049 +0100
  11892. @@ -345,6 +345,25 @@
  11893. This support is also available as a module. If so, the module
  11894. will be called i2c-bcm2835.
  11895. +config I2C_BCM2708
  11896. + tristate "BCM2708 BSC"
  11897. + depends on MACH_BCM2708
  11898. + help
  11899. + Enabling this option will add BSC (Broadcom Serial Controller)
  11900. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  11901. + with I2C/TWI/SMBus.
  11902. +
  11903. +config I2C_BCM2708_BAUDRATE
  11904. + prompt "BCM2708 I2C baudrate"
  11905. + depends on I2C_BCM2708
  11906. + int
  11907. + default 100000
  11908. + help
  11909. + Set the I2C baudrate. This will alter the default value. A
  11910. + different baudrate can be set by using a module parameter as well. If
  11911. + no parameter is provided when loading, this is the value that will be
  11912. + used.
  11913. +
  11914. config I2C_BLACKFIN_TWI
  11915. tristate "Blackfin TWI I2C support"
  11916. depends on BLACKFIN
  11917. diff -Nur linux-3.10.33/drivers/i2c/busses/Makefile linux-raspberry-pi/drivers/i2c/busses/Makefile
  11918. --- linux-3.10.33/drivers/i2c/busses/Makefile 2014-03-07 06:58:45.000000000 +0100
  11919. +++ linux-raspberry-pi/drivers/i2c/busses/Makefile 2014-03-13 12:46:16.092051049 +0100
  11920. @@ -32,6 +32,7 @@
  11921. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  11922. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  11923. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  11924. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  11925. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  11926. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  11927. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  11928. diff -Nur linux-3.10.33/drivers/media/dvb-core/dvb-usb-ids.h linux-raspberry-pi/drivers/media/dvb-core/dvb-usb-ids.h
  11929. --- linux-3.10.33/drivers/media/dvb-core/dvb-usb-ids.h 2014-03-07 06:58:45.000000000 +0100
  11930. +++ linux-raspberry-pi/drivers/media/dvb-core/dvb-usb-ids.h 2014-03-13 12:46:17.644054155 +0100
  11931. @@ -365,6 +365,7 @@
  11932. #define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac
  11933. #define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001
  11934. #define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002
  11935. +#define USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI 0x0003
  11936. #define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004
  11937. #define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500
  11938. #endif
  11939. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/bcm2835-camera.c linux-raspberry-pi/drivers/media/platform/bcm2835/bcm2835-camera.c
  11940. --- linux-3.10.33/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  11941. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-03-13 12:46:18.260055389 +0100
  11942. @@ -0,0 +1,1695 @@
  11943. +/*
  11944. + * Broadcom BM2835 V4L2 driver
  11945. + *
  11946. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  11947. + *
  11948. + * This file is subject to the terms and conditions of the GNU General Public
  11949. + * License. See the file COPYING in the main directory of this archive
  11950. + * for more details.
  11951. + *
  11952. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  11953. + * Dave Stevenson <dsteve@broadcom.com>
  11954. + * Simon Mellor <simellor@broadcom.com>
  11955. + * Luke Diamand <luked@broadcom.com>
  11956. + */
  11957. +
  11958. +#include <linux/errno.h>
  11959. +#include <linux/kernel.h>
  11960. +#include <linux/module.h>
  11961. +#include <linux/slab.h>
  11962. +#include <media/videobuf2-vmalloc.h>
  11963. +#include <media/videobuf2-dma-contig.h>
  11964. +#include <media/v4l2-device.h>
  11965. +#include <media/v4l2-ioctl.h>
  11966. +#include <media/v4l2-ctrls.h>
  11967. +#include <media/v4l2-fh.h>
  11968. +#include <media/v4l2-event.h>
  11969. +#include <media/v4l2-common.h>
  11970. +#include <linux/delay.h>
  11971. +
  11972. +#include "mmal-common.h"
  11973. +#include "mmal-encodings.h"
  11974. +#include "mmal-vchiq.h"
  11975. +#include "mmal-msg.h"
  11976. +#include "mmal-parameters.h"
  11977. +#include "bcm2835-camera.h"
  11978. +
  11979. +#define BM2835_MMAL_VERSION "0.0.2"
  11980. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  11981. +#define MIN_WIDTH 16
  11982. +#define MIN_HEIGHT 16
  11983. +#define MAX_WIDTH 2592
  11984. +#define MAX_HEIGHT 1944
  11985. +#define MIN_BUFFER_SIZE (80*1024)
  11986. +
  11987. +#define MAX_VIDEO_MODE_WIDTH 1280
  11988. +#define MAX_VIDEO_MODE_HEIGHT 720
  11989. +
  11990. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  11991. +MODULE_AUTHOR("Vincent Sanders");
  11992. +MODULE_LICENSE("GPL");
  11993. +MODULE_VERSION(BM2835_MMAL_VERSION);
  11994. +
  11995. +int bcm2835_v4l2_debug;
  11996. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  11997. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  11998. +
  11999. +static struct bm2835_mmal_dev *gdev; /* global device data */
  12000. +
  12001. +#define FPS_MIN 1
  12002. +#define FPS_MAX 90
  12003. +
  12004. +/* timeperframe: min/max and default */
  12005. +static const struct v4l2_fract
  12006. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  12007. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  12008. + tpf_default = {.numerator = 1000, .denominator = 30000};
  12009. +
  12010. +/* video formats */
  12011. +static struct mmal_fmt formats[] = {
  12012. + {
  12013. + .name = "4:2:0, packed YUV",
  12014. + .fourcc = V4L2_PIX_FMT_YUV420,
  12015. + .flags = 0,
  12016. + .mmal = MMAL_ENCODING_I420,
  12017. + .depth = 12,
  12018. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12019. + },
  12020. + {
  12021. + .name = "4:2:2, packed, YUYV",
  12022. + .fourcc = V4L2_PIX_FMT_YUYV,
  12023. + .flags = 0,
  12024. + .mmal = MMAL_ENCODING_YUYV,
  12025. + .depth = 16,
  12026. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12027. + },
  12028. + {
  12029. + .name = "RGB24 (LE)",
  12030. + .fourcc = V4L2_PIX_FMT_RGB24,
  12031. + .flags = 0,
  12032. + .mmal = MMAL_ENCODING_BGR24,
  12033. + .depth = 24,
  12034. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12035. + },
  12036. + {
  12037. + .name = "JPEG",
  12038. + .fourcc = V4L2_PIX_FMT_JPEG,
  12039. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  12040. + .mmal = MMAL_ENCODING_JPEG,
  12041. + .depth = 8,
  12042. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  12043. + },
  12044. + {
  12045. + .name = "H264",
  12046. + .fourcc = V4L2_PIX_FMT_H264,
  12047. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  12048. + .mmal = MMAL_ENCODING_H264,
  12049. + .depth = 8,
  12050. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  12051. + },
  12052. + {
  12053. + .name = "MJPEG",
  12054. + .fourcc = V4L2_PIX_FMT_MJPEG,
  12055. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  12056. + .mmal = MMAL_ENCODING_MJPEG,
  12057. + .depth = 8,
  12058. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  12059. + },
  12060. + {
  12061. + .name = "4:2:2, packed, YVYU",
  12062. + .fourcc = V4L2_PIX_FMT_YVYU,
  12063. + .flags = 0,
  12064. + .mmal = MMAL_ENCODING_YVYU,
  12065. + .depth = 16,
  12066. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12067. + },
  12068. + {
  12069. + .name = "4:2:2, packed, VYUY",
  12070. + .fourcc = V4L2_PIX_FMT_VYUY,
  12071. + .flags = 0,
  12072. + .mmal = MMAL_ENCODING_VYUY,
  12073. + .depth = 16,
  12074. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12075. + },
  12076. + {
  12077. + .name = "4:2:2, packed, UYVY",
  12078. + .fourcc = V4L2_PIX_FMT_UYVY,
  12079. + .flags = 0,
  12080. + .mmal = MMAL_ENCODING_UYVY,
  12081. + .depth = 16,
  12082. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12083. + },
  12084. + {
  12085. + .name = "4:2:0, packed, NV12",
  12086. + .fourcc = V4L2_PIX_FMT_NV12,
  12087. + .flags = 0,
  12088. + .mmal = MMAL_ENCODING_NV12,
  12089. + .depth = 12,
  12090. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12091. + },
  12092. +};
  12093. +
  12094. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  12095. +{
  12096. + struct mmal_fmt *fmt;
  12097. + unsigned int k;
  12098. +
  12099. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  12100. + fmt = &formats[k];
  12101. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  12102. + break;
  12103. + }
  12104. +
  12105. + if (k == ARRAY_SIZE(formats))
  12106. + return NULL;
  12107. +
  12108. + return &formats[k];
  12109. +}
  12110. +
  12111. +/* ------------------------------------------------------------------
  12112. + Videobuf queue operations
  12113. + ------------------------------------------------------------------*/
  12114. +
  12115. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  12116. + unsigned int *nbuffers, unsigned int *nplanes,
  12117. + unsigned int sizes[], void *alloc_ctxs[])
  12118. +{
  12119. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12120. + unsigned long size;
  12121. +
  12122. + /* refuse queue setup if port is not configured */
  12123. + if (dev->capture.port == NULL) {
  12124. + v4l2_err(&dev->v4l2_dev,
  12125. + "%s: capture port not configured\n", __func__);
  12126. + return -EINVAL;
  12127. + }
  12128. +
  12129. + size = dev->capture.port->current_buffer.size;
  12130. + if (size == 0) {
  12131. + v4l2_err(&dev->v4l2_dev,
  12132. + "%s: capture port buffer size is zero\n", __func__);
  12133. + return -EINVAL;
  12134. + }
  12135. +
  12136. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  12137. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  12138. +
  12139. + *nplanes = 1;
  12140. +
  12141. + sizes[0] = size;
  12142. +
  12143. + /*
  12144. + * videobuf2-vmalloc allocator is context-less so no need to set
  12145. + * alloc_ctxs array.
  12146. + */
  12147. +
  12148. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12149. + __func__, dev);
  12150. +
  12151. + return 0;
  12152. +}
  12153. +
  12154. +static int buffer_prepare(struct vb2_buffer *vb)
  12155. +{
  12156. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  12157. + unsigned long size;
  12158. +
  12159. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12160. + __func__, dev);
  12161. +
  12162. + BUG_ON(dev->capture.port == NULL);
  12163. + BUG_ON(dev->capture.fmt == NULL);
  12164. +
  12165. + size = dev->capture.stride * dev->capture.height;
  12166. + if (vb2_plane_size(vb, 0) < size) {
  12167. + v4l2_err(&dev->v4l2_dev,
  12168. + "%s data will not fit into plane (%lu < %lu)\n",
  12169. + __func__, vb2_plane_size(vb, 0), size);
  12170. + return -EINVAL;
  12171. + }
  12172. +
  12173. + return 0;
  12174. +}
  12175. +
  12176. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  12177. +{
  12178. + return dev->capture.camera_port ==
  12179. + &dev->
  12180. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  12181. +}
  12182. +
  12183. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  12184. + struct vchiq_mmal_port *port,
  12185. + int status,
  12186. + struct mmal_buffer *buf,
  12187. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  12188. +{
  12189. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  12190. +
  12191. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12192. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  12193. + __func__, status, buf, length, mmal_flags, pts);
  12194. +
  12195. + if (status != 0) {
  12196. + /* error in transfer */
  12197. + if (buf != NULL) {
  12198. + /* there was a buffer with the error so return it */
  12199. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  12200. + }
  12201. + return;
  12202. + } else if (length == 0) {
  12203. + /* stream ended */
  12204. + if (buf != NULL) {
  12205. + /* this should only ever happen if the port is
  12206. + * disabled and there are buffers still queued
  12207. + */
  12208. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  12209. + pr_debug("Empty buffer");
  12210. + } else if (dev->capture.frame_count) {
  12211. + /* grab another frame */
  12212. + if (is_capturing(dev)) {
  12213. + pr_debug("Grab another frame");
  12214. + vchiq_mmal_port_parameter_set(
  12215. + instance,
  12216. + dev->capture.
  12217. + camera_port,
  12218. + MMAL_PARAMETER_CAPTURE,
  12219. + &dev->capture.
  12220. + frame_count,
  12221. + sizeof(dev->capture.frame_count));
  12222. + }
  12223. + } else {
  12224. + /* signal frame completion */
  12225. + complete(&dev->capture.frame_cmplt);
  12226. + }
  12227. + } else {
  12228. + if (dev->capture.frame_count) {
  12229. + if (dev->capture.vc_start_timestamp != -1 &&
  12230. + pts != 0) {
  12231. + s64 runtime_us = pts -
  12232. + dev->capture.vc_start_timestamp;
  12233. + u32 div = 0;
  12234. + u32 rem = 0;
  12235. +
  12236. + div =
  12237. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  12238. + buf->vb.v4l2_buf.timestamp.tv_sec =
  12239. + dev->capture.kernel_start_ts.tv_sec - 1 +
  12240. + div;
  12241. + buf->vb.v4l2_buf.timestamp.tv_usec =
  12242. + dev->capture.kernel_start_ts.tv_usec + rem;
  12243. +
  12244. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  12245. + USEC_PER_SEC) {
  12246. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  12247. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  12248. + USEC_PER_SEC;
  12249. + }
  12250. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12251. + "Convert start time %d.%06d and %llu "
  12252. + "with offset %llu to %d.%06d\n",
  12253. + (int)dev->capture.kernel_start_ts.
  12254. + tv_sec,
  12255. + (int)dev->capture.kernel_start_ts.
  12256. + tv_usec,
  12257. + dev->capture.vc_start_timestamp, pts,
  12258. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  12259. + (int)buf->vb.v4l2_buf.timestamp.
  12260. + tv_usec);
  12261. + } else {
  12262. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  12263. + }
  12264. +
  12265. + vb2_set_plane_payload(&buf->vb, 0, length);
  12266. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  12267. +
  12268. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  12269. + is_capturing(dev)) {
  12270. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12271. + "Grab another frame as buffer has EOS");
  12272. + vchiq_mmal_port_parameter_set(
  12273. + instance,
  12274. + dev->capture.
  12275. + camera_port,
  12276. + MMAL_PARAMETER_CAPTURE,
  12277. + &dev->capture.
  12278. + frame_count,
  12279. + sizeof(dev->capture.frame_count));
  12280. + }
  12281. + } else {
  12282. + /* signal frame completion */
  12283. + complete(&dev->capture.frame_cmplt);
  12284. + }
  12285. + }
  12286. +}
  12287. +
  12288. +static int enable_camera(struct bm2835_mmal_dev *dev)
  12289. +{
  12290. + int ret;
  12291. + if (!dev->camera_use_count) {
  12292. + ret = vchiq_mmal_component_enable(
  12293. + dev->instance,
  12294. + dev->component[MMAL_COMPONENT_CAMERA]);
  12295. + if (ret < 0) {
  12296. + v4l2_err(&dev->v4l2_dev,
  12297. + "Failed enabling camera, ret %d\n", ret);
  12298. + return -EINVAL;
  12299. + }
  12300. + }
  12301. + dev->camera_use_count++;
  12302. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12303. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  12304. + dev->camera_use_count);
  12305. + return 0;
  12306. +}
  12307. +
  12308. +static int disable_camera(struct bm2835_mmal_dev *dev)
  12309. +{
  12310. + int ret;
  12311. + if (!dev->camera_use_count) {
  12312. + v4l2_err(&dev->v4l2_dev,
  12313. + "Disabled the camera when already disabled\n");
  12314. + return -EINVAL;
  12315. + }
  12316. + dev->camera_use_count--;
  12317. + if (!dev->camera_use_count) {
  12318. + unsigned int i = 0xFFFFFFFF;
  12319. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12320. + "Disabling camera\n");
  12321. + ret =
  12322. + vchiq_mmal_component_disable(
  12323. + dev->instance,
  12324. + dev->component[MMAL_COMPONENT_CAMERA]);
  12325. + if (ret < 0) {
  12326. + v4l2_err(&dev->v4l2_dev,
  12327. + "Failed disabling camera, ret %d\n", ret);
  12328. + return -EINVAL;
  12329. + }
  12330. + vchiq_mmal_port_parameter_set(
  12331. + dev->instance,
  12332. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  12333. + MMAL_PARAMETER_CAMERA_NUM, &i,
  12334. + sizeof(i));
  12335. + }
  12336. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12337. + "Camera refcount now %d\n", dev->camera_use_count);
  12338. + return 0;
  12339. +}
  12340. +
  12341. +static void buffer_queue(struct vb2_buffer *vb)
  12342. +{
  12343. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  12344. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  12345. + int ret;
  12346. +
  12347. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12348. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  12349. +
  12350. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  12351. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  12352. +
  12353. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  12354. + if (ret < 0)
  12355. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  12356. + __func__);
  12357. +}
  12358. +
  12359. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  12360. +{
  12361. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12362. + int ret;
  12363. + int parameter_size;
  12364. +
  12365. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12366. + __func__, dev);
  12367. +
  12368. + /* ensure a format has actually been set */
  12369. + if (dev->capture.port == NULL)
  12370. + return -EINVAL;
  12371. +
  12372. + if (enable_camera(dev) < 0) {
  12373. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  12374. + return -EINVAL;
  12375. + }
  12376. +
  12377. + /*init_completion(&dev->capture.frame_cmplt); */
  12378. +
  12379. + /* enable frame capture */
  12380. + dev->capture.frame_count = 1;
  12381. +
  12382. + /* if the preview is not already running, wait for a few frames for AGC
  12383. + * to settle down.
  12384. + */
  12385. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  12386. + msleep(300);
  12387. +
  12388. + /* enable the connection from camera to encoder (if applicable) */
  12389. + if (dev->capture.camera_port != dev->capture.port
  12390. + && dev->capture.camera_port) {
  12391. + ret = vchiq_mmal_port_enable(dev->instance,
  12392. + dev->capture.camera_port, NULL);
  12393. + if (ret) {
  12394. + v4l2_err(&dev->v4l2_dev,
  12395. + "Failed to enable encode tunnel - error %d\n",
  12396. + ret);
  12397. + return -1;
  12398. + }
  12399. + }
  12400. +
  12401. + /* Get VC timestamp at this point in time */
  12402. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  12403. + if (vchiq_mmal_port_parameter_get(dev->instance,
  12404. + dev->capture.camera_port,
  12405. + MMAL_PARAMETER_SYSTEM_TIME,
  12406. + &dev->capture.vc_start_timestamp,
  12407. + &parameter_size)) {
  12408. + v4l2_err(&dev->v4l2_dev,
  12409. + "Failed to get VC start time - update your VC f/w\n");
  12410. +
  12411. + /* Flag to indicate just to rely on kernel timestamps */
  12412. + dev->capture.vc_start_timestamp = -1;
  12413. + } else
  12414. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12415. + "Start time %lld size %d\n",
  12416. + dev->capture.vc_start_timestamp, parameter_size);
  12417. +
  12418. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  12419. +
  12420. + /* enable the camera port */
  12421. + dev->capture.port->cb_ctx = dev;
  12422. + ret =
  12423. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  12424. + if (ret) {
  12425. + v4l2_err(&dev->v4l2_dev,
  12426. + "Failed to enable capture port - error %d. "
  12427. + "Disabling camera port again\n", ret);
  12428. +
  12429. + vchiq_mmal_port_disable(dev->instance,
  12430. + dev->capture.camera_port);
  12431. + if (disable_camera(dev) < 0) {
  12432. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  12433. + return -EINVAL;
  12434. + }
  12435. + return -1;
  12436. + }
  12437. +
  12438. + /* capture the first frame */
  12439. + vchiq_mmal_port_parameter_set(dev->instance,
  12440. + dev->capture.camera_port,
  12441. + MMAL_PARAMETER_CAPTURE,
  12442. + &dev->capture.frame_count,
  12443. + sizeof(dev->capture.frame_count));
  12444. + return 0;
  12445. +}
  12446. +
  12447. +/* abort streaming and wait for last buffer */
  12448. +static int stop_streaming(struct vb2_queue *vq)
  12449. +{
  12450. + int ret;
  12451. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12452. +
  12453. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12454. + __func__, dev);
  12455. +
  12456. + init_completion(&dev->capture.frame_cmplt);
  12457. + dev->capture.frame_count = 0;
  12458. +
  12459. + /* ensure a format has actually been set */
  12460. + if (dev->capture.port == NULL)
  12461. + return -EINVAL;
  12462. +
  12463. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  12464. +
  12465. + /* stop capturing frames */
  12466. + vchiq_mmal_port_parameter_set(dev->instance,
  12467. + dev->capture.camera_port,
  12468. + MMAL_PARAMETER_CAPTURE,
  12469. + &dev->capture.frame_count,
  12470. + sizeof(dev->capture.frame_count));
  12471. +
  12472. + /* wait for last frame to complete */
  12473. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  12474. + if (ret <= 0)
  12475. + v4l2_err(&dev->v4l2_dev,
  12476. + "error %d waiting for frame completion\n", ret);
  12477. +
  12478. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12479. + "disabling connection\n");
  12480. +
  12481. + /* disable the connection from camera to encoder */
  12482. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  12483. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  12484. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12485. + "disabling port\n");
  12486. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  12487. + } else if (dev->capture.camera_port != dev->capture.port) {
  12488. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  12489. + ret);
  12490. + }
  12491. +
  12492. + if (disable_camera(dev) < 0) {
  12493. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  12494. + return -EINVAL;
  12495. + }
  12496. +
  12497. + return ret;
  12498. +}
  12499. +
  12500. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  12501. +{
  12502. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12503. + mutex_lock(&dev->mutex);
  12504. +}
  12505. +
  12506. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  12507. +{
  12508. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12509. + mutex_unlock(&dev->mutex);
  12510. +}
  12511. +
  12512. +static struct vb2_ops bm2835_mmal_video_qops = {
  12513. + .queue_setup = queue_setup,
  12514. + .buf_prepare = buffer_prepare,
  12515. + .buf_queue = buffer_queue,
  12516. + .start_streaming = start_streaming,
  12517. + .stop_streaming = stop_streaming,
  12518. + .wait_prepare = bm2835_mmal_unlock,
  12519. + .wait_finish = bm2835_mmal_lock,
  12520. +};
  12521. +
  12522. +/* ------------------------------------------------------------------
  12523. + IOCTL operations
  12524. + ------------------------------------------------------------------*/
  12525. +
  12526. +/* overlay ioctl */
  12527. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  12528. + struct v4l2_fmtdesc *f)
  12529. +{
  12530. + struct mmal_fmt *fmt;
  12531. +
  12532. + if (f->index >= ARRAY_SIZE(formats))
  12533. + return -EINVAL;
  12534. +
  12535. + fmt = &formats[f->index];
  12536. +
  12537. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12538. + f->pixelformat = fmt->fourcc;
  12539. + f->flags = fmt->flags;
  12540. +
  12541. + return 0;
  12542. +}
  12543. +
  12544. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  12545. + struct v4l2_format *f)
  12546. +{
  12547. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12548. +
  12549. + f->fmt.win = dev->overlay;
  12550. +
  12551. + return 0;
  12552. +}
  12553. +
  12554. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  12555. + struct v4l2_format *f)
  12556. +{
  12557. + /* Only support one format so get the current one. */
  12558. + vidioc_g_fmt_vid_overlay(file, priv, f);
  12559. +
  12560. + /* todo: allow the size and/or offset to be changed. */
  12561. + return 0;
  12562. +}
  12563. +
  12564. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  12565. + struct v4l2_format *f)
  12566. +{
  12567. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12568. +
  12569. + vidioc_try_fmt_vid_overlay(file, priv, f);
  12570. +
  12571. + dev->overlay = f->fmt.win;
  12572. +
  12573. + /* todo: program the preview port parameters */
  12574. + return 0;
  12575. +}
  12576. +
  12577. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  12578. +{
  12579. + int ret;
  12580. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12581. + struct vchiq_mmal_port *src;
  12582. + struct vchiq_mmal_port *dst;
  12583. + struct mmal_parameter_displayregion prev_config = {
  12584. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  12585. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  12586. + .layer = PREVIEW_LAYER,
  12587. + .alpha = 255,
  12588. + .fullscreen = 0,
  12589. + .dest_rect = {
  12590. + .x = dev->overlay.w.left,
  12591. + .y = dev->overlay.w.top,
  12592. + .width = dev->overlay.w.width,
  12593. + .height = dev->overlay.w.height,
  12594. + },
  12595. + };
  12596. +
  12597. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  12598. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  12599. + return 0; /* already in requested state */
  12600. +
  12601. + src =
  12602. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12603. + output[MMAL_CAMERA_PORT_PREVIEW];
  12604. +
  12605. + if (!on) {
  12606. + /* disconnect preview ports and disable component */
  12607. + ret = vchiq_mmal_port_disable(dev->instance, src);
  12608. + if (!ret)
  12609. + ret =
  12610. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  12611. + NULL);
  12612. + if (ret >= 0)
  12613. + ret = vchiq_mmal_component_disable(
  12614. + dev->instance,
  12615. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12616. +
  12617. + disable_camera(dev);
  12618. + return ret;
  12619. + }
  12620. +
  12621. + /* set preview port format and connect it to output */
  12622. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  12623. +
  12624. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  12625. + if (ret < 0)
  12626. + goto error;
  12627. +
  12628. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  12629. + MMAL_PARAMETER_DISPLAYREGION,
  12630. + &prev_config, sizeof(prev_config));
  12631. + if (ret < 0)
  12632. + goto error;
  12633. +
  12634. + if (enable_camera(dev) < 0)
  12635. + goto error;
  12636. +
  12637. + ret = vchiq_mmal_component_enable(
  12638. + dev->instance,
  12639. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12640. + if (ret < 0)
  12641. + goto error;
  12642. +
  12643. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  12644. + src, dst);
  12645. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  12646. + if (!ret)
  12647. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  12648. +error:
  12649. + return ret;
  12650. +}
  12651. +
  12652. +static int vidioc_g_fbuf(struct file *file, void *fh,
  12653. + struct v4l2_framebuffer *a)
  12654. +{
  12655. + /* The video overlay must stay within the framebuffer and can't be
  12656. + positioned independently. */
  12657. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12658. + struct vchiq_mmal_port *preview_port =
  12659. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12660. + output[MMAL_CAMERA_PORT_PREVIEW];
  12661. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  12662. + a->fmt.width = preview_port->es.video.width;
  12663. + a->fmt.height = preview_port->es.video.height;
  12664. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  12665. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  12666. + a->fmt.sizeimage = (preview_port->es.video.width *
  12667. + preview_port->es.video.height * 3)>>1;
  12668. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  12669. +
  12670. + return 0;
  12671. +}
  12672. +
  12673. +/* input ioctls */
  12674. +static int vidioc_enum_input(struct file *file, void *priv,
  12675. + struct v4l2_input *inp)
  12676. +{
  12677. + /* only a single camera input */
  12678. + if (inp->index != 0)
  12679. + return -EINVAL;
  12680. +
  12681. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  12682. + sprintf(inp->name, "Camera %u", inp->index);
  12683. + return 0;
  12684. +}
  12685. +
  12686. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  12687. +{
  12688. + *i = 0;
  12689. + return 0;
  12690. +}
  12691. +
  12692. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  12693. +{
  12694. + if (i != 0)
  12695. + return -EINVAL;
  12696. +
  12697. + return 0;
  12698. +}
  12699. +
  12700. +/* capture ioctls */
  12701. +static int vidioc_querycap(struct file *file, void *priv,
  12702. + struct v4l2_capability *cap)
  12703. +{
  12704. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12705. + u32 major;
  12706. + u32 minor;
  12707. +
  12708. + vchiq_mmal_version(dev->instance, &major, &minor);
  12709. +
  12710. + strcpy(cap->driver, "bm2835 mmal");
  12711. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  12712. + major, minor);
  12713. +
  12714. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  12715. + "platform:%s", dev->v4l2_dev.name);
  12716. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  12717. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  12718. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  12719. +
  12720. + return 0;
  12721. +}
  12722. +
  12723. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  12724. + struct v4l2_fmtdesc *f)
  12725. +{
  12726. + struct mmal_fmt *fmt;
  12727. +
  12728. + if (f->index >= ARRAY_SIZE(formats))
  12729. + return -EINVAL;
  12730. +
  12731. + fmt = &formats[f->index];
  12732. +
  12733. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12734. + f->pixelformat = fmt->fourcc;
  12735. + f->flags = fmt->flags;
  12736. +
  12737. + return 0;
  12738. +}
  12739. +
  12740. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  12741. + struct v4l2_format *f)
  12742. +{
  12743. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12744. +
  12745. + f->fmt.pix.width = dev->capture.width;
  12746. + f->fmt.pix.height = dev->capture.height;
  12747. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12748. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  12749. + f->fmt.pix.bytesperline =
  12750. + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  12751. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12752. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  12753. + && f->fmt.pix.sizeimage < (100 << 10)) {
  12754. + /* Need a minimum size for JPEG to account for EXIF. */
  12755. + f->fmt.pix.sizeimage = (100 << 10);
  12756. + }
  12757. +
  12758. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12759. + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  12760. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12761. + else
  12762. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12763. + f->fmt.pix.priv = 0;
  12764. +
  12765. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12766. + __func__);
  12767. + return 0;
  12768. +}
  12769. +
  12770. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  12771. + struct v4l2_format *f)
  12772. +{
  12773. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12774. + struct mmal_fmt *mfmt;
  12775. +
  12776. + mfmt = get_format(f);
  12777. + if (!mfmt) {
  12778. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12779. + "Fourcc format (0x%08x) unknown.\n",
  12780. + f->fmt.pix.pixelformat);
  12781. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12782. + mfmt = get_format(f);
  12783. + }
  12784. +
  12785. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12786. + /* image must be a multiple of 32 pixels wide and 16 lines high */
  12787. + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  12788. + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  12789. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  12790. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12791. + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  12792. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  12793. +
  12794. + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12795. + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  12796. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12797. + else
  12798. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12799. + f->fmt.pix.priv = 0;
  12800. +
  12801. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12802. + __func__);
  12803. + return 0;
  12804. +}
  12805. +
  12806. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  12807. + struct v4l2_format *f)
  12808. +{
  12809. + int ret;
  12810. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  12811. + struct vchiq_mmal_component *encode_component = NULL;
  12812. + struct mmal_fmt *mfmt = get_format(f);
  12813. +
  12814. + BUG_ON(!mfmt);
  12815. +
  12816. + if (dev->capture.encode_component) {
  12817. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12818. + "vid_cap - disconnect previous tunnel\n");
  12819. +
  12820. + /* Disconnect any previous connection */
  12821. + vchiq_mmal_port_connect_tunnel(dev->instance,
  12822. + dev->capture.camera_port, NULL);
  12823. + dev->capture.camera_port = NULL;
  12824. + ret = vchiq_mmal_component_disable(dev->instance,
  12825. + dev->capture.
  12826. + encode_component);
  12827. + if (ret)
  12828. + v4l2_err(&dev->v4l2_dev,
  12829. + "Failed to disable encode component %d\n",
  12830. + ret);
  12831. +
  12832. + dev->capture.encode_component = NULL;
  12833. + }
  12834. + /* format dependant port setup */
  12835. + switch (mfmt->mmal_component) {
  12836. + case MMAL_COMPONENT_CAMERA:
  12837. + /* Make a further decision on port based on resolution */
  12838. + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  12839. + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  12840. + camera_port = port =
  12841. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12842. + output[MMAL_CAMERA_PORT_VIDEO];
  12843. + else
  12844. + camera_port = port =
  12845. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12846. + output[MMAL_CAMERA_PORT_CAPTURE];
  12847. + break;
  12848. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12849. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  12850. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  12851. + camera_port =
  12852. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12853. + output[MMAL_CAMERA_PORT_CAPTURE];
  12854. + break;
  12855. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12856. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  12857. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12858. + camera_port =
  12859. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12860. + output[MMAL_CAMERA_PORT_VIDEO];
  12861. + break;
  12862. + default:
  12863. + break;
  12864. + }
  12865. +
  12866. + if (!port)
  12867. + return -EINVAL;
  12868. +
  12869. + if (encode_component)
  12870. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  12871. + else
  12872. + camera_port->format.encoding = mfmt->mmal;
  12873. +
  12874. + camera_port->format.encoding_variant = 0;
  12875. + camera_port->es.video.width = f->fmt.pix.width;
  12876. + camera_port->es.video.height = f->fmt.pix.height;
  12877. + camera_port->es.video.crop.x = 0;
  12878. + camera_port->es.video.crop.y = 0;
  12879. + camera_port->es.video.crop.width = f->fmt.pix.width;
  12880. + camera_port->es.video.crop.height = f->fmt.pix.height;
  12881. + camera_port->es.video.frame_rate.num = 0;
  12882. + camera_port->es.video.frame_rate.den = 1;
  12883. +
  12884. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  12885. +
  12886. + if (!ret
  12887. + && camera_port ==
  12888. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12889. + output[MMAL_CAMERA_PORT_VIDEO]) {
  12890. + bool overlay_enabled =
  12891. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  12892. + struct vchiq_mmal_port *preview_port =
  12893. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12894. + output[MMAL_CAMERA_PORT_PREVIEW];
  12895. + /* Preview and encode ports need to match on resolution */
  12896. + if (overlay_enabled) {
  12897. + /* Need to disable the overlay before we can update
  12898. + * the resolution
  12899. + */
  12900. + ret =
  12901. + vchiq_mmal_port_disable(dev->instance,
  12902. + preview_port);
  12903. + if (!ret)
  12904. + ret =
  12905. + vchiq_mmal_port_connect_tunnel(
  12906. + dev->instance,
  12907. + preview_port,
  12908. + NULL);
  12909. + }
  12910. + preview_port->es.video.width = f->fmt.pix.width;
  12911. + preview_port->es.video.height = f->fmt.pix.height;
  12912. + preview_port->es.video.crop.x = 0;
  12913. + preview_port->es.video.crop.y = 0;
  12914. + preview_port->es.video.crop.width = f->fmt.pix.width;
  12915. + preview_port->es.video.crop.height = f->fmt.pix.height;
  12916. + preview_port->es.video.frame_rate.num =
  12917. + dev->capture.timeperframe.denominator;
  12918. + preview_port->es.video.frame_rate.den =
  12919. + dev->capture.timeperframe.numerator;
  12920. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  12921. + if (overlay_enabled) {
  12922. + ret = vchiq_mmal_port_connect_tunnel(
  12923. + dev->instance,
  12924. + preview_port,
  12925. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  12926. + if (!ret)
  12927. + ret = vchiq_mmal_port_enable(dev->instance,
  12928. + preview_port,
  12929. + NULL);
  12930. + }
  12931. + }
  12932. +
  12933. + if (ret) {
  12934. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12935. + "%s failed to set format\n", __func__);
  12936. + /* ensure capture is not going to be tried */
  12937. + dev->capture.port = NULL;
  12938. + } else {
  12939. + if (encode_component) {
  12940. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12941. + "vid_cap - set up encode comp\n");
  12942. +
  12943. + /* configure buffering */
  12944. + camera_port->current_buffer.size =
  12945. + camera_port->recommended_buffer.size;
  12946. + camera_port->current_buffer.num =
  12947. + camera_port->recommended_buffer.num;
  12948. +
  12949. + ret =
  12950. + vchiq_mmal_port_connect_tunnel(
  12951. + dev->instance,
  12952. + camera_port,
  12953. + &encode_component->input[0]);
  12954. + if (ret) {
  12955. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12956. + &dev->v4l2_dev,
  12957. + "%s failed to create connection\n",
  12958. + __func__);
  12959. + /* ensure capture is not going to be tried */
  12960. + dev->capture.port = NULL;
  12961. + } else {
  12962. + port->es.video.width = f->fmt.pix.width;
  12963. + port->es.video.height = f->fmt.pix.height;
  12964. + port->es.video.crop.x = 0;
  12965. + port->es.video.crop.y = 0;
  12966. + port->es.video.crop.width = f->fmt.pix.width;
  12967. + port->es.video.crop.height = f->fmt.pix.height;
  12968. + port->es.video.frame_rate.num =
  12969. + dev->capture.timeperframe.denominator;
  12970. + port->es.video.frame_rate.den =
  12971. + dev->capture.timeperframe.numerator;
  12972. +
  12973. + port->format.encoding = mfmt->mmal;
  12974. + port->format.encoding_variant = 0;
  12975. + /* Set any encoding specific parameters */
  12976. + switch (mfmt->mmal_component) {
  12977. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12978. + port->format.bitrate =
  12979. + dev->capture.encode_bitrate;
  12980. + break;
  12981. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12982. + /* Could set EXIF parameters here */
  12983. + break;
  12984. + default:
  12985. + break;
  12986. + }
  12987. + ret = vchiq_mmal_port_set_format(dev->instance,
  12988. + port);
  12989. + if (ret)
  12990. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12991. + &dev->v4l2_dev,
  12992. + "%s failed to set format\n",
  12993. + __func__);
  12994. + }
  12995. +
  12996. + if (!ret) {
  12997. + ret = vchiq_mmal_component_enable(
  12998. + dev->instance,
  12999. + encode_component);
  13000. + if (ret) {
  13001. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13002. + &dev->v4l2_dev,
  13003. + "%s Failed to enable encode components\n",
  13004. + __func__);
  13005. + }
  13006. + }
  13007. + if (!ret) {
  13008. + /* configure buffering */
  13009. + port->current_buffer.num = 1;
  13010. + port->current_buffer.size =
  13011. + f->fmt.pix.sizeimage;
  13012. + if (port->format.encoding ==
  13013. + MMAL_ENCODING_JPEG) {
  13014. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13015. + &dev->v4l2_dev,
  13016. + "JPG - buf size now %d was %d\n",
  13017. + f->fmt.pix.sizeimage,
  13018. + port->current_buffer.size);
  13019. + port->current_buffer.size =
  13020. + (f->fmt.pix.sizeimage <
  13021. + (100 << 10))
  13022. + ? (100 << 10) : f->fmt.pix.
  13023. + sizeimage;
  13024. + }
  13025. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13026. + &dev->v4l2_dev,
  13027. + "vid_cap - cur_buf.size set to %d\n",
  13028. + f->fmt.pix.sizeimage);
  13029. + port->current_buffer.alignment = 0;
  13030. + }
  13031. + } else {
  13032. + /* configure buffering */
  13033. + camera_port->current_buffer.num = 1;
  13034. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  13035. + camera_port->current_buffer.alignment = 0;
  13036. + }
  13037. +
  13038. + if (!ret) {
  13039. + dev->capture.fmt = mfmt;
  13040. + dev->capture.stride = f->fmt.pix.bytesperline;
  13041. + dev->capture.width = camera_port->es.video.crop.width;
  13042. + dev->capture.height = camera_port->es.video.crop.height;
  13043. +
  13044. + /* select port for capture */
  13045. + dev->capture.port = port;
  13046. + dev->capture.camera_port = camera_port;
  13047. + dev->capture.encode_component = encode_component;
  13048. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13049. + &dev->v4l2_dev,
  13050. + "Set dev->capture.fmt %08X, %dx%d, stride %d",
  13051. + port->format.encoding,
  13052. + dev->capture.width, dev->capture.height,
  13053. + dev->capture.stride);
  13054. + }
  13055. + }
  13056. +
  13057. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  13058. + return ret;
  13059. +}
  13060. +
  13061. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  13062. + struct v4l2_format *f)
  13063. +{
  13064. + int ret;
  13065. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13066. + struct mmal_fmt *mfmt;
  13067. +
  13068. + /* try the format to set valid parameters */
  13069. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  13070. + if (ret) {
  13071. + v4l2_err(&dev->v4l2_dev,
  13072. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  13073. + return ret;
  13074. + }
  13075. +
  13076. + /* if a capture is running refuse to set format */
  13077. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  13078. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  13079. + return -EBUSY;
  13080. + }
  13081. +
  13082. + /* If the format is unsupported v4l2 says we should switch to
  13083. + * a supported one and not return an error. */
  13084. + mfmt = get_format(f);
  13085. + if (!mfmt) {
  13086. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13087. + "Fourcc format (0x%08x) unknown.\n",
  13088. + f->fmt.pix.pixelformat);
  13089. + f->fmt.pix.pixelformat = formats[0].fourcc;
  13090. + mfmt = get_format(f);
  13091. + }
  13092. +
  13093. + ret = mmal_setup_components(dev, f);
  13094. + if (ret != 0) {
  13095. + v4l2_err(&dev->v4l2_dev,
  13096. + "%s: failed to setup mmal components: %d\n",
  13097. + __func__, ret);
  13098. + ret = -EINVAL;
  13099. + }
  13100. +
  13101. + return ret;
  13102. +}
  13103. +
  13104. +int vidioc_enum_framesizes(struct file *file, void *fh,
  13105. + struct v4l2_frmsizeenum *fsize)
  13106. +{
  13107. + static const struct v4l2_frmsize_stepwise sizes = {
  13108. + MIN_WIDTH, MAX_WIDTH, 2,
  13109. + MIN_HEIGHT, MAX_HEIGHT, 2
  13110. + };
  13111. + int i;
  13112. +
  13113. + if (fsize->index)
  13114. + return -EINVAL;
  13115. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  13116. + if (formats[i].fourcc == fsize->pixel_format)
  13117. + break;
  13118. + if (i == ARRAY_SIZE(formats))
  13119. + return -EINVAL;
  13120. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  13121. + fsize->stepwise = sizes;
  13122. + return 0;
  13123. +}
  13124. +
  13125. +/* timeperframe is arbitrary and continous */
  13126. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  13127. + struct v4l2_frmivalenum *fival)
  13128. +{
  13129. + int i;
  13130. +
  13131. + if (fival->index)
  13132. + return -EINVAL;
  13133. +
  13134. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  13135. + if (formats[i].fourcc == fival->pixel_format)
  13136. + break;
  13137. + if (i == ARRAY_SIZE(formats))
  13138. + return -EINVAL;
  13139. +
  13140. + /* regarding width & height - we support any within range */
  13141. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  13142. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  13143. + return -EINVAL;
  13144. +
  13145. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  13146. +
  13147. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  13148. + fival->stepwise.min = tpf_min;
  13149. + fival->stepwise.max = tpf_max;
  13150. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  13151. +
  13152. + return 0;
  13153. +}
  13154. +
  13155. +static int vidioc_g_parm(struct file *file, void *priv,
  13156. + struct v4l2_streamparm *parm)
  13157. +{
  13158. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13159. +
  13160. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  13161. + return -EINVAL;
  13162. +
  13163. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  13164. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  13165. + parm->parm.capture.readbuffers = 1;
  13166. + return 0;
  13167. +}
  13168. +
  13169. +#define FRACT_CMP(a, OP, b) \
  13170. + ((u64)(a).numerator * (b).denominator OP \
  13171. + (u64)(b).numerator * (a).denominator)
  13172. +
  13173. +static int vidioc_s_parm(struct file *file, void *priv,
  13174. + struct v4l2_streamparm *parm)
  13175. +{
  13176. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13177. + struct v4l2_fract tpf;
  13178. + struct mmal_parameter_rational fps_param;
  13179. +
  13180. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  13181. + return -EINVAL;
  13182. +
  13183. + tpf = parm->parm.capture.timeperframe;
  13184. +
  13185. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  13186. + tpf = tpf.denominator ? tpf : tpf_default;
  13187. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  13188. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  13189. +
  13190. + dev->capture.timeperframe = tpf;
  13191. + parm->parm.capture.timeperframe = tpf;
  13192. + parm->parm.capture.readbuffers = 1;
  13193. +
  13194. + fps_param.num = 0; /* Select variable fps, and then use
  13195. + * FPS_RANGE to select the actual limits.
  13196. + */
  13197. + fps_param.den = 1;
  13198. + set_framerate_params(dev);
  13199. +
  13200. + return 0;
  13201. +}
  13202. +
  13203. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  13204. + /* overlay */
  13205. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  13206. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  13207. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  13208. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  13209. + .vidioc_overlay = vidioc_overlay,
  13210. + .vidioc_g_fbuf = vidioc_g_fbuf,
  13211. +
  13212. + /* inputs */
  13213. + .vidioc_enum_input = vidioc_enum_input,
  13214. + .vidioc_g_input = vidioc_g_input,
  13215. + .vidioc_s_input = vidioc_s_input,
  13216. +
  13217. + /* capture */
  13218. + .vidioc_querycap = vidioc_querycap,
  13219. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  13220. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  13221. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  13222. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  13223. +
  13224. + /* buffer management */
  13225. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  13226. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  13227. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  13228. + .vidioc_querybuf = vb2_ioctl_querybuf,
  13229. + .vidioc_qbuf = vb2_ioctl_qbuf,
  13230. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  13231. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  13232. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  13233. + .vidioc_g_parm = vidioc_g_parm,
  13234. + .vidioc_s_parm = vidioc_s_parm,
  13235. + .vidioc_streamon = vb2_ioctl_streamon,
  13236. + .vidioc_streamoff = vb2_ioctl_streamoff,
  13237. +
  13238. + .vidioc_log_status = v4l2_ctrl_log_status,
  13239. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  13240. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  13241. +};
  13242. +
  13243. +/* ------------------------------------------------------------------
  13244. + Driver init/finalise
  13245. + ------------------------------------------------------------------*/
  13246. +
  13247. +static const struct v4l2_file_operations camera0_fops = {
  13248. + .owner = THIS_MODULE,
  13249. + .open = v4l2_fh_open,
  13250. + .release = vb2_fop_release,
  13251. + .read = vb2_fop_read,
  13252. + .poll = vb2_fop_poll,
  13253. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  13254. + .mmap = vb2_fop_mmap,
  13255. +};
  13256. +
  13257. +static struct video_device vdev_template = {
  13258. + .name = "camera0",
  13259. + .fops = &camera0_fops,
  13260. + .ioctl_ops = &camera0_ioctl_ops,
  13261. + .release = video_device_release_empty,
  13262. +};
  13263. +
  13264. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  13265. + struct vchiq_mmal_component *camera)
  13266. +{
  13267. + int ret;
  13268. + struct mmal_parameter_camera_config cam_config = {
  13269. + .max_stills_w = MAX_WIDTH,
  13270. + .max_stills_h = MAX_HEIGHT,
  13271. + .stills_yuv422 = 1,
  13272. + .one_shot_stills = 1,
  13273. + .max_preview_video_w = 1920,
  13274. + .max_preview_video_h = 1088,
  13275. + .num_preview_video_frames = 3,
  13276. + .stills_capture_circular_buffer_height = 0,
  13277. + .fast_preview_resume = 0,
  13278. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  13279. + };
  13280. +
  13281. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  13282. + MMAL_PARAMETER_CAMERA_CONFIG,
  13283. + &cam_config, sizeof(cam_config));
  13284. + return ret;
  13285. +}
  13286. +
  13287. +/* MMAL instance and component init */
  13288. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  13289. +{
  13290. + int ret;
  13291. + struct mmal_es_format *format;
  13292. +
  13293. + ret = vchiq_mmal_init(&dev->instance);
  13294. + if (ret < 0)
  13295. + return ret;
  13296. +
  13297. + /* get the camera component ready */
  13298. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  13299. + &dev->component[MMAL_COMPONENT_CAMERA]);
  13300. + if (ret < 0)
  13301. + goto unreg_mmal;
  13302. +
  13303. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  13304. + MMAL_CAMERA_PORT_COUNT) {
  13305. + ret = -EINVAL;
  13306. + goto unreg_camera;
  13307. + }
  13308. +
  13309. + ret = set_camera_parameters(dev->instance,
  13310. + dev->component[MMAL_COMPONENT_CAMERA]);
  13311. + if (ret < 0)
  13312. + goto unreg_camera;
  13313. +
  13314. + format =
  13315. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13316. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  13317. +
  13318. + format->encoding = MMAL_ENCODING_OPAQUE;
  13319. + format->encoding_variant = MMAL_ENCODING_I420;
  13320. +
  13321. + format->es->video.width = 1024;
  13322. + format->es->video.height = 768;
  13323. + format->es->video.crop.x = 0;
  13324. + format->es->video.crop.y = 0;
  13325. + format->es->video.crop.width = 1024;
  13326. + format->es->video.crop.height = 768;
  13327. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  13328. + format->es->video.frame_rate.den = 1;
  13329. +
  13330. + format =
  13331. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13332. + output[MMAL_CAMERA_PORT_VIDEO].format;
  13333. +
  13334. + format->encoding = MMAL_ENCODING_OPAQUE;
  13335. + format->encoding_variant = MMAL_ENCODING_I420;
  13336. +
  13337. + format->es->video.width = 1024;
  13338. + format->es->video.height = 768;
  13339. + format->es->video.crop.x = 0;
  13340. + format->es->video.crop.y = 0;
  13341. + format->es->video.crop.width = 1024;
  13342. + format->es->video.crop.height = 768;
  13343. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  13344. + format->es->video.frame_rate.den = 1;
  13345. +
  13346. + format =
  13347. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13348. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  13349. +
  13350. + format->encoding = MMAL_ENCODING_OPAQUE;
  13351. +
  13352. + format->es->video.width = 2592;
  13353. + format->es->video.height = 1944;
  13354. + format->es->video.crop.x = 0;
  13355. + format->es->video.crop.y = 0;
  13356. + format->es->video.crop.width = 2592;
  13357. + format->es->video.crop.height = 1944;
  13358. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  13359. + format->es->video.frame_rate.den = 1;
  13360. +
  13361. + dev->capture.width = format->es->video.width;
  13362. + dev->capture.height = format->es->video.height;
  13363. + dev->capture.fmt = &formats[0];
  13364. + dev->capture.encode_component = NULL;
  13365. + dev->capture.timeperframe = tpf_default;
  13366. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  13367. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  13368. +
  13369. + /* get the preview component ready */
  13370. + ret = vchiq_mmal_component_init(
  13371. + dev->instance, "ril.video_render",
  13372. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  13373. + if (ret < 0)
  13374. + goto unreg_camera;
  13375. +
  13376. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  13377. + ret = -EINVAL;
  13378. + pr_debug("too few input ports %d needed %d\n",
  13379. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  13380. + goto unreg_preview;
  13381. + }
  13382. +
  13383. + /* get the image encoder component ready */
  13384. + ret = vchiq_mmal_component_init(
  13385. + dev->instance, "ril.image_encode",
  13386. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13387. + if (ret < 0)
  13388. + goto unreg_preview;
  13389. +
  13390. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  13391. + ret = -EINVAL;
  13392. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  13393. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  13394. + 1);
  13395. + goto unreg_image_encoder;
  13396. + }
  13397. +
  13398. + /* get the video encoder component ready */
  13399. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  13400. + &dev->
  13401. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13402. + if (ret < 0)
  13403. + goto unreg_image_encoder;
  13404. +
  13405. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  13406. + ret = -EINVAL;
  13407. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  13408. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  13409. + 1);
  13410. + goto unreg_vid_encoder;
  13411. + }
  13412. +
  13413. + {
  13414. + struct vchiq_mmal_port *encoder_port =
  13415. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13416. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  13417. + ret = vchiq_mmal_port_set_format(dev->instance,
  13418. + encoder_port);
  13419. + }
  13420. +
  13421. + {
  13422. + unsigned int enable = 1;
  13423. + vchiq_mmal_port_parameter_set(
  13424. + dev->instance,
  13425. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  13426. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  13427. + &enable, sizeof(enable));
  13428. +
  13429. + vchiq_mmal_port_parameter_set(dev->instance,
  13430. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  13431. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  13432. + &enable,
  13433. + sizeof(enable));
  13434. + }
  13435. + ret = bm2835_mmal_set_all_camera_controls(dev);
  13436. + if (ret < 0)
  13437. + goto unreg_vid_encoder;
  13438. +
  13439. + return 0;
  13440. +
  13441. +unreg_vid_encoder:
  13442. + pr_err("Cleanup: Destroy video encoder\n");
  13443. + vchiq_mmal_component_finalise(
  13444. + dev->instance,
  13445. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13446. +
  13447. +unreg_image_encoder:
  13448. + pr_err("Cleanup: Destroy image encoder\n");
  13449. + vchiq_mmal_component_finalise(
  13450. + dev->instance,
  13451. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13452. +
  13453. +unreg_preview:
  13454. + pr_err("Cleanup: Destroy video render\n");
  13455. + vchiq_mmal_component_finalise(dev->instance,
  13456. + dev->component[MMAL_COMPONENT_PREVIEW]);
  13457. +
  13458. +unreg_camera:
  13459. + pr_err("Cleanup: Destroy camera\n");
  13460. + vchiq_mmal_component_finalise(dev->instance,
  13461. + dev->component[MMAL_COMPONENT_CAMERA]);
  13462. +
  13463. +unreg_mmal:
  13464. + vchiq_mmal_finalise(dev->instance);
  13465. + return ret;
  13466. +}
  13467. +
  13468. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  13469. + struct video_device *vfd)
  13470. +{
  13471. + int ret;
  13472. +
  13473. + *vfd = vdev_template;
  13474. +
  13475. + vfd->v4l2_dev = &dev->v4l2_dev;
  13476. +
  13477. + vfd->lock = &dev->mutex;
  13478. +
  13479. + vfd->queue = &dev->capture.vb_vidq;
  13480. +
  13481. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  13482. +
  13483. + /* video device needs to be able to access instance data */
  13484. + video_set_drvdata(vfd, dev);
  13485. +
  13486. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  13487. + if (ret < 0)
  13488. + return ret;
  13489. +
  13490. + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  13491. + video_device_node_name(vfd));
  13492. +
  13493. + return 0;
  13494. +}
  13495. +
  13496. +static struct v4l2_format default_v4l2_format = {
  13497. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  13498. + .fmt.pix.width = 1024,
  13499. + .fmt.pix.bytesperline = 1024 * 3 / 2,
  13500. + .fmt.pix.height = 768,
  13501. + .fmt.pix.sizeimage = 1<<18,
  13502. +};
  13503. +
  13504. +static int __init bm2835_mmal_init(void)
  13505. +{
  13506. + int ret;
  13507. + struct bm2835_mmal_dev *dev;
  13508. + struct vb2_queue *q;
  13509. +
  13510. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  13511. + if (!dev)
  13512. + return -ENOMEM;
  13513. +
  13514. + /* setup device defaults */
  13515. + dev->overlay.w.left = 150;
  13516. + dev->overlay.w.top = 50;
  13517. + dev->overlay.w.width = 1024;
  13518. + dev->overlay.w.height = 768;
  13519. + dev->overlay.clipcount = 0;
  13520. + dev->overlay.field = V4L2_FIELD_NONE;
  13521. +
  13522. + dev->capture.fmt = &formats[3]; /* JPEG */
  13523. +
  13524. + /* v4l device registration */
  13525. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  13526. + "%s", BM2835_MMAL_MODULE_NAME);
  13527. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  13528. + if (ret)
  13529. + goto free_dev;
  13530. +
  13531. + /* setup v4l controls */
  13532. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  13533. + if (ret < 0)
  13534. + goto unreg_dev;
  13535. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  13536. +
  13537. + /* mmal init */
  13538. + ret = mmal_init(dev);
  13539. + if (ret < 0)
  13540. + goto unreg_dev;
  13541. +
  13542. + /* initialize queue */
  13543. + q = &dev->capture.vb_vidq;
  13544. + memset(q, 0, sizeof(*q));
  13545. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  13546. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  13547. + q->drv_priv = dev;
  13548. + q->buf_struct_size = sizeof(struct mmal_buffer);
  13549. + q->ops = &bm2835_mmal_video_qops;
  13550. + q->mem_ops = &vb2_vmalloc_memops;
  13551. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  13552. + ret = vb2_queue_init(q);
  13553. + if (ret < 0)
  13554. + goto unreg_dev;
  13555. +
  13556. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  13557. + mutex_init(&dev->mutex);
  13558. +
  13559. + /* initialise video devices */
  13560. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  13561. + if (ret < 0)
  13562. + goto unreg_dev;
  13563. +
  13564. + ret = mmal_setup_components(dev, &default_v4l2_format);
  13565. + if (ret < 0) {
  13566. + v4l2_err(&dev->v4l2_dev,
  13567. + "%s: could not setup components\n", __func__);
  13568. + goto unreg_dev;
  13569. + }
  13570. +
  13571. + v4l2_info(&dev->v4l2_dev,
  13572. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  13573. + BM2835_MMAL_VERSION);
  13574. +
  13575. + gdev = dev;
  13576. + return 0;
  13577. +
  13578. +unreg_dev:
  13579. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  13580. + v4l2_device_unregister(&dev->v4l2_dev);
  13581. +
  13582. +free_dev:
  13583. + kfree(dev);
  13584. +
  13585. + v4l2_err(&dev->v4l2_dev,
  13586. + "%s: error %d while loading driver\n",
  13587. + BM2835_MMAL_MODULE_NAME, ret);
  13588. +
  13589. + return ret;
  13590. +}
  13591. +
  13592. +static void __exit bm2835_mmal_exit(void)
  13593. +{
  13594. + if (!gdev)
  13595. + return;
  13596. +
  13597. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  13598. + video_device_node_name(&gdev->vdev));
  13599. +
  13600. + video_unregister_device(&gdev->vdev);
  13601. +
  13602. + if (gdev->capture.encode_component) {
  13603. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  13604. + "mmal_exit - disconnect tunnel\n");
  13605. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  13606. + gdev->capture.camera_port, NULL);
  13607. + vchiq_mmal_component_disable(gdev->instance,
  13608. + gdev->capture.encode_component);
  13609. + }
  13610. + vchiq_mmal_component_disable(gdev->instance,
  13611. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13612. +
  13613. + vchiq_mmal_component_finalise(gdev->instance,
  13614. + gdev->
  13615. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13616. +
  13617. + vchiq_mmal_component_finalise(gdev->instance,
  13618. + gdev->
  13619. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13620. +
  13621. + vchiq_mmal_component_finalise(gdev->instance,
  13622. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  13623. +
  13624. + vchiq_mmal_component_finalise(gdev->instance,
  13625. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13626. +
  13627. + vchiq_mmal_finalise(gdev->instance);
  13628. +
  13629. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  13630. +
  13631. + v4l2_device_unregister(&gdev->v4l2_dev);
  13632. +
  13633. + kfree(gdev);
  13634. +}
  13635. +
  13636. +module_init(bm2835_mmal_init);
  13637. +module_exit(bm2835_mmal_exit);
  13638. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/bcm2835-camera.h linux-raspberry-pi/drivers/media/platform/bcm2835/bcm2835-camera.h
  13639. --- linux-3.10.33/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  13640. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-03-13 12:46:18.260055389 +0100
  13641. @@ -0,0 +1,123 @@
  13642. +/*
  13643. + * Broadcom BM2835 V4L2 driver
  13644. + *
  13645. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13646. + *
  13647. + * This file is subject to the terms and conditions of the GNU General Public
  13648. + * License. See the file COPYING in the main directory of this archive
  13649. + * for more details.
  13650. + *
  13651. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13652. + * Dave Stevenson <dsteve@broadcom.com>
  13653. + * Simon Mellor <simellor@broadcom.com>
  13654. + * Luke Diamand <luked@broadcom.com>
  13655. + *
  13656. + * core driver device
  13657. + */
  13658. +
  13659. +#define V4L2_CTRL_COUNT 25 /* number of v4l controls */
  13660. +
  13661. +enum {
  13662. + MMAL_COMPONENT_CAMERA = 0,
  13663. + MMAL_COMPONENT_PREVIEW,
  13664. + MMAL_COMPONENT_IMAGE_ENCODE,
  13665. + MMAL_COMPONENT_VIDEO_ENCODE,
  13666. + MMAL_COMPONENT_COUNT
  13667. +};
  13668. +
  13669. +enum {
  13670. + MMAL_CAMERA_PORT_PREVIEW = 0,
  13671. + MMAL_CAMERA_PORT_VIDEO,
  13672. + MMAL_CAMERA_PORT_CAPTURE,
  13673. + MMAL_CAMERA_PORT_COUNT
  13674. +};
  13675. +
  13676. +#define PREVIEW_LAYER 2
  13677. +
  13678. +extern int bcm2835_v4l2_debug;
  13679. +
  13680. +struct bm2835_mmal_dev {
  13681. + /* v4l2 devices */
  13682. + struct v4l2_device v4l2_dev;
  13683. + struct video_device vdev;
  13684. + struct mutex mutex;
  13685. +
  13686. + /* controls */
  13687. + struct v4l2_ctrl_handler ctrl_handler;
  13688. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  13689. + enum v4l2_scene_mode scene_mode;
  13690. + struct mmal_colourfx colourfx;
  13691. + int hflip;
  13692. + int vflip;
  13693. + enum mmal_parameter_exposuremode exposure_mode_user;
  13694. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  13695. + /* active exposure mode may differ if selected via a scene mode */
  13696. + enum mmal_parameter_exposuremode exposure_mode_active;
  13697. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13698. + unsigned int manual_shutter_speed;
  13699. + bool exp_auto_priority;
  13700. +
  13701. + /* allocated mmal instance and components */
  13702. + struct vchiq_mmal_instance *instance;
  13703. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  13704. + int camera_use_count;
  13705. +
  13706. + struct v4l2_window overlay;
  13707. +
  13708. + struct {
  13709. + unsigned int width; /* width */
  13710. + unsigned int height; /* height */
  13711. + unsigned int stride; /* stride */
  13712. + struct mmal_fmt *fmt;
  13713. + struct v4l2_fract timeperframe;
  13714. +
  13715. + /* H264 encode bitrate */
  13716. + int encode_bitrate;
  13717. + /* H264 bitrate mode. CBR/VBR */
  13718. + int encode_bitrate_mode;
  13719. + /* H264 profile */
  13720. + enum v4l2_mpeg_video_h264_profile enc_profile;
  13721. + /* H264 level */
  13722. + enum v4l2_mpeg_video_h264_level enc_level;
  13723. + /* JPEG Q-factor */
  13724. + int q_factor;
  13725. +
  13726. + struct vb2_queue vb_vidq;
  13727. +
  13728. + /* VC start timestamp for streaming */
  13729. + s64 vc_start_timestamp;
  13730. + /* Kernel start timestamp for streaming */
  13731. + struct timeval kernel_start_ts;
  13732. +
  13733. + struct vchiq_mmal_port *port; /* port being used for capture */
  13734. + /* camera port being used for capture */
  13735. + struct vchiq_mmal_port *camera_port;
  13736. + /* component being used for encode */
  13737. + struct vchiq_mmal_component *encode_component;
  13738. + /* number of frames remaining which driver should capture */
  13739. + unsigned int frame_count;
  13740. + /* last frame completion */
  13741. + struct completion frame_cmplt;
  13742. +
  13743. + } capture;
  13744. +
  13745. +};
  13746. +
  13747. +int bm2835_mmal_init_controls(
  13748. + struct bm2835_mmal_dev *dev,
  13749. + struct v4l2_ctrl_handler *hdl);
  13750. +
  13751. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  13752. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  13753. +
  13754. +/* Debug helpers */
  13755. +
  13756. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  13757. +{ \
  13758. + v4l2_dbg(level, debug, dev, \
  13759. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  13760. + desc == NULL ? "" : desc, \
  13761. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  13762. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  13763. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  13764. +}
  13765. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/controls.c linux-raspberry-pi/drivers/media/platform/bcm2835/controls.c
  13766. --- linux-3.10.33/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  13767. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/controls.c 2014-03-13 12:46:18.260055389 +0100
  13768. @@ -0,0 +1,1278 @@
  13769. +/*
  13770. + * Broadcom BM2835 V4L2 driver
  13771. + *
  13772. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13773. + *
  13774. + * This file is subject to the terms and conditions of the GNU General Public
  13775. + * License. See the file COPYING in the main directory of this archive
  13776. + * for more details.
  13777. + *
  13778. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13779. + * Dave Stevenson <dsteve@broadcom.com>
  13780. + * Simon Mellor <simellor@broadcom.com>
  13781. + * Luke Diamand <luked@broadcom.com>
  13782. + */
  13783. +
  13784. +#include <linux/errno.h>
  13785. +#include <linux/kernel.h>
  13786. +#include <linux/module.h>
  13787. +#include <linux/slab.h>
  13788. +#include <media/videobuf2-vmalloc.h>
  13789. +#include <media/v4l2-device.h>
  13790. +#include <media/v4l2-ioctl.h>
  13791. +#include <media/v4l2-ctrls.h>
  13792. +#include <media/v4l2-fh.h>
  13793. +#include <media/v4l2-event.h>
  13794. +#include <media/v4l2-common.h>
  13795. +
  13796. +#include "mmal-common.h"
  13797. +#include "mmal-vchiq.h"
  13798. +#include "mmal-parameters.h"
  13799. +#include "bcm2835-camera.h"
  13800. +
  13801. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  13802. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  13803. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  13804. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  13805. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  13806. + * -4 to +4
  13807. + */
  13808. +static const s64 ev_bias_qmenu[] = {
  13809. + -4000, -3667, -3333,
  13810. + -3000, -2667, -2333,
  13811. + -2000, -1667, -1333,
  13812. + -1000, -667, -333,
  13813. + 0, 333, 667,
  13814. + 1000, 1333, 1667,
  13815. + 2000, 2333, 2667,
  13816. + 3000, 3333, 3667,
  13817. + 4000
  13818. +};
  13819. +
  13820. +/* Supported ISO values
  13821. + * ISOO = auto ISO
  13822. + */
  13823. +static const s64 iso_qmenu[] = {
  13824. + 0, 100, 200, 400, 800,
  13825. +};
  13826. +
  13827. +static const s64 mains_freq_qmenu[] = {
  13828. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  13829. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  13830. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  13831. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  13832. +};
  13833. +
  13834. +/* Supported video encode modes */
  13835. +static const s64 bitrate_mode_qmenu[] = {
  13836. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  13837. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  13838. +};
  13839. +
  13840. +enum bm2835_mmal_ctrl_type {
  13841. + MMAL_CONTROL_TYPE_STD,
  13842. + MMAL_CONTROL_TYPE_STD_MENU,
  13843. + MMAL_CONTROL_TYPE_INT_MENU,
  13844. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  13845. +};
  13846. +
  13847. +struct bm2835_mmal_v4l2_ctrl;
  13848. +
  13849. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  13850. + struct bm2835_mmal_dev *dev,
  13851. + struct v4l2_ctrl *ctrl,
  13852. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  13853. +
  13854. +struct bm2835_mmal_v4l2_ctrl {
  13855. + u32 id; /* v4l2 control identifier */
  13856. + enum bm2835_mmal_ctrl_type type;
  13857. + /* control minimum value or
  13858. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  13859. + s32 min;
  13860. + s32 max; /* maximum value of control */
  13861. + s32 def; /* default value of control */
  13862. + s32 step; /* step size of the control */
  13863. + const s64 *imenu; /* integer menu array */
  13864. + u32 mmal_id; /* mmal parameter id */
  13865. + bm2835_mmal_v4l2_ctrl_cb *setter;
  13866. + bool ignore_errors;
  13867. +};
  13868. +
  13869. +struct v4l2_to_mmal_effects_setting {
  13870. + u32 v4l2_effect;
  13871. + u32 mmal_effect;
  13872. + s32 col_fx_enable;
  13873. + s32 col_fx_fixed_cbcr;
  13874. + u32 u;
  13875. + u32 v;
  13876. + u32 num_effect_params;
  13877. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  13878. +};
  13879. +
  13880. +static const struct v4l2_to_mmal_effects_setting
  13881. + v4l2_to_mmal_effects_values[] = {
  13882. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  13883. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13884. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  13885. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  13886. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  13887. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  13888. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  13889. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13890. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  13891. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13892. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  13893. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13894. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  13895. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13896. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  13897. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13898. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  13899. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13900. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  13901. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13902. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  13903. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  13904. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  13905. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13906. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  13907. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13908. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  13909. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  13910. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  13911. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  13912. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  13913. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  13914. +};
  13915. +
  13916. +struct v4l2_mmal_scene_config {
  13917. + enum v4l2_scene_mode v4l2_scene;
  13918. + enum mmal_parameter_exposuremode exposure_mode;
  13919. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13920. +};
  13921. +
  13922. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  13923. + /* V4L2_SCENE_MODE_NONE automatically added */
  13924. + {
  13925. + V4L2_SCENE_MODE_NIGHT,
  13926. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  13927. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  13928. + },
  13929. + {
  13930. + V4L2_SCENE_MODE_SPORTS,
  13931. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  13932. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  13933. + },
  13934. +};
  13935. +
  13936. +/* control handlers*/
  13937. +
  13938. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  13939. + struct v4l2_ctrl *ctrl,
  13940. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13941. +{
  13942. + struct mmal_parameter_rational rational_value;
  13943. + struct vchiq_mmal_port *control;
  13944. +
  13945. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13946. +
  13947. + rational_value.num = ctrl->val;
  13948. + rational_value.den = 100;
  13949. +
  13950. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13951. + mmal_ctrl->mmal_id,
  13952. + &rational_value,
  13953. + sizeof(rational_value));
  13954. +}
  13955. +
  13956. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  13957. + struct v4l2_ctrl *ctrl,
  13958. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13959. +{
  13960. + u32 u32_value;
  13961. + struct vchiq_mmal_port *control;
  13962. +
  13963. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13964. +
  13965. + u32_value = ctrl->val;
  13966. +
  13967. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13968. + mmal_ctrl->mmal_id,
  13969. + &u32_value, sizeof(u32_value));
  13970. +}
  13971. +
  13972. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  13973. + struct v4l2_ctrl *ctrl,
  13974. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13975. +{
  13976. + u32 u32_value;
  13977. + struct vchiq_mmal_port *control;
  13978. +
  13979. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  13980. + return 1;
  13981. +
  13982. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13983. +
  13984. + u32_value = mmal_ctrl->imenu[ctrl->val];
  13985. +
  13986. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13987. + mmal_ctrl->mmal_id,
  13988. + &u32_value, sizeof(u32_value));
  13989. +}
  13990. +
  13991. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  13992. + struct v4l2_ctrl *ctrl,
  13993. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13994. +{
  13995. + s32 s32_value;
  13996. + struct vchiq_mmal_port *control;
  13997. +
  13998. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13999. +
  14000. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  14001. +
  14002. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14003. + mmal_ctrl->mmal_id,
  14004. + &s32_value, sizeof(s32_value));
  14005. +}
  14006. +
  14007. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  14008. + struct v4l2_ctrl *ctrl,
  14009. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14010. +{
  14011. + int ret;
  14012. + u32 u32_value;
  14013. + struct vchiq_mmal_component *camera;
  14014. +
  14015. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  14016. +
  14017. + u32_value = ((ctrl->val % 360) / 90) * 90;
  14018. +
  14019. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  14020. + mmal_ctrl->mmal_id,
  14021. + &u32_value, sizeof(u32_value));
  14022. + if (ret < 0)
  14023. + return ret;
  14024. +
  14025. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  14026. + mmal_ctrl->mmal_id,
  14027. + &u32_value, sizeof(u32_value));
  14028. + if (ret < 0)
  14029. + return ret;
  14030. +
  14031. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  14032. + mmal_ctrl->mmal_id,
  14033. + &u32_value, sizeof(u32_value));
  14034. +
  14035. + return ret;
  14036. +}
  14037. +
  14038. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  14039. + struct v4l2_ctrl *ctrl,
  14040. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14041. +{
  14042. + int ret;
  14043. + u32 u32_value;
  14044. + struct vchiq_mmal_component *camera;
  14045. +
  14046. + if (ctrl->id == V4L2_CID_HFLIP)
  14047. + dev->hflip = ctrl->val;
  14048. + else
  14049. + dev->vflip = ctrl->val;
  14050. +
  14051. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  14052. +
  14053. + if (dev->hflip && dev->vflip)
  14054. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  14055. + else if (dev->hflip)
  14056. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  14057. + else if (dev->vflip)
  14058. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  14059. + else
  14060. + u32_value = MMAL_PARAM_MIRROR_NONE;
  14061. +
  14062. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  14063. + mmal_ctrl->mmal_id,
  14064. + &u32_value, sizeof(u32_value));
  14065. + if (ret < 0)
  14066. + return ret;
  14067. +
  14068. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  14069. + mmal_ctrl->mmal_id,
  14070. + &u32_value, sizeof(u32_value));
  14071. + if (ret < 0)
  14072. + return ret;
  14073. +
  14074. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  14075. + mmal_ctrl->mmal_id,
  14076. + &u32_value, sizeof(u32_value));
  14077. +
  14078. + return ret;
  14079. +
  14080. +}
  14081. +
  14082. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  14083. + struct v4l2_ctrl *ctrl,
  14084. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14085. +{
  14086. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  14087. + u32 shutter_speed = 0;
  14088. + struct vchiq_mmal_port *control;
  14089. + int ret = 0;
  14090. +
  14091. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14092. +
  14093. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  14094. + /* V4L2 is in 100usec increments.
  14095. + * MMAL is 1usec.
  14096. + */
  14097. + dev->manual_shutter_speed = ctrl->val * 100;
  14098. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  14099. + switch (ctrl->val) {
  14100. + case V4L2_EXPOSURE_AUTO:
  14101. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  14102. + break;
  14103. +
  14104. + case V4L2_EXPOSURE_MANUAL:
  14105. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  14106. + break;
  14107. + }
  14108. + dev->exposure_mode_user = exp_mode;
  14109. + dev->exposure_mode_v4l2_user = ctrl->val;
  14110. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  14111. + dev->exp_auto_priority = ctrl->val;
  14112. + }
  14113. +
  14114. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  14115. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  14116. + shutter_speed = dev->manual_shutter_speed;
  14117. +
  14118. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14119. + control,
  14120. + MMAL_PARAMETER_SHUTTER_SPEED,
  14121. + &shutter_speed,
  14122. + sizeof(shutter_speed));
  14123. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14124. + control,
  14125. + MMAL_PARAMETER_EXPOSURE_MODE,
  14126. + &exp_mode,
  14127. + sizeof(u32));
  14128. + dev->exposure_mode_active = exp_mode;
  14129. + }
  14130. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  14131. + * always apply irrespective of scene mode.
  14132. + */
  14133. + ret += set_framerate_params(dev);
  14134. +
  14135. + return ret;
  14136. +}
  14137. +
  14138. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  14139. + struct v4l2_ctrl *ctrl,
  14140. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14141. +{
  14142. + switch (ctrl->val) {
  14143. + case V4L2_EXPOSURE_METERING_AVERAGE:
  14144. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  14145. + break;
  14146. +
  14147. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  14148. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  14149. + break;
  14150. +
  14151. + case V4L2_EXPOSURE_METERING_SPOT:
  14152. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  14153. + break;
  14154. +
  14155. + /* todo matrix weighting not added to Linux API till 3.9
  14156. + case V4L2_EXPOSURE_METERING_MATRIX:
  14157. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  14158. + break;
  14159. + */
  14160. +
  14161. + }
  14162. +
  14163. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  14164. + struct vchiq_mmal_port *control;
  14165. + u32 u32_value = dev->metering_mode;
  14166. +
  14167. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14168. +
  14169. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14170. + mmal_ctrl->mmal_id,
  14171. + &u32_value, sizeof(u32_value));
  14172. + } else
  14173. + return 0;
  14174. +}
  14175. +
  14176. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  14177. + struct v4l2_ctrl *ctrl,
  14178. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14179. +{
  14180. + u32 u32_value;
  14181. + struct vchiq_mmal_port *control;
  14182. +
  14183. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14184. +
  14185. + switch (ctrl->val) {
  14186. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  14187. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  14188. + break;
  14189. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  14190. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  14191. + break;
  14192. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  14193. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  14194. + break;
  14195. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  14196. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  14197. + break;
  14198. + }
  14199. +
  14200. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14201. + mmal_ctrl->mmal_id,
  14202. + &u32_value, sizeof(u32_value));
  14203. +}
  14204. +
  14205. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  14206. + struct v4l2_ctrl *ctrl,
  14207. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14208. +{
  14209. + u32 u32_value;
  14210. + struct vchiq_mmal_port *control;
  14211. +
  14212. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14213. +
  14214. + switch (ctrl->val) {
  14215. + case V4L2_WHITE_BALANCE_MANUAL:
  14216. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  14217. + break;
  14218. +
  14219. + case V4L2_WHITE_BALANCE_AUTO:
  14220. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  14221. + break;
  14222. +
  14223. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  14224. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  14225. + break;
  14226. +
  14227. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  14228. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  14229. + break;
  14230. +
  14231. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  14232. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  14233. + break;
  14234. +
  14235. + case V4L2_WHITE_BALANCE_HORIZON:
  14236. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  14237. + break;
  14238. +
  14239. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  14240. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  14241. + break;
  14242. +
  14243. + case V4L2_WHITE_BALANCE_FLASH:
  14244. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  14245. + break;
  14246. +
  14247. + case V4L2_WHITE_BALANCE_CLOUDY:
  14248. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  14249. + break;
  14250. +
  14251. + case V4L2_WHITE_BALANCE_SHADE:
  14252. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  14253. + break;
  14254. +
  14255. + }
  14256. +
  14257. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14258. + mmal_ctrl->mmal_id,
  14259. + &u32_value, sizeof(u32_value));
  14260. +}
  14261. +
  14262. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  14263. + struct v4l2_ctrl *ctrl,
  14264. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14265. +{
  14266. + int ret = -EINVAL;
  14267. + int i, j;
  14268. + struct vchiq_mmal_port *control;
  14269. + struct mmal_parameter_imagefx_parameters imagefx;
  14270. +
  14271. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  14272. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  14273. +
  14274. + imagefx.effect =
  14275. + v4l2_to_mmal_effects_values[i].mmal_effect;
  14276. + imagefx.num_effect_params =
  14277. + v4l2_to_mmal_effects_values[i].num_effect_params;
  14278. +
  14279. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  14280. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  14281. +
  14282. + for (j = 0; j < imagefx.num_effect_params; j++)
  14283. + imagefx.effect_parameter[j] =
  14284. + v4l2_to_mmal_effects_values[i].effect_params[j];
  14285. +
  14286. + dev->colourfx.enable =
  14287. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  14288. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  14289. + dev->colourfx.u =
  14290. + v4l2_to_mmal_effects_values[i].u;
  14291. + dev->colourfx.v =
  14292. + v4l2_to_mmal_effects_values[i].v;
  14293. + }
  14294. +
  14295. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14296. +
  14297. + ret = vchiq_mmal_port_parameter_set(
  14298. + dev->instance, control,
  14299. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  14300. + &imagefx, sizeof(imagefx));
  14301. + if (ret)
  14302. + goto exit;
  14303. +
  14304. + ret = vchiq_mmal_port_parameter_set(
  14305. + dev->instance, control,
  14306. + MMAL_PARAMETER_COLOUR_EFFECT,
  14307. + &dev->colourfx, sizeof(dev->colourfx));
  14308. + }
  14309. + }
  14310. +
  14311. +exit:
  14312. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14313. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  14314. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  14315. + dev->colourfx.enable ? "true" : "false",
  14316. + dev->colourfx.u, dev->colourfx.v,
  14317. + ret, (ret == 0 ? 0 : -EINVAL));
  14318. + return (ret == 0 ? 0 : EINVAL);
  14319. +}
  14320. +
  14321. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  14322. + struct v4l2_ctrl *ctrl,
  14323. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14324. +{
  14325. + int ret = -EINVAL;
  14326. + struct vchiq_mmal_port *control;
  14327. +
  14328. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14329. +
  14330. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  14331. + dev->colourfx.enable = ctrl->val & 0xff;
  14332. +
  14333. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  14334. + MMAL_PARAMETER_COLOUR_EFFECT,
  14335. + &dev->colourfx, sizeof(dev->colourfx));
  14336. +
  14337. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14338. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  14339. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  14340. + (ret == 0 ? 0 : -EINVAL));
  14341. + return (ret == 0 ? 0 : EINVAL);
  14342. +}
  14343. +
  14344. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  14345. + struct v4l2_ctrl *ctrl,
  14346. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14347. +{
  14348. + int ret;
  14349. + struct vchiq_mmal_port *encoder_out;
  14350. +
  14351. + dev->capture.encode_bitrate = ctrl->val;
  14352. +
  14353. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14354. +
  14355. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  14356. + mmal_ctrl->mmal_id,
  14357. + &ctrl->val, sizeof(ctrl->val));
  14358. + ret = 0;
  14359. + return ret;
  14360. +}
  14361. +
  14362. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  14363. + struct v4l2_ctrl *ctrl,
  14364. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14365. +{
  14366. + u32 bitrate_mode;
  14367. + struct vchiq_mmal_port *encoder_out;
  14368. +
  14369. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14370. +
  14371. + dev->capture.encode_bitrate_mode = ctrl->val;
  14372. + switch (ctrl->val) {
  14373. + default:
  14374. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  14375. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  14376. + break;
  14377. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  14378. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  14379. + break;
  14380. + }
  14381. +
  14382. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  14383. + mmal_ctrl->mmal_id,
  14384. + &bitrate_mode,
  14385. + sizeof(bitrate_mode));
  14386. + return 0;
  14387. +}
  14388. +
  14389. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  14390. + struct v4l2_ctrl *ctrl,
  14391. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14392. +{
  14393. + u32 u32_value;
  14394. + struct vchiq_mmal_port *jpeg_out;
  14395. +
  14396. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  14397. +
  14398. + u32_value = ctrl->val;
  14399. +
  14400. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  14401. + mmal_ctrl->mmal_id,
  14402. + &u32_value, sizeof(u32_value));
  14403. +}
  14404. +
  14405. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  14406. + struct v4l2_ctrl *ctrl,
  14407. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14408. +{
  14409. + u32 u32_value;
  14410. + struct vchiq_mmal_port *vid_enc_ctl;
  14411. +
  14412. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14413. +
  14414. + u32_value = ctrl->val;
  14415. +
  14416. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  14417. + mmal_ctrl->mmal_id,
  14418. + &u32_value, sizeof(u32_value));
  14419. +}
  14420. +
  14421. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  14422. + struct v4l2_ctrl *ctrl,
  14423. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14424. +{
  14425. + struct mmal_parameter_video_profile param;
  14426. + int ret = 0;
  14427. +
  14428. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  14429. + switch (ctrl->val) {
  14430. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  14431. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  14432. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  14433. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  14434. + dev->capture.enc_profile = ctrl->val;
  14435. + break;
  14436. + default:
  14437. + ret = -EINVAL;
  14438. + break;
  14439. + }
  14440. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  14441. + switch (ctrl->val) {
  14442. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  14443. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  14444. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  14445. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  14446. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  14447. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  14448. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  14449. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  14450. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  14451. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  14452. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  14453. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  14454. + dev->capture.enc_level = ctrl->val;
  14455. + break;
  14456. + default:
  14457. + ret = -EINVAL;
  14458. + break;
  14459. + }
  14460. + }
  14461. +
  14462. + if (!ret) {
  14463. + switch (dev->capture.enc_profile) {
  14464. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  14465. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  14466. + break;
  14467. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  14468. + param.profile =
  14469. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  14470. + break;
  14471. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  14472. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  14473. + break;
  14474. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  14475. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  14476. + break;
  14477. + default:
  14478. + /* Should never get here */
  14479. + break;
  14480. + }
  14481. +
  14482. + switch (dev->capture.enc_level) {
  14483. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  14484. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  14485. + break;
  14486. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  14487. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  14488. + break;
  14489. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  14490. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  14491. + break;
  14492. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  14493. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  14494. + break;
  14495. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  14496. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  14497. + break;
  14498. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  14499. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  14500. + break;
  14501. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  14502. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  14503. + break;
  14504. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  14505. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  14506. + break;
  14507. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  14508. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  14509. + break;
  14510. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  14511. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  14512. + break;
  14513. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  14514. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  14515. + break;
  14516. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  14517. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  14518. + break;
  14519. + default:
  14520. + /* Should never get here */
  14521. + break;
  14522. + }
  14523. +
  14524. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14525. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  14526. + mmal_ctrl->mmal_id,
  14527. + &param, sizeof(param));
  14528. + }
  14529. + return ret;
  14530. +}
  14531. +
  14532. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  14533. + struct v4l2_ctrl *ctrl,
  14534. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14535. +{
  14536. + int ret = 0;
  14537. + int shutter_speed;
  14538. + struct vchiq_mmal_port *control;
  14539. +
  14540. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14541. + "scene mode selected %d, was %d\n", ctrl->val,
  14542. + dev->scene_mode);
  14543. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14544. +
  14545. + if (ctrl->val == dev->scene_mode)
  14546. + return 0;
  14547. +
  14548. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  14549. + /* Restore all user selections */
  14550. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  14551. +
  14552. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  14553. + shutter_speed = dev->manual_shutter_speed;
  14554. + else
  14555. + shutter_speed = 0;
  14556. +
  14557. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14558. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  14559. + __func__, shutter_speed, dev->exposure_mode_user,
  14560. + dev->metering_mode);
  14561. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14562. + control,
  14563. + MMAL_PARAMETER_SHUTTER_SPEED,
  14564. + &shutter_speed,
  14565. + sizeof(shutter_speed));
  14566. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14567. + control,
  14568. + MMAL_PARAMETER_EXPOSURE_MODE,
  14569. + &dev->exposure_mode_user,
  14570. + sizeof(u32));
  14571. + dev->exposure_mode_active = dev->exposure_mode_user;
  14572. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14573. + control,
  14574. + MMAL_PARAMETER_EXP_METERING_MODE,
  14575. + &dev->metering_mode,
  14576. + sizeof(u32));
  14577. + ret += set_framerate_params(dev);
  14578. + } else {
  14579. + /* Set up scene mode */
  14580. + int i;
  14581. + const struct v4l2_mmal_scene_config *scene = NULL;
  14582. + int shutter_speed;
  14583. + enum mmal_parameter_exposuremode exposure_mode;
  14584. + enum mmal_parameter_exposuremeteringmode metering_mode;
  14585. +
  14586. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  14587. + if (scene_configs[i].v4l2_scene ==
  14588. + ctrl->val) {
  14589. + scene = &scene_configs[i];
  14590. + break;
  14591. + }
  14592. + }
  14593. + if (i >= ARRAY_SIZE(scene_configs))
  14594. + return -EINVAL;
  14595. +
  14596. + /* Set all the values */
  14597. + dev->scene_mode = ctrl->val;
  14598. +
  14599. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  14600. + shutter_speed = dev->manual_shutter_speed;
  14601. + else
  14602. + shutter_speed = 0;
  14603. + exposure_mode = scene->exposure_mode;
  14604. + metering_mode = scene->metering_mode;
  14605. +
  14606. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14607. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  14608. + __func__, shutter_speed, exposure_mode, metering_mode);
  14609. +
  14610. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  14611. + MMAL_PARAMETER_SHUTTER_SPEED,
  14612. + &shutter_speed,
  14613. + sizeof(shutter_speed));
  14614. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14615. + control,
  14616. + MMAL_PARAMETER_EXPOSURE_MODE,
  14617. + &exposure_mode,
  14618. + sizeof(u32));
  14619. + dev->exposure_mode_active = exposure_mode;
  14620. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  14621. + MMAL_PARAMETER_EXPOSURE_MODE,
  14622. + &exposure_mode,
  14623. + sizeof(u32));
  14624. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  14625. + MMAL_PARAMETER_EXP_METERING_MODE,
  14626. + &metering_mode,
  14627. + sizeof(u32));
  14628. + ret += set_framerate_params(dev);
  14629. + }
  14630. + if (ret) {
  14631. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14632. + "%s: Setting scene to %d, ret=%d\n",
  14633. + __func__, ctrl->val, ret);
  14634. + ret = -EINVAL;
  14635. + }
  14636. + return 0;
  14637. +}
  14638. +
  14639. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  14640. +{
  14641. + struct bm2835_mmal_dev *dev =
  14642. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  14643. + ctrl_handler);
  14644. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  14645. + int ret;
  14646. +
  14647. + if ((mmal_ctrl == NULL) ||
  14648. + (mmal_ctrl->id != ctrl->id) ||
  14649. + (mmal_ctrl->setter == NULL)) {
  14650. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  14651. + return -EINVAL;
  14652. + }
  14653. +
  14654. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  14655. + if (ret)
  14656. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  14657. + ctrl->id, mmal_ctrl->mmal_id, ret);
  14658. + if (mmal_ctrl->ignore_errors)
  14659. + ret = 0;
  14660. + return ret;
  14661. +}
  14662. +
  14663. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  14664. + .s_ctrl = bm2835_mmal_s_ctrl,
  14665. +};
  14666. +
  14667. +
  14668. +
  14669. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  14670. + {
  14671. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  14672. + -100, 100, 0, 1, NULL,
  14673. + MMAL_PARAMETER_SATURATION,
  14674. + &ctrl_set_rational,
  14675. + false
  14676. + },
  14677. + {
  14678. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  14679. + -100, 100, 0, 1, NULL,
  14680. + MMAL_PARAMETER_SHARPNESS,
  14681. + &ctrl_set_rational,
  14682. + false
  14683. + },
  14684. + {
  14685. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  14686. + -100, 100, 0, 1, NULL,
  14687. + MMAL_PARAMETER_CONTRAST,
  14688. + &ctrl_set_rational,
  14689. + false
  14690. + },
  14691. + {
  14692. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  14693. + 0, 100, 50, 1, NULL,
  14694. + MMAL_PARAMETER_BRIGHTNESS,
  14695. + &ctrl_set_rational,
  14696. + false
  14697. + },
  14698. + {
  14699. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  14700. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  14701. + MMAL_PARAMETER_ISO,
  14702. + &ctrl_set_value_menu,
  14703. + false
  14704. + },
  14705. + {
  14706. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  14707. + 0, 1, 0, 1, NULL,
  14708. + MMAL_PARAMETER_VIDEO_STABILISATION,
  14709. + &ctrl_set_value,
  14710. + false
  14711. + },
  14712. +/* {
  14713. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  14714. + },
  14715. +*/ {
  14716. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  14717. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  14718. + MMAL_PARAMETER_EXPOSURE_MODE,
  14719. + &ctrl_set_exposure,
  14720. + false
  14721. + },
  14722. +/* todo this needs mixing in with set exposure
  14723. + {
  14724. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14725. + },
  14726. + */
  14727. + {
  14728. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  14729. + /* Units of 100usecs */
  14730. + 1, 1*1000*10, 100*10, 1, NULL,
  14731. + MMAL_PARAMETER_SHUTTER_SPEED,
  14732. + &ctrl_set_exposure,
  14733. + false
  14734. + },
  14735. + {
  14736. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  14737. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  14738. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  14739. + MMAL_PARAMETER_EXPOSURE_COMP,
  14740. + &ctrl_set_value_ev,
  14741. + false
  14742. + },
  14743. + {
  14744. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  14745. + 0, 1,
  14746. + 0, 1, NULL,
  14747. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  14748. + &ctrl_set_exposure,
  14749. + false
  14750. + },
  14751. + {
  14752. + V4L2_CID_EXPOSURE_METERING,
  14753. + MMAL_CONTROL_TYPE_STD_MENU,
  14754. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  14755. + MMAL_PARAMETER_EXP_METERING_MODE,
  14756. + &ctrl_set_metering_mode,
  14757. + false
  14758. + },
  14759. + {
  14760. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  14761. + MMAL_CONTROL_TYPE_STD_MENU,
  14762. + ~0x3fe, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  14763. + MMAL_PARAMETER_AWB_MODE,
  14764. + &ctrl_set_awb_mode,
  14765. + false
  14766. + },
  14767. + {
  14768. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  14769. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  14770. + MMAL_PARAMETER_IMAGE_EFFECT,
  14771. + &ctrl_set_image_effect,
  14772. + false
  14773. + },
  14774. + {
  14775. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  14776. + 0, 0xffff, 0x8080, 1, NULL,
  14777. + MMAL_PARAMETER_COLOUR_EFFECT,
  14778. + &ctrl_set_colfx,
  14779. + false
  14780. + },
  14781. + {
  14782. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  14783. + 0, 360, 0, 90, NULL,
  14784. + MMAL_PARAMETER_ROTATION,
  14785. + &ctrl_set_rotate,
  14786. + false
  14787. + },
  14788. + {
  14789. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  14790. + 0, 1, 0, 1, NULL,
  14791. + MMAL_PARAMETER_MIRROR,
  14792. + &ctrl_set_flip,
  14793. + false
  14794. + },
  14795. + {
  14796. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  14797. + 0, 1, 0, 1, NULL,
  14798. + MMAL_PARAMETER_MIRROR,
  14799. + &ctrl_set_flip,
  14800. + false
  14801. + },
  14802. + {
  14803. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14804. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  14805. + 0, 0, bitrate_mode_qmenu,
  14806. + MMAL_PARAMETER_RATECONTROL,
  14807. + &ctrl_set_bitrate_mode,
  14808. + false
  14809. + },
  14810. + {
  14811. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  14812. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  14813. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  14814. + &ctrl_set_bitrate,
  14815. + false
  14816. + },
  14817. + {
  14818. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  14819. + 1, 100,
  14820. + 30, 1, NULL,
  14821. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  14822. + &ctrl_set_image_encode_output,
  14823. + false
  14824. + },
  14825. + {
  14826. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  14827. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  14828. + 1, 1, NULL,
  14829. + MMAL_PARAMETER_FLICKER_AVOID,
  14830. + &ctrl_set_flicker_avoidance,
  14831. + false
  14832. + },
  14833. + {
  14834. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  14835. + 0, 1,
  14836. + 0, 1, NULL,
  14837. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  14838. + &ctrl_set_video_encode_param_output,
  14839. + true /* Errors ignored as requires latest firmware to work */
  14840. + },
  14841. + {
  14842. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  14843. + MMAL_CONTROL_TYPE_STD_MENU,
  14844. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  14845. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  14846. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  14847. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  14848. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  14849. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  14850. + MMAL_PARAMETER_PROFILE,
  14851. + &ctrl_set_video_encode_profile_level,
  14852. + false
  14853. + },
  14854. + {
  14855. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  14856. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  14857. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  14858. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  14859. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  14860. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  14861. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  14862. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  14863. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  14864. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  14865. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  14866. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  14867. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  14868. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  14869. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  14870. + MMAL_PARAMETER_PROFILE,
  14871. + &ctrl_set_video_encode_profile_level,
  14872. + false
  14873. + },
  14874. + {
  14875. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14876. + -1, /* Min is computed at runtime */
  14877. + V4L2_SCENE_MODE_TEXT,
  14878. + V4L2_SCENE_MODE_NONE, 1, NULL,
  14879. + MMAL_PARAMETER_PROFILE,
  14880. + &ctrl_set_scene_mode,
  14881. + false
  14882. + },
  14883. +};
  14884. +
  14885. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  14886. +{
  14887. + int c;
  14888. + int ret = 0;
  14889. +
  14890. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14891. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  14892. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  14893. + &v4l2_ctrls[c]);
  14894. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  14895. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14896. + "Failed when setting default values for ctrl %d\n",
  14897. + c);
  14898. + break;
  14899. + }
  14900. + }
  14901. + }
  14902. + return ret;
  14903. +}
  14904. +
  14905. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  14906. +{
  14907. + struct mmal_parameter_fps_range fps_range;
  14908. + int ret;
  14909. +
  14910. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  14911. + (dev->exp_auto_priority)) {
  14912. + /* Variable FPS. Define min FPS as 1fps.
  14913. + * Max as max defined FPS.
  14914. + */
  14915. + fps_range.fps_low.num = 1;
  14916. + fps_range.fps_low.den = 1;
  14917. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  14918. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  14919. + } else {
  14920. + /* Fixed FPS - set min and max to be the same */
  14921. + fps_range.fps_low.num = fps_range.fps_high.num =
  14922. + dev->capture.timeperframe.denominator;
  14923. + fps_range.fps_low.den = fps_range.fps_high.den =
  14924. + dev->capture.timeperframe.numerator;
  14925. + }
  14926. +
  14927. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14928. + "Set fps range to %d/%d to %d/%d\n",
  14929. + fps_range.fps_low.num,
  14930. + fps_range.fps_low.den,
  14931. + fps_range.fps_high.num,
  14932. + fps_range.fps_high.den
  14933. + );
  14934. +
  14935. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14936. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14937. + output[MMAL_CAMERA_PORT_PREVIEW],
  14938. + MMAL_PARAMETER_FPS_RANGE,
  14939. + &fps_range, sizeof(fps_range));
  14940. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14941. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14942. + output[MMAL_CAMERA_PORT_VIDEO],
  14943. + MMAL_PARAMETER_FPS_RANGE,
  14944. + &fps_range, sizeof(fps_range));
  14945. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14946. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14947. + output[MMAL_CAMERA_PORT_CAPTURE],
  14948. + MMAL_PARAMETER_FPS_RANGE,
  14949. + &fps_range, sizeof(fps_range));
  14950. + if (ret)
  14951. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14952. + "Failed to set fps ret %d\n",
  14953. + ret);
  14954. +
  14955. + return ret;
  14956. +
  14957. +}
  14958. +
  14959. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  14960. + struct v4l2_ctrl_handler *hdl)
  14961. +{
  14962. + int c;
  14963. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  14964. +
  14965. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  14966. +
  14967. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14968. + ctrl = &v4l2_ctrls[c];
  14969. +
  14970. + switch (ctrl->type) {
  14971. + case MMAL_CONTROL_TYPE_STD:
  14972. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  14973. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14974. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  14975. + break;
  14976. +
  14977. + case MMAL_CONTROL_TYPE_STD_MENU:
  14978. + {
  14979. + int mask = ctrl->min;
  14980. +
  14981. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  14982. + /* Special handling to work out the mask
  14983. + * value based on the scene_configs array
  14984. + * at runtime. Reduces the chance of
  14985. + * mismatches.
  14986. + */
  14987. + int i;
  14988. + mask = 1<<V4L2_SCENE_MODE_NONE;
  14989. + for (i = 0;
  14990. + i < ARRAY_SIZE(scene_configs);
  14991. + i++) {
  14992. + mask |= 1<<scene_configs[i].v4l2_scene;
  14993. + }
  14994. + mask = ~mask;
  14995. + }
  14996. +
  14997. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  14998. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14999. + ctrl->max, mask, ctrl->def);
  15000. + break;
  15001. + }
  15002. +
  15003. + case MMAL_CONTROL_TYPE_INT_MENU:
  15004. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  15005. + &bm2835_mmal_ctrl_ops, ctrl->id,
  15006. + ctrl->max, ctrl->def, ctrl->imenu);
  15007. + break;
  15008. +
  15009. + case MMAL_CONTROL_TYPE_CLUSTER:
  15010. + /* skip this entry when constructing controls */
  15011. + continue;
  15012. + }
  15013. +
  15014. + if (hdl->error)
  15015. + break;
  15016. +
  15017. + dev->ctrls[c]->priv = (void *)ctrl;
  15018. + }
  15019. +
  15020. + if (hdl->error) {
  15021. + pr_err("error adding control %d/%d id 0x%x\n", c,
  15022. + V4L2_CTRL_COUNT, ctrl->id);
  15023. + return hdl->error;
  15024. + }
  15025. +
  15026. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  15027. + ctrl = &v4l2_ctrls[c];
  15028. +
  15029. + switch (ctrl->type) {
  15030. + case MMAL_CONTROL_TYPE_CLUSTER:
  15031. + v4l2_ctrl_auto_cluster(ctrl->min,
  15032. + &dev->ctrls[c+1],
  15033. + ctrl->max,
  15034. + ctrl->def);
  15035. + break;
  15036. +
  15037. + case MMAL_CONTROL_TYPE_STD:
  15038. + case MMAL_CONTROL_TYPE_STD_MENU:
  15039. + case MMAL_CONTROL_TYPE_INT_MENU:
  15040. + break;
  15041. + }
  15042. +
  15043. + }
  15044. +
  15045. + return 0;
  15046. +}
  15047. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/Kconfig linux-raspberry-pi/drivers/media/platform/bcm2835/Kconfig
  15048. --- linux-3.10.33/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  15049. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/Kconfig 2014-03-13 12:46:18.260055389 +0100
  15050. @@ -0,0 +1,25 @@
  15051. +# Broadcom VideoCore IV v4l2 camera support
  15052. +
  15053. +config VIDEO_BCM2835
  15054. + bool "Broadcom BCM2835 camera interface driver"
  15055. + depends on VIDEO_V4L2 && ARCH_BCM2708
  15056. + ---help---
  15057. + Say Y here to enable camera host interface devices for
  15058. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  15059. + to a service running on VideoCore.
  15060. +
  15061. +
  15062. +if VIDEO_BCM2835
  15063. +
  15064. +config VIDEO_BCM2835_MMAL
  15065. + tristate "Broadcom BM2835 MMAL camera interface driver"
  15066. + depends on BCM2708_VCHIQ
  15067. + select VIDEOBUF2_VMALLOC
  15068. + ---help---
  15069. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  15070. +
  15071. + To compile this driver as a module, choose M here: the
  15072. + module will be called bcm2835-v4l2.o
  15073. +
  15074. +
  15075. +endif # VIDEO_BM2835
  15076. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/Makefile linux-raspberry-pi/drivers/media/platform/bcm2835/Makefile
  15077. --- linux-3.10.33/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  15078. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/Makefile 2014-03-13 12:46:18.260055389 +0100
  15079. @@ -0,0 +1,5 @@
  15080. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  15081. +
  15082. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  15083. +
  15084. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  15085. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-common.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-common.h
  15086. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  15087. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-common.h 2014-03-13 12:46:18.260055389 +0100
  15088. @@ -0,0 +1,53 @@
  15089. +/*
  15090. + * Broadcom BM2835 V4L2 driver
  15091. + *
  15092. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15093. + *
  15094. + * This file is subject to the terms and conditions of the GNU General Public
  15095. + * License. See the file COPYING in the main directory of this archive
  15096. + * for more details.
  15097. + *
  15098. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15099. + * Dave Stevenson <dsteve@broadcom.com>
  15100. + * Simon Mellor <simellor@broadcom.com>
  15101. + * Luke Diamand <luked@broadcom.com>
  15102. + *
  15103. + * MMAL structures
  15104. + *
  15105. + */
  15106. +
  15107. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  15108. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  15109. +
  15110. +/** Special value signalling that time is not known */
  15111. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  15112. +
  15113. +/* mapping between v4l and mmal video modes */
  15114. +struct mmal_fmt {
  15115. + char *name;
  15116. + u32 fourcc; /* v4l2 format id */
  15117. + int flags; /* v4l2 flags field */
  15118. + u32 mmal;
  15119. + int depth;
  15120. + u32 mmal_component; /* MMAL component index to be used to encode */
  15121. +};
  15122. +
  15123. +/* buffer for one video frame */
  15124. +struct mmal_buffer {
  15125. + /* v4l buffer data -- must be first */
  15126. + struct vb2_buffer vb;
  15127. +
  15128. + /* list of buffers available */
  15129. + struct list_head list;
  15130. +
  15131. + void *buffer; /* buffer pointer */
  15132. + unsigned long buffer_size; /* size of allocated buffer */
  15133. +};
  15134. +
  15135. +/* */
  15136. +struct mmal_colourfx {
  15137. + s32 enable;
  15138. + u32 u;
  15139. + u32 v;
  15140. +};
  15141. +
  15142. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-encodings.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-encodings.h
  15143. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  15144. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-encodings.h 2014-03-13 12:46:18.260055389 +0100
  15145. @@ -0,0 +1,94 @@
  15146. +/*
  15147. + * Broadcom BM2835 V4L2 driver
  15148. + *
  15149. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15150. + *
  15151. + * This file is subject to the terms and conditions of the GNU General Public
  15152. + * License. See the file COPYING in the main directory of this archive
  15153. + * for more details.
  15154. + *
  15155. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15156. + * Dave Stevenson <dsteve@broadcom.com>
  15157. + * Simon Mellor <simellor@broadcom.com>
  15158. + * Luke Diamand <luked@broadcom.com>
  15159. + */
  15160. +
  15161. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  15162. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  15163. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  15164. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  15165. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  15166. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  15167. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  15168. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  15169. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  15170. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  15171. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  15172. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  15173. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  15174. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  15175. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  15176. +
  15177. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  15178. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  15179. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  15180. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  15181. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  15182. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  15183. +
  15184. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  15185. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  15186. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  15187. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  15188. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  15189. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  15190. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  15191. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  15192. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  15193. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  15194. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  15195. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  15196. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  15197. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  15198. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  15199. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  15200. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  15201. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  15202. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  15203. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  15204. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  15205. +
  15206. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  15207. + * This format is *not* opaque - if requested you will receive full frames
  15208. + * of YUV_UV video.
  15209. + */
  15210. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  15211. +
  15212. +/** VideoCore opaque image format, image handles are returned to
  15213. + * the host but not the actual image data.
  15214. + */
  15215. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  15216. +
  15217. +/** An EGL image handle
  15218. + */
  15219. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  15220. +
  15221. +/* }@ */
  15222. +
  15223. +/** \name Pre-defined audio encodings */
  15224. +/* @{ */
  15225. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  15226. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  15227. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  15228. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  15229. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  15230. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  15231. +
  15232. +/* Pre-defined H264 encoding variants */
  15233. +
  15234. +/** ISO 14496-10 Annex B byte stream format */
  15235. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  15236. +/** ISO 14496-15 AVC stream format */
  15237. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  15238. +/** Implicitly delineated NAL units without emulation prevention */
  15239. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  15240. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg-common.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg-common.h
  15241. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  15242. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-03-13 12:46:18.260055389 +0100
  15243. @@ -0,0 +1,50 @@
  15244. +/*
  15245. + * Broadcom BM2835 V4L2 driver
  15246. + *
  15247. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15248. + *
  15249. + * This file is subject to the terms and conditions of the GNU General Public
  15250. + * License. See the file COPYING in the main directory of this archive
  15251. + * for more details.
  15252. + *
  15253. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15254. + * Dave Stevenson <dsteve@broadcom.com>
  15255. + * Simon Mellor <simellor@broadcom.com>
  15256. + * Luke Diamand <luked@broadcom.com>
  15257. + */
  15258. +
  15259. +#ifndef MMAL_MSG_COMMON_H
  15260. +#define MMAL_MSG_COMMON_H
  15261. +
  15262. +enum mmal_msg_status {
  15263. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  15264. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  15265. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  15266. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  15267. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  15268. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  15269. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  15270. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  15271. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  15272. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  15273. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  15274. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  15275. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  15276. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  15277. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  15278. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  15279. +};
  15280. +
  15281. +struct mmal_rect {
  15282. + s32 x; /**< x coordinate (from left) */
  15283. + s32 y; /**< y coordinate (from top) */
  15284. + s32 width; /**< width */
  15285. + s32 height; /**< height */
  15286. +};
  15287. +
  15288. +struct mmal_rational {
  15289. + s32 num; /**< Numerator */
  15290. + s32 den; /**< Denominator */
  15291. +};
  15292. +
  15293. +#endif /* MMAL_MSG_COMMON_H */
  15294. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg-format.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg-format.h
  15295. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  15296. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-03-13 12:46:18.260055389 +0100
  15297. @@ -0,0 +1,81 @@
  15298. +/*
  15299. + * Broadcom BM2835 V4L2 driver
  15300. + *
  15301. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15302. + *
  15303. + * This file is subject to the terms and conditions of the GNU General Public
  15304. + * License. See the file COPYING in the main directory of this archive
  15305. + * for more details.
  15306. + *
  15307. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15308. + * Dave Stevenson <dsteve@broadcom.com>
  15309. + * Simon Mellor <simellor@broadcom.com>
  15310. + * Luke Diamand <luked@broadcom.com>
  15311. + */
  15312. +
  15313. +#ifndef MMAL_MSG_FORMAT_H
  15314. +#define MMAL_MSG_FORMAT_H
  15315. +
  15316. +#include "mmal-msg-common.h"
  15317. +
  15318. +/* MMAL_ES_FORMAT_T */
  15319. +
  15320. +
  15321. +struct mmal_audio_format {
  15322. + u32 channels; /**< Number of audio channels */
  15323. + u32 sample_rate; /**< Sample rate */
  15324. +
  15325. + u32 bits_per_sample; /**< Bits per sample */
  15326. + u32 block_align; /**< Size of a block of data */
  15327. +};
  15328. +
  15329. +struct mmal_video_format {
  15330. + u32 width; /**< Width of frame in pixels */
  15331. + u32 height; /**< Height of frame in rows of pixels */
  15332. + struct mmal_rect crop; /**< Visible region of the frame */
  15333. + struct mmal_rational frame_rate; /**< Frame rate */
  15334. + struct mmal_rational par; /**< Pixel aspect ratio */
  15335. +
  15336. + /* FourCC specifying the color space of the video stream. See the
  15337. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  15338. + */
  15339. + u32 color_space;
  15340. +};
  15341. +
  15342. +struct mmal_subpicture_format {
  15343. + u32 x_offset;
  15344. + u32 y_offset;
  15345. +};
  15346. +
  15347. +union mmal_es_specific_format {
  15348. + struct mmal_audio_format audio;
  15349. + struct mmal_video_format video;
  15350. + struct mmal_subpicture_format subpicture;
  15351. +};
  15352. +
  15353. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  15354. +struct mmal_es_format {
  15355. + u32 type; /* enum mmal_es_type */
  15356. +
  15357. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  15358. + u32 encoding_variant; /* FourCC specifying the specific
  15359. + * encoding variant of the elementary
  15360. + * stream.
  15361. + */
  15362. +
  15363. + union mmal_es_specific_format *es; /* TODO: pointers in
  15364. + * message serialisation?!?
  15365. + */
  15366. + /* Type specific
  15367. + * information for the
  15368. + * elementary stream
  15369. + */
  15370. +
  15371. + u32 bitrate; /**< Bitrate in bits per second */
  15372. + u32 flags; /**< Flags describing properties of the elementary stream. */
  15373. +
  15374. + u32 extradata_size; /**< Size of the codec specific data */
  15375. + u8 *extradata; /**< Codec specific data */
  15376. +};
  15377. +
  15378. +#endif /* MMAL_MSG_FORMAT_H */
  15379. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg.h
  15380. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  15381. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg.h 2014-03-13 12:46:18.260055389 +0100
  15382. @@ -0,0 +1,404 @@
  15383. +/*
  15384. + * Broadcom BM2835 V4L2 driver
  15385. + *
  15386. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15387. + *
  15388. + * This file is subject to the terms and conditions of the GNU General Public
  15389. + * License. See the file COPYING in the main directory of this archive
  15390. + * for more details.
  15391. + *
  15392. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15393. + * Dave Stevenson <dsteve@broadcom.com>
  15394. + * Simon Mellor <simellor@broadcom.com>
  15395. + * Luke Diamand <luked@broadcom.com>
  15396. + */
  15397. +
  15398. +/* all the data structures which serialise the MMAL protocol. note
  15399. + * these are directly mapped onto the recived message data.
  15400. + *
  15401. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  15402. + * structure padding!
  15403. + *
  15404. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  15405. + * than assigning values to enums to force their size the
  15406. + * implementation uses fixed size types and not the enums (though the
  15407. + * comments have the actual enum type
  15408. + */
  15409. +
  15410. +#define VC_MMAL_VER 15
  15411. +#define VC_MMAL_MIN_VER 10
  15412. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  15413. +
  15414. +/* max total message size is 512 bytes */
  15415. +#define MMAL_MSG_MAX_SIZE 512
  15416. +/* with six 32bit header elements max payload is therefore 488 bytes */
  15417. +#define MMAL_MSG_MAX_PAYLOAD 488
  15418. +
  15419. +#include "mmal-msg-common.h"
  15420. +#include "mmal-msg-format.h"
  15421. +#include "mmal-msg-port.h"
  15422. +
  15423. +enum mmal_msg_type {
  15424. + MMAL_MSG_TYPE_QUIT = 1,
  15425. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  15426. + MMAL_MSG_TYPE_GET_VERSION,
  15427. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  15428. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  15429. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  15430. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  15431. + MMAL_MSG_TYPE_PORT_INFO_GET,
  15432. + MMAL_MSG_TYPE_PORT_INFO_SET,
  15433. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  15434. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  15435. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  15436. + MMAL_MSG_TYPE_GET_STATS,
  15437. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  15438. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  15439. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  15440. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  15441. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  15442. + MMAL_MSG_TYPE_CONSUME_MEM,
  15443. + MMAL_MSG_TYPE_LMK, /* 20 */
  15444. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  15445. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  15446. + MMAL_MSG_TYPE_DRM_GET_TIME,
  15447. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  15448. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  15449. + MMAL_MSG_TYPE_HOST_LOG,
  15450. + MMAL_MSG_TYPE_MSG_LAST
  15451. +};
  15452. +
  15453. +/* port action request messages differ depending on the action type */
  15454. +enum mmal_msg_port_action_type {
  15455. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  15456. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  15457. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  15458. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  15459. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  15460. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  15461. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  15462. +};
  15463. +
  15464. +struct mmal_msg_header {
  15465. + u32 magic;
  15466. + u32 type; /** enum mmal_msg_type */
  15467. +
  15468. + /* Opaque handle to the control service */
  15469. + struct mmal_control_service *control_service;
  15470. +
  15471. + struct mmal_msg_context *context; /** a u32 per message context */
  15472. + u32 status; /** The status of the vchiq operation */
  15473. + u32 padding;
  15474. +};
  15475. +
  15476. +/* Send from VC to host to report version */
  15477. +struct mmal_msg_version {
  15478. + u32 flags;
  15479. + u32 major;
  15480. + u32 minor;
  15481. + u32 minimum;
  15482. +};
  15483. +
  15484. +/* request to VC to create component */
  15485. +struct mmal_msg_component_create {
  15486. + void *client_component; /* component context */
  15487. + char name[128];
  15488. + u32 pid; /* For debug */
  15489. +};
  15490. +
  15491. +/* reply from VC to component creation request */
  15492. +struct mmal_msg_component_create_reply {
  15493. + u32 status; /** enum mmal_msg_status - how does this differ to
  15494. + * the one in the header?
  15495. + */
  15496. + u32 component_handle; /* VideoCore handle for component */
  15497. + u32 input_num; /* Number of input ports */
  15498. + u32 output_num; /* Number of output ports */
  15499. + u32 clock_num; /* Number of clock ports */
  15500. +};
  15501. +
  15502. +/* request to VC to destroy a component */
  15503. +struct mmal_msg_component_destroy {
  15504. + u32 component_handle;
  15505. +};
  15506. +
  15507. +struct mmal_msg_component_destroy_reply {
  15508. + u32 status; /** The component destruction status */
  15509. +};
  15510. +
  15511. +
  15512. +/* request and reply to VC to enable a component */
  15513. +struct mmal_msg_component_enable {
  15514. + u32 component_handle;
  15515. +};
  15516. +
  15517. +struct mmal_msg_component_enable_reply {
  15518. + u32 status; /** The component enable status */
  15519. +};
  15520. +
  15521. +
  15522. +/* request and reply to VC to disable a component */
  15523. +struct mmal_msg_component_disable {
  15524. + u32 component_handle;
  15525. +};
  15526. +
  15527. +struct mmal_msg_component_disable_reply {
  15528. + u32 status; /** The component disable status */
  15529. +};
  15530. +
  15531. +/* request to VC to get port information */
  15532. +struct mmal_msg_port_info_get {
  15533. + u32 component_handle; /* component handle port is associated with */
  15534. + u32 port_type; /* enum mmal_msg_port_type */
  15535. + u32 index; /* port index to query */
  15536. +};
  15537. +
  15538. +/* reply from VC to get port info request */
  15539. +struct mmal_msg_port_info_get_reply {
  15540. + u32 status; /** enum mmal_msg_status */
  15541. + u32 component_handle; /* component handle port is associated with */
  15542. + u32 port_type; /* enum mmal_msg_port_type */
  15543. + u32 port_index; /* port indexed in query */
  15544. + s32 found; /* unused */
  15545. + u32 port_handle; /**< Handle to use for this port */
  15546. + struct mmal_port port;
  15547. + struct mmal_es_format format; /* elementry stream format */
  15548. + union mmal_es_specific_format es; /* es type specific data */
  15549. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  15550. +};
  15551. +
  15552. +/* request to VC to set port information */
  15553. +struct mmal_msg_port_info_set {
  15554. + u32 component_handle;
  15555. + u32 port_type; /* enum mmal_msg_port_type */
  15556. + u32 port_index; /* port indexed in query */
  15557. + struct mmal_port port;
  15558. + struct mmal_es_format format;
  15559. + union mmal_es_specific_format es;
  15560. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  15561. +};
  15562. +
  15563. +/* reply from VC to port info set request */
  15564. +struct mmal_msg_port_info_set_reply {
  15565. + u32 status;
  15566. + u32 component_handle; /* component handle port is associated with */
  15567. + u32 port_type; /* enum mmal_msg_port_type */
  15568. + u32 index; /* port indexed in query */
  15569. + s32 found; /* unused */
  15570. + u32 port_handle; /**< Handle to use for this port */
  15571. + struct mmal_port port;
  15572. + struct mmal_es_format format;
  15573. + union mmal_es_specific_format es;
  15574. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  15575. +};
  15576. +
  15577. +
  15578. +/* port action requests that take a mmal_port as a parameter */
  15579. +struct mmal_msg_port_action_port {
  15580. + u32 component_handle;
  15581. + u32 port_handle;
  15582. + u32 action; /* enum mmal_msg_port_action_type */
  15583. + struct mmal_port port;
  15584. +};
  15585. +
  15586. +/* port action requests that take handles as a parameter */
  15587. +struct mmal_msg_port_action_handle {
  15588. + u32 component_handle;
  15589. + u32 port_handle;
  15590. + u32 action; /* enum mmal_msg_port_action_type */
  15591. + u32 connect_component_handle;
  15592. + u32 connect_port_handle;
  15593. +};
  15594. +
  15595. +struct mmal_msg_port_action_reply {
  15596. + u32 status; /** The port action operation status */
  15597. +};
  15598. +
  15599. +
  15600. +
  15601. +
  15602. +/* MMAL buffer transfer */
  15603. +
  15604. +/** Size of space reserved in a buffer message for short messages. */
  15605. +#define MMAL_VC_SHORT_DATA 128
  15606. +
  15607. +/** Signals that the current payload is the end of the stream of data */
  15608. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  15609. +/** Signals that the start of the current payload starts a frame */
  15610. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  15611. +/** Signals that the end of the current payload ends a frame */
  15612. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  15613. +/** Signals that the current payload contains only complete frames (>1) */
  15614. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  15615. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  15616. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  15617. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  15618. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  15619. + * Can be used for instance by a decoder to reset its state */
  15620. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  15621. +/** Signals a buffer containing some kind of config data for the component
  15622. + * (e.g. codec config data) */
  15623. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  15624. +/** Signals an encrypted payload */
  15625. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  15626. +/** Signals a buffer containing side information */
  15627. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  15628. +/** Signals a buffer which is the snapshot/postview image from a stills
  15629. + * capture
  15630. + */
  15631. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  15632. +/** Signals a buffer which contains data known to be corrupted */
  15633. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  15634. +/** Signals that a buffer failed to be transmitted */
  15635. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  15636. +
  15637. +struct mmal_driver_buffer {
  15638. + u32 magic;
  15639. + u32 component_handle;
  15640. + u32 port_handle;
  15641. + void *client_context;
  15642. +};
  15643. +
  15644. +/* buffer header */
  15645. +struct mmal_buffer_header {
  15646. + struct mmal_buffer_header *next; /* next header */
  15647. + void *priv; /* framework private data */
  15648. + u32 cmd;
  15649. + void *data;
  15650. + u32 alloc_size;
  15651. + u32 length;
  15652. + u32 offset;
  15653. + u32 flags;
  15654. + s64 pts;
  15655. + s64 dts;
  15656. + void *type;
  15657. + void *user_data;
  15658. +};
  15659. +
  15660. +struct mmal_buffer_header_type_specific {
  15661. + union {
  15662. + struct {
  15663. + u32 planes;
  15664. + u32 offset[4];
  15665. + u32 pitch[4];
  15666. + u32 flags;
  15667. + } video;
  15668. + } u;
  15669. +};
  15670. +
  15671. +struct mmal_msg_buffer_from_host {
  15672. + /* The front 32 bytes of the buffer header are copied
  15673. + * back to us in the reply to allow for context. This
  15674. + * area is used to store two mmal_driver_buffer structures to
  15675. + * allow for multiple concurrent service users.
  15676. + */
  15677. + /* control data */
  15678. + struct mmal_driver_buffer drvbuf;
  15679. +
  15680. + /* referenced control data for passthrough buffer management */
  15681. + struct mmal_driver_buffer drvbuf_ref;
  15682. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  15683. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  15684. + s32 is_zero_copy;
  15685. + s32 has_reference;
  15686. +
  15687. + /** allows short data to be xfered in control message */
  15688. + u32 payload_in_message;
  15689. + u8 short_data[MMAL_VC_SHORT_DATA];
  15690. +};
  15691. +
  15692. +
  15693. +/* port parameter setting */
  15694. +
  15695. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  15696. +
  15697. +struct mmal_msg_port_parameter_set {
  15698. + u32 component_handle; /* component */
  15699. + u32 port_handle; /* port */
  15700. + u32 id; /* Parameter ID */
  15701. + u32 size; /* Parameter size */
  15702. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15703. +};
  15704. +
  15705. +struct mmal_msg_port_parameter_set_reply {
  15706. + u32 status; /** enum mmal_msg_status todo: how does this
  15707. + * differ to the one in the header?
  15708. + */
  15709. +};
  15710. +
  15711. +/* port parameter getting */
  15712. +
  15713. +struct mmal_msg_port_parameter_get {
  15714. + u32 component_handle; /* component */
  15715. + u32 port_handle; /* port */
  15716. + u32 id; /* Parameter ID */
  15717. + u32 size; /* Parameter size */
  15718. +};
  15719. +
  15720. +struct mmal_msg_port_parameter_get_reply {
  15721. + u32 status; /* Status of mmal_port_parameter_get call */
  15722. + u32 id; /* Parameter ID */
  15723. + u32 size; /* Parameter size */
  15724. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15725. +};
  15726. +
  15727. +/* event messages */
  15728. +#define MMAL_WORKER_EVENT_SPACE 256
  15729. +
  15730. +struct mmal_msg_event_to_host {
  15731. + void *client_component; /* component context */
  15732. +
  15733. + u32 port_type;
  15734. + u32 port_num;
  15735. +
  15736. + u32 cmd;
  15737. + u32 length;
  15738. + u8 data[MMAL_WORKER_EVENT_SPACE];
  15739. + struct mmal_buffer_header *delayed_buffer;
  15740. +};
  15741. +
  15742. +/* all mmal messages are serialised through this structure */
  15743. +struct mmal_msg {
  15744. + /* header */
  15745. + struct mmal_msg_header h;
  15746. + /* payload */
  15747. + union {
  15748. + struct mmal_msg_version version;
  15749. +
  15750. + struct mmal_msg_component_create component_create;
  15751. + struct mmal_msg_component_create_reply component_create_reply;
  15752. +
  15753. + struct mmal_msg_component_destroy component_destroy;
  15754. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  15755. +
  15756. + struct mmal_msg_component_enable component_enable;
  15757. + struct mmal_msg_component_enable_reply component_enable_reply;
  15758. +
  15759. + struct mmal_msg_component_disable component_disable;
  15760. + struct mmal_msg_component_disable_reply component_disable_reply;
  15761. +
  15762. + struct mmal_msg_port_info_get port_info_get;
  15763. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  15764. +
  15765. + struct mmal_msg_port_info_set port_info_set;
  15766. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  15767. +
  15768. + struct mmal_msg_port_action_port port_action_port;
  15769. + struct mmal_msg_port_action_handle port_action_handle;
  15770. + struct mmal_msg_port_action_reply port_action_reply;
  15771. +
  15772. + struct mmal_msg_buffer_from_host buffer_from_host;
  15773. +
  15774. + struct mmal_msg_port_parameter_set port_parameter_set;
  15775. + struct mmal_msg_port_parameter_set_reply
  15776. + port_parameter_set_reply;
  15777. + struct mmal_msg_port_parameter_get
  15778. + port_parameter_get;
  15779. + struct mmal_msg_port_parameter_get_reply
  15780. + port_parameter_get_reply;
  15781. +
  15782. + struct mmal_msg_event_to_host event_to_host;
  15783. +
  15784. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  15785. + } u;
  15786. +};
  15787. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg-port.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg-port.h
  15788. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  15789. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-03-13 12:46:18.260055389 +0100
  15790. @@ -0,0 +1,107 @@
  15791. +/*
  15792. + * Broadcom BM2835 V4L2 driver
  15793. + *
  15794. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15795. + *
  15796. + * This file is subject to the terms and conditions of the GNU General Public
  15797. + * License. See the file COPYING in the main directory of this archive
  15798. + * for more details.
  15799. + *
  15800. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15801. + * Dave Stevenson <dsteve@broadcom.com>
  15802. + * Simon Mellor <simellor@broadcom.com>
  15803. + * Luke Diamand <luked@broadcom.com>
  15804. + */
  15805. +
  15806. +/* MMAL_PORT_TYPE_T */
  15807. +enum mmal_port_type {
  15808. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  15809. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  15810. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  15811. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  15812. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  15813. +};
  15814. +
  15815. +/** The port is pass-through and doesn't need buffer headers allocated */
  15816. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  15817. +/** The port wants to allocate the buffer payloads.
  15818. + * This signals a preference that payload allocation should be done
  15819. + * on this port for efficiency reasons. */
  15820. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  15821. +/** The port supports format change events.
  15822. + * This applies to input ports and is used to let the client know
  15823. + * whether the port supports being reconfigured via a format
  15824. + * change event (i.e. without having to disable the port). */
  15825. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  15826. +
  15827. +/* mmal port structure (MMAL_PORT_T)
  15828. + *
  15829. + * most elements are informational only, the pointer values for
  15830. + * interogation messages are generally provided as additional
  15831. + * strucures within the message. When used to set values only teh
  15832. + * buffer_num, buffer_size and userdata parameters are writable.
  15833. + */
  15834. +struct mmal_port {
  15835. + void *priv; /* Private member used by the framework */
  15836. + const char *name; /* Port name. Used for debugging purposes (RO) */
  15837. +
  15838. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  15839. + u16 index; /* Index of the port in its type list (RO) */
  15840. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  15841. +
  15842. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  15843. + struct mmal_es_format *format; /* Format of the elementary stream */
  15844. +
  15845. + u32 buffer_num_min; /* Minimum number of buffers the port
  15846. + * requires (RO). This is set by the
  15847. + * component.
  15848. + */
  15849. +
  15850. + u32 buffer_size_min; /* Minimum size of buffers the port
  15851. + * requires (RO). This is set by the
  15852. + * component.
  15853. + */
  15854. +
  15855. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  15856. + * the buffers (RO). A value of
  15857. + * zero means no special alignment
  15858. + * requirements. This is set by the
  15859. + * component.
  15860. + */
  15861. +
  15862. + u32 buffer_num_recommended; /* Number of buffers the port
  15863. + * recommends for optimal
  15864. + * performance (RO). A value of
  15865. + * zero means no special
  15866. + * recommendation. This is set
  15867. + * by the component.
  15868. + */
  15869. +
  15870. + u32 buffer_size_recommended; /* Size of buffers the port
  15871. + * recommends for optimal
  15872. + * performance (RO). A value of
  15873. + * zero means no special
  15874. + * recommendation. This is set
  15875. + * by the component.
  15876. + */
  15877. +
  15878. + u32 buffer_num; /* Actual number of buffers the port will use.
  15879. + * This is set by the client.
  15880. + */
  15881. +
  15882. + u32 buffer_size; /* Actual maximum size of the buffers that
  15883. + * will be sent to the port. This is set by
  15884. + * the client.
  15885. + */
  15886. +
  15887. + void *component; /* Component this port belongs to (Read Only) */
  15888. +
  15889. + void *userdata; /* Field reserved for use by the client */
  15890. +
  15891. + u32 capabilities; /* Flags describing the capabilities of a
  15892. + * port (RO). Bitwise combination of \ref
  15893. + * portcapabilities "Port capabilities"
  15894. + * values.
  15895. + */
  15896. +
  15897. +};
  15898. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-parameters.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-parameters.h
  15899. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  15900. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-parameters.h 2014-03-13 12:46:18.260055389 +0100
  15901. @@ -0,0 +1,649 @@
  15902. +/*
  15903. + * Broadcom BM2835 V4L2 driver
  15904. + *
  15905. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15906. + *
  15907. + * This file is subject to the terms and conditions of the GNU General Public
  15908. + * License. See the file COPYING in the main directory of this archive
  15909. + * for more details.
  15910. + *
  15911. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15912. + * Dave Stevenson <dsteve@broadcom.com>
  15913. + * Simon Mellor <simellor@broadcom.com>
  15914. + * Luke Diamand <luked@broadcom.com>
  15915. + */
  15916. +
  15917. +/* common parameters */
  15918. +
  15919. +/** @name Parameter groups
  15920. + * Parameters are divided into groups, and then allocated sequentially within
  15921. + * a group using an enum.
  15922. + * @{
  15923. + */
  15924. +
  15925. +/** Common parameter ID group, used with many types of component. */
  15926. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  15927. +/** Camera-specific parameter ID group. */
  15928. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  15929. +/** Video-specific parameter ID group. */
  15930. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  15931. +/** Audio-specific parameter ID group. */
  15932. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  15933. +/** Clock-specific parameter ID group. */
  15934. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  15935. +/** Miracast-specific parameter ID group. */
  15936. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  15937. +
  15938. +/* Common parameters */
  15939. +enum mmal_parameter_common_type {
  15940. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  15941. + = MMAL_PARAMETER_GROUP_COMMON,
  15942. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  15943. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  15944. +
  15945. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  15946. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  15947. +
  15948. + /** MMAL_PARAMETER_BOOLEAN_T */
  15949. + MMAL_PARAMETER_ZERO_COPY,
  15950. +
  15951. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  15952. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  15953. +
  15954. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  15955. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  15956. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  15957. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  15958. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  15959. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  15960. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  15961. + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  15962. +};
  15963. +
  15964. +/* camera parameters */
  15965. +
  15966. +enum mmal_parameter_camera_type {
  15967. + /* 0 */
  15968. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  15969. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  15970. + = MMAL_PARAMETER_GROUP_CAMERA,
  15971. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  15972. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  15973. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15974. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  15975. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  15976. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  15977. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  15978. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  15979. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  15980. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  15981. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  15982. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  15983. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15984. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  15985. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  15986. +
  15987. + /* 0x10 */
  15988. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  15989. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15990. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  15991. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  15992. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  15993. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  15994. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  15995. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  15996. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15997. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  15998. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  15999. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  16000. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  16001. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16002. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  16003. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16004. +
  16005. + /* 0x20 */
  16006. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  16007. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16008. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16009. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  16010. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  16011. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  16012. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  16013. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  16014. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  16015. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16016. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  16017. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  16018. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16019. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16020. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16021. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16022. +
  16023. + /* 0x30 */
  16024. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  16025. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16026. +
  16027. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  16028. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  16029. +
  16030. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16031. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  16032. +
  16033. + /** @ref MMAL_PARAMETER_UINT32_T */
  16034. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  16035. +
  16036. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  16037. + MMAL_PARAMETER_CAMERA_USE_CASE,
  16038. +
  16039. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16040. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  16041. +
  16042. + /** @ref MMAL_PARAMETER_UINT32_T */
  16043. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  16044. +
  16045. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16046. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  16047. +
  16048. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16049. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  16050. +
  16051. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  16052. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  16053. +
  16054. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  16055. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  16056. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16057. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  16058. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  16059. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  16060. +
  16061. + /* 0x40 */
  16062. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16063. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16064. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16065. + MMAL_PARAMETER_SHUTTER_SPEED /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  16066. +};
  16067. +
  16068. +struct mmal_parameter_rational {
  16069. + s32 num; /**< Numerator */
  16070. + s32 den; /**< Denominator */
  16071. +};
  16072. +
  16073. +enum mmal_parameter_camera_config_timestamp_mode {
  16074. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  16075. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  16076. + * for the frame timestamp
  16077. + */
  16078. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  16079. + * but subtract the
  16080. + * timestamp of the first
  16081. + * frame sent to give a
  16082. + * zero based timestamp.
  16083. + */
  16084. +};
  16085. +
  16086. +struct mmal_parameter_fps_range {
  16087. + /**< Low end of the permitted framerate range */
  16088. + struct mmal_parameter_rational fps_low;
  16089. + /**< High end of the permitted framerate range */
  16090. + struct mmal_parameter_rational fps_high;
  16091. +};
  16092. +
  16093. +
  16094. +/* camera configuration parameter */
  16095. +struct mmal_parameter_camera_config {
  16096. + /* Parameters for setting up the image pools */
  16097. + u32 max_stills_w; /* Max size of stills capture */
  16098. + u32 max_stills_h;
  16099. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  16100. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  16101. +
  16102. + u32 max_preview_video_w; /* Max size of the preview or video
  16103. + * capture frames
  16104. + */
  16105. + u32 max_preview_video_h;
  16106. + u32 num_preview_video_frames;
  16107. +
  16108. + /** Sets the height of the circular buffer for stills capture. */
  16109. + u32 stills_capture_circular_buffer_height;
  16110. +
  16111. + /** Allows preview/encode to resume as fast as possible after the stills
  16112. + * input frame has been received, and then processes the still frame in
  16113. + * the background whilst preview/encode has resumed.
  16114. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  16115. + */
  16116. + u32 fast_preview_resume;
  16117. +
  16118. + /** Selects algorithm for timestamping frames if
  16119. + * there is no clock component connected.
  16120. + * enum mmal_parameter_camera_config_timestamp_mode
  16121. + */
  16122. + s32 use_stc_timestamp;
  16123. +};
  16124. +
  16125. +
  16126. +enum mmal_parameter_exposuremode {
  16127. + MMAL_PARAM_EXPOSUREMODE_OFF,
  16128. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  16129. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  16130. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  16131. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  16132. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  16133. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  16134. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  16135. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  16136. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  16137. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  16138. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  16139. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  16140. +};
  16141. +
  16142. +enum mmal_parameter_exposuremeteringmode {
  16143. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  16144. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  16145. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  16146. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  16147. +};
  16148. +
  16149. +enum mmal_parameter_awbmode {
  16150. + MMAL_PARAM_AWBMODE_OFF,
  16151. + MMAL_PARAM_AWBMODE_AUTO,
  16152. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  16153. + MMAL_PARAM_AWBMODE_CLOUDY,
  16154. + MMAL_PARAM_AWBMODE_SHADE,
  16155. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  16156. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  16157. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  16158. + MMAL_PARAM_AWBMODE_FLASH,
  16159. + MMAL_PARAM_AWBMODE_HORIZON,
  16160. +};
  16161. +
  16162. +enum mmal_parameter_imagefx {
  16163. + MMAL_PARAM_IMAGEFX_NONE,
  16164. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  16165. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  16166. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  16167. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  16168. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  16169. + MMAL_PARAM_IMAGEFX_SKETCH,
  16170. + MMAL_PARAM_IMAGEFX_DENOISE,
  16171. + MMAL_PARAM_IMAGEFX_EMBOSS,
  16172. + MMAL_PARAM_IMAGEFX_OILPAINT,
  16173. + MMAL_PARAM_IMAGEFX_HATCH,
  16174. + MMAL_PARAM_IMAGEFX_GPEN,
  16175. + MMAL_PARAM_IMAGEFX_PASTEL,
  16176. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  16177. + MMAL_PARAM_IMAGEFX_FILM,
  16178. + MMAL_PARAM_IMAGEFX_BLUR,
  16179. + MMAL_PARAM_IMAGEFX_SATURATION,
  16180. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  16181. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  16182. + MMAL_PARAM_IMAGEFX_POSTERISE,
  16183. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  16184. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  16185. + MMAL_PARAM_IMAGEFX_CARTOON,
  16186. +};
  16187. +
  16188. +enum MMAL_PARAM_FLICKERAVOID_T {
  16189. + MMAL_PARAM_FLICKERAVOID_OFF,
  16190. + MMAL_PARAM_FLICKERAVOID_AUTO,
  16191. + MMAL_PARAM_FLICKERAVOID_50HZ,
  16192. + MMAL_PARAM_FLICKERAVOID_60HZ,
  16193. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  16194. +};
  16195. +
  16196. +/** Manner of video rate control */
  16197. +enum mmal_parameter_rate_control_mode {
  16198. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  16199. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  16200. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  16201. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  16202. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  16203. +};
  16204. +
  16205. +enum mmal_video_profile {
  16206. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  16207. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  16208. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  16209. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  16210. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  16211. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  16212. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  16213. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  16214. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  16215. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  16216. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  16217. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  16218. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  16219. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  16220. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  16221. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  16222. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  16223. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  16224. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  16225. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  16226. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  16227. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  16228. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  16229. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  16230. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  16231. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  16232. + MMAL_VIDEO_PROFILE_H264_MAIN,
  16233. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  16234. + MMAL_VIDEO_PROFILE_H264_HIGH,
  16235. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  16236. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  16237. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  16238. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  16239. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  16240. +};
  16241. +
  16242. +enum mmal_video_level {
  16243. + MMAL_VIDEO_LEVEL_H263_10,
  16244. + MMAL_VIDEO_LEVEL_H263_20,
  16245. + MMAL_VIDEO_LEVEL_H263_30,
  16246. + MMAL_VIDEO_LEVEL_H263_40,
  16247. + MMAL_VIDEO_LEVEL_H263_45,
  16248. + MMAL_VIDEO_LEVEL_H263_50,
  16249. + MMAL_VIDEO_LEVEL_H263_60,
  16250. + MMAL_VIDEO_LEVEL_H263_70,
  16251. + MMAL_VIDEO_LEVEL_MP4V_0,
  16252. + MMAL_VIDEO_LEVEL_MP4V_0b,
  16253. + MMAL_VIDEO_LEVEL_MP4V_1,
  16254. + MMAL_VIDEO_LEVEL_MP4V_2,
  16255. + MMAL_VIDEO_LEVEL_MP4V_3,
  16256. + MMAL_VIDEO_LEVEL_MP4V_4,
  16257. + MMAL_VIDEO_LEVEL_MP4V_4a,
  16258. + MMAL_VIDEO_LEVEL_MP4V_5,
  16259. + MMAL_VIDEO_LEVEL_MP4V_6,
  16260. + MMAL_VIDEO_LEVEL_H264_1,
  16261. + MMAL_VIDEO_LEVEL_H264_1b,
  16262. + MMAL_VIDEO_LEVEL_H264_11,
  16263. + MMAL_VIDEO_LEVEL_H264_12,
  16264. + MMAL_VIDEO_LEVEL_H264_13,
  16265. + MMAL_VIDEO_LEVEL_H264_2,
  16266. + MMAL_VIDEO_LEVEL_H264_21,
  16267. + MMAL_VIDEO_LEVEL_H264_22,
  16268. + MMAL_VIDEO_LEVEL_H264_3,
  16269. + MMAL_VIDEO_LEVEL_H264_31,
  16270. + MMAL_VIDEO_LEVEL_H264_32,
  16271. + MMAL_VIDEO_LEVEL_H264_4,
  16272. + MMAL_VIDEO_LEVEL_H264_41,
  16273. + MMAL_VIDEO_LEVEL_H264_42,
  16274. + MMAL_VIDEO_LEVEL_H264_5,
  16275. + MMAL_VIDEO_LEVEL_H264_51,
  16276. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  16277. +};
  16278. +
  16279. +struct mmal_parameter_video_profile {
  16280. + enum mmal_video_profile profile;
  16281. + enum mmal_video_level level;
  16282. +};
  16283. +
  16284. +/* video parameters */
  16285. +
  16286. +enum mmal_parameter_video_type {
  16287. + /** @ref MMAL_DISPLAYREGION_T */
  16288. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  16289. +
  16290. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  16291. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  16292. +
  16293. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  16294. + MMAL_PARAMETER_PROFILE,
  16295. +
  16296. + /** @ref MMAL_PARAMETER_UINT32_T */
  16297. + MMAL_PARAMETER_INTRAPERIOD,
  16298. +
  16299. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  16300. + MMAL_PARAMETER_RATECONTROL,
  16301. +
  16302. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  16303. + MMAL_PARAMETER_NALUNITFORMAT,
  16304. +
  16305. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16306. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  16307. +
  16308. + /** @ref MMAL_PARAMETER_UINT32_T.
  16309. + * Setting the value to zero resets to the default (one slice per frame).
  16310. + */
  16311. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  16312. +
  16313. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  16314. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  16315. +
  16316. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  16317. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  16318. +
  16319. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  16320. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  16321. +
  16322. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  16323. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  16324. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  16325. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  16326. +
  16327. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16328. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  16329. +
  16330. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  16331. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  16332. +
  16333. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  16334. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  16335. +
  16336. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16337. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  16338. +
  16339. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16340. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  16341. +
  16342. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  16343. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  16344. +
  16345. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  16346. + /** @ref MMAL_PARAMETER_UINT32_T.
  16347. + * Changing this parameter from the default can reduce frame rate
  16348. + * because image buffers need to be re-pitched.
  16349. + */
  16350. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  16351. +
  16352. + /** @ref MMAL_PARAMETER_UINT32_T.
  16353. + * Changing this parameter from the default can reduce frame rate
  16354. + * because image buffers need to be re-pitched.
  16355. + */
  16356. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  16357. +
  16358. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16359. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  16360. +
  16361. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16362. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  16363. +
  16364. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  16365. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  16366. +
  16367. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  16368. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  16369. +
  16370. + /** @ref MMAL_PARAMETER_UINT32_T */
  16371. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  16372. +
  16373. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16374. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  16375. +
  16376. + /* H264 specific parameters */
  16377. +
  16378. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16379. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  16380. +
  16381. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16382. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  16383. +
  16384. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16385. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  16386. +
  16387. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16388. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  16389. +
  16390. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  16391. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  16392. +
  16393. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16394. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  16395. +
  16396. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16397. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  16398. +
  16399. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  16400. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  16401. +
  16402. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16403. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  16404. +
  16405. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16406. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  16407. +
  16408. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  16409. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  16410. +
  16411. + /** @ref MMAL_PARAMETER_BYTES_T */
  16412. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  16413. +
  16414. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16415. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  16416. +
  16417. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16418. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  16419. +
  16420. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16421. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  16422. +};
  16423. +
  16424. +/** Valid mirror modes */
  16425. +enum mmal_parameter_mirror {
  16426. + MMAL_PARAM_MIRROR_NONE,
  16427. + MMAL_PARAM_MIRROR_VERTICAL,
  16428. + MMAL_PARAM_MIRROR_HORIZONTAL,
  16429. + MMAL_PARAM_MIRROR_BOTH,
  16430. +};
  16431. +
  16432. +enum mmal_parameter_displaytransform {
  16433. + MMAL_DISPLAY_ROT0 = 0,
  16434. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  16435. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  16436. + MMAL_DISPLAY_ROT180 = 3,
  16437. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  16438. + MMAL_DISPLAY_ROT270 = 5,
  16439. + MMAL_DISPLAY_ROT90 = 6,
  16440. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  16441. +};
  16442. +
  16443. +enum mmal_parameter_displaymode {
  16444. + MMAL_DISPLAY_MODE_FILL = 0,
  16445. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  16446. +};
  16447. +
  16448. +enum mmal_parameter_displayset {
  16449. + MMAL_DISPLAY_SET_NONE = 0,
  16450. + MMAL_DISPLAY_SET_NUM = 1,
  16451. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  16452. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  16453. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  16454. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  16455. + MMAL_DISPLAY_SET_MODE = 0x20,
  16456. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  16457. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  16458. + MMAL_DISPLAY_SET_LAYER = 0x100,
  16459. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  16460. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  16461. +};
  16462. +
  16463. +struct mmal_parameter_displayregion {
  16464. + /** Bitfield that indicates which fields are set and should be
  16465. + * used. All other fields will maintain their current value.
  16466. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  16467. + * combined.
  16468. + */
  16469. + u32 set;
  16470. +
  16471. + /** Describes the display output device, with 0 typically
  16472. + * being a directly connected LCD display. The actual values
  16473. + * will depend on the hardware. Code using hard-wired numbers
  16474. + * (e.g. 2) is certain to fail.
  16475. + */
  16476. +
  16477. + u32 display_num;
  16478. + /** Indicates that we are using the full device screen area,
  16479. + * rather than a window of the display. If zero, then
  16480. + * dest_rect is used to specify a region of the display to
  16481. + * use.
  16482. + */
  16483. +
  16484. + s32 fullscreen;
  16485. + /** Indicates any rotation or flipping used to map frames onto
  16486. + * the natural display orientation.
  16487. + */
  16488. + u32 transform; /* enum mmal_parameter_displaytransform */
  16489. +
  16490. + /** Where to display the frame within the screen, if
  16491. + * fullscreen is zero.
  16492. + */
  16493. + struct vchiq_mmal_rect dest_rect;
  16494. +
  16495. + /** Indicates which area of the frame to display. If all
  16496. + * values are zero, the whole frame will be used.
  16497. + */
  16498. + struct vchiq_mmal_rect src_rect;
  16499. +
  16500. + /** If set to non-zero, indicates that any display scaling
  16501. + * should disregard the aspect ratio of the frame region being
  16502. + * displayed.
  16503. + */
  16504. + s32 noaspect;
  16505. +
  16506. + /** Indicates how the image should be scaled to fit the
  16507. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  16508. + * that the image should fill the screen by potentially
  16509. + * cropping the frames. Setting \code mode \endcode to \code
  16510. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  16511. + * source region should be displayed and black bars added if
  16512. + * necessary.
  16513. + */
  16514. + u32 mode; /* enum mmal_parameter_displaymode */
  16515. +
  16516. + /** If non-zero, defines the width of a source pixel relative
  16517. + * to \code pixel_y \endcode. If zero, then pixels default to
  16518. + * being square.
  16519. + */
  16520. + u32 pixel_x;
  16521. +
  16522. + /** If non-zero, defines the height of a source pixel relative
  16523. + * to \code pixel_x \endcode. If zero, then pixels default to
  16524. + * being square.
  16525. + */
  16526. + u32 pixel_y;
  16527. +
  16528. + /** Sets the relative depth of the images, with greater values
  16529. + * being in front of smaller values.
  16530. + */
  16531. + u32 layer;
  16532. +
  16533. + /** Set to non-zero to ensure copy protection is used on
  16534. + * output.
  16535. + */
  16536. + s32 copyprotect_required;
  16537. +
  16538. + /** Level of opacity of the layer, where zero is fully
  16539. + * transparent and 255 is fully opaque.
  16540. + */
  16541. + u32 alpha;
  16542. +};
  16543. +
  16544. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  16545. +
  16546. +struct mmal_parameter_imagefx_parameters {
  16547. + enum mmal_parameter_imagefx effect;
  16548. + u32 num_effect_params;
  16549. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  16550. +};
  16551. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-vchiq.c linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-vchiq.c
  16552. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  16553. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-03-13 12:46:18.260055389 +0100
  16554. @@ -0,0 +1,1916 @@
  16555. +/*
  16556. + * Broadcom BM2835 V4L2 driver
  16557. + *
  16558. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  16559. + *
  16560. + * This file is subject to the terms and conditions of the GNU General Public
  16561. + * License. See the file COPYING in the main directory of this archive
  16562. + * for more details.
  16563. + *
  16564. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  16565. + * Dave Stevenson <dsteve@broadcom.com>
  16566. + * Simon Mellor <simellor@broadcom.com>
  16567. + * Luke Diamand <luked@broadcom.com>
  16568. + *
  16569. + * V4L2 driver MMAL vchiq interface code
  16570. + */
  16571. +
  16572. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16573. +
  16574. +#include <linux/errno.h>
  16575. +#include <linux/kernel.h>
  16576. +#include <linux/mutex.h>
  16577. +#include <linux/mm.h>
  16578. +#include <linux/slab.h>
  16579. +#include <linux/completion.h>
  16580. +#include <linux/vmalloc.h>
  16581. +#include <asm/cacheflush.h>
  16582. +#include <media/videobuf2-vmalloc.h>
  16583. +
  16584. +#include "mmal-common.h"
  16585. +#include "mmal-vchiq.h"
  16586. +#include "mmal-msg.h"
  16587. +
  16588. +#define USE_VCHIQ_ARM
  16589. +#include "interface/vchi/vchi.h"
  16590. +
  16591. +/* maximum number of components supported */
  16592. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  16593. +
  16594. +/*#define FULL_MSG_DUMP 1*/
  16595. +
  16596. +#ifdef DEBUG
  16597. +static const char *const msg_type_names[] = {
  16598. + "UNKNOWN",
  16599. + "QUIT",
  16600. + "SERVICE_CLOSED",
  16601. + "GET_VERSION",
  16602. + "COMPONENT_CREATE",
  16603. + "COMPONENT_DESTROY",
  16604. + "COMPONENT_ENABLE",
  16605. + "COMPONENT_DISABLE",
  16606. + "PORT_INFO_GET",
  16607. + "PORT_INFO_SET",
  16608. + "PORT_ACTION",
  16609. + "BUFFER_FROM_HOST",
  16610. + "BUFFER_TO_HOST",
  16611. + "GET_STATS",
  16612. + "PORT_PARAMETER_SET",
  16613. + "PORT_PARAMETER_GET",
  16614. + "EVENT_TO_HOST",
  16615. + "GET_CORE_STATS_FOR_PORT",
  16616. + "OPAQUE_ALLOCATOR",
  16617. + "CONSUME_MEM",
  16618. + "LMK",
  16619. + "OPAQUE_ALLOCATOR_DESC",
  16620. + "DRM_GET_LHS32",
  16621. + "DRM_GET_TIME",
  16622. + "BUFFER_FROM_HOST_ZEROLEN",
  16623. + "PORT_FLUSH",
  16624. + "HOST_LOG",
  16625. +};
  16626. +#endif
  16627. +
  16628. +static const char *const port_action_type_names[] = {
  16629. + "UNKNOWN",
  16630. + "ENABLE",
  16631. + "DISABLE",
  16632. + "FLUSH",
  16633. + "CONNECT",
  16634. + "DISCONNECT",
  16635. + "SET_REQUIREMENTS",
  16636. +};
  16637. +
  16638. +#if defined(DEBUG)
  16639. +#if defined(FULL_MSG_DUMP)
  16640. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16641. + do { \
  16642. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16643. + msg_type_names[(MSG)->h.type], \
  16644. + (MSG)->h.type, (MSG_LEN)); \
  16645. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  16646. + 16, 4, (MSG), \
  16647. + sizeof(struct mmal_msg_header), 1); \
  16648. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  16649. + 16, 4, \
  16650. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  16651. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  16652. + } while (0)
  16653. +#else
  16654. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16655. + { \
  16656. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16657. + msg_type_names[(MSG)->h.type], \
  16658. + (MSG)->h.type, (MSG_LEN)); \
  16659. + }
  16660. +#endif
  16661. +#else
  16662. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  16663. +#endif
  16664. +
  16665. +/* normal message context */
  16666. +struct mmal_msg_context {
  16667. + union {
  16668. + struct {
  16669. + /* work struct for defered callback - must come first */
  16670. + struct work_struct work;
  16671. + /* mmal instance */
  16672. + struct vchiq_mmal_instance *instance;
  16673. + /* mmal port */
  16674. + struct vchiq_mmal_port *port;
  16675. + /* actual buffer used to store bulk reply */
  16676. + struct mmal_buffer *buffer;
  16677. + /* amount of buffer used */
  16678. + unsigned long buffer_used;
  16679. + /* MMAL buffer flags */
  16680. + u32 mmal_flags;
  16681. + /* Presentation and Decode timestamps */
  16682. + s64 pts;
  16683. + s64 dts;
  16684. +
  16685. + int status; /* context status */
  16686. +
  16687. + } bulk; /* bulk data */
  16688. +
  16689. + struct {
  16690. + /* message handle to release */
  16691. + VCHI_HELD_MSG_T msg_handle;
  16692. + /* pointer to received message */
  16693. + struct mmal_msg *msg;
  16694. + /* received message length */
  16695. + u32 msg_len;
  16696. + /* completion upon reply */
  16697. + struct completion cmplt;
  16698. + } sync; /* synchronous response */
  16699. + } u;
  16700. +
  16701. +};
  16702. +
  16703. +struct vchiq_mmal_instance {
  16704. + VCHI_SERVICE_HANDLE_T handle;
  16705. +
  16706. + /* ensure serialised access to service */
  16707. + struct mutex vchiq_mutex;
  16708. +
  16709. + /* ensure serialised access to bulk operations */
  16710. + struct mutex bulk_mutex;
  16711. +
  16712. + /* vmalloc page to receive scratch bulk xfers into */
  16713. + void *bulk_scratch;
  16714. +
  16715. + /* component to use next */
  16716. + int component_idx;
  16717. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  16718. +};
  16719. +
  16720. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  16721. + *instance)
  16722. +{
  16723. + struct mmal_msg_context *msg_context;
  16724. +
  16725. + /* todo: should this be allocated from a pool to avoid kmalloc */
  16726. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  16727. + memset(msg_context, 0, sizeof(*msg_context));
  16728. +
  16729. + return msg_context;
  16730. +}
  16731. +
  16732. +static void release_msg_context(struct mmal_msg_context *msg_context)
  16733. +{
  16734. + kfree(msg_context);
  16735. +}
  16736. +
  16737. +/* deals with receipt of event to host message */
  16738. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  16739. + struct mmal_msg *msg, u32 msg_len)
  16740. +{
  16741. + pr_debug("unhandled event\n");
  16742. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  16743. + msg->u.event_to_host.client_component,
  16744. + msg->u.event_to_host.port_type,
  16745. + msg->u.event_to_host.port_num,
  16746. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  16747. +}
  16748. +
  16749. +/* workqueue scheduled callback
  16750. + *
  16751. + * we do this because it is important we do not call any other vchiq
  16752. + * sync calls from witin the message delivery thread
  16753. + */
  16754. +static void buffer_work_cb(struct work_struct *work)
  16755. +{
  16756. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  16757. +
  16758. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  16759. + msg_context->u.bulk.port,
  16760. + msg_context->u.bulk.status,
  16761. + msg_context->u.bulk.buffer,
  16762. + msg_context->u.bulk.buffer_used,
  16763. + msg_context->u.bulk.mmal_flags,
  16764. + msg_context->u.bulk.dts,
  16765. + msg_context->u.bulk.pts);
  16766. +
  16767. + /* release message context */
  16768. + release_msg_context(msg_context);
  16769. +}
  16770. +
  16771. +/* enqueue a bulk receive for a given message context */
  16772. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  16773. + struct mmal_msg *msg,
  16774. + struct mmal_msg_context *msg_context)
  16775. +{
  16776. + unsigned long rd_len;
  16777. + unsigned long flags = 0;
  16778. + int ret;
  16779. +
  16780. + /* bulk mutex stops other bulk operations while we have a
  16781. + * receive in progress - released in callback
  16782. + */
  16783. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16784. + if (ret != 0)
  16785. + return ret;
  16786. +
  16787. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  16788. +
  16789. + /* take buffer from queue */
  16790. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16791. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16792. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16793. + pr_err("buffer list empty trying to submit bulk receive\n");
  16794. +
  16795. + /* todo: this is a serious error, we should never have
  16796. + * commited a buffer_to_host operation to the mmal
  16797. + * port without the buffer to back it up (underflow
  16798. + * handling) and there is no obvious way to deal with
  16799. + * this - how is the mmal servie going to react when
  16800. + * we fail to do the xfer and reschedule a buffer when
  16801. + * it arrives? perhaps a starved flag to indicate a
  16802. + * waiting bulk receive?
  16803. + */
  16804. +
  16805. + mutex_unlock(&instance->bulk_mutex);
  16806. +
  16807. + return -EINVAL;
  16808. + }
  16809. +
  16810. + msg_context->u.bulk.buffer =
  16811. + list_entry(msg_context->u.bulk.port->buffers.next,
  16812. + struct mmal_buffer, list);
  16813. + list_del(&msg_context->u.bulk.buffer->list);
  16814. +
  16815. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16816. +
  16817. + /* ensure we do not overrun the available buffer */
  16818. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  16819. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  16820. + pr_warn("short read as not enough receive buffer space\n");
  16821. + /* todo: is this the correct response, what happens to
  16822. + * the rest of the message data?
  16823. + */
  16824. + }
  16825. +
  16826. + /* store length */
  16827. + msg_context->u.bulk.buffer_used = rd_len;
  16828. + msg_context->u.bulk.mmal_flags =
  16829. + msg->u.buffer_from_host.buffer_header.flags;
  16830. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  16831. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  16832. +
  16833. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  16834. + // cache.
  16835. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  16836. +
  16837. + /* queue the bulk submission */
  16838. + vchi_service_use(instance->handle);
  16839. + ret = vchi_bulk_queue_receive(instance->handle,
  16840. + msg_context->u.bulk.buffer->buffer,
  16841. + /* Actual receive needs to be a multiple
  16842. + * of 4 bytes
  16843. + */
  16844. + (rd_len + 3) & ~3,
  16845. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16846. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16847. + msg_context);
  16848. +
  16849. + vchi_service_release(instance->handle);
  16850. +
  16851. + if (ret != 0) {
  16852. + /* callback will not be clearing the mutex */
  16853. + mutex_unlock(&instance->bulk_mutex);
  16854. + }
  16855. +
  16856. + return ret;
  16857. +}
  16858. +
  16859. +/* enque a dummy bulk receive for a given message context */
  16860. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  16861. + struct mmal_msg_context *msg_context)
  16862. +{
  16863. + int ret;
  16864. +
  16865. + /* bulk mutex stops other bulk operations while we have a
  16866. + * receive in progress - released in callback
  16867. + */
  16868. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16869. + if (ret != 0)
  16870. + return ret;
  16871. +
  16872. + /* zero length indicates this was a dummy transfer */
  16873. + msg_context->u.bulk.buffer_used = 0;
  16874. +
  16875. + /* queue the bulk submission */
  16876. + vchi_service_use(instance->handle);
  16877. +
  16878. + ret = vchi_bulk_queue_receive(instance->handle,
  16879. + instance->bulk_scratch,
  16880. + 8,
  16881. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16882. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16883. + msg_context);
  16884. +
  16885. + vchi_service_release(instance->handle);
  16886. +
  16887. + if (ret != 0) {
  16888. + /* callback will not be clearing the mutex */
  16889. + mutex_unlock(&instance->bulk_mutex);
  16890. + }
  16891. +
  16892. + return ret;
  16893. +}
  16894. +
  16895. +/* data in message, memcpy from packet into output buffer */
  16896. +static int inline_receive(struct vchiq_mmal_instance *instance,
  16897. + struct mmal_msg *msg,
  16898. + struct mmal_msg_context *msg_context)
  16899. +{
  16900. + unsigned long flags = 0;
  16901. +
  16902. + /* take buffer from queue */
  16903. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16904. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16905. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16906. + pr_err("buffer list empty trying to receive inline\n");
  16907. +
  16908. + /* todo: this is a serious error, we should never have
  16909. + * commited a buffer_to_host operation to the mmal
  16910. + * port without the buffer to back it up (with
  16911. + * underflow handling) and there is no obvious way to
  16912. + * deal with this. Less bad than the bulk case as we
  16913. + * can just drop this on the floor but...unhelpful
  16914. + */
  16915. + return -EINVAL;
  16916. + }
  16917. +
  16918. + msg_context->u.bulk.buffer =
  16919. + list_entry(msg_context->u.bulk.port->buffers.next,
  16920. + struct mmal_buffer, list);
  16921. + list_del(&msg_context->u.bulk.buffer->list);
  16922. +
  16923. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16924. +
  16925. + memcpy(msg_context->u.bulk.buffer->buffer,
  16926. + msg->u.buffer_from_host.short_data,
  16927. + msg->u.buffer_from_host.payload_in_message);
  16928. +
  16929. + msg_context->u.bulk.buffer_used =
  16930. + msg->u.buffer_from_host.payload_in_message;
  16931. +
  16932. + return 0;
  16933. +}
  16934. +
  16935. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  16936. +static int
  16937. +buffer_from_host(struct vchiq_mmal_instance *instance,
  16938. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  16939. +{
  16940. + struct mmal_msg_context *msg_context;
  16941. + struct mmal_msg m;
  16942. + int ret;
  16943. +
  16944. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  16945. +
  16946. + /* bulk mutex stops other bulk operations while we
  16947. + * have a receive in progress
  16948. + */
  16949. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  16950. + return -EINTR;
  16951. +
  16952. + /* get context */
  16953. + msg_context = get_msg_context(instance);
  16954. + if (msg_context == NULL)
  16955. + return -ENOMEM;
  16956. +
  16957. + /* store bulk message context for when data arrives */
  16958. + msg_context->u.bulk.instance = instance;
  16959. + msg_context->u.bulk.port = port;
  16960. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  16961. + msg_context->u.bulk.buffer_used = 0;
  16962. +
  16963. + /* initialise work structure ready to schedule callback */
  16964. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  16965. +
  16966. + /* prep the buffer from host message */
  16967. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  16968. +
  16969. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  16970. + m.h.magic = MMAL_MAGIC;
  16971. + m.h.context = msg_context;
  16972. + m.h.status = 0;
  16973. +
  16974. + /* drvbuf is our private data passed back */
  16975. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  16976. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  16977. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  16978. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  16979. +
  16980. + /* buffer header */
  16981. + m.u.buffer_from_host.buffer_header.cmd = 0;
  16982. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  16983. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  16984. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  16985. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  16986. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  16987. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  16988. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  16989. +
  16990. + /* clear buffer type sepecific data */
  16991. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  16992. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  16993. +
  16994. + /* no payload in message */
  16995. + m.u.buffer_from_host.payload_in_message = 0;
  16996. +
  16997. + vchi_service_use(instance->handle);
  16998. +
  16999. + ret = vchi_msg_queue(instance->handle, &m,
  17000. + sizeof(struct mmal_msg_header) +
  17001. + sizeof(m.u.buffer_from_host),
  17002. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  17003. +
  17004. + if (ret != 0) {
  17005. + release_msg_context(msg_context);
  17006. + /* todo: is this correct error value? */
  17007. + }
  17008. +
  17009. + vchi_service_release(instance->handle);
  17010. +
  17011. + mutex_unlock(&instance->bulk_mutex);
  17012. +
  17013. + return ret;
  17014. +}
  17015. +
  17016. +/* submit a buffer to the mmal sevice
  17017. + *
  17018. + * the buffer_from_host uses size data from the ports next available
  17019. + * mmal_buffer and deals with there being no buffer available by
  17020. + * incrementing the underflow for later
  17021. + */
  17022. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  17023. + struct vchiq_mmal_port *port)
  17024. +{
  17025. + int ret;
  17026. + struct mmal_buffer *buf;
  17027. + unsigned long flags = 0;
  17028. +
  17029. + if (!port->enabled)
  17030. + return -EINVAL;
  17031. +
  17032. + /* peek buffer from queue */
  17033. + spin_lock_irqsave(&port->slock, flags);
  17034. + if (list_empty(&port->buffers)) {
  17035. + port->buffer_underflow++;
  17036. + spin_unlock_irqrestore(&port->slock, flags);
  17037. + return -ENOSPC;
  17038. + }
  17039. +
  17040. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  17041. +
  17042. + spin_unlock_irqrestore(&port->slock, flags);
  17043. +
  17044. + /* issue buffer to mmal service */
  17045. + ret = buffer_from_host(instance, port, buf);
  17046. + if (ret) {
  17047. + pr_err("adding buffer header failed\n");
  17048. + /* todo: how should this be dealt with */
  17049. + }
  17050. +
  17051. + return ret;
  17052. +}
  17053. +
  17054. +/* deals with receipt of buffer to host message */
  17055. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  17056. + struct mmal_msg *msg, u32 msg_len)
  17057. +{
  17058. + struct mmal_msg_context *msg_context;
  17059. +
  17060. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  17061. + instance, msg, msg_len);
  17062. +
  17063. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  17064. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  17065. + } else {
  17066. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  17067. + return;
  17068. + }
  17069. +
  17070. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  17071. + /* message reception had an error */
  17072. + pr_warn("error %d in reply\n", msg->h.status);
  17073. +
  17074. + msg_context->u.bulk.status = msg->h.status;
  17075. +
  17076. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  17077. + /* empty buffer */
  17078. + if (msg->u.buffer_from_host.buffer_header.flags &
  17079. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  17080. + msg_context->u.bulk.status =
  17081. + dummy_bulk_receive(instance, msg_context);
  17082. + if (msg_context->u.bulk.status == 0)
  17083. + return; /* successful bulk submission, bulk
  17084. + * completion will trigger callback
  17085. + */
  17086. + } else {
  17087. + /* do callback with empty buffer - not EOS though */
  17088. + msg_context->u.bulk.status = 0;
  17089. + msg_context->u.bulk.buffer_used = 0;
  17090. + }
  17091. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  17092. + /* data is not in message, queue a bulk receive */
  17093. + msg_context->u.bulk.status =
  17094. + bulk_receive(instance, msg, msg_context);
  17095. + if (msg_context->u.bulk.status == 0)
  17096. + return; /* successful bulk submission, bulk
  17097. + * completion will trigger callback
  17098. + */
  17099. +
  17100. + /* failed to submit buffer, this will end badly */
  17101. + pr_err("error %d on bulk submission\n",
  17102. + msg_context->u.bulk.status);
  17103. +
  17104. + } else if (msg->u.buffer_from_host.payload_in_message <=
  17105. + MMAL_VC_SHORT_DATA) {
  17106. + /* data payload within message */
  17107. + msg_context->u.bulk.status = inline_receive(instance, msg,
  17108. + msg_context);
  17109. + } else {
  17110. + pr_err("message with invalid short payload\n");
  17111. +
  17112. + /* signal error */
  17113. + msg_context->u.bulk.status = -EINVAL;
  17114. + msg_context->u.bulk.buffer_used =
  17115. + msg->u.buffer_from_host.payload_in_message;
  17116. + }
  17117. +
  17118. + /* replace the buffer header */
  17119. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  17120. +
  17121. + /* schedule the port callback */
  17122. + schedule_work(&msg_context->u.bulk.work);
  17123. +}
  17124. +
  17125. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  17126. + struct mmal_msg_context *msg_context)
  17127. +{
  17128. + /* bulk receive operation complete */
  17129. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  17130. +
  17131. + /* replace the buffer header */
  17132. + port_buffer_from_host(msg_context->u.bulk.instance,
  17133. + msg_context->u.bulk.port);
  17134. +
  17135. + msg_context->u.bulk.status = 0;
  17136. +
  17137. + /* schedule the port callback */
  17138. + schedule_work(&msg_context->u.bulk.work);
  17139. +}
  17140. +
  17141. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  17142. + struct mmal_msg_context *msg_context)
  17143. +{
  17144. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  17145. +
  17146. + /* bulk receive operation complete */
  17147. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  17148. +
  17149. + /* replace the buffer header */
  17150. + port_buffer_from_host(msg_context->u.bulk.instance,
  17151. + msg_context->u.bulk.port);
  17152. +
  17153. + msg_context->u.bulk.status = -EINTR;
  17154. +
  17155. + schedule_work(&msg_context->u.bulk.work);
  17156. +}
  17157. +
  17158. +/* incoming event service callback */
  17159. +static void service_callback(void *param,
  17160. + const VCHI_CALLBACK_REASON_T reason,
  17161. + void *bulk_ctx)
  17162. +{
  17163. + struct vchiq_mmal_instance *instance = param;
  17164. + int status;
  17165. + u32 msg_len;
  17166. + struct mmal_msg *msg;
  17167. + VCHI_HELD_MSG_T msg_handle;
  17168. +
  17169. + if (!instance) {
  17170. + pr_err("Message callback passed NULL instance\n");
  17171. + return;
  17172. + }
  17173. +
  17174. + switch (reason) {
  17175. + case VCHI_CALLBACK_MSG_AVAILABLE:
  17176. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  17177. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  17178. + if (status) {
  17179. + pr_err("Unable to dequeue a message (%d)\n", status);
  17180. + break;
  17181. + }
  17182. +
  17183. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  17184. +
  17185. + /* handling is different for buffer messages */
  17186. + switch (msg->h.type) {
  17187. +
  17188. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  17189. + vchi_held_msg_release(&msg_handle);
  17190. + break;
  17191. +
  17192. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  17193. + event_to_host_cb(instance, msg, msg_len);
  17194. + vchi_held_msg_release(&msg_handle);
  17195. +
  17196. + break;
  17197. +
  17198. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  17199. + buffer_to_host_cb(instance, msg, msg_len);
  17200. + vchi_held_msg_release(&msg_handle);
  17201. + break;
  17202. +
  17203. + default:
  17204. + /* messages dependant on header context to complete */
  17205. +
  17206. + /* todo: the msg.context really ought to be sanity
  17207. + * checked before we just use it, afaict it comes back
  17208. + * and is used raw from the videocore. Perhaps it
  17209. + * should be verified the address lies in the kernel
  17210. + * address space.
  17211. + */
  17212. + if (msg->h.context == NULL) {
  17213. + pr_err("received message context was null!\n");
  17214. + vchi_held_msg_release(&msg_handle);
  17215. + break;
  17216. + }
  17217. +
  17218. + /* fill in context values */
  17219. + msg->h.context->u.sync.msg_handle = msg_handle;
  17220. + msg->h.context->u.sync.msg = msg;
  17221. + msg->h.context->u.sync.msg_len = msg_len;
  17222. +
  17223. + /* todo: should this check (completion_done()
  17224. + * == 1) for no one waiting? or do we need a
  17225. + * flag to tell us the completion has been
  17226. + * interrupted so we can free the message and
  17227. + * its context. This probably also solves the
  17228. + * message arriving after interruption todo
  17229. + * below
  17230. + */
  17231. +
  17232. + /* complete message so caller knows it happened */
  17233. + complete(&msg->h.context->u.sync.cmplt);
  17234. + break;
  17235. + }
  17236. +
  17237. + break;
  17238. +
  17239. + case VCHI_CALLBACK_BULK_RECEIVED:
  17240. + bulk_receive_cb(instance, bulk_ctx);
  17241. + break;
  17242. +
  17243. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  17244. + bulk_abort_cb(instance, bulk_ctx);
  17245. + break;
  17246. +
  17247. + case VCHI_CALLBACK_SERVICE_CLOSED:
  17248. + /* TODO: consider if this requires action if received when
  17249. + * driver is not explicitly closing the service
  17250. + */
  17251. + break;
  17252. +
  17253. + default:
  17254. + pr_err("Received unhandled message reason %d\n", reason);
  17255. + break;
  17256. + }
  17257. +}
  17258. +
  17259. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  17260. + struct mmal_msg *msg,
  17261. + unsigned int payload_len,
  17262. + struct mmal_msg **msg_out,
  17263. + VCHI_HELD_MSG_T *msg_handle_out)
  17264. +{
  17265. + struct mmal_msg_context msg_context;
  17266. + int ret;
  17267. +
  17268. + /* payload size must not cause message to exceed max size */
  17269. + if (payload_len >
  17270. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  17271. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  17272. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  17273. + return -EINVAL;
  17274. + }
  17275. +
  17276. + init_completion(&msg_context.u.sync.cmplt);
  17277. +
  17278. + msg->h.magic = MMAL_MAGIC;
  17279. + msg->h.context = &msg_context;
  17280. + msg->h.status = 0;
  17281. +
  17282. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  17283. + ">>> sync message");
  17284. +
  17285. + vchi_service_use(instance->handle);
  17286. +
  17287. + ret = vchi_msg_queue(instance->handle,
  17288. + msg,
  17289. + sizeof(struct mmal_msg_header) + payload_len,
  17290. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  17291. +
  17292. + vchi_service_release(instance->handle);
  17293. +
  17294. + if (ret) {
  17295. + pr_err("error %d queuing message\n", ret);
  17296. + return ret;
  17297. + }
  17298. +
  17299. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  17300. + if (ret <= 0) {
  17301. + pr_err("error %d waiting for sync completion\n", ret);
  17302. + if (ret == 0)
  17303. + ret = -ETIME;
  17304. + /* todo: what happens if the message arrives after aborting */
  17305. + return ret;
  17306. + }
  17307. +
  17308. + *msg_out = msg_context.u.sync.msg;
  17309. + *msg_handle_out = msg_context.u.sync.msg_handle;
  17310. +
  17311. + return 0;
  17312. +}
  17313. +
  17314. +static void dump_port_info(struct vchiq_mmal_port *port)
  17315. +{
  17316. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  17317. +
  17318. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  17319. + port->minimum_buffer.num,
  17320. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  17321. +
  17322. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  17323. + port->recommended_buffer.num,
  17324. + port->recommended_buffer.size,
  17325. + port->recommended_buffer.alignment);
  17326. +
  17327. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  17328. + port->current_buffer.num,
  17329. + port->current_buffer.size, port->current_buffer.alignment);
  17330. +
  17331. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  17332. + port->format.type,
  17333. + port->format.encoding, port->format.encoding_variant);
  17334. +
  17335. + pr_debug(" bitrate:%d flags:0x%x\n",
  17336. + port->format.bitrate, port->format.flags);
  17337. +
  17338. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  17339. + pr_debug
  17340. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  17341. + port->es.video.width, port->es.video.height,
  17342. + port->es.video.color_space);
  17343. +
  17344. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  17345. + port->es.video.crop.x,
  17346. + port->es.video.crop.y,
  17347. + port->es.video.crop.width, port->es.video.crop.height);
  17348. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  17349. + port->es.video.frame_rate.num,
  17350. + port->es.video.frame_rate.den,
  17351. + port->es.video.par.num, port->es.video.par.den);
  17352. + }
  17353. +}
  17354. +
  17355. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  17356. +{
  17357. +
  17358. + /* todo do readonly fields need setting at all? */
  17359. + p->type = port->type;
  17360. + p->index = port->index;
  17361. + p->index_all = 0;
  17362. + p->is_enabled = port->enabled;
  17363. + p->buffer_num_min = port->minimum_buffer.num;
  17364. + p->buffer_size_min = port->minimum_buffer.size;
  17365. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  17366. + p->buffer_num_recommended = port->recommended_buffer.num;
  17367. + p->buffer_size_recommended = port->recommended_buffer.size;
  17368. +
  17369. + /* only three writable fields in a port */
  17370. + p->buffer_num = port->current_buffer.num;
  17371. + p->buffer_size = port->current_buffer.size;
  17372. + p->userdata = port;
  17373. +}
  17374. +
  17375. +static int port_info_set(struct vchiq_mmal_instance *instance,
  17376. + struct vchiq_mmal_port *port)
  17377. +{
  17378. + int ret;
  17379. + struct mmal_msg m;
  17380. + struct mmal_msg *rmsg;
  17381. + VCHI_HELD_MSG_T rmsg_handle;
  17382. +
  17383. + pr_debug("setting port info port %p\n", port);
  17384. + if (!port)
  17385. + return -1;
  17386. + dump_port_info(port);
  17387. +
  17388. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  17389. +
  17390. + m.u.port_info_set.component_handle = port->component->handle;
  17391. + m.u.port_info_set.port_type = port->type;
  17392. + m.u.port_info_set.port_index = port->index;
  17393. +
  17394. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  17395. +
  17396. + /* elementry stream format setup */
  17397. + m.u.port_info_set.format.type = port->format.type;
  17398. + m.u.port_info_set.format.encoding = port->format.encoding;
  17399. + m.u.port_info_set.format.encoding_variant =
  17400. + port->format.encoding_variant;
  17401. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  17402. + m.u.port_info_set.format.flags = port->format.flags;
  17403. +
  17404. + memcpy(&m.u.port_info_set.es, &port->es,
  17405. + sizeof(union mmal_es_specific_format));
  17406. +
  17407. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  17408. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  17409. + port->format.extradata_size);
  17410. +
  17411. + ret = send_synchronous_mmal_msg(instance, &m,
  17412. + sizeof(m.u.port_info_set),
  17413. + &rmsg, &rmsg_handle);
  17414. + if (ret)
  17415. + return ret;
  17416. +
  17417. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  17418. + /* got an unexpected message type in reply */
  17419. + ret = -EINVAL;
  17420. + goto release_msg;
  17421. + }
  17422. +
  17423. + /* return operation status */
  17424. + ret = -rmsg->u.port_info_get_reply.status;
  17425. +
  17426. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  17427. + port->component->handle, port->handle);
  17428. +
  17429. +release_msg:
  17430. + vchi_held_msg_release(&rmsg_handle);
  17431. +
  17432. + return ret;
  17433. +
  17434. +}
  17435. +
  17436. +/* use port info get message to retrive port information */
  17437. +static int port_info_get(struct vchiq_mmal_instance *instance,
  17438. + struct vchiq_mmal_port *port)
  17439. +{
  17440. + int ret;
  17441. + struct mmal_msg m;
  17442. + struct mmal_msg *rmsg;
  17443. + VCHI_HELD_MSG_T rmsg_handle;
  17444. +
  17445. + /* port info time */
  17446. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  17447. + m.u.port_info_get.component_handle = port->component->handle;
  17448. + m.u.port_info_get.port_type = port->type;
  17449. + m.u.port_info_get.index = port->index;
  17450. +
  17451. + ret = send_synchronous_mmal_msg(instance, &m,
  17452. + sizeof(m.u.port_info_get),
  17453. + &rmsg, &rmsg_handle);
  17454. + if (ret)
  17455. + return ret;
  17456. +
  17457. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  17458. + /* got an unexpected message type in reply */
  17459. + ret = -EINVAL;
  17460. + goto release_msg;
  17461. + }
  17462. +
  17463. + /* return operation status */
  17464. + ret = -rmsg->u.port_info_get_reply.status;
  17465. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  17466. + goto release_msg;
  17467. +
  17468. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  17469. + port->enabled = false;
  17470. + else
  17471. + port->enabled = true;
  17472. +
  17473. + /* copy the values out of the message */
  17474. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  17475. +
  17476. + /* port type and index cached to use on port info set becuase
  17477. + * it does not use a port handle
  17478. + */
  17479. + port->type = rmsg->u.port_info_get_reply.port_type;
  17480. + port->index = rmsg->u.port_info_get_reply.port_index;
  17481. +
  17482. + port->minimum_buffer.num =
  17483. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  17484. + port->minimum_buffer.size =
  17485. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  17486. + port->minimum_buffer.alignment =
  17487. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  17488. +
  17489. + port->recommended_buffer.alignment =
  17490. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  17491. + port->recommended_buffer.num =
  17492. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  17493. +
  17494. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  17495. + port->current_buffer.size =
  17496. + rmsg->u.port_info_get_reply.port.buffer_size;
  17497. +
  17498. + /* stream format */
  17499. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  17500. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  17501. + port->format.encoding_variant =
  17502. + rmsg->u.port_info_get_reply.format.encoding_variant;
  17503. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  17504. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  17505. +
  17506. + /* elementry stream format */
  17507. + memcpy(&port->es,
  17508. + &rmsg->u.port_info_get_reply.es,
  17509. + sizeof(union mmal_es_specific_format));
  17510. + port->format.es = &port->es;
  17511. +
  17512. + port->format.extradata_size =
  17513. + rmsg->u.port_info_get_reply.format.extradata_size;
  17514. + memcpy(port->format.extradata,
  17515. + rmsg->u.port_info_get_reply.extradata,
  17516. + port->format.extradata_size);
  17517. +
  17518. + pr_debug("received port info\n");
  17519. + dump_port_info(port);
  17520. +
  17521. +release_msg:
  17522. +
  17523. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  17524. + __func__, ret, port->component->handle, port->handle);
  17525. +
  17526. + vchi_held_msg_release(&rmsg_handle);
  17527. +
  17528. + return ret;
  17529. +}
  17530. +
  17531. +/* create comonent on vc */
  17532. +static int create_component(struct vchiq_mmal_instance *instance,
  17533. + struct vchiq_mmal_component *component,
  17534. + const char *name)
  17535. +{
  17536. + int ret;
  17537. + struct mmal_msg m;
  17538. + struct mmal_msg *rmsg;
  17539. + VCHI_HELD_MSG_T rmsg_handle;
  17540. +
  17541. + /* build component create message */
  17542. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  17543. + m.u.component_create.client_component = component;
  17544. + strncpy(m.u.component_create.name, name,
  17545. + sizeof(m.u.component_create.name));
  17546. +
  17547. + ret = send_synchronous_mmal_msg(instance, &m,
  17548. + sizeof(m.u.component_create),
  17549. + &rmsg, &rmsg_handle);
  17550. + if (ret)
  17551. + return ret;
  17552. +
  17553. + if (rmsg->h.type != m.h.type) {
  17554. + /* got an unexpected message type in reply */
  17555. + ret = -EINVAL;
  17556. + goto release_msg;
  17557. + }
  17558. +
  17559. + ret = -rmsg->u.component_create_reply.status;
  17560. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  17561. + goto release_msg;
  17562. +
  17563. + /* a valid component response received */
  17564. + component->handle = rmsg->u.component_create_reply.component_handle;
  17565. + component->inputs = rmsg->u.component_create_reply.input_num;
  17566. + component->outputs = rmsg->u.component_create_reply.output_num;
  17567. + component->clocks = rmsg->u.component_create_reply.clock_num;
  17568. +
  17569. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  17570. + component->handle,
  17571. + component->inputs, component->outputs, component->clocks);
  17572. +
  17573. +release_msg:
  17574. + vchi_held_msg_release(&rmsg_handle);
  17575. +
  17576. + return ret;
  17577. +}
  17578. +
  17579. +/* destroys a component on vc */
  17580. +static int destroy_component(struct vchiq_mmal_instance *instance,
  17581. + struct vchiq_mmal_component *component)
  17582. +{
  17583. + int ret;
  17584. + struct mmal_msg m;
  17585. + struct mmal_msg *rmsg;
  17586. + VCHI_HELD_MSG_T rmsg_handle;
  17587. +
  17588. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  17589. + m.u.component_destroy.component_handle = component->handle;
  17590. +
  17591. + ret = send_synchronous_mmal_msg(instance, &m,
  17592. + sizeof(m.u.component_destroy),
  17593. + &rmsg, &rmsg_handle);
  17594. + if (ret)
  17595. + return ret;
  17596. +
  17597. + if (rmsg->h.type != m.h.type) {
  17598. + /* got an unexpected message type in reply */
  17599. + ret = -EINVAL;
  17600. + goto release_msg;
  17601. + }
  17602. +
  17603. + ret = -rmsg->u.component_destroy_reply.status;
  17604. +
  17605. +release_msg:
  17606. +
  17607. + vchi_held_msg_release(&rmsg_handle);
  17608. +
  17609. + return ret;
  17610. +}
  17611. +
  17612. +/* enable a component on vc */
  17613. +static int enable_component(struct vchiq_mmal_instance *instance,
  17614. + struct vchiq_mmal_component *component)
  17615. +{
  17616. + int ret;
  17617. + struct mmal_msg m;
  17618. + struct mmal_msg *rmsg;
  17619. + VCHI_HELD_MSG_T rmsg_handle;
  17620. +
  17621. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  17622. + m.u.component_enable.component_handle = component->handle;
  17623. +
  17624. + ret = send_synchronous_mmal_msg(instance, &m,
  17625. + sizeof(m.u.component_enable),
  17626. + &rmsg, &rmsg_handle);
  17627. + if (ret)
  17628. + return ret;
  17629. +
  17630. + if (rmsg->h.type != m.h.type) {
  17631. + /* got an unexpected message type in reply */
  17632. + ret = -EINVAL;
  17633. + goto release_msg;
  17634. + }
  17635. +
  17636. + ret = -rmsg->u.component_enable_reply.status;
  17637. +
  17638. +release_msg:
  17639. + vchi_held_msg_release(&rmsg_handle);
  17640. +
  17641. + return ret;
  17642. +}
  17643. +
  17644. +/* disable a component on vc */
  17645. +static int disable_component(struct vchiq_mmal_instance *instance,
  17646. + struct vchiq_mmal_component *component)
  17647. +{
  17648. + int ret;
  17649. + struct mmal_msg m;
  17650. + struct mmal_msg *rmsg;
  17651. + VCHI_HELD_MSG_T rmsg_handle;
  17652. +
  17653. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  17654. + m.u.component_disable.component_handle = component->handle;
  17655. +
  17656. + ret = send_synchronous_mmal_msg(instance, &m,
  17657. + sizeof(m.u.component_disable),
  17658. + &rmsg, &rmsg_handle);
  17659. + if (ret)
  17660. + return ret;
  17661. +
  17662. + if (rmsg->h.type != m.h.type) {
  17663. + /* got an unexpected message type in reply */
  17664. + ret = -EINVAL;
  17665. + goto release_msg;
  17666. + }
  17667. +
  17668. + ret = -rmsg->u.component_disable_reply.status;
  17669. +
  17670. +release_msg:
  17671. +
  17672. + vchi_held_msg_release(&rmsg_handle);
  17673. +
  17674. + return ret;
  17675. +}
  17676. +
  17677. +/* get version of mmal implementation */
  17678. +static int get_version(struct vchiq_mmal_instance *instance,
  17679. + u32 *major_out, u32 *minor_out)
  17680. +{
  17681. + int ret;
  17682. + struct mmal_msg m;
  17683. + struct mmal_msg *rmsg;
  17684. + VCHI_HELD_MSG_T rmsg_handle;
  17685. +
  17686. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  17687. +
  17688. + ret = send_synchronous_mmal_msg(instance, &m,
  17689. + sizeof(m.u.version),
  17690. + &rmsg, &rmsg_handle);
  17691. + if (ret)
  17692. + return ret;
  17693. +
  17694. + if (rmsg->h.type != m.h.type) {
  17695. + /* got an unexpected message type in reply */
  17696. + ret = -EINVAL;
  17697. + goto release_msg;
  17698. + }
  17699. +
  17700. + *major_out = rmsg->u.version.major;
  17701. + *minor_out = rmsg->u.version.minor;
  17702. +
  17703. +release_msg:
  17704. + vchi_held_msg_release(&rmsg_handle);
  17705. +
  17706. + return ret;
  17707. +}
  17708. +
  17709. +/* do a port action with a port as a parameter */
  17710. +static int port_action_port(struct vchiq_mmal_instance *instance,
  17711. + struct vchiq_mmal_port *port,
  17712. + enum mmal_msg_port_action_type action_type)
  17713. +{
  17714. + int ret;
  17715. + struct mmal_msg m;
  17716. + struct mmal_msg *rmsg;
  17717. + VCHI_HELD_MSG_T rmsg_handle;
  17718. +
  17719. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17720. + m.u.port_action_port.component_handle = port->component->handle;
  17721. + m.u.port_action_port.port_handle = port->handle;
  17722. + m.u.port_action_port.action = action_type;
  17723. +
  17724. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  17725. +
  17726. + ret = send_synchronous_mmal_msg(instance, &m,
  17727. + sizeof(m.u.port_action_port),
  17728. + &rmsg, &rmsg_handle);
  17729. + if (ret)
  17730. + return ret;
  17731. +
  17732. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17733. + /* got an unexpected message type in reply */
  17734. + ret = -EINVAL;
  17735. + goto release_msg;
  17736. + }
  17737. +
  17738. + ret = -rmsg->u.port_action_reply.status;
  17739. +
  17740. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  17741. + __func__,
  17742. + ret, port->component->handle, port->handle,
  17743. + port_action_type_names[action_type], action_type);
  17744. +
  17745. +release_msg:
  17746. + vchi_held_msg_release(&rmsg_handle);
  17747. +
  17748. + return ret;
  17749. +}
  17750. +
  17751. +/* do a port action with handles as parameters */
  17752. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  17753. + struct vchiq_mmal_port *port,
  17754. + enum mmal_msg_port_action_type action_type,
  17755. + u32 connect_component_handle,
  17756. + u32 connect_port_handle)
  17757. +{
  17758. + int ret;
  17759. + struct mmal_msg m;
  17760. + struct mmal_msg *rmsg;
  17761. + VCHI_HELD_MSG_T rmsg_handle;
  17762. +
  17763. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17764. +
  17765. + m.u.port_action_handle.component_handle = port->component->handle;
  17766. + m.u.port_action_handle.port_handle = port->handle;
  17767. + m.u.port_action_handle.action = action_type;
  17768. +
  17769. + m.u.port_action_handle.connect_component_handle =
  17770. + connect_component_handle;
  17771. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  17772. +
  17773. + ret = send_synchronous_mmal_msg(instance, &m,
  17774. + sizeof(m.u.port_action_handle),
  17775. + &rmsg, &rmsg_handle);
  17776. + if (ret)
  17777. + return ret;
  17778. +
  17779. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17780. + /* got an unexpected message type in reply */
  17781. + ret = -EINVAL;
  17782. + goto release_msg;
  17783. + }
  17784. +
  17785. + ret = -rmsg->u.port_action_reply.status;
  17786. +
  17787. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  17788. + " connect component:0x%x connect port:%d\n",
  17789. + __func__,
  17790. + ret, port->component->handle, port->handle,
  17791. + port_action_type_names[action_type],
  17792. + action_type, connect_component_handle, connect_port_handle);
  17793. +
  17794. +release_msg:
  17795. + vchi_held_msg_release(&rmsg_handle);
  17796. +
  17797. + return ret;
  17798. +}
  17799. +
  17800. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  17801. + struct vchiq_mmal_port *port,
  17802. + u32 parameter_id, void *value, u32 value_size)
  17803. +{
  17804. + int ret;
  17805. + struct mmal_msg m;
  17806. + struct mmal_msg *rmsg;
  17807. + VCHI_HELD_MSG_T rmsg_handle;
  17808. +
  17809. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  17810. +
  17811. + m.u.port_parameter_set.component_handle = port->component->handle;
  17812. + m.u.port_parameter_set.port_handle = port->handle;
  17813. + m.u.port_parameter_set.id = parameter_id;
  17814. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  17815. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  17816. +
  17817. + ret = send_synchronous_mmal_msg(instance, &m,
  17818. + (4 * sizeof(u32)) + value_size,
  17819. + &rmsg, &rmsg_handle);
  17820. + if (ret)
  17821. + return ret;
  17822. +
  17823. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  17824. + /* got an unexpected message type in reply */
  17825. + ret = -EINVAL;
  17826. + goto release_msg;
  17827. + }
  17828. +
  17829. + ret = -rmsg->u.port_parameter_set_reply.status;
  17830. +
  17831. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  17832. + __func__,
  17833. + ret, port->component->handle, port->handle, parameter_id);
  17834. +
  17835. +release_msg:
  17836. + vchi_held_msg_release(&rmsg_handle);
  17837. +
  17838. + return ret;
  17839. +}
  17840. +
  17841. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  17842. + struct vchiq_mmal_port *port,
  17843. + u32 parameter_id, void *value, u32 *value_size)
  17844. +{
  17845. + int ret;
  17846. + struct mmal_msg m;
  17847. + struct mmal_msg *rmsg;
  17848. + VCHI_HELD_MSG_T rmsg_handle;
  17849. +
  17850. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  17851. +
  17852. + m.u.port_parameter_get.component_handle = port->component->handle;
  17853. + m.u.port_parameter_get.port_handle = port->handle;
  17854. + m.u.port_parameter_get.id = parameter_id;
  17855. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  17856. +
  17857. + ret = send_synchronous_mmal_msg(instance, &m,
  17858. + sizeof(struct
  17859. + mmal_msg_port_parameter_get),
  17860. + &rmsg, &rmsg_handle);
  17861. + if (ret)
  17862. + return ret;
  17863. +
  17864. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  17865. + /* got an unexpected message type in reply */
  17866. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  17867. + ret = -EINVAL;
  17868. + goto release_msg;
  17869. + }
  17870. +
  17871. + ret = -rmsg->u.port_parameter_get_reply.status;
  17872. + if (ret) {
  17873. + /* Copy only as much as we have space for
  17874. + * but report true size of parameter
  17875. + */
  17876. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17877. + *value_size);
  17878. + *value_size = rmsg->u.port_parameter_get_reply.size;
  17879. + } else
  17880. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17881. + rmsg->u.port_parameter_get_reply.size);
  17882. +
  17883. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  17884. + ret, port->component->handle, port->handle, parameter_id);
  17885. +
  17886. +release_msg:
  17887. + vchi_held_msg_release(&rmsg_handle);
  17888. +
  17889. + return ret;
  17890. +}
  17891. +
  17892. +/* disables a port and drains buffers from it */
  17893. +static int port_disable(struct vchiq_mmal_instance *instance,
  17894. + struct vchiq_mmal_port *port)
  17895. +{
  17896. + int ret;
  17897. + struct list_head *q, *buf_head;
  17898. + unsigned long flags = 0;
  17899. +
  17900. + if (!port->enabled)
  17901. + return 0;
  17902. +
  17903. + port->enabled = false;
  17904. +
  17905. + ret = port_action_port(instance, port,
  17906. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  17907. + if (ret == 0) {
  17908. +
  17909. + /* drain all queued buffers on port */
  17910. + spin_lock_irqsave(&port->slock, flags);
  17911. +
  17912. + list_for_each_safe(buf_head, q, &port->buffers) {
  17913. + struct mmal_buffer *mmalbuf;
  17914. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17915. + list);
  17916. + list_del(buf_head);
  17917. + if (port->buffer_cb)
  17918. + port->buffer_cb(instance,
  17919. + port, 0, mmalbuf, 0, 0,
  17920. + MMAL_TIME_UNKNOWN,
  17921. + MMAL_TIME_UNKNOWN);
  17922. + }
  17923. +
  17924. + spin_unlock_irqrestore(&port->slock, flags);
  17925. +
  17926. + ret = port_info_get(instance, port);
  17927. + }
  17928. +
  17929. + return ret;
  17930. +}
  17931. +
  17932. +/* enable a port */
  17933. +static int port_enable(struct vchiq_mmal_instance *instance,
  17934. + struct vchiq_mmal_port *port)
  17935. +{
  17936. + unsigned int hdr_count;
  17937. + struct list_head *buf_head;
  17938. + int ret;
  17939. +
  17940. + if (port->enabled)
  17941. + return 0;
  17942. +
  17943. + /* ensure there are enough buffers queued to cover the buffer headers */
  17944. + if (port->buffer_cb != NULL) {
  17945. + hdr_count = 0;
  17946. + list_for_each(buf_head, &port->buffers) {
  17947. + hdr_count++;
  17948. + }
  17949. + if (hdr_count < port->current_buffer.num)
  17950. + return -ENOSPC;
  17951. + }
  17952. +
  17953. + ret = port_action_port(instance, port,
  17954. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  17955. + if (ret)
  17956. + goto done;
  17957. +
  17958. + port->enabled = true;
  17959. +
  17960. + if (port->buffer_cb) {
  17961. + /* send buffer headers to videocore */
  17962. + hdr_count = 1;
  17963. + list_for_each(buf_head, &port->buffers) {
  17964. + struct mmal_buffer *mmalbuf;
  17965. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17966. + list);
  17967. + ret = buffer_from_host(instance, port, mmalbuf);
  17968. + if (ret)
  17969. + goto done;
  17970. +
  17971. + hdr_count++;
  17972. + if (hdr_count > port->current_buffer.num)
  17973. + break;
  17974. + }
  17975. + }
  17976. +
  17977. + ret = port_info_get(instance, port);
  17978. +
  17979. +done:
  17980. + return ret;
  17981. +}
  17982. +
  17983. +/* ------------------------------------------------------------------
  17984. + * Exported API
  17985. + *------------------------------------------------------------------*/
  17986. +
  17987. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  17988. + struct vchiq_mmal_port *port)
  17989. +{
  17990. + int ret;
  17991. +
  17992. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17993. + return -EINTR;
  17994. +
  17995. + ret = port_info_set(instance, port);
  17996. + if (ret)
  17997. + goto release_unlock;
  17998. +
  17999. + /* read what has actually been set */
  18000. + ret = port_info_get(instance, port);
  18001. +
  18002. +release_unlock:
  18003. + mutex_unlock(&instance->vchiq_mutex);
  18004. +
  18005. + return ret;
  18006. +
  18007. +}
  18008. +
  18009. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  18010. + struct vchiq_mmal_port *port,
  18011. + u32 parameter, void *value, u32 value_size)
  18012. +{
  18013. + int ret;
  18014. +
  18015. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18016. + return -EINTR;
  18017. +
  18018. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  18019. +
  18020. + mutex_unlock(&instance->vchiq_mutex);
  18021. +
  18022. + return ret;
  18023. +}
  18024. +
  18025. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  18026. + struct vchiq_mmal_port *port,
  18027. + u32 parameter, void *value, u32 *value_size)
  18028. +{
  18029. + int ret;
  18030. +
  18031. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18032. + return -EINTR;
  18033. +
  18034. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  18035. +
  18036. + mutex_unlock(&instance->vchiq_mutex);
  18037. +
  18038. + return ret;
  18039. +}
  18040. +
  18041. +/* enable a port
  18042. + *
  18043. + * enables a port and queues buffers for satisfying callbacks if we
  18044. + * provide a callback handler
  18045. + */
  18046. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  18047. + struct vchiq_mmal_port *port,
  18048. + vchiq_mmal_buffer_cb buffer_cb)
  18049. +{
  18050. + int ret;
  18051. +
  18052. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18053. + return -EINTR;
  18054. +
  18055. + /* already enabled - noop */
  18056. + if (port->enabled) {
  18057. + ret = 0;
  18058. + goto unlock;
  18059. + }
  18060. +
  18061. + port->buffer_cb = buffer_cb;
  18062. +
  18063. + ret = port_enable(instance, port);
  18064. +
  18065. +unlock:
  18066. + mutex_unlock(&instance->vchiq_mutex);
  18067. +
  18068. + return ret;
  18069. +}
  18070. +
  18071. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  18072. + struct vchiq_mmal_port *port)
  18073. +{
  18074. + int ret;
  18075. +
  18076. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18077. + return -EINTR;
  18078. +
  18079. + if (!port->enabled) {
  18080. + mutex_unlock(&instance->vchiq_mutex);
  18081. + return 0;
  18082. + }
  18083. +
  18084. + ret = port_disable(instance, port);
  18085. +
  18086. + mutex_unlock(&instance->vchiq_mutex);
  18087. +
  18088. + return ret;
  18089. +}
  18090. +
  18091. +/* ports will be connected in a tunneled manner so data buffers
  18092. + * are not handled by client.
  18093. + */
  18094. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  18095. + struct vchiq_mmal_port *src,
  18096. + struct vchiq_mmal_port *dst)
  18097. +{
  18098. + int ret;
  18099. +
  18100. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18101. + return -EINTR;
  18102. +
  18103. + /* disconnect ports if connected */
  18104. + if (src->connected != NULL) {
  18105. + ret = port_disable(instance, src);
  18106. + if (ret) {
  18107. + pr_err("failed disabling src port(%d)\n", ret);
  18108. + goto release_unlock;
  18109. + }
  18110. +
  18111. + /* do not need to disable the destination port as they
  18112. + * are connected and it is done automatically
  18113. + */
  18114. +
  18115. + ret = port_action_handle(instance, src,
  18116. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  18117. + src->connected->component->handle,
  18118. + src->connected->handle);
  18119. + if (ret < 0) {
  18120. + pr_err("failed disconnecting src port\n");
  18121. + goto release_unlock;
  18122. + }
  18123. + src->connected->enabled = false;
  18124. + src->connected = NULL;
  18125. + }
  18126. +
  18127. + if (dst == NULL) {
  18128. + /* do not make new connection */
  18129. + ret = 0;
  18130. + pr_debug("not making new connection\n");
  18131. + goto release_unlock;
  18132. + }
  18133. +
  18134. + /* copy src port format to dst */
  18135. + dst->format.encoding = src->format.encoding;
  18136. + dst->es.video.width = src->es.video.width;
  18137. + dst->es.video.height = src->es.video.height;
  18138. + dst->es.video.crop.x = src->es.video.crop.x;
  18139. + dst->es.video.crop.y = src->es.video.crop.y;
  18140. + dst->es.video.crop.width = src->es.video.crop.width;
  18141. + dst->es.video.crop.height = src->es.video.crop.height;
  18142. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  18143. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  18144. +
  18145. + /* set new format */
  18146. + ret = port_info_set(instance, dst);
  18147. + if (ret) {
  18148. + pr_debug("setting port info failed\n");
  18149. + goto release_unlock;
  18150. + }
  18151. +
  18152. + /* read what has actually been set */
  18153. + ret = port_info_get(instance, dst);
  18154. + if (ret) {
  18155. + pr_debug("read back port info failed\n");
  18156. + goto release_unlock;
  18157. + }
  18158. +
  18159. + /* connect two ports together */
  18160. + ret = port_action_handle(instance, src,
  18161. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  18162. + dst->component->handle, dst->handle);
  18163. + if (ret < 0) {
  18164. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  18165. + src->component->handle, src->handle,
  18166. + dst->component->handle, dst->handle);
  18167. + goto release_unlock;
  18168. + }
  18169. + src->connected = dst;
  18170. +
  18171. +release_unlock:
  18172. +
  18173. + mutex_unlock(&instance->vchiq_mutex);
  18174. +
  18175. + return ret;
  18176. +}
  18177. +
  18178. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  18179. + struct vchiq_mmal_port *port,
  18180. + struct mmal_buffer *buffer)
  18181. +{
  18182. + unsigned long flags = 0;
  18183. +
  18184. + spin_lock_irqsave(&port->slock, flags);
  18185. + list_add_tail(&buffer->list, &port->buffers);
  18186. + spin_unlock_irqrestore(&port->slock, flags);
  18187. +
  18188. + /* the port previously underflowed because it was missing a
  18189. + * mmal_buffer which has just been added, submit that buffer
  18190. + * to the mmal service.
  18191. + */
  18192. + if (port->buffer_underflow) {
  18193. + port_buffer_from_host(instance, port);
  18194. + port->buffer_underflow--;
  18195. + }
  18196. +
  18197. + return 0;
  18198. +}
  18199. +
  18200. +/* Initialise a mmal component and its ports
  18201. + *
  18202. + */
  18203. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  18204. + const char *name,
  18205. + struct vchiq_mmal_component **component_out)
  18206. +{
  18207. + int ret;
  18208. + int idx; /* port index */
  18209. + struct vchiq_mmal_component *component;
  18210. +
  18211. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18212. + return -EINTR;
  18213. +
  18214. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  18215. + ret = -EINVAL; /* todo is this correct error? */
  18216. + goto unlock;
  18217. + }
  18218. +
  18219. + component = &instance->component[instance->component_idx];
  18220. +
  18221. + ret = create_component(instance, component, name);
  18222. + if (ret < 0)
  18223. + goto unlock;
  18224. +
  18225. + /* ports info needs gathering */
  18226. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  18227. + component->control.index = 0;
  18228. + component->control.component = component;
  18229. + spin_lock_init(&component->control.slock);
  18230. + INIT_LIST_HEAD(&component->control.buffers);
  18231. + ret = port_info_get(instance, &component->control);
  18232. + if (ret < 0)
  18233. + goto release_component;
  18234. +
  18235. + for (idx = 0; idx < component->inputs; idx++) {
  18236. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  18237. + component->input[idx].index = idx;
  18238. + component->input[idx].component = component;
  18239. + spin_lock_init(&component->input[idx].slock);
  18240. + INIT_LIST_HEAD(&component->input[idx].buffers);
  18241. + ret = port_info_get(instance, &component->input[idx]);
  18242. + if (ret < 0)
  18243. + goto release_component;
  18244. + }
  18245. +
  18246. + for (idx = 0; idx < component->outputs; idx++) {
  18247. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  18248. + component->output[idx].index = idx;
  18249. + component->output[idx].component = component;
  18250. + spin_lock_init(&component->output[idx].slock);
  18251. + INIT_LIST_HEAD(&component->output[idx].buffers);
  18252. + ret = port_info_get(instance, &component->output[idx]);
  18253. + if (ret < 0)
  18254. + goto release_component;
  18255. + }
  18256. +
  18257. + for (idx = 0; idx < component->clocks; idx++) {
  18258. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  18259. + component->clock[idx].index = idx;
  18260. + component->clock[idx].component = component;
  18261. + spin_lock_init(&component->clock[idx].slock);
  18262. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  18263. + ret = port_info_get(instance, &component->clock[idx]);
  18264. + if (ret < 0)
  18265. + goto release_component;
  18266. + }
  18267. +
  18268. + instance->component_idx++;
  18269. +
  18270. + *component_out = component;
  18271. +
  18272. + mutex_unlock(&instance->vchiq_mutex);
  18273. +
  18274. + return 0;
  18275. +
  18276. +release_component:
  18277. + destroy_component(instance, component);
  18278. +unlock:
  18279. + mutex_unlock(&instance->vchiq_mutex);
  18280. +
  18281. + return ret;
  18282. +}
  18283. +
  18284. +/*
  18285. + * cause a mmal component to be destroyed
  18286. + */
  18287. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  18288. + struct vchiq_mmal_component *component)
  18289. +{
  18290. + int ret;
  18291. +
  18292. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18293. + return -EINTR;
  18294. +
  18295. + if (component->enabled)
  18296. + ret = disable_component(instance, component);
  18297. +
  18298. + ret = destroy_component(instance, component);
  18299. +
  18300. + mutex_unlock(&instance->vchiq_mutex);
  18301. +
  18302. + return ret;
  18303. +}
  18304. +
  18305. +/*
  18306. + * cause a mmal component to be enabled
  18307. + */
  18308. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  18309. + struct vchiq_mmal_component *component)
  18310. +{
  18311. + int ret;
  18312. +
  18313. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18314. + return -EINTR;
  18315. +
  18316. + if (component->enabled) {
  18317. + mutex_unlock(&instance->vchiq_mutex);
  18318. + return 0;
  18319. + }
  18320. +
  18321. + ret = enable_component(instance, component);
  18322. + if (ret == 0)
  18323. + component->enabled = true;
  18324. +
  18325. + mutex_unlock(&instance->vchiq_mutex);
  18326. +
  18327. + return ret;
  18328. +}
  18329. +
  18330. +/*
  18331. + * cause a mmal component to be enabled
  18332. + */
  18333. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  18334. + struct vchiq_mmal_component *component)
  18335. +{
  18336. + int ret;
  18337. +
  18338. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18339. + return -EINTR;
  18340. +
  18341. + if (!component->enabled) {
  18342. + mutex_unlock(&instance->vchiq_mutex);
  18343. + return 0;
  18344. + }
  18345. +
  18346. + ret = disable_component(instance, component);
  18347. + if (ret == 0)
  18348. + component->enabled = false;
  18349. +
  18350. + mutex_unlock(&instance->vchiq_mutex);
  18351. +
  18352. + return ret;
  18353. +}
  18354. +
  18355. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  18356. + u32 *major_out, u32 *minor_out)
  18357. +{
  18358. + int ret;
  18359. +
  18360. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18361. + return -EINTR;
  18362. +
  18363. + ret = get_version(instance, major_out, minor_out);
  18364. +
  18365. + mutex_unlock(&instance->vchiq_mutex);
  18366. +
  18367. + return ret;
  18368. +}
  18369. +
  18370. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  18371. +{
  18372. + int status = 0;
  18373. +
  18374. + if (instance == NULL)
  18375. + return -EINVAL;
  18376. +
  18377. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18378. + return -EINTR;
  18379. +
  18380. + vchi_service_use(instance->handle);
  18381. +
  18382. + status = vchi_service_close(instance->handle);
  18383. + if (status != 0)
  18384. + pr_err("mmal-vchiq: VCHIQ close failed");
  18385. +
  18386. + mutex_unlock(&instance->vchiq_mutex);
  18387. +
  18388. + vfree(instance->bulk_scratch);
  18389. +
  18390. + kfree(instance);
  18391. +
  18392. + return status;
  18393. +}
  18394. +
  18395. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  18396. +{
  18397. + int status;
  18398. + struct vchiq_mmal_instance *instance;
  18399. + static VCHI_CONNECTION_T *vchi_connection;
  18400. + static VCHI_INSTANCE_T vchi_instance;
  18401. + SERVICE_CREATION_T params = {
  18402. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  18403. + VC_MMAL_SERVER_NAME,
  18404. + vchi_connection,
  18405. + 0, /* rx fifo size (unused) */
  18406. + 0, /* tx fifo size (unused) */
  18407. + service_callback,
  18408. + NULL, /* service callback parameter */
  18409. + 1, /* unaligned bulk receives */
  18410. + 1, /* unaligned bulk transmits */
  18411. + 0 /* want crc check on bulk transfers */
  18412. + };
  18413. +
  18414. + /* compile time checks to ensure structure size as they are
  18415. + * directly (de)serialised from memory.
  18416. + */
  18417. +
  18418. + /* ensure the header structure has packed to the correct size */
  18419. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  18420. +
  18421. + /* ensure message structure does not exceed maximum length */
  18422. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  18423. +
  18424. + /* mmal port struct is correct size */
  18425. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  18426. +
  18427. + /* create a vchi instance */
  18428. + status = vchi_initialise(&vchi_instance);
  18429. + if (status) {
  18430. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  18431. + status);
  18432. + return -EIO;
  18433. + }
  18434. +
  18435. + status = vchi_connect(NULL, 0, vchi_instance);
  18436. + if (status) {
  18437. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  18438. + return -EIO;
  18439. + }
  18440. +
  18441. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  18442. + memset(instance, 0, sizeof(*instance));
  18443. +
  18444. + mutex_init(&instance->vchiq_mutex);
  18445. + mutex_init(&instance->bulk_mutex);
  18446. +
  18447. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  18448. +
  18449. + params.callback_param = instance;
  18450. +
  18451. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  18452. + if (status) {
  18453. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  18454. + status);
  18455. + goto err_close_services;
  18456. + }
  18457. +
  18458. + vchi_service_release(instance->handle);
  18459. +
  18460. + *out_instance = instance;
  18461. +
  18462. + return 0;
  18463. +
  18464. +err_close_services:
  18465. +
  18466. + vchi_service_close(instance->handle);
  18467. + vfree(instance->bulk_scratch);
  18468. + kfree(instance);
  18469. + return -ENODEV;
  18470. +}
  18471. diff -Nur linux-3.10.33/drivers/media/platform/bcm2835/mmal-vchiq.h linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-vchiq.h
  18472. --- linux-3.10.33/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  18473. +++ linux-raspberry-pi/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-03-13 12:46:18.260055389 +0100
  18474. @@ -0,0 +1,178 @@
  18475. +/*
  18476. + * Broadcom BM2835 V4L2 driver
  18477. + *
  18478. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  18479. + *
  18480. + * This file is subject to the terms and conditions of the GNU General Public
  18481. + * License. See the file COPYING in the main directory of this archive
  18482. + * for more details.
  18483. + *
  18484. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  18485. + * Dave Stevenson <dsteve@broadcom.com>
  18486. + * Simon Mellor <simellor@broadcom.com>
  18487. + * Luke Diamand <luked@broadcom.com>
  18488. + *
  18489. + * MMAL interface to VCHIQ message passing
  18490. + */
  18491. +
  18492. +#ifndef MMAL_VCHIQ_H
  18493. +#define MMAL_VCHIQ_H
  18494. +
  18495. +#include "mmal-msg-format.h"
  18496. +
  18497. +#define MAX_PORT_COUNT 4
  18498. +
  18499. +/* Maximum size of the format extradata. */
  18500. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  18501. +
  18502. +struct vchiq_mmal_instance;
  18503. +
  18504. +enum vchiq_mmal_es_type {
  18505. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  18506. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  18507. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  18508. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  18509. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  18510. +};
  18511. +
  18512. +/* rectangle, used lots so it gets its own struct */
  18513. +struct vchiq_mmal_rect {
  18514. + s32 x;
  18515. + s32 y;
  18516. + s32 width;
  18517. + s32 height;
  18518. +};
  18519. +
  18520. +struct vchiq_mmal_port_buffer {
  18521. + unsigned int num; /* number of buffers */
  18522. + u32 size; /* size of buffers */
  18523. + u32 alignment; /* alignment of buffers */
  18524. +};
  18525. +
  18526. +struct vchiq_mmal_port;
  18527. +
  18528. +typedef void (*vchiq_mmal_buffer_cb)(
  18529. + struct vchiq_mmal_instance *instance,
  18530. + struct vchiq_mmal_port *port,
  18531. + int status, struct mmal_buffer *buffer,
  18532. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  18533. +
  18534. +struct vchiq_mmal_port {
  18535. + bool enabled;
  18536. + u32 handle;
  18537. + u32 type; /* port type, cached to use on port info set */
  18538. + u32 index; /* port index, cached to use on port info set */
  18539. +
  18540. + /* component port belongs to, allows simple deref */
  18541. + struct vchiq_mmal_component *component;
  18542. +
  18543. + struct vchiq_mmal_port *connected; /* port conencted to */
  18544. +
  18545. + /* buffer info */
  18546. + struct vchiq_mmal_port_buffer minimum_buffer;
  18547. + struct vchiq_mmal_port_buffer recommended_buffer;
  18548. + struct vchiq_mmal_port_buffer current_buffer;
  18549. +
  18550. + /* stream format */
  18551. + struct mmal_es_format format;
  18552. + /* elementry stream format */
  18553. + union mmal_es_specific_format es;
  18554. +
  18555. + /* data buffers to fill */
  18556. + struct list_head buffers;
  18557. + /* lock to serialise adding and removing buffers from list */
  18558. + spinlock_t slock;
  18559. + /* count of how many buffer header refils have failed because
  18560. + * there was no buffer to satisfy them
  18561. + */
  18562. + int buffer_underflow;
  18563. + /* callback on buffer completion */
  18564. + vchiq_mmal_buffer_cb buffer_cb;
  18565. + /* callback context */
  18566. + void *cb_ctx;
  18567. +};
  18568. +
  18569. +struct vchiq_mmal_component {
  18570. + bool enabled;
  18571. + u32 handle; /* VideoCore handle for component */
  18572. + u32 inputs; /* Number of input ports */
  18573. + u32 outputs; /* Number of output ports */
  18574. + u32 clocks; /* Number of clock ports */
  18575. + struct vchiq_mmal_port control; /* control port */
  18576. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  18577. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  18578. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  18579. +};
  18580. +
  18581. +
  18582. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  18583. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  18584. +
  18585. +/* Initialise a mmal component and its ports
  18586. +*
  18587. +*/
  18588. +int vchiq_mmal_component_init(
  18589. + struct vchiq_mmal_instance *instance,
  18590. + const char *name,
  18591. + struct vchiq_mmal_component **component_out);
  18592. +
  18593. +int vchiq_mmal_component_finalise(
  18594. + struct vchiq_mmal_instance *instance,
  18595. + struct vchiq_mmal_component *component);
  18596. +
  18597. +int vchiq_mmal_component_enable(
  18598. + struct vchiq_mmal_instance *instance,
  18599. + struct vchiq_mmal_component *component);
  18600. +
  18601. +int vchiq_mmal_component_disable(
  18602. + struct vchiq_mmal_instance *instance,
  18603. + struct vchiq_mmal_component *component);
  18604. +
  18605. +
  18606. +
  18607. +/* enable a mmal port
  18608. + *
  18609. + * enables a port and if a buffer callback provided enque buffer
  18610. + * headers as apropriate for the port.
  18611. + */
  18612. +int vchiq_mmal_port_enable(
  18613. + struct vchiq_mmal_instance *instance,
  18614. + struct vchiq_mmal_port *port,
  18615. + vchiq_mmal_buffer_cb buffer_cb);
  18616. +
  18617. +/* disable a port
  18618. + *
  18619. + * disable a port will dequeue any pending buffers
  18620. + */
  18621. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  18622. + struct vchiq_mmal_port *port);
  18623. +
  18624. +
  18625. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  18626. + struct vchiq_mmal_port *port,
  18627. + u32 parameter,
  18628. + void *value,
  18629. + u32 value_size);
  18630. +
  18631. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  18632. + struct vchiq_mmal_port *port,
  18633. + u32 parameter,
  18634. + void *value,
  18635. + u32 *value_size);
  18636. +
  18637. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  18638. + struct vchiq_mmal_port *port);
  18639. +
  18640. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  18641. + struct vchiq_mmal_port *src,
  18642. + struct vchiq_mmal_port *dst);
  18643. +
  18644. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  18645. + u32 *major_out,
  18646. + u32 *minor_out);
  18647. +
  18648. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  18649. + struct vchiq_mmal_port *port,
  18650. + struct mmal_buffer *buf);
  18651. +
  18652. +#endif /* MMAL_VCHIQ_H */
  18653. diff -Nur linux-3.10.33/drivers/media/platform/Kconfig linux-raspberry-pi/drivers/media/platform/Kconfig
  18654. --- linux-3.10.33/drivers/media/platform/Kconfig 2014-03-07 06:58:45.000000000 +0100
  18655. +++ linux-raspberry-pi/drivers/media/platform/Kconfig 2014-03-13 12:46:18.256055381 +0100
  18656. @@ -124,6 +124,7 @@
  18657. source "drivers/media/platform/soc_camera/Kconfig"
  18658. source "drivers/media/platform/exynos4-is/Kconfig"
  18659. source "drivers/media/platform/s5p-tv/Kconfig"
  18660. +source "drivers/media/platform/bcm2835/Kconfig"
  18661. endif # V4L_PLATFORM_DRIVERS
  18662. diff -Nur linux-3.10.33/drivers/media/platform/Makefile linux-raspberry-pi/drivers/media/platform/Makefile
  18663. --- linux-3.10.33/drivers/media/platform/Makefile 2014-03-07 06:58:45.000000000 +0100
  18664. +++ linux-raspberry-pi/drivers/media/platform/Makefile 2014-03-13 12:46:18.256055381 +0100
  18665. @@ -50,4 +50,6 @@
  18666. obj-$(CONFIG_ARCH_OMAP) += omap/
  18667. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  18668. +
  18669. ccflags-y += -I$(srctree)/drivers/media/i2c
  18670. diff -Nur linux-3.10.33/drivers/media/usb/dvb-usb-v2/az6007.c linux-raspberry-pi/drivers/media/usb/dvb-usb-v2/az6007.c
  18671. --- linux-3.10.33/drivers/media/usb/dvb-usb-v2/az6007.c 2014-03-07 06:58:45.000000000 +0100
  18672. +++ linux-raspberry-pi/drivers/media/usb/dvb-usb-v2/az6007.c 2014-03-13 12:46:18.908056686 +0100
  18673. @@ -68,6 +68,19 @@
  18674. .microcode_name = "dvb-usb-terratec-h7-drxk.fw",
  18675. };
  18676. +static struct drxk_config cablestar_hdci_drxk = {
  18677. + .adr = 0x29,
  18678. + .parallel_ts = true,
  18679. + .dynamic_clk = true,
  18680. + .single_master = true,
  18681. + .enable_merr_cfg = true,
  18682. + .no_i2c_bridge = false,
  18683. + .chunk_size = 64,
  18684. + .mpeg_out_clk_strength = 0x02,
  18685. + .qam_demod_parameter_count = 2,
  18686. + .microcode_name = "dvb-usb-technisat-cablestar-hdci-drxk.fw",
  18687. +};
  18688. +
  18689. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  18690. {
  18691. struct az6007_device_state *st = fe_to_priv(fe);
  18692. @@ -630,6 +643,27 @@
  18693. return 0;
  18694. }
  18695. +static int az6007_cablestar_hdci_frontend_attach(struct dvb_usb_adapter *adap)
  18696. +{
  18697. + struct az6007_device_state *st = adap_to_priv(adap);
  18698. + struct dvb_usb_device *d = adap_to_d(adap);
  18699. +
  18700. + pr_debug("attaching demod drxk\n");
  18701. +
  18702. + adap->fe[0] = dvb_attach(drxk_attach, &cablestar_hdci_drxk,
  18703. + &d->i2c_adap);
  18704. + if (!adap->fe[0])
  18705. + return -EINVAL;
  18706. +
  18707. + adap->fe[0]->sec_priv = adap;
  18708. + st->gate_ctrl = adap->fe[0]->ops.i2c_gate_ctrl;
  18709. + adap->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  18710. +
  18711. + az6007_ci_init(adap);
  18712. +
  18713. + return 0;
  18714. +}
  18715. +
  18716. static int az6007_tuner_attach(struct dvb_usb_adapter *adap)
  18717. {
  18718. struct dvb_usb_device *d = adap_to_d(adap);
  18719. @@ -868,6 +902,29 @@
  18720. }
  18721. };
  18722. +static struct dvb_usb_device_properties az6007_cablestar_hdci_props = {
  18723. + .driver_name = KBUILD_MODNAME,
  18724. + .owner = THIS_MODULE,
  18725. + .firmware = AZ6007_FIRMWARE,
  18726. +
  18727. + .adapter_nr = adapter_nr,
  18728. + .size_of_priv = sizeof(struct az6007_device_state),
  18729. + .i2c_algo = &az6007_i2c_algo,
  18730. + .tuner_attach = az6007_tuner_attach,
  18731. + .frontend_attach = az6007_cablestar_hdci_frontend_attach,
  18732. + .streaming_ctrl = az6007_streaming_ctrl,
  18733. +/* ditch get_rc_config as it can't work (TS35 remote, I believe it's rc5) */
  18734. + .get_rc_config = NULL,
  18735. + .read_mac_address = az6007_read_mac_addr,
  18736. + .download_firmware = az6007_download_firmware,
  18737. + .identify_state = az6007_identify_state,
  18738. + .power_ctrl = az6007_power_ctrl,
  18739. + .num_adapters = 1,
  18740. + .adapter = {
  18741. + { .stream = DVB_USB_STREAM_BULK(0x02, 10, 4096), }
  18742. + }
  18743. +};
  18744. +
  18745. static struct usb_device_id az6007_usb_table[] = {
  18746. {DVB_USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007,
  18747. &az6007_props, "Azurewave 6007", RC_MAP_EMPTY)},
  18748. @@ -875,6 +932,8 @@
  18749. &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
  18750. {DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7_2,
  18751. &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
  18752. + {DVB_USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI,
  18753. + &az6007_cablestar_hdci_props, "Technisat CableStar Combo HD CI", RC_MAP_EMPTY)},
  18754. {0},
  18755. };
  18756. diff -Nur linux-3.10.33/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-raspberry-pi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  18757. --- linux-3.10.33/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-03-07 06:58:45.000000000 +0100
  18758. +++ linux-raspberry-pi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-03-13 12:46:18.964056798 +0100
  18759. @@ -1408,6 +1408,10 @@
  18760. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  18761. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  18762. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  18763. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  18764. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18765. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  18766. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18767. { }
  18768. };
  18769. MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
  18770. diff -Nur linux-3.10.33/drivers/misc/Kconfig linux-raspberry-pi/drivers/misc/Kconfig
  18771. --- linux-3.10.33/drivers/misc/Kconfig 2014-03-07 06:58:45.000000000 +0100
  18772. +++ linux-raspberry-pi/drivers/misc/Kconfig 2014-03-13 12:46:20.576060026 +0100
  18773. @@ -536,4 +536,6 @@
  18774. source "drivers/misc/altera-stapl/Kconfig"
  18775. source "drivers/misc/mei/Kconfig"
  18776. source "drivers/misc/vmw_vmci/Kconfig"
  18777. +source "drivers/misc/vc04_services/Kconfig"
  18778. endmenu
  18779. +
  18780. diff -Nur linux-3.10.33/drivers/misc/Makefile linux-raspberry-pi/drivers/misc/Makefile
  18781. --- linux-3.10.33/drivers/misc/Makefile 2014-03-07 06:58:45.000000000 +0100
  18782. +++ linux-raspberry-pi/drivers/misc/Makefile 2014-03-13 12:46:20.576060026 +0100
  18783. @@ -53,3 +53,4 @@
  18784. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  18785. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  18786. obj-$(CONFIG_SRAM) += sram.o
  18787. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  18788. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  18789. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  18790. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-03-13 12:46:20.596060066 +0100
  18791. @@ -0,0 +1,328 @@
  18792. +/**
  18793. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18794. + *
  18795. + * Redistribution and use in source and binary forms, with or without
  18796. + * modification, are permitted provided that the following conditions
  18797. + * are met:
  18798. + * 1. Redistributions of source code must retain the above copyright
  18799. + * notice, this list of conditions, and the following disclaimer,
  18800. + * without modification.
  18801. + * 2. Redistributions in binary form must reproduce the above copyright
  18802. + * notice, this list of conditions and the following disclaimer in the
  18803. + * documentation and/or other materials provided with the distribution.
  18804. + * 3. The names of the above-listed copyright holders may not be used
  18805. + * to endorse or promote products derived from this software without
  18806. + * specific prior written permission.
  18807. + *
  18808. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18809. + * GNU General Public License ("GPL") version 2, as published by the Free
  18810. + * Software Foundation.
  18811. + *
  18812. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18813. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18814. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18815. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18816. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18817. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18818. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18819. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18820. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18821. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18822. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18823. + */
  18824. +
  18825. +#ifndef CONNECTION_H_
  18826. +#define CONNECTION_H_
  18827. +
  18828. +#include <linux/kernel.h>
  18829. +#include <linux/types.h>
  18830. +#include <linux/semaphore.h>
  18831. +
  18832. +#include "interface/vchi/vchi_cfg_internal.h"
  18833. +#include "interface/vchi/vchi_common.h"
  18834. +#include "interface/vchi/message_drivers/message.h"
  18835. +
  18836. +/******************************************************************************
  18837. + Global defs
  18838. + *****************************************************************************/
  18839. +
  18840. +// Opaque handle for a connection / service pair
  18841. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  18842. +
  18843. +// opaque handle to the connection state information
  18844. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  18845. +
  18846. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  18847. +
  18848. +
  18849. +/******************************************************************************
  18850. + API
  18851. + *****************************************************************************/
  18852. +
  18853. +// Routine to init a connection with a particular low level driver
  18854. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  18855. + const VCHI_MESSAGE_DRIVER_T * driver );
  18856. +
  18857. +// Routine to control CRC enabling at a connection level
  18858. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18859. + VCHI_CRC_CONTROL_T control );
  18860. +
  18861. +// Routine to create a service
  18862. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18863. + int32_t service_id,
  18864. + uint32_t rx_fifo_size,
  18865. + uint32_t tx_fifo_size,
  18866. + int server,
  18867. + VCHI_CALLBACK_T callback,
  18868. + void *callback_param,
  18869. + int32_t want_crc,
  18870. + int32_t want_unaligned_bulk_rx,
  18871. + int32_t want_unaligned_bulk_tx,
  18872. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  18873. +
  18874. +// Routine to close a service
  18875. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  18876. +
  18877. +// Routine to queue a message
  18878. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18879. + const void *data,
  18880. + uint32_t data_size,
  18881. + VCHI_FLAGS_T flags,
  18882. + void *msg_handle );
  18883. +
  18884. +// scatter-gather (vector) message queueing
  18885. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18886. + VCHI_MSG_VECTOR_T *vector,
  18887. + uint32_t count,
  18888. + VCHI_FLAGS_T flags,
  18889. + void *msg_handle );
  18890. +
  18891. +// Routine to dequeue a message
  18892. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18893. + void *data,
  18894. + uint32_t max_data_size_to_read,
  18895. + uint32_t *actual_msg_size,
  18896. + VCHI_FLAGS_T flags );
  18897. +
  18898. +// Routine to peek at a message
  18899. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18900. + void **data,
  18901. + uint32_t *msg_size,
  18902. + VCHI_FLAGS_T flags );
  18903. +
  18904. +// Routine to hold a message
  18905. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18906. + void **data,
  18907. + uint32_t *msg_size,
  18908. + VCHI_FLAGS_T flags,
  18909. + void **message_handle );
  18910. +
  18911. +// Routine to initialise a received message iterator
  18912. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18913. + VCHI_MSG_ITER_T *iter,
  18914. + VCHI_FLAGS_T flags );
  18915. +
  18916. +// Routine to release a held message
  18917. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18918. + void *message_handle );
  18919. +
  18920. +// Routine to get info on a held message
  18921. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18922. + void *message_handle,
  18923. + void **data,
  18924. + int32_t *msg_size,
  18925. + uint32_t *tx_timestamp,
  18926. + uint32_t *rx_timestamp );
  18927. +
  18928. +// Routine to check whether the iterator has a next message
  18929. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18930. + const VCHI_MSG_ITER_T *iter );
  18931. +
  18932. +// Routine to advance the iterator
  18933. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18934. + VCHI_MSG_ITER_T *iter,
  18935. + void **data,
  18936. + uint32_t *msg_size );
  18937. +
  18938. +// Routine to remove the last message returned by the iterator
  18939. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18940. + VCHI_MSG_ITER_T *iter );
  18941. +
  18942. +// Routine to hold the last message returned by the iterator
  18943. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18944. + VCHI_MSG_ITER_T *iter,
  18945. + void **msg_handle );
  18946. +
  18947. +// Routine to transmit bulk data
  18948. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18949. + const void *data_src,
  18950. + uint32_t data_size,
  18951. + VCHI_FLAGS_T flags,
  18952. + void *bulk_handle );
  18953. +
  18954. +// Routine to receive data
  18955. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18956. + void *data_dst,
  18957. + uint32_t data_size,
  18958. + VCHI_FLAGS_T flags,
  18959. + void *bulk_handle );
  18960. +
  18961. +// Routine to report if a server is available
  18962. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  18963. +
  18964. +// Routine to report the number of RX slots available
  18965. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  18966. +
  18967. +// Routine to report the RX slot size
  18968. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  18969. +
  18970. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18971. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  18972. + int32_t service,
  18973. + uint32_t length,
  18974. + MESSAGE_TX_CHANNEL_T channel,
  18975. + uint32_t channel_params,
  18976. + uint32_t data_length,
  18977. + uint32_t data_offset);
  18978. +
  18979. +// Callback to inform a service that a Xon or Xoff message has been received
  18980. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  18981. +
  18982. +// Callback to inform a service that a server available reply message has been received
  18983. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  18984. +
  18985. +// Callback to indicate that bulk auxiliary messages have arrived
  18986. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  18987. +
  18988. +// Callback to indicate that bulk auxiliary messages have arrived
  18989. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  18990. +
  18991. +// Callback with all the connection info you require
  18992. +typedef void (*VCHI_CONNECTION_INFO)(VCHI_CONNECTION_STATE_T *state, uint32_t protocol_version, uint32_t slot_size, uint32_t num_slots, uint32_t min_bulk_size);
  18993. +
  18994. +// Callback to inform of a disconnect
  18995. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  18996. +
  18997. +// Callback to inform of a power control request
  18998. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  18999. +
  19000. +// allocate memory suitably aligned for this connection
  19001. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  19002. +
  19003. +// free memory allocated by buffer_allocate
  19004. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  19005. +
  19006. +
  19007. +/******************************************************************************
  19008. + System driver struct
  19009. + *****************************************************************************/
  19010. +
  19011. +struct opaque_vchi_connection_api_t
  19012. +{
  19013. + // Routine to init the connection
  19014. + VCHI_CONNECTION_INIT_T init;
  19015. +
  19016. + // Connection-level CRC control
  19017. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  19018. +
  19019. + // Routine to connect to or create service
  19020. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  19021. +
  19022. + // Routine to disconnect from a service
  19023. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  19024. +
  19025. + // Routine to queue a message
  19026. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  19027. +
  19028. + // scatter-gather (vector) message queue
  19029. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  19030. +
  19031. + // Routine to dequeue a message
  19032. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  19033. +
  19034. + // Routine to peek at a message
  19035. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  19036. +
  19037. + // Routine to hold a message
  19038. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  19039. +
  19040. + // Routine to initialise a received message iterator
  19041. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  19042. +
  19043. + // Routine to release a message
  19044. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  19045. +
  19046. + // Routine to get information on a held message
  19047. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  19048. +
  19049. + // Routine to check for next message on iterator
  19050. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  19051. +
  19052. + // Routine to get next message on iterator
  19053. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  19054. +
  19055. + // Routine to remove the last message returned by iterator
  19056. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  19057. +
  19058. + // Routine to hold the last message returned by iterator
  19059. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  19060. +
  19061. + // Routine to transmit bulk data
  19062. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  19063. +
  19064. + // Routine to receive data
  19065. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  19066. +
  19067. + // Routine to report the available servers
  19068. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  19069. +
  19070. + // Routine to report the number of RX slots available
  19071. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  19072. +
  19073. + // Routine to report the RX slot size
  19074. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  19075. +
  19076. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  19077. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  19078. +
  19079. + // Callback to inform a service that a Xon or Xoff message has been received
  19080. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  19081. +
  19082. + // Callback to inform a service that a server available reply message has been received
  19083. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  19084. +
  19085. + // Callback to indicate that bulk auxiliary messages have arrived
  19086. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  19087. +
  19088. + // Callback to indicate that a bulk auxiliary message has been transmitted
  19089. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  19090. +
  19091. + // Callback to provide information about the connection
  19092. + VCHI_CONNECTION_INFO connection_info;
  19093. +
  19094. + // Callback to notify that peer has requested disconnect
  19095. + VCHI_CONNECTION_DISCONNECT disconnect;
  19096. +
  19097. + // Callback to notify that peer has requested power change
  19098. + VCHI_CONNECTION_POWER_CONTROL power_control;
  19099. +
  19100. + // allocate memory suitably aligned for this connection
  19101. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  19102. +
  19103. + // free memory allocated by buffer_allocate
  19104. + VCHI_BUFFER_FREE buffer_free;
  19105. +
  19106. +};
  19107. +
  19108. +struct vchi_connection_t {
  19109. + const VCHI_CONNECTION_API_T *api;
  19110. + VCHI_CONNECTION_STATE_T *state;
  19111. +#ifdef VCHI_COARSE_LOCKING
  19112. + struct semaphore sem;
  19113. +#endif
  19114. +};
  19115. +
  19116. +
  19117. +#endif /* CONNECTION_H_ */
  19118. +
  19119. +/****************************** End of file **********************************/
  19120. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  19121. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  19122. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-03-13 12:46:20.596060066 +0100
  19123. @@ -0,0 +1,204 @@
  19124. +/**
  19125. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19126. + *
  19127. + * Redistribution and use in source and binary forms, with or without
  19128. + * modification, are permitted provided that the following conditions
  19129. + * are met:
  19130. + * 1. Redistributions of source code must retain the above copyright
  19131. + * notice, this list of conditions, and the following disclaimer,
  19132. + * without modification.
  19133. + * 2. Redistributions in binary form must reproduce the above copyright
  19134. + * notice, this list of conditions and the following disclaimer in the
  19135. + * documentation and/or other materials provided with the distribution.
  19136. + * 3. The names of the above-listed copyright holders may not be used
  19137. + * to endorse or promote products derived from this software without
  19138. + * specific prior written permission.
  19139. + *
  19140. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19141. + * GNU General Public License ("GPL") version 2, as published by the Free
  19142. + * Software Foundation.
  19143. + *
  19144. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19145. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19146. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19147. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19148. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19149. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19150. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19151. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19152. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19153. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19154. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19155. + */
  19156. +
  19157. +#ifndef _VCHI_MESSAGE_H_
  19158. +#define _VCHI_MESSAGE_H_
  19159. +
  19160. +#include <linux/kernel.h>
  19161. +#include <linux/types.h>
  19162. +#include <linux/semaphore.h>
  19163. +
  19164. +#include "interface/vchi/vchi_cfg_internal.h"
  19165. +#include "interface/vchi/vchi_common.h"
  19166. +
  19167. +
  19168. +typedef enum message_event_type {
  19169. + MESSAGE_EVENT_NONE,
  19170. + MESSAGE_EVENT_NOP,
  19171. + MESSAGE_EVENT_MESSAGE,
  19172. + MESSAGE_EVENT_SLOT_COMPLETE,
  19173. + MESSAGE_EVENT_RX_BULK_PAUSED,
  19174. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  19175. + MESSAGE_EVENT_TX_COMPLETE,
  19176. + MESSAGE_EVENT_MSG_DISCARDED
  19177. +} MESSAGE_EVENT_TYPE_T;
  19178. +
  19179. +typedef enum vchi_msg_flags
  19180. +{
  19181. + VCHI_MSG_FLAGS_NONE = 0x0,
  19182. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  19183. +} VCHI_MSG_FLAGS_T;
  19184. +
  19185. +typedef enum message_tx_channel
  19186. +{
  19187. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  19188. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  19189. +} MESSAGE_TX_CHANNEL_T;
  19190. +
  19191. +// Macros used for cycling through bulk channels
  19192. +#define MESSAGE_TX_CHANNEL_BULK_PREV(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION-1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  19193. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  19194. +
  19195. +typedef enum message_rx_channel
  19196. +{
  19197. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  19198. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  19199. +} MESSAGE_RX_CHANNEL_T;
  19200. +
  19201. +// Message receive slot information
  19202. +typedef struct rx_msg_slot_info {
  19203. +
  19204. + struct rx_msg_slot_info *next;
  19205. + //struct slot_info *prev;
  19206. +#if !defined VCHI_COARSE_LOCKING
  19207. + struct semaphore sem;
  19208. +#endif
  19209. +
  19210. + uint8_t *addr; // base address of slot
  19211. + uint32_t len; // length of slot in bytes
  19212. +
  19213. + uint32_t write_ptr; // hardware causes this to advance
  19214. + uint32_t read_ptr; // this module does the reading
  19215. + int active; // is this slot in the hardware dma fifo?
  19216. + uint32_t msgs_parsed; // count how many messages are in this slot
  19217. + uint32_t msgs_released; // how many messages have been released
  19218. + void *state; // connection state information
  19219. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  19220. +} RX_MSG_SLOTINFO_T;
  19221. +
  19222. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  19223. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  19224. +// driver will be tasked with sending the aligned core section.
  19225. +typedef struct rx_bulk_slotinfo_t {
  19226. + struct rx_bulk_slotinfo_t *next;
  19227. +
  19228. + struct semaphore *blocking;
  19229. +
  19230. + // needed by DMA
  19231. + void *addr;
  19232. + uint32_t len;
  19233. +
  19234. + // needed for the callback
  19235. + void *service;
  19236. + void *handle;
  19237. + VCHI_FLAGS_T flags;
  19238. +} RX_BULK_SLOTINFO_T;
  19239. +
  19240. +
  19241. +/* ----------------------------------------------------------------------
  19242. + * each connection driver will have a pool of the following struct.
  19243. + *
  19244. + * the pool will be managed by vchi_qman_*
  19245. + * this means there will be multiple queues (single linked lists)
  19246. + * a given struct message_info will be on exactly one of these queues
  19247. + * at any one time
  19248. + * -------------------------------------------------------------------- */
  19249. +typedef struct rx_message_info {
  19250. +
  19251. + struct message_info *next;
  19252. + //struct message_info *prev;
  19253. +
  19254. + uint8_t *addr;
  19255. + uint32_t len;
  19256. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  19257. + uint32_t tx_timestamp;
  19258. + uint32_t rx_timestamp;
  19259. +
  19260. +} RX_MESSAGE_INFO_T;
  19261. +
  19262. +typedef struct {
  19263. + MESSAGE_EVENT_TYPE_T type;
  19264. +
  19265. + struct {
  19266. + // for messages
  19267. + void *addr; // address of message
  19268. + uint16_t slot_delta; // whether this message indicated slot delta
  19269. + uint32_t len; // length of message
  19270. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  19271. + int32_t service; // service id this message is destined for
  19272. + uint32_t tx_timestamp; // timestamp from the header
  19273. + uint32_t rx_timestamp; // timestamp when we parsed it
  19274. + } message;
  19275. +
  19276. + // FIXME: cleanup slot reporting...
  19277. + RX_MSG_SLOTINFO_T *rx_msg;
  19278. + RX_BULK_SLOTINFO_T *rx_bulk;
  19279. + void *tx_handle;
  19280. + MESSAGE_TX_CHANNEL_T tx_channel;
  19281. +
  19282. +} MESSAGE_EVENT_T;
  19283. +
  19284. +
  19285. +// callbacks
  19286. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  19287. +
  19288. +typedef struct {
  19289. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  19290. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  19291. +
  19292. +
  19293. +// handle to this instance of message driver (as returned by ->open)
  19294. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  19295. +
  19296. +struct opaque_vchi_message_driver_t {
  19297. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  19298. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  19299. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  19300. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  19301. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  19302. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  19303. + int32_t (*send)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, VCHI_MSG_FLAGS_T flags, void *send_handle ); // tx (message & bulk)
  19304. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  19305. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  19306. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  19307. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  19308. +
  19309. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  19310. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  19311. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  19312. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  19313. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  19314. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  19315. +
  19316. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  19317. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  19318. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  19319. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  19320. + void (*form_bulk_aux)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, uint32_t chunk_size, const void **aux_data, int32_t *aux_len );
  19321. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  19322. +};
  19323. +
  19324. +
  19325. +#endif // _VCHI_MESSAGE_H_
  19326. +
  19327. +/****************************** End of file ***********************************/
  19328. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  19329. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  19330. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-03-13 12:46:20.596060066 +0100
  19331. @@ -0,0 +1,224 @@
  19332. +/**
  19333. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19334. + *
  19335. + * Redistribution and use in source and binary forms, with or without
  19336. + * modification, are permitted provided that the following conditions
  19337. + * are met:
  19338. + * 1. Redistributions of source code must retain the above copyright
  19339. + * notice, this list of conditions, and the following disclaimer,
  19340. + * without modification.
  19341. + * 2. Redistributions in binary form must reproduce the above copyright
  19342. + * notice, this list of conditions and the following disclaimer in the
  19343. + * documentation and/or other materials provided with the distribution.
  19344. + * 3. The names of the above-listed copyright holders may not be used
  19345. + * to endorse or promote products derived from this software without
  19346. + * specific prior written permission.
  19347. + *
  19348. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19349. + * GNU General Public License ("GPL") version 2, as published by the Free
  19350. + * Software Foundation.
  19351. + *
  19352. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19353. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19354. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19355. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19356. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19357. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19358. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19359. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19360. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19361. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19362. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19363. + */
  19364. +
  19365. +#ifndef VCHI_CFG_H_
  19366. +#define VCHI_CFG_H_
  19367. +
  19368. +/****************************************************************************************
  19369. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  19370. + * services.
  19371. + ***************************************************************************************/
  19372. +
  19373. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  19374. +/* Really determined by the message driver, and should be available from a run-time call. */
  19375. +#ifndef VCHI_BULK_ALIGN
  19376. +# if __VCCOREVER__ >= 0x04000000
  19377. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  19378. +# else
  19379. +# define VCHI_BULK_ALIGN 16
  19380. +# endif
  19381. +#endif
  19382. +
  19383. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  19384. +/* May be less than or greater than VCHI_BULK_ALIGN */
  19385. +/* Really determined by the message driver, and should be available from a run-time call. */
  19386. +#ifndef VCHI_BULK_GRANULARITY
  19387. +# if __VCCOREVER__ >= 0x04000000
  19388. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  19389. +# else
  19390. +# define VCHI_BULK_GRANULARITY 16
  19391. +# endif
  19392. +#endif
  19393. +
  19394. +/* The largest possible message to be queued with vchi_msg_queue. */
  19395. +#ifndef VCHI_MAX_MSG_SIZE
  19396. +# if defined VCHI_LOCAL_HOST_PORT
  19397. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  19398. +# else
  19399. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  19400. +# endif
  19401. +#endif
  19402. +
  19403. +/******************************************************************************************
  19404. + * Defines below are system configuration options, and should not be used by VCHI services.
  19405. + *****************************************************************************************/
  19406. +
  19407. +/* How many connections can we support? A localhost implementation uses 2 connections,
  19408. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  19409. + * driver. */
  19410. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  19411. +# define VCHI_MAX_NUM_CONNECTIONS 3
  19412. +#endif
  19413. +
  19414. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  19415. + * amount of static memory. */
  19416. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  19417. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  19418. +#endif
  19419. +
  19420. +/* Adjust if using a message driver that supports more logical TX channels */
  19421. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  19422. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  19423. +#endif
  19424. +
  19425. +/* Adjust if using a message driver that supports more logical RX channels */
  19426. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  19427. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  19428. +#endif
  19429. +
  19430. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  19431. + * receive queue space, less message headers. */
  19432. +#ifndef VCHI_NUM_READ_SLOTS
  19433. +# if defined(VCHI_LOCAL_HOST_PORT)
  19434. +# define VCHI_NUM_READ_SLOTS 4
  19435. +# else
  19436. +# define VCHI_NUM_READ_SLOTS 48
  19437. +# endif
  19438. +#endif
  19439. +
  19440. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  19441. + * performance. Only define on VideoCore end, talking to host.
  19442. + */
  19443. +//#define VCHI_MSG_RX_OVERRUN
  19444. +
  19445. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  19446. + * underneath VCHI will usually have its own buffering. */
  19447. +#ifndef VCHI_NUM_WRITE_SLOTS
  19448. +# define VCHI_NUM_WRITE_SLOTS 4
  19449. +#endif
  19450. +
  19451. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  19452. + * then it's taking up too much buffer space, and the peer service will be told to stop
  19453. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  19454. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  19455. + * is too high. */
  19456. +#ifndef VCHI_XOFF_THRESHOLD
  19457. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  19458. +#endif
  19459. +
  19460. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  19461. + * service has dequeued/released enough messages that it's now occupying
  19462. + * VCHI_XON_THRESHOLD slots or fewer. */
  19463. +#ifndef VCHI_XON_THRESHOLD
  19464. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  19465. +#endif
  19466. +
  19467. +/* A size below which a bulk transfer omits the handshake completely and always goes
  19468. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  19469. + * can guarantee this by enabling unaligned transmits).
  19470. + * Not API. */
  19471. +#ifndef VCHI_MIN_BULK_SIZE
  19472. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  19473. +#endif
  19474. +
  19475. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  19476. + * speed and latency; the smaller the chunk size the better change of messages and other
  19477. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  19478. + * break transmissions into chunks.
  19479. + */
  19480. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  19481. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  19482. +#endif
  19483. +
  19484. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  19485. + * with multiple-line frames. Only use if the receiver can cope. */
  19486. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  19487. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  19488. +#endif
  19489. +
  19490. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  19491. + * vchi_msg_queue will be blocked. */
  19492. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  19493. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  19494. +#endif
  19495. +
  19496. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  19497. + * will be suspended until older messages are dequeued/released. */
  19498. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  19499. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  19500. +#endif
  19501. +
  19502. +/* Really should be able to cope if we run out of received message descriptors, by
  19503. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  19504. + * under the carpet. */
  19505. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  19506. +# undef VCHI_RX_MSG_QUEUE_SIZE
  19507. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  19508. +#endif
  19509. +
  19510. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  19511. + * will be blocked. */
  19512. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  19513. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  19514. +#endif
  19515. +
  19516. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  19517. + * will be blocked. */
  19518. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  19519. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  19520. +#endif
  19521. +
  19522. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  19523. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  19524. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  19525. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  19526. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  19527. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  19528. +#endif
  19529. +
  19530. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  19531. + * transmitter on and off.
  19532. + */
  19533. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  19534. +
  19535. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  19536. +
  19537. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  19538. + * negative for no IDLE.
  19539. + */
  19540. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  19541. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  19542. +# endif
  19543. +
  19544. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  19545. + * negative for no OFF.
  19546. + */
  19547. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  19548. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  19549. +# endif
  19550. +
  19551. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  19552. +
  19553. +#endif /* VCHI_CFG_H_ */
  19554. +
  19555. +/****************************** End of file **********************************/
  19556. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  19557. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  19558. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-03-13 12:46:20.596060066 +0100
  19559. @@ -0,0 +1,71 @@
  19560. +/**
  19561. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19562. + *
  19563. + * Redistribution and use in source and binary forms, with or without
  19564. + * modification, are permitted provided that the following conditions
  19565. + * are met:
  19566. + * 1. Redistributions of source code must retain the above copyright
  19567. + * notice, this list of conditions, and the following disclaimer,
  19568. + * without modification.
  19569. + * 2. Redistributions in binary form must reproduce the above copyright
  19570. + * notice, this list of conditions and the following disclaimer in the
  19571. + * documentation and/or other materials provided with the distribution.
  19572. + * 3. The names of the above-listed copyright holders may not be used
  19573. + * to endorse or promote products derived from this software without
  19574. + * specific prior written permission.
  19575. + *
  19576. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19577. + * GNU General Public License ("GPL") version 2, as published by the Free
  19578. + * Software Foundation.
  19579. + *
  19580. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19581. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19582. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19583. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19584. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19585. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19586. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19587. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19588. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19589. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19590. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19591. + */
  19592. +
  19593. +#ifndef VCHI_CFG_INTERNAL_H_
  19594. +#define VCHI_CFG_INTERNAL_H_
  19595. +
  19596. +/****************************************************************************************
  19597. + * Control optimisation attempts.
  19598. + ***************************************************************************************/
  19599. +
  19600. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  19601. +#define VCHI_COARSE_LOCKING
  19602. +
  19603. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  19604. +// (only relevant if VCHI_COARSE_LOCKING)
  19605. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  19606. +
  19607. +// Avoid lock on non-blocking peek
  19608. +// (only relevant if VCHI_COARSE_LOCKING)
  19609. +#define VCHI_AVOID_PEEK_LOCK
  19610. +
  19611. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  19612. +#define VCHI_MULTIPLE_HANDLER_THREADS
  19613. +
  19614. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  19615. +// our way through the pool of descriptors.
  19616. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  19617. +
  19618. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  19619. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  19620. +
  19621. +// Don't use message descriptors for TX messages that don't need them
  19622. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  19623. +
  19624. +// Nano-locks for multiqueue
  19625. +//#define VCHI_MQUEUE_NANOLOCKS
  19626. +
  19627. +// Lock-free(er) dequeuing
  19628. +//#define VCHI_RX_NANOLOCKS
  19629. +
  19630. +#endif /*VCHI_CFG_INTERNAL_H_*/
  19631. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  19632. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  19633. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-03-13 12:46:20.596060066 +0100
  19634. @@ -0,0 +1,163 @@
  19635. +/**
  19636. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19637. + *
  19638. + * Redistribution and use in source and binary forms, with or without
  19639. + * modification, are permitted provided that the following conditions
  19640. + * are met:
  19641. + * 1. Redistributions of source code must retain the above copyright
  19642. + * notice, this list of conditions, and the following disclaimer,
  19643. + * without modification.
  19644. + * 2. Redistributions in binary form must reproduce the above copyright
  19645. + * notice, this list of conditions and the following disclaimer in the
  19646. + * documentation and/or other materials provided with the distribution.
  19647. + * 3. The names of the above-listed copyright holders may not be used
  19648. + * to endorse or promote products derived from this software without
  19649. + * specific prior written permission.
  19650. + *
  19651. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19652. + * GNU General Public License ("GPL") version 2, as published by the Free
  19653. + * Software Foundation.
  19654. + *
  19655. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19656. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19657. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19658. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19659. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19660. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19661. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19662. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19663. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19664. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19665. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19666. + */
  19667. +
  19668. +#ifndef VCHI_COMMON_H_
  19669. +#define VCHI_COMMON_H_
  19670. +
  19671. +
  19672. +//flags used when sending messages (must be bitmapped)
  19673. +typedef enum
  19674. +{
  19675. + VCHI_FLAGS_NONE = 0x0,
  19676. + VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE = 0x1, // waits for message to be received, or sent (NB. not the same as being seen on other side)
  19677. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  19678. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  19679. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  19680. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  19681. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  19682. +
  19683. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  19684. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  19685. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  19686. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  19687. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  19688. + VCHI_FLAGS_INTERNAL = 0xFF0000
  19689. +} VCHI_FLAGS_T;
  19690. +
  19691. +// constants for vchi_crc_control()
  19692. +typedef enum {
  19693. + VCHI_CRC_NOTHING = -1,
  19694. + VCHI_CRC_PER_SERVICE = 0,
  19695. + VCHI_CRC_EVERYTHING = 1,
  19696. +} VCHI_CRC_CONTROL_T;
  19697. +
  19698. +//callback reasons when an event occurs on a service
  19699. +typedef enum
  19700. +{
  19701. + VCHI_CALLBACK_REASON_MIN,
  19702. +
  19703. + //This indicates that there is data available
  19704. + //handle is the msg id that was transmitted with the data
  19705. + // When a message is received and there was no FULL message available previously, send callback
  19706. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  19707. + VCHI_CALLBACK_MSG_AVAILABLE,
  19708. + VCHI_CALLBACK_MSG_SENT,
  19709. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  19710. +
  19711. + // This indicates that a transfer from the other side has completed
  19712. + VCHI_CALLBACK_BULK_RECEIVED,
  19713. + //This indicates that data queued up to be sent has now gone
  19714. + //handle is the msg id that was used when sending the data
  19715. + VCHI_CALLBACK_BULK_SENT,
  19716. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  19717. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  19718. +
  19719. + VCHI_CALLBACK_SERVICE_CLOSED,
  19720. +
  19721. + // this side has sent XOFF to peer due to lack of data consumption by service
  19722. + // (suggests the service may need to take some recovery action if it has
  19723. + // been deliberately holding off consuming data)
  19724. + VCHI_CALLBACK_SENT_XOFF,
  19725. + VCHI_CALLBACK_SENT_XON,
  19726. +
  19727. + // indicates that a bulk transfer has finished reading the source buffer
  19728. + VCHI_CALLBACK_BULK_DATA_READ,
  19729. +
  19730. + // power notification events (currently host side only)
  19731. + VCHI_CALLBACK_PEER_OFF,
  19732. + VCHI_CALLBACK_PEER_SUSPENDED,
  19733. + VCHI_CALLBACK_PEER_ON,
  19734. + VCHI_CALLBACK_PEER_RESUMED,
  19735. + VCHI_CALLBACK_FORCED_POWER_OFF,
  19736. +
  19737. +#ifdef USE_VCHIQ_ARM
  19738. + // some extra notifications provided by vchiq_arm
  19739. + VCHI_CALLBACK_SERVICE_OPENED,
  19740. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  19741. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  19742. +#endif
  19743. +
  19744. + VCHI_CALLBACK_REASON_MAX
  19745. +} VCHI_CALLBACK_REASON_T;
  19746. +
  19747. +//Calback used by all services / bulk transfers
  19748. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  19749. + VCHI_CALLBACK_REASON_T reason,
  19750. + void *handle ); //for transmitting msg's only
  19751. +
  19752. +
  19753. +
  19754. +/*
  19755. + * Define vector struct for scatter-gather (vector) operations
  19756. + * Vectors can be nested - if a vector element has negative length, then
  19757. + * the data pointer is treated as pointing to another vector array, with
  19758. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  19759. + * you can do this:
  19760. + *
  19761. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  19762. + * {
  19763. + * VCHI_MSG_VECTOR_T nv[2];
  19764. + * nv[0].vec_base = my_header;
  19765. + * nv[0].vec_len = sizeof my_header;
  19766. + * nv[1].vec_base = v;
  19767. + * nv[1].vec_len = -n;
  19768. + * ...
  19769. + *
  19770. + */
  19771. +typedef struct vchi_msg_vector {
  19772. + const void *vec_base;
  19773. + int32_t vec_len;
  19774. +} VCHI_MSG_VECTOR_T;
  19775. +
  19776. +// Opaque type for a connection API
  19777. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  19778. +
  19779. +// Opaque type for a message driver
  19780. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  19781. +
  19782. +
  19783. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  19784. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  19785. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  19786. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  19787. +// is used again after messages for that service are removed/dequeued by any
  19788. +// means other than vchi_msg_iter_... calls on the iterator itself.
  19789. +typedef struct {
  19790. + struct opaque_vchi_service_t *service;
  19791. + void *last;
  19792. + void *next;
  19793. + void *remove;
  19794. +} VCHI_MSG_ITER_T;
  19795. +
  19796. +
  19797. +#endif // VCHI_COMMON_H_
  19798. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi.h
  19799. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  19800. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-03-13 12:46:20.596060066 +0100
  19801. @@ -0,0 +1,373 @@
  19802. +/**
  19803. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19804. + *
  19805. + * Redistribution and use in source and binary forms, with or without
  19806. + * modification, are permitted provided that the following conditions
  19807. + * are met:
  19808. + * 1. Redistributions of source code must retain the above copyright
  19809. + * notice, this list of conditions, and the following disclaimer,
  19810. + * without modification.
  19811. + * 2. Redistributions in binary form must reproduce the above copyright
  19812. + * notice, this list of conditions and the following disclaimer in the
  19813. + * documentation and/or other materials provided with the distribution.
  19814. + * 3. The names of the above-listed copyright holders may not be used
  19815. + * to endorse or promote products derived from this software without
  19816. + * specific prior written permission.
  19817. + *
  19818. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19819. + * GNU General Public License ("GPL") version 2, as published by the Free
  19820. + * Software Foundation.
  19821. + *
  19822. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19823. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19824. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19825. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19826. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19827. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19828. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19829. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19830. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19831. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19832. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19833. + */
  19834. +
  19835. +#ifndef VCHI_H_
  19836. +#define VCHI_H_
  19837. +
  19838. +#include "interface/vchi/vchi_cfg.h"
  19839. +#include "interface/vchi/vchi_common.h"
  19840. +#include "interface/vchi/connections/connection.h"
  19841. +#include "vchi_mh.h"
  19842. +
  19843. +
  19844. +/******************************************************************************
  19845. + Global defs
  19846. + *****************************************************************************/
  19847. +
  19848. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  19849. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  19850. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  19851. +
  19852. +#ifdef USE_VCHIQ_ARM
  19853. +#define VCHI_BULK_ALIGNED(x) 1
  19854. +#else
  19855. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  19856. +#endif
  19857. +
  19858. +struct vchi_version {
  19859. + uint32_t version;
  19860. + uint32_t version_min;
  19861. +};
  19862. +#define VCHI_VERSION(v_) { v_, v_ }
  19863. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  19864. +
  19865. +typedef enum
  19866. +{
  19867. + VCHI_VEC_POINTER,
  19868. + VCHI_VEC_HANDLE,
  19869. + VCHI_VEC_LIST
  19870. +} VCHI_MSG_VECTOR_TYPE_T;
  19871. +
  19872. +typedef struct vchi_msg_vector_ex {
  19873. +
  19874. + VCHI_MSG_VECTOR_TYPE_T type;
  19875. + union
  19876. + {
  19877. + // a memory handle
  19878. + struct
  19879. + {
  19880. + VCHI_MEM_HANDLE_T handle;
  19881. + uint32_t offset;
  19882. + int32_t vec_len;
  19883. + } handle;
  19884. +
  19885. + // an ordinary data pointer
  19886. + struct
  19887. + {
  19888. + const void *vec_base;
  19889. + int32_t vec_len;
  19890. + } ptr;
  19891. +
  19892. + // a nested vector list
  19893. + struct
  19894. + {
  19895. + struct vchi_msg_vector_ex *vec;
  19896. + uint32_t vec_len;
  19897. + } list;
  19898. + } u;
  19899. +} VCHI_MSG_VECTOR_EX_T;
  19900. +
  19901. +
  19902. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  19903. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  19904. +
  19905. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  19906. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  19907. +
  19908. +// Macros to manipulate 'FOURCC' values
  19909. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  19910. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  19911. +
  19912. +
  19913. +// Opaque service information
  19914. +struct opaque_vchi_service_t;
  19915. +
  19916. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  19917. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  19918. +typedef struct
  19919. +{
  19920. + struct opaque_vchi_service_t *service;
  19921. + void *message;
  19922. +} VCHI_HELD_MSG_T;
  19923. +
  19924. +
  19925. +
  19926. +// structure used to provide the information needed to open a server or a client
  19927. +typedef struct {
  19928. + struct vchi_version version;
  19929. + int32_t service_id;
  19930. + VCHI_CONNECTION_T *connection;
  19931. + uint32_t rx_fifo_size;
  19932. + uint32_t tx_fifo_size;
  19933. + VCHI_CALLBACK_T callback;
  19934. + void *callback_param;
  19935. + /* client intends to receive bulk transfers of
  19936. + odd lengths or into unaligned buffers */
  19937. + int32_t want_unaligned_bulk_rx;
  19938. + /* client intends to transmit bulk transfers of
  19939. + odd lengths or out of unaligned buffers */
  19940. + int32_t want_unaligned_bulk_tx;
  19941. + /* client wants to check CRCs on (bulk) xfers.
  19942. + Only needs to be set at 1 end - will do both directions. */
  19943. + int32_t want_crc;
  19944. +} SERVICE_CREATION_T;
  19945. +
  19946. +// Opaque handle for a VCHI instance
  19947. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  19948. +
  19949. +// Opaque handle for a server or client
  19950. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  19951. +
  19952. +// Service registration & startup
  19953. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  19954. +
  19955. +typedef struct service_info_tag {
  19956. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  19957. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  19958. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  19959. +} SERVICE_INFO_T;
  19960. +
  19961. +/******************************************************************************
  19962. + Global funcs - implementation is specific to which side you are on (local / remote)
  19963. + *****************************************************************************/
  19964. +
  19965. +#ifdef __cplusplus
  19966. +extern "C" {
  19967. +#endif
  19968. +
  19969. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  19970. + const VCHI_MESSAGE_DRIVER_T * low_level);
  19971. +
  19972. +
  19973. +// Routine used to initialise the vchi on both local + remote connections
  19974. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  19975. +
  19976. +extern int32_t vchi_exit( void );
  19977. +
  19978. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  19979. + const uint32_t num_connections,
  19980. + VCHI_INSTANCE_T instance_handle );
  19981. +
  19982. +//When this is called, ensure that all services have no data pending.
  19983. +//Bulk transfers can remain 'queued'
  19984. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  19985. +
  19986. +// Global control over bulk CRC checking
  19987. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  19988. + VCHI_CRC_CONTROL_T control );
  19989. +
  19990. +// helper functions
  19991. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  19992. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  19993. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  19994. +
  19995. +
  19996. +/******************************************************************************
  19997. + Global service API
  19998. + *****************************************************************************/
  19999. +// Routine to create a named service
  20000. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  20001. + SERVICE_CREATION_T *setup,
  20002. + VCHI_SERVICE_HANDLE_T *handle );
  20003. +
  20004. +// Routine to destory a service
  20005. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  20006. +
  20007. +// Routine to open a named service
  20008. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  20009. + SERVICE_CREATION_T *setup,
  20010. + VCHI_SERVICE_HANDLE_T *handle);
  20011. +
  20012. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  20013. + short *peer_version );
  20014. +
  20015. +// Routine to close a named service
  20016. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  20017. +
  20018. +// Routine to increment ref count on a named service
  20019. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  20020. +
  20021. +// Routine to decrement ref count on a named service
  20022. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  20023. +
  20024. +// Routine to send a message accross a service
  20025. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  20026. + const void *data,
  20027. + uint32_t data_size,
  20028. + VCHI_FLAGS_T flags,
  20029. + void *msg_handle );
  20030. +
  20031. +// scatter-gather (vector) and send message
  20032. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  20033. + VCHI_MSG_VECTOR_EX_T *vector,
  20034. + uint32_t count,
  20035. + VCHI_FLAGS_T flags,
  20036. + void *msg_handle );
  20037. +
  20038. +// legacy scatter-gather (vector) and send message, only handles pointers
  20039. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  20040. + VCHI_MSG_VECTOR_T *vector,
  20041. + uint32_t count,
  20042. + VCHI_FLAGS_T flags,
  20043. + void *msg_handle );
  20044. +
  20045. +// Routine to receive a msg from a service
  20046. +// Dequeue is equivalent to hold, copy into client buffer, release
  20047. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  20048. + void *data,
  20049. + uint32_t max_data_size_to_read,
  20050. + uint32_t *actual_msg_size,
  20051. + VCHI_FLAGS_T flags );
  20052. +
  20053. +// Routine to look at a message in place.
  20054. +// The message is not dequeued, so a subsequent call to peek or dequeue
  20055. +// will return the same message.
  20056. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  20057. + void **data,
  20058. + uint32_t *msg_size,
  20059. + VCHI_FLAGS_T flags );
  20060. +
  20061. +// Routine to remove a message after it has been read in place with peek
  20062. +// The first message on the queue is dequeued.
  20063. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  20064. +
  20065. +// Routine to look at a message in place.
  20066. +// The message is dequeued, so the caller is left holding it; the descriptor is
  20067. +// filled in and must be released when the user has finished with the message.
  20068. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  20069. + void **data, // } may be NULL, as info can be
  20070. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  20071. + VCHI_FLAGS_T flags,
  20072. + VCHI_HELD_MSG_T *message_descriptor );
  20073. +
  20074. +// Initialise an iterator to look through messages in place
  20075. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  20076. + VCHI_MSG_ITER_T *iter,
  20077. + VCHI_FLAGS_T flags );
  20078. +
  20079. +/******************************************************************************
  20080. + Global service support API - operations on held messages and message iterators
  20081. + *****************************************************************************/
  20082. +
  20083. +// Routine to get the address of a held message
  20084. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  20085. +
  20086. +// Routine to get the size of a held message
  20087. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  20088. +
  20089. +// Routine to get the transmit timestamp as written into the header by the peer
  20090. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  20091. +
  20092. +// Routine to get the reception timestamp, written as we parsed the header
  20093. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  20094. +
  20095. +// Routine to release a held message after it has been processed
  20096. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  20097. +
  20098. +// Indicates whether the iterator has a next message.
  20099. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  20100. +
  20101. +// Return the pointer and length for the next message and advance the iterator.
  20102. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  20103. + void **data,
  20104. + uint32_t *msg_size );
  20105. +
  20106. +// Remove the last message returned by vchi_msg_iter_next.
  20107. +// Can only be called once after each call to vchi_msg_iter_next.
  20108. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  20109. +
  20110. +// Hold the last message returned by vchi_msg_iter_next.
  20111. +// Can only be called once after each call to vchi_msg_iter_next.
  20112. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  20113. + VCHI_HELD_MSG_T *message );
  20114. +
  20115. +// Return information for the next message, and hold it, advancing the iterator.
  20116. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  20117. + void **data, // } may be NULL
  20118. + uint32_t *msg_size, // }
  20119. + VCHI_HELD_MSG_T *message );
  20120. +
  20121. +
  20122. +/******************************************************************************
  20123. + Global bulk API
  20124. + *****************************************************************************/
  20125. +
  20126. +// Routine to prepare interface for a transfer from the other side
  20127. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  20128. + void *data_dst,
  20129. + uint32_t data_size,
  20130. + VCHI_FLAGS_T flags,
  20131. + void *transfer_handle );
  20132. +
  20133. +
  20134. +// Prepare interface for a transfer from the other side into relocatable memory.
  20135. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  20136. + VCHI_MEM_HANDLE_T h_dst,
  20137. + uint32_t offset,
  20138. + uint32_t data_size,
  20139. + const VCHI_FLAGS_T flags,
  20140. + void * const bulk_handle );
  20141. +
  20142. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  20143. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  20144. + const void *data_src,
  20145. + uint32_t data_size,
  20146. + VCHI_FLAGS_T flags,
  20147. + void *transfer_handle );
  20148. +
  20149. +
  20150. +/******************************************************************************
  20151. + Configuration plumbing
  20152. + *****************************************************************************/
  20153. +
  20154. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  20155. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  20156. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  20157. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  20158. +
  20159. +// declare all message drivers here
  20160. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  20161. +
  20162. +#ifdef __cplusplus
  20163. +}
  20164. +#endif
  20165. +
  20166. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  20167. + VCHI_MEM_HANDLE_T h_src,
  20168. + uint32_t offset,
  20169. + uint32_t data_size,
  20170. + VCHI_FLAGS_T flags,
  20171. + void *transfer_handle );
  20172. +#endif /* VCHI_H_ */
  20173. +
  20174. +/****************************** End of file **********************************/
  20175. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  20176. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  20177. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-03-13 12:46:20.596060066 +0100
  20178. @@ -0,0 +1,42 @@
  20179. +/**
  20180. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20181. + *
  20182. + * Redistribution and use in source and binary forms, with or without
  20183. + * modification, are permitted provided that the following conditions
  20184. + * are met:
  20185. + * 1. Redistributions of source code must retain the above copyright
  20186. + * notice, this list of conditions, and the following disclaimer,
  20187. + * without modification.
  20188. + * 2. Redistributions in binary form must reproduce the above copyright
  20189. + * notice, this list of conditions and the following disclaimer in the
  20190. + * documentation and/or other materials provided with the distribution.
  20191. + * 3. The names of the above-listed copyright holders may not be used
  20192. + * to endorse or promote products derived from this software without
  20193. + * specific prior written permission.
  20194. + *
  20195. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20196. + * GNU General Public License ("GPL") version 2, as published by the Free
  20197. + * Software Foundation.
  20198. + *
  20199. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20200. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20201. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20202. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20203. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20204. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20205. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20206. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20207. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20208. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20209. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20210. + */
  20211. +
  20212. +#ifndef VCHI_MH_H_
  20213. +#define VCHI_MH_H_
  20214. +
  20215. +#include <linux/types.h>
  20216. +
  20217. +typedef int32_t VCHI_MEM_HANDLE_T;
  20218. +#define VCHI_MEM_HANDLE_INVALID 0
  20219. +
  20220. +#endif
  20221. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  20222. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  20223. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-03-13 12:46:20.596060066 +0100
  20224. @@ -0,0 +1,561 @@
  20225. +/**
  20226. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20227. + *
  20228. + * Redistribution and use in source and binary forms, with or without
  20229. + * modification, are permitted provided that the following conditions
  20230. + * are met:
  20231. + * 1. Redistributions of source code must retain the above copyright
  20232. + * notice, this list of conditions, and the following disclaimer,
  20233. + * without modification.
  20234. + * 2. Redistributions in binary form must reproduce the above copyright
  20235. + * notice, this list of conditions and the following disclaimer in the
  20236. + * documentation and/or other materials provided with the distribution.
  20237. + * 3. The names of the above-listed copyright holders may not be used
  20238. + * to endorse or promote products derived from this software without
  20239. + * specific prior written permission.
  20240. + *
  20241. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20242. + * GNU General Public License ("GPL") version 2, as published by the Free
  20243. + * Software Foundation.
  20244. + *
  20245. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20246. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20247. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20248. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20249. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20250. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20251. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20252. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20253. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20254. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20255. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20256. + */
  20257. +
  20258. +#include <linux/kernel.h>
  20259. +#include <linux/types.h>
  20260. +#include <linux/errno.h>
  20261. +#include <linux/interrupt.h>
  20262. +#include <linux/irq.h>
  20263. +#include <linux/pagemap.h>
  20264. +#include <linux/dma-mapping.h>
  20265. +#include <linux/version.h>
  20266. +#include <linux/io.h>
  20267. +#include <linux/uaccess.h>
  20268. +#include <asm/pgtable.h>
  20269. +
  20270. +#include <mach/irqs.h>
  20271. +
  20272. +#include <mach/platform.h>
  20273. +#include <mach/vcio.h>
  20274. +
  20275. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  20276. +
  20277. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  20278. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  20279. +
  20280. +#include "vchiq_arm.h"
  20281. +#include "vchiq_2835.h"
  20282. +#include "vchiq_connected.h"
  20283. +
  20284. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  20285. +
  20286. +typedef struct vchiq_2835_state_struct {
  20287. + int inited;
  20288. + VCHIQ_ARM_STATE_T arm_state;
  20289. +} VCHIQ_2835_ARM_STATE_T;
  20290. +
  20291. +static char *g_slot_mem;
  20292. +static int g_slot_mem_size;
  20293. +dma_addr_t g_slot_phys;
  20294. +static FRAGMENTS_T *g_fragments_base;
  20295. +static FRAGMENTS_T *g_free_fragments;
  20296. +struct semaphore g_free_fragments_sema;
  20297. +
  20298. +extern int vchiq_arm_log_level;
  20299. +
  20300. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  20301. +
  20302. +static irqreturn_t
  20303. +vchiq_doorbell_irq(int irq, void *dev_id);
  20304. +
  20305. +static int
  20306. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  20307. + struct task_struct *task, PAGELIST_T ** ppagelist);
  20308. +
  20309. +static void
  20310. +free_pagelist(PAGELIST_T *pagelist, int actual);
  20311. +
  20312. +int __init
  20313. +vchiq_platform_init(VCHIQ_STATE_T *state)
  20314. +{
  20315. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  20316. + int frag_mem_size;
  20317. + int err;
  20318. + int i;
  20319. +
  20320. + /* Allocate space for the channels in coherent memory */
  20321. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  20322. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  20323. +
  20324. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  20325. + &g_slot_phys, GFP_ATOMIC);
  20326. +
  20327. + if (!g_slot_mem) {
  20328. + vchiq_log_error(vchiq_arm_log_level,
  20329. + "Unable to allocate channel memory");
  20330. + err = -ENOMEM;
  20331. + goto failed_alloc;
  20332. + }
  20333. +
  20334. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  20335. +
  20336. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  20337. + if (!vchiq_slot_zero) {
  20338. + err = -EINVAL;
  20339. + goto failed_init_slots;
  20340. + }
  20341. +
  20342. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  20343. + (int)g_slot_phys + g_slot_mem_size;
  20344. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  20345. + MAX_FRAGMENTS;
  20346. +
  20347. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  20348. + g_slot_mem_size += frag_mem_size;
  20349. +
  20350. + g_free_fragments = g_fragments_base;
  20351. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  20352. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  20353. + &g_fragments_base[i + 1];
  20354. + }
  20355. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  20356. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  20357. +
  20358. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  20359. + VCHIQ_SUCCESS) {
  20360. + err = -EINVAL;
  20361. + goto failed_vchiq_init;
  20362. + }
  20363. +
  20364. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  20365. + IRQF_IRQPOLL, "VCHIQ doorbell",
  20366. + state);
  20367. + if (err < 0) {
  20368. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  20369. + "irq=%d err=%d", __func__,
  20370. + VCHIQ_DOORBELL_IRQ, err);
  20371. + goto failed_request_irq;
  20372. + }
  20373. +
  20374. + /* Send the base address of the slots to VideoCore */
  20375. +
  20376. + dsb(); /* Ensure all writes have completed */
  20377. +
  20378. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  20379. +
  20380. + vchiq_log_info(vchiq_arm_log_level,
  20381. + "vchiq_init - done (slots %x, phys %x)",
  20382. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  20383. +
  20384. + vchiq_call_connected_callbacks();
  20385. +
  20386. + return 0;
  20387. +
  20388. +failed_request_irq:
  20389. +failed_vchiq_init:
  20390. +failed_init_slots:
  20391. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  20392. +
  20393. +failed_alloc:
  20394. + return err;
  20395. +}
  20396. +
  20397. +void __exit
  20398. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  20399. +{
  20400. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  20401. + dma_free_coherent(NULL, g_slot_mem_size,
  20402. + g_slot_mem, g_slot_phys);
  20403. +}
  20404. +
  20405. +
  20406. +VCHIQ_STATUS_T
  20407. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  20408. +{
  20409. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20410. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  20411. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  20412. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  20413. + if(status != VCHIQ_SUCCESS)
  20414. + {
  20415. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  20416. + }
  20417. + return status;
  20418. +}
  20419. +
  20420. +VCHIQ_ARM_STATE_T*
  20421. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  20422. +{
  20423. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  20424. + {
  20425. + BUG();
  20426. + }
  20427. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  20428. +}
  20429. +
  20430. +void
  20431. +remote_event_signal(REMOTE_EVENT_T *event)
  20432. +{
  20433. + wmb();
  20434. +
  20435. + event->fired = 1;
  20436. +
  20437. + dsb(); /* data barrier operation */
  20438. +
  20439. + if (event->armed) {
  20440. + /* trigger vc interrupt */
  20441. +
  20442. + writel(0, __io_address(ARM_0_BELL2));
  20443. + }
  20444. +}
  20445. +
  20446. +int
  20447. +vchiq_copy_from_user(void *dst, const void *src, int size)
  20448. +{
  20449. + if ((uint32_t)src < TASK_SIZE) {
  20450. + return copy_from_user(dst, src, size);
  20451. + } else {
  20452. + memcpy(dst, src, size);
  20453. + return 0;
  20454. + }
  20455. +}
  20456. +
  20457. +VCHIQ_STATUS_T
  20458. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  20459. + void *offset, int size, int dir)
  20460. +{
  20461. + PAGELIST_T *pagelist;
  20462. + int ret;
  20463. +
  20464. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  20465. +
  20466. + ret = create_pagelist((char __user *)offset, size,
  20467. + (dir == VCHIQ_BULK_RECEIVE)
  20468. + ? PAGELIST_READ
  20469. + : PAGELIST_WRITE,
  20470. + current,
  20471. + &pagelist);
  20472. + if (ret != 0)
  20473. + return VCHIQ_ERROR;
  20474. +
  20475. + bulk->handle = memhandle;
  20476. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  20477. +
  20478. + /* Store the pagelist address in remote_data, which isn't used by the
  20479. + slave. */
  20480. + bulk->remote_data = pagelist;
  20481. +
  20482. + return VCHIQ_SUCCESS;
  20483. +}
  20484. +
  20485. +void
  20486. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  20487. +{
  20488. + if (bulk && bulk->remote_data && bulk->actual)
  20489. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  20490. +}
  20491. +
  20492. +void
  20493. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  20494. +{
  20495. + /*
  20496. + * This should only be called on the master (VideoCore) side, but
  20497. + * provide an implementation to avoid the need for ifdefery.
  20498. + */
  20499. + BUG();
  20500. +}
  20501. +
  20502. +void
  20503. +vchiq_dump_platform_state(void *dump_context)
  20504. +{
  20505. + char buf[80];
  20506. + int len;
  20507. + len = snprintf(buf, sizeof(buf),
  20508. + " Platform: 2835 (VC master)");
  20509. + vchiq_dump(dump_context, buf, len + 1);
  20510. +}
  20511. +
  20512. +VCHIQ_STATUS_T
  20513. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  20514. +{
  20515. + return VCHIQ_ERROR;
  20516. +}
  20517. +
  20518. +VCHIQ_STATUS_T
  20519. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  20520. +{
  20521. + return VCHIQ_SUCCESS;
  20522. +}
  20523. +
  20524. +void
  20525. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  20526. +{
  20527. +}
  20528. +
  20529. +void
  20530. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  20531. +{
  20532. +}
  20533. +
  20534. +int
  20535. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  20536. +{
  20537. + return 1; // autosuspend not supported - videocore always wanted
  20538. +}
  20539. +
  20540. +int
  20541. +vchiq_platform_use_suspend_timer(void)
  20542. +{
  20543. + return 0;
  20544. +}
  20545. +void
  20546. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  20547. +{
  20548. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  20549. +}
  20550. +void
  20551. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  20552. +{
  20553. + (void)state;
  20554. +}
  20555. +/*
  20556. + * Local functions
  20557. + */
  20558. +
  20559. +static irqreturn_t
  20560. +vchiq_doorbell_irq(int irq, void *dev_id)
  20561. +{
  20562. + VCHIQ_STATE_T *state = dev_id;
  20563. + irqreturn_t ret = IRQ_NONE;
  20564. + unsigned int status;
  20565. +
  20566. + /* Read (and clear) the doorbell */
  20567. + status = readl(__io_address(ARM_0_BELL0));
  20568. +
  20569. + if (status & 0x4) { /* Was the doorbell rung? */
  20570. + remote_event_pollall(state);
  20571. + ret = IRQ_HANDLED;
  20572. + }
  20573. +
  20574. + return ret;
  20575. +}
  20576. +
  20577. +/* There is a potential problem with partial cache lines (pages?)
  20578. +** at the ends of the block when reading. If the CPU accessed anything in
  20579. +** the same line (page?) then it may have pulled old data into the cache,
  20580. +** obscuring the new data underneath. We can solve this by transferring the
  20581. +** partial cache lines separately, and allowing the ARM to copy into the
  20582. +** cached area.
  20583. +
  20584. +** N.B. This implementation plays slightly fast and loose with the Linux
  20585. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  20586. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  20587. +** from increased speed as a result.
  20588. +*/
  20589. +
  20590. +static int
  20591. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  20592. + struct task_struct *task, PAGELIST_T ** ppagelist)
  20593. +{
  20594. + PAGELIST_T *pagelist;
  20595. + struct page **pages;
  20596. + struct page *page;
  20597. + unsigned long *addrs;
  20598. + unsigned int num_pages, offset, i;
  20599. + char *addr, *base_addr, *next_addr;
  20600. + int run, addridx, actual_pages;
  20601. + unsigned long *need_release;
  20602. +
  20603. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  20604. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  20605. +
  20606. + *ppagelist = NULL;
  20607. +
  20608. + /* Allocate enough storage to hold the page pointers and the page
  20609. + ** list
  20610. + */
  20611. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  20612. + (num_pages * sizeof(unsigned long)) +
  20613. + sizeof(unsigned long) +
  20614. + (num_pages * sizeof(pages[0])),
  20615. + GFP_KERNEL);
  20616. +
  20617. + vchiq_log_trace(vchiq_arm_log_level,
  20618. + "create_pagelist - %x", (unsigned int)pagelist);
  20619. + if (!pagelist)
  20620. + return -ENOMEM;
  20621. +
  20622. + addrs = pagelist->addrs;
  20623. + need_release = (unsigned long *)(addrs + num_pages);
  20624. + pages = (struct page **)(addrs + num_pages + 1);
  20625. +
  20626. + if (is_vmalloc_addr(buf)) {
  20627. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  20628. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  20629. + }
  20630. + *need_release = 0; /* do not try and release vmalloc pages */
  20631. + } else {
  20632. + down_read(&task->mm->mmap_sem);
  20633. + actual_pages = get_user_pages(task, task->mm,
  20634. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  20635. + num_pages,
  20636. + (type == PAGELIST_READ) /*Write */ ,
  20637. + 0 /*Force */ ,
  20638. + pages,
  20639. + NULL /*vmas */);
  20640. + up_read(&task->mm->mmap_sem);
  20641. +
  20642. + if (actual_pages != num_pages) {
  20643. + vchiq_log_info(vchiq_arm_log_level,
  20644. + "create_pagelist - only %d/%d pages locked",
  20645. + actual_pages,
  20646. + num_pages);
  20647. +
  20648. + /* This is probably due to the process being killed */
  20649. + while (actual_pages > 0)
  20650. + {
  20651. + actual_pages--;
  20652. + page_cache_release(pages[actual_pages]);
  20653. + }
  20654. + kfree(pagelist);
  20655. + if (actual_pages == 0)
  20656. + actual_pages = -ENOMEM;
  20657. + return actual_pages;
  20658. + }
  20659. + *need_release = 1; /* release user pages */
  20660. + }
  20661. +
  20662. + pagelist->length = count;
  20663. + pagelist->type = type;
  20664. + pagelist->offset = offset;
  20665. +
  20666. + /* Group the pages into runs of contiguous pages */
  20667. +
  20668. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  20669. + next_addr = base_addr + PAGE_SIZE;
  20670. + addridx = 0;
  20671. + run = 0;
  20672. +
  20673. + for (i = 1; i < num_pages; i++) {
  20674. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  20675. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  20676. + next_addr += PAGE_SIZE;
  20677. + run++;
  20678. + } else {
  20679. + addrs[addridx] = (unsigned long)base_addr + run;
  20680. + addridx++;
  20681. + base_addr = addr;
  20682. + next_addr = addr + PAGE_SIZE;
  20683. + run = 0;
  20684. + }
  20685. + }
  20686. +
  20687. + addrs[addridx] = (unsigned long)base_addr + run;
  20688. + addridx++;
  20689. +
  20690. + /* Partial cache lines (fragments) require special measures */
  20691. + if ((type == PAGELIST_READ) &&
  20692. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  20693. + ((pagelist->offset + pagelist->length) &
  20694. + (CACHE_LINE_SIZE - 1)))) {
  20695. + FRAGMENTS_T *fragments;
  20696. +
  20697. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  20698. + kfree(pagelist);
  20699. + return -EINTR;
  20700. + }
  20701. +
  20702. + WARN_ON(g_free_fragments == NULL);
  20703. +
  20704. + down(&g_free_fragments_mutex);
  20705. + fragments = (FRAGMENTS_T *) g_free_fragments;
  20706. + WARN_ON(fragments == NULL);
  20707. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  20708. + up(&g_free_fragments_mutex);
  20709. + pagelist->type =
  20710. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  20711. + g_fragments_base);
  20712. + }
  20713. +
  20714. + for (page = virt_to_page(pagelist);
  20715. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  20716. + flush_dcache_page(page);
  20717. + }
  20718. +
  20719. + *ppagelist = pagelist;
  20720. +
  20721. + return 0;
  20722. +}
  20723. +
  20724. +static void
  20725. +free_pagelist(PAGELIST_T *pagelist, int actual)
  20726. +{
  20727. + unsigned long *need_release;
  20728. + struct page **pages;
  20729. + unsigned int num_pages, i;
  20730. +
  20731. + vchiq_log_trace(vchiq_arm_log_level,
  20732. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  20733. +
  20734. + num_pages =
  20735. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  20736. + PAGE_SIZE;
  20737. +
  20738. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  20739. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  20740. +
  20741. + /* Deal with any partial cache lines (fragments) */
  20742. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  20743. + FRAGMENTS_T *fragments = g_fragments_base +
  20744. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  20745. + int head_bytes, tail_bytes;
  20746. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  20747. + (CACHE_LINE_SIZE - 1);
  20748. + tail_bytes = (pagelist->offset + actual) &
  20749. + (CACHE_LINE_SIZE - 1);
  20750. +
  20751. + if ((actual >= 0) && (head_bytes != 0)) {
  20752. + if (head_bytes > actual)
  20753. + head_bytes = actual;
  20754. +
  20755. + memcpy((char *)page_address(pages[0]) +
  20756. + pagelist->offset,
  20757. + fragments->headbuf,
  20758. + head_bytes);
  20759. + }
  20760. + if ((actual >= 0) && (head_bytes < actual) &&
  20761. + (tail_bytes != 0)) {
  20762. + memcpy((char *)page_address(pages[num_pages - 1]) +
  20763. + ((pagelist->offset + actual) &
  20764. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  20765. + fragments->tailbuf, tail_bytes);
  20766. + }
  20767. +
  20768. + down(&g_free_fragments_mutex);
  20769. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  20770. + g_free_fragments = fragments;
  20771. + up(&g_free_fragments_mutex);
  20772. + up(&g_free_fragments_sema);
  20773. + }
  20774. +
  20775. + if (*need_release) {
  20776. + for (i = 0; i < num_pages; i++) {
  20777. + if (pagelist->type != PAGELIST_WRITE)
  20778. + set_page_dirty(pages[i]);
  20779. +
  20780. + page_cache_release(pages[i]);
  20781. + }
  20782. + }
  20783. +
  20784. + kfree(pagelist);
  20785. +}
  20786. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  20787. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  20788. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-03-13 12:46:20.596060066 +0100
  20789. @@ -0,0 +1,42 @@
  20790. +/**
  20791. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20792. + *
  20793. + * Redistribution and use in source and binary forms, with or without
  20794. + * modification, are permitted provided that the following conditions
  20795. + * are met:
  20796. + * 1. Redistributions of source code must retain the above copyright
  20797. + * notice, this list of conditions, and the following disclaimer,
  20798. + * without modification.
  20799. + * 2. Redistributions in binary form must reproduce the above copyright
  20800. + * notice, this list of conditions and the following disclaimer in the
  20801. + * documentation and/or other materials provided with the distribution.
  20802. + * 3. The names of the above-listed copyright holders may not be used
  20803. + * to endorse or promote products derived from this software without
  20804. + * specific prior written permission.
  20805. + *
  20806. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20807. + * GNU General Public License ("GPL") version 2, as published by the Free
  20808. + * Software Foundation.
  20809. + *
  20810. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20811. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20812. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20813. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20814. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20815. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20816. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20817. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20818. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20819. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20820. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20821. + */
  20822. +
  20823. +#ifndef VCHIQ_2835_H
  20824. +#define VCHIQ_2835_H
  20825. +
  20826. +#include "vchiq_pagelist.h"
  20827. +
  20828. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  20829. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  20830. +
  20831. +#endif /* VCHIQ_2835_H */
  20832. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  20833. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  20834. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-03-13 12:46:20.596060066 +0100
  20835. @@ -0,0 +1,2813 @@
  20836. +/**
  20837. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20838. + *
  20839. + * Redistribution and use in source and binary forms, with or without
  20840. + * modification, are permitted provided that the following conditions
  20841. + * are met:
  20842. + * 1. Redistributions of source code must retain the above copyright
  20843. + * notice, this list of conditions, and the following disclaimer,
  20844. + * without modification.
  20845. + * 2. Redistributions in binary form must reproduce the above copyright
  20846. + * notice, this list of conditions and the following disclaimer in the
  20847. + * documentation and/or other materials provided with the distribution.
  20848. + * 3. The names of the above-listed copyright holders may not be used
  20849. + * to endorse or promote products derived from this software without
  20850. + * specific prior written permission.
  20851. + *
  20852. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20853. + * GNU General Public License ("GPL") version 2, as published by the Free
  20854. + * Software Foundation.
  20855. + *
  20856. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20857. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20858. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20859. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20860. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20861. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20862. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20863. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20864. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20865. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20866. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20867. + */
  20868. +
  20869. +#include <linux/kernel.h>
  20870. +#include <linux/module.h>
  20871. +#include <linux/types.h>
  20872. +#include <linux/errno.h>
  20873. +#include <linux/cdev.h>
  20874. +#include <linux/fs.h>
  20875. +#include <linux/device.h>
  20876. +#include <linux/mm.h>
  20877. +#include <linux/highmem.h>
  20878. +#include <linux/pagemap.h>
  20879. +#include <linux/bug.h>
  20880. +#include <linux/semaphore.h>
  20881. +#include <linux/list.h>
  20882. +#include <linux/proc_fs.h>
  20883. +
  20884. +#include "vchiq_core.h"
  20885. +#include "vchiq_ioctl.h"
  20886. +#include "vchiq_arm.h"
  20887. +
  20888. +#define DEVICE_NAME "vchiq"
  20889. +
  20890. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  20891. +#undef MODULE_PARAM_PREFIX
  20892. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  20893. +
  20894. +#define VCHIQ_MINOR 0
  20895. +
  20896. +/* Some per-instance constants */
  20897. +#define MAX_COMPLETIONS 16
  20898. +#define MAX_SERVICES 64
  20899. +#define MAX_ELEMENTS 8
  20900. +#define MSG_QUEUE_SIZE 64
  20901. +
  20902. +#define KEEPALIVE_VER 1
  20903. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  20904. +
  20905. +/* Run time control of log level, based on KERN_XXX level. */
  20906. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  20907. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  20908. +
  20909. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  20910. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  20911. +
  20912. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  20913. +static const char *const suspend_state_names[] = {
  20914. + "VC_SUSPEND_FORCE_CANCELED",
  20915. + "VC_SUSPEND_REJECTED",
  20916. + "VC_SUSPEND_FAILED",
  20917. + "VC_SUSPEND_IDLE",
  20918. + "VC_SUSPEND_REQUESTED",
  20919. + "VC_SUSPEND_IN_PROGRESS",
  20920. + "VC_SUSPEND_SUSPENDED"
  20921. +};
  20922. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  20923. +static const char *const resume_state_names[] = {
  20924. + "VC_RESUME_FAILED",
  20925. + "VC_RESUME_IDLE",
  20926. + "VC_RESUME_REQUESTED",
  20927. + "VC_RESUME_IN_PROGRESS",
  20928. + "VC_RESUME_RESUMED"
  20929. +};
  20930. +/* The number of times we allow force suspend to timeout before actually
  20931. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  20932. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  20933. +*/
  20934. +#define FORCE_SUSPEND_FAIL_MAX 8
  20935. +
  20936. +/* The time in ms allowed for videocore to go idle when force suspend has been
  20937. + * requested */
  20938. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  20939. +
  20940. +
  20941. +static void suspend_timer_callback(unsigned long context);
  20942. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  20943. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  20944. +
  20945. +
  20946. +typedef struct user_service_struct {
  20947. + VCHIQ_SERVICE_T *service;
  20948. + void *userdata;
  20949. + VCHIQ_INSTANCE_T instance;
  20950. + int is_vchi;
  20951. + int dequeue_pending;
  20952. + int message_available_pos;
  20953. + int msg_insert;
  20954. + int msg_remove;
  20955. + struct semaphore insert_event;
  20956. + struct semaphore remove_event;
  20957. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  20958. +} USER_SERVICE_T;
  20959. +
  20960. +struct bulk_waiter_node {
  20961. + struct bulk_waiter bulk_waiter;
  20962. + int pid;
  20963. + struct list_head list;
  20964. +};
  20965. +
  20966. +struct vchiq_instance_struct {
  20967. + VCHIQ_STATE_T *state;
  20968. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  20969. + int completion_insert;
  20970. + int completion_remove;
  20971. + struct semaphore insert_event;
  20972. + struct semaphore remove_event;
  20973. + struct mutex completion_mutex;
  20974. +
  20975. + int connected;
  20976. + int closing;
  20977. + int pid;
  20978. + int mark;
  20979. +
  20980. + struct list_head bulk_waiter_list;
  20981. + struct mutex bulk_waiter_list_mutex;
  20982. +
  20983. + struct proc_dir_entry *proc_entry;
  20984. +};
  20985. +
  20986. +typedef struct dump_context_struct {
  20987. + char __user *buf;
  20988. + size_t actual;
  20989. + size_t space;
  20990. + loff_t offset;
  20991. +} DUMP_CONTEXT_T;
  20992. +
  20993. +static struct cdev vchiq_cdev;
  20994. +static dev_t vchiq_devid;
  20995. +static VCHIQ_STATE_T g_state;
  20996. +static struct class *vchiq_class;
  20997. +static struct device *vchiq_dev;
  20998. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  20999. +
  21000. +static const char *const ioctl_names[] = {
  21001. + "CONNECT",
  21002. + "SHUTDOWN",
  21003. + "CREATE_SERVICE",
  21004. + "REMOVE_SERVICE",
  21005. + "QUEUE_MESSAGE",
  21006. + "QUEUE_BULK_TRANSMIT",
  21007. + "QUEUE_BULK_RECEIVE",
  21008. + "AWAIT_COMPLETION",
  21009. + "DEQUEUE_MESSAGE",
  21010. + "GET_CLIENT_ID",
  21011. + "GET_CONFIG",
  21012. + "CLOSE_SERVICE",
  21013. + "USE_SERVICE",
  21014. + "RELEASE_SERVICE",
  21015. + "SET_SERVICE_OPTION",
  21016. + "DUMP_PHYS_MEM"
  21017. +};
  21018. +
  21019. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  21020. + (VCHIQ_IOC_MAX + 1));
  21021. +
  21022. +static void
  21023. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  21024. +
  21025. +/****************************************************************************
  21026. +*
  21027. +* add_completion
  21028. +*
  21029. +***************************************************************************/
  21030. +
  21031. +static VCHIQ_STATUS_T
  21032. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  21033. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  21034. + void *bulk_userdata)
  21035. +{
  21036. + VCHIQ_COMPLETION_DATA_T *completion;
  21037. + DEBUG_INITIALISE(g_state.local)
  21038. +
  21039. + while (instance->completion_insert ==
  21040. + (instance->completion_remove + MAX_COMPLETIONS)) {
  21041. + /* Out of space - wait for the client */
  21042. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21043. + vchiq_log_trace(vchiq_arm_log_level,
  21044. + "add_completion - completion queue full");
  21045. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  21046. + if (down_interruptible(&instance->remove_event) != 0) {
  21047. + vchiq_log_info(vchiq_arm_log_level,
  21048. + "service_callback interrupted");
  21049. + return VCHIQ_RETRY;
  21050. + } else if (instance->closing) {
  21051. + vchiq_log_info(vchiq_arm_log_level,
  21052. + "service_callback closing");
  21053. + return VCHIQ_ERROR;
  21054. + }
  21055. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21056. + }
  21057. +
  21058. + completion =
  21059. + &instance->completions[instance->completion_insert &
  21060. + (MAX_COMPLETIONS - 1)];
  21061. +
  21062. + completion->header = header;
  21063. + completion->reason = reason;
  21064. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  21065. + completion->service_userdata = user_service->service;
  21066. + completion->bulk_userdata = bulk_userdata;
  21067. +
  21068. + if (reason == VCHIQ_SERVICE_CLOSED)
  21069. + /* Take an extra reference, to be held until
  21070. + this CLOSED notification is delivered. */
  21071. + lock_service(user_service->service);
  21072. +
  21073. + /* A write barrier is needed here to ensure that the entire completion
  21074. + record is written out before the insert point. */
  21075. + wmb();
  21076. +
  21077. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  21078. + user_service->message_available_pos =
  21079. + instance->completion_insert;
  21080. + instance->completion_insert++;
  21081. +
  21082. + up(&instance->insert_event);
  21083. +
  21084. + return VCHIQ_SUCCESS;
  21085. +}
  21086. +
  21087. +/****************************************************************************
  21088. +*
  21089. +* service_callback
  21090. +*
  21091. +***************************************************************************/
  21092. +
  21093. +static VCHIQ_STATUS_T
  21094. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  21095. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  21096. +{
  21097. + /* How do we ensure the callback goes to the right client?
  21098. + ** The service_user data points to a USER_SERVICE_T record containing
  21099. + ** the original callback and the user state structure, which contains a
  21100. + ** circular buffer for completion records.
  21101. + */
  21102. + USER_SERVICE_T *user_service;
  21103. + VCHIQ_SERVICE_T *service;
  21104. + VCHIQ_INSTANCE_T instance;
  21105. + DEBUG_INITIALISE(g_state.local)
  21106. +
  21107. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21108. +
  21109. + service = handle_to_service(handle);
  21110. + BUG_ON(!service);
  21111. + user_service = (USER_SERVICE_T *)service->base.userdata;
  21112. + instance = user_service->instance;
  21113. +
  21114. + if (!instance || instance->closing)
  21115. + return VCHIQ_SUCCESS;
  21116. +
  21117. + vchiq_log_trace(vchiq_arm_log_level,
  21118. + "service_callback - service %lx(%d), reason %d, header %lx, "
  21119. + "instance %lx, bulk_userdata %lx",
  21120. + (unsigned long)user_service,
  21121. + service->localport,
  21122. + reason, (unsigned long)header,
  21123. + (unsigned long)instance, (unsigned long)bulk_userdata);
  21124. +
  21125. + if (header && user_service->is_vchi) {
  21126. + spin_lock(&msg_queue_spinlock);
  21127. + while (user_service->msg_insert ==
  21128. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  21129. + spin_unlock(&msg_queue_spinlock);
  21130. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21131. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  21132. + vchiq_log_trace(vchiq_arm_log_level,
  21133. + "service_callback - msg queue full");
  21134. + /* If there is no MESSAGE_AVAILABLE in the completion
  21135. + ** queue, add one
  21136. + */
  21137. + if ((user_service->message_available_pos -
  21138. + instance->completion_remove) < 0) {
  21139. + VCHIQ_STATUS_T status;
  21140. + vchiq_log_info(vchiq_arm_log_level,
  21141. + "Inserting extra MESSAGE_AVAILABLE");
  21142. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21143. + status = add_completion(instance, reason,
  21144. + NULL, user_service, bulk_userdata);
  21145. + if (status != VCHIQ_SUCCESS) {
  21146. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21147. + return status;
  21148. + }
  21149. + }
  21150. +
  21151. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21152. + if (down_interruptible(&user_service->remove_event)
  21153. + != 0) {
  21154. + vchiq_log_info(vchiq_arm_log_level,
  21155. + "service_callback interrupted");
  21156. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21157. + return VCHIQ_RETRY;
  21158. + } else if (instance->closing) {
  21159. + vchiq_log_info(vchiq_arm_log_level,
  21160. + "service_callback closing");
  21161. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21162. + return VCHIQ_ERROR;
  21163. + }
  21164. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21165. + spin_lock(&msg_queue_spinlock);
  21166. + }
  21167. +
  21168. + user_service->msg_queue[user_service->msg_insert &
  21169. + (MSG_QUEUE_SIZE - 1)] = header;
  21170. + user_service->msg_insert++;
  21171. + spin_unlock(&msg_queue_spinlock);
  21172. +
  21173. + up(&user_service->insert_event);
  21174. +
  21175. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  21176. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  21177. + ** bypass the completion queue.
  21178. + */
  21179. + if (((user_service->message_available_pos -
  21180. + instance->completion_remove) >= 0) ||
  21181. + user_service->dequeue_pending) {
  21182. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21183. + user_service->dequeue_pending = 0;
  21184. + return VCHIQ_SUCCESS;
  21185. + }
  21186. +
  21187. + header = NULL;
  21188. + }
  21189. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21190. +
  21191. + return add_completion(instance, reason, header, user_service,
  21192. + bulk_userdata);
  21193. +}
  21194. +
  21195. +/****************************************************************************
  21196. +*
  21197. +* user_service_free
  21198. +*
  21199. +***************************************************************************/
  21200. +static void
  21201. +user_service_free(void *userdata)
  21202. +{
  21203. + kfree(userdata);
  21204. +}
  21205. +
  21206. +/****************************************************************************
  21207. +*
  21208. +* vchiq_ioctl
  21209. +*
  21210. +***************************************************************************/
  21211. +
  21212. +static long
  21213. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  21214. +{
  21215. + VCHIQ_INSTANCE_T instance = file->private_data;
  21216. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21217. + VCHIQ_SERVICE_T *service = NULL;
  21218. + long ret = 0;
  21219. + int i, rc;
  21220. + DEBUG_INITIALISE(g_state.local)
  21221. +
  21222. + vchiq_log_trace(vchiq_arm_log_level,
  21223. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  21224. + (unsigned int)instance,
  21225. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  21226. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  21227. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  21228. +
  21229. + switch (cmd) {
  21230. + case VCHIQ_IOC_SHUTDOWN:
  21231. + if (!instance->connected)
  21232. + break;
  21233. +
  21234. + /* Remove all services */
  21235. + i = 0;
  21236. + while ((service = next_service_by_instance(instance->state,
  21237. + instance, &i)) != NULL) {
  21238. + status = vchiq_remove_service(service->handle);
  21239. + unlock_service(service);
  21240. + if (status != VCHIQ_SUCCESS)
  21241. + break;
  21242. + }
  21243. + service = NULL;
  21244. +
  21245. + if (status == VCHIQ_SUCCESS) {
  21246. + /* Wake the completion thread and ask it to exit */
  21247. + instance->closing = 1;
  21248. + up(&instance->insert_event);
  21249. + }
  21250. +
  21251. + break;
  21252. +
  21253. + case VCHIQ_IOC_CONNECT:
  21254. + if (instance->connected) {
  21255. + ret = -EINVAL;
  21256. + break;
  21257. + }
  21258. + rc = mutex_lock_interruptible(&instance->state->mutex);
  21259. + if (rc != 0) {
  21260. + vchiq_log_error(vchiq_arm_log_level,
  21261. + "vchiq: connect: could not lock mutex for "
  21262. + "state %d: %d",
  21263. + instance->state->id, rc);
  21264. + ret = -EINTR;
  21265. + break;
  21266. + }
  21267. + status = vchiq_connect_internal(instance->state, instance);
  21268. + mutex_unlock(&instance->state->mutex);
  21269. +
  21270. + if (status == VCHIQ_SUCCESS)
  21271. + instance->connected = 1;
  21272. + else
  21273. + vchiq_log_error(vchiq_arm_log_level,
  21274. + "vchiq: could not connect: %d", status);
  21275. + break;
  21276. +
  21277. + case VCHIQ_IOC_CREATE_SERVICE: {
  21278. + VCHIQ_CREATE_SERVICE_T args;
  21279. + USER_SERVICE_T *user_service = NULL;
  21280. + void *userdata;
  21281. + int srvstate;
  21282. +
  21283. + if (copy_from_user
  21284. + (&args, (const void __user *)arg,
  21285. + sizeof(args)) != 0) {
  21286. + ret = -EFAULT;
  21287. + break;
  21288. + }
  21289. +
  21290. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  21291. + if (!user_service) {
  21292. + ret = -ENOMEM;
  21293. + break;
  21294. + }
  21295. +
  21296. + if (args.is_open) {
  21297. + if (!instance->connected) {
  21298. + ret = -ENOTCONN;
  21299. + kfree(user_service);
  21300. + break;
  21301. + }
  21302. + srvstate = VCHIQ_SRVSTATE_OPENING;
  21303. + } else {
  21304. + srvstate =
  21305. + instance->connected ?
  21306. + VCHIQ_SRVSTATE_LISTENING :
  21307. + VCHIQ_SRVSTATE_HIDDEN;
  21308. + }
  21309. +
  21310. + userdata = args.params.userdata;
  21311. + args.params.callback = service_callback;
  21312. + args.params.userdata = user_service;
  21313. + service = vchiq_add_service_internal(
  21314. + instance->state,
  21315. + &args.params, srvstate,
  21316. + instance, user_service_free);
  21317. +
  21318. + if (service != NULL) {
  21319. + user_service->service = service;
  21320. + user_service->userdata = userdata;
  21321. + user_service->instance = instance;
  21322. + user_service->is_vchi = args.is_vchi;
  21323. + user_service->dequeue_pending = 0;
  21324. + user_service->message_available_pos =
  21325. + instance->completion_remove - 1;
  21326. + user_service->msg_insert = 0;
  21327. + user_service->msg_remove = 0;
  21328. + sema_init(&user_service->insert_event, 0);
  21329. + sema_init(&user_service->remove_event, 0);
  21330. +
  21331. + if (args.is_open) {
  21332. + status = vchiq_open_service_internal
  21333. + (service, instance->pid);
  21334. + if (status != VCHIQ_SUCCESS) {
  21335. + vchiq_remove_service(service->handle);
  21336. + service = NULL;
  21337. + ret = (status == VCHIQ_RETRY) ?
  21338. + -EINTR : -EIO;
  21339. + break;
  21340. + }
  21341. + }
  21342. +
  21343. + if (copy_to_user((void __user *)
  21344. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  21345. + arg)->handle),
  21346. + (const void *)&service->handle,
  21347. + sizeof(service->handle)) != 0) {
  21348. + ret = -EFAULT;
  21349. + vchiq_remove_service(service->handle);
  21350. + }
  21351. +
  21352. + service = NULL;
  21353. + } else {
  21354. + ret = -EEXIST;
  21355. + kfree(user_service);
  21356. + }
  21357. + } break;
  21358. +
  21359. + case VCHIQ_IOC_CLOSE_SERVICE: {
  21360. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21361. +
  21362. + service = find_service_for_instance(instance, handle);
  21363. + if (service != NULL)
  21364. + status = vchiq_close_service(service->handle);
  21365. + else
  21366. + ret = -EINVAL;
  21367. + } break;
  21368. +
  21369. + case VCHIQ_IOC_REMOVE_SERVICE: {
  21370. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21371. +
  21372. + service = find_service_for_instance(instance, handle);
  21373. + if (service != NULL)
  21374. + status = vchiq_remove_service(service->handle);
  21375. + else
  21376. + ret = -EINVAL;
  21377. + } break;
  21378. +
  21379. + case VCHIQ_IOC_USE_SERVICE:
  21380. + case VCHIQ_IOC_RELEASE_SERVICE: {
  21381. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21382. +
  21383. + service = find_service_for_instance(instance, handle);
  21384. + if (service != NULL) {
  21385. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  21386. + vchiq_use_service_internal(service) :
  21387. + vchiq_release_service_internal(service);
  21388. + if (status != VCHIQ_SUCCESS) {
  21389. + vchiq_log_error(vchiq_susp_log_level,
  21390. + "%s: cmd %s returned error %d for "
  21391. + "service %c%c%c%c:%03d",
  21392. + __func__,
  21393. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  21394. + "VCHIQ_IOC_USE_SERVICE" :
  21395. + "VCHIQ_IOC_RELEASE_SERVICE",
  21396. + status,
  21397. + VCHIQ_FOURCC_AS_4CHARS(
  21398. + service->base.fourcc),
  21399. + service->client_id);
  21400. + ret = -EINVAL;
  21401. + }
  21402. + } else
  21403. + ret = -EINVAL;
  21404. + } break;
  21405. +
  21406. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  21407. + VCHIQ_QUEUE_MESSAGE_T args;
  21408. + if (copy_from_user
  21409. + (&args, (const void __user *)arg,
  21410. + sizeof(args)) != 0) {
  21411. + ret = -EFAULT;
  21412. + break;
  21413. + }
  21414. +
  21415. + service = find_service_for_instance(instance, args.handle);
  21416. +
  21417. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  21418. + /* Copy elements into kernel space */
  21419. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  21420. + if (copy_from_user(elements, args.elements,
  21421. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  21422. + status = vchiq_queue_message
  21423. + (args.handle,
  21424. + elements, args.count);
  21425. + else
  21426. + ret = -EFAULT;
  21427. + } else {
  21428. + ret = -EINVAL;
  21429. + }
  21430. + } break;
  21431. +
  21432. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  21433. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  21434. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  21435. + struct bulk_waiter_node *waiter = NULL;
  21436. + VCHIQ_BULK_DIR_T dir =
  21437. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  21438. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  21439. +
  21440. + if (copy_from_user
  21441. + (&args, (const void __user *)arg,
  21442. + sizeof(args)) != 0) {
  21443. + ret = -EFAULT;
  21444. + break;
  21445. + }
  21446. +
  21447. + service = find_service_for_instance(instance, args.handle);
  21448. + if (!service) {
  21449. + ret = -EINVAL;
  21450. + break;
  21451. + }
  21452. +
  21453. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  21454. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  21455. + GFP_KERNEL);
  21456. + if (!waiter) {
  21457. + ret = -ENOMEM;
  21458. + break;
  21459. + }
  21460. + args.userdata = &waiter->bulk_waiter;
  21461. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  21462. + struct list_head *pos;
  21463. + mutex_lock(&instance->bulk_waiter_list_mutex);
  21464. + list_for_each(pos, &instance->bulk_waiter_list) {
  21465. + if (list_entry(pos, struct bulk_waiter_node,
  21466. + list)->pid == current->pid) {
  21467. + waiter = list_entry(pos,
  21468. + struct bulk_waiter_node,
  21469. + list);
  21470. + list_del(pos);
  21471. + break;
  21472. + }
  21473. +
  21474. + }
  21475. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  21476. + if (!waiter) {
  21477. + vchiq_log_error(vchiq_arm_log_level,
  21478. + "no bulk_waiter found for pid %d",
  21479. + current->pid);
  21480. + ret = -ESRCH;
  21481. + break;
  21482. + }
  21483. + vchiq_log_info(vchiq_arm_log_level,
  21484. + "found bulk_waiter %x for pid %d",
  21485. + (unsigned int)waiter, current->pid);
  21486. + args.userdata = &waiter->bulk_waiter;
  21487. + }
  21488. + status = vchiq_bulk_transfer
  21489. + (args.handle,
  21490. + VCHI_MEM_HANDLE_INVALID,
  21491. + args.data, args.size,
  21492. + args.userdata, args.mode,
  21493. + dir);
  21494. + if (!waiter)
  21495. + break;
  21496. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  21497. + !waiter->bulk_waiter.bulk) {
  21498. + if (waiter->bulk_waiter.bulk) {
  21499. + /* Cancel the signal when the transfer
  21500. + ** completes. */
  21501. + spin_lock(&bulk_waiter_spinlock);
  21502. + waiter->bulk_waiter.bulk->userdata = NULL;
  21503. + spin_unlock(&bulk_waiter_spinlock);
  21504. + }
  21505. + kfree(waiter);
  21506. + } else {
  21507. + const VCHIQ_BULK_MODE_T mode_waiting =
  21508. + VCHIQ_BULK_MODE_WAITING;
  21509. + waiter->pid = current->pid;
  21510. + mutex_lock(&instance->bulk_waiter_list_mutex);
  21511. + list_add(&waiter->list, &instance->bulk_waiter_list);
  21512. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  21513. + vchiq_log_info(vchiq_arm_log_level,
  21514. + "saved bulk_waiter %x for pid %d",
  21515. + (unsigned int)waiter, current->pid);
  21516. +
  21517. + if (copy_to_user((void __user *)
  21518. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  21519. + arg)->mode),
  21520. + (const void *)&mode_waiting,
  21521. + sizeof(mode_waiting)) != 0)
  21522. + ret = -EFAULT;
  21523. + }
  21524. + } break;
  21525. +
  21526. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  21527. + VCHIQ_AWAIT_COMPLETION_T args;
  21528. +
  21529. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21530. + if (!instance->connected) {
  21531. + ret = -ENOTCONN;
  21532. + break;
  21533. + }
  21534. +
  21535. + if (copy_from_user(&args, (const void __user *)arg,
  21536. + sizeof(args)) != 0) {
  21537. + ret = -EFAULT;
  21538. + break;
  21539. + }
  21540. +
  21541. + mutex_lock(&instance->completion_mutex);
  21542. +
  21543. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21544. + while ((instance->completion_remove ==
  21545. + instance->completion_insert)
  21546. + && !instance->closing) {
  21547. + int rc;
  21548. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21549. + mutex_unlock(&instance->completion_mutex);
  21550. + rc = down_interruptible(&instance->insert_event);
  21551. + mutex_lock(&instance->completion_mutex);
  21552. + if (rc != 0) {
  21553. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21554. + vchiq_log_info(vchiq_arm_log_level,
  21555. + "AWAIT_COMPLETION interrupted");
  21556. + ret = -EINTR;
  21557. + break;
  21558. + }
  21559. + }
  21560. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21561. +
  21562. + /* A read memory barrier is needed to stop prefetch of a stale
  21563. + ** completion record
  21564. + */
  21565. + rmb();
  21566. +
  21567. + if (ret == 0) {
  21568. + int msgbufcount = args.msgbufcount;
  21569. + for (ret = 0; ret < args.count; ret++) {
  21570. + VCHIQ_COMPLETION_DATA_T *completion;
  21571. + VCHIQ_SERVICE_T *service;
  21572. + USER_SERVICE_T *user_service;
  21573. + VCHIQ_HEADER_T *header;
  21574. + if (instance->completion_remove ==
  21575. + instance->completion_insert)
  21576. + break;
  21577. + completion = &instance->completions[
  21578. + instance->completion_remove &
  21579. + (MAX_COMPLETIONS - 1)];
  21580. +
  21581. + service = completion->service_userdata;
  21582. + user_service = service->base.userdata;
  21583. + completion->service_userdata =
  21584. + user_service->userdata;
  21585. +
  21586. + header = completion->header;
  21587. + if (header) {
  21588. + void __user *msgbuf;
  21589. + int msglen;
  21590. +
  21591. + msglen = header->size +
  21592. + sizeof(VCHIQ_HEADER_T);
  21593. + /* This must be a VCHIQ-style service */
  21594. + if (args.msgbufsize < msglen) {
  21595. + vchiq_log_error(
  21596. + vchiq_arm_log_level,
  21597. + "header %x: msgbufsize"
  21598. + " %x < msglen %x",
  21599. + (unsigned int)header,
  21600. + args.msgbufsize,
  21601. + msglen);
  21602. + WARN(1, "invalid message "
  21603. + "size\n");
  21604. + if (ret == 0)
  21605. + ret = -EMSGSIZE;
  21606. + break;
  21607. + }
  21608. + if (msgbufcount <= 0)
  21609. + /* Stall here for lack of a
  21610. + ** buffer for the message. */
  21611. + break;
  21612. + /* Get the pointer from user space */
  21613. + msgbufcount--;
  21614. + if (copy_from_user(&msgbuf,
  21615. + (const void __user *)
  21616. + &args.msgbufs[msgbufcount],
  21617. + sizeof(msgbuf)) != 0) {
  21618. + if (ret == 0)
  21619. + ret = -EFAULT;
  21620. + break;
  21621. + }
  21622. +
  21623. + /* Copy the message to user space */
  21624. + if (copy_to_user(msgbuf, header,
  21625. + msglen) != 0) {
  21626. + if (ret == 0)
  21627. + ret = -EFAULT;
  21628. + break;
  21629. + }
  21630. +
  21631. + /* Now it has been copied, the message
  21632. + ** can be released. */
  21633. + vchiq_release_message(service->handle,
  21634. + header);
  21635. +
  21636. + /* The completion must point to the
  21637. + ** msgbuf. */
  21638. + completion->header = msgbuf;
  21639. + }
  21640. +
  21641. + if (completion->reason ==
  21642. + VCHIQ_SERVICE_CLOSED)
  21643. + unlock_service(service);
  21644. +
  21645. + if (copy_to_user((void __user *)(
  21646. + (size_t)args.buf +
  21647. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  21648. + completion,
  21649. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  21650. + if (ret == 0)
  21651. + ret = -EFAULT;
  21652. + break;
  21653. + }
  21654. +
  21655. + instance->completion_remove++;
  21656. + }
  21657. +
  21658. + if (msgbufcount != args.msgbufcount) {
  21659. + if (copy_to_user((void __user *)
  21660. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  21661. + msgbufcount,
  21662. + &msgbufcount,
  21663. + sizeof(msgbufcount)) != 0) {
  21664. + ret = -EFAULT;
  21665. + }
  21666. + }
  21667. + }
  21668. +
  21669. + if (ret != 0)
  21670. + up(&instance->remove_event);
  21671. + mutex_unlock(&instance->completion_mutex);
  21672. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21673. + } break;
  21674. +
  21675. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  21676. + VCHIQ_DEQUEUE_MESSAGE_T args;
  21677. + USER_SERVICE_T *user_service;
  21678. + VCHIQ_HEADER_T *header;
  21679. +
  21680. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21681. + if (copy_from_user
  21682. + (&args, (const void __user *)arg,
  21683. + sizeof(args)) != 0) {
  21684. + ret = -EFAULT;
  21685. + break;
  21686. + }
  21687. + service = find_service_for_instance(instance, args.handle);
  21688. + if (!service) {
  21689. + ret = -EINVAL;
  21690. + break;
  21691. + }
  21692. + user_service = (USER_SERVICE_T *)service->base.userdata;
  21693. + if (user_service->is_vchi == 0) {
  21694. + ret = -EINVAL;
  21695. + break;
  21696. + }
  21697. +
  21698. + spin_lock(&msg_queue_spinlock);
  21699. + if (user_service->msg_remove == user_service->msg_insert) {
  21700. + if (!args.blocking) {
  21701. + spin_unlock(&msg_queue_spinlock);
  21702. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21703. + ret = -EWOULDBLOCK;
  21704. + break;
  21705. + }
  21706. + user_service->dequeue_pending = 1;
  21707. + do {
  21708. + spin_unlock(&msg_queue_spinlock);
  21709. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21710. + if (down_interruptible(
  21711. + &user_service->insert_event) != 0) {
  21712. + vchiq_log_info(vchiq_arm_log_level,
  21713. + "DEQUEUE_MESSAGE interrupted");
  21714. + ret = -EINTR;
  21715. + break;
  21716. + }
  21717. + spin_lock(&msg_queue_spinlock);
  21718. + } while (user_service->msg_remove ==
  21719. + user_service->msg_insert);
  21720. +
  21721. + if (ret)
  21722. + break;
  21723. + }
  21724. +
  21725. + BUG_ON((int)(user_service->msg_insert -
  21726. + user_service->msg_remove) < 0);
  21727. +
  21728. + header = user_service->msg_queue[user_service->msg_remove &
  21729. + (MSG_QUEUE_SIZE - 1)];
  21730. + user_service->msg_remove++;
  21731. + spin_unlock(&msg_queue_spinlock);
  21732. +
  21733. + up(&user_service->remove_event);
  21734. + if (header == NULL)
  21735. + ret = -ENOTCONN;
  21736. + else if (header->size <= args.bufsize) {
  21737. + /* Copy to user space if msgbuf is not NULL */
  21738. + if ((args.buf == NULL) ||
  21739. + (copy_to_user((void __user *)args.buf,
  21740. + header->data,
  21741. + header->size) == 0)) {
  21742. + ret = header->size;
  21743. + vchiq_release_message(
  21744. + service->handle,
  21745. + header);
  21746. + } else
  21747. + ret = -EFAULT;
  21748. + } else {
  21749. + vchiq_log_error(vchiq_arm_log_level,
  21750. + "header %x: bufsize %x < size %x",
  21751. + (unsigned int)header, args.bufsize,
  21752. + header->size);
  21753. + WARN(1, "invalid size\n");
  21754. + ret = -EMSGSIZE;
  21755. + }
  21756. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21757. + } break;
  21758. +
  21759. + case VCHIQ_IOC_GET_CLIENT_ID: {
  21760. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21761. +
  21762. + ret = vchiq_get_client_id(handle);
  21763. + } break;
  21764. +
  21765. + case VCHIQ_IOC_GET_CONFIG: {
  21766. + VCHIQ_GET_CONFIG_T args;
  21767. + VCHIQ_CONFIG_T config;
  21768. +
  21769. + if (copy_from_user(&args, (const void __user *)arg,
  21770. + sizeof(args)) != 0) {
  21771. + ret = -EFAULT;
  21772. + break;
  21773. + }
  21774. + if (args.config_size > sizeof(config)) {
  21775. + ret = -EINVAL;
  21776. + break;
  21777. + }
  21778. + status = vchiq_get_config(instance, args.config_size, &config);
  21779. + if (status == VCHIQ_SUCCESS) {
  21780. + if (copy_to_user((void __user *)args.pconfig,
  21781. + &config, args.config_size) != 0) {
  21782. + ret = -EFAULT;
  21783. + break;
  21784. + }
  21785. + }
  21786. + } break;
  21787. +
  21788. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  21789. + VCHIQ_SET_SERVICE_OPTION_T args;
  21790. +
  21791. + if (copy_from_user(
  21792. + &args, (const void __user *)arg,
  21793. + sizeof(args)) != 0) {
  21794. + ret = -EFAULT;
  21795. + break;
  21796. + }
  21797. +
  21798. + service = find_service_for_instance(instance, args.handle);
  21799. + if (!service) {
  21800. + ret = -EINVAL;
  21801. + break;
  21802. + }
  21803. +
  21804. + status = vchiq_set_service_option(
  21805. + args.handle, args.option, args.value);
  21806. + } break;
  21807. +
  21808. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  21809. + VCHIQ_DUMP_MEM_T args;
  21810. +
  21811. + if (copy_from_user
  21812. + (&args, (const void __user *)arg,
  21813. + sizeof(args)) != 0) {
  21814. + ret = -EFAULT;
  21815. + break;
  21816. + }
  21817. + dump_phys_mem(args.virt_addr, args.num_bytes);
  21818. + } break;
  21819. +
  21820. + default:
  21821. + ret = -ENOTTY;
  21822. + break;
  21823. + }
  21824. +
  21825. + if (service)
  21826. + unlock_service(service);
  21827. +
  21828. + if (ret == 0) {
  21829. + if (status == VCHIQ_ERROR)
  21830. + ret = -EIO;
  21831. + else if (status == VCHIQ_RETRY)
  21832. + ret = -EINTR;
  21833. + }
  21834. +
  21835. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  21836. + (ret != -EWOULDBLOCK))
  21837. + vchiq_log_info(vchiq_arm_log_level,
  21838. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21839. + (unsigned long)instance,
  21840. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21841. + ioctl_names[_IOC_NR(cmd)] :
  21842. + "<invalid>",
  21843. + status, ret);
  21844. + else
  21845. + vchiq_log_trace(vchiq_arm_log_level,
  21846. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21847. + (unsigned long)instance,
  21848. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21849. + ioctl_names[_IOC_NR(cmd)] :
  21850. + "<invalid>",
  21851. + status, ret);
  21852. +
  21853. + return ret;
  21854. +}
  21855. +
  21856. +/****************************************************************************
  21857. +*
  21858. +* vchiq_open
  21859. +*
  21860. +***************************************************************************/
  21861. +
  21862. +static int
  21863. +vchiq_open(struct inode *inode, struct file *file)
  21864. +{
  21865. + int dev = iminor(inode) & 0x0f;
  21866. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  21867. + switch (dev) {
  21868. + case VCHIQ_MINOR: {
  21869. + int ret;
  21870. + VCHIQ_STATE_T *state = vchiq_get_state();
  21871. + VCHIQ_INSTANCE_T instance;
  21872. +
  21873. + if (!state) {
  21874. + vchiq_log_error(vchiq_arm_log_level,
  21875. + "vchiq has no connection to VideoCore");
  21876. + return -ENOTCONN;
  21877. + }
  21878. +
  21879. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  21880. + if (!instance)
  21881. + return -ENOMEM;
  21882. +
  21883. + instance->state = state;
  21884. + instance->pid = current->tgid;
  21885. +
  21886. + ret = vchiq_proc_add_instance(instance);
  21887. + if (ret != 0) {
  21888. + kfree(instance);
  21889. + return ret;
  21890. + }
  21891. +
  21892. + sema_init(&instance->insert_event, 0);
  21893. + sema_init(&instance->remove_event, 0);
  21894. + mutex_init(&instance->completion_mutex);
  21895. + mutex_init(&instance->bulk_waiter_list_mutex);
  21896. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  21897. +
  21898. + file->private_data = instance;
  21899. + } break;
  21900. +
  21901. + default:
  21902. + vchiq_log_error(vchiq_arm_log_level,
  21903. + "Unknown minor device: %d", dev);
  21904. + return -ENXIO;
  21905. + }
  21906. +
  21907. + return 0;
  21908. +}
  21909. +
  21910. +/****************************************************************************
  21911. +*
  21912. +* vchiq_release
  21913. +*
  21914. +***************************************************************************/
  21915. +
  21916. +static int
  21917. +vchiq_release(struct inode *inode, struct file *file)
  21918. +{
  21919. + int dev = iminor(inode) & 0x0f;
  21920. + int ret = 0;
  21921. + switch (dev) {
  21922. + case VCHIQ_MINOR: {
  21923. + VCHIQ_INSTANCE_T instance = file->private_data;
  21924. + VCHIQ_STATE_T *state = vchiq_get_state();
  21925. + VCHIQ_SERVICE_T *service;
  21926. + int i;
  21927. +
  21928. + vchiq_log_info(vchiq_arm_log_level,
  21929. + "vchiq_release: instance=%lx",
  21930. + (unsigned long)instance);
  21931. +
  21932. + if (!state) {
  21933. + ret = -EPERM;
  21934. + goto out;
  21935. + }
  21936. +
  21937. + /* Ensure videocore is awake to allow termination. */
  21938. + vchiq_use_internal(instance->state, NULL,
  21939. + USE_TYPE_VCHIQ);
  21940. +
  21941. + mutex_lock(&instance->completion_mutex);
  21942. +
  21943. + /* Wake the completion thread and ask it to exit */
  21944. + instance->closing = 1;
  21945. + up(&instance->insert_event);
  21946. +
  21947. + mutex_unlock(&instance->completion_mutex);
  21948. +
  21949. + /* Wake the slot handler if the completion queue is full. */
  21950. + up(&instance->remove_event);
  21951. +
  21952. + /* Mark all services for termination... */
  21953. + i = 0;
  21954. + while ((service = next_service_by_instance(state, instance,
  21955. + &i)) != NULL) {
  21956. + USER_SERVICE_T *user_service = service->base.userdata;
  21957. +
  21958. + /* Wake the slot handler if the msg queue is full. */
  21959. + up(&user_service->remove_event);
  21960. +
  21961. + vchiq_terminate_service_internal(service);
  21962. + unlock_service(service);
  21963. + }
  21964. +
  21965. + /* ...and wait for them to die */
  21966. + i = 0;
  21967. + while ((service = next_service_by_instance(state, instance, &i))
  21968. + != NULL) {
  21969. + USER_SERVICE_T *user_service = service->base.userdata;
  21970. +
  21971. + down(&service->remove_event);
  21972. +
  21973. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  21974. +
  21975. + spin_lock(&msg_queue_spinlock);
  21976. +
  21977. + while (user_service->msg_remove !=
  21978. + user_service->msg_insert) {
  21979. + VCHIQ_HEADER_T *header = user_service->
  21980. + msg_queue[user_service->msg_remove &
  21981. + (MSG_QUEUE_SIZE - 1)];
  21982. + user_service->msg_remove++;
  21983. + spin_unlock(&msg_queue_spinlock);
  21984. +
  21985. + if (header)
  21986. + vchiq_release_message(
  21987. + service->handle,
  21988. + header);
  21989. + spin_lock(&msg_queue_spinlock);
  21990. + }
  21991. +
  21992. + spin_unlock(&msg_queue_spinlock);
  21993. +
  21994. + unlock_service(service);
  21995. + }
  21996. +
  21997. + /* Release any closed services */
  21998. + while (instance->completion_remove !=
  21999. + instance->completion_insert) {
  22000. + VCHIQ_COMPLETION_DATA_T *completion;
  22001. + VCHIQ_SERVICE_T *service;
  22002. + completion = &instance->completions[
  22003. + instance->completion_remove &
  22004. + (MAX_COMPLETIONS - 1)];
  22005. + service = completion->service_userdata;
  22006. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  22007. + unlock_service(service);
  22008. + instance->completion_remove++;
  22009. + }
  22010. +
  22011. + /* Release the PEER service count. */
  22012. + vchiq_release_internal(instance->state, NULL);
  22013. +
  22014. + {
  22015. + struct list_head *pos, *next;
  22016. + list_for_each_safe(pos, next,
  22017. + &instance->bulk_waiter_list) {
  22018. + struct bulk_waiter_node *waiter;
  22019. + waiter = list_entry(pos,
  22020. + struct bulk_waiter_node,
  22021. + list);
  22022. + list_del(pos);
  22023. + vchiq_log_info(vchiq_arm_log_level,
  22024. + "bulk_waiter - cleaned up %x "
  22025. + "for pid %d",
  22026. + (unsigned int)waiter, waiter->pid);
  22027. + kfree(waiter);
  22028. + }
  22029. + }
  22030. +
  22031. + vchiq_proc_remove_instance(instance);
  22032. +
  22033. + kfree(instance);
  22034. + file->private_data = NULL;
  22035. + } break;
  22036. +
  22037. + default:
  22038. + vchiq_log_error(vchiq_arm_log_level,
  22039. + "Unknown minor device: %d", dev);
  22040. + ret = -ENXIO;
  22041. + }
  22042. +
  22043. +out:
  22044. + return ret;
  22045. +}
  22046. +
  22047. +/****************************************************************************
  22048. +*
  22049. +* vchiq_dump
  22050. +*
  22051. +***************************************************************************/
  22052. +
  22053. +void
  22054. +vchiq_dump(void *dump_context, const char *str, int len)
  22055. +{
  22056. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  22057. +
  22058. + if (context->actual < context->space) {
  22059. + int copy_bytes;
  22060. + if (context->offset > 0) {
  22061. + int skip_bytes = min(len, (int)context->offset);
  22062. + str += skip_bytes;
  22063. + len -= skip_bytes;
  22064. + context->offset -= skip_bytes;
  22065. + if (context->offset > 0)
  22066. + return;
  22067. + }
  22068. + copy_bytes = min(len, (int)(context->space - context->actual));
  22069. + if (copy_bytes == 0)
  22070. + return;
  22071. + if (copy_to_user(context->buf + context->actual, str,
  22072. + copy_bytes))
  22073. + context->actual = -EFAULT;
  22074. + context->actual += copy_bytes;
  22075. + len -= copy_bytes;
  22076. +
  22077. + /* If tne terminating NUL is included in the length, then it
  22078. + ** marks the end of a line and should be replaced with a
  22079. + ** carriage return. */
  22080. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  22081. + char cr = '\n';
  22082. + if (copy_to_user(context->buf + context->actual - 1,
  22083. + &cr, 1))
  22084. + context->actual = -EFAULT;
  22085. + }
  22086. + }
  22087. +}
  22088. +
  22089. +/****************************************************************************
  22090. +*
  22091. +* vchiq_dump_platform_instance_state
  22092. +*
  22093. +***************************************************************************/
  22094. +
  22095. +void
  22096. +vchiq_dump_platform_instances(void *dump_context)
  22097. +{
  22098. + VCHIQ_STATE_T *state = vchiq_get_state();
  22099. + char buf[80];
  22100. + int len;
  22101. + int i;
  22102. +
  22103. + /* There is no list of instances, so instead scan all services,
  22104. + marking those that have been dumped. */
  22105. +
  22106. + for (i = 0; i < state->unused_service; i++) {
  22107. + VCHIQ_SERVICE_T *service = state->services[i];
  22108. + VCHIQ_INSTANCE_T instance;
  22109. +
  22110. + if (service && (service->base.callback == service_callback)) {
  22111. + instance = service->instance;
  22112. + if (instance)
  22113. + instance->mark = 0;
  22114. + }
  22115. + }
  22116. +
  22117. + for (i = 0; i < state->unused_service; i++) {
  22118. + VCHIQ_SERVICE_T *service = state->services[i];
  22119. + VCHIQ_INSTANCE_T instance;
  22120. +
  22121. + if (service && (service->base.callback == service_callback)) {
  22122. + instance = service->instance;
  22123. + if (instance && !instance->mark) {
  22124. + len = snprintf(buf, sizeof(buf),
  22125. + "Instance %x: pid %d,%s completions "
  22126. + "%d/%d",
  22127. + (unsigned int)instance, instance->pid,
  22128. + instance->connected ? " connected, " :
  22129. + "",
  22130. + instance->completion_insert -
  22131. + instance->completion_remove,
  22132. + MAX_COMPLETIONS);
  22133. +
  22134. + vchiq_dump(dump_context, buf, len + 1);
  22135. +
  22136. + instance->mark = 1;
  22137. + }
  22138. + }
  22139. + }
  22140. +}
  22141. +
  22142. +/****************************************************************************
  22143. +*
  22144. +* vchiq_dump_platform_service_state
  22145. +*
  22146. +***************************************************************************/
  22147. +
  22148. +void
  22149. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  22150. +{
  22151. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  22152. + char buf[80];
  22153. + int len;
  22154. +
  22155. + len = snprintf(buf, sizeof(buf), " instance %x",
  22156. + (unsigned int)service->instance);
  22157. +
  22158. + if ((service->base.callback == service_callback) &&
  22159. + user_service->is_vchi) {
  22160. + len += snprintf(buf + len, sizeof(buf) - len,
  22161. + ", %d/%d messages",
  22162. + user_service->msg_insert - user_service->msg_remove,
  22163. + MSG_QUEUE_SIZE);
  22164. +
  22165. + if (user_service->dequeue_pending)
  22166. + len += snprintf(buf + len, sizeof(buf) - len,
  22167. + " (dequeue pending)");
  22168. + }
  22169. +
  22170. + vchiq_dump(dump_context, buf, len + 1);
  22171. +}
  22172. +
  22173. +/****************************************************************************
  22174. +*
  22175. +* dump_user_mem
  22176. +*
  22177. +***************************************************************************/
  22178. +
  22179. +static void
  22180. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  22181. +{
  22182. + int rc;
  22183. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  22184. + int num_pages;
  22185. + int offset;
  22186. + int end_offset;
  22187. + int page_idx;
  22188. + int prev_idx;
  22189. + struct page *page;
  22190. + struct page **pages;
  22191. + uint8_t *kmapped_virt_ptr;
  22192. +
  22193. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  22194. +
  22195. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  22196. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  22197. + ~0x0fuL);
  22198. +
  22199. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  22200. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  22201. +
  22202. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  22203. +
  22204. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  22205. + if (pages == NULL) {
  22206. + vchiq_log_error(vchiq_arm_log_level,
  22207. + "Unable to allocation memory for %d pages\n",
  22208. + num_pages);
  22209. + return;
  22210. + }
  22211. +
  22212. + down_read(&current->mm->mmap_sem);
  22213. + rc = get_user_pages(current, /* task */
  22214. + current->mm, /* mm */
  22215. + (unsigned long)virt_addr, /* start */
  22216. + num_pages, /* len */
  22217. + 0, /* write */
  22218. + 0, /* force */
  22219. + pages, /* pages (array of page pointers) */
  22220. + NULL); /* vmas */
  22221. + up_read(&current->mm->mmap_sem);
  22222. +
  22223. + prev_idx = -1;
  22224. + page = NULL;
  22225. +
  22226. + while (offset < end_offset) {
  22227. +
  22228. + int page_offset = offset % PAGE_SIZE;
  22229. + page_idx = offset / PAGE_SIZE;
  22230. +
  22231. + if (page_idx != prev_idx) {
  22232. +
  22233. + if (page != NULL)
  22234. + kunmap(page);
  22235. + page = pages[page_idx];
  22236. + kmapped_virt_ptr = kmap(page);
  22237. +
  22238. + prev_idx = page_idx;
  22239. + }
  22240. +
  22241. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  22242. + vchiq_log_dump_mem("ph",
  22243. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  22244. + page_offset],
  22245. + &kmapped_virt_ptr[page_offset], 16);
  22246. +
  22247. + offset += 16;
  22248. + }
  22249. + if (page != NULL)
  22250. + kunmap(page);
  22251. +
  22252. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  22253. + page_cache_release(pages[page_idx]);
  22254. +
  22255. + kfree(pages);
  22256. +}
  22257. +
  22258. +/****************************************************************************
  22259. +*
  22260. +* vchiq_read
  22261. +*
  22262. +***************************************************************************/
  22263. +
  22264. +static ssize_t
  22265. +vchiq_read(struct file *file, char __user *buf,
  22266. + size_t count, loff_t *ppos)
  22267. +{
  22268. + DUMP_CONTEXT_T context;
  22269. + context.buf = buf;
  22270. + context.actual = 0;
  22271. + context.space = count;
  22272. + context.offset = *ppos;
  22273. +
  22274. + vchiq_dump_state(&context, &g_state);
  22275. +
  22276. + *ppos += context.actual;
  22277. +
  22278. + return context.actual;
  22279. +}
  22280. +
  22281. +VCHIQ_STATE_T *
  22282. +vchiq_get_state(void)
  22283. +{
  22284. +
  22285. + if (g_state.remote == NULL)
  22286. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  22287. + else if (g_state.remote->initialised != 1)
  22288. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  22289. + __func__, g_state.remote->initialised);
  22290. +
  22291. + return ((g_state.remote != NULL) &&
  22292. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  22293. +}
  22294. +
  22295. +static const struct file_operations
  22296. +vchiq_fops = {
  22297. + .owner = THIS_MODULE,
  22298. + .unlocked_ioctl = vchiq_ioctl,
  22299. + .open = vchiq_open,
  22300. + .release = vchiq_release,
  22301. + .read = vchiq_read
  22302. +};
  22303. +
  22304. +/*
  22305. + * Autosuspend related functionality
  22306. + */
  22307. +
  22308. +int
  22309. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  22310. +{
  22311. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22312. + if (!arm_state)
  22313. + /* autosuspend not supported - always return wanted */
  22314. + return 1;
  22315. + else if (arm_state->blocked_count)
  22316. + return 1;
  22317. + else if (!arm_state->videocore_use_count)
  22318. + /* usage count zero - check for override unless we're forcing */
  22319. + if (arm_state->resume_blocked)
  22320. + return 0;
  22321. + else
  22322. + return vchiq_platform_videocore_wanted(state);
  22323. + else
  22324. + /* non-zero usage count - videocore still required */
  22325. + return 1;
  22326. +}
  22327. +
  22328. +static VCHIQ_STATUS_T
  22329. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  22330. + VCHIQ_HEADER_T *header,
  22331. + VCHIQ_SERVICE_HANDLE_T service_user,
  22332. + void *bulk_user)
  22333. +{
  22334. + vchiq_log_error(vchiq_susp_log_level,
  22335. + "%s callback reason %d", __func__, reason);
  22336. + return 0;
  22337. +}
  22338. +
  22339. +static int
  22340. +vchiq_keepalive_thread_func(void *v)
  22341. +{
  22342. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  22343. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22344. +
  22345. + VCHIQ_STATUS_T status;
  22346. + VCHIQ_INSTANCE_T instance;
  22347. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  22348. +
  22349. + VCHIQ_SERVICE_PARAMS_T params = {
  22350. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  22351. + .callback = vchiq_keepalive_vchiq_callback,
  22352. + .version = KEEPALIVE_VER,
  22353. + .version_min = KEEPALIVE_VER_MIN
  22354. + };
  22355. +
  22356. + status = vchiq_initialise(&instance);
  22357. + if (status != VCHIQ_SUCCESS) {
  22358. + vchiq_log_error(vchiq_susp_log_level,
  22359. + "%s vchiq_initialise failed %d", __func__, status);
  22360. + goto exit;
  22361. + }
  22362. +
  22363. + status = vchiq_connect(instance);
  22364. + if (status != VCHIQ_SUCCESS) {
  22365. + vchiq_log_error(vchiq_susp_log_level,
  22366. + "%s vchiq_connect failed %d", __func__, status);
  22367. + goto shutdown;
  22368. + }
  22369. +
  22370. + status = vchiq_add_service(instance, &params, &ka_handle);
  22371. + if (status != VCHIQ_SUCCESS) {
  22372. + vchiq_log_error(vchiq_susp_log_level,
  22373. + "%s vchiq_open_service failed %d", __func__, status);
  22374. + goto shutdown;
  22375. + }
  22376. +
  22377. + while (1) {
  22378. + long rc = 0, uc = 0;
  22379. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  22380. + != 0) {
  22381. + vchiq_log_error(vchiq_susp_log_level,
  22382. + "%s interrupted", __func__);
  22383. + flush_signals(current);
  22384. + continue;
  22385. + }
  22386. +
  22387. + /* read and clear counters. Do release_count then use_count to
  22388. + * prevent getting more releases than uses */
  22389. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  22390. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  22391. +
  22392. + /* Call use/release service the requisite number of times.
  22393. + * Process use before release so use counts don't go negative */
  22394. + while (uc--) {
  22395. + atomic_inc(&arm_state->ka_use_ack_count);
  22396. + status = vchiq_use_service(ka_handle);
  22397. + if (status != VCHIQ_SUCCESS) {
  22398. + vchiq_log_error(vchiq_susp_log_level,
  22399. + "%s vchiq_use_service error %d",
  22400. + __func__, status);
  22401. + }
  22402. + }
  22403. + while (rc--) {
  22404. + status = vchiq_release_service(ka_handle);
  22405. + if (status != VCHIQ_SUCCESS) {
  22406. + vchiq_log_error(vchiq_susp_log_level,
  22407. + "%s vchiq_release_service error %d",
  22408. + __func__, status);
  22409. + }
  22410. + }
  22411. + }
  22412. +
  22413. +shutdown:
  22414. + vchiq_shutdown(instance);
  22415. +exit:
  22416. + return 0;
  22417. +}
  22418. +
  22419. +
  22420. +
  22421. +VCHIQ_STATUS_T
  22422. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  22423. +{
  22424. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  22425. +
  22426. + if (arm_state) {
  22427. + rwlock_init(&arm_state->susp_res_lock);
  22428. +
  22429. + init_completion(&arm_state->ka_evt);
  22430. + atomic_set(&arm_state->ka_use_count, 0);
  22431. + atomic_set(&arm_state->ka_use_ack_count, 0);
  22432. + atomic_set(&arm_state->ka_release_count, 0);
  22433. +
  22434. + init_completion(&arm_state->vc_suspend_complete);
  22435. +
  22436. + init_completion(&arm_state->vc_resume_complete);
  22437. + /* Initialise to 'done' state. We only want to block on resume
  22438. + * completion while videocore is suspended. */
  22439. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  22440. +
  22441. + init_completion(&arm_state->resume_blocker);
  22442. + /* Initialise to 'done' state. We only want to block on this
  22443. + * completion while resume is blocked */
  22444. + complete_all(&arm_state->resume_blocker);
  22445. +
  22446. + init_completion(&arm_state->blocked_blocker);
  22447. + /* Initialise to 'done' state. We only want to block on this
  22448. + * completion while things are waiting on the resume blocker */
  22449. + complete_all(&arm_state->blocked_blocker);
  22450. +
  22451. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  22452. + arm_state->suspend_timer_running = 0;
  22453. + init_timer(&arm_state->suspend_timer);
  22454. + arm_state->suspend_timer.data = (unsigned long)(state);
  22455. + arm_state->suspend_timer.function = suspend_timer_callback;
  22456. +
  22457. + arm_state->first_connect = 0;
  22458. +
  22459. + }
  22460. + return status;
  22461. +}
  22462. +
  22463. +/*
  22464. +** Functions to modify the state variables;
  22465. +** set_suspend_state
  22466. +** set_resume_state
  22467. +**
  22468. +** There are more state variables than we might like, so ensure they remain in
  22469. +** step. Suspend and resume state are maintained separately, since most of
  22470. +** these state machines can operate independently. However, there are a few
  22471. +** states where state transitions in one state machine cause a reset to the
  22472. +** other state machine. In addition, there are some completion events which
  22473. +** need to occur on state machine reset and end-state(s), so these are also
  22474. +** dealt with in these functions.
  22475. +**
  22476. +** In all states we set the state variable according to the input, but in some
  22477. +** cases we perform additional steps outlined below;
  22478. +**
  22479. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  22480. +** The suspend completion is completed after any suspend
  22481. +** attempt. When we reset the state machine we also reset
  22482. +** the completion. This reset occurs when videocore is
  22483. +** resumed, and also if we initiate suspend after a suspend
  22484. +** failure.
  22485. +**
  22486. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  22487. +** suspend - ie from this point on we must try to suspend
  22488. +** before resuming can occur. We therefore also reset the
  22489. +** resume state machine to VC_RESUME_IDLE in this state.
  22490. +**
  22491. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  22492. +** complete_all on the suspend completion to notify
  22493. +** anything waiting for suspend to happen.
  22494. +**
  22495. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  22496. +** initiate resume, so no need to alter resume state.
  22497. +** We call complete_all on the suspend completion to notify
  22498. +** of suspend rejection.
  22499. +**
  22500. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  22501. +** suspend completion and reset the resume state machine.
  22502. +**
  22503. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  22504. +** resume completion is in it's 'done' state whenever
  22505. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  22506. +** implies that videocore is suspended.
  22507. +** Hence, any thread which needs to wait until videocore is
  22508. +** running can wait on this completion - it will only block
  22509. +** if videocore is suspended.
  22510. +**
  22511. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  22512. +** Call complete_all on the resume completion to unblock
  22513. +** any threads waiting for resume. Also reset the suspend
  22514. +** state machine to it's idle state.
  22515. +**
  22516. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  22517. +*/
  22518. +
  22519. +inline void
  22520. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  22521. + enum vc_suspend_status new_state)
  22522. +{
  22523. + /* set the state in all cases */
  22524. + arm_state->vc_suspend_state = new_state;
  22525. +
  22526. + /* state specific additional actions */
  22527. + switch (new_state) {
  22528. + case VC_SUSPEND_FORCE_CANCELED:
  22529. + complete_all(&arm_state->vc_suspend_complete);
  22530. + break;
  22531. + case VC_SUSPEND_REJECTED:
  22532. + complete_all(&arm_state->vc_suspend_complete);
  22533. + break;
  22534. + case VC_SUSPEND_FAILED:
  22535. + complete_all(&arm_state->vc_suspend_complete);
  22536. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  22537. + complete_all(&arm_state->vc_resume_complete);
  22538. + break;
  22539. + case VC_SUSPEND_IDLE:
  22540. + INIT_COMPLETION(arm_state->vc_suspend_complete);
  22541. + break;
  22542. + case VC_SUSPEND_REQUESTED:
  22543. + break;
  22544. + case VC_SUSPEND_IN_PROGRESS:
  22545. + set_resume_state(arm_state, VC_RESUME_IDLE);
  22546. + break;
  22547. + case VC_SUSPEND_SUSPENDED:
  22548. + complete_all(&arm_state->vc_suspend_complete);
  22549. + break;
  22550. + default:
  22551. + BUG();
  22552. + break;
  22553. + }
  22554. +}
  22555. +
  22556. +inline void
  22557. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  22558. + enum vc_resume_status new_state)
  22559. +{
  22560. + /* set the state in all cases */
  22561. + arm_state->vc_resume_state = new_state;
  22562. +
  22563. + /* state specific additional actions */
  22564. + switch (new_state) {
  22565. + case VC_RESUME_FAILED:
  22566. + break;
  22567. + case VC_RESUME_IDLE:
  22568. + INIT_COMPLETION(arm_state->vc_resume_complete);
  22569. + break;
  22570. + case VC_RESUME_REQUESTED:
  22571. + break;
  22572. + case VC_RESUME_IN_PROGRESS:
  22573. + break;
  22574. + case VC_RESUME_RESUMED:
  22575. + complete_all(&arm_state->vc_resume_complete);
  22576. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22577. + break;
  22578. + default:
  22579. + BUG();
  22580. + break;
  22581. + }
  22582. +}
  22583. +
  22584. +
  22585. +/* should be called with the write lock held */
  22586. +inline void
  22587. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  22588. +{
  22589. + del_timer(&arm_state->suspend_timer);
  22590. + arm_state->suspend_timer.expires = jiffies +
  22591. + msecs_to_jiffies(arm_state->
  22592. + suspend_timer_timeout);
  22593. + add_timer(&arm_state->suspend_timer);
  22594. + arm_state->suspend_timer_running = 1;
  22595. +}
  22596. +
  22597. +/* should be called with the write lock held */
  22598. +static inline void
  22599. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  22600. +{
  22601. + if (arm_state->suspend_timer_running) {
  22602. + del_timer(&arm_state->suspend_timer);
  22603. + arm_state->suspend_timer_running = 0;
  22604. + }
  22605. +}
  22606. +
  22607. +static inline int
  22608. +need_resume(VCHIQ_STATE_T *state)
  22609. +{
  22610. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22611. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  22612. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  22613. + vchiq_videocore_wanted(state);
  22614. +}
  22615. +
  22616. +static int
  22617. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  22618. +{
  22619. + int status = VCHIQ_SUCCESS;
  22620. + const unsigned long timeout_val =
  22621. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  22622. + int resume_count = 0;
  22623. +
  22624. + /* Allow any threads which were blocked by the last force suspend to
  22625. + * complete if they haven't already. Only give this one shot; if
  22626. + * blocked_count is incremented after blocked_blocker is completed
  22627. + * (which only happens when blocked_count hits 0) then those threads
  22628. + * will have to wait until next time around */
  22629. + if (arm_state->blocked_count) {
  22630. + INIT_COMPLETION(arm_state->blocked_blocker);
  22631. + write_unlock_bh(&arm_state->susp_res_lock);
  22632. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  22633. + "blocked clients", __func__);
  22634. + if (wait_for_completion_interruptible_timeout(
  22635. + &arm_state->blocked_blocker, timeout_val)
  22636. + <= 0) {
  22637. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22638. + "previously blocked clients failed" , __func__);
  22639. + status = VCHIQ_ERROR;
  22640. + write_lock_bh(&arm_state->susp_res_lock);
  22641. + goto out;
  22642. + }
  22643. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  22644. + "clients resumed", __func__);
  22645. + write_lock_bh(&arm_state->susp_res_lock);
  22646. + }
  22647. +
  22648. + /* We need to wait for resume to complete if it's in process */
  22649. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  22650. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  22651. + if (resume_count > 1) {
  22652. + status = VCHIQ_ERROR;
  22653. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  22654. + "many times for resume" , __func__);
  22655. + goto out;
  22656. + }
  22657. + write_unlock_bh(&arm_state->susp_res_lock);
  22658. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  22659. + __func__);
  22660. + if (wait_for_completion_interruptible_timeout(
  22661. + &arm_state->vc_resume_complete, timeout_val)
  22662. + <= 0) {
  22663. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22664. + "resume failed (%s)", __func__,
  22665. + resume_state_names[arm_state->vc_resume_state +
  22666. + VC_RESUME_NUM_OFFSET]);
  22667. + status = VCHIQ_ERROR;
  22668. + write_lock_bh(&arm_state->susp_res_lock);
  22669. + goto out;
  22670. + }
  22671. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  22672. + write_lock_bh(&arm_state->susp_res_lock);
  22673. + resume_count++;
  22674. + }
  22675. + INIT_COMPLETION(arm_state->resume_blocker);
  22676. + arm_state->resume_blocked = 1;
  22677. +
  22678. +out:
  22679. + return status;
  22680. +}
  22681. +
  22682. +static inline void
  22683. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  22684. +{
  22685. + complete_all(&arm_state->resume_blocker);
  22686. + arm_state->resume_blocked = 0;
  22687. +}
  22688. +
  22689. +/* Initiate suspend via slot handler. Should be called with the write lock
  22690. + * held */
  22691. +VCHIQ_STATUS_T
  22692. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  22693. +{
  22694. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22695. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22696. +
  22697. + if (!arm_state)
  22698. + goto out;
  22699. +
  22700. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22701. + status = VCHIQ_SUCCESS;
  22702. +
  22703. +
  22704. + switch (arm_state->vc_suspend_state) {
  22705. + case VC_SUSPEND_REQUESTED:
  22706. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  22707. + "requested", __func__);
  22708. + break;
  22709. + case VC_SUSPEND_IN_PROGRESS:
  22710. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  22711. + "progress", __func__);
  22712. + break;
  22713. +
  22714. + default:
  22715. + /* We don't expect to be in other states, so log but continue
  22716. + * anyway */
  22717. + vchiq_log_error(vchiq_susp_log_level,
  22718. + "%s unexpected suspend state %s", __func__,
  22719. + suspend_state_names[arm_state->vc_suspend_state +
  22720. + VC_SUSPEND_NUM_OFFSET]);
  22721. + /* fall through */
  22722. + case VC_SUSPEND_REJECTED:
  22723. + case VC_SUSPEND_FAILED:
  22724. + /* Ensure any idle state actions have been run */
  22725. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22726. + /* fall through */
  22727. + case VC_SUSPEND_IDLE:
  22728. + vchiq_log_info(vchiq_susp_log_level,
  22729. + "%s: suspending", __func__);
  22730. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  22731. + /* kick the slot handler thread to initiate suspend */
  22732. + request_poll(state, NULL, 0);
  22733. + break;
  22734. + }
  22735. +
  22736. +out:
  22737. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22738. + return status;
  22739. +}
  22740. +
  22741. +void
  22742. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  22743. +{
  22744. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22745. + int susp = 0;
  22746. +
  22747. + if (!arm_state)
  22748. + goto out;
  22749. +
  22750. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22751. +
  22752. + write_lock_bh(&arm_state->susp_res_lock);
  22753. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  22754. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  22755. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  22756. + susp = 1;
  22757. + }
  22758. + write_unlock_bh(&arm_state->susp_res_lock);
  22759. +
  22760. + if (susp)
  22761. + vchiq_platform_suspend(state);
  22762. +
  22763. +out:
  22764. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22765. + return;
  22766. +}
  22767. +
  22768. +
  22769. +static void
  22770. +output_timeout_error(VCHIQ_STATE_T *state)
  22771. +{
  22772. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22773. + char service_err[50] = "";
  22774. + int vc_use_count = arm_state->videocore_use_count;
  22775. + int active_services = state->unused_service;
  22776. + int i;
  22777. +
  22778. + if (!arm_state->videocore_use_count) {
  22779. + snprintf(service_err, 50, " Videocore usecount is 0");
  22780. + goto output_msg;
  22781. + }
  22782. + for (i = 0; i < active_services; i++) {
  22783. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22784. + if (service_ptr && service_ptr->service_use_count &&
  22785. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  22786. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  22787. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  22788. + service_ptr->base.fourcc),
  22789. + service_ptr->client_id,
  22790. + service_ptr->service_use_count,
  22791. + service_ptr->service_use_count ==
  22792. + vc_use_count ? "" : " (+ more)");
  22793. + break;
  22794. + }
  22795. + }
  22796. +
  22797. +output_msg:
  22798. + vchiq_log_error(vchiq_susp_log_level,
  22799. + "timed out waiting for vc suspend (%d).%s",
  22800. + arm_state->autosuspend_override, service_err);
  22801. +
  22802. +}
  22803. +
  22804. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  22805. +** We don't actually force suspend, since videocore may get into a bad state
  22806. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  22807. +** determine a good point to suspend. If this doesn't happen within 100ms we
  22808. +** report failure.
  22809. +**
  22810. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  22811. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  22812. +*/
  22813. +VCHIQ_STATUS_T
  22814. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  22815. +{
  22816. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22817. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22818. + long rc = 0;
  22819. + int repeat = -1;
  22820. +
  22821. + if (!arm_state)
  22822. + goto out;
  22823. +
  22824. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22825. +
  22826. + write_lock_bh(&arm_state->susp_res_lock);
  22827. +
  22828. + status = block_resume(arm_state);
  22829. + if (status != VCHIQ_SUCCESS)
  22830. + goto unlock;
  22831. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22832. + /* Already suspended - just block resume and exit */
  22833. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  22834. + __func__);
  22835. + status = VCHIQ_SUCCESS;
  22836. + goto unlock;
  22837. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  22838. + /* initiate suspend immediately in the case that we're waiting
  22839. + * for the timeout */
  22840. + stop_suspend_timer(arm_state);
  22841. + if (!vchiq_videocore_wanted(state)) {
  22842. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  22843. + "idle, initiating suspend", __func__);
  22844. + status = vchiq_arm_vcsuspend(state);
  22845. + } else if (arm_state->autosuspend_override <
  22846. + FORCE_SUSPEND_FAIL_MAX) {
  22847. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  22848. + "videocore go idle", __func__);
  22849. + status = VCHIQ_SUCCESS;
  22850. + } else {
  22851. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  22852. + "many times - attempting suspend", __func__);
  22853. + status = vchiq_arm_vcsuspend(state);
  22854. + }
  22855. + } else {
  22856. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  22857. + "in progress - wait for completion", __func__);
  22858. + status = VCHIQ_SUCCESS;
  22859. + }
  22860. +
  22861. + /* Wait for suspend to happen due to system idle (not forced..) */
  22862. + if (status != VCHIQ_SUCCESS)
  22863. + goto unblock_resume;
  22864. +
  22865. + do {
  22866. + write_unlock_bh(&arm_state->susp_res_lock);
  22867. +
  22868. + rc = wait_for_completion_interruptible_timeout(
  22869. + &arm_state->vc_suspend_complete,
  22870. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  22871. +
  22872. + write_lock_bh(&arm_state->susp_res_lock);
  22873. + if (rc < 0) {
  22874. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  22875. + "interrupted waiting for suspend", __func__);
  22876. + status = VCHIQ_ERROR;
  22877. + goto unblock_resume;
  22878. + } else if (rc == 0) {
  22879. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  22880. + /* Repeat timeout once if in progress */
  22881. + if (repeat < 0) {
  22882. + repeat = 1;
  22883. + continue;
  22884. + }
  22885. + }
  22886. + arm_state->autosuspend_override++;
  22887. + output_timeout_error(state);
  22888. +
  22889. + status = VCHIQ_RETRY;
  22890. + goto unblock_resume;
  22891. + }
  22892. + } while (0 < (repeat--));
  22893. +
  22894. + /* Check and report state in case we need to abort ARM suspend */
  22895. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  22896. + status = VCHIQ_RETRY;
  22897. + vchiq_log_error(vchiq_susp_log_level,
  22898. + "%s videocore suspend failed (state %s)", __func__,
  22899. + suspend_state_names[arm_state->vc_suspend_state +
  22900. + VC_SUSPEND_NUM_OFFSET]);
  22901. + /* Reset the state only if it's still in an error state.
  22902. + * Something could have already initiated another suspend. */
  22903. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  22904. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22905. +
  22906. + goto unblock_resume;
  22907. + }
  22908. +
  22909. + /* successfully suspended - unlock and exit */
  22910. + goto unlock;
  22911. +
  22912. +unblock_resume:
  22913. + /* all error states need to unblock resume before exit */
  22914. + unblock_resume(arm_state);
  22915. +
  22916. +unlock:
  22917. + write_unlock_bh(&arm_state->susp_res_lock);
  22918. +
  22919. +out:
  22920. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22921. + return status;
  22922. +}
  22923. +
  22924. +void
  22925. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  22926. +{
  22927. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22928. +
  22929. + if (!arm_state)
  22930. + goto out;
  22931. +
  22932. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22933. +
  22934. + write_lock_bh(&arm_state->susp_res_lock);
  22935. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  22936. + arm_state->first_connect &&
  22937. + !vchiq_videocore_wanted(state)) {
  22938. + vchiq_arm_vcsuspend(state);
  22939. + }
  22940. + write_unlock_bh(&arm_state->susp_res_lock);
  22941. +
  22942. +out:
  22943. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22944. + return;
  22945. +}
  22946. +
  22947. +
  22948. +int
  22949. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  22950. +{
  22951. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22952. + int resume = 0;
  22953. + int ret = -1;
  22954. +
  22955. + if (!arm_state)
  22956. + goto out;
  22957. +
  22958. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22959. +
  22960. + write_lock_bh(&arm_state->susp_res_lock);
  22961. + unblock_resume(arm_state);
  22962. + resume = vchiq_check_resume(state);
  22963. + write_unlock_bh(&arm_state->susp_res_lock);
  22964. +
  22965. + if (resume) {
  22966. + if (wait_for_completion_interruptible(
  22967. + &arm_state->vc_resume_complete) < 0) {
  22968. + vchiq_log_error(vchiq_susp_log_level,
  22969. + "%s interrupted", __func__);
  22970. + /* failed, cannot accurately derive suspend
  22971. + * state, so exit early. */
  22972. + goto out;
  22973. + }
  22974. + }
  22975. +
  22976. + read_lock_bh(&arm_state->susp_res_lock);
  22977. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22978. + vchiq_log_info(vchiq_susp_log_level,
  22979. + "%s: Videocore remains suspended", __func__);
  22980. + } else {
  22981. + vchiq_log_info(vchiq_susp_log_level,
  22982. + "%s: Videocore resumed", __func__);
  22983. + ret = 0;
  22984. + }
  22985. + read_unlock_bh(&arm_state->susp_res_lock);
  22986. +out:
  22987. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22988. + return ret;
  22989. +}
  22990. +
  22991. +/* This function should be called with the write lock held */
  22992. +int
  22993. +vchiq_check_resume(VCHIQ_STATE_T *state)
  22994. +{
  22995. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22996. + int resume = 0;
  22997. +
  22998. + if (!arm_state)
  22999. + goto out;
  23000. +
  23001. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23002. +
  23003. + if (need_resume(state)) {
  23004. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  23005. + request_poll(state, NULL, 0);
  23006. + resume = 1;
  23007. + }
  23008. +
  23009. +out:
  23010. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  23011. + return resume;
  23012. +}
  23013. +
  23014. +void
  23015. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  23016. +{
  23017. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23018. + int res = 0;
  23019. +
  23020. + if (!arm_state)
  23021. + goto out;
  23022. +
  23023. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23024. +
  23025. + write_lock_bh(&arm_state->susp_res_lock);
  23026. + if (arm_state->wake_address == 0) {
  23027. + vchiq_log_info(vchiq_susp_log_level,
  23028. + "%s: already awake", __func__);
  23029. + goto unlock;
  23030. + }
  23031. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  23032. + vchiq_log_info(vchiq_susp_log_level,
  23033. + "%s: already resuming", __func__);
  23034. + goto unlock;
  23035. + }
  23036. +
  23037. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  23038. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  23039. + res = 1;
  23040. + } else
  23041. + vchiq_log_trace(vchiq_susp_log_level,
  23042. + "%s: not resuming (resume state %s)", __func__,
  23043. + resume_state_names[arm_state->vc_resume_state +
  23044. + VC_RESUME_NUM_OFFSET]);
  23045. +
  23046. +unlock:
  23047. + write_unlock_bh(&arm_state->susp_res_lock);
  23048. +
  23049. + if (res)
  23050. + vchiq_platform_resume(state);
  23051. +
  23052. +out:
  23053. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  23054. + return;
  23055. +
  23056. +}
  23057. +
  23058. +
  23059. +
  23060. +VCHIQ_STATUS_T
  23061. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23062. + enum USE_TYPE_E use_type)
  23063. +{
  23064. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23065. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  23066. + char entity[16];
  23067. + int *entity_uc;
  23068. + int local_uc, local_entity_uc;
  23069. +
  23070. + if (!arm_state)
  23071. + goto out;
  23072. +
  23073. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23074. +
  23075. + if (use_type == USE_TYPE_VCHIQ) {
  23076. + sprintf(entity, "VCHIQ: ");
  23077. + entity_uc = &arm_state->peer_use_count;
  23078. + } else if (service) {
  23079. + sprintf(entity, "%c%c%c%c:%03d",
  23080. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23081. + service->client_id);
  23082. + entity_uc = &service->service_use_count;
  23083. + } else {
  23084. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  23085. + "ptr", __func__);
  23086. + ret = VCHIQ_ERROR;
  23087. + goto out;
  23088. + }
  23089. +
  23090. + write_lock_bh(&arm_state->susp_res_lock);
  23091. + while (arm_state->resume_blocked) {
  23092. + /* If we call 'use' while force suspend is waiting for suspend,
  23093. + * then we're about to block the thread which the force is
  23094. + * waiting to complete, so we're bound to just time out. In this
  23095. + * case, set the suspend state such that the wait will be
  23096. + * canceled, so we can complete as quickly as possible. */
  23097. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  23098. + VC_SUSPEND_IDLE) {
  23099. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  23100. + break;
  23101. + }
  23102. + /* If suspend is already in progress then we need to block */
  23103. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  23104. + /* Indicate that there are threads waiting on the resume
  23105. + * blocker. These need to be allowed to complete before
  23106. + * a _second_ call to force suspend can complete,
  23107. + * otherwise low priority threads might never actually
  23108. + * continue */
  23109. + arm_state->blocked_count++;
  23110. + write_unlock_bh(&arm_state->susp_res_lock);
  23111. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  23112. + "blocked - waiting...", __func__, entity);
  23113. + if (wait_for_completion_killable(
  23114. + &arm_state->resume_blocker) != 0) {
  23115. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  23116. + "wait for resume blocker interrupted",
  23117. + __func__, entity);
  23118. + ret = VCHIQ_ERROR;
  23119. + write_lock_bh(&arm_state->susp_res_lock);
  23120. + arm_state->blocked_count--;
  23121. + write_unlock_bh(&arm_state->susp_res_lock);
  23122. + goto out;
  23123. + }
  23124. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  23125. + "unblocked", __func__, entity);
  23126. + write_lock_bh(&arm_state->susp_res_lock);
  23127. + if (--arm_state->blocked_count == 0)
  23128. + complete_all(&arm_state->blocked_blocker);
  23129. + }
  23130. + }
  23131. +
  23132. + stop_suspend_timer(arm_state);
  23133. +
  23134. + local_uc = ++arm_state->videocore_use_count;
  23135. + local_entity_uc = ++(*entity_uc);
  23136. +
  23137. + /* If there's a pending request which hasn't yet been serviced then
  23138. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  23139. + * vc_resume_complete will block until we either resume or fail to
  23140. + * suspend */
  23141. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  23142. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  23143. +
  23144. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  23145. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  23146. + vchiq_log_info(vchiq_susp_log_level,
  23147. + "%s %s count %d, state count %d",
  23148. + __func__, entity, local_entity_uc, local_uc);
  23149. + request_poll(state, NULL, 0);
  23150. + } else
  23151. + vchiq_log_trace(vchiq_susp_log_level,
  23152. + "%s %s count %d, state count %d",
  23153. + __func__, entity, *entity_uc, local_uc);
  23154. +
  23155. +
  23156. + write_unlock_bh(&arm_state->susp_res_lock);
  23157. +
  23158. + /* Completion is in a done state when we're not suspended, so this won't
  23159. + * block for the non-suspended case. */
  23160. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  23161. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  23162. + __func__, entity);
  23163. + if (wait_for_completion_killable(
  23164. + &arm_state->vc_resume_complete) != 0) {
  23165. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  23166. + "resume interrupted", __func__, entity);
  23167. + ret = VCHIQ_ERROR;
  23168. + goto out;
  23169. + }
  23170. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  23171. + entity);
  23172. + }
  23173. +
  23174. + if (ret == VCHIQ_SUCCESS) {
  23175. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  23176. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  23177. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  23178. + /* Send the use notify to videocore */
  23179. + status = vchiq_send_remote_use_active(state);
  23180. + if (status == VCHIQ_SUCCESS)
  23181. + ack_cnt--;
  23182. + else
  23183. + atomic_add(ack_cnt,
  23184. + &arm_state->ka_use_ack_count);
  23185. + }
  23186. + }
  23187. +
  23188. +out:
  23189. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  23190. + return ret;
  23191. +}
  23192. +
  23193. +VCHIQ_STATUS_T
  23194. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  23195. +{
  23196. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23197. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  23198. + char entity[16];
  23199. + int *entity_uc;
  23200. + int local_uc, local_entity_uc;
  23201. +
  23202. + if (!arm_state)
  23203. + goto out;
  23204. +
  23205. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23206. +
  23207. + if (service) {
  23208. + sprintf(entity, "%c%c%c%c:%03d",
  23209. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23210. + service->client_id);
  23211. + entity_uc = &service->service_use_count;
  23212. + } else {
  23213. + sprintf(entity, "PEER: ");
  23214. + entity_uc = &arm_state->peer_use_count;
  23215. + }
  23216. +
  23217. + write_lock_bh(&arm_state->susp_res_lock);
  23218. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  23219. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  23220. + WARN_ON(!arm_state->videocore_use_count);
  23221. + WARN_ON(!(*entity_uc));
  23222. + ret = VCHIQ_ERROR;
  23223. + goto unlock;
  23224. + }
  23225. + local_uc = --arm_state->videocore_use_count;
  23226. + local_entity_uc = --(*entity_uc);
  23227. +
  23228. + if (!vchiq_videocore_wanted(state)) {
  23229. + if (vchiq_platform_use_suspend_timer() &&
  23230. + !arm_state->resume_blocked) {
  23231. + /* Only use the timer if we're not trying to force
  23232. + * suspend (=> resume_blocked) */
  23233. + start_suspend_timer(arm_state);
  23234. + } else {
  23235. + vchiq_log_info(vchiq_susp_log_level,
  23236. + "%s %s count %d, state count %d - suspending",
  23237. + __func__, entity, *entity_uc,
  23238. + arm_state->videocore_use_count);
  23239. + vchiq_arm_vcsuspend(state);
  23240. + }
  23241. + } else
  23242. + vchiq_log_trace(vchiq_susp_log_level,
  23243. + "%s %s count %d, state count %d",
  23244. + __func__, entity, *entity_uc,
  23245. + arm_state->videocore_use_count);
  23246. +
  23247. +unlock:
  23248. + write_unlock_bh(&arm_state->susp_res_lock);
  23249. +
  23250. +out:
  23251. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  23252. + return ret;
  23253. +}
  23254. +
  23255. +void
  23256. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  23257. +{
  23258. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23259. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23260. + atomic_inc(&arm_state->ka_use_count);
  23261. + complete(&arm_state->ka_evt);
  23262. +}
  23263. +
  23264. +void
  23265. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  23266. +{
  23267. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23268. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23269. + atomic_inc(&arm_state->ka_release_count);
  23270. + complete(&arm_state->ka_evt);
  23271. +}
  23272. +
  23273. +VCHIQ_STATUS_T
  23274. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  23275. +{
  23276. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  23277. +}
  23278. +
  23279. +VCHIQ_STATUS_T
  23280. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  23281. +{
  23282. + return vchiq_release_internal(service->state, service);
  23283. +}
  23284. +
  23285. +static void suspend_timer_callback(unsigned long context)
  23286. +{
  23287. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  23288. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23289. + if (!arm_state)
  23290. + goto out;
  23291. + vchiq_log_info(vchiq_susp_log_level,
  23292. + "%s - suspend timer expired - check suspend", __func__);
  23293. + vchiq_check_suspend(state);
  23294. +out:
  23295. + return;
  23296. +}
  23297. +
  23298. +VCHIQ_STATUS_T
  23299. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  23300. +{
  23301. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23302. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23303. + if (service) {
  23304. + ret = vchiq_use_internal(service->state, service,
  23305. + USE_TYPE_SERVICE_NO_RESUME);
  23306. + unlock_service(service);
  23307. + }
  23308. + return ret;
  23309. +}
  23310. +
  23311. +VCHIQ_STATUS_T
  23312. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  23313. +{
  23314. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23315. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23316. + if (service) {
  23317. + ret = vchiq_use_internal(service->state, service,
  23318. + USE_TYPE_SERVICE);
  23319. + unlock_service(service);
  23320. + }
  23321. + return ret;
  23322. +}
  23323. +
  23324. +VCHIQ_STATUS_T
  23325. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  23326. +{
  23327. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23328. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23329. + if (service) {
  23330. + ret = vchiq_release_internal(service->state, service);
  23331. + unlock_service(service);
  23332. + }
  23333. + return ret;
  23334. +}
  23335. +
  23336. +void
  23337. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  23338. +{
  23339. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23340. + int i, j = 0;
  23341. + /* Only dump 64 services */
  23342. + static const int local_max_services = 64;
  23343. + /* If there's more than 64 services, only dump ones with
  23344. + * non-zero counts */
  23345. + int only_nonzero = 0;
  23346. + static const char *nz = "<-- preventing suspend";
  23347. +
  23348. + enum vc_suspend_status vc_suspend_state;
  23349. + enum vc_resume_status vc_resume_state;
  23350. + int peer_count;
  23351. + int vc_use_count;
  23352. + int active_services;
  23353. + struct service_data_struct {
  23354. + int fourcc;
  23355. + int clientid;
  23356. + int use_count;
  23357. + } service_data[local_max_services];
  23358. +
  23359. + if (!arm_state)
  23360. + return;
  23361. +
  23362. + read_lock_bh(&arm_state->susp_res_lock);
  23363. + vc_suspend_state = arm_state->vc_suspend_state;
  23364. + vc_resume_state = arm_state->vc_resume_state;
  23365. + peer_count = arm_state->peer_use_count;
  23366. + vc_use_count = arm_state->videocore_use_count;
  23367. + active_services = state->unused_service;
  23368. + if (active_services > local_max_services)
  23369. + only_nonzero = 1;
  23370. +
  23371. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  23372. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  23373. + if (!service_ptr)
  23374. + continue;
  23375. +
  23376. + if (only_nonzero && !service_ptr->service_use_count)
  23377. + continue;
  23378. +
  23379. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  23380. + service_data[j].fourcc = service_ptr->base.fourcc;
  23381. + service_data[j].clientid = service_ptr->client_id;
  23382. + service_data[j++].use_count = service_ptr->
  23383. + service_use_count;
  23384. + }
  23385. + }
  23386. +
  23387. + read_unlock_bh(&arm_state->susp_res_lock);
  23388. +
  23389. + vchiq_log_warning(vchiq_susp_log_level,
  23390. + "-- Videcore suspend state: %s --",
  23391. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  23392. + vchiq_log_warning(vchiq_susp_log_level,
  23393. + "-- Videcore resume state: %s --",
  23394. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  23395. +
  23396. + if (only_nonzero)
  23397. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  23398. + "services (%d). Only dumping up to first %d services "
  23399. + "with non-zero use-count", active_services,
  23400. + local_max_services);
  23401. +
  23402. + for (i = 0; i < j; i++) {
  23403. + vchiq_log_warning(vchiq_susp_log_level,
  23404. + "----- %c%c%c%c:%d service count %d %s",
  23405. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  23406. + service_data[i].clientid,
  23407. + service_data[i].use_count,
  23408. + service_data[i].use_count ? nz : "");
  23409. + }
  23410. + vchiq_log_warning(vchiq_susp_log_level,
  23411. + "----- VCHIQ use count count %d", peer_count);
  23412. + vchiq_log_warning(vchiq_susp_log_level,
  23413. + "--- Overall vchiq instance use count %d", vc_use_count);
  23414. +
  23415. + vchiq_dump_platform_use_state(state);
  23416. +}
  23417. +
  23418. +VCHIQ_STATUS_T
  23419. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  23420. +{
  23421. + VCHIQ_ARM_STATE_T *arm_state;
  23422. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23423. +
  23424. + if (!service || !service->state)
  23425. + goto out;
  23426. +
  23427. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23428. +
  23429. + arm_state = vchiq_platform_get_arm_state(service->state);
  23430. +
  23431. + read_lock_bh(&arm_state->susp_res_lock);
  23432. + if (service->service_use_count)
  23433. + ret = VCHIQ_SUCCESS;
  23434. + read_unlock_bh(&arm_state->susp_res_lock);
  23435. +
  23436. + if (ret == VCHIQ_ERROR) {
  23437. + vchiq_log_error(vchiq_susp_log_level,
  23438. + "%s ERROR - %c%c%c%c:%d service count %d, "
  23439. + "state count %d, videocore suspend state %s", __func__,
  23440. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23441. + service->client_id, service->service_use_count,
  23442. + arm_state->videocore_use_count,
  23443. + suspend_state_names[arm_state->vc_suspend_state +
  23444. + VC_SUSPEND_NUM_OFFSET]);
  23445. + vchiq_dump_service_use_state(service->state);
  23446. + }
  23447. +out:
  23448. + return ret;
  23449. +}
  23450. +
  23451. +/* stub functions */
  23452. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  23453. +{
  23454. + (void)state;
  23455. +}
  23456. +
  23457. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  23458. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  23459. +{
  23460. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23461. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  23462. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  23463. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  23464. + write_lock_bh(&arm_state->susp_res_lock);
  23465. + if (!arm_state->first_connect) {
  23466. + char threadname[10];
  23467. + arm_state->first_connect = 1;
  23468. + write_unlock_bh(&arm_state->susp_res_lock);
  23469. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  23470. + state->id);
  23471. + arm_state->ka_thread = kthread_create(
  23472. + &vchiq_keepalive_thread_func,
  23473. + (void *)state,
  23474. + threadname);
  23475. + if (arm_state->ka_thread == NULL) {
  23476. + vchiq_log_error(vchiq_susp_log_level,
  23477. + "vchiq: FATAL: couldn't create thread %s",
  23478. + threadname);
  23479. + } else {
  23480. + wake_up_process(arm_state->ka_thread);
  23481. + }
  23482. + } else
  23483. + write_unlock_bh(&arm_state->susp_res_lock);
  23484. + }
  23485. +}
  23486. +
  23487. +
  23488. +/****************************************************************************
  23489. +*
  23490. +* vchiq_init - called when the module is loaded.
  23491. +*
  23492. +***************************************************************************/
  23493. +
  23494. +static int __init
  23495. +vchiq_init(void)
  23496. +{
  23497. + int err;
  23498. + void *ptr_err;
  23499. +
  23500. + /* create proc entries */
  23501. + err = vchiq_proc_init();
  23502. + if (err != 0)
  23503. + goto failed_proc_init;
  23504. +
  23505. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  23506. + if (err != 0) {
  23507. + vchiq_log_error(vchiq_arm_log_level,
  23508. + "Unable to allocate device number");
  23509. + goto failed_alloc_chrdev;
  23510. + }
  23511. + cdev_init(&vchiq_cdev, &vchiq_fops);
  23512. + vchiq_cdev.owner = THIS_MODULE;
  23513. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  23514. + if (err != 0) {
  23515. + vchiq_log_error(vchiq_arm_log_level,
  23516. + "Unable to register device");
  23517. + goto failed_cdev_add;
  23518. + }
  23519. +
  23520. + /* create sysfs entries */
  23521. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  23522. + ptr_err = vchiq_class;
  23523. + if (IS_ERR(ptr_err))
  23524. + goto failed_class_create;
  23525. +
  23526. + vchiq_dev = device_create(vchiq_class, NULL,
  23527. + vchiq_devid, NULL, "vchiq");
  23528. + ptr_err = vchiq_dev;
  23529. + if (IS_ERR(ptr_err))
  23530. + goto failed_device_create;
  23531. +
  23532. + err = vchiq_platform_init(&g_state);
  23533. + if (err != 0)
  23534. + goto failed_platform_init;
  23535. +
  23536. + vchiq_log_info(vchiq_arm_log_level,
  23537. + "vchiq: initialised - version %d (min %d), device %d.%d",
  23538. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  23539. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  23540. +
  23541. + return 0;
  23542. +
  23543. +failed_platform_init:
  23544. + device_destroy(vchiq_class, vchiq_devid);
  23545. +failed_device_create:
  23546. + class_destroy(vchiq_class);
  23547. +failed_class_create:
  23548. + cdev_del(&vchiq_cdev);
  23549. + err = PTR_ERR(ptr_err);
  23550. +failed_cdev_add:
  23551. + unregister_chrdev_region(vchiq_devid, 1);
  23552. +failed_alloc_chrdev:
  23553. + vchiq_proc_deinit();
  23554. +failed_proc_init:
  23555. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  23556. + return err;
  23557. +}
  23558. +
  23559. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  23560. +{
  23561. + VCHIQ_SERVICE_T *service;
  23562. + int use_count = 0, i;
  23563. + i = 0;
  23564. + while ((service = next_service_by_instance(instance->state,
  23565. + instance, &i)) != NULL) {
  23566. + use_count += service->service_use_count;
  23567. + unlock_service(service);
  23568. + }
  23569. + return use_count;
  23570. +}
  23571. +
  23572. +/* read the per-process use-count */
  23573. +static int proc_read_use_count(char *page, char **start,
  23574. + off_t off, int count,
  23575. + int *eof, void *data)
  23576. +{
  23577. + VCHIQ_INSTANCE_T instance = data;
  23578. + int len, use_count;
  23579. +
  23580. + use_count = vchiq_instance_get_use_count(instance);
  23581. + len = snprintf(page+off, count, "%d\n", use_count);
  23582. +
  23583. + return len;
  23584. +}
  23585. +
  23586. +/* add an instance (process) to the proc entries */
  23587. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  23588. +{
  23589. +#if 1
  23590. + return 0;
  23591. +#else
  23592. + char pidstr[32];
  23593. + struct proc_dir_entry *top, *use_count;
  23594. + struct proc_dir_entry *clients = vchiq_clients_top();
  23595. + int pid = instance->pid;
  23596. +
  23597. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  23598. + top = proc_mkdir(pidstr, clients);
  23599. + if (!top)
  23600. + goto fail_top;
  23601. +
  23602. + use_count = create_proc_read_entry("use_count",
  23603. + 0444, top,
  23604. + proc_read_use_count,
  23605. + instance);
  23606. + if (!use_count)
  23607. + goto fail_use_count;
  23608. +
  23609. + instance->proc_entry = top;
  23610. +
  23611. + return 0;
  23612. +
  23613. +fail_use_count:
  23614. + remove_proc_entry(top->name, clients);
  23615. +fail_top:
  23616. + return -ENOMEM;
  23617. +#endif
  23618. +}
  23619. +
  23620. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  23621. +{
  23622. +#if 0
  23623. + struct proc_dir_entry *clients = vchiq_clients_top();
  23624. + remove_proc_entry("use_count", instance->proc_entry);
  23625. + remove_proc_entry(instance->proc_entry->name, clients);
  23626. +#endif
  23627. +}
  23628. +
  23629. +/****************************************************************************
  23630. +*
  23631. +* vchiq_exit - called when the module is unloaded.
  23632. +*
  23633. +***************************************************************************/
  23634. +
  23635. +static void __exit
  23636. +vchiq_exit(void)
  23637. +{
  23638. + vchiq_platform_exit(&g_state);
  23639. + device_destroy(vchiq_class, vchiq_devid);
  23640. + class_destroy(vchiq_class);
  23641. + cdev_del(&vchiq_cdev);
  23642. + unregister_chrdev_region(vchiq_devid, 1);
  23643. +}
  23644. +
  23645. +module_init(vchiq_init);
  23646. +module_exit(vchiq_exit);
  23647. +MODULE_LICENSE("GPL");
  23648. +MODULE_AUTHOR("Broadcom Corporation");
  23649. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  23650. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  23651. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-03-13 12:46:20.596060066 +0100
  23652. @@ -0,0 +1,212 @@
  23653. +/**
  23654. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23655. + *
  23656. + * Redistribution and use in source and binary forms, with or without
  23657. + * modification, are permitted provided that the following conditions
  23658. + * are met:
  23659. + * 1. Redistributions of source code must retain the above copyright
  23660. + * notice, this list of conditions, and the following disclaimer,
  23661. + * without modification.
  23662. + * 2. Redistributions in binary form must reproduce the above copyright
  23663. + * notice, this list of conditions and the following disclaimer in the
  23664. + * documentation and/or other materials provided with the distribution.
  23665. + * 3. The names of the above-listed copyright holders may not be used
  23666. + * to endorse or promote products derived from this software without
  23667. + * specific prior written permission.
  23668. + *
  23669. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23670. + * GNU General Public License ("GPL") version 2, as published by the Free
  23671. + * Software Foundation.
  23672. + *
  23673. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23674. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23675. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23676. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23677. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23678. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23679. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23680. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23681. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23682. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23683. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23684. + */
  23685. +
  23686. +#ifndef VCHIQ_ARM_H
  23687. +#define VCHIQ_ARM_H
  23688. +
  23689. +#include <linux/mutex.h>
  23690. +#include <linux/semaphore.h>
  23691. +#include <linux/atomic.h>
  23692. +#include "vchiq_core.h"
  23693. +
  23694. +
  23695. +enum vc_suspend_status {
  23696. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  23697. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  23698. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  23699. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  23700. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  23701. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  23702. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  23703. +};
  23704. +
  23705. +enum vc_resume_status {
  23706. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  23707. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  23708. + VC_RESUME_REQUESTED, /* User has requested resume */
  23709. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  23710. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  23711. +};
  23712. +
  23713. +
  23714. +enum USE_TYPE_E {
  23715. + USE_TYPE_SERVICE,
  23716. + USE_TYPE_SERVICE_NO_RESUME,
  23717. + USE_TYPE_VCHIQ
  23718. +};
  23719. +
  23720. +
  23721. +
  23722. +typedef struct vchiq_arm_state_struct {
  23723. + /* Keepalive-related data */
  23724. + struct task_struct *ka_thread;
  23725. + struct completion ka_evt;
  23726. + atomic_t ka_use_count;
  23727. + atomic_t ka_use_ack_count;
  23728. + atomic_t ka_release_count;
  23729. +
  23730. + struct completion vc_suspend_complete;
  23731. + struct completion vc_resume_complete;
  23732. +
  23733. + rwlock_t susp_res_lock;
  23734. + enum vc_suspend_status vc_suspend_state;
  23735. + enum vc_resume_status vc_resume_state;
  23736. +
  23737. + unsigned int wake_address;
  23738. +
  23739. + struct timer_list suspend_timer;
  23740. + int suspend_timer_timeout;
  23741. + int suspend_timer_running;
  23742. +
  23743. + /* Global use count for videocore.
  23744. + ** This is equal to the sum of the use counts for all services. When
  23745. + ** this hits zero the videocore suspend procedure will be initiated.
  23746. + */
  23747. + int videocore_use_count;
  23748. +
  23749. + /* Use count to track requests from videocore peer.
  23750. + ** This use count is not associated with a service, so needs to be
  23751. + ** tracked separately with the state.
  23752. + */
  23753. + int peer_use_count;
  23754. +
  23755. + /* Flag to indicate whether resume is blocked. This happens when the
  23756. + ** ARM is suspending
  23757. + */
  23758. + struct completion resume_blocker;
  23759. + int resume_blocked;
  23760. + struct completion blocked_blocker;
  23761. + int blocked_count;
  23762. +
  23763. + int autosuspend_override;
  23764. +
  23765. + /* Flag to indicate that the first vchiq connect has made it through.
  23766. + ** This means that both sides should be fully ready, and we should
  23767. + ** be able to suspend after this point.
  23768. + */
  23769. + int first_connect;
  23770. +
  23771. + unsigned long long suspend_start_time;
  23772. + unsigned long long sleep_start_time;
  23773. + unsigned long long resume_start_time;
  23774. + unsigned long long last_wake_time;
  23775. +
  23776. +} VCHIQ_ARM_STATE_T;
  23777. +
  23778. +extern int vchiq_arm_log_level;
  23779. +extern int vchiq_susp_log_level;
  23780. +
  23781. +extern int __init
  23782. +vchiq_platform_init(VCHIQ_STATE_T *state);
  23783. +
  23784. +extern void __exit
  23785. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  23786. +
  23787. +extern VCHIQ_STATE_T *
  23788. +vchiq_get_state(void);
  23789. +
  23790. +extern VCHIQ_STATUS_T
  23791. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  23792. +
  23793. +extern VCHIQ_STATUS_T
  23794. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  23795. +
  23796. +extern int
  23797. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  23798. +
  23799. +extern VCHIQ_STATUS_T
  23800. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  23801. +
  23802. +extern VCHIQ_STATUS_T
  23803. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  23804. +
  23805. +extern int
  23806. +vchiq_check_resume(VCHIQ_STATE_T *state);
  23807. +
  23808. +extern void
  23809. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  23810. +
  23811. +extern VCHIQ_STATUS_T
  23812. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  23813. +
  23814. +extern VCHIQ_STATUS_T
  23815. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  23816. +
  23817. +extern VCHIQ_STATUS_T
  23818. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  23819. +
  23820. +extern VCHIQ_STATUS_T
  23821. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  23822. +
  23823. +extern int
  23824. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  23825. +
  23826. +extern int
  23827. +vchiq_platform_use_suspend_timer(void);
  23828. +
  23829. +extern void
  23830. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  23831. +
  23832. +extern void
  23833. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  23834. +
  23835. +extern VCHIQ_ARM_STATE_T*
  23836. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  23837. +
  23838. +extern int
  23839. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  23840. +
  23841. +extern VCHIQ_STATUS_T
  23842. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23843. + enum USE_TYPE_E use_type);
  23844. +extern VCHIQ_STATUS_T
  23845. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  23846. +
  23847. +void
  23848. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  23849. + enum vc_suspend_status new_state);
  23850. +
  23851. +void
  23852. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  23853. + enum vc_resume_status new_state);
  23854. +
  23855. +void
  23856. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  23857. +
  23858. +extern int vchiq_proc_init(void);
  23859. +extern void vchiq_proc_deinit(void);
  23860. +extern struct proc_dir_entry *vchiq_proc_top(void);
  23861. +extern struct proc_dir_entry *vchiq_clients_top(void);
  23862. +
  23863. +
  23864. +#endif /* VCHIQ_ARM_H */
  23865. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  23866. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  23867. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-03-13 12:46:20.596060066 +0100
  23868. @@ -0,0 +1,37 @@
  23869. +/**
  23870. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23871. + *
  23872. + * Redistribution and use in source and binary forms, with or without
  23873. + * modification, are permitted provided that the following conditions
  23874. + * are met:
  23875. + * 1. Redistributions of source code must retain the above copyright
  23876. + * notice, this list of conditions, and the following disclaimer,
  23877. + * without modification.
  23878. + * 2. Redistributions in binary form must reproduce the above copyright
  23879. + * notice, this list of conditions and the following disclaimer in the
  23880. + * documentation and/or other materials provided with the distribution.
  23881. + * 3. The names of the above-listed copyright holders may not be used
  23882. + * to endorse or promote products derived from this software without
  23883. + * specific prior written permission.
  23884. + *
  23885. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23886. + * GNU General Public License ("GPL") version 2, as published by the Free
  23887. + * Software Foundation.
  23888. + *
  23889. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23890. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23891. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23892. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23893. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23894. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23895. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23896. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23897. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23898. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23899. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23900. + */
  23901. +
  23902. +const char *vchiq_get_build_hostname(void);
  23903. +const char *vchiq_get_build_version(void);
  23904. +const char *vchiq_get_build_time(void);
  23905. +const char *vchiq_get_build_date(void);
  23906. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  23907. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  23908. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-03-13 12:46:20.596060066 +0100
  23909. @@ -0,0 +1,60 @@
  23910. +/**
  23911. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23912. + *
  23913. + * Redistribution and use in source and binary forms, with or without
  23914. + * modification, are permitted provided that the following conditions
  23915. + * are met:
  23916. + * 1. Redistributions of source code must retain the above copyright
  23917. + * notice, this list of conditions, and the following disclaimer,
  23918. + * without modification.
  23919. + * 2. Redistributions in binary form must reproduce the above copyright
  23920. + * notice, this list of conditions and the following disclaimer in the
  23921. + * documentation and/or other materials provided with the distribution.
  23922. + * 3. The names of the above-listed copyright holders may not be used
  23923. + * to endorse or promote products derived from this software without
  23924. + * specific prior written permission.
  23925. + *
  23926. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23927. + * GNU General Public License ("GPL") version 2, as published by the Free
  23928. + * Software Foundation.
  23929. + *
  23930. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23931. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23932. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23933. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23934. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23935. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23936. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23937. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23938. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23939. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23940. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23941. + */
  23942. +
  23943. +#ifndef VCHIQ_CFG_H
  23944. +#define VCHIQ_CFG_H
  23945. +
  23946. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  23947. +/* The version of VCHIQ - change with any non-trivial change */
  23948. +#define VCHIQ_VERSION 6
  23949. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  23950. +** incompatible change */
  23951. +#define VCHIQ_VERSION_MIN 3
  23952. +
  23953. +#define VCHIQ_MAX_STATES 1
  23954. +#define VCHIQ_MAX_SERVICES 4096
  23955. +#define VCHIQ_MAX_SLOTS 128
  23956. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  23957. +
  23958. +#define VCHIQ_NUM_CURRENT_BULKS 32
  23959. +#define VCHIQ_NUM_SERVICE_BULKS 4
  23960. +
  23961. +#ifndef VCHIQ_ENABLE_DEBUG
  23962. +#define VCHIQ_ENABLE_DEBUG 1
  23963. +#endif
  23964. +
  23965. +#ifndef VCHIQ_ENABLE_STATS
  23966. +#define VCHIQ_ENABLE_STATS 1
  23967. +#endif
  23968. +
  23969. +#endif /* VCHIQ_CFG_H */
  23970. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  23971. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  23972. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-03-13 12:46:20.596060066 +0100
  23973. @@ -0,0 +1,119 @@
  23974. +/**
  23975. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23976. + *
  23977. + * Redistribution and use in source and binary forms, with or without
  23978. + * modification, are permitted provided that the following conditions
  23979. + * are met:
  23980. + * 1. Redistributions of source code must retain the above copyright
  23981. + * notice, this list of conditions, and the following disclaimer,
  23982. + * without modification.
  23983. + * 2. Redistributions in binary form must reproduce the above copyright
  23984. + * notice, this list of conditions and the following disclaimer in the
  23985. + * documentation and/or other materials provided with the distribution.
  23986. + * 3. The names of the above-listed copyright holders may not be used
  23987. + * to endorse or promote products derived from this software without
  23988. + * specific prior written permission.
  23989. + *
  23990. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23991. + * GNU General Public License ("GPL") version 2, as published by the Free
  23992. + * Software Foundation.
  23993. + *
  23994. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23995. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23996. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23997. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23998. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23999. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24000. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24001. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24002. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24003. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24004. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24005. + */
  24006. +
  24007. +#include "vchiq_connected.h"
  24008. +#include "vchiq_core.h"
  24009. +#include <linux/module.h>
  24010. +#include <linux/mutex.h>
  24011. +
  24012. +#define MAX_CALLBACKS 10
  24013. +
  24014. +static int g_connected;
  24015. +static int g_num_deferred_callbacks;
  24016. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  24017. +static int g_once_init;
  24018. +static struct mutex g_connected_mutex;
  24019. +
  24020. +/****************************************************************************
  24021. +*
  24022. +* Function to initialize our lock.
  24023. +*
  24024. +***************************************************************************/
  24025. +
  24026. +static void connected_init(void)
  24027. +{
  24028. + if (!g_once_init) {
  24029. + mutex_init(&g_connected_mutex);
  24030. + g_once_init = 1;
  24031. + }
  24032. +}
  24033. +
  24034. +/****************************************************************************
  24035. +*
  24036. +* This function is used to defer initialization until the vchiq stack is
  24037. +* initialized. If the stack is already initialized, then the callback will
  24038. +* be made immediately, otherwise it will be deferred until
  24039. +* vchiq_call_connected_callbacks is called.
  24040. +*
  24041. +***************************************************************************/
  24042. +
  24043. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  24044. +{
  24045. + connected_init();
  24046. +
  24047. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  24048. + return;
  24049. +
  24050. + if (g_connected)
  24051. + /* We're already connected. Call the callback immediately. */
  24052. +
  24053. + callback();
  24054. + else {
  24055. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  24056. + vchiq_log_error(vchiq_core_log_level,
  24057. + "There already %d callback registered - "
  24058. + "please increase MAX_CALLBACKS",
  24059. + g_num_deferred_callbacks);
  24060. + else {
  24061. + g_deferred_callback[g_num_deferred_callbacks] =
  24062. + callback;
  24063. + g_num_deferred_callbacks++;
  24064. + }
  24065. + }
  24066. + mutex_unlock(&g_connected_mutex);
  24067. +}
  24068. +
  24069. +/****************************************************************************
  24070. +*
  24071. +* This function is called by the vchiq stack once it has been connected to
  24072. +* the videocore and clients can start to use the stack.
  24073. +*
  24074. +***************************************************************************/
  24075. +
  24076. +void vchiq_call_connected_callbacks(void)
  24077. +{
  24078. + int i;
  24079. +
  24080. + connected_init();
  24081. +
  24082. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  24083. + return;
  24084. +
  24085. + for (i = 0; i < g_num_deferred_callbacks; i++)
  24086. + g_deferred_callback[i]();
  24087. +
  24088. + g_num_deferred_callbacks = 0;
  24089. + g_connected = 1;
  24090. + mutex_unlock(&g_connected_mutex);
  24091. +}
  24092. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  24093. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  24094. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  24095. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-03-13 12:46:20.596060066 +0100
  24096. @@ -0,0 +1,51 @@
  24097. +/**
  24098. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24099. + *
  24100. + * Redistribution and use in source and binary forms, with or without
  24101. + * modification, are permitted provided that the following conditions
  24102. + * are met:
  24103. + * 1. Redistributions of source code must retain the above copyright
  24104. + * notice, this list of conditions, and the following disclaimer,
  24105. + * without modification.
  24106. + * 2. Redistributions in binary form must reproduce the above copyright
  24107. + * notice, this list of conditions and the following disclaimer in the
  24108. + * documentation and/or other materials provided with the distribution.
  24109. + * 3. The names of the above-listed copyright holders may not be used
  24110. + * to endorse or promote products derived from this software without
  24111. + * specific prior written permission.
  24112. + *
  24113. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24114. + * GNU General Public License ("GPL") version 2, as published by the Free
  24115. + * Software Foundation.
  24116. + *
  24117. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24118. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24119. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24120. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24121. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24122. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24123. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24124. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24125. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24126. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24127. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24128. + */
  24129. +
  24130. +#ifndef VCHIQ_CONNECTED_H
  24131. +#define VCHIQ_CONNECTED_H
  24132. +
  24133. +/* ---- Include Files ----------------------------------------------------- */
  24134. +
  24135. +/* ---- Constants and Types ---------------------------------------------- */
  24136. +
  24137. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  24138. +
  24139. +/* ---- Variable Externs ------------------------------------------------- */
  24140. +
  24141. +/* ---- Function Prototypes ---------------------------------------------- */
  24142. +
  24143. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  24144. +void vchiq_call_connected_callbacks(void);
  24145. +
  24146. +#endif /* VCHIQ_CONNECTED_H */
  24147. +
  24148. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  24149. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  24150. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-03-13 12:46:20.596060066 +0100
  24151. @@ -0,0 +1,3824 @@
  24152. +/**
  24153. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24154. + *
  24155. + * Redistribution and use in source and binary forms, with or without
  24156. + * modification, are permitted provided that the following conditions
  24157. + * are met:
  24158. + * 1. Redistributions of source code must retain the above copyright
  24159. + * notice, this list of conditions, and the following disclaimer,
  24160. + * without modification.
  24161. + * 2. Redistributions in binary form must reproduce the above copyright
  24162. + * notice, this list of conditions and the following disclaimer in the
  24163. + * documentation and/or other materials provided with the distribution.
  24164. + * 3. The names of the above-listed copyright holders may not be used
  24165. + * to endorse or promote products derived from this software without
  24166. + * specific prior written permission.
  24167. + *
  24168. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24169. + * GNU General Public License ("GPL") version 2, as published by the Free
  24170. + * Software Foundation.
  24171. + *
  24172. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24173. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24174. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24175. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24176. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24177. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24178. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24179. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24180. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24181. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24182. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24183. + */
  24184. +
  24185. +#include "vchiq_core.h"
  24186. +
  24187. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  24188. +
  24189. +#define HANDLE_STATE_SHIFT 12
  24190. +
  24191. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  24192. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  24193. +#define SLOT_INDEX_FROM_DATA(state, data) \
  24194. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  24195. + VCHIQ_SLOT_SIZE)
  24196. +#define SLOT_INDEX_FROM_INFO(state, info) \
  24197. + ((unsigned int)(info - state->slot_info))
  24198. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  24199. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  24200. +
  24201. +
  24202. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  24203. +
  24204. +
  24205. +struct vchiq_open_payload {
  24206. + int fourcc;
  24207. + int client_id;
  24208. + short version;
  24209. + short version_min;
  24210. +};
  24211. +
  24212. +struct vchiq_openack_payload {
  24213. + short version;
  24214. +};
  24215. +
  24216. +/* we require this for consistency between endpoints */
  24217. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  24218. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  24219. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  24220. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  24221. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  24222. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  24223. +
  24224. +/* Run time control of log level, based on KERN_XXX level. */
  24225. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  24226. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  24227. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  24228. +
  24229. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  24230. +
  24231. +static DEFINE_SPINLOCK(service_spinlock);
  24232. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  24233. +DEFINE_SPINLOCK(quota_spinlock);
  24234. +
  24235. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  24236. +static unsigned int handle_seq;
  24237. +
  24238. +static const char *const srvstate_names[] = {
  24239. + "FREE",
  24240. + "HIDDEN",
  24241. + "LISTENING",
  24242. + "OPENING",
  24243. + "OPEN",
  24244. + "OPENSYNC",
  24245. + "CLOSESENT",
  24246. + "CLOSERECVD",
  24247. + "CLOSEWAIT",
  24248. + "CLOSED"
  24249. +};
  24250. +
  24251. +static const char *const reason_names[] = {
  24252. + "SERVICE_OPENED",
  24253. + "SERVICE_CLOSED",
  24254. + "MESSAGE_AVAILABLE",
  24255. + "BULK_TRANSMIT_DONE",
  24256. + "BULK_RECEIVE_DONE",
  24257. + "BULK_TRANSMIT_ABORTED",
  24258. + "BULK_RECEIVE_ABORTED"
  24259. +};
  24260. +
  24261. +static const char *const conn_state_names[] = {
  24262. + "DISCONNECTED",
  24263. + "CONNECTING",
  24264. + "CONNECTED",
  24265. + "PAUSING",
  24266. + "PAUSE_SENT",
  24267. + "PAUSED",
  24268. + "RESUMING",
  24269. + "PAUSE_TIMEOUT",
  24270. + "RESUME_TIMEOUT"
  24271. +};
  24272. +
  24273. +
  24274. +static void
  24275. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  24276. +
  24277. +static const char *msg_type_str(unsigned int msg_type)
  24278. +{
  24279. + switch (msg_type) {
  24280. + case VCHIQ_MSG_PADDING: return "PADDING";
  24281. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  24282. + case VCHIQ_MSG_OPEN: return "OPEN";
  24283. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  24284. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  24285. + case VCHIQ_MSG_DATA: return "DATA";
  24286. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  24287. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  24288. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  24289. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  24290. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  24291. + case VCHIQ_MSG_RESUME: return "RESUME";
  24292. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  24293. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  24294. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  24295. + }
  24296. + return "???";
  24297. +}
  24298. +
  24299. +static inline void
  24300. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  24301. +{
  24302. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  24303. + service->state->id, service->localport,
  24304. + srvstate_names[service->srvstate],
  24305. + srvstate_names[newstate]);
  24306. + service->srvstate = newstate;
  24307. +}
  24308. +
  24309. +VCHIQ_SERVICE_T *
  24310. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  24311. +{
  24312. + VCHIQ_SERVICE_T *service;
  24313. +
  24314. + spin_lock(&service_spinlock);
  24315. + service = handle_to_service(handle);
  24316. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  24317. + (service->handle == handle)) {
  24318. + BUG_ON(service->ref_count == 0);
  24319. + service->ref_count++;
  24320. + } else
  24321. + service = NULL;
  24322. + spin_unlock(&service_spinlock);
  24323. +
  24324. + if (!service)
  24325. + vchiq_log_info(vchiq_core_log_level,
  24326. + "Invalid service handle 0x%x", handle);
  24327. +
  24328. + return service;
  24329. +}
  24330. +
  24331. +VCHIQ_SERVICE_T *
  24332. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  24333. +{
  24334. + VCHIQ_SERVICE_T *service = NULL;
  24335. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  24336. + spin_lock(&service_spinlock);
  24337. + service = state->services[localport];
  24338. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  24339. + BUG_ON(service->ref_count == 0);
  24340. + service->ref_count++;
  24341. + } else
  24342. + service = NULL;
  24343. + spin_unlock(&service_spinlock);
  24344. + }
  24345. +
  24346. + if (!service)
  24347. + vchiq_log_info(vchiq_core_log_level,
  24348. + "Invalid port %d", localport);
  24349. +
  24350. + return service;
  24351. +}
  24352. +
  24353. +VCHIQ_SERVICE_T *
  24354. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  24355. + VCHIQ_SERVICE_HANDLE_T handle) {
  24356. + VCHIQ_SERVICE_T *service;
  24357. +
  24358. + spin_lock(&service_spinlock);
  24359. + service = handle_to_service(handle);
  24360. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  24361. + (service->handle == handle) &&
  24362. + (service->instance == instance)) {
  24363. + BUG_ON(service->ref_count == 0);
  24364. + service->ref_count++;
  24365. + } else
  24366. + service = NULL;
  24367. + spin_unlock(&service_spinlock);
  24368. +
  24369. + if (!service)
  24370. + vchiq_log_info(vchiq_core_log_level,
  24371. + "Invalid service handle 0x%x", handle);
  24372. +
  24373. + return service;
  24374. +}
  24375. +
  24376. +VCHIQ_SERVICE_T *
  24377. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  24378. + int *pidx)
  24379. +{
  24380. + VCHIQ_SERVICE_T *service = NULL;
  24381. + int idx = *pidx;
  24382. +
  24383. + spin_lock(&service_spinlock);
  24384. + while (idx < state->unused_service) {
  24385. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  24386. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  24387. + (srv->instance == instance)) {
  24388. + service = srv;
  24389. + BUG_ON(service->ref_count == 0);
  24390. + service->ref_count++;
  24391. + break;
  24392. + }
  24393. + }
  24394. + spin_unlock(&service_spinlock);
  24395. +
  24396. + *pidx = idx;
  24397. +
  24398. + return service;
  24399. +}
  24400. +
  24401. +void
  24402. +lock_service(VCHIQ_SERVICE_T *service)
  24403. +{
  24404. + spin_lock(&service_spinlock);
  24405. + BUG_ON(!service || (service->ref_count == 0));
  24406. + if (service)
  24407. + service->ref_count++;
  24408. + spin_unlock(&service_spinlock);
  24409. +}
  24410. +
  24411. +void
  24412. +unlock_service(VCHIQ_SERVICE_T *service)
  24413. +{
  24414. + VCHIQ_STATE_T *state = service->state;
  24415. + spin_lock(&service_spinlock);
  24416. + BUG_ON(!service || (service->ref_count == 0));
  24417. + if (service && service->ref_count) {
  24418. + service->ref_count--;
  24419. + if (!service->ref_count) {
  24420. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  24421. + state->services[service->localport] = NULL;
  24422. + } else
  24423. + service = NULL;
  24424. + }
  24425. + spin_unlock(&service_spinlock);
  24426. +
  24427. + if (service && service->userdata_term)
  24428. + service->userdata_term(service->base.userdata);
  24429. +
  24430. + kfree(service);
  24431. +}
  24432. +
  24433. +int
  24434. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  24435. +{
  24436. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  24437. + int id;
  24438. +
  24439. + id = service ? service->client_id : 0;
  24440. + if (service)
  24441. + unlock_service(service);
  24442. +
  24443. + return id;
  24444. +}
  24445. +
  24446. +void *
  24447. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  24448. +{
  24449. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  24450. +
  24451. + return service ? service->base.userdata : NULL;
  24452. +}
  24453. +
  24454. +int
  24455. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  24456. +{
  24457. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  24458. +
  24459. + return service ? service->base.fourcc : 0;
  24460. +}
  24461. +
  24462. +static void
  24463. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  24464. +{
  24465. + VCHIQ_STATE_T *state = service->state;
  24466. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  24467. +
  24468. + service->closing = 1;
  24469. +
  24470. + /* Synchronise with other threads. */
  24471. + mutex_lock(&state->recycle_mutex);
  24472. + mutex_unlock(&state->recycle_mutex);
  24473. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  24474. + /* If we're pausing then the slot_mutex is held until resume
  24475. + * by the slot handler. Therefore don't try to acquire this
  24476. + * mutex if we're the slot handler and in the pause sent state.
  24477. + * We don't need to in this case anyway. */
  24478. + mutex_lock(&state->slot_mutex);
  24479. + mutex_unlock(&state->slot_mutex);
  24480. + }
  24481. +
  24482. + /* Unblock any sending thread. */
  24483. + service_quota = &state->service_quotas[service->localport];
  24484. + up(&service_quota->quota_event);
  24485. +}
  24486. +
  24487. +static void
  24488. +mark_service_closing(VCHIQ_SERVICE_T *service)
  24489. +{
  24490. + mark_service_closing_internal(service, 0);
  24491. +}
  24492. +
  24493. +static inline VCHIQ_STATUS_T
  24494. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  24495. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  24496. +{
  24497. + VCHIQ_STATUS_T status;
  24498. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  24499. + service->state->id, service->localport, reason_names[reason],
  24500. + (unsigned int)header, (unsigned int)bulk_userdata);
  24501. + status = service->base.callback(reason, header, service->handle,
  24502. + bulk_userdata);
  24503. + if (status == VCHIQ_ERROR) {
  24504. + vchiq_log_warning(vchiq_core_log_level,
  24505. + "%d: ignoring ERROR from callback to service %x",
  24506. + service->state->id, service->handle);
  24507. + status = VCHIQ_SUCCESS;
  24508. + }
  24509. + return status;
  24510. +}
  24511. +
  24512. +inline void
  24513. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  24514. +{
  24515. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  24516. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  24517. + conn_state_names[oldstate],
  24518. + conn_state_names[newstate]);
  24519. + state->conn_state = newstate;
  24520. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  24521. +}
  24522. +
  24523. +static inline void
  24524. +remote_event_create(REMOTE_EVENT_T *event)
  24525. +{
  24526. + event->armed = 0;
  24527. + /* Don't clear the 'fired' flag because it may already have been set
  24528. + ** by the other side. */
  24529. + sema_init(event->event, 0);
  24530. +}
  24531. +
  24532. +static inline void
  24533. +remote_event_destroy(REMOTE_EVENT_T *event)
  24534. +{
  24535. + (void)event;
  24536. +}
  24537. +
  24538. +static inline int
  24539. +remote_event_wait(REMOTE_EVENT_T *event)
  24540. +{
  24541. + if (!event->fired) {
  24542. + event->armed = 1;
  24543. + dsb();
  24544. + if (!event->fired) {
  24545. + if (down_interruptible(event->event) != 0) {
  24546. + event->armed = 0;
  24547. + return 0;
  24548. + }
  24549. + }
  24550. + event->armed = 0;
  24551. + wmb();
  24552. + }
  24553. +
  24554. + event->fired = 0;
  24555. + return 1;
  24556. +}
  24557. +
  24558. +static inline void
  24559. +remote_event_signal_local(REMOTE_EVENT_T *event)
  24560. +{
  24561. + event->armed = 0;
  24562. + up(event->event);
  24563. +}
  24564. +
  24565. +static inline void
  24566. +remote_event_poll(REMOTE_EVENT_T *event)
  24567. +{
  24568. + if (event->fired && event->armed)
  24569. + remote_event_signal_local(event);
  24570. +}
  24571. +
  24572. +void
  24573. +remote_event_pollall(VCHIQ_STATE_T *state)
  24574. +{
  24575. + remote_event_poll(&state->local->sync_trigger);
  24576. + remote_event_poll(&state->local->sync_release);
  24577. + remote_event_poll(&state->local->trigger);
  24578. + remote_event_poll(&state->local->recycle);
  24579. +}
  24580. +
  24581. +/* Round up message sizes so that any space at the end of a slot is always big
  24582. +** enough for a header. This relies on header size being a power of two, which
  24583. +** has been verified earlier by a static assertion. */
  24584. +
  24585. +static inline unsigned int
  24586. +calc_stride(unsigned int size)
  24587. +{
  24588. + /* Allow room for the header */
  24589. + size += sizeof(VCHIQ_HEADER_T);
  24590. +
  24591. + /* Round up */
  24592. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  24593. + - 1);
  24594. +}
  24595. +
  24596. +/* Called by the slot handler thread */
  24597. +static VCHIQ_SERVICE_T *
  24598. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  24599. +{
  24600. + int i;
  24601. +
  24602. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  24603. +
  24604. + for (i = 0; i < state->unused_service; i++) {
  24605. + VCHIQ_SERVICE_T *service = state->services[i];
  24606. + if (service &&
  24607. + (service->public_fourcc == fourcc) &&
  24608. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  24609. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  24610. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  24611. + lock_service(service);
  24612. + return service;
  24613. + }
  24614. + }
  24615. +
  24616. + return NULL;
  24617. +}
  24618. +
  24619. +/* Called by the slot handler thread */
  24620. +static VCHIQ_SERVICE_T *
  24621. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  24622. +{
  24623. + int i;
  24624. + for (i = 0; i < state->unused_service; i++) {
  24625. + VCHIQ_SERVICE_T *service = state->services[i];
  24626. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  24627. + && (service->remoteport == port)) {
  24628. + lock_service(service);
  24629. + return service;
  24630. + }
  24631. + }
  24632. + return NULL;
  24633. +}
  24634. +
  24635. +inline void
  24636. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  24637. +{
  24638. + uint32_t value;
  24639. +
  24640. + if (service) {
  24641. + do {
  24642. + value = atomic_read(&service->poll_flags);
  24643. + } while (atomic_cmpxchg(&service->poll_flags, value,
  24644. + value | (1 << poll_type)) != value);
  24645. +
  24646. + do {
  24647. + value = atomic_read(&state->poll_services[
  24648. + service->localport>>5]);
  24649. + } while (atomic_cmpxchg(
  24650. + &state->poll_services[service->localport>>5],
  24651. + value, value | (1 << (service->localport & 0x1f)))
  24652. + != value);
  24653. + }
  24654. +
  24655. + state->poll_needed = 1;
  24656. + wmb();
  24657. +
  24658. + /* ... and ensure the slot handler runs. */
  24659. + remote_event_signal_local(&state->local->trigger);
  24660. +}
  24661. +
  24662. +/* Called from queue_message, by the slot handler and application threads,
  24663. +** with slot_mutex held */
  24664. +static VCHIQ_HEADER_T *
  24665. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  24666. +{
  24667. + VCHIQ_SHARED_STATE_T *local = state->local;
  24668. + int tx_pos = state->local_tx_pos;
  24669. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  24670. +
  24671. + if (space > slot_space) {
  24672. + VCHIQ_HEADER_T *header;
  24673. + /* Fill the remaining space with padding */
  24674. + WARN_ON(state->tx_data == NULL);
  24675. + header = (VCHIQ_HEADER_T *)
  24676. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24677. + header->msgid = VCHIQ_MSGID_PADDING;
  24678. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  24679. +
  24680. + tx_pos += slot_space;
  24681. + }
  24682. +
  24683. + /* If necessary, get the next slot. */
  24684. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  24685. + int slot_index;
  24686. +
  24687. + /* If there is no free slot... */
  24688. +
  24689. + if (down_trylock(&state->slot_available_event) != 0) {
  24690. + /* ...wait for one. */
  24691. +
  24692. + VCHIQ_STATS_INC(state, slot_stalls);
  24693. +
  24694. + /* But first, flush through the last slot. */
  24695. + state->local_tx_pos = tx_pos;
  24696. + local->tx_pos = tx_pos;
  24697. + remote_event_signal(&state->remote->trigger);
  24698. +
  24699. + if (!is_blocking ||
  24700. + (down_interruptible(
  24701. + &state->slot_available_event) != 0))
  24702. + return NULL; /* No space available */
  24703. + }
  24704. +
  24705. + BUG_ON(tx_pos ==
  24706. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  24707. +
  24708. + slot_index = local->slot_queue[
  24709. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  24710. + VCHIQ_SLOT_QUEUE_MASK];
  24711. + state->tx_data =
  24712. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24713. + }
  24714. +
  24715. + state->local_tx_pos = tx_pos + space;
  24716. +
  24717. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24718. +}
  24719. +
  24720. +/* Called by the recycle thread. */
  24721. +static void
  24722. +process_free_queue(VCHIQ_STATE_T *state)
  24723. +{
  24724. + VCHIQ_SHARED_STATE_T *local = state->local;
  24725. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  24726. + int slot_queue_available;
  24727. +
  24728. + /* Use a read memory barrier to ensure that any state that may have
  24729. + ** been modified by another thread is not masked by stale prefetched
  24730. + ** values. */
  24731. + rmb();
  24732. +
  24733. + /* Find slots which have been freed by the other side, and return them
  24734. + ** to the available queue. */
  24735. + slot_queue_available = state->slot_queue_available;
  24736. +
  24737. + while (slot_queue_available != local->slot_queue_recycle) {
  24738. + unsigned int pos;
  24739. + int slot_index = local->slot_queue[slot_queue_available++ &
  24740. + VCHIQ_SLOT_QUEUE_MASK];
  24741. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24742. + int data_found = 0;
  24743. +
  24744. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  24745. + state->id, slot_index, (unsigned int)data,
  24746. + local->slot_queue_recycle, slot_queue_available);
  24747. +
  24748. + /* Initialise the bitmask for services which have used this
  24749. + ** slot */
  24750. + BITSET_ZERO(service_found);
  24751. +
  24752. + pos = 0;
  24753. +
  24754. + while (pos < VCHIQ_SLOT_SIZE) {
  24755. + VCHIQ_HEADER_T *header =
  24756. + (VCHIQ_HEADER_T *)(data + pos);
  24757. + int msgid = header->msgid;
  24758. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  24759. + int port = VCHIQ_MSG_SRCPORT(msgid);
  24760. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  24761. + &state->service_quotas[port];
  24762. + int count;
  24763. + spin_lock(&quota_spinlock);
  24764. + count = service_quota->message_use_count;
  24765. + if (count > 0)
  24766. + service_quota->message_use_count =
  24767. + count - 1;
  24768. + spin_unlock(&quota_spinlock);
  24769. +
  24770. + if (count == service_quota->message_quota)
  24771. + /* Signal the service that it
  24772. + ** has dropped below its quota
  24773. + */
  24774. + up(&service_quota->quota_event);
  24775. + else if (count == 0) {
  24776. + vchiq_log_error(vchiq_core_log_level,
  24777. + "service %d "
  24778. + "message_use_count=%d "
  24779. + "(header %x, msgid %x, "
  24780. + "header->msgid %x, "
  24781. + "header->size %x)",
  24782. + port,
  24783. + service_quota->
  24784. + message_use_count,
  24785. + (unsigned int)header, msgid,
  24786. + header->msgid,
  24787. + header->size);
  24788. + WARN(1, "invalid message use count\n");
  24789. + }
  24790. + if (!BITSET_IS_SET(service_found, port)) {
  24791. + /* Set the found bit for this service */
  24792. + BITSET_SET(service_found, port);
  24793. +
  24794. + spin_lock(&quota_spinlock);
  24795. + count = service_quota->slot_use_count;
  24796. + if (count > 0)
  24797. + service_quota->slot_use_count =
  24798. + count - 1;
  24799. + spin_unlock(&quota_spinlock);
  24800. +
  24801. + if (count > 0) {
  24802. + /* Signal the service in case
  24803. + ** it has dropped below its
  24804. + ** quota */
  24805. + up(&service_quota->quota_event);
  24806. + vchiq_log_trace(
  24807. + vchiq_core_log_level,
  24808. + "%d: pfq:%d %x@%x - "
  24809. + "slot_use->%d",
  24810. + state->id, port,
  24811. + header->size,
  24812. + (unsigned int)header,
  24813. + count - 1);
  24814. + } else {
  24815. + vchiq_log_error(
  24816. + vchiq_core_log_level,
  24817. + "service %d "
  24818. + "slot_use_count"
  24819. + "=%d (header %x"
  24820. + ", msgid %x, "
  24821. + "header->msgid"
  24822. + " %x, header->"
  24823. + "size %x)",
  24824. + port, count,
  24825. + (unsigned int)header,
  24826. + msgid,
  24827. + header->msgid,
  24828. + header->size);
  24829. + WARN(1, "bad slot use count\n");
  24830. + }
  24831. + }
  24832. +
  24833. + data_found = 1;
  24834. + }
  24835. +
  24836. + pos += calc_stride(header->size);
  24837. + if (pos > VCHIQ_SLOT_SIZE) {
  24838. + vchiq_log_error(vchiq_core_log_level,
  24839. + "pfq - pos %x: header %x, msgid %x, "
  24840. + "header->msgid %x, header->size %x",
  24841. + pos, (unsigned int)header, msgid,
  24842. + header->msgid, header->size);
  24843. + WARN(1, "invalid slot position\n");
  24844. + }
  24845. + }
  24846. +
  24847. + if (data_found) {
  24848. + int count;
  24849. + spin_lock(&quota_spinlock);
  24850. + count = state->data_use_count;
  24851. + if (count > 0)
  24852. + state->data_use_count =
  24853. + count - 1;
  24854. + spin_unlock(&quota_spinlock);
  24855. + if (count == state->data_quota)
  24856. + up(&state->data_quota_event);
  24857. + }
  24858. +
  24859. + state->slot_queue_available = slot_queue_available;
  24860. + up(&state->slot_available_event);
  24861. + }
  24862. +}
  24863. +
  24864. +/* Called by the slot handler and application threads */
  24865. +static VCHIQ_STATUS_T
  24866. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24867. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24868. + int count, int size, int is_blocking)
  24869. +{
  24870. + VCHIQ_SHARED_STATE_T *local;
  24871. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  24872. + VCHIQ_HEADER_T *header;
  24873. + int type = VCHIQ_MSG_TYPE(msgid);
  24874. +
  24875. + unsigned int stride;
  24876. +
  24877. + local = state->local;
  24878. +
  24879. + stride = calc_stride(size);
  24880. +
  24881. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  24882. +
  24883. + if ((type != VCHIQ_MSG_RESUME) &&
  24884. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  24885. + return VCHIQ_RETRY;
  24886. +
  24887. + if (type == VCHIQ_MSG_DATA) {
  24888. + int tx_end_index;
  24889. +
  24890. + BUG_ON(!service);
  24891. +
  24892. + if (service->closing) {
  24893. + /* The service has been closed */
  24894. + mutex_unlock(&state->slot_mutex);
  24895. + return VCHIQ_ERROR;
  24896. + }
  24897. +
  24898. + service_quota = &state->service_quotas[service->localport];
  24899. +
  24900. + spin_lock(&quota_spinlock);
  24901. +
  24902. + /* Ensure this service doesn't use more than its quota of
  24903. + ** messages or slots */
  24904. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24905. + state->local_tx_pos + stride - 1);
  24906. +
  24907. + /* Ensure data messages don't use more than their quota of
  24908. + ** slots */
  24909. + while ((tx_end_index != state->previous_data_index) &&
  24910. + (state->data_use_count == state->data_quota)) {
  24911. + VCHIQ_STATS_INC(state, data_stalls);
  24912. + spin_unlock(&quota_spinlock);
  24913. + mutex_unlock(&state->slot_mutex);
  24914. +
  24915. + if (down_interruptible(&state->data_quota_event)
  24916. + != 0)
  24917. + return VCHIQ_RETRY;
  24918. +
  24919. + mutex_lock(&state->slot_mutex);
  24920. + spin_lock(&quota_spinlock);
  24921. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24922. + state->local_tx_pos + stride - 1);
  24923. + if ((tx_end_index == state->previous_data_index) ||
  24924. + (state->data_use_count < state->data_quota)) {
  24925. + /* Pass the signal on to other waiters */
  24926. + up(&state->data_quota_event);
  24927. + break;
  24928. + }
  24929. + }
  24930. +
  24931. + while ((service_quota->message_use_count ==
  24932. + service_quota->message_quota) ||
  24933. + ((tx_end_index != service_quota->previous_tx_index) &&
  24934. + (service_quota->slot_use_count ==
  24935. + service_quota->slot_quota))) {
  24936. + spin_unlock(&quota_spinlock);
  24937. + vchiq_log_trace(vchiq_core_log_level,
  24938. + "%d: qm:%d %s,%x - quota stall "
  24939. + "(msg %d, slot %d)",
  24940. + state->id, service->localport,
  24941. + msg_type_str(type), size,
  24942. + service_quota->message_use_count,
  24943. + service_quota->slot_use_count);
  24944. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  24945. + mutex_unlock(&state->slot_mutex);
  24946. + if (down_interruptible(&service_quota->quota_event)
  24947. + != 0)
  24948. + return VCHIQ_RETRY;
  24949. + if (service->closing)
  24950. + return VCHIQ_ERROR;
  24951. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  24952. + return VCHIQ_RETRY;
  24953. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  24954. + /* The service has been closed */
  24955. + mutex_unlock(&state->slot_mutex);
  24956. + return VCHIQ_ERROR;
  24957. + }
  24958. + spin_lock(&quota_spinlock);
  24959. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24960. + state->local_tx_pos + stride - 1);
  24961. + }
  24962. +
  24963. + spin_unlock(&quota_spinlock);
  24964. + }
  24965. +
  24966. + header = reserve_space(state, stride, is_blocking);
  24967. +
  24968. + if (!header) {
  24969. + if (service)
  24970. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  24971. + mutex_unlock(&state->slot_mutex);
  24972. + return VCHIQ_RETRY;
  24973. + }
  24974. +
  24975. + if (type == VCHIQ_MSG_DATA) {
  24976. + int i, pos;
  24977. + int tx_end_index;
  24978. + int slot_use_count;
  24979. +
  24980. + vchiq_log_info(vchiq_core_log_level,
  24981. + "%d: qm %s@%x,%x (%d->%d)",
  24982. + state->id,
  24983. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24984. + (unsigned int)header, size,
  24985. + VCHIQ_MSG_SRCPORT(msgid),
  24986. + VCHIQ_MSG_DSTPORT(msgid));
  24987. +
  24988. + BUG_ON(!service);
  24989. +
  24990. + for (i = 0, pos = 0; i < (unsigned int)count;
  24991. + pos += elements[i++].size)
  24992. + if (elements[i].size) {
  24993. + if (vchiq_copy_from_user
  24994. + (header->data + pos, elements[i].data,
  24995. + (size_t) elements[i].size) !=
  24996. + VCHIQ_SUCCESS) {
  24997. + mutex_unlock(&state->slot_mutex);
  24998. + VCHIQ_SERVICE_STATS_INC(service,
  24999. + error_count);
  25000. + return VCHIQ_ERROR;
  25001. + }
  25002. + if (i == 0) {
  25003. + if (vchiq_core_msg_log_level >=
  25004. + VCHIQ_LOG_INFO)
  25005. + vchiq_log_dump_mem("Sent", 0,
  25006. + header->data + pos,
  25007. + min(64u,
  25008. + elements[0].size));
  25009. + }
  25010. + }
  25011. +
  25012. + spin_lock(&quota_spinlock);
  25013. + service_quota->message_use_count++;
  25014. +
  25015. + tx_end_index =
  25016. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  25017. +
  25018. + /* If this transmission can't fit in the last slot used by any
  25019. + ** service, the data_use_count must be increased. */
  25020. + if (tx_end_index != state->previous_data_index) {
  25021. + state->previous_data_index = tx_end_index;
  25022. + state->data_use_count++;
  25023. + }
  25024. +
  25025. + /* If this isn't the same slot last used by this service,
  25026. + ** the service's slot_use_count must be increased. */
  25027. + if (tx_end_index != service_quota->previous_tx_index) {
  25028. + service_quota->previous_tx_index = tx_end_index;
  25029. + slot_use_count = ++service_quota->slot_use_count;
  25030. + } else {
  25031. + slot_use_count = 0;
  25032. + }
  25033. +
  25034. + spin_unlock(&quota_spinlock);
  25035. +
  25036. + if (slot_use_count)
  25037. + vchiq_log_trace(vchiq_core_log_level,
  25038. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  25039. + state->id, service->localport,
  25040. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  25041. + slot_use_count, header);
  25042. +
  25043. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  25044. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  25045. + } else {
  25046. + vchiq_log_info(vchiq_core_log_level,
  25047. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  25048. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25049. + (unsigned int)header, size,
  25050. + VCHIQ_MSG_SRCPORT(msgid),
  25051. + VCHIQ_MSG_DSTPORT(msgid));
  25052. + if (size != 0) {
  25053. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  25054. + memcpy(header->data, elements[0].data,
  25055. + elements[0].size);
  25056. + }
  25057. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  25058. + }
  25059. +
  25060. + header->msgid = msgid;
  25061. + header->size = size;
  25062. +
  25063. + {
  25064. + int svc_fourcc;
  25065. +
  25066. + svc_fourcc = service
  25067. + ? service->base.fourcc
  25068. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25069. +
  25070. + vchiq_log_info(vchiq_core_msg_log_level,
  25071. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  25072. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25073. + VCHIQ_MSG_TYPE(msgid),
  25074. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25075. + VCHIQ_MSG_SRCPORT(msgid),
  25076. + VCHIQ_MSG_DSTPORT(msgid),
  25077. + size);
  25078. + }
  25079. +
  25080. + /* Make sure the new header is visible to the peer. */
  25081. + wmb();
  25082. +
  25083. + /* Make the new tx_pos visible to the peer. */
  25084. + local->tx_pos = state->local_tx_pos;
  25085. + wmb();
  25086. +
  25087. + if (service && (type == VCHIQ_MSG_CLOSE))
  25088. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  25089. +
  25090. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  25091. + mutex_unlock(&state->slot_mutex);
  25092. +
  25093. + remote_event_signal(&state->remote->trigger);
  25094. +
  25095. + return VCHIQ_SUCCESS;
  25096. +}
  25097. +
  25098. +/* Called by the slot handler and application threads */
  25099. +static VCHIQ_STATUS_T
  25100. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  25101. + int msgid, const VCHIQ_ELEMENT_T *elements,
  25102. + int count, int size, int is_blocking)
  25103. +{
  25104. + VCHIQ_SHARED_STATE_T *local;
  25105. + VCHIQ_HEADER_T *header;
  25106. +
  25107. + local = state->local;
  25108. +
  25109. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  25110. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  25111. + return VCHIQ_RETRY;
  25112. +
  25113. + remote_event_wait(&local->sync_release);
  25114. +
  25115. + rmb();
  25116. +
  25117. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  25118. + local->slot_sync);
  25119. +
  25120. + {
  25121. + int oldmsgid = header->msgid;
  25122. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  25123. + vchiq_log_error(vchiq_core_log_level,
  25124. + "%d: qms - msgid %x, not PADDING",
  25125. + state->id, oldmsgid);
  25126. + }
  25127. +
  25128. + if (service) {
  25129. + int i, pos;
  25130. +
  25131. + vchiq_log_info(vchiq_sync_log_level,
  25132. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  25133. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25134. + (unsigned int)header, size,
  25135. + VCHIQ_MSG_SRCPORT(msgid),
  25136. + VCHIQ_MSG_DSTPORT(msgid));
  25137. +
  25138. + for (i = 0, pos = 0; i < (unsigned int)count;
  25139. + pos += elements[i++].size)
  25140. + if (elements[i].size) {
  25141. + if (vchiq_copy_from_user
  25142. + (header->data + pos, elements[i].data,
  25143. + (size_t) elements[i].size) !=
  25144. + VCHIQ_SUCCESS) {
  25145. + mutex_unlock(&state->sync_mutex);
  25146. + VCHIQ_SERVICE_STATS_INC(service,
  25147. + error_count);
  25148. + return VCHIQ_ERROR;
  25149. + }
  25150. + if (i == 0) {
  25151. + if (vchiq_sync_log_level >=
  25152. + VCHIQ_LOG_TRACE)
  25153. + vchiq_log_dump_mem("Sent Sync",
  25154. + 0, header->data + pos,
  25155. + min(64u,
  25156. + elements[0].size));
  25157. + }
  25158. + }
  25159. +
  25160. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  25161. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  25162. + } else {
  25163. + vchiq_log_info(vchiq_sync_log_level,
  25164. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  25165. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25166. + (unsigned int)header, size,
  25167. + VCHIQ_MSG_SRCPORT(msgid),
  25168. + VCHIQ_MSG_DSTPORT(msgid));
  25169. + if (size != 0) {
  25170. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  25171. + memcpy(header->data, elements[0].data,
  25172. + elements[0].size);
  25173. + }
  25174. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  25175. + }
  25176. +
  25177. + header->size = size;
  25178. + header->msgid = msgid;
  25179. +
  25180. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25181. + int svc_fourcc;
  25182. +
  25183. + svc_fourcc = service
  25184. + ? service->base.fourcc
  25185. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25186. +
  25187. + vchiq_log_trace(vchiq_sync_log_level,
  25188. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  25189. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25190. + VCHIQ_MSG_TYPE(msgid),
  25191. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25192. + VCHIQ_MSG_SRCPORT(msgid),
  25193. + VCHIQ_MSG_DSTPORT(msgid),
  25194. + size);
  25195. + }
  25196. +
  25197. + /* Make sure the new header is visible to the peer. */
  25198. + wmb();
  25199. +
  25200. + remote_event_signal(&state->remote->sync_trigger);
  25201. +
  25202. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  25203. + mutex_unlock(&state->sync_mutex);
  25204. +
  25205. + return VCHIQ_SUCCESS;
  25206. +}
  25207. +
  25208. +static inline void
  25209. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  25210. +{
  25211. + slot->use_count++;
  25212. +}
  25213. +
  25214. +static void
  25215. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  25216. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  25217. +{
  25218. + int release_count;
  25219. +
  25220. + mutex_lock(&state->recycle_mutex);
  25221. +
  25222. + if (header) {
  25223. + int msgid = header->msgid;
  25224. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  25225. + (service && service->closing)) {
  25226. + mutex_unlock(&state->recycle_mutex);
  25227. + return;
  25228. + }
  25229. +
  25230. + /* Rewrite the message header to prevent a double
  25231. + ** release */
  25232. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  25233. + }
  25234. +
  25235. + release_count = slot_info->release_count;
  25236. + slot_info->release_count = ++release_count;
  25237. +
  25238. + if (release_count == slot_info->use_count) {
  25239. + int slot_queue_recycle;
  25240. + /* Add to the freed queue */
  25241. +
  25242. + /* A read barrier is necessary here to prevent speculative
  25243. + ** fetches of remote->slot_queue_recycle from overtaking the
  25244. + ** mutex. */
  25245. + rmb();
  25246. +
  25247. + slot_queue_recycle = state->remote->slot_queue_recycle;
  25248. + state->remote->slot_queue[slot_queue_recycle &
  25249. + VCHIQ_SLOT_QUEUE_MASK] =
  25250. + SLOT_INDEX_FROM_INFO(state, slot_info);
  25251. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  25252. + vchiq_log_info(vchiq_core_log_level,
  25253. + "%d: release_slot %d - recycle->%x",
  25254. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  25255. + state->remote->slot_queue_recycle);
  25256. +
  25257. + /* A write barrier is necessary, but remote_event_signal
  25258. + ** contains one. */
  25259. + remote_event_signal(&state->remote->recycle);
  25260. + }
  25261. +
  25262. + mutex_unlock(&state->recycle_mutex);
  25263. +}
  25264. +
  25265. +/* Called by the slot handler - don't hold the bulk mutex */
  25266. +static VCHIQ_STATUS_T
  25267. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  25268. + int retry_poll)
  25269. +{
  25270. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25271. +
  25272. + vchiq_log_trace(vchiq_core_log_level,
  25273. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  25274. + service->state->id, service->localport,
  25275. + (queue == &service->bulk_tx) ? 't' : 'r',
  25276. + queue->process, queue->remote_notify, queue->remove);
  25277. +
  25278. + if (service->state->is_master) {
  25279. + while (queue->remote_notify != queue->process) {
  25280. + VCHIQ_BULK_T *bulk =
  25281. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  25282. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  25283. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  25284. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  25285. + service->remoteport);
  25286. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  25287. + /* Only reply to non-dummy bulk requests */
  25288. + if (bulk->remote_data) {
  25289. + status = queue_message(service->state, NULL,
  25290. + msgid, &element, 1, 4, 0);
  25291. + if (status != VCHIQ_SUCCESS)
  25292. + break;
  25293. + }
  25294. + queue->remote_notify++;
  25295. + }
  25296. + } else {
  25297. + queue->remote_notify = queue->process;
  25298. + }
  25299. +
  25300. + if (status == VCHIQ_SUCCESS) {
  25301. + while (queue->remove != queue->remote_notify) {
  25302. + VCHIQ_BULK_T *bulk =
  25303. + &queue->bulks[BULK_INDEX(queue->remove)];
  25304. +
  25305. + /* Only generate callbacks for non-dummy bulk
  25306. + ** requests, and non-terminated services */
  25307. + if (bulk->data && service->instance) {
  25308. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  25309. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  25310. + VCHIQ_SERVICE_STATS_INC(service,
  25311. + bulk_tx_count);
  25312. + VCHIQ_SERVICE_STATS_ADD(service,
  25313. + bulk_tx_bytes,
  25314. + bulk->actual);
  25315. + } else {
  25316. + VCHIQ_SERVICE_STATS_INC(service,
  25317. + bulk_rx_count);
  25318. + VCHIQ_SERVICE_STATS_ADD(service,
  25319. + bulk_rx_bytes,
  25320. + bulk->actual);
  25321. + }
  25322. + } else {
  25323. + VCHIQ_SERVICE_STATS_INC(service,
  25324. + bulk_aborted_count);
  25325. + }
  25326. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  25327. + struct bulk_waiter *waiter;
  25328. + spin_lock(&bulk_waiter_spinlock);
  25329. + waiter = bulk->userdata;
  25330. + if (waiter) {
  25331. + waiter->actual = bulk->actual;
  25332. + up(&waiter->event);
  25333. + }
  25334. + spin_unlock(&bulk_waiter_spinlock);
  25335. + } else if (bulk->mode ==
  25336. + VCHIQ_BULK_MODE_CALLBACK) {
  25337. + VCHIQ_REASON_T reason = (bulk->dir ==
  25338. + VCHIQ_BULK_TRANSMIT) ?
  25339. + ((bulk->actual ==
  25340. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  25341. + VCHIQ_BULK_TRANSMIT_ABORTED :
  25342. + VCHIQ_BULK_TRANSMIT_DONE) :
  25343. + ((bulk->actual ==
  25344. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  25345. + VCHIQ_BULK_RECEIVE_ABORTED :
  25346. + VCHIQ_BULK_RECEIVE_DONE);
  25347. + status = make_service_callback(service,
  25348. + reason, NULL, bulk->userdata);
  25349. + if (status == VCHIQ_RETRY)
  25350. + break;
  25351. + }
  25352. + }
  25353. +
  25354. + queue->remove++;
  25355. + up(&service->bulk_remove_event);
  25356. + }
  25357. + if (!retry_poll)
  25358. + status = VCHIQ_SUCCESS;
  25359. + }
  25360. +
  25361. + if (status == VCHIQ_RETRY)
  25362. + request_poll(service->state, service,
  25363. + (queue == &service->bulk_tx) ?
  25364. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  25365. +
  25366. + return status;
  25367. +}
  25368. +
  25369. +/* Called by the slot handler thread */
  25370. +static void
  25371. +poll_services(VCHIQ_STATE_T *state)
  25372. +{
  25373. + int group, i;
  25374. +
  25375. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  25376. + uint32_t flags;
  25377. + flags = atomic_xchg(&state->poll_services[group], 0);
  25378. + for (i = 0; flags; i++) {
  25379. + if (flags & (1 << i)) {
  25380. + VCHIQ_SERVICE_T *service =
  25381. + find_service_by_port(state,
  25382. + (group<<5) + i);
  25383. + uint32_t service_flags;
  25384. + flags &= ~(1 << i);
  25385. + if (!service)
  25386. + continue;
  25387. + service_flags =
  25388. + atomic_xchg(&service->poll_flags, 0);
  25389. + if (service_flags &
  25390. + (1 << VCHIQ_POLL_REMOVE)) {
  25391. + vchiq_log_info(vchiq_core_log_level,
  25392. + "%d: ps - remove %d<->%d",
  25393. + state->id, service->localport,
  25394. + service->remoteport);
  25395. +
  25396. + /* Make it look like a client, because
  25397. + it must be removed and not left in
  25398. + the LISTENING state. */
  25399. + service->public_fourcc =
  25400. + VCHIQ_FOURCC_INVALID;
  25401. +
  25402. + if (vchiq_close_service_internal(
  25403. + service, 0/*!close_recvd*/) !=
  25404. + VCHIQ_SUCCESS)
  25405. + request_poll(state, service,
  25406. + VCHIQ_POLL_REMOVE);
  25407. + } else if (service_flags &
  25408. + (1 << VCHIQ_POLL_TERMINATE)) {
  25409. + vchiq_log_info(vchiq_core_log_level,
  25410. + "%d: ps - terminate %d<->%d",
  25411. + state->id, service->localport,
  25412. + service->remoteport);
  25413. + if (vchiq_close_service_internal(
  25414. + service, 0/*!close_recvd*/) !=
  25415. + VCHIQ_SUCCESS)
  25416. + request_poll(state, service,
  25417. + VCHIQ_POLL_TERMINATE);
  25418. + }
  25419. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  25420. + notify_bulks(service,
  25421. + &service->bulk_tx,
  25422. + 1/*retry_poll*/);
  25423. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  25424. + notify_bulks(service,
  25425. + &service->bulk_rx,
  25426. + 1/*retry_poll*/);
  25427. + unlock_service(service);
  25428. + }
  25429. + }
  25430. + }
  25431. +}
  25432. +
  25433. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  25434. +static int
  25435. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  25436. +{
  25437. + VCHIQ_STATE_T *state = service->state;
  25438. + int resolved = 0;
  25439. + int rc;
  25440. +
  25441. + while ((queue->process != queue->local_insert) &&
  25442. + (queue->process != queue->remote_insert)) {
  25443. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  25444. +
  25445. + vchiq_log_trace(vchiq_core_log_level,
  25446. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  25447. + state->id, service->localport,
  25448. + (queue == &service->bulk_tx) ? 't' : 'r',
  25449. + queue->local_insert, queue->remote_insert,
  25450. + queue->process);
  25451. +
  25452. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  25453. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  25454. +
  25455. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  25456. + if (rc != 0)
  25457. + break;
  25458. +
  25459. + vchiq_transfer_bulk(bulk);
  25460. + mutex_unlock(&state->bulk_transfer_mutex);
  25461. +
  25462. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  25463. + const char *header = (queue == &service->bulk_tx) ?
  25464. + "Send Bulk to" : "Recv Bulk from";
  25465. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  25466. + vchiq_log_info(vchiq_core_msg_log_level,
  25467. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  25468. + header,
  25469. + VCHIQ_FOURCC_AS_4CHARS(
  25470. + service->base.fourcc),
  25471. + service->remoteport,
  25472. + bulk->size,
  25473. + (unsigned int)bulk->data,
  25474. + (unsigned int)bulk->remote_data);
  25475. + else
  25476. + vchiq_log_info(vchiq_core_msg_log_level,
  25477. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  25478. + " rx len:%d %x<->%x",
  25479. + header,
  25480. + VCHIQ_FOURCC_AS_4CHARS(
  25481. + service->base.fourcc),
  25482. + service->remoteport,
  25483. + bulk->size,
  25484. + bulk->remote_size,
  25485. + (unsigned int)bulk->data,
  25486. + (unsigned int)bulk->remote_data);
  25487. + }
  25488. +
  25489. + vchiq_complete_bulk(bulk);
  25490. + queue->process++;
  25491. + resolved++;
  25492. + }
  25493. + return resolved;
  25494. +}
  25495. +
  25496. +/* Called with the bulk_mutex held */
  25497. +static void
  25498. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  25499. +{
  25500. + int is_tx = (queue == &service->bulk_tx);
  25501. + vchiq_log_trace(vchiq_core_log_level,
  25502. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  25503. + service->state->id, service->localport, is_tx ? 't' : 'r',
  25504. + queue->local_insert, queue->remote_insert, queue->process);
  25505. +
  25506. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  25507. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  25508. +
  25509. + while ((queue->process != queue->local_insert) ||
  25510. + (queue->process != queue->remote_insert)) {
  25511. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  25512. +
  25513. + if (queue->process == queue->remote_insert) {
  25514. + /* fabricate a matching dummy bulk */
  25515. + bulk->remote_data = NULL;
  25516. + bulk->remote_size = 0;
  25517. + queue->remote_insert++;
  25518. + }
  25519. +
  25520. + if (queue->process != queue->local_insert) {
  25521. + vchiq_complete_bulk(bulk);
  25522. +
  25523. + vchiq_log_info(vchiq_core_msg_log_level,
  25524. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  25525. + "rx len:%d",
  25526. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  25527. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  25528. + service->remoteport,
  25529. + bulk->size,
  25530. + bulk->remote_size);
  25531. + } else {
  25532. + /* fabricate a matching dummy bulk */
  25533. + bulk->data = NULL;
  25534. + bulk->size = 0;
  25535. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  25536. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  25537. + VCHIQ_BULK_RECEIVE;
  25538. + queue->local_insert++;
  25539. + }
  25540. +
  25541. + queue->process++;
  25542. + }
  25543. +}
  25544. +
  25545. +/* Called from the slot handler thread */
  25546. +static void
  25547. +pause_bulks(VCHIQ_STATE_T *state)
  25548. +{
  25549. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  25550. + WARN_ON_ONCE(1);
  25551. + atomic_set(&pause_bulks_count, 1);
  25552. + return;
  25553. + }
  25554. +
  25555. + /* Block bulk transfers from all services */
  25556. + mutex_lock(&state->bulk_transfer_mutex);
  25557. +}
  25558. +
  25559. +/* Called from the slot handler thread */
  25560. +static void
  25561. +resume_bulks(VCHIQ_STATE_T *state)
  25562. +{
  25563. + int i;
  25564. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  25565. + WARN_ON_ONCE(1);
  25566. + atomic_set(&pause_bulks_count, 0);
  25567. + return;
  25568. + }
  25569. +
  25570. + /* Allow bulk transfers from all services */
  25571. + mutex_unlock(&state->bulk_transfer_mutex);
  25572. +
  25573. + if (state->deferred_bulks == 0)
  25574. + return;
  25575. +
  25576. + /* Deal with any bulks which had to be deferred due to being in
  25577. + * paused state. Don't try to match up to number of deferred bulks
  25578. + * in case we've had something come and close the service in the
  25579. + * interim - just process all bulk queues for all services */
  25580. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  25581. + __func__, state->deferred_bulks);
  25582. +
  25583. + for (i = 0; i < state->unused_service; i++) {
  25584. + VCHIQ_SERVICE_T *service = state->services[i];
  25585. + int resolved_rx = 0;
  25586. + int resolved_tx = 0;
  25587. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  25588. + continue;
  25589. +
  25590. + mutex_lock(&service->bulk_mutex);
  25591. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  25592. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  25593. + mutex_unlock(&service->bulk_mutex);
  25594. + if (resolved_rx)
  25595. + notify_bulks(service, &service->bulk_rx, 1);
  25596. + if (resolved_tx)
  25597. + notify_bulks(service, &service->bulk_tx, 1);
  25598. + }
  25599. + state->deferred_bulks = 0;
  25600. +}
  25601. +
  25602. +static int
  25603. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  25604. +{
  25605. + VCHIQ_SERVICE_T *service = NULL;
  25606. + int msgid, size;
  25607. + int type;
  25608. + unsigned int localport, remoteport;
  25609. +
  25610. + msgid = header->msgid;
  25611. + size = header->size;
  25612. + type = VCHIQ_MSG_TYPE(msgid);
  25613. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25614. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25615. + if (size >= sizeof(struct vchiq_open_payload)) {
  25616. + const struct vchiq_open_payload *payload =
  25617. + (struct vchiq_open_payload *)header->data;
  25618. + unsigned int fourcc;
  25619. +
  25620. + fourcc = payload->fourcc;
  25621. + vchiq_log_info(vchiq_core_log_level,
  25622. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  25623. + state->id, (unsigned int)header,
  25624. + localport,
  25625. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  25626. +
  25627. + service = get_listening_service(state, fourcc);
  25628. +
  25629. + if (service) {
  25630. + /* A matching service exists */
  25631. + short version = payload->version;
  25632. + short version_min = payload->version_min;
  25633. + if ((service->version < version_min) ||
  25634. + (version < service->version_min)) {
  25635. + /* Version mismatch */
  25636. + vchiq_loud_error_header();
  25637. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  25638. + "version mismatch - local (%d, min %d)"
  25639. + " vs. remote (%d, min %d)",
  25640. + state->id, service->localport,
  25641. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  25642. + service->version, service->version_min,
  25643. + version, version_min);
  25644. + vchiq_loud_error_footer();
  25645. + unlock_service(service);
  25646. + service = NULL;
  25647. + goto fail_open;
  25648. + }
  25649. + service->peer_version = version;
  25650. +
  25651. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  25652. + struct vchiq_openack_payload ack_payload = {
  25653. + service->version
  25654. + };
  25655. + VCHIQ_ELEMENT_T body = {
  25656. + &ack_payload,
  25657. + sizeof(ack_payload)
  25658. + };
  25659. +
  25660. + /* Acknowledge the OPEN */
  25661. + if (service->sync) {
  25662. + if (queue_message_sync(state, NULL,
  25663. + VCHIQ_MAKE_MSG(
  25664. + VCHIQ_MSG_OPENACK,
  25665. + service->localport,
  25666. + remoteport),
  25667. + &body, 1, sizeof(ack_payload),
  25668. + 0) == VCHIQ_RETRY)
  25669. + goto bail_not_ready;
  25670. + } else {
  25671. + if (queue_message(state, NULL,
  25672. + VCHIQ_MAKE_MSG(
  25673. + VCHIQ_MSG_OPENACK,
  25674. + service->localport,
  25675. + remoteport),
  25676. + &body, 1, sizeof(ack_payload),
  25677. + 0) == VCHIQ_RETRY)
  25678. + goto bail_not_ready;
  25679. + }
  25680. +
  25681. + /* The service is now open */
  25682. + vchiq_set_service_state(service,
  25683. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  25684. + : VCHIQ_SRVSTATE_OPEN);
  25685. + }
  25686. +
  25687. + service->remoteport = remoteport;
  25688. + service->client_id = ((int *)header->data)[1];
  25689. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  25690. + NULL, NULL) == VCHIQ_RETRY) {
  25691. + /* Bail out if not ready */
  25692. + service->remoteport = VCHIQ_PORT_FREE;
  25693. + goto bail_not_ready;
  25694. + }
  25695. +
  25696. + /* Success - the message has been dealt with */
  25697. + unlock_service(service);
  25698. + return 1;
  25699. + }
  25700. + }
  25701. +
  25702. +fail_open:
  25703. + /* No available service, or an invalid request - send a CLOSE */
  25704. + if (queue_message(state, NULL,
  25705. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  25706. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25707. + goto bail_not_ready;
  25708. +
  25709. + return 1;
  25710. +
  25711. +bail_not_ready:
  25712. + if (service)
  25713. + unlock_service(service);
  25714. +
  25715. + return 0;
  25716. +}
  25717. +
  25718. +/* Called by the slot handler thread */
  25719. +static void
  25720. +parse_rx_slots(VCHIQ_STATE_T *state)
  25721. +{
  25722. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  25723. + VCHIQ_SERVICE_T *service = NULL;
  25724. + int tx_pos;
  25725. + DEBUG_INITIALISE(state->local)
  25726. +
  25727. + tx_pos = remote->tx_pos;
  25728. +
  25729. + while (state->rx_pos != tx_pos) {
  25730. + VCHIQ_HEADER_T *header;
  25731. + int msgid, size;
  25732. + int type;
  25733. + unsigned int localport, remoteport;
  25734. +
  25735. + DEBUG_TRACE(PARSE_LINE);
  25736. + if (!state->rx_data) {
  25737. + int rx_index;
  25738. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  25739. + rx_index = remote->slot_queue[
  25740. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  25741. + VCHIQ_SLOT_QUEUE_MASK];
  25742. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  25743. + rx_index);
  25744. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  25745. +
  25746. + /* Initialise use_count to one, and increment
  25747. + ** release_count at the end of the slot to avoid
  25748. + ** releasing the slot prematurely. */
  25749. + state->rx_info->use_count = 1;
  25750. + state->rx_info->release_count = 0;
  25751. + }
  25752. +
  25753. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  25754. + (state->rx_pos & VCHIQ_SLOT_MASK));
  25755. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  25756. + msgid = header->msgid;
  25757. + DEBUG_VALUE(PARSE_MSGID, msgid);
  25758. + size = header->size;
  25759. + type = VCHIQ_MSG_TYPE(msgid);
  25760. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25761. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25762. +
  25763. + if (type != VCHIQ_MSG_DATA)
  25764. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  25765. +
  25766. + switch (type) {
  25767. + case VCHIQ_MSG_OPENACK:
  25768. + case VCHIQ_MSG_CLOSE:
  25769. + case VCHIQ_MSG_DATA:
  25770. + case VCHIQ_MSG_BULK_RX:
  25771. + case VCHIQ_MSG_BULK_TX:
  25772. + case VCHIQ_MSG_BULK_RX_DONE:
  25773. + case VCHIQ_MSG_BULK_TX_DONE:
  25774. + service = find_service_by_port(state, localport);
  25775. + if ((!service || service->remoteport != remoteport) &&
  25776. + (localport == 0) &&
  25777. + (type == VCHIQ_MSG_CLOSE)) {
  25778. + /* This could be a CLOSE from a client which
  25779. + hadn't yet received the OPENACK - look for
  25780. + the connected service */
  25781. + if (service)
  25782. + unlock_service(service);
  25783. + service = get_connected_service(state,
  25784. + remoteport);
  25785. + if (service)
  25786. + vchiq_log_warning(vchiq_core_log_level,
  25787. + "%d: prs %s@%x (%d->%d) - "
  25788. + "found connected service %d",
  25789. + state->id, msg_type_str(type),
  25790. + (unsigned int)header,
  25791. + remoteport, localport,
  25792. + service->localport);
  25793. + }
  25794. +
  25795. + if (!service) {
  25796. + vchiq_log_error(vchiq_core_log_level,
  25797. + "%d: prs %s@%x (%d->%d) - "
  25798. + "invalid/closed service %d",
  25799. + state->id, msg_type_str(type),
  25800. + (unsigned int)header,
  25801. + remoteport, localport, localport);
  25802. + goto skip_message;
  25803. + }
  25804. + break;
  25805. + default:
  25806. + break;
  25807. + }
  25808. +
  25809. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  25810. + int svc_fourcc;
  25811. +
  25812. + svc_fourcc = service
  25813. + ? service->base.fourcc
  25814. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25815. + vchiq_log_info(vchiq_core_msg_log_level,
  25816. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  25817. + "len:%d",
  25818. + msg_type_str(type), type,
  25819. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25820. + remoteport, localport, size);
  25821. + if (size > 0)
  25822. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25823. + min(64, size));
  25824. + }
  25825. +
  25826. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  25827. + > VCHIQ_SLOT_SIZE) {
  25828. + vchiq_log_error(vchiq_core_log_level,
  25829. + "header %x (msgid %x) - size %x too big for "
  25830. + "slot",
  25831. + (unsigned int)header, (unsigned int)msgid,
  25832. + (unsigned int)size);
  25833. + WARN(1, "oversized for slot\n");
  25834. + }
  25835. +
  25836. + switch (type) {
  25837. + case VCHIQ_MSG_OPEN:
  25838. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  25839. + if (!parse_open(state, header))
  25840. + goto bail_not_ready;
  25841. + break;
  25842. + case VCHIQ_MSG_OPENACK:
  25843. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25844. + const struct vchiq_openack_payload *payload =
  25845. + (struct vchiq_openack_payload *)
  25846. + header->data;
  25847. + service->peer_version = payload->version;
  25848. + }
  25849. + vchiq_log_info(vchiq_core_log_level,
  25850. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  25851. + state->id, (unsigned int)header, size,
  25852. + remoteport, localport, service->peer_version);
  25853. + if (service->srvstate ==
  25854. + VCHIQ_SRVSTATE_OPENING) {
  25855. + service->remoteport = remoteport;
  25856. + vchiq_set_service_state(service,
  25857. + VCHIQ_SRVSTATE_OPEN);
  25858. + up(&service->remove_event);
  25859. + } else
  25860. + vchiq_log_error(vchiq_core_log_level,
  25861. + "OPENACK received in state %s",
  25862. + srvstate_names[service->srvstate]);
  25863. + break;
  25864. + case VCHIQ_MSG_CLOSE:
  25865. + WARN_ON(size != 0); /* There should be no data */
  25866. +
  25867. + vchiq_log_info(vchiq_core_log_level,
  25868. + "%d: prs CLOSE@%x (%d->%d)",
  25869. + state->id, (unsigned int)header,
  25870. + remoteport, localport);
  25871. +
  25872. + mark_service_closing_internal(service, 1);
  25873. +
  25874. + if (vchiq_close_service_internal(service,
  25875. + 1/*close_recvd*/) == VCHIQ_RETRY)
  25876. + goto bail_not_ready;
  25877. +
  25878. + vchiq_log_info(vchiq_core_log_level,
  25879. + "Close Service %c%c%c%c s:%u d:%d",
  25880. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  25881. + service->localport,
  25882. + service->remoteport);
  25883. + break;
  25884. + case VCHIQ_MSG_DATA:
  25885. + vchiq_log_trace(vchiq_core_log_level,
  25886. + "%d: prs DATA@%x,%x (%d->%d)",
  25887. + state->id, (unsigned int)header, size,
  25888. + remoteport, localport);
  25889. +
  25890. + if ((service->remoteport == remoteport)
  25891. + && (service->srvstate ==
  25892. + VCHIQ_SRVSTATE_OPEN)) {
  25893. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  25894. + claim_slot(state->rx_info);
  25895. + DEBUG_TRACE(PARSE_LINE);
  25896. + if (make_service_callback(service,
  25897. + VCHIQ_MESSAGE_AVAILABLE, header,
  25898. + NULL) == VCHIQ_RETRY) {
  25899. + DEBUG_TRACE(PARSE_LINE);
  25900. + goto bail_not_ready;
  25901. + }
  25902. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  25903. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  25904. + size);
  25905. + } else {
  25906. + VCHIQ_STATS_INC(state, error_count);
  25907. + }
  25908. + break;
  25909. + case VCHIQ_MSG_CONNECT:
  25910. + vchiq_log_info(vchiq_core_log_level,
  25911. + "%d: prs CONNECT@%x",
  25912. + state->id, (unsigned int)header);
  25913. + up(&state->connect);
  25914. + break;
  25915. + case VCHIQ_MSG_BULK_RX:
  25916. + case VCHIQ_MSG_BULK_TX: {
  25917. + VCHIQ_BULK_QUEUE_T *queue;
  25918. + WARN_ON(!state->is_master);
  25919. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  25920. + &service->bulk_tx : &service->bulk_rx;
  25921. + if ((service->remoteport == remoteport)
  25922. + && (service->srvstate ==
  25923. + VCHIQ_SRVSTATE_OPEN)) {
  25924. + VCHIQ_BULK_T *bulk;
  25925. + int resolved = 0;
  25926. +
  25927. + DEBUG_TRACE(PARSE_LINE);
  25928. + if (mutex_lock_interruptible(
  25929. + &service->bulk_mutex) != 0) {
  25930. + DEBUG_TRACE(PARSE_LINE);
  25931. + goto bail_not_ready;
  25932. + }
  25933. +
  25934. + WARN_ON(!(queue->remote_insert < queue->remove +
  25935. + VCHIQ_NUM_SERVICE_BULKS));
  25936. + bulk = &queue->bulks[
  25937. + BULK_INDEX(queue->remote_insert)];
  25938. + bulk->remote_data =
  25939. + (void *)((int *)header->data)[0];
  25940. + bulk->remote_size = ((int *)header->data)[1];
  25941. + wmb();
  25942. +
  25943. + vchiq_log_info(vchiq_core_log_level,
  25944. + "%d: prs %s@%x (%d->%d) %x@%x",
  25945. + state->id, msg_type_str(type),
  25946. + (unsigned int)header,
  25947. + remoteport, localport,
  25948. + bulk->remote_size,
  25949. + (unsigned int)bulk->remote_data);
  25950. +
  25951. + queue->remote_insert++;
  25952. +
  25953. + if (atomic_read(&pause_bulks_count)) {
  25954. + state->deferred_bulks++;
  25955. + vchiq_log_info(vchiq_core_log_level,
  25956. + "%s: deferring bulk (%d)",
  25957. + __func__,
  25958. + state->deferred_bulks);
  25959. + if (state->conn_state !=
  25960. + VCHIQ_CONNSTATE_PAUSE_SENT)
  25961. + vchiq_log_error(
  25962. + vchiq_core_log_level,
  25963. + "%s: bulks paused in "
  25964. + "unexpected state %s",
  25965. + __func__,
  25966. + conn_state_names[
  25967. + state->conn_state]);
  25968. + } else if (state->conn_state ==
  25969. + VCHIQ_CONNSTATE_CONNECTED) {
  25970. + DEBUG_TRACE(PARSE_LINE);
  25971. + resolved = resolve_bulks(service,
  25972. + queue);
  25973. + }
  25974. +
  25975. + mutex_unlock(&service->bulk_mutex);
  25976. + if (resolved)
  25977. + notify_bulks(service, queue,
  25978. + 1/*retry_poll*/);
  25979. + }
  25980. + } break;
  25981. + case VCHIQ_MSG_BULK_RX_DONE:
  25982. + case VCHIQ_MSG_BULK_TX_DONE:
  25983. + WARN_ON(state->is_master);
  25984. + if ((service->remoteport == remoteport)
  25985. + && (service->srvstate !=
  25986. + VCHIQ_SRVSTATE_FREE)) {
  25987. + VCHIQ_BULK_QUEUE_T *queue;
  25988. + VCHIQ_BULK_T *bulk;
  25989. +
  25990. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25991. + &service->bulk_rx : &service->bulk_tx;
  25992. +
  25993. + DEBUG_TRACE(PARSE_LINE);
  25994. + if (mutex_lock_interruptible(
  25995. + &service->bulk_mutex) != 0) {
  25996. + DEBUG_TRACE(PARSE_LINE);
  25997. + goto bail_not_ready;
  25998. + }
  25999. + if ((int)(queue->remote_insert -
  26000. + queue->local_insert) >= 0) {
  26001. + vchiq_log_error(vchiq_core_log_level,
  26002. + "%d: prs %s@%x (%d->%d) "
  26003. + "unexpected (ri=%d,li=%d)",
  26004. + state->id, msg_type_str(type),
  26005. + (unsigned int)header,
  26006. + remoteport, localport,
  26007. + queue->remote_insert,
  26008. + queue->local_insert);
  26009. + mutex_unlock(&service->bulk_mutex);
  26010. + break;
  26011. + }
  26012. +
  26013. + BUG_ON(queue->process == queue->local_insert);
  26014. + BUG_ON(queue->process != queue->remote_insert);
  26015. +
  26016. + bulk = &queue->bulks[
  26017. + BULK_INDEX(queue->remote_insert)];
  26018. + bulk->actual = *(int *)header->data;
  26019. + queue->remote_insert++;
  26020. +
  26021. + vchiq_log_info(vchiq_core_log_level,
  26022. + "%d: prs %s@%x (%d->%d) %x@%x",
  26023. + state->id, msg_type_str(type),
  26024. + (unsigned int)header,
  26025. + remoteport, localport,
  26026. + bulk->actual, (unsigned int)bulk->data);
  26027. +
  26028. + vchiq_log_trace(vchiq_core_log_level,
  26029. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  26030. + state->id, localport,
  26031. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  26032. + 'r' : 't',
  26033. + queue->local_insert,
  26034. + queue->remote_insert, queue->process);
  26035. +
  26036. + DEBUG_TRACE(PARSE_LINE);
  26037. + WARN_ON(queue->process == queue->local_insert);
  26038. + vchiq_complete_bulk(bulk);
  26039. + queue->process++;
  26040. + mutex_unlock(&service->bulk_mutex);
  26041. + DEBUG_TRACE(PARSE_LINE);
  26042. + notify_bulks(service, queue, 1/*retry_poll*/);
  26043. + DEBUG_TRACE(PARSE_LINE);
  26044. + }
  26045. + break;
  26046. + case VCHIQ_MSG_PADDING:
  26047. + vchiq_log_trace(vchiq_core_log_level,
  26048. + "%d: prs PADDING@%x,%x",
  26049. + state->id, (unsigned int)header, size);
  26050. + break;
  26051. + case VCHIQ_MSG_PAUSE:
  26052. + /* If initiated, signal the application thread */
  26053. + vchiq_log_trace(vchiq_core_log_level,
  26054. + "%d: prs PAUSE@%x,%x",
  26055. + state->id, (unsigned int)header, size);
  26056. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  26057. + vchiq_log_error(vchiq_core_log_level,
  26058. + "%d: PAUSE received in state PAUSED",
  26059. + state->id);
  26060. + break;
  26061. + }
  26062. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  26063. + /* Send a PAUSE in response */
  26064. + if (queue_message(state, NULL,
  26065. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  26066. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  26067. + goto bail_not_ready;
  26068. + if (state->is_master)
  26069. + pause_bulks(state);
  26070. + }
  26071. + /* At this point slot_mutex is held */
  26072. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  26073. + vchiq_platform_paused(state);
  26074. + break;
  26075. + case VCHIQ_MSG_RESUME:
  26076. + vchiq_log_trace(vchiq_core_log_level,
  26077. + "%d: prs RESUME@%x,%x",
  26078. + state->id, (unsigned int)header, size);
  26079. + /* Release the slot mutex */
  26080. + mutex_unlock(&state->slot_mutex);
  26081. + if (state->is_master)
  26082. + resume_bulks(state);
  26083. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  26084. + vchiq_platform_resumed(state);
  26085. + break;
  26086. +
  26087. + case VCHIQ_MSG_REMOTE_USE:
  26088. + vchiq_on_remote_use(state);
  26089. + break;
  26090. + case VCHIQ_MSG_REMOTE_RELEASE:
  26091. + vchiq_on_remote_release(state);
  26092. + break;
  26093. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  26094. + vchiq_on_remote_use_active(state);
  26095. + break;
  26096. +
  26097. + default:
  26098. + vchiq_log_error(vchiq_core_log_level,
  26099. + "%d: prs invalid msgid %x@%x,%x",
  26100. + state->id, msgid, (unsigned int)header, size);
  26101. + WARN(1, "invalid message\n");
  26102. + break;
  26103. + }
  26104. +
  26105. +skip_message:
  26106. + if (service) {
  26107. + unlock_service(service);
  26108. + service = NULL;
  26109. + }
  26110. +
  26111. + state->rx_pos += calc_stride(size);
  26112. +
  26113. + DEBUG_TRACE(PARSE_LINE);
  26114. + /* Perform some housekeeping when the end of the slot is
  26115. + ** reached. */
  26116. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  26117. + /* Remove the extra reference count. */
  26118. + release_slot(state, state->rx_info, NULL, NULL);
  26119. + state->rx_data = NULL;
  26120. + }
  26121. + }
  26122. +
  26123. +bail_not_ready:
  26124. + if (service)
  26125. + unlock_service(service);
  26126. +}
  26127. +
  26128. +/* Called by the slot handler thread */
  26129. +static int
  26130. +slot_handler_func(void *v)
  26131. +{
  26132. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  26133. + VCHIQ_SHARED_STATE_T *local = state->local;
  26134. + DEBUG_INITIALISE(local)
  26135. +
  26136. + while (1) {
  26137. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  26138. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  26139. + remote_event_wait(&local->trigger);
  26140. +
  26141. + rmb();
  26142. +
  26143. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  26144. + if (state->poll_needed) {
  26145. + /* Check if we need to suspend - may change our
  26146. + * conn_state */
  26147. + vchiq_platform_check_suspend(state);
  26148. +
  26149. + state->poll_needed = 0;
  26150. +
  26151. + /* Handle service polling and other rare conditions here
  26152. + ** out of the mainline code */
  26153. + switch (state->conn_state) {
  26154. + case VCHIQ_CONNSTATE_CONNECTED:
  26155. + /* Poll the services as requested */
  26156. + poll_services(state);
  26157. + break;
  26158. +
  26159. + case VCHIQ_CONNSTATE_PAUSING:
  26160. + if (state->is_master)
  26161. + pause_bulks(state);
  26162. + if (queue_message(state, NULL,
  26163. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  26164. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  26165. + vchiq_set_conn_state(state,
  26166. + VCHIQ_CONNSTATE_PAUSE_SENT);
  26167. + } else {
  26168. + if (state->is_master)
  26169. + resume_bulks(state);
  26170. + /* Retry later */
  26171. + state->poll_needed = 1;
  26172. + }
  26173. + break;
  26174. +
  26175. + case VCHIQ_CONNSTATE_PAUSED:
  26176. + vchiq_platform_resume(state);
  26177. + break;
  26178. +
  26179. + case VCHIQ_CONNSTATE_RESUMING:
  26180. + if (queue_message(state, NULL,
  26181. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  26182. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  26183. + if (state->is_master)
  26184. + resume_bulks(state);
  26185. + vchiq_set_conn_state(state,
  26186. + VCHIQ_CONNSTATE_CONNECTED);
  26187. + vchiq_platform_resumed(state);
  26188. + } else {
  26189. + /* This should really be impossible,
  26190. + ** since the PAUSE should have flushed
  26191. + ** through outstanding messages. */
  26192. + vchiq_log_error(vchiq_core_log_level,
  26193. + "Failed to send RESUME "
  26194. + "message");
  26195. + BUG();
  26196. + }
  26197. + break;
  26198. +
  26199. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  26200. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  26201. + vchiq_platform_handle_timeout(state);
  26202. + break;
  26203. + default:
  26204. + break;
  26205. + }
  26206. +
  26207. +
  26208. + }
  26209. +
  26210. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  26211. + parse_rx_slots(state);
  26212. + }
  26213. + return 0;
  26214. +}
  26215. +
  26216. +
  26217. +/* Called by the recycle thread */
  26218. +static int
  26219. +recycle_func(void *v)
  26220. +{
  26221. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  26222. + VCHIQ_SHARED_STATE_T *local = state->local;
  26223. +
  26224. + while (1) {
  26225. + remote_event_wait(&local->recycle);
  26226. +
  26227. + process_free_queue(state);
  26228. + }
  26229. + return 0;
  26230. +}
  26231. +
  26232. +
  26233. +/* Called by the sync thread */
  26234. +static int
  26235. +sync_func(void *v)
  26236. +{
  26237. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  26238. + VCHIQ_SHARED_STATE_T *local = state->local;
  26239. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  26240. + state->remote->slot_sync);
  26241. +
  26242. + while (1) {
  26243. + VCHIQ_SERVICE_T *service;
  26244. + int msgid, size;
  26245. + int type;
  26246. + unsigned int localport, remoteport;
  26247. +
  26248. + remote_event_wait(&local->sync_trigger);
  26249. +
  26250. + rmb();
  26251. +
  26252. + msgid = header->msgid;
  26253. + size = header->size;
  26254. + type = VCHIQ_MSG_TYPE(msgid);
  26255. + localport = VCHIQ_MSG_DSTPORT(msgid);
  26256. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  26257. +
  26258. + service = find_service_by_port(state, localport);
  26259. +
  26260. + if (!service) {
  26261. + vchiq_log_error(vchiq_sync_log_level,
  26262. + "%d: sf %s@%x (%d->%d) - "
  26263. + "invalid/closed service %d",
  26264. + state->id, msg_type_str(type),
  26265. + (unsigned int)header,
  26266. + remoteport, localport, localport);
  26267. + release_message_sync(state, header);
  26268. + continue;
  26269. + }
  26270. +
  26271. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  26272. + int svc_fourcc;
  26273. +
  26274. + svc_fourcc = service
  26275. + ? service->base.fourcc
  26276. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  26277. + vchiq_log_trace(vchiq_sync_log_level,
  26278. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  26279. + msg_type_str(type),
  26280. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  26281. + remoteport, localport, size);
  26282. + if (size > 0)
  26283. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  26284. + min(64, size));
  26285. + }
  26286. +
  26287. + switch (type) {
  26288. + case VCHIQ_MSG_OPENACK:
  26289. + if (size >= sizeof(struct vchiq_openack_payload)) {
  26290. + const struct vchiq_openack_payload *payload =
  26291. + (struct vchiq_openack_payload *)
  26292. + header->data;
  26293. + service->peer_version = payload->version;
  26294. + }
  26295. + vchiq_log_info(vchiq_sync_log_level,
  26296. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  26297. + state->id, (unsigned int)header, size,
  26298. + remoteport, localport, service->peer_version);
  26299. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  26300. + service->remoteport = remoteport;
  26301. + vchiq_set_service_state(service,
  26302. + VCHIQ_SRVSTATE_OPENSYNC);
  26303. + up(&service->remove_event);
  26304. + }
  26305. + release_message_sync(state, header);
  26306. + break;
  26307. +
  26308. + case VCHIQ_MSG_DATA:
  26309. + vchiq_log_trace(vchiq_sync_log_level,
  26310. + "%d: sf DATA@%x,%x (%d->%d)",
  26311. + state->id, (unsigned int)header, size,
  26312. + remoteport, localport);
  26313. +
  26314. + if ((service->remoteport == remoteport) &&
  26315. + (service->srvstate ==
  26316. + VCHIQ_SRVSTATE_OPENSYNC)) {
  26317. + if (make_service_callback(service,
  26318. + VCHIQ_MESSAGE_AVAILABLE, header,
  26319. + NULL) == VCHIQ_RETRY)
  26320. + vchiq_log_error(vchiq_sync_log_level,
  26321. + "synchronous callback to "
  26322. + "service %d returns "
  26323. + "VCHIQ_RETRY",
  26324. + localport);
  26325. + }
  26326. + break;
  26327. +
  26328. + default:
  26329. + vchiq_log_error(vchiq_sync_log_level,
  26330. + "%d: sf unexpected msgid %x@%x,%x",
  26331. + state->id, msgid, (unsigned int)header, size);
  26332. + release_message_sync(state, header);
  26333. + break;
  26334. + }
  26335. +
  26336. + unlock_service(service);
  26337. + }
  26338. +
  26339. + return 0;
  26340. +}
  26341. +
  26342. +
  26343. +static void
  26344. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  26345. +{
  26346. + queue->local_insert = 0;
  26347. + queue->remote_insert = 0;
  26348. + queue->process = 0;
  26349. + queue->remote_notify = 0;
  26350. + queue->remove = 0;
  26351. +}
  26352. +
  26353. +
  26354. +inline const char *
  26355. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  26356. +{
  26357. + return conn_state_names[conn_state];
  26358. +}
  26359. +
  26360. +
  26361. +VCHIQ_SLOT_ZERO_T *
  26362. +vchiq_init_slots(void *mem_base, int mem_size)
  26363. +{
  26364. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  26365. + VCHIQ_SLOT_ZERO_T *slot_zero =
  26366. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  26367. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  26368. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  26369. +
  26370. + /* Ensure there is enough memory to run an absolutely minimum system */
  26371. + num_slots -= first_data_slot;
  26372. +
  26373. + if (num_slots < 4) {
  26374. + vchiq_log_error(vchiq_core_log_level,
  26375. + "vchiq_init_slots - insufficient memory %x bytes",
  26376. + mem_size);
  26377. + return NULL;
  26378. + }
  26379. +
  26380. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  26381. +
  26382. + slot_zero->magic = VCHIQ_MAGIC;
  26383. + slot_zero->version = VCHIQ_VERSION;
  26384. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  26385. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  26386. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  26387. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  26388. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  26389. +
  26390. + slot_zero->master.slot_sync = first_data_slot;
  26391. + slot_zero->master.slot_first = first_data_slot + 1;
  26392. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  26393. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  26394. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  26395. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  26396. +
  26397. + return slot_zero;
  26398. +}
  26399. +
  26400. +VCHIQ_STATUS_T
  26401. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  26402. + int is_master)
  26403. +{
  26404. + VCHIQ_SHARED_STATE_T *local;
  26405. + VCHIQ_SHARED_STATE_T *remote;
  26406. + VCHIQ_STATUS_T status;
  26407. + char threadname[10];
  26408. + static int id;
  26409. + int i;
  26410. +
  26411. + vchiq_log_warning(vchiq_core_log_level,
  26412. + "%s: slot_zero = 0x%08lx, is_master = %d",
  26413. + __func__, (unsigned long)slot_zero, is_master);
  26414. +
  26415. + /* Check the input configuration */
  26416. +
  26417. + if (slot_zero->magic != VCHIQ_MAGIC) {
  26418. + vchiq_loud_error_header();
  26419. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  26420. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  26421. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  26422. + vchiq_loud_error_footer();
  26423. + return VCHIQ_ERROR;
  26424. + }
  26425. +
  26426. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  26427. + vchiq_loud_error_header();
  26428. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  26429. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  26430. + "(minimum %d)",
  26431. + (unsigned int)slot_zero, slot_zero->version,
  26432. + VCHIQ_VERSION_MIN);
  26433. + vchiq_loud_error("Restart with a newer VideoCore image.");
  26434. + vchiq_loud_error_footer();
  26435. + return VCHIQ_ERROR;
  26436. + }
  26437. +
  26438. + if (VCHIQ_VERSION < slot_zero->version_min) {
  26439. + vchiq_loud_error_header();
  26440. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  26441. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  26442. + "minimum %d)",
  26443. + (unsigned int)slot_zero, VCHIQ_VERSION,
  26444. + slot_zero->version_min);
  26445. + vchiq_loud_error("Restart with a newer kernel.");
  26446. + vchiq_loud_error_footer();
  26447. + return VCHIQ_ERROR;
  26448. + }
  26449. +
  26450. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  26451. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  26452. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  26453. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  26454. + vchiq_loud_error_header();
  26455. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  26456. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  26457. + "(expected %x)",
  26458. + (unsigned int)slot_zero,
  26459. + slot_zero->slot_zero_size,
  26460. + sizeof(VCHIQ_SLOT_ZERO_T));
  26461. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  26462. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  26463. + "(expected %d",
  26464. + (unsigned int)slot_zero, slot_zero->slot_size,
  26465. + VCHIQ_SLOT_SIZE);
  26466. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  26467. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  26468. + "(expected %d)",
  26469. + (unsigned int)slot_zero, slot_zero->max_slots,
  26470. + VCHIQ_MAX_SLOTS);
  26471. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  26472. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  26473. + "(expected %d)",
  26474. + (unsigned int)slot_zero,
  26475. + slot_zero->max_slots_per_side,
  26476. + VCHIQ_MAX_SLOTS_PER_SIDE);
  26477. + vchiq_loud_error_footer();
  26478. + return VCHIQ_ERROR;
  26479. + }
  26480. +
  26481. + if (is_master) {
  26482. + local = &slot_zero->master;
  26483. + remote = &slot_zero->slave;
  26484. + } else {
  26485. + local = &slot_zero->slave;
  26486. + remote = &slot_zero->master;
  26487. + }
  26488. +
  26489. + if (local->initialised) {
  26490. + vchiq_loud_error_header();
  26491. + if (remote->initialised)
  26492. + vchiq_loud_error("local state has already been "
  26493. + "initialised");
  26494. + else
  26495. + vchiq_loud_error("master/slave mismatch - two %ss",
  26496. + is_master ? "master" : "slave");
  26497. + vchiq_loud_error_footer();
  26498. + return VCHIQ_ERROR;
  26499. + }
  26500. +
  26501. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  26502. +
  26503. + state->id = id++;
  26504. + state->is_master = is_master;
  26505. +
  26506. + /*
  26507. + initialize shared state pointers
  26508. + */
  26509. +
  26510. + state->local = local;
  26511. + state->remote = remote;
  26512. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  26513. +
  26514. + /*
  26515. + initialize events and mutexes
  26516. + */
  26517. +
  26518. + sema_init(&state->connect, 0);
  26519. + mutex_init(&state->mutex);
  26520. + sema_init(&state->trigger_event, 0);
  26521. + sema_init(&state->recycle_event, 0);
  26522. + sema_init(&state->sync_trigger_event, 0);
  26523. + sema_init(&state->sync_release_event, 0);
  26524. +
  26525. + mutex_init(&state->slot_mutex);
  26526. + mutex_init(&state->recycle_mutex);
  26527. + mutex_init(&state->sync_mutex);
  26528. + mutex_init(&state->bulk_transfer_mutex);
  26529. +
  26530. + sema_init(&state->slot_available_event, 0);
  26531. + sema_init(&state->slot_remove_event, 0);
  26532. + sema_init(&state->data_quota_event, 0);
  26533. +
  26534. + state->slot_queue_available = 0;
  26535. +
  26536. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  26537. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26538. + &state->service_quotas[i];
  26539. + sema_init(&service_quota->quota_event, 0);
  26540. + }
  26541. +
  26542. + for (i = local->slot_first; i <= local->slot_last; i++) {
  26543. + local->slot_queue[state->slot_queue_available++] = i;
  26544. + up(&state->slot_available_event);
  26545. + }
  26546. +
  26547. + state->default_slot_quota = state->slot_queue_available/2;
  26548. + state->default_message_quota =
  26549. + min((unsigned short)(state->default_slot_quota * 256),
  26550. + (unsigned short)~0);
  26551. +
  26552. + state->previous_data_index = -1;
  26553. + state->data_use_count = 0;
  26554. + state->data_quota = state->slot_queue_available - 1;
  26555. +
  26556. + local->trigger.event = &state->trigger_event;
  26557. + remote_event_create(&local->trigger);
  26558. + local->tx_pos = 0;
  26559. +
  26560. + local->recycle.event = &state->recycle_event;
  26561. + remote_event_create(&local->recycle);
  26562. + local->slot_queue_recycle = state->slot_queue_available;
  26563. +
  26564. + local->sync_trigger.event = &state->sync_trigger_event;
  26565. + remote_event_create(&local->sync_trigger);
  26566. +
  26567. + local->sync_release.event = &state->sync_release_event;
  26568. + remote_event_create(&local->sync_release);
  26569. +
  26570. + /* At start-of-day, the slot is empty and available */
  26571. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  26572. + = VCHIQ_MSGID_PADDING;
  26573. + remote_event_signal_local(&local->sync_release);
  26574. +
  26575. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  26576. +
  26577. + status = vchiq_platform_init_state(state);
  26578. +
  26579. + /*
  26580. + bring up slot handler thread
  26581. + */
  26582. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  26583. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  26584. + (void *)state,
  26585. + threadname);
  26586. +
  26587. + if (state->slot_handler_thread == NULL) {
  26588. + vchiq_loud_error_header();
  26589. + vchiq_loud_error("couldn't create thread %s", threadname);
  26590. + vchiq_loud_error_footer();
  26591. + return VCHIQ_ERROR;
  26592. + }
  26593. + set_user_nice(state->slot_handler_thread, -19);
  26594. + wake_up_process(state->slot_handler_thread);
  26595. +
  26596. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  26597. + state->recycle_thread = kthread_create(&recycle_func,
  26598. + (void *)state,
  26599. + threadname);
  26600. + if (state->recycle_thread == NULL) {
  26601. + vchiq_loud_error_header();
  26602. + vchiq_loud_error("couldn't create thread %s", threadname);
  26603. + vchiq_loud_error_footer();
  26604. + return VCHIQ_ERROR;
  26605. + }
  26606. + set_user_nice(state->recycle_thread, -19);
  26607. + wake_up_process(state->recycle_thread);
  26608. +
  26609. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  26610. + state->sync_thread = kthread_create(&sync_func,
  26611. + (void *)state,
  26612. + threadname);
  26613. + if (state->sync_thread == NULL) {
  26614. + vchiq_loud_error_header();
  26615. + vchiq_loud_error("couldn't create thread %s", threadname);
  26616. + vchiq_loud_error_footer();
  26617. + return VCHIQ_ERROR;
  26618. + }
  26619. + set_user_nice(state->sync_thread, -20);
  26620. + wake_up_process(state->sync_thread);
  26621. +
  26622. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  26623. + vchiq_states[state->id] = state;
  26624. +
  26625. + /* Indicate readiness to the other side */
  26626. + local->initialised = 1;
  26627. +
  26628. + return status;
  26629. +}
  26630. +
  26631. +/* Called from application thread when a client or server service is created. */
  26632. +VCHIQ_SERVICE_T *
  26633. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  26634. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  26635. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  26636. +{
  26637. + VCHIQ_SERVICE_T *service;
  26638. +
  26639. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  26640. + if (service) {
  26641. + service->base.fourcc = params->fourcc;
  26642. + service->base.callback = params->callback;
  26643. + service->base.userdata = params->userdata;
  26644. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  26645. + service->ref_count = 1;
  26646. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  26647. + service->userdata_term = userdata_term;
  26648. + service->localport = VCHIQ_PORT_FREE;
  26649. + service->remoteport = VCHIQ_PORT_FREE;
  26650. +
  26651. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  26652. + VCHIQ_FOURCC_INVALID : params->fourcc;
  26653. + service->client_id = 0;
  26654. + service->auto_close = 1;
  26655. + service->sync = 0;
  26656. + service->closing = 0;
  26657. + atomic_set(&service->poll_flags, 0);
  26658. + service->version = params->version;
  26659. + service->version_min = params->version_min;
  26660. + service->state = state;
  26661. + service->instance = instance;
  26662. + service->service_use_count = 0;
  26663. + init_bulk_queue(&service->bulk_tx);
  26664. + init_bulk_queue(&service->bulk_rx);
  26665. + sema_init(&service->remove_event, 0);
  26666. + sema_init(&service->bulk_remove_event, 0);
  26667. + mutex_init(&service->bulk_mutex);
  26668. + memset(&service->stats, 0, sizeof(service->stats));
  26669. + } else {
  26670. + vchiq_log_error(vchiq_core_log_level,
  26671. + "Out of memory");
  26672. + }
  26673. +
  26674. + if (service) {
  26675. + VCHIQ_SERVICE_T **pservice = NULL;
  26676. + int i;
  26677. +
  26678. + /* Although it is perfectly possible to use service_spinlock
  26679. + ** to protect the creation of services, it is overkill as it
  26680. + ** disables interrupts while the array is searched.
  26681. + ** The only danger is of another thread trying to create a
  26682. + ** service - service deletion is safe.
  26683. + ** Therefore it is preferable to use state->mutex which,
  26684. + ** although slower to claim, doesn't block interrupts while
  26685. + ** it is held.
  26686. + */
  26687. +
  26688. + mutex_lock(&state->mutex);
  26689. +
  26690. + /* Prepare to use a previously unused service */
  26691. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  26692. + pservice = &state->services[state->unused_service];
  26693. +
  26694. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  26695. + for (i = 0; i < state->unused_service; i++) {
  26696. + VCHIQ_SERVICE_T *srv = state->services[i];
  26697. + if (!srv) {
  26698. + pservice = &state->services[i];
  26699. + break;
  26700. + }
  26701. + }
  26702. + } else {
  26703. + for (i = (state->unused_service - 1); i >= 0; i--) {
  26704. + VCHIQ_SERVICE_T *srv = state->services[i];
  26705. + if (!srv)
  26706. + pservice = &state->services[i];
  26707. + else if ((srv->public_fourcc == params->fourcc)
  26708. + && ((srv->instance != instance) ||
  26709. + (srv->base.callback !=
  26710. + params->callback))) {
  26711. + /* There is another server using this
  26712. + ** fourcc which doesn't match. */
  26713. + pservice = NULL;
  26714. + break;
  26715. + }
  26716. + }
  26717. + }
  26718. +
  26719. + if (pservice) {
  26720. + service->localport = (pservice - state->services);
  26721. + if (!handle_seq)
  26722. + handle_seq = VCHIQ_MAX_STATES *
  26723. + VCHIQ_MAX_SERVICES;
  26724. + service->handle = handle_seq |
  26725. + (state->id * VCHIQ_MAX_SERVICES) |
  26726. + service->localport;
  26727. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  26728. + *pservice = service;
  26729. + if (pservice == &state->services[state->unused_service])
  26730. + state->unused_service++;
  26731. + }
  26732. +
  26733. + mutex_unlock(&state->mutex);
  26734. +
  26735. + if (!pservice) {
  26736. + kfree(service);
  26737. + service = NULL;
  26738. + }
  26739. + }
  26740. +
  26741. + if (service) {
  26742. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26743. + &state->service_quotas[service->localport];
  26744. + service_quota->slot_quota = state->default_slot_quota;
  26745. + service_quota->message_quota = state->default_message_quota;
  26746. + if (service_quota->slot_use_count == 0)
  26747. + service_quota->previous_tx_index =
  26748. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  26749. + - 1;
  26750. +
  26751. + /* Bring this service online */
  26752. + vchiq_set_service_state(service, srvstate);
  26753. +
  26754. + vchiq_log_info(vchiq_core_msg_log_level,
  26755. + "%s Service %c%c%c%c SrcPort:%d",
  26756. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  26757. + ? "Open" : "Add",
  26758. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  26759. + service->localport);
  26760. + }
  26761. +
  26762. + /* Don't unlock the service - leave it with a ref_count of 1. */
  26763. +
  26764. + return service;
  26765. +}
  26766. +
  26767. +VCHIQ_STATUS_T
  26768. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  26769. +{
  26770. + struct vchiq_open_payload payload = {
  26771. + service->base.fourcc,
  26772. + client_id,
  26773. + service->version,
  26774. + service->version_min
  26775. + };
  26776. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  26777. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26778. +
  26779. + service->client_id = client_id;
  26780. + vchiq_use_service_internal(service);
  26781. + status = queue_message(service->state, NULL,
  26782. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  26783. + &body, 1, sizeof(payload), 1);
  26784. + if (status == VCHIQ_SUCCESS) {
  26785. + if (down_interruptible(&service->remove_event) != 0) {
  26786. + status = VCHIQ_RETRY;
  26787. + vchiq_release_service_internal(service);
  26788. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  26789. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  26790. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  26791. + vchiq_log_error(vchiq_core_log_level,
  26792. + "%d: osi - srvstate = %s (ref %d)",
  26793. + service->state->id,
  26794. + srvstate_names[service->srvstate],
  26795. + service->ref_count);
  26796. + status = VCHIQ_ERROR;
  26797. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26798. + vchiq_release_service_internal(service);
  26799. + }
  26800. + }
  26801. + return status;
  26802. +}
  26803. +
  26804. +static void
  26805. +release_service_messages(VCHIQ_SERVICE_T *service)
  26806. +{
  26807. + VCHIQ_STATE_T *state = service->state;
  26808. + int slot_last = state->remote->slot_last;
  26809. + int i;
  26810. +
  26811. + /* Release any claimed messages */
  26812. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  26813. + VCHIQ_SLOT_INFO_T *slot_info =
  26814. + SLOT_INFO_FROM_INDEX(state, i);
  26815. + if (slot_info->release_count != slot_info->use_count) {
  26816. + char *data =
  26817. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  26818. + unsigned int pos, end;
  26819. +
  26820. + end = VCHIQ_SLOT_SIZE;
  26821. + if (data == state->rx_data)
  26822. + /* This buffer is still being read from - stop
  26823. + ** at the current read position */
  26824. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  26825. +
  26826. + pos = 0;
  26827. +
  26828. + while (pos < end) {
  26829. + VCHIQ_HEADER_T *header =
  26830. + (VCHIQ_HEADER_T *)(data + pos);
  26831. + int msgid = header->msgid;
  26832. + int port = VCHIQ_MSG_DSTPORT(msgid);
  26833. + if ((port == service->localport) &&
  26834. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  26835. + vchiq_log_info(vchiq_core_log_level,
  26836. + " fsi - hdr %x",
  26837. + (unsigned int)header);
  26838. + release_slot(state, slot_info, header,
  26839. + NULL);
  26840. + }
  26841. + pos += calc_stride(header->size);
  26842. + if (pos > VCHIQ_SLOT_SIZE) {
  26843. + vchiq_log_error(vchiq_core_log_level,
  26844. + "fsi - pos %x: header %x, "
  26845. + "msgid %x, header->msgid %x, "
  26846. + "header->size %x",
  26847. + pos, (unsigned int)header,
  26848. + msgid, header->msgid,
  26849. + header->size);
  26850. + WARN(1, "invalid slot position\n");
  26851. + }
  26852. + }
  26853. + }
  26854. + }
  26855. +}
  26856. +
  26857. +static int
  26858. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  26859. +{
  26860. + VCHIQ_STATUS_T status;
  26861. +
  26862. + /* Abort any outstanding bulk transfers */
  26863. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  26864. + return 0;
  26865. + abort_outstanding_bulks(service, &service->bulk_tx);
  26866. + abort_outstanding_bulks(service, &service->bulk_rx);
  26867. + mutex_unlock(&service->bulk_mutex);
  26868. +
  26869. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  26870. + if (status == VCHIQ_SUCCESS)
  26871. + status = notify_bulks(service, &service->bulk_rx,
  26872. + 0/*!retry_poll*/);
  26873. + return (status == VCHIQ_SUCCESS);
  26874. +}
  26875. +
  26876. +static VCHIQ_STATUS_T
  26877. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  26878. +{
  26879. + VCHIQ_STATUS_T status;
  26880. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26881. + int newstate;
  26882. +
  26883. + switch (service->srvstate) {
  26884. + case VCHIQ_SRVSTATE_OPEN:
  26885. + case VCHIQ_SRVSTATE_CLOSESENT:
  26886. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26887. + if (is_server) {
  26888. + if (service->auto_close) {
  26889. + service->client_id = 0;
  26890. + service->remoteport = VCHIQ_PORT_FREE;
  26891. + newstate = VCHIQ_SRVSTATE_LISTENING;
  26892. + } else
  26893. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  26894. + } else
  26895. + newstate = VCHIQ_SRVSTATE_CLOSED;
  26896. + vchiq_set_service_state(service, newstate);
  26897. + break;
  26898. + case VCHIQ_SRVSTATE_LISTENING:
  26899. + break;
  26900. + default:
  26901. + vchiq_log_error(vchiq_core_log_level,
  26902. + "close_service_complete(%x) called in state %s",
  26903. + service->handle, srvstate_names[service->srvstate]);
  26904. + WARN(1, "close_service_complete in unexpected state\n");
  26905. + return VCHIQ_ERROR;
  26906. + }
  26907. +
  26908. + status = make_service_callback(service,
  26909. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  26910. +
  26911. + if (status != VCHIQ_RETRY) {
  26912. + int uc = service->service_use_count;
  26913. + int i;
  26914. + /* Complete the close process */
  26915. + for (i = 0; i < uc; i++)
  26916. + /* cater for cases where close is forced and the
  26917. + ** client may not close all it's handles */
  26918. + vchiq_release_service_internal(service);
  26919. +
  26920. + service->client_id = 0;
  26921. + service->remoteport = VCHIQ_PORT_FREE;
  26922. +
  26923. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  26924. + vchiq_free_service_internal(service);
  26925. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  26926. + if (is_server)
  26927. + service->closing = 0;
  26928. +
  26929. + up(&service->remove_event);
  26930. + }
  26931. + } else
  26932. + vchiq_set_service_state(service, failstate);
  26933. +
  26934. + return status;
  26935. +}
  26936. +
  26937. +/* Called by the slot handler */
  26938. +VCHIQ_STATUS_T
  26939. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  26940. +{
  26941. + VCHIQ_STATE_T *state = service->state;
  26942. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26943. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26944. +
  26945. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  26946. + service->state->id, service->localport, close_recvd,
  26947. + srvstate_names[service->srvstate]);
  26948. +
  26949. + switch (service->srvstate) {
  26950. + case VCHIQ_SRVSTATE_CLOSED:
  26951. + case VCHIQ_SRVSTATE_HIDDEN:
  26952. + case VCHIQ_SRVSTATE_LISTENING:
  26953. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26954. + if (close_recvd)
  26955. + vchiq_log_error(vchiq_core_log_level,
  26956. + "vchiq_close_service_internal(1) called "
  26957. + "in state %s",
  26958. + srvstate_names[service->srvstate]);
  26959. + else if (is_server) {
  26960. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  26961. + status = VCHIQ_ERROR;
  26962. + } else {
  26963. + service->client_id = 0;
  26964. + service->remoteport = VCHIQ_PORT_FREE;
  26965. + if (service->srvstate ==
  26966. + VCHIQ_SRVSTATE_CLOSEWAIT)
  26967. + vchiq_set_service_state(service,
  26968. + VCHIQ_SRVSTATE_LISTENING);
  26969. + }
  26970. + up(&service->remove_event);
  26971. + } else
  26972. + vchiq_free_service_internal(service);
  26973. + break;
  26974. + case VCHIQ_SRVSTATE_OPENING:
  26975. + if (close_recvd) {
  26976. + /* The open was rejected - tell the user */
  26977. + vchiq_set_service_state(service,
  26978. + VCHIQ_SRVSTATE_CLOSEWAIT);
  26979. + up(&service->remove_event);
  26980. + } else {
  26981. + /* Shutdown mid-open - let the other side know */
  26982. + status = queue_message(state, service,
  26983. + VCHIQ_MAKE_MSG
  26984. + (VCHIQ_MSG_CLOSE,
  26985. + service->localport,
  26986. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26987. + NULL, 0, 0, 0);
  26988. + }
  26989. + break;
  26990. +
  26991. + case VCHIQ_SRVSTATE_OPENSYNC:
  26992. + mutex_lock(&state->sync_mutex);
  26993. + /* Drop through */
  26994. +
  26995. + case VCHIQ_SRVSTATE_OPEN:
  26996. + if (state->is_master || close_recvd) {
  26997. + if (!do_abort_bulks(service))
  26998. + status = VCHIQ_RETRY;
  26999. + }
  27000. +
  27001. + release_service_messages(service);
  27002. +
  27003. + if (status == VCHIQ_SUCCESS)
  27004. + status = queue_message(state, service,
  27005. + VCHIQ_MAKE_MSG
  27006. + (VCHIQ_MSG_CLOSE,
  27007. + service->localport,
  27008. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  27009. + NULL, 0, 0, 0);
  27010. +
  27011. + if (status == VCHIQ_SUCCESS) {
  27012. + if (!close_recvd)
  27013. + break;
  27014. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  27015. + mutex_unlock(&state->sync_mutex);
  27016. + break;
  27017. + } else
  27018. + break;
  27019. +
  27020. + status = close_service_complete(service,
  27021. + VCHIQ_SRVSTATE_CLOSERECVD);
  27022. + break;
  27023. +
  27024. + case VCHIQ_SRVSTATE_CLOSESENT:
  27025. + if (!close_recvd)
  27026. + /* This happens when a process is killed mid-close */
  27027. + break;
  27028. +
  27029. + if (!state->is_master) {
  27030. + if (!do_abort_bulks(service)) {
  27031. + status = VCHIQ_RETRY;
  27032. + break;
  27033. + }
  27034. + }
  27035. +
  27036. + if (status == VCHIQ_SUCCESS)
  27037. + status = close_service_complete(service,
  27038. + VCHIQ_SRVSTATE_CLOSERECVD);
  27039. + break;
  27040. +
  27041. + case VCHIQ_SRVSTATE_CLOSERECVD:
  27042. + if (!close_recvd && is_server)
  27043. + /* Force into LISTENING mode */
  27044. + vchiq_set_service_state(service,
  27045. + VCHIQ_SRVSTATE_LISTENING);
  27046. + status = close_service_complete(service,
  27047. + VCHIQ_SRVSTATE_CLOSERECVD);
  27048. + break;
  27049. +
  27050. + default:
  27051. + vchiq_log_error(vchiq_core_log_level,
  27052. + "vchiq_close_service_internal(%d) called in state %s",
  27053. + close_recvd, srvstate_names[service->srvstate]);
  27054. + break;
  27055. + }
  27056. +
  27057. + return status;
  27058. +}
  27059. +
  27060. +/* Called from the application process upon process death */
  27061. +void
  27062. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  27063. +{
  27064. + VCHIQ_STATE_T *state = service->state;
  27065. +
  27066. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  27067. + state->id, service->localport, service->remoteport);
  27068. +
  27069. + mark_service_closing(service);
  27070. +
  27071. + /* Mark the service for removal by the slot handler */
  27072. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  27073. +}
  27074. +
  27075. +/* Called from the slot handler */
  27076. +void
  27077. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  27078. +{
  27079. + VCHIQ_STATE_T *state = service->state;
  27080. +
  27081. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  27082. + state->id, service->localport);
  27083. +
  27084. + switch (service->srvstate) {
  27085. + case VCHIQ_SRVSTATE_OPENING:
  27086. + case VCHIQ_SRVSTATE_CLOSED:
  27087. + case VCHIQ_SRVSTATE_HIDDEN:
  27088. + case VCHIQ_SRVSTATE_LISTENING:
  27089. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  27090. + break;
  27091. + default:
  27092. + vchiq_log_error(vchiq_core_log_level,
  27093. + "%d: fsi - (%d) in state %s",
  27094. + state->id, service->localport,
  27095. + srvstate_names[service->srvstate]);
  27096. + return;
  27097. + }
  27098. +
  27099. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  27100. +
  27101. + up(&service->remove_event);
  27102. +
  27103. + /* Release the initial lock */
  27104. + unlock_service(service);
  27105. +}
  27106. +
  27107. +VCHIQ_STATUS_T
  27108. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  27109. +{
  27110. + VCHIQ_SERVICE_T *service;
  27111. + int i;
  27112. +
  27113. + /* Find all services registered to this client and enable them. */
  27114. + i = 0;
  27115. + while ((service = next_service_by_instance(state, instance,
  27116. + &i)) != NULL) {
  27117. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  27118. + vchiq_set_service_state(service,
  27119. + VCHIQ_SRVSTATE_LISTENING);
  27120. + unlock_service(service);
  27121. + }
  27122. +
  27123. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  27124. + if (queue_message(state, NULL,
  27125. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  27126. + 0, 1) == VCHIQ_RETRY)
  27127. + return VCHIQ_RETRY;
  27128. +
  27129. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  27130. + }
  27131. +
  27132. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  27133. + if (down_interruptible(&state->connect) != 0)
  27134. + return VCHIQ_RETRY;
  27135. +
  27136. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  27137. + up(&state->connect);
  27138. + }
  27139. +
  27140. + return VCHIQ_SUCCESS;
  27141. +}
  27142. +
  27143. +VCHIQ_STATUS_T
  27144. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  27145. +{
  27146. + VCHIQ_SERVICE_T *service;
  27147. + int i;
  27148. +
  27149. + /* Find all services registered to this client and enable them. */
  27150. + i = 0;
  27151. + while ((service = next_service_by_instance(state, instance,
  27152. + &i)) != NULL) {
  27153. + (void)vchiq_remove_service(service->handle);
  27154. + unlock_service(service);
  27155. + }
  27156. +
  27157. + return VCHIQ_SUCCESS;
  27158. +}
  27159. +
  27160. +VCHIQ_STATUS_T
  27161. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  27162. +{
  27163. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27164. +
  27165. + switch (state->conn_state) {
  27166. + case VCHIQ_CONNSTATE_CONNECTED:
  27167. + /* Request a pause */
  27168. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  27169. + request_poll(state, NULL, 0);
  27170. + break;
  27171. + default:
  27172. + vchiq_log_error(vchiq_core_log_level,
  27173. + "vchiq_pause_internal in state %s\n",
  27174. + conn_state_names[state->conn_state]);
  27175. + status = VCHIQ_ERROR;
  27176. + VCHIQ_STATS_INC(state, error_count);
  27177. + break;
  27178. + }
  27179. +
  27180. + return status;
  27181. +}
  27182. +
  27183. +VCHIQ_STATUS_T
  27184. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  27185. +{
  27186. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27187. +
  27188. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  27189. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  27190. + request_poll(state, NULL, 0);
  27191. + } else {
  27192. + status = VCHIQ_ERROR;
  27193. + VCHIQ_STATS_INC(state, error_count);
  27194. + }
  27195. +
  27196. + return status;
  27197. +}
  27198. +
  27199. +VCHIQ_STATUS_T
  27200. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  27201. +{
  27202. + /* Unregister the service */
  27203. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27204. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27205. +
  27206. + if (!service)
  27207. + return VCHIQ_ERROR;
  27208. +
  27209. + vchiq_log_info(vchiq_core_log_level,
  27210. + "%d: close_service:%d",
  27211. + service->state->id, service->localport);
  27212. +
  27213. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  27214. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  27215. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  27216. + unlock_service(service);
  27217. + return VCHIQ_ERROR;
  27218. + }
  27219. +
  27220. + mark_service_closing(service);
  27221. +
  27222. + if (current == service->state->slot_handler_thread) {
  27223. + status = vchiq_close_service_internal(service,
  27224. + 0/*!close_recvd*/);
  27225. + BUG_ON(status == VCHIQ_RETRY);
  27226. + } else {
  27227. + /* Mark the service for termination by the slot handler */
  27228. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  27229. + }
  27230. +
  27231. + while (1) {
  27232. + if (down_interruptible(&service->remove_event) != 0) {
  27233. + status = VCHIQ_RETRY;
  27234. + break;
  27235. + }
  27236. +
  27237. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  27238. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  27239. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  27240. + break;
  27241. +
  27242. + vchiq_log_warning(vchiq_core_log_level,
  27243. + "%d: close_service:%d - waiting in state %s",
  27244. + service->state->id, service->localport,
  27245. + srvstate_names[service->srvstate]);
  27246. + }
  27247. +
  27248. + if ((status == VCHIQ_SUCCESS) &&
  27249. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  27250. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  27251. + status = VCHIQ_ERROR;
  27252. +
  27253. + unlock_service(service);
  27254. +
  27255. + return status;
  27256. +}
  27257. +
  27258. +VCHIQ_STATUS_T
  27259. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  27260. +{
  27261. + /* Unregister the service */
  27262. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27263. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27264. +
  27265. + if (!service)
  27266. + return VCHIQ_ERROR;
  27267. +
  27268. + vchiq_log_info(vchiq_core_log_level,
  27269. + "%d: remove_service:%d",
  27270. + service->state->id, service->localport);
  27271. +
  27272. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  27273. + unlock_service(service);
  27274. + return VCHIQ_ERROR;
  27275. + }
  27276. +
  27277. + mark_service_closing(service);
  27278. +
  27279. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  27280. + (current == service->state->slot_handler_thread)) {
  27281. + /* Make it look like a client, because it must be removed and
  27282. + not left in the LISTENING state. */
  27283. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  27284. +
  27285. + status = vchiq_close_service_internal(service,
  27286. + 0/*!close_recvd*/);
  27287. + BUG_ON(status == VCHIQ_RETRY);
  27288. + } else {
  27289. + /* Mark the service for removal by the slot handler */
  27290. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  27291. + }
  27292. + while (1) {
  27293. + if (down_interruptible(&service->remove_event) != 0) {
  27294. + status = VCHIQ_RETRY;
  27295. + break;
  27296. + }
  27297. +
  27298. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  27299. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  27300. + break;
  27301. +
  27302. + vchiq_log_warning(vchiq_core_log_level,
  27303. + "%d: remove_service:%d - waiting in state %s",
  27304. + service->state->id, service->localport,
  27305. + srvstate_names[service->srvstate]);
  27306. + }
  27307. +
  27308. + if ((status == VCHIQ_SUCCESS) &&
  27309. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  27310. + status = VCHIQ_ERROR;
  27311. +
  27312. + unlock_service(service);
  27313. +
  27314. + return status;
  27315. +}
  27316. +
  27317. +
  27318. +/* This function may be called by kernel threads or user threads.
  27319. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  27320. + * received and the call should be retried after being returned to user
  27321. + * context.
  27322. + * When called in blocking mode, the userdata field points to a bulk_waiter
  27323. + * structure.
  27324. + */
  27325. +VCHIQ_STATUS_T
  27326. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27327. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27328. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  27329. +{
  27330. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27331. + VCHIQ_BULK_QUEUE_T *queue;
  27332. + VCHIQ_BULK_T *bulk;
  27333. + VCHIQ_STATE_T *state;
  27334. + struct bulk_waiter *bulk_waiter = NULL;
  27335. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  27336. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  27337. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  27338. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27339. +
  27340. + if (!service ||
  27341. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  27342. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  27343. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  27344. + goto error_exit;
  27345. +
  27346. + switch (mode) {
  27347. + case VCHIQ_BULK_MODE_NOCALLBACK:
  27348. + case VCHIQ_BULK_MODE_CALLBACK:
  27349. + break;
  27350. + case VCHIQ_BULK_MODE_BLOCKING:
  27351. + bulk_waiter = (struct bulk_waiter *)userdata;
  27352. + sema_init(&bulk_waiter->event, 0);
  27353. + bulk_waiter->actual = 0;
  27354. + bulk_waiter->bulk = NULL;
  27355. + break;
  27356. + case VCHIQ_BULK_MODE_WAITING:
  27357. + bulk_waiter = (struct bulk_waiter *)userdata;
  27358. + bulk = bulk_waiter->bulk;
  27359. + goto waiting;
  27360. + default:
  27361. + goto error_exit;
  27362. + }
  27363. +
  27364. + state = service->state;
  27365. +
  27366. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  27367. + &service->bulk_tx : &service->bulk_rx;
  27368. +
  27369. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  27370. + status = VCHIQ_RETRY;
  27371. + goto error_exit;
  27372. + }
  27373. +
  27374. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  27375. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  27376. + do {
  27377. + mutex_unlock(&service->bulk_mutex);
  27378. + if (down_interruptible(&service->bulk_remove_event)
  27379. + != 0) {
  27380. + status = VCHIQ_RETRY;
  27381. + goto error_exit;
  27382. + }
  27383. + if (mutex_lock_interruptible(&service->bulk_mutex)
  27384. + != 0) {
  27385. + status = VCHIQ_RETRY;
  27386. + goto error_exit;
  27387. + }
  27388. + } while (queue->local_insert == queue->remove +
  27389. + VCHIQ_NUM_SERVICE_BULKS);
  27390. + }
  27391. +
  27392. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  27393. +
  27394. + bulk->mode = mode;
  27395. + bulk->dir = dir;
  27396. + bulk->userdata = userdata;
  27397. + bulk->size = size;
  27398. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  27399. +
  27400. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  27401. + VCHIQ_SUCCESS)
  27402. + goto unlock_error_exit;
  27403. +
  27404. + wmb();
  27405. +
  27406. + vchiq_log_info(vchiq_core_log_level,
  27407. + "%d: bt (%d->%d) %cx %x@%x %x",
  27408. + state->id,
  27409. + service->localport, service->remoteport, dir_char,
  27410. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  27411. +
  27412. + if (state->is_master) {
  27413. + queue->local_insert++;
  27414. + if (resolve_bulks(service, queue))
  27415. + request_poll(state, service,
  27416. + (dir == VCHIQ_BULK_TRANSMIT) ?
  27417. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  27418. + } else {
  27419. + int payload[2] = { (int)bulk->data, bulk->size };
  27420. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  27421. +
  27422. + status = queue_message(state, NULL,
  27423. + VCHIQ_MAKE_MSG(dir_msgtype,
  27424. + service->localport, service->remoteport),
  27425. + &element, 1, sizeof(payload), 1);
  27426. + if (status != VCHIQ_SUCCESS) {
  27427. + vchiq_complete_bulk(bulk);
  27428. + goto unlock_error_exit;
  27429. + }
  27430. + queue->local_insert++;
  27431. + }
  27432. +
  27433. + mutex_unlock(&service->bulk_mutex);
  27434. +
  27435. + vchiq_log_trace(vchiq_core_log_level,
  27436. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  27437. + state->id,
  27438. + service->localport, dir_char,
  27439. + queue->local_insert, queue->remote_insert, queue->process);
  27440. +
  27441. +waiting:
  27442. + unlock_service(service);
  27443. +
  27444. + status = VCHIQ_SUCCESS;
  27445. +
  27446. + if (bulk_waiter) {
  27447. + bulk_waiter->bulk = bulk;
  27448. + if (down_interruptible(&bulk_waiter->event) != 0)
  27449. + status = VCHIQ_RETRY;
  27450. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  27451. + status = VCHIQ_ERROR;
  27452. + }
  27453. +
  27454. + return status;
  27455. +
  27456. +unlock_error_exit:
  27457. + mutex_unlock(&service->bulk_mutex);
  27458. +
  27459. +error_exit:
  27460. + if (service)
  27461. + unlock_service(service);
  27462. + return status;
  27463. +}
  27464. +
  27465. +VCHIQ_STATUS_T
  27466. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  27467. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  27468. +{
  27469. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27470. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27471. +
  27472. + unsigned int size = 0;
  27473. + unsigned int i;
  27474. +
  27475. + if (!service ||
  27476. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  27477. + goto error_exit;
  27478. +
  27479. + for (i = 0; i < (unsigned int)count; i++) {
  27480. + if (elements[i].size) {
  27481. + if (elements[i].data == NULL) {
  27482. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  27483. + goto error_exit;
  27484. + }
  27485. + size += elements[i].size;
  27486. + }
  27487. + }
  27488. +
  27489. + if (size > VCHIQ_MAX_MSG_SIZE) {
  27490. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  27491. + goto error_exit;
  27492. + }
  27493. +
  27494. + switch (service->srvstate) {
  27495. + case VCHIQ_SRVSTATE_OPEN:
  27496. + status = queue_message(service->state, service,
  27497. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  27498. + service->localport,
  27499. + service->remoteport),
  27500. + elements, count, size, 1);
  27501. + break;
  27502. + case VCHIQ_SRVSTATE_OPENSYNC:
  27503. + status = queue_message_sync(service->state, service,
  27504. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  27505. + service->localport,
  27506. + service->remoteport),
  27507. + elements, count, size, 1);
  27508. + break;
  27509. + default:
  27510. + status = VCHIQ_ERROR;
  27511. + break;
  27512. + }
  27513. +
  27514. +error_exit:
  27515. + if (service)
  27516. + unlock_service(service);
  27517. +
  27518. + return status;
  27519. +}
  27520. +
  27521. +void
  27522. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  27523. +{
  27524. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27525. + VCHIQ_SHARED_STATE_T *remote;
  27526. + VCHIQ_STATE_T *state;
  27527. + int slot_index;
  27528. +
  27529. + if (!service)
  27530. + return;
  27531. +
  27532. + state = service->state;
  27533. + remote = state->remote;
  27534. +
  27535. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  27536. +
  27537. + if ((slot_index >= remote->slot_first) &&
  27538. + (slot_index <= remote->slot_last)) {
  27539. + int msgid = header->msgid;
  27540. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  27541. + VCHIQ_SLOT_INFO_T *slot_info =
  27542. + SLOT_INFO_FROM_INDEX(state, slot_index);
  27543. +
  27544. + release_slot(state, slot_info, header, service);
  27545. + }
  27546. + } else if (slot_index == remote->slot_sync)
  27547. + release_message_sync(state, header);
  27548. +
  27549. + unlock_service(service);
  27550. +}
  27551. +
  27552. +static void
  27553. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  27554. +{
  27555. + header->msgid = VCHIQ_MSGID_PADDING;
  27556. + wmb();
  27557. + remote_event_signal(&state->remote->sync_release);
  27558. +}
  27559. +
  27560. +VCHIQ_STATUS_T
  27561. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  27562. +{
  27563. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27564. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27565. +
  27566. + if (!service ||
  27567. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  27568. + !peer_version)
  27569. + goto exit;
  27570. + *peer_version = service->peer_version;
  27571. + status = VCHIQ_SUCCESS;
  27572. +
  27573. +exit:
  27574. + if (service)
  27575. + unlock_service(service);
  27576. + return status;
  27577. +}
  27578. +
  27579. +VCHIQ_STATUS_T
  27580. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  27581. + int config_size, VCHIQ_CONFIG_T *pconfig)
  27582. +{
  27583. + VCHIQ_CONFIG_T config;
  27584. +
  27585. + (void)instance;
  27586. +
  27587. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  27588. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  27589. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  27590. + config.max_services = VCHIQ_MAX_SERVICES;
  27591. + config.version = VCHIQ_VERSION;
  27592. + config.version_min = VCHIQ_VERSION_MIN;
  27593. +
  27594. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  27595. + return VCHIQ_ERROR;
  27596. +
  27597. + memcpy(pconfig, &config,
  27598. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  27599. +
  27600. + return VCHIQ_SUCCESS;
  27601. +}
  27602. +
  27603. +VCHIQ_STATUS_T
  27604. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  27605. + VCHIQ_SERVICE_OPTION_T option, int value)
  27606. +{
  27607. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27608. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27609. +
  27610. + if (service) {
  27611. + switch (option) {
  27612. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  27613. + service->auto_close = value;
  27614. + status = VCHIQ_SUCCESS;
  27615. + break;
  27616. +
  27617. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  27618. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27619. + &service->state->service_quotas[
  27620. + service->localport];
  27621. + if (value == 0)
  27622. + value = service->state->default_slot_quota;
  27623. + if ((value >= service_quota->slot_use_count) &&
  27624. + (value < (unsigned short)~0)) {
  27625. + service_quota->slot_quota = value;
  27626. + if ((value >= service_quota->slot_use_count) &&
  27627. + (service_quota->message_quota >=
  27628. + service_quota->message_use_count)) {
  27629. + /* Signal the service that it may have
  27630. + ** dropped below its quota */
  27631. + up(&service_quota->quota_event);
  27632. + }
  27633. + status = VCHIQ_SUCCESS;
  27634. + }
  27635. + } break;
  27636. +
  27637. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  27638. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27639. + &service->state->service_quotas[
  27640. + service->localport];
  27641. + if (value == 0)
  27642. + value = service->state->default_message_quota;
  27643. + if ((value >= service_quota->message_use_count) &&
  27644. + (value < (unsigned short)~0)) {
  27645. + service_quota->message_quota = value;
  27646. + if ((value >=
  27647. + service_quota->message_use_count) &&
  27648. + (service_quota->slot_quota >=
  27649. + service_quota->slot_use_count))
  27650. + /* Signal the service that it may have
  27651. + ** dropped below its quota */
  27652. + up(&service_quota->quota_event);
  27653. + status = VCHIQ_SUCCESS;
  27654. + }
  27655. + } break;
  27656. +
  27657. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  27658. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  27659. + (service->srvstate ==
  27660. + VCHIQ_SRVSTATE_LISTENING)) {
  27661. + service->sync = value;
  27662. + status = VCHIQ_SUCCESS;
  27663. + }
  27664. + break;
  27665. +
  27666. + default:
  27667. + break;
  27668. + }
  27669. + unlock_service(service);
  27670. + }
  27671. +
  27672. + return status;
  27673. +}
  27674. +
  27675. +void
  27676. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  27677. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  27678. +{
  27679. + static const char *const debug_names[] = {
  27680. + "<entries>",
  27681. + "SLOT_HANDLER_COUNT",
  27682. + "SLOT_HANDLER_LINE",
  27683. + "PARSE_LINE",
  27684. + "PARSE_HEADER",
  27685. + "PARSE_MSGID",
  27686. + "AWAIT_COMPLETION_LINE",
  27687. + "DEQUEUE_MESSAGE_LINE",
  27688. + "SERVICE_CALLBACK_LINE",
  27689. + "MSG_QUEUE_FULL_COUNT",
  27690. + "COMPLETION_QUEUE_FULL_COUNT"
  27691. + };
  27692. + int i;
  27693. +
  27694. + char buf[80];
  27695. + int len;
  27696. + len = snprintf(buf, sizeof(buf),
  27697. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  27698. + label, shared->slot_first, shared->slot_last,
  27699. + shared->tx_pos, shared->slot_queue_recycle);
  27700. + vchiq_dump(dump_context, buf, len + 1);
  27701. +
  27702. + len = snprintf(buf, sizeof(buf),
  27703. + " Slots claimed:");
  27704. + vchiq_dump(dump_context, buf, len + 1);
  27705. +
  27706. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  27707. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  27708. + if (slot_info.use_count != slot_info.release_count) {
  27709. + len = snprintf(buf, sizeof(buf),
  27710. + " %d: %d/%d", i, slot_info.use_count,
  27711. + slot_info.release_count);
  27712. + vchiq_dump(dump_context, buf, len + 1);
  27713. + }
  27714. + }
  27715. +
  27716. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  27717. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  27718. + debug_names[i], shared->debug[i], shared->debug[i]);
  27719. + vchiq_dump(dump_context, buf, len + 1);
  27720. + }
  27721. +}
  27722. +
  27723. +void
  27724. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  27725. +{
  27726. + char buf[80];
  27727. + int len;
  27728. + int i;
  27729. +
  27730. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  27731. + conn_state_names[state->conn_state]);
  27732. + vchiq_dump(dump_context, buf, len + 1);
  27733. +
  27734. + len = snprintf(buf, sizeof(buf),
  27735. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  27736. + state->local->tx_pos,
  27737. + (uint32_t)state->tx_data +
  27738. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  27739. + state->rx_pos,
  27740. + (uint32_t)state->rx_data +
  27741. + (state->rx_pos & VCHIQ_SLOT_MASK));
  27742. + vchiq_dump(dump_context, buf, len + 1);
  27743. +
  27744. + len = snprintf(buf, sizeof(buf),
  27745. + " Version: %d (min %d)",
  27746. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  27747. + vchiq_dump(dump_context, buf, len + 1);
  27748. +
  27749. + if (VCHIQ_ENABLE_STATS) {
  27750. + len = snprintf(buf, sizeof(buf),
  27751. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  27752. + "error_count=%d",
  27753. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  27754. + state->stats.error_count);
  27755. + vchiq_dump(dump_context, buf, len + 1);
  27756. + }
  27757. +
  27758. + len = snprintf(buf, sizeof(buf),
  27759. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  27760. + "(%d data)",
  27761. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  27762. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  27763. + state->data_quota - state->data_use_count,
  27764. + state->local->slot_queue_recycle - state->slot_queue_available,
  27765. + state->stats.slot_stalls, state->stats.data_stalls);
  27766. + vchiq_dump(dump_context, buf, len + 1);
  27767. +
  27768. + vchiq_dump_platform_state(dump_context);
  27769. +
  27770. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  27771. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  27772. +
  27773. + vchiq_dump_platform_instances(dump_context);
  27774. +
  27775. + for (i = 0; i < state->unused_service; i++) {
  27776. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  27777. +
  27778. + if (service) {
  27779. + vchiq_dump_service_state(dump_context, service);
  27780. + unlock_service(service);
  27781. + }
  27782. + }
  27783. +}
  27784. +
  27785. +void
  27786. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  27787. +{
  27788. + char buf[80];
  27789. + int len;
  27790. +
  27791. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  27792. + service->localport, srvstate_names[service->srvstate],
  27793. + service->ref_count - 1); /*Don't include the lock just taken*/
  27794. +
  27795. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  27796. + char remoteport[30];
  27797. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27798. + &service->state->service_quotas[service->localport];
  27799. + int fourcc = service->base.fourcc;
  27800. + int tx_pending, rx_pending;
  27801. + if (service->remoteport != VCHIQ_PORT_FREE) {
  27802. + int len2 = snprintf(remoteport, sizeof(remoteport),
  27803. + "%d", service->remoteport);
  27804. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  27805. + snprintf(remoteport + len2,
  27806. + sizeof(remoteport) - len2,
  27807. + " (client %x)", service->client_id);
  27808. + } else
  27809. + strcpy(remoteport, "n/a");
  27810. +
  27811. + len += snprintf(buf + len, sizeof(buf) - len,
  27812. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  27813. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  27814. + remoteport,
  27815. + service_quota->message_use_count,
  27816. + service_quota->message_quota,
  27817. + service_quota->slot_use_count,
  27818. + service_quota->slot_quota);
  27819. +
  27820. + vchiq_dump(dump_context, buf, len + 1);
  27821. +
  27822. + tx_pending = service->bulk_tx.local_insert -
  27823. + service->bulk_tx.remote_insert;
  27824. +
  27825. + rx_pending = service->bulk_rx.local_insert -
  27826. + service->bulk_rx.remote_insert;
  27827. +
  27828. + len = snprintf(buf, sizeof(buf),
  27829. + " Bulk: tx_pending=%d (size %d),"
  27830. + " rx_pending=%d (size %d)",
  27831. + tx_pending,
  27832. + tx_pending ? service->bulk_tx.bulks[
  27833. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  27834. + rx_pending,
  27835. + rx_pending ? service->bulk_rx.bulks[
  27836. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  27837. +
  27838. + if (VCHIQ_ENABLE_STATS) {
  27839. + vchiq_dump(dump_context, buf, len + 1);
  27840. +
  27841. + len = snprintf(buf, sizeof(buf),
  27842. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  27843. + "rx_count=%d, rx_bytes=%llu",
  27844. + service->stats.ctrl_tx_count,
  27845. + service->stats.ctrl_tx_bytes,
  27846. + service->stats.ctrl_rx_count,
  27847. + service->stats.ctrl_rx_bytes);
  27848. + vchiq_dump(dump_context, buf, len + 1);
  27849. +
  27850. + len = snprintf(buf, sizeof(buf),
  27851. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  27852. + "rx_count=%d, rx_bytes=%llu",
  27853. + service->stats.bulk_tx_count,
  27854. + service->stats.bulk_tx_bytes,
  27855. + service->stats.bulk_rx_count,
  27856. + service->stats.bulk_rx_bytes);
  27857. + vchiq_dump(dump_context, buf, len + 1);
  27858. +
  27859. + len = snprintf(buf, sizeof(buf),
  27860. + " %d quota stalls, %d slot stalls, "
  27861. + "%d bulk stalls, %d aborted, %d errors",
  27862. + service->stats.quota_stalls,
  27863. + service->stats.slot_stalls,
  27864. + service->stats.bulk_stalls,
  27865. + service->stats.bulk_aborted_count,
  27866. + service->stats.error_count);
  27867. + }
  27868. + }
  27869. +
  27870. + vchiq_dump(dump_context, buf, len + 1);
  27871. +
  27872. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  27873. + vchiq_dump_platform_service_state(dump_context, service);
  27874. +}
  27875. +
  27876. +
  27877. +void
  27878. +vchiq_loud_error_header(void)
  27879. +{
  27880. + vchiq_log_error(vchiq_core_log_level,
  27881. + "============================================================"
  27882. + "================");
  27883. + vchiq_log_error(vchiq_core_log_level,
  27884. + "============================================================"
  27885. + "================");
  27886. + vchiq_log_error(vchiq_core_log_level, "=====");
  27887. +}
  27888. +
  27889. +void
  27890. +vchiq_loud_error_footer(void)
  27891. +{
  27892. + vchiq_log_error(vchiq_core_log_level, "=====");
  27893. + vchiq_log_error(vchiq_core_log_level,
  27894. + "============================================================"
  27895. + "================");
  27896. + vchiq_log_error(vchiq_core_log_level,
  27897. + "============================================================"
  27898. + "================");
  27899. +}
  27900. +
  27901. +
  27902. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  27903. +{
  27904. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27905. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27906. + status = queue_message(state, NULL,
  27907. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  27908. + NULL, 0, 0, 0);
  27909. + return status;
  27910. +}
  27911. +
  27912. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  27913. +{
  27914. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27915. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27916. + status = queue_message(state, NULL,
  27917. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  27918. + NULL, 0, 0, 0);
  27919. + return status;
  27920. +}
  27921. +
  27922. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  27923. +{
  27924. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27925. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27926. + status = queue_message(state, NULL,
  27927. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  27928. + NULL, 0, 0, 0);
  27929. + return status;
  27930. +}
  27931. +
  27932. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  27933. + size_t numBytes)
  27934. +{
  27935. + const uint8_t *mem = (const uint8_t *)voidMem;
  27936. + size_t offset;
  27937. + char lineBuf[100];
  27938. + char *s;
  27939. +
  27940. + while (numBytes > 0) {
  27941. + s = lineBuf;
  27942. +
  27943. + for (offset = 0; offset < 16; offset++) {
  27944. + if (offset < numBytes)
  27945. + s += snprintf(s, 4, "%02x ", mem[offset]);
  27946. + else
  27947. + s += snprintf(s, 4, " ");
  27948. + }
  27949. +
  27950. + for (offset = 0; offset < 16; offset++) {
  27951. + if (offset < numBytes) {
  27952. + uint8_t ch = mem[offset];
  27953. +
  27954. + if ((ch < ' ') || (ch > '~'))
  27955. + ch = '.';
  27956. + *s++ = (char)ch;
  27957. + }
  27958. + }
  27959. + *s++ = '\0';
  27960. +
  27961. + if ((label != NULL) && (*label != '\0'))
  27962. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27963. + "%s: %08x: %s", label, addr, lineBuf);
  27964. + else
  27965. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27966. + "%08x: %s", addr, lineBuf);
  27967. +
  27968. + addr += 16;
  27969. + mem += 16;
  27970. + if (numBytes > 16)
  27971. + numBytes -= 16;
  27972. + else
  27973. + numBytes = 0;
  27974. + }
  27975. +}
  27976. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  27977. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  27978. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-03-13 12:46:20.600060074 +0100
  27979. @@ -0,0 +1,706 @@
  27980. +/**
  27981. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27982. + *
  27983. + * Redistribution and use in source and binary forms, with or without
  27984. + * modification, are permitted provided that the following conditions
  27985. + * are met:
  27986. + * 1. Redistributions of source code must retain the above copyright
  27987. + * notice, this list of conditions, and the following disclaimer,
  27988. + * without modification.
  27989. + * 2. Redistributions in binary form must reproduce the above copyright
  27990. + * notice, this list of conditions and the following disclaimer in the
  27991. + * documentation and/or other materials provided with the distribution.
  27992. + * 3. The names of the above-listed copyright holders may not be used
  27993. + * to endorse or promote products derived from this software without
  27994. + * specific prior written permission.
  27995. + *
  27996. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27997. + * GNU General Public License ("GPL") version 2, as published by the Free
  27998. + * Software Foundation.
  27999. + *
  28000. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28001. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28002. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28003. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28004. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28005. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28006. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28007. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28008. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28009. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28010. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28011. + */
  28012. +
  28013. +#ifndef VCHIQ_CORE_H
  28014. +#define VCHIQ_CORE_H
  28015. +
  28016. +#include <linux/mutex.h>
  28017. +#include <linux/semaphore.h>
  28018. +#include <linux/kthread.h>
  28019. +
  28020. +#include "vchiq_cfg.h"
  28021. +
  28022. +#include "vchiq.h"
  28023. +
  28024. +/* Run time control of log level, based on KERN_XXX level. */
  28025. +#define VCHIQ_LOG_DEFAULT 4
  28026. +#define VCHIQ_LOG_ERROR 3
  28027. +#define VCHIQ_LOG_WARNING 4
  28028. +#define VCHIQ_LOG_INFO 6
  28029. +#define VCHIQ_LOG_TRACE 7
  28030. +
  28031. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  28032. +
  28033. +#ifndef vchiq_log_error
  28034. +#define vchiq_log_error(cat, fmt, ...) \
  28035. + do { if (cat >= VCHIQ_LOG_ERROR) \
  28036. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28037. +#endif
  28038. +#ifndef vchiq_log_warning
  28039. +#define vchiq_log_warning(cat, fmt, ...) \
  28040. + do { if (cat >= VCHIQ_LOG_WARNING) \
  28041. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28042. +#endif
  28043. +#ifndef vchiq_log_info
  28044. +#define vchiq_log_info(cat, fmt, ...) \
  28045. + do { if (cat >= VCHIQ_LOG_INFO) \
  28046. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28047. +#endif
  28048. +#ifndef vchiq_log_trace
  28049. +#define vchiq_log_trace(cat, fmt, ...) \
  28050. + do { if (cat >= VCHIQ_LOG_TRACE) \
  28051. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28052. +#endif
  28053. +
  28054. +#define vchiq_loud_error(...) \
  28055. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  28056. +
  28057. +#ifndef vchiq_static_assert
  28058. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  28059. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  28060. +#endif
  28061. +
  28062. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  28063. +
  28064. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  28065. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  28066. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  28067. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  28068. +
  28069. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  28070. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  28071. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  28072. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  28073. +
  28074. +#define VCHIQ_MSG_PADDING 0 /* - */
  28075. +#define VCHIQ_MSG_CONNECT 1 /* - */
  28076. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  28077. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  28078. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  28079. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  28080. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  28081. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  28082. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  28083. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  28084. +#define VCHIQ_MSG_PAUSE 10 /* - */
  28085. +#define VCHIQ_MSG_RESUME 11 /* - */
  28086. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  28087. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  28088. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  28089. +
  28090. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  28091. +#define VCHIQ_PORT_FREE 0x1000
  28092. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  28093. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  28094. + ((type<<24) | (srcport<<12) | (dstport<<0))
  28095. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  28096. +#define VCHIQ_MSG_SRCPORT(msgid) \
  28097. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  28098. +#define VCHIQ_MSG_DSTPORT(msgid) \
  28099. + ((unsigned short)msgid & 0xfff)
  28100. +
  28101. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  28102. + ((fourcc) >> 24) & 0xff, \
  28103. + ((fourcc) >> 16) & 0xff, \
  28104. + ((fourcc) >> 8) & 0xff, \
  28105. + (fourcc) & 0xff
  28106. +
  28107. +/* Ensure the fields are wide enough */
  28108. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  28109. + == 0);
  28110. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  28111. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  28112. + (unsigned int)VCHIQ_PORT_FREE);
  28113. +
  28114. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  28115. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  28116. +
  28117. +#define VCHIQ_FOURCC_INVALID 0x00000000
  28118. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  28119. +
  28120. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  28121. +
  28122. +typedef uint32_t BITSET_T;
  28123. +
  28124. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  28125. +
  28126. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  28127. +#define BITSET_WORD(b) (b >> 5)
  28128. +#define BITSET_BIT(b) (1 << (b & 31))
  28129. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  28130. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  28131. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  28132. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  28133. +
  28134. +#if VCHIQ_ENABLE_STATS
  28135. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  28136. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  28137. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  28138. + (service->stats. stat += addend)
  28139. +#else
  28140. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  28141. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  28142. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  28143. +#endif
  28144. +
  28145. +enum {
  28146. + DEBUG_ENTRIES,
  28147. +#if VCHIQ_ENABLE_DEBUG
  28148. + DEBUG_SLOT_HANDLER_COUNT,
  28149. + DEBUG_SLOT_HANDLER_LINE,
  28150. + DEBUG_PARSE_LINE,
  28151. + DEBUG_PARSE_HEADER,
  28152. + DEBUG_PARSE_MSGID,
  28153. + DEBUG_AWAIT_COMPLETION_LINE,
  28154. + DEBUG_DEQUEUE_MESSAGE_LINE,
  28155. + DEBUG_SERVICE_CALLBACK_LINE,
  28156. + DEBUG_MSG_QUEUE_FULL_COUNT,
  28157. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  28158. +#endif
  28159. + DEBUG_MAX
  28160. +};
  28161. +
  28162. +#if VCHIQ_ENABLE_DEBUG
  28163. +
  28164. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  28165. +#define DEBUG_TRACE(d) \
  28166. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  28167. +#define DEBUG_VALUE(d, v) \
  28168. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  28169. +#define DEBUG_COUNT(d) \
  28170. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  28171. +
  28172. +#else /* VCHIQ_ENABLE_DEBUG */
  28173. +
  28174. +#define DEBUG_INITIALISE(local)
  28175. +#define DEBUG_TRACE(d)
  28176. +#define DEBUG_VALUE(d, v)
  28177. +#define DEBUG_COUNT(d)
  28178. +
  28179. +#endif /* VCHIQ_ENABLE_DEBUG */
  28180. +
  28181. +typedef enum {
  28182. + VCHIQ_CONNSTATE_DISCONNECTED,
  28183. + VCHIQ_CONNSTATE_CONNECTING,
  28184. + VCHIQ_CONNSTATE_CONNECTED,
  28185. + VCHIQ_CONNSTATE_PAUSING,
  28186. + VCHIQ_CONNSTATE_PAUSE_SENT,
  28187. + VCHIQ_CONNSTATE_PAUSED,
  28188. + VCHIQ_CONNSTATE_RESUMING,
  28189. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  28190. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  28191. +} VCHIQ_CONNSTATE_T;
  28192. +
  28193. +enum {
  28194. + VCHIQ_SRVSTATE_FREE,
  28195. + VCHIQ_SRVSTATE_HIDDEN,
  28196. + VCHIQ_SRVSTATE_LISTENING,
  28197. + VCHIQ_SRVSTATE_OPENING,
  28198. + VCHIQ_SRVSTATE_OPEN,
  28199. + VCHIQ_SRVSTATE_OPENSYNC,
  28200. + VCHIQ_SRVSTATE_CLOSESENT,
  28201. + VCHIQ_SRVSTATE_CLOSERECVD,
  28202. + VCHIQ_SRVSTATE_CLOSEWAIT,
  28203. + VCHIQ_SRVSTATE_CLOSED
  28204. +};
  28205. +
  28206. +enum {
  28207. + VCHIQ_POLL_TERMINATE,
  28208. + VCHIQ_POLL_REMOVE,
  28209. + VCHIQ_POLL_TXNOTIFY,
  28210. + VCHIQ_POLL_RXNOTIFY,
  28211. + VCHIQ_POLL_COUNT
  28212. +};
  28213. +
  28214. +typedef enum {
  28215. + VCHIQ_BULK_TRANSMIT,
  28216. + VCHIQ_BULK_RECEIVE
  28217. +} VCHIQ_BULK_DIR_T;
  28218. +
  28219. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  28220. +
  28221. +typedef struct vchiq_bulk_struct {
  28222. + short mode;
  28223. + short dir;
  28224. + void *userdata;
  28225. + VCHI_MEM_HANDLE_T handle;
  28226. + void *data;
  28227. + int size;
  28228. + void *remote_data;
  28229. + int remote_size;
  28230. + int actual;
  28231. +} VCHIQ_BULK_T;
  28232. +
  28233. +typedef struct vchiq_bulk_queue_struct {
  28234. + int local_insert; /* Where to insert the next local bulk */
  28235. + int remote_insert; /* Where to insert the next remote bulk (master) */
  28236. + int process; /* Bulk to transfer next */
  28237. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  28238. + int remove; /* Bulk to notify the local client of, and remove,
  28239. + ** next */
  28240. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  28241. +} VCHIQ_BULK_QUEUE_T;
  28242. +
  28243. +typedef struct remote_event_struct {
  28244. + int armed;
  28245. + int fired;
  28246. + struct semaphore *event;
  28247. +} REMOTE_EVENT_T;
  28248. +
  28249. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  28250. +
  28251. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  28252. +
  28253. +typedef struct vchiq_slot_struct {
  28254. + char data[VCHIQ_SLOT_SIZE];
  28255. +} VCHIQ_SLOT_T;
  28256. +
  28257. +typedef struct vchiq_slot_info_struct {
  28258. + /* Use two counters rather than one to avoid the need for a mutex. */
  28259. + short use_count;
  28260. + short release_count;
  28261. +} VCHIQ_SLOT_INFO_T;
  28262. +
  28263. +typedef struct vchiq_service_struct {
  28264. + VCHIQ_SERVICE_BASE_T base;
  28265. + VCHIQ_SERVICE_HANDLE_T handle;
  28266. + unsigned int ref_count;
  28267. + int srvstate;
  28268. + VCHIQ_USERDATA_TERM_T userdata_term;
  28269. + unsigned int localport;
  28270. + unsigned int remoteport;
  28271. + int public_fourcc;
  28272. + int client_id;
  28273. + char auto_close;
  28274. + char sync;
  28275. + char closing;
  28276. + atomic_t poll_flags;
  28277. + short version;
  28278. + short version_min;
  28279. + short peer_version;
  28280. +
  28281. + VCHIQ_STATE_T *state;
  28282. + VCHIQ_INSTANCE_T instance;
  28283. +
  28284. + int service_use_count;
  28285. +
  28286. + VCHIQ_BULK_QUEUE_T bulk_tx;
  28287. + VCHIQ_BULK_QUEUE_T bulk_rx;
  28288. +
  28289. + struct semaphore remove_event;
  28290. + struct semaphore bulk_remove_event;
  28291. + struct mutex bulk_mutex;
  28292. +
  28293. + struct service_stats_struct {
  28294. + int quota_stalls;
  28295. + int slot_stalls;
  28296. + int bulk_stalls;
  28297. + int error_count;
  28298. + int ctrl_tx_count;
  28299. + int ctrl_rx_count;
  28300. + int bulk_tx_count;
  28301. + int bulk_rx_count;
  28302. + int bulk_aborted_count;
  28303. + uint64_t ctrl_tx_bytes;
  28304. + uint64_t ctrl_rx_bytes;
  28305. + uint64_t bulk_tx_bytes;
  28306. + uint64_t bulk_rx_bytes;
  28307. + } stats;
  28308. +} VCHIQ_SERVICE_T;
  28309. +
  28310. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  28311. + statically allocated, since for accounting reasons a service's slot
  28312. + usage is carried over between users of the same port number.
  28313. + */
  28314. +typedef struct vchiq_service_quota_struct {
  28315. + unsigned short slot_quota;
  28316. + unsigned short slot_use_count;
  28317. + unsigned short message_quota;
  28318. + unsigned short message_use_count;
  28319. + struct semaphore quota_event;
  28320. + int previous_tx_index;
  28321. +} VCHIQ_SERVICE_QUOTA_T;
  28322. +
  28323. +typedef struct vchiq_shared_state_struct {
  28324. +
  28325. + /* A non-zero value here indicates that the content is valid. */
  28326. + int initialised;
  28327. +
  28328. + /* The first and last (inclusive) slots allocated to the owner. */
  28329. + int slot_first;
  28330. + int slot_last;
  28331. +
  28332. + /* The slot allocated to synchronous messages from the owner. */
  28333. + int slot_sync;
  28334. +
  28335. + /* Signalling this event indicates that owner's slot handler thread
  28336. + ** should run. */
  28337. + REMOTE_EVENT_T trigger;
  28338. +
  28339. + /* Indicates the byte position within the stream where the next message
  28340. + ** will be written. The least significant bits are an index into the
  28341. + ** slot. The next bits are the index of the slot in slot_queue. */
  28342. + int tx_pos;
  28343. +
  28344. + /* This event should be signalled when a slot is recycled. */
  28345. + REMOTE_EVENT_T recycle;
  28346. +
  28347. + /* The slot_queue index where the next recycled slot will be written. */
  28348. + int slot_queue_recycle;
  28349. +
  28350. + /* This event should be signalled when a synchronous message is sent. */
  28351. + REMOTE_EVENT_T sync_trigger;
  28352. +
  28353. + /* This event should be signalled when a synchronous message has been
  28354. + ** released. */
  28355. + REMOTE_EVENT_T sync_release;
  28356. +
  28357. + /* A circular buffer of slot indexes. */
  28358. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  28359. +
  28360. + /* Debugging state */
  28361. + int debug[DEBUG_MAX];
  28362. +} VCHIQ_SHARED_STATE_T;
  28363. +
  28364. +typedef struct vchiq_slot_zero_struct {
  28365. + int magic;
  28366. + short version;
  28367. + short version_min;
  28368. + int slot_zero_size;
  28369. + int slot_size;
  28370. + int max_slots;
  28371. + int max_slots_per_side;
  28372. + int platform_data[2];
  28373. + VCHIQ_SHARED_STATE_T master;
  28374. + VCHIQ_SHARED_STATE_T slave;
  28375. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  28376. +} VCHIQ_SLOT_ZERO_T;
  28377. +
  28378. +struct vchiq_state_struct {
  28379. + int id;
  28380. + int initialised;
  28381. + VCHIQ_CONNSTATE_T conn_state;
  28382. + int is_master;
  28383. +
  28384. + VCHIQ_SHARED_STATE_T *local;
  28385. + VCHIQ_SHARED_STATE_T *remote;
  28386. + VCHIQ_SLOT_T *slot_data;
  28387. +
  28388. + unsigned short default_slot_quota;
  28389. + unsigned short default_message_quota;
  28390. +
  28391. + /* Event indicating connect message received */
  28392. + struct semaphore connect;
  28393. +
  28394. + /* Mutex protecting services */
  28395. + struct mutex mutex;
  28396. + VCHIQ_INSTANCE_T *instance;
  28397. +
  28398. + /* Processes incoming messages */
  28399. + struct task_struct *slot_handler_thread;
  28400. +
  28401. + /* Processes recycled slots */
  28402. + struct task_struct *recycle_thread;
  28403. +
  28404. + /* Processes synchronous messages */
  28405. + struct task_struct *sync_thread;
  28406. +
  28407. + /* Local implementation of the trigger remote event */
  28408. + struct semaphore trigger_event;
  28409. +
  28410. + /* Local implementation of the recycle remote event */
  28411. + struct semaphore recycle_event;
  28412. +
  28413. + /* Local implementation of the sync trigger remote event */
  28414. + struct semaphore sync_trigger_event;
  28415. +
  28416. + /* Local implementation of the sync release remote event */
  28417. + struct semaphore sync_release_event;
  28418. +
  28419. + char *tx_data;
  28420. + char *rx_data;
  28421. + VCHIQ_SLOT_INFO_T *rx_info;
  28422. +
  28423. + struct mutex slot_mutex;
  28424. +
  28425. + struct mutex recycle_mutex;
  28426. +
  28427. + struct mutex sync_mutex;
  28428. +
  28429. + struct mutex bulk_transfer_mutex;
  28430. +
  28431. + /* Indicates the byte position within the stream from where the next
  28432. + ** message will be read. The least significant bits are an index into
  28433. + ** the slot.The next bits are the index of the slot in
  28434. + ** remote->slot_queue. */
  28435. + int rx_pos;
  28436. +
  28437. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  28438. + from remote->tx_pos. */
  28439. + int local_tx_pos;
  28440. +
  28441. + /* The slot_queue index of the slot to become available next. */
  28442. + int slot_queue_available;
  28443. +
  28444. + /* A flag to indicate if any poll has been requested */
  28445. + int poll_needed;
  28446. +
  28447. + /* Ths index of the previous slot used for data messages. */
  28448. + int previous_data_index;
  28449. +
  28450. + /* The number of slots occupied by data messages. */
  28451. + unsigned short data_use_count;
  28452. +
  28453. + /* The maximum number of slots to be occupied by data messages. */
  28454. + unsigned short data_quota;
  28455. +
  28456. + /* An array of bit sets indicating which services must be polled. */
  28457. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  28458. +
  28459. + /* The number of the first unused service */
  28460. + int unused_service;
  28461. +
  28462. + /* Signalled when a free slot becomes available. */
  28463. + struct semaphore slot_available_event;
  28464. +
  28465. + struct semaphore slot_remove_event;
  28466. +
  28467. + /* Signalled when a free data slot becomes available. */
  28468. + struct semaphore data_quota_event;
  28469. +
  28470. + /* Incremented when there are bulk transfers which cannot be processed
  28471. + * whilst paused and must be processed on resume */
  28472. + int deferred_bulks;
  28473. +
  28474. + struct state_stats_struct {
  28475. + int slot_stalls;
  28476. + int data_stalls;
  28477. + int ctrl_tx_count;
  28478. + int ctrl_rx_count;
  28479. + int error_count;
  28480. + } stats;
  28481. +
  28482. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  28483. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  28484. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  28485. +
  28486. + VCHIQ_PLATFORM_STATE_T platform_state;
  28487. +};
  28488. +
  28489. +struct bulk_waiter {
  28490. + VCHIQ_BULK_T *bulk;
  28491. + struct semaphore event;
  28492. + int actual;
  28493. +};
  28494. +
  28495. +extern spinlock_t bulk_waiter_spinlock;
  28496. +
  28497. +extern int vchiq_core_log_level;
  28498. +extern int vchiq_core_msg_log_level;
  28499. +extern int vchiq_sync_log_level;
  28500. +
  28501. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  28502. +
  28503. +extern const char *
  28504. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  28505. +
  28506. +extern VCHIQ_SLOT_ZERO_T *
  28507. +vchiq_init_slots(void *mem_base, int mem_size);
  28508. +
  28509. +extern VCHIQ_STATUS_T
  28510. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  28511. + int is_master);
  28512. +
  28513. +extern VCHIQ_STATUS_T
  28514. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  28515. +
  28516. +extern VCHIQ_SERVICE_T *
  28517. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  28518. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  28519. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  28520. +
  28521. +extern VCHIQ_STATUS_T
  28522. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  28523. +
  28524. +extern VCHIQ_STATUS_T
  28525. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  28526. +
  28527. +extern void
  28528. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  28529. +
  28530. +extern void
  28531. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  28532. +
  28533. +extern VCHIQ_STATUS_T
  28534. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  28535. +
  28536. +extern VCHIQ_STATUS_T
  28537. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  28538. +
  28539. +extern VCHIQ_STATUS_T
  28540. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  28541. +
  28542. +extern void
  28543. +remote_event_pollall(VCHIQ_STATE_T *state);
  28544. +
  28545. +extern VCHIQ_STATUS_T
  28546. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  28547. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  28548. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  28549. +
  28550. +extern void
  28551. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  28552. +
  28553. +extern void
  28554. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  28555. +
  28556. +extern void
  28557. +vchiq_loud_error_header(void);
  28558. +
  28559. +extern void
  28560. +vchiq_loud_error_footer(void);
  28561. +
  28562. +extern void
  28563. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  28564. +
  28565. +static inline VCHIQ_SERVICE_T *
  28566. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  28567. +{
  28568. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  28569. + (VCHIQ_MAX_STATES - 1)];
  28570. + if (!state)
  28571. + return NULL;
  28572. +
  28573. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  28574. +}
  28575. +
  28576. +extern VCHIQ_SERVICE_T *
  28577. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  28578. +
  28579. +extern VCHIQ_SERVICE_T *
  28580. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  28581. +
  28582. +extern VCHIQ_SERVICE_T *
  28583. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  28584. + VCHIQ_SERVICE_HANDLE_T handle);
  28585. +
  28586. +extern VCHIQ_SERVICE_T *
  28587. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  28588. + int *pidx);
  28589. +
  28590. +extern void
  28591. +lock_service(VCHIQ_SERVICE_T *service);
  28592. +
  28593. +extern void
  28594. +unlock_service(VCHIQ_SERVICE_T *service);
  28595. +
  28596. +/* The following functions are called from vchiq_core, and external
  28597. +** implementations must be provided. */
  28598. +
  28599. +extern VCHIQ_STATUS_T
  28600. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  28601. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  28602. +
  28603. +extern void
  28604. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  28605. +
  28606. +extern void
  28607. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  28608. +
  28609. +extern VCHIQ_STATUS_T
  28610. +vchiq_copy_from_user(void *dst, const void *src, int size);
  28611. +
  28612. +extern void
  28613. +remote_event_signal(REMOTE_EVENT_T *event);
  28614. +
  28615. +void
  28616. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  28617. +
  28618. +extern void
  28619. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  28620. +
  28621. +extern VCHIQ_STATUS_T
  28622. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  28623. +
  28624. +extern void
  28625. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  28626. +
  28627. +extern void
  28628. +vchiq_dump(void *dump_context, const char *str, int len);
  28629. +
  28630. +extern void
  28631. +vchiq_dump_platform_state(void *dump_context);
  28632. +
  28633. +extern void
  28634. +vchiq_dump_platform_instances(void *dump_context);
  28635. +
  28636. +extern void
  28637. +vchiq_dump_platform_service_state(void *dump_context,
  28638. + VCHIQ_SERVICE_T *service);
  28639. +
  28640. +extern VCHIQ_STATUS_T
  28641. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  28642. +
  28643. +extern VCHIQ_STATUS_T
  28644. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  28645. +
  28646. +extern void
  28647. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  28648. +
  28649. +extern void
  28650. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  28651. +
  28652. +extern VCHIQ_STATUS_T
  28653. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  28654. +
  28655. +extern VCHIQ_STATUS_T
  28656. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  28657. +
  28658. +extern void
  28659. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  28660. +
  28661. +extern VCHIQ_STATUS_T
  28662. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  28663. +
  28664. +extern VCHIQ_STATUS_T
  28665. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  28666. +
  28667. +extern VCHIQ_STATUS_T
  28668. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  28669. +
  28670. +extern void
  28671. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  28672. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  28673. +
  28674. +extern void
  28675. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  28676. +
  28677. +extern void
  28678. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  28679. +
  28680. +
  28681. +extern void
  28682. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  28683. + size_t numBytes);
  28684. +
  28685. +#endif
  28686. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  28687. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  28688. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-03-13 12:46:20.600060074 +0100
  28689. @@ -0,0 +1,89 @@
  28690. +#!/usr/bin/perl -w
  28691. +
  28692. +use strict;
  28693. +
  28694. +#
  28695. +# Generate a version from available information
  28696. +#
  28697. +
  28698. +my $prefix = shift @ARGV;
  28699. +my $root = shift @ARGV;
  28700. +
  28701. +
  28702. +if ( not defined $root ) {
  28703. + die "usage: $0 prefix root-dir\n";
  28704. +}
  28705. +
  28706. +if ( ! -d $root ) {
  28707. + die "root directory $root not found\n";
  28708. +}
  28709. +
  28710. +my $version = "unknown";
  28711. +my $tainted = "";
  28712. +
  28713. +if ( -d "$root/.git" ) {
  28714. + # attempt to work out git version. only do so
  28715. + # on a linux build host, as cygwin builds are
  28716. + # already slow enough
  28717. +
  28718. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  28719. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  28720. + $version = "no git version";
  28721. + }
  28722. + else {
  28723. + $version = <F>;
  28724. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28725. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28726. + }
  28727. +
  28728. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  28729. + $tainted = <G>;
  28730. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28731. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28732. + if (length $tainted) {
  28733. + $version = join ' ', $version, "(tainted)";
  28734. + }
  28735. + else {
  28736. + $version = join ' ', $version, "(clean)";
  28737. + }
  28738. + }
  28739. + }
  28740. +}
  28741. +
  28742. +my $hostname = `hostname`;
  28743. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28744. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28745. +
  28746. +
  28747. +print STDERR "Version $version\n";
  28748. +print <<EOF;
  28749. +#include "${prefix}_build_info.h"
  28750. +#include <linux/broadcom/vc_debug_sym.h>
  28751. +
  28752. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  28753. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  28754. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  28755. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  28756. +
  28757. +const char *vchiq_get_build_hostname( void )
  28758. +{
  28759. + return vchiq_build_hostname;
  28760. +}
  28761. +
  28762. +const char *vchiq_get_build_version( void )
  28763. +{
  28764. + return vchiq_build_version;
  28765. +}
  28766. +
  28767. +const char *vchiq_get_build_date( void )
  28768. +{
  28769. + return vchiq_build_date;
  28770. +}
  28771. +
  28772. +const char *vchiq_get_build_time( void )
  28773. +{
  28774. + return vchiq_build_time;
  28775. +}
  28776. +EOF
  28777. +
  28778. +
  28779. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  28780. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  28781. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-03-13 12:46:20.596060066 +0100
  28782. @@ -0,0 +1,41 @@
  28783. +/**
  28784. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28785. + *
  28786. + * Redistribution and use in source and binary forms, with or without
  28787. + * modification, are permitted provided that the following conditions
  28788. + * are met:
  28789. + * 1. Redistributions of source code must retain the above copyright
  28790. + * notice, this list of conditions, and the following disclaimer,
  28791. + * without modification.
  28792. + * 2. Redistributions in binary form must reproduce the above copyright
  28793. + * notice, this list of conditions and the following disclaimer in the
  28794. + * documentation and/or other materials provided with the distribution.
  28795. + * 3. The names of the above-listed copyright holders may not be used
  28796. + * to endorse or promote products derived from this software without
  28797. + * specific prior written permission.
  28798. + *
  28799. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28800. + * GNU General Public License ("GPL") version 2, as published by the Free
  28801. + * Software Foundation.
  28802. + *
  28803. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28804. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28805. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28806. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28807. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28808. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28809. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28810. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28811. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28812. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28813. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28814. + */
  28815. +
  28816. +#ifndef VCHIQ_VCHIQ_H
  28817. +#define VCHIQ_VCHIQ_H
  28818. +
  28819. +#include "vchiq_if.h"
  28820. +#include "vchiq_util.h"
  28821. +
  28822. +#endif
  28823. +
  28824. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  28825. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  28826. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-03-13 12:46:20.600060074 +0100
  28827. @@ -0,0 +1,188 @@
  28828. +/**
  28829. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28830. + *
  28831. + * Redistribution and use in source and binary forms, with or without
  28832. + * modification, are permitted provided that the following conditions
  28833. + * are met:
  28834. + * 1. Redistributions of source code must retain the above copyright
  28835. + * notice, this list of conditions, and the following disclaimer,
  28836. + * without modification.
  28837. + * 2. Redistributions in binary form must reproduce the above copyright
  28838. + * notice, this list of conditions and the following disclaimer in the
  28839. + * documentation and/or other materials provided with the distribution.
  28840. + * 3. The names of the above-listed copyright holders may not be used
  28841. + * to endorse or promote products derived from this software without
  28842. + * specific prior written permission.
  28843. + *
  28844. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28845. + * GNU General Public License ("GPL") version 2, as published by the Free
  28846. + * Software Foundation.
  28847. + *
  28848. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28849. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28850. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28851. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28852. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28853. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28854. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28855. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28856. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28857. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28858. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28859. + */
  28860. +
  28861. +#ifndef VCHIQ_IF_H
  28862. +#define VCHIQ_IF_H
  28863. +
  28864. +#include "interface/vchi/vchi_mh.h"
  28865. +
  28866. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  28867. +
  28868. +#define VCHIQ_SLOT_SIZE 4096
  28869. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  28870. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  28871. +
  28872. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  28873. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  28874. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  28875. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  28876. +
  28877. +typedef enum {
  28878. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  28879. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  28880. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  28881. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  28882. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  28883. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  28884. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  28885. +} VCHIQ_REASON_T;
  28886. +
  28887. +typedef enum {
  28888. + VCHIQ_ERROR = -1,
  28889. + VCHIQ_SUCCESS = 0,
  28890. + VCHIQ_RETRY = 1
  28891. +} VCHIQ_STATUS_T;
  28892. +
  28893. +typedef enum {
  28894. + VCHIQ_BULK_MODE_CALLBACK,
  28895. + VCHIQ_BULK_MODE_BLOCKING,
  28896. + VCHIQ_BULK_MODE_NOCALLBACK,
  28897. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  28898. +} VCHIQ_BULK_MODE_T;
  28899. +
  28900. +typedef enum {
  28901. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  28902. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  28903. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  28904. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  28905. +} VCHIQ_SERVICE_OPTION_T;
  28906. +
  28907. +typedef struct vchiq_header_struct {
  28908. + /* The message identifier - opaque to applications. */
  28909. + int msgid;
  28910. +
  28911. + /* Size of message data. */
  28912. + unsigned int size;
  28913. +
  28914. + char data[0]; /* message */
  28915. +} VCHIQ_HEADER_T;
  28916. +
  28917. +typedef struct {
  28918. + const void *data;
  28919. + unsigned int size;
  28920. +} VCHIQ_ELEMENT_T;
  28921. +
  28922. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  28923. +
  28924. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  28925. + VCHIQ_SERVICE_HANDLE_T, void *);
  28926. +
  28927. +typedef struct vchiq_service_base_struct {
  28928. + int fourcc;
  28929. + VCHIQ_CALLBACK_T callback;
  28930. + void *userdata;
  28931. +} VCHIQ_SERVICE_BASE_T;
  28932. +
  28933. +typedef struct vchiq_service_params_struct {
  28934. + int fourcc;
  28935. + VCHIQ_CALLBACK_T callback;
  28936. + void *userdata;
  28937. + short version; /* Increment for non-trivial changes */
  28938. + short version_min; /* Update for incompatible changes */
  28939. +} VCHIQ_SERVICE_PARAMS_T;
  28940. +
  28941. +typedef struct vchiq_config_struct {
  28942. + unsigned int max_msg_size;
  28943. + unsigned int bulk_threshold; /* The message size above which it
  28944. + is better to use a bulk transfer
  28945. + (<= max_msg_size) */
  28946. + unsigned int max_outstanding_bulks;
  28947. + unsigned int max_services;
  28948. + short version; /* The version of VCHIQ */
  28949. + short version_min; /* The minimum compatible version of VCHIQ */
  28950. +} VCHIQ_CONFIG_T;
  28951. +
  28952. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  28953. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  28954. +
  28955. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  28956. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  28957. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  28958. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  28959. + const VCHIQ_SERVICE_PARAMS_T *params,
  28960. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28961. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  28962. + const VCHIQ_SERVICE_PARAMS_T *params,
  28963. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28964. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  28965. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  28966. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  28967. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  28968. + VCHIQ_SERVICE_HANDLE_T service);
  28969. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  28970. +
  28971. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  28972. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  28973. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  28974. + VCHIQ_HEADER_T *header);
  28975. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28976. + const void *data, unsigned int size, void *userdata);
  28977. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28978. + void *data, unsigned int size, void *userdata);
  28979. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  28980. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28981. + const void *offset, unsigned int size, void *userdata);
  28982. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  28983. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28984. + void *offset, unsigned int size, void *userdata);
  28985. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28986. + const void *data, unsigned int size, void *userdata,
  28987. + VCHIQ_BULK_MODE_T mode);
  28988. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28989. + void *data, unsigned int size, void *userdata,
  28990. + VCHIQ_BULK_MODE_T mode);
  28991. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  28992. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  28993. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28994. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  28995. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  28996. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28997. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  28998. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  28999. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  29000. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  29001. + int config_size, VCHIQ_CONFIG_T *pconfig);
  29002. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  29003. + VCHIQ_SERVICE_OPTION_T option, int value);
  29004. +
  29005. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  29006. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  29007. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  29008. +
  29009. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  29010. + void *ptr, size_t num_bytes);
  29011. +
  29012. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  29013. + short *peer_version);
  29014. +
  29015. +#endif /* VCHIQ_IF_H */
  29016. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  29017. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  29018. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-03-13 12:46:20.600060074 +0100
  29019. @@ -0,0 +1,129 @@
  29020. +/**
  29021. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29022. + *
  29023. + * Redistribution and use in source and binary forms, with or without
  29024. + * modification, are permitted provided that the following conditions
  29025. + * are met:
  29026. + * 1. Redistributions of source code must retain the above copyright
  29027. + * notice, this list of conditions, and the following disclaimer,
  29028. + * without modification.
  29029. + * 2. Redistributions in binary form must reproduce the above copyright
  29030. + * notice, this list of conditions and the following disclaimer in the
  29031. + * documentation and/or other materials provided with the distribution.
  29032. + * 3. The names of the above-listed copyright holders may not be used
  29033. + * to endorse or promote products derived from this software without
  29034. + * specific prior written permission.
  29035. + *
  29036. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29037. + * GNU General Public License ("GPL") version 2, as published by the Free
  29038. + * Software Foundation.
  29039. + *
  29040. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29041. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29042. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29043. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29044. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29045. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29046. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29047. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29048. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29049. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29050. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29051. + */
  29052. +
  29053. +#ifndef VCHIQ_IOCTLS_H
  29054. +#define VCHIQ_IOCTLS_H
  29055. +
  29056. +#include <linux/ioctl.h>
  29057. +#include "vchiq_if.h"
  29058. +
  29059. +#define VCHIQ_IOC_MAGIC 0xc4
  29060. +#define VCHIQ_INVALID_HANDLE (~0)
  29061. +
  29062. +typedef struct {
  29063. + VCHIQ_SERVICE_PARAMS_T params;
  29064. + int is_open;
  29065. + int is_vchi;
  29066. + unsigned int handle; /* OUT */
  29067. +} VCHIQ_CREATE_SERVICE_T;
  29068. +
  29069. +typedef struct {
  29070. + unsigned int handle;
  29071. + unsigned int count;
  29072. + const VCHIQ_ELEMENT_T *elements;
  29073. +} VCHIQ_QUEUE_MESSAGE_T;
  29074. +
  29075. +typedef struct {
  29076. + unsigned int handle;
  29077. + void *data;
  29078. + unsigned int size;
  29079. + void *userdata;
  29080. + VCHIQ_BULK_MODE_T mode;
  29081. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  29082. +
  29083. +typedef struct {
  29084. + VCHIQ_REASON_T reason;
  29085. + VCHIQ_HEADER_T *header;
  29086. + void *service_userdata;
  29087. + void *bulk_userdata;
  29088. +} VCHIQ_COMPLETION_DATA_T;
  29089. +
  29090. +typedef struct {
  29091. + unsigned int count;
  29092. + VCHIQ_COMPLETION_DATA_T *buf;
  29093. + unsigned int msgbufsize;
  29094. + unsigned int msgbufcount; /* IN/OUT */
  29095. + void **msgbufs;
  29096. +} VCHIQ_AWAIT_COMPLETION_T;
  29097. +
  29098. +typedef struct {
  29099. + unsigned int handle;
  29100. + int blocking;
  29101. + unsigned int bufsize;
  29102. + void *buf;
  29103. +} VCHIQ_DEQUEUE_MESSAGE_T;
  29104. +
  29105. +typedef struct {
  29106. + unsigned int config_size;
  29107. + VCHIQ_CONFIG_T *pconfig;
  29108. +} VCHIQ_GET_CONFIG_T;
  29109. +
  29110. +typedef struct {
  29111. + unsigned int handle;
  29112. + VCHIQ_SERVICE_OPTION_T option;
  29113. + int value;
  29114. +} VCHIQ_SET_SERVICE_OPTION_T;
  29115. +
  29116. +typedef struct {
  29117. + void *virt_addr;
  29118. + size_t num_bytes;
  29119. +} VCHIQ_DUMP_MEM_T;
  29120. +
  29121. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  29122. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  29123. +#define VCHIQ_IOC_CREATE_SERVICE \
  29124. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  29125. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  29126. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  29127. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  29128. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  29129. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  29130. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  29131. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  29132. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  29133. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  29134. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  29135. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  29136. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  29137. +#define VCHIQ_IOC_GET_CONFIG \
  29138. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  29139. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  29140. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  29141. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  29142. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  29143. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  29144. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  29145. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  29146. +#define VCHIQ_IOC_MAX 15
  29147. +
  29148. +#endif
  29149. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  29150. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  29151. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-03-13 12:46:20.600060074 +0100
  29152. @@ -0,0 +1,456 @@
  29153. +/**
  29154. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29155. + *
  29156. + * Redistribution and use in source and binary forms, with or without
  29157. + * modification, are permitted provided that the following conditions
  29158. + * are met:
  29159. + * 1. Redistributions of source code must retain the above copyright
  29160. + * notice, this list of conditions, and the following disclaimer,
  29161. + * without modification.
  29162. + * 2. Redistributions in binary form must reproduce the above copyright
  29163. + * notice, this list of conditions and the following disclaimer in the
  29164. + * documentation and/or other materials provided with the distribution.
  29165. + * 3. The names of the above-listed copyright holders may not be used
  29166. + * to endorse or promote products derived from this software without
  29167. + * specific prior written permission.
  29168. + *
  29169. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29170. + * GNU General Public License ("GPL") version 2, as published by the Free
  29171. + * Software Foundation.
  29172. + *
  29173. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29174. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29175. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29176. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29177. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29178. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29179. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29180. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29181. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29182. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29183. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29184. + */
  29185. +
  29186. +/* ---- Include Files ---------------------------------------------------- */
  29187. +
  29188. +#include <linux/kernel.h>
  29189. +#include <linux/module.h>
  29190. +#include <linux/mutex.h>
  29191. +
  29192. +#include "vchiq_core.h"
  29193. +#include "vchiq_arm.h"
  29194. +
  29195. +/* ---- Public Variables ------------------------------------------------- */
  29196. +
  29197. +/* ---- Private Constants and Types -------------------------------------- */
  29198. +
  29199. +struct bulk_waiter_node {
  29200. + struct bulk_waiter bulk_waiter;
  29201. + int pid;
  29202. + struct list_head list;
  29203. +};
  29204. +
  29205. +struct vchiq_instance_struct {
  29206. + VCHIQ_STATE_T *state;
  29207. +
  29208. + int connected;
  29209. +
  29210. + struct list_head bulk_waiter_list;
  29211. + struct mutex bulk_waiter_list_mutex;
  29212. +};
  29213. +
  29214. +static VCHIQ_STATUS_T
  29215. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29216. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  29217. +
  29218. +/****************************************************************************
  29219. +*
  29220. +* vchiq_initialise
  29221. +*
  29222. +***************************************************************************/
  29223. +#define VCHIQ_INIT_RETRIES 10
  29224. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  29225. +{
  29226. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  29227. + VCHIQ_STATE_T *state;
  29228. + VCHIQ_INSTANCE_T instance = NULL;
  29229. + int i;
  29230. +
  29231. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  29232. +
  29233. + /* VideoCore may not be ready due to boot up timing.
  29234. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  29235. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  29236. + state = vchiq_get_state();
  29237. + if (state)
  29238. + break;
  29239. + udelay(500);
  29240. + }
  29241. + if (i==VCHIQ_INIT_RETRIES) {
  29242. + vchiq_log_error(vchiq_core_log_level,
  29243. + "%s: videocore not initialized\n", __func__);
  29244. + goto failed;
  29245. + } else if (i>0) {
  29246. + vchiq_log_warning(vchiq_core_log_level,
  29247. + "%s: videocore initialized after %d retries\n", __func__, i);
  29248. + }
  29249. +
  29250. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  29251. + if (!instance) {
  29252. + vchiq_log_error(vchiq_core_log_level,
  29253. + "%s: error allocating vchiq instance\n", __func__);
  29254. + goto failed;
  29255. + }
  29256. +
  29257. + instance->connected = 0;
  29258. + instance->state = state;
  29259. + mutex_init(&instance->bulk_waiter_list_mutex);
  29260. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  29261. +
  29262. + *instanceOut = instance;
  29263. +
  29264. + status = VCHIQ_SUCCESS;
  29265. +
  29266. +failed:
  29267. + vchiq_log_trace(vchiq_core_log_level,
  29268. + "%s(%p): returning %d", __func__, instance, status);
  29269. +
  29270. + return status;
  29271. +}
  29272. +EXPORT_SYMBOL(vchiq_initialise);
  29273. +
  29274. +/****************************************************************************
  29275. +*
  29276. +* vchiq_shutdown
  29277. +*
  29278. +***************************************************************************/
  29279. +
  29280. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  29281. +{
  29282. + VCHIQ_STATUS_T status;
  29283. + VCHIQ_STATE_T *state = instance->state;
  29284. +
  29285. + vchiq_log_trace(vchiq_core_log_level,
  29286. + "%s(%p) called", __func__, instance);
  29287. +
  29288. + if (mutex_lock_interruptible(&state->mutex) != 0)
  29289. + return VCHIQ_RETRY;
  29290. +
  29291. + /* Remove all services */
  29292. + status = vchiq_shutdown_internal(state, instance);
  29293. +
  29294. + mutex_unlock(&state->mutex);
  29295. +
  29296. + vchiq_log_trace(vchiq_core_log_level,
  29297. + "%s(%p): returning %d", __func__, instance, status);
  29298. +
  29299. + if (status == VCHIQ_SUCCESS) {
  29300. + struct list_head *pos, *next;
  29301. + list_for_each_safe(pos, next,
  29302. + &instance->bulk_waiter_list) {
  29303. + struct bulk_waiter_node *waiter;
  29304. + waiter = list_entry(pos,
  29305. + struct bulk_waiter_node,
  29306. + list);
  29307. + list_del(pos);
  29308. + vchiq_log_info(vchiq_arm_log_level,
  29309. + "bulk_waiter - cleaned up %x "
  29310. + "for pid %d",
  29311. + (unsigned int)waiter, waiter->pid);
  29312. + kfree(waiter);
  29313. + }
  29314. + kfree(instance);
  29315. + }
  29316. +
  29317. + return status;
  29318. +}
  29319. +EXPORT_SYMBOL(vchiq_shutdown);
  29320. +
  29321. +/****************************************************************************
  29322. +*
  29323. +* vchiq_is_connected
  29324. +*
  29325. +***************************************************************************/
  29326. +
  29327. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  29328. +{
  29329. + return instance->connected;
  29330. +}
  29331. +
  29332. +/****************************************************************************
  29333. +*
  29334. +* vchiq_connect
  29335. +*
  29336. +***************************************************************************/
  29337. +
  29338. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  29339. +{
  29340. + VCHIQ_STATUS_T status;
  29341. + VCHIQ_STATE_T *state = instance->state;
  29342. +
  29343. + vchiq_log_trace(vchiq_core_log_level,
  29344. + "%s(%p) called", __func__, instance);
  29345. +
  29346. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  29347. + vchiq_log_trace(vchiq_core_log_level,
  29348. + "%s: call to mutex_lock failed", __func__);
  29349. + status = VCHIQ_RETRY;
  29350. + goto failed;
  29351. + }
  29352. + status = vchiq_connect_internal(state, instance);
  29353. +
  29354. + if (status == VCHIQ_SUCCESS)
  29355. + instance->connected = 1;
  29356. +
  29357. + mutex_unlock(&state->mutex);
  29358. +
  29359. +failed:
  29360. + vchiq_log_trace(vchiq_core_log_level,
  29361. + "%s(%p): returning %d", __func__, instance, status);
  29362. +
  29363. + return status;
  29364. +}
  29365. +EXPORT_SYMBOL(vchiq_connect);
  29366. +
  29367. +/****************************************************************************
  29368. +*
  29369. +* vchiq_add_service
  29370. +*
  29371. +***************************************************************************/
  29372. +
  29373. +VCHIQ_STATUS_T vchiq_add_service(
  29374. + VCHIQ_INSTANCE_T instance,
  29375. + const VCHIQ_SERVICE_PARAMS_T *params,
  29376. + VCHIQ_SERVICE_HANDLE_T *phandle)
  29377. +{
  29378. + VCHIQ_STATUS_T status;
  29379. + VCHIQ_STATE_T *state = instance->state;
  29380. + VCHIQ_SERVICE_T *service = NULL;
  29381. + int srvstate;
  29382. +
  29383. + vchiq_log_trace(vchiq_core_log_level,
  29384. + "%s(%p) called", __func__, instance);
  29385. +
  29386. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  29387. +
  29388. + srvstate = vchiq_is_connected(instance)
  29389. + ? VCHIQ_SRVSTATE_LISTENING
  29390. + : VCHIQ_SRVSTATE_HIDDEN;
  29391. +
  29392. + service = vchiq_add_service_internal(
  29393. + state,
  29394. + params,
  29395. + srvstate,
  29396. + instance,
  29397. + NULL);
  29398. +
  29399. + if (service) {
  29400. + *phandle = service->handle;
  29401. + status = VCHIQ_SUCCESS;
  29402. + } else
  29403. + status = VCHIQ_ERROR;
  29404. +
  29405. + vchiq_log_trace(vchiq_core_log_level,
  29406. + "%s(%p): returning %d", __func__, instance, status);
  29407. +
  29408. + return status;
  29409. +}
  29410. +EXPORT_SYMBOL(vchiq_add_service);
  29411. +
  29412. +/****************************************************************************
  29413. +*
  29414. +* vchiq_open_service
  29415. +*
  29416. +***************************************************************************/
  29417. +
  29418. +VCHIQ_STATUS_T vchiq_open_service(
  29419. + VCHIQ_INSTANCE_T instance,
  29420. + const VCHIQ_SERVICE_PARAMS_T *params,
  29421. + VCHIQ_SERVICE_HANDLE_T *phandle)
  29422. +{
  29423. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  29424. + VCHIQ_STATE_T *state = instance->state;
  29425. + VCHIQ_SERVICE_T *service = NULL;
  29426. +
  29427. + vchiq_log_trace(vchiq_core_log_level,
  29428. + "%s(%p) called", __func__, instance);
  29429. +
  29430. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  29431. +
  29432. + if (!vchiq_is_connected(instance))
  29433. + goto failed;
  29434. +
  29435. + service = vchiq_add_service_internal(state,
  29436. + params,
  29437. + VCHIQ_SRVSTATE_OPENING,
  29438. + instance,
  29439. + NULL);
  29440. +
  29441. + if (service) {
  29442. + status = vchiq_open_service_internal(service, current->pid);
  29443. + if (status == VCHIQ_SUCCESS)
  29444. + *phandle = service->handle;
  29445. + else
  29446. + vchiq_remove_service(service->handle);
  29447. + }
  29448. +
  29449. +failed:
  29450. + vchiq_log_trace(vchiq_core_log_level,
  29451. + "%s(%p): returning %d", __func__, instance, status);
  29452. +
  29453. + return status;
  29454. +}
  29455. +EXPORT_SYMBOL(vchiq_open_service);
  29456. +
  29457. +VCHIQ_STATUS_T
  29458. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  29459. + const void *data, unsigned int size, void *userdata)
  29460. +{
  29461. + return vchiq_bulk_transfer(handle,
  29462. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  29463. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  29464. +}
  29465. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  29466. +
  29467. +VCHIQ_STATUS_T
  29468. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29469. + unsigned int size, void *userdata)
  29470. +{
  29471. + return vchiq_bulk_transfer(handle,
  29472. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  29473. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  29474. +}
  29475. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  29476. +
  29477. +VCHIQ_STATUS_T
  29478. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  29479. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  29480. +{
  29481. + VCHIQ_STATUS_T status;
  29482. +
  29483. + switch (mode) {
  29484. + case VCHIQ_BULK_MODE_NOCALLBACK:
  29485. + case VCHIQ_BULK_MODE_CALLBACK:
  29486. + status = vchiq_bulk_transfer(handle,
  29487. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  29488. + mode, VCHIQ_BULK_TRANSMIT);
  29489. + break;
  29490. + case VCHIQ_BULK_MODE_BLOCKING:
  29491. + status = vchiq_blocking_bulk_transfer(handle,
  29492. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  29493. + break;
  29494. + default:
  29495. + return VCHIQ_ERROR;
  29496. + }
  29497. +
  29498. + return status;
  29499. +}
  29500. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  29501. +
  29502. +VCHIQ_STATUS_T
  29503. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29504. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  29505. +{
  29506. + VCHIQ_STATUS_T status;
  29507. +
  29508. + switch (mode) {
  29509. + case VCHIQ_BULK_MODE_NOCALLBACK:
  29510. + case VCHIQ_BULK_MODE_CALLBACK:
  29511. + status = vchiq_bulk_transfer(handle,
  29512. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  29513. + mode, VCHIQ_BULK_RECEIVE);
  29514. + break;
  29515. + case VCHIQ_BULK_MODE_BLOCKING:
  29516. + status = vchiq_blocking_bulk_transfer(handle,
  29517. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  29518. + break;
  29519. + default:
  29520. + return VCHIQ_ERROR;
  29521. + }
  29522. +
  29523. + return status;
  29524. +}
  29525. +EXPORT_SYMBOL(vchiq_bulk_receive);
  29526. +
  29527. +static VCHIQ_STATUS_T
  29528. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29529. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  29530. +{
  29531. + VCHIQ_INSTANCE_T instance;
  29532. + VCHIQ_SERVICE_T *service;
  29533. + VCHIQ_STATUS_T status;
  29534. + struct bulk_waiter_node *waiter = NULL;
  29535. + struct list_head *pos;
  29536. +
  29537. + service = find_service_by_handle(handle);
  29538. + if (!service)
  29539. + return VCHIQ_ERROR;
  29540. +
  29541. + instance = service->instance;
  29542. +
  29543. + unlock_service(service);
  29544. +
  29545. + mutex_lock(&instance->bulk_waiter_list_mutex);
  29546. + list_for_each(pos, &instance->bulk_waiter_list) {
  29547. + if (list_entry(pos, struct bulk_waiter_node,
  29548. + list)->pid == current->pid) {
  29549. + waiter = list_entry(pos,
  29550. + struct bulk_waiter_node,
  29551. + list);
  29552. + list_del(pos);
  29553. + break;
  29554. + }
  29555. + }
  29556. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  29557. +
  29558. + if (waiter) {
  29559. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  29560. + if (bulk) {
  29561. + /* This thread has an outstanding bulk transfer. */
  29562. + if ((bulk->data != data) ||
  29563. + (bulk->size != size)) {
  29564. + /* This is not a retry of the previous one.
  29565. + ** Cancel the signal when the transfer
  29566. + ** completes. */
  29567. + spin_lock(&bulk_waiter_spinlock);
  29568. + bulk->userdata = NULL;
  29569. + spin_unlock(&bulk_waiter_spinlock);
  29570. + }
  29571. + }
  29572. + }
  29573. +
  29574. + if (!waiter) {
  29575. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  29576. + if (!waiter) {
  29577. + vchiq_log_error(vchiq_core_log_level,
  29578. + "%s - out of memory", __func__);
  29579. + return VCHIQ_ERROR;
  29580. + }
  29581. + }
  29582. +
  29583. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  29584. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  29585. + dir);
  29586. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  29587. + !waiter->bulk_waiter.bulk) {
  29588. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  29589. + if (bulk) {
  29590. + /* Cancel the signal when the transfer
  29591. + ** completes. */
  29592. + spin_lock(&bulk_waiter_spinlock);
  29593. + bulk->userdata = NULL;
  29594. + spin_unlock(&bulk_waiter_spinlock);
  29595. + }
  29596. + kfree(waiter);
  29597. + } else {
  29598. + waiter->pid = current->pid;
  29599. + mutex_lock(&instance->bulk_waiter_list_mutex);
  29600. + list_add(&waiter->list, &instance->bulk_waiter_list);
  29601. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  29602. + vchiq_log_info(vchiq_arm_log_level,
  29603. + "saved bulk_waiter %x for pid %d",
  29604. + (unsigned int)waiter, current->pid);
  29605. + }
  29606. +
  29607. + return status;
  29608. +}
  29609. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  29610. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  29611. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-03-13 12:46:20.600060074 +0100
  29612. @@ -0,0 +1,71 @@
  29613. +/**
  29614. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29615. + *
  29616. + * Redistribution and use in source and binary forms, with or without
  29617. + * modification, are permitted provided that the following conditions
  29618. + * are met:
  29619. + * 1. Redistributions of source code must retain the above copyright
  29620. + * notice, this list of conditions, and the following disclaimer,
  29621. + * without modification.
  29622. + * 2. Redistributions in binary form must reproduce the above copyright
  29623. + * notice, this list of conditions and the following disclaimer in the
  29624. + * documentation and/or other materials provided with the distribution.
  29625. + * 3. The names of the above-listed copyright holders may not be used
  29626. + * to endorse or promote products derived from this software without
  29627. + * specific prior written permission.
  29628. + *
  29629. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29630. + * GNU General Public License ("GPL") version 2, as published by the Free
  29631. + * Software Foundation.
  29632. + *
  29633. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29634. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29635. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29636. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29637. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29638. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29639. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29640. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29641. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29642. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29643. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29644. + */
  29645. +
  29646. +#ifndef VCHIQ_MEMDRV_H
  29647. +#define VCHIQ_MEMDRV_H
  29648. +
  29649. +/* ---- Include Files ----------------------------------------------------- */
  29650. +
  29651. +#include <linux/kernel.h>
  29652. +#include "vchiq_if.h"
  29653. +
  29654. +/* ---- Constants and Types ---------------------------------------------- */
  29655. +
  29656. +typedef struct {
  29657. + void *armSharedMemVirt;
  29658. + dma_addr_t armSharedMemPhys;
  29659. + size_t armSharedMemSize;
  29660. +
  29661. + void *vcSharedMemVirt;
  29662. + dma_addr_t vcSharedMemPhys;
  29663. + size_t vcSharedMemSize;
  29664. +} VCHIQ_SHARED_MEM_INFO_T;
  29665. +
  29666. +/* ---- Variable Externs ------------------------------------------------- */
  29667. +
  29668. +/* ---- Function Prototypes ---------------------------------------------- */
  29669. +
  29670. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  29671. +
  29672. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  29673. +
  29674. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  29675. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29676. +
  29677. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  29678. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29679. +
  29680. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  29681. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29682. +
  29683. +#endif
  29684. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  29685. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  29686. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-03-13 12:46:20.600060074 +0100
  29687. @@ -0,0 +1,58 @@
  29688. +/**
  29689. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29690. + *
  29691. + * Redistribution and use in source and binary forms, with or without
  29692. + * modification, are permitted provided that the following conditions
  29693. + * are met:
  29694. + * 1. Redistributions of source code must retain the above copyright
  29695. + * notice, this list of conditions, and the following disclaimer,
  29696. + * without modification.
  29697. + * 2. Redistributions in binary form must reproduce the above copyright
  29698. + * notice, this list of conditions and the following disclaimer in the
  29699. + * documentation and/or other materials provided with the distribution.
  29700. + * 3. The names of the above-listed copyright holders may not be used
  29701. + * to endorse or promote products derived from this software without
  29702. + * specific prior written permission.
  29703. + *
  29704. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29705. + * GNU General Public License ("GPL") version 2, as published by the Free
  29706. + * Software Foundation.
  29707. + *
  29708. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29709. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29710. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29711. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29712. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29713. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29714. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29715. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29716. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29717. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29718. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29719. + */
  29720. +
  29721. +#ifndef VCHIQ_PAGELIST_H
  29722. +#define VCHIQ_PAGELIST_H
  29723. +
  29724. +#ifndef PAGE_SIZE
  29725. +#define PAGE_SIZE 4096
  29726. +#endif
  29727. +#define CACHE_LINE_SIZE 32
  29728. +#define PAGELIST_WRITE 0
  29729. +#define PAGELIST_READ 1
  29730. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  29731. +
  29732. +typedef struct pagelist_struct {
  29733. + unsigned long length;
  29734. + unsigned short type;
  29735. + unsigned short offset;
  29736. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  29737. + pages at consecutive addresses. */
  29738. +} PAGELIST_T;
  29739. +
  29740. +typedef struct fragments_struct {
  29741. + char headbuf[CACHE_LINE_SIZE];
  29742. + char tailbuf[CACHE_LINE_SIZE];
  29743. +} FRAGMENTS_T;
  29744. +
  29745. +#endif /* VCHIQ_PAGELIST_H */
  29746. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  29747. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  29748. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-03-13 12:46:20.600060074 +0100
  29749. @@ -0,0 +1,254 @@
  29750. +/**
  29751. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29752. + *
  29753. + * Redistribution and use in source and binary forms, with or without
  29754. + * modification, are permitted provided that the following conditions
  29755. + * are met:
  29756. + * 1. Redistributions of source code must retain the above copyright
  29757. + * notice, this list of conditions, and the following disclaimer,
  29758. + * without modification.
  29759. + * 2. Redistributions in binary form must reproduce the above copyright
  29760. + * notice, this list of conditions and the following disclaimer in the
  29761. + * documentation and/or other materials provided with the distribution.
  29762. + * 3. The names of the above-listed copyright holders may not be used
  29763. + * to endorse or promote products derived from this software without
  29764. + * specific prior written permission.
  29765. + *
  29766. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29767. + * GNU General Public License ("GPL") version 2, as published by the Free
  29768. + * Software Foundation.
  29769. + *
  29770. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29771. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29772. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29773. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29774. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29775. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29776. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29777. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29778. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29779. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29780. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29781. + */
  29782. +
  29783. +
  29784. +#include <linux/proc_fs.h>
  29785. +#include "vchiq_core.h"
  29786. +#include "vchiq_arm.h"
  29787. +
  29788. +#if 1
  29789. +
  29790. +int vchiq_proc_init(void)
  29791. +{
  29792. + return 0;
  29793. +}
  29794. +
  29795. +void vchiq_proc_deinit(void)
  29796. +{
  29797. +}
  29798. +
  29799. +#else
  29800. +
  29801. +struct vchiq_proc_info {
  29802. + /* Global 'vc' proc entry used by all instances */
  29803. + struct proc_dir_entry *vc_cfg_dir;
  29804. +
  29805. + /* one entry per client process */
  29806. + struct proc_dir_entry *clients;
  29807. +
  29808. + /* log categories */
  29809. + struct proc_dir_entry *log_categories;
  29810. +};
  29811. +
  29812. +static struct vchiq_proc_info proc_info;
  29813. +
  29814. +struct proc_dir_entry *vchiq_proc_top(void)
  29815. +{
  29816. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  29817. + return proc_info.vc_cfg_dir;
  29818. +}
  29819. +
  29820. +/****************************************************************************
  29821. +*
  29822. +* log category entries
  29823. +*
  29824. +***************************************************************************/
  29825. +#define PROC_WRITE_BUF_SIZE 256
  29826. +
  29827. +#define VCHIQ_LOG_ERROR_STR "error"
  29828. +#define VCHIQ_LOG_WARNING_STR "warning"
  29829. +#define VCHIQ_LOG_INFO_STR "info"
  29830. +#define VCHIQ_LOG_TRACE_STR "trace"
  29831. +
  29832. +static int log_cfg_read(char *buffer,
  29833. + char **start,
  29834. + off_t off,
  29835. + int count,
  29836. + int *eof,
  29837. + void *data)
  29838. +{
  29839. + int len = 0;
  29840. + char *log_value = NULL;
  29841. +
  29842. + switch (*((int *)data)) {
  29843. + case VCHIQ_LOG_ERROR:
  29844. + log_value = VCHIQ_LOG_ERROR_STR;
  29845. + break;
  29846. + case VCHIQ_LOG_WARNING:
  29847. + log_value = VCHIQ_LOG_WARNING_STR;
  29848. + break;
  29849. + case VCHIQ_LOG_INFO:
  29850. + log_value = VCHIQ_LOG_INFO_STR;
  29851. + break;
  29852. + case VCHIQ_LOG_TRACE:
  29853. + log_value = VCHIQ_LOG_TRACE_STR;
  29854. + break;
  29855. + default:
  29856. + break;
  29857. + }
  29858. +
  29859. + len += sprintf(buffer + len,
  29860. + "%s\n",
  29861. + log_value ? log_value : "(null)");
  29862. +
  29863. + return len;
  29864. +}
  29865. +
  29866. +
  29867. +static int log_cfg_write(struct file *file,
  29868. + const char __user *buffer,
  29869. + unsigned long count,
  29870. + void *data)
  29871. +{
  29872. + int *log_module = data;
  29873. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  29874. +
  29875. + (void)file;
  29876. +
  29877. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  29878. + if (count >= PROC_WRITE_BUF_SIZE)
  29879. + count = PROC_WRITE_BUF_SIZE;
  29880. +
  29881. + if (copy_from_user(kbuf,
  29882. + buffer,
  29883. + count) != 0)
  29884. + return -EFAULT;
  29885. + kbuf[count - 1] = 0;
  29886. +
  29887. + if (strncmp("error", kbuf, strlen("error")) == 0)
  29888. + *log_module = VCHIQ_LOG_ERROR;
  29889. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  29890. + *log_module = VCHIQ_LOG_WARNING;
  29891. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  29892. + *log_module = VCHIQ_LOG_INFO;
  29893. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  29894. + *log_module = VCHIQ_LOG_TRACE;
  29895. + else
  29896. + *log_module = VCHIQ_LOG_DEFAULT;
  29897. +
  29898. + return count;
  29899. +}
  29900. +
  29901. +/* Log category proc entries */
  29902. +struct vchiq_proc_log_entry {
  29903. + const char *name;
  29904. + int *plevel;
  29905. + struct proc_dir_entry *dir;
  29906. +};
  29907. +
  29908. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  29909. + { "core", &vchiq_core_log_level },
  29910. + { "msg", &vchiq_core_msg_log_level },
  29911. + { "sync", &vchiq_sync_log_level },
  29912. + { "susp", &vchiq_susp_log_level },
  29913. + { "arm", &vchiq_arm_log_level },
  29914. +};
  29915. +static int n_log_entries =
  29916. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  29917. +
  29918. +/* create an entry under /proc/vc/log for each log category */
  29919. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  29920. +{
  29921. + struct proc_dir_entry *dir;
  29922. + size_t i;
  29923. + int ret = 0;
  29924. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  29925. + if (!dir)
  29926. + return -ENOMEM;
  29927. + proc_info.log_categories = dir;
  29928. +
  29929. + for (i = 0; i < n_log_entries; i++) {
  29930. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  29931. + 0644,
  29932. + proc_info.log_categories);
  29933. + if (!dir) {
  29934. + ret = -ENOMEM;
  29935. + break;
  29936. + }
  29937. +
  29938. + dir->read_proc = &log_cfg_read;
  29939. + dir->write_proc = &log_cfg_write;
  29940. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  29941. +
  29942. + vchiq_proc_log_entries[i].dir = dir;
  29943. + }
  29944. + return ret;
  29945. +}
  29946. +
  29947. +
  29948. +int vchiq_proc_init(void)
  29949. +{
  29950. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  29951. +
  29952. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  29953. + if (proc_info.vc_cfg_dir == NULL)
  29954. + goto fail;
  29955. +
  29956. + proc_info.clients = proc_mkdir("clients",
  29957. + proc_info.vc_cfg_dir);
  29958. + if (!proc_info.clients)
  29959. + goto fail;
  29960. +
  29961. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  29962. + goto fail;
  29963. +
  29964. + return 0;
  29965. +
  29966. +fail:
  29967. + vchiq_proc_deinit();
  29968. + vchiq_log_error(vchiq_arm_log_level,
  29969. + "%s: failed to create proc directory",
  29970. + __func__);
  29971. +
  29972. + return -ENOMEM;
  29973. +}
  29974. +
  29975. +/* remove all the proc entries */
  29976. +void vchiq_proc_deinit(void)
  29977. +{
  29978. + /* log category entries */
  29979. + if (proc_info.log_categories) {
  29980. + size_t i;
  29981. + for (i = 0; i < n_log_entries; i++)
  29982. + if (vchiq_proc_log_entries[i].dir)
  29983. + remove_proc_entry(
  29984. + vchiq_proc_log_entries[i].name,
  29985. + proc_info.log_categories);
  29986. +
  29987. + remove_proc_entry(proc_info.log_categories->name,
  29988. + proc_info.vc_cfg_dir);
  29989. + }
  29990. + if (proc_info.clients)
  29991. + remove_proc_entry(proc_info.clients->name,
  29992. + proc_info.vc_cfg_dir);
  29993. + if (proc_info.vc_cfg_dir)
  29994. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  29995. +}
  29996. +
  29997. +struct proc_dir_entry *vchiq_clients_top(void)
  29998. +{
  29999. + return proc_info.clients;
  30000. +}
  30001. +
  30002. +#endif
  30003. +
  30004. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  30005. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  30006. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-03-13 12:46:20.600060074 +0100
  30007. @@ -0,0 +1,828 @@
  30008. +/**
  30009. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30010. + *
  30011. + * Redistribution and use in source and binary forms, with or without
  30012. + * modification, are permitted provided that the following conditions
  30013. + * are met:
  30014. + * 1. Redistributions of source code must retain the above copyright
  30015. + * notice, this list of conditions, and the following disclaimer,
  30016. + * without modification.
  30017. + * 2. Redistributions in binary form must reproduce the above copyright
  30018. + * notice, this list of conditions and the following disclaimer in the
  30019. + * documentation and/or other materials provided with the distribution.
  30020. + * 3. The names of the above-listed copyright holders may not be used
  30021. + * to endorse or promote products derived from this software without
  30022. + * specific prior written permission.
  30023. + *
  30024. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30025. + * GNU General Public License ("GPL") version 2, as published by the Free
  30026. + * Software Foundation.
  30027. + *
  30028. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30029. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30030. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30031. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30032. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30033. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30034. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30035. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30036. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30037. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30038. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30039. + */
  30040. +#include <linux/module.h>
  30041. +#include <linux/types.h>
  30042. +
  30043. +#include "interface/vchi/vchi.h"
  30044. +#include "vchiq.h"
  30045. +#include "vchiq_core.h"
  30046. +
  30047. +#include "vchiq_util.h"
  30048. +
  30049. +#include <stddef.h>
  30050. +
  30051. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  30052. +
  30053. +typedef struct {
  30054. + VCHIQ_SERVICE_HANDLE_T handle;
  30055. +
  30056. + VCHIU_QUEUE_T queue;
  30057. +
  30058. + VCHI_CALLBACK_T callback;
  30059. + void *callback_param;
  30060. +} SHIM_SERVICE_T;
  30061. +
  30062. +/* ----------------------------------------------------------------------
  30063. + * return pointer to the mphi message driver function table
  30064. + * -------------------------------------------------------------------- */
  30065. +const VCHI_MESSAGE_DRIVER_T *
  30066. +vchi_mphi_message_driver_func_table(void)
  30067. +{
  30068. + return NULL;
  30069. +}
  30070. +
  30071. +/* ----------------------------------------------------------------------
  30072. + * return a pointer to the 'single' connection driver fops
  30073. + * -------------------------------------------------------------------- */
  30074. +const VCHI_CONNECTION_API_T *
  30075. +single_get_func_table(void)
  30076. +{
  30077. + return NULL;
  30078. +}
  30079. +
  30080. +VCHI_CONNECTION_T *vchi_create_connection(
  30081. + const VCHI_CONNECTION_API_T *function_table,
  30082. + const VCHI_MESSAGE_DRIVER_T *low_level)
  30083. +{
  30084. + (void)function_table;
  30085. + (void)low_level;
  30086. + return NULL;
  30087. +}
  30088. +
  30089. +/***********************************************************
  30090. + * Name: vchi_msg_peek
  30091. + *
  30092. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  30093. + * void **data,
  30094. + * uint32_t *msg_size,
  30095. +
  30096. +
  30097. + * VCHI_FLAGS_T flags
  30098. + *
  30099. + * Description: Routine to return a pointer to the current message (to allow in
  30100. + * place processing). The message can be removed using
  30101. + * vchi_msg_remove when you're finished
  30102. + *
  30103. + * Returns: int32_t - success == 0
  30104. + *
  30105. + ***********************************************************/
  30106. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  30107. + void **data,
  30108. + uint32_t *msg_size,
  30109. + VCHI_FLAGS_T flags)
  30110. +{
  30111. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30112. + VCHIQ_HEADER_T *header;
  30113. +
  30114. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  30115. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  30116. +
  30117. + if (flags == VCHI_FLAGS_NONE)
  30118. + if (vchiu_queue_is_empty(&service->queue))
  30119. + return -1;
  30120. +
  30121. + header = vchiu_queue_peek(&service->queue);
  30122. +
  30123. + *data = header->data;
  30124. + *msg_size = header->size;
  30125. +
  30126. + return 0;
  30127. +}
  30128. +EXPORT_SYMBOL(vchi_msg_peek);
  30129. +
  30130. +/***********************************************************
  30131. + * Name: vchi_msg_remove
  30132. + *
  30133. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  30134. + *
  30135. + * Description: Routine to remove a message (after it has been read with
  30136. + * vchi_msg_peek)
  30137. + *
  30138. + * Returns: int32_t - success == 0
  30139. + *
  30140. + ***********************************************************/
  30141. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  30142. +{
  30143. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30144. + VCHIQ_HEADER_T *header;
  30145. +
  30146. + header = vchiu_queue_pop(&service->queue);
  30147. +
  30148. + vchiq_release_message(service->handle, header);
  30149. +
  30150. + return 0;
  30151. +}
  30152. +EXPORT_SYMBOL(vchi_msg_remove);
  30153. +
  30154. +/***********************************************************
  30155. + * Name: vchi_msg_queue
  30156. + *
  30157. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30158. + * const void *data,
  30159. + * uint32_t data_size,
  30160. + * VCHI_FLAGS_T flags,
  30161. + * void *msg_handle,
  30162. + *
  30163. + * Description: Thin wrapper to queue a message onto a connection
  30164. + *
  30165. + * Returns: int32_t - success == 0
  30166. + *
  30167. + ***********************************************************/
  30168. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  30169. + const void *data,
  30170. + uint32_t data_size,
  30171. + VCHI_FLAGS_T flags,
  30172. + void *msg_handle)
  30173. +{
  30174. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30175. + VCHIQ_ELEMENT_T element = {data, data_size};
  30176. + VCHIQ_STATUS_T status;
  30177. +
  30178. + (void)msg_handle;
  30179. +
  30180. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  30181. +
  30182. + status = vchiq_queue_message(service->handle, &element, 1);
  30183. +
  30184. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  30185. + ** implement a retry mechanism since this function is supposed
  30186. + ** to block until queued
  30187. + */
  30188. + while (status == VCHIQ_RETRY) {
  30189. + msleep(1);
  30190. + status = vchiq_queue_message(service->handle, &element, 1);
  30191. + }
  30192. +
  30193. + return vchiq_status_to_vchi(status);
  30194. +}
  30195. +EXPORT_SYMBOL(vchi_msg_queue);
  30196. +
  30197. +/***********************************************************
  30198. + * Name: vchi_bulk_queue_receive
  30199. + *
  30200. + * Arguments: VCHI_BULK_HANDLE_T handle,
  30201. + * void *data_dst,
  30202. + * const uint32_t data_size,
  30203. + * VCHI_FLAGS_T flags
  30204. + * void *bulk_handle
  30205. + *
  30206. + * Description: Routine to setup a rcv buffer
  30207. + *
  30208. + * Returns: int32_t - success == 0
  30209. + *
  30210. + ***********************************************************/
  30211. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  30212. + void *data_dst,
  30213. + uint32_t data_size,
  30214. + VCHI_FLAGS_T flags,
  30215. + void *bulk_handle)
  30216. +{
  30217. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30218. + VCHIQ_BULK_MODE_T mode;
  30219. + VCHIQ_STATUS_T status;
  30220. +
  30221. + switch ((int)flags) {
  30222. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  30223. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30224. + WARN_ON(!service->callback);
  30225. + mode = VCHIQ_BULK_MODE_CALLBACK;
  30226. + break;
  30227. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  30228. + mode = VCHIQ_BULK_MODE_BLOCKING;
  30229. + break;
  30230. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30231. + case VCHI_FLAGS_NONE:
  30232. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  30233. + break;
  30234. + default:
  30235. + WARN(1, "unsupported message\n");
  30236. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  30237. + }
  30238. +
  30239. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  30240. + bulk_handle, mode);
  30241. +
  30242. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  30243. + ** implement a retry mechanism since this function is supposed
  30244. + ** to block until queued
  30245. + */
  30246. + while (status == VCHIQ_RETRY) {
  30247. + msleep(1);
  30248. + status = vchiq_bulk_receive(service->handle, data_dst,
  30249. + data_size, bulk_handle, mode);
  30250. + }
  30251. +
  30252. + return vchiq_status_to_vchi(status);
  30253. +}
  30254. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  30255. +
  30256. +/***********************************************************
  30257. + * Name: vchi_bulk_queue_transmit
  30258. + *
  30259. + * Arguments: VCHI_BULK_HANDLE_T handle,
  30260. + * const void *data_src,
  30261. + * uint32_t data_size,
  30262. + * VCHI_FLAGS_T flags,
  30263. + * void *bulk_handle
  30264. + *
  30265. + * Description: Routine to transmit some data
  30266. + *
  30267. + * Returns: int32_t - success == 0
  30268. + *
  30269. + ***********************************************************/
  30270. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  30271. + const void *data_src,
  30272. + uint32_t data_size,
  30273. + VCHI_FLAGS_T flags,
  30274. + void *bulk_handle)
  30275. +{
  30276. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30277. + VCHIQ_BULK_MODE_T mode;
  30278. + VCHIQ_STATUS_T status;
  30279. +
  30280. + switch ((int)flags) {
  30281. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  30282. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30283. + WARN_ON(!service->callback);
  30284. + mode = VCHIQ_BULK_MODE_CALLBACK;
  30285. + break;
  30286. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  30287. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  30288. + mode = VCHIQ_BULK_MODE_BLOCKING;
  30289. + break;
  30290. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30291. + case VCHI_FLAGS_NONE:
  30292. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  30293. + break;
  30294. + default:
  30295. + WARN(1, "unsupported message\n");
  30296. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  30297. + }
  30298. +
  30299. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  30300. + bulk_handle, mode);
  30301. +
  30302. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  30303. + ** implement a retry mechanism since this function is supposed
  30304. + ** to block until queued
  30305. + */
  30306. + while (status == VCHIQ_RETRY) {
  30307. + msleep(1);
  30308. + status = vchiq_bulk_transmit(service->handle, data_src,
  30309. + data_size, bulk_handle, mode);
  30310. + }
  30311. +
  30312. + return vchiq_status_to_vchi(status);
  30313. +}
  30314. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  30315. +
  30316. +/***********************************************************
  30317. + * Name: vchi_msg_dequeue
  30318. + *
  30319. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30320. + * void *data,
  30321. + * uint32_t max_data_size_to_read,
  30322. + * uint32_t *actual_msg_size
  30323. + * VCHI_FLAGS_T flags
  30324. + *
  30325. + * Description: Routine to dequeue a message into the supplied buffer
  30326. + *
  30327. + * Returns: int32_t - success == 0
  30328. + *
  30329. + ***********************************************************/
  30330. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  30331. + void *data,
  30332. + uint32_t max_data_size_to_read,
  30333. + uint32_t *actual_msg_size,
  30334. + VCHI_FLAGS_T flags)
  30335. +{
  30336. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30337. + VCHIQ_HEADER_T *header;
  30338. +
  30339. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  30340. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  30341. +
  30342. + if (flags == VCHI_FLAGS_NONE)
  30343. + if (vchiu_queue_is_empty(&service->queue))
  30344. + return -1;
  30345. +
  30346. + header = vchiu_queue_pop(&service->queue);
  30347. +
  30348. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  30349. + header->size : max_data_size_to_read);
  30350. +
  30351. + *actual_msg_size = header->size;
  30352. +
  30353. + vchiq_release_message(service->handle, header);
  30354. +
  30355. + return 0;
  30356. +}
  30357. +EXPORT_SYMBOL(vchi_msg_dequeue);
  30358. +
  30359. +/***********************************************************
  30360. + * Name: vchi_msg_queuev
  30361. + *
  30362. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30363. + * VCHI_MSG_VECTOR_T *vector,
  30364. + * uint32_t count,
  30365. + * VCHI_FLAGS_T flags,
  30366. + * void *msg_handle
  30367. + *
  30368. + * Description: Thin wrapper to queue a message onto a connection
  30369. + *
  30370. + * Returns: int32_t - success == 0
  30371. + *
  30372. + ***********************************************************/
  30373. +
  30374. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  30375. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  30376. + offsetof(VCHIQ_ELEMENT_T, data));
  30377. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  30378. + offsetof(VCHIQ_ELEMENT_T, size));
  30379. +
  30380. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  30381. + VCHI_MSG_VECTOR_T *vector,
  30382. + uint32_t count,
  30383. + VCHI_FLAGS_T flags,
  30384. + void *msg_handle)
  30385. +{
  30386. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30387. +
  30388. + (void)msg_handle;
  30389. +
  30390. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  30391. +
  30392. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  30393. + (const VCHIQ_ELEMENT_T *)vector, count));
  30394. +}
  30395. +EXPORT_SYMBOL(vchi_msg_queuev);
  30396. +
  30397. +/***********************************************************
  30398. + * Name: vchi_held_msg_release
  30399. + *
  30400. + * Arguments: VCHI_HELD_MSG_T *message
  30401. + *
  30402. + * Description: Routine to release a held message (after it has been read with
  30403. + * vchi_msg_hold)
  30404. + *
  30405. + * Returns: int32_t - success == 0
  30406. + *
  30407. + ***********************************************************/
  30408. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  30409. +{
  30410. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  30411. + (VCHIQ_HEADER_T *)message->message);
  30412. +
  30413. + return 0;
  30414. +}
  30415. +EXPORT_SYMBOL(vchi_held_msg_release);
  30416. +
  30417. +/***********************************************************
  30418. + * Name: vchi_msg_hold
  30419. + *
  30420. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30421. + * void **data,
  30422. + * uint32_t *msg_size,
  30423. + * VCHI_FLAGS_T flags,
  30424. + * VCHI_HELD_MSG_T *message_handle
  30425. + *
  30426. + * Description: Routine to return a pointer to the current message (to allow
  30427. + * in place processing). The message is dequeued - don't forget
  30428. + * to release the message using vchi_held_msg_release when you're
  30429. + * finished.
  30430. + *
  30431. + * Returns: int32_t - success == 0
  30432. + *
  30433. + ***********************************************************/
  30434. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  30435. + void **data,
  30436. + uint32_t *msg_size,
  30437. + VCHI_FLAGS_T flags,
  30438. + VCHI_HELD_MSG_T *message_handle)
  30439. +{
  30440. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30441. + VCHIQ_HEADER_T *header;
  30442. +
  30443. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  30444. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  30445. +
  30446. + if (flags == VCHI_FLAGS_NONE)
  30447. + if (vchiu_queue_is_empty(&service->queue))
  30448. + return -1;
  30449. +
  30450. + header = vchiu_queue_pop(&service->queue);
  30451. +
  30452. + *data = header->data;
  30453. + *msg_size = header->size;
  30454. +
  30455. + message_handle->service =
  30456. + (struct opaque_vchi_service_t *)service->handle;
  30457. + message_handle->message = header;
  30458. +
  30459. + return 0;
  30460. +}
  30461. +EXPORT_SYMBOL(vchi_msg_hold);
  30462. +
  30463. +/***********************************************************
  30464. + * Name: vchi_initialise
  30465. + *
  30466. + * Arguments: VCHI_INSTANCE_T *instance_handle
  30467. + * VCHI_CONNECTION_T **connections
  30468. + * const uint32_t num_connections
  30469. + *
  30470. + * Description: Initialises the hardware but does not transmit anything
  30471. + * When run as a Host App this will be called twice hence the need
  30472. + * to malloc the state information
  30473. + *
  30474. + * Returns: 0 if successful, failure otherwise
  30475. + *
  30476. + ***********************************************************/
  30477. +
  30478. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  30479. +{
  30480. + VCHIQ_INSTANCE_T instance;
  30481. + VCHIQ_STATUS_T status;
  30482. +
  30483. + status = vchiq_initialise(&instance);
  30484. +
  30485. + *instance_handle = (VCHI_INSTANCE_T)instance;
  30486. +
  30487. + return vchiq_status_to_vchi(status);
  30488. +}
  30489. +EXPORT_SYMBOL(vchi_initialise);
  30490. +
  30491. +/***********************************************************
  30492. + * Name: vchi_connect
  30493. + *
  30494. + * Arguments: VCHI_CONNECTION_T **connections
  30495. + * const uint32_t num_connections
  30496. + * VCHI_INSTANCE_T instance_handle)
  30497. + *
  30498. + * Description: Starts the command service on each connection,
  30499. + * causing INIT messages to be pinged back and forth
  30500. + *
  30501. + * Returns: 0 if successful, failure otherwise
  30502. + *
  30503. + ***********************************************************/
  30504. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  30505. + const uint32_t num_connections,
  30506. + VCHI_INSTANCE_T instance_handle)
  30507. +{
  30508. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30509. +
  30510. + (void)connections;
  30511. + (void)num_connections;
  30512. +
  30513. + return vchiq_connect(instance);
  30514. +}
  30515. +EXPORT_SYMBOL(vchi_connect);
  30516. +
  30517. +
  30518. +/***********************************************************
  30519. + * Name: vchi_disconnect
  30520. + *
  30521. + * Arguments: VCHI_INSTANCE_T instance_handle
  30522. + *
  30523. + * Description: Stops the command service on each connection,
  30524. + * causing DE-INIT messages to be pinged back and forth
  30525. + *
  30526. + * Returns: 0 if successful, failure otherwise
  30527. + *
  30528. + ***********************************************************/
  30529. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  30530. +{
  30531. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30532. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  30533. +}
  30534. +EXPORT_SYMBOL(vchi_disconnect);
  30535. +
  30536. +
  30537. +/***********************************************************
  30538. + * Name: vchi_service_open
  30539. + * Name: vchi_service_create
  30540. + *
  30541. + * Arguments: VCHI_INSTANCE_T *instance_handle
  30542. + * SERVICE_CREATION_T *setup,
  30543. + * VCHI_SERVICE_HANDLE_T *handle
  30544. + *
  30545. + * Description: Routine to open a service
  30546. + *
  30547. + * Returns: int32_t - success == 0
  30548. + *
  30549. + ***********************************************************/
  30550. +
  30551. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  30552. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  30553. +{
  30554. + SHIM_SERVICE_T *service =
  30555. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  30556. +
  30557. + if (!service->callback)
  30558. + goto release;
  30559. +
  30560. + switch (reason) {
  30561. + case VCHIQ_MESSAGE_AVAILABLE:
  30562. + vchiu_queue_push(&service->queue, header);
  30563. +
  30564. + service->callback(service->callback_param,
  30565. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  30566. +
  30567. + goto done;
  30568. + break;
  30569. +
  30570. + case VCHIQ_BULK_TRANSMIT_DONE:
  30571. + service->callback(service->callback_param,
  30572. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  30573. + break;
  30574. +
  30575. + case VCHIQ_BULK_RECEIVE_DONE:
  30576. + service->callback(service->callback_param,
  30577. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  30578. + break;
  30579. +
  30580. + case VCHIQ_SERVICE_CLOSED:
  30581. + service->callback(service->callback_param,
  30582. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  30583. + break;
  30584. +
  30585. + case VCHIQ_SERVICE_OPENED:
  30586. + /* No equivalent VCHI reason */
  30587. + break;
  30588. +
  30589. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  30590. + service->callback(service->callback_param,
  30591. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  30592. + bulk_user);
  30593. + break;
  30594. +
  30595. + case VCHIQ_BULK_RECEIVE_ABORTED:
  30596. + service->callback(service->callback_param,
  30597. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  30598. + bulk_user);
  30599. + break;
  30600. +
  30601. + default:
  30602. + WARN(1, "not supported\n");
  30603. + break;
  30604. + }
  30605. +
  30606. +release:
  30607. + vchiq_release_message(service->handle, header);
  30608. +done:
  30609. + return VCHIQ_SUCCESS;
  30610. +}
  30611. +
  30612. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  30613. + SERVICE_CREATION_T *setup)
  30614. +{
  30615. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  30616. +
  30617. + (void)instance;
  30618. +
  30619. + if (service) {
  30620. + if (vchiu_queue_init(&service->queue, 64)) {
  30621. + service->callback = setup->callback;
  30622. + service->callback_param = setup->callback_param;
  30623. + } else {
  30624. + kfree(service);
  30625. + service = NULL;
  30626. + }
  30627. + }
  30628. +
  30629. + return service;
  30630. +}
  30631. +
  30632. +static void service_free(SHIM_SERVICE_T *service)
  30633. +{
  30634. + if (service) {
  30635. + vchiu_queue_delete(&service->queue);
  30636. + kfree(service);
  30637. + }
  30638. +}
  30639. +
  30640. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  30641. + SERVICE_CREATION_T *setup,
  30642. + VCHI_SERVICE_HANDLE_T *handle)
  30643. +{
  30644. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30645. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30646. + if (service) {
  30647. + VCHIQ_SERVICE_PARAMS_T params;
  30648. + VCHIQ_STATUS_T status;
  30649. +
  30650. + memset(&params, 0, sizeof(params));
  30651. + params.fourcc = setup->service_id;
  30652. + params.callback = shim_callback;
  30653. + params.userdata = service;
  30654. + params.version = setup->version.version;
  30655. + params.version_min = setup->version.version_min;
  30656. +
  30657. + status = vchiq_open_service(instance, &params,
  30658. + &service->handle);
  30659. + if (status != VCHIQ_SUCCESS) {
  30660. + service_free(service);
  30661. + service = NULL;
  30662. + }
  30663. + }
  30664. +
  30665. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30666. +
  30667. + return (service != NULL) ? 0 : -1;
  30668. +}
  30669. +EXPORT_SYMBOL(vchi_service_open);
  30670. +
  30671. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  30672. + SERVICE_CREATION_T *setup,
  30673. + VCHI_SERVICE_HANDLE_T *handle)
  30674. +{
  30675. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30676. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30677. + if (service) {
  30678. + VCHIQ_SERVICE_PARAMS_T params;
  30679. + VCHIQ_STATUS_T status;
  30680. +
  30681. + memset(&params, 0, sizeof(params));
  30682. + params.fourcc = setup->service_id;
  30683. + params.callback = shim_callback;
  30684. + params.userdata = service;
  30685. + params.version = setup->version.version;
  30686. + params.version_min = setup->version.version_min;
  30687. + status = vchiq_add_service(instance, &params, &service->handle);
  30688. +
  30689. + if (status != VCHIQ_SUCCESS) {
  30690. + service_free(service);
  30691. + service = NULL;
  30692. + }
  30693. + }
  30694. +
  30695. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30696. +
  30697. + return (service != NULL) ? 0 : -1;
  30698. +}
  30699. +EXPORT_SYMBOL(vchi_service_create);
  30700. +
  30701. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  30702. +{
  30703. + int32_t ret = -1;
  30704. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30705. + if (service) {
  30706. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  30707. + if (status == VCHIQ_SUCCESS) {
  30708. + service_free(service);
  30709. + service = NULL;
  30710. + }
  30711. +
  30712. + ret = vchiq_status_to_vchi(status);
  30713. + }
  30714. + return ret;
  30715. +}
  30716. +EXPORT_SYMBOL(vchi_service_close);
  30717. +
  30718. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  30719. +{
  30720. + int32_t ret = -1;
  30721. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30722. + if (service) {
  30723. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  30724. + if (status == VCHIQ_SUCCESS) {
  30725. + service_free(service);
  30726. + service = NULL;
  30727. + }
  30728. +
  30729. + ret = vchiq_status_to_vchi(status);
  30730. + }
  30731. + return ret;
  30732. +}
  30733. +EXPORT_SYMBOL(vchi_service_destroy);
  30734. +
  30735. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  30736. +{
  30737. + int32_t ret = -1;
  30738. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30739. + if(service)
  30740. + {
  30741. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  30742. + ret = vchiq_status_to_vchi( status );
  30743. + }
  30744. + return ret;
  30745. +}
  30746. +EXPORT_SYMBOL(vchi_get_peer_version);
  30747. +
  30748. +/* ----------------------------------------------------------------------
  30749. + * read a uint32_t from buffer.
  30750. + * network format is defined to be little endian
  30751. + * -------------------------------------------------------------------- */
  30752. +uint32_t
  30753. +vchi_readbuf_uint32(const void *_ptr)
  30754. +{
  30755. + const unsigned char *ptr = _ptr;
  30756. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  30757. +}
  30758. +
  30759. +/* ----------------------------------------------------------------------
  30760. + * write a uint32_t to buffer.
  30761. + * network format is defined to be little endian
  30762. + * -------------------------------------------------------------------- */
  30763. +void
  30764. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  30765. +{
  30766. + unsigned char *ptr = _ptr;
  30767. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  30768. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  30769. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  30770. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  30771. +}
  30772. +
  30773. +/* ----------------------------------------------------------------------
  30774. + * read a uint16_t from buffer.
  30775. + * network format is defined to be little endian
  30776. + * -------------------------------------------------------------------- */
  30777. +uint16_t
  30778. +vchi_readbuf_uint16(const void *_ptr)
  30779. +{
  30780. + const unsigned char *ptr = _ptr;
  30781. + return ptr[0] | (ptr[1] << 8);
  30782. +}
  30783. +
  30784. +/* ----------------------------------------------------------------------
  30785. + * write a uint16_t into the buffer.
  30786. + * network format is defined to be little endian
  30787. + * -------------------------------------------------------------------- */
  30788. +void
  30789. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  30790. +{
  30791. + unsigned char *ptr = _ptr;
  30792. + ptr[0] = (value >> 0) & 0xFF;
  30793. + ptr[1] = (value >> 8) & 0xFF;
  30794. +}
  30795. +
  30796. +/***********************************************************
  30797. + * Name: vchi_service_use
  30798. + *
  30799. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30800. + *
  30801. + * Description: Routine to increment refcount on a service
  30802. + *
  30803. + * Returns: void
  30804. + *
  30805. + ***********************************************************/
  30806. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  30807. +{
  30808. + int32_t ret = -1;
  30809. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30810. + if (service)
  30811. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  30812. + return ret;
  30813. +}
  30814. +EXPORT_SYMBOL(vchi_service_use);
  30815. +
  30816. +/***********************************************************
  30817. + * Name: vchi_service_release
  30818. + *
  30819. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30820. + *
  30821. + * Description: Routine to decrement refcount on a service
  30822. + *
  30823. + * Returns: void
  30824. + *
  30825. + ***********************************************************/
  30826. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  30827. +{
  30828. + int32_t ret = -1;
  30829. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30830. + if (service)
  30831. + ret = vchiq_status_to_vchi(
  30832. + vchiq_release_service(service->handle));
  30833. + return ret;
  30834. +}
  30835. +EXPORT_SYMBOL(vchi_service_release);
  30836. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  30837. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  30838. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-03-13 12:46:20.600060074 +0100
  30839. @@ -0,0 +1,151 @@
  30840. +/**
  30841. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30842. + *
  30843. + * Redistribution and use in source and binary forms, with or without
  30844. + * modification, are permitted provided that the following conditions
  30845. + * are met:
  30846. + * 1. Redistributions of source code must retain the above copyright
  30847. + * notice, this list of conditions, and the following disclaimer,
  30848. + * without modification.
  30849. + * 2. Redistributions in binary form must reproduce the above copyright
  30850. + * notice, this list of conditions and the following disclaimer in the
  30851. + * documentation and/or other materials provided with the distribution.
  30852. + * 3. The names of the above-listed copyright holders may not be used
  30853. + * to endorse or promote products derived from this software without
  30854. + * specific prior written permission.
  30855. + *
  30856. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30857. + * GNU General Public License ("GPL") version 2, as published by the Free
  30858. + * Software Foundation.
  30859. + *
  30860. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30861. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30862. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30863. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30864. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30865. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30866. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30867. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30868. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30869. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30870. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30871. + */
  30872. +
  30873. +#include "vchiq_util.h"
  30874. +
  30875. +static inline int is_pow2(int i)
  30876. +{
  30877. + return i && !(i & (i - 1));
  30878. +}
  30879. +
  30880. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  30881. +{
  30882. + WARN_ON(!is_pow2(size));
  30883. +
  30884. + queue->size = size;
  30885. + queue->read = 0;
  30886. + queue->write = 0;
  30887. +
  30888. + sema_init(&queue->pop, 0);
  30889. + sema_init(&queue->push, 0);
  30890. +
  30891. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  30892. + if (queue->storage == NULL) {
  30893. + vchiu_queue_delete(queue);
  30894. + return 0;
  30895. + }
  30896. + return 1;
  30897. +}
  30898. +
  30899. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  30900. +{
  30901. + if (queue->storage != NULL)
  30902. + kfree(queue->storage);
  30903. +}
  30904. +
  30905. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  30906. +{
  30907. + return queue->read == queue->write;
  30908. +}
  30909. +
  30910. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  30911. +{
  30912. + return queue->write == queue->read + queue->size;
  30913. +}
  30914. +
  30915. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  30916. +{
  30917. + while (queue->write == queue->read + queue->size) {
  30918. + if (down_interruptible(&queue->pop) != 0) {
  30919. + flush_signals(current);
  30920. + }
  30921. + }
  30922. +
  30923. + /*
  30924. + * Write to queue->storage must be visible after read from
  30925. + * queue->read
  30926. + */
  30927. + smp_mb();
  30928. +
  30929. + queue->storage[queue->write & (queue->size - 1)] = header;
  30930. +
  30931. + /*
  30932. + * Write to queue->storage must be visible before write to
  30933. + * queue->write
  30934. + */
  30935. + smp_wmb();
  30936. +
  30937. + queue->write++;
  30938. +
  30939. + up(&queue->push);
  30940. +}
  30941. +
  30942. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  30943. +{
  30944. + while (queue->write == queue->read) {
  30945. + if (down_interruptible(&queue->push) != 0) {
  30946. + flush_signals(current);
  30947. + }
  30948. + }
  30949. +
  30950. + up(&queue->push); // We haven't removed anything from the queue.
  30951. +
  30952. + /*
  30953. + * Read from queue->storage must be visible after read from
  30954. + * queue->write
  30955. + */
  30956. + smp_rmb();
  30957. +
  30958. + return queue->storage[queue->read & (queue->size - 1)];
  30959. +}
  30960. +
  30961. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  30962. +{
  30963. + VCHIQ_HEADER_T *header;
  30964. +
  30965. + while (queue->write == queue->read) {
  30966. + if (down_interruptible(&queue->push) != 0) {
  30967. + flush_signals(current);
  30968. + }
  30969. + }
  30970. +
  30971. + /*
  30972. + * Read from queue->storage must be visible after read from
  30973. + * queue->write
  30974. + */
  30975. + smp_rmb();
  30976. +
  30977. + header = queue->storage[queue->read & (queue->size - 1)];
  30978. +
  30979. + /*
  30980. + * Read from queue->storage must be visible before write to
  30981. + * queue->read
  30982. + */
  30983. + smp_mb();
  30984. +
  30985. + queue->read++;
  30986. +
  30987. + up(&queue->pop);
  30988. +
  30989. + return header;
  30990. +}
  30991. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  30992. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  30993. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-03-13 12:46:20.600060074 +0100
  30994. @@ -0,0 +1,82 @@
  30995. +/**
  30996. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30997. + *
  30998. + * Redistribution and use in source and binary forms, with or without
  30999. + * modification, are permitted provided that the following conditions
  31000. + * are met:
  31001. + * 1. Redistributions of source code must retain the above copyright
  31002. + * notice, this list of conditions, and the following disclaimer,
  31003. + * without modification.
  31004. + * 2. Redistributions in binary form must reproduce the above copyright
  31005. + * notice, this list of conditions and the following disclaimer in the
  31006. + * documentation and/or other materials provided with the distribution.
  31007. + * 3. The names of the above-listed copyright holders may not be used
  31008. + * to endorse or promote products derived from this software without
  31009. + * specific prior written permission.
  31010. + *
  31011. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31012. + * GNU General Public License ("GPL") version 2, as published by the Free
  31013. + * Software Foundation.
  31014. + *
  31015. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31016. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31017. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31018. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31019. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31020. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31021. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31022. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31023. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31024. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31025. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31026. + */
  31027. +
  31028. +#ifndef VCHIQ_UTIL_H
  31029. +#define VCHIQ_UTIL_H
  31030. +
  31031. +#include <linux/types.h>
  31032. +#include <linux/semaphore.h>
  31033. +#include <linux/mutex.h>
  31034. +#include <linux/bitops.h>
  31035. +#include <linux/kthread.h>
  31036. +#include <linux/wait.h>
  31037. +#include <linux/vmalloc.h>
  31038. +#include <linux/jiffies.h>
  31039. +#include <linux/delay.h>
  31040. +#include <linux/string.h>
  31041. +#include <linux/types.h>
  31042. +#include <linux/interrupt.h>
  31043. +#include <linux/random.h>
  31044. +#include <linux/sched.h>
  31045. +#include <linux/ctype.h>
  31046. +#include <linux/uaccess.h>
  31047. +#include <linux/time.h> /* for time_t */
  31048. +#include <linux/slab.h>
  31049. +#include <linux/vmalloc.h>
  31050. +
  31051. +#include "vchiq_if.h"
  31052. +
  31053. +typedef struct {
  31054. + int size;
  31055. + int read;
  31056. + int write;
  31057. +
  31058. + struct semaphore pop;
  31059. + struct semaphore push;
  31060. +
  31061. + VCHIQ_HEADER_T **storage;
  31062. +} VCHIU_QUEUE_T;
  31063. +
  31064. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  31065. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  31066. +
  31067. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  31068. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  31069. +
  31070. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  31071. +
  31072. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  31073. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  31074. +
  31075. +#endif
  31076. +
  31077. diff -Nur linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  31078. --- linux-3.10.33/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  31079. +++ linux-raspberry-pi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-03-13 12:46:20.600060074 +0100
  31080. @@ -0,0 +1,59 @@
  31081. +/**
  31082. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31083. + *
  31084. + * Redistribution and use in source and binary forms, with or without
  31085. + * modification, are permitted provided that the following conditions
  31086. + * are met:
  31087. + * 1. Redistributions of source code must retain the above copyright
  31088. + * notice, this list of conditions, and the following disclaimer,
  31089. + * without modification.
  31090. + * 2. Redistributions in binary form must reproduce the above copyright
  31091. + * notice, this list of conditions and the following disclaimer in the
  31092. + * documentation and/or other materials provided with the distribution.
  31093. + * 3. The names of the above-listed copyright holders may not be used
  31094. + * to endorse or promote products derived from this software without
  31095. + * specific prior written permission.
  31096. + *
  31097. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31098. + * GNU General Public License ("GPL") version 2, as published by the Free
  31099. + * Software Foundation.
  31100. + *
  31101. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31102. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31103. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31104. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31105. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31106. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31107. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31108. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31109. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31110. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31111. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31112. + */
  31113. +#include "vchiq_build_info.h"
  31114. +#include <linux/broadcom/vc_debug_sym.h>
  31115. +
  31116. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  31117. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  31118. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  31119. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  31120. +
  31121. +const char *vchiq_get_build_hostname( void )
  31122. +{
  31123. + return vchiq_build_hostname;
  31124. +}
  31125. +
  31126. +const char *vchiq_get_build_version( void )
  31127. +{
  31128. + return vchiq_build_version;
  31129. +}
  31130. +
  31131. +const char *vchiq_get_build_date( void )
  31132. +{
  31133. + return vchiq_build_date;
  31134. +}
  31135. +
  31136. +const char *vchiq_get_build_time( void )
  31137. +{
  31138. + return vchiq_build_time;
  31139. +}
  31140. diff -Nur linux-3.10.33/drivers/misc/vc04_services/Kconfig linux-raspberry-pi/drivers/misc/vc04_services/Kconfig
  31141. --- linux-3.10.33/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  31142. +++ linux-raspberry-pi/drivers/misc/vc04_services/Kconfig 2014-03-13 12:46:20.596060066 +0100
  31143. @@ -0,0 +1,10 @@
  31144. +config BCM2708_VCHIQ
  31145. + tristate "Videocore VCHIQ"
  31146. + depends on MACH_BCM2708
  31147. + default y
  31148. + help
  31149. + Kernel to VideoCore communication interface for the
  31150. + BCM2708 family of products.
  31151. + Defaults to Y when the Broadcom Videocore services
  31152. + are included in the build, N otherwise.
  31153. +
  31154. diff -Nur linux-3.10.33/drivers/misc/vc04_services/Makefile linux-raspberry-pi/drivers/misc/vc04_services/Makefile
  31155. --- linux-3.10.33/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  31156. +++ linux-raspberry-pi/drivers/misc/vc04_services/Makefile 2014-03-13 12:46:20.596060066 +0100
  31157. @@ -0,0 +1,18 @@
  31158. +ifeq ($(CONFIG_MACH_BCM2708),y)
  31159. +
  31160. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  31161. +
  31162. +vchiq-objs := \
  31163. + interface/vchiq_arm/vchiq_core.o \
  31164. + interface/vchiq_arm/vchiq_arm.o \
  31165. + interface/vchiq_arm/vchiq_kern_lib.o \
  31166. + interface/vchiq_arm/vchiq_2835_arm.o \
  31167. + interface/vchiq_arm/vchiq_proc.o \
  31168. + interface/vchiq_arm/vchiq_shim.o \
  31169. + interface/vchiq_arm/vchiq_util.o \
  31170. + interface/vchiq_arm/vchiq_connected.o \
  31171. +
  31172. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  31173. +
  31174. +endif
  31175. +
  31176. diff -Nur linux-3.10.33/drivers/mmc/card/block.c linux-raspberry-pi/drivers/mmc/card/block.c
  31177. --- linux-3.10.33/drivers/mmc/card/block.c 2014-03-07 06:58:45.000000000 +0100
  31178. +++ linux-raspberry-pi/drivers/mmc/card/block.c 2014-03-13 12:46:20.796060466 +0100
  31179. @@ -1333,7 +1333,7 @@
  31180. brq->data.blocks = 1;
  31181. }
  31182. - if (brq->data.blocks > 1 || do_rel_wr) {
  31183. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  31184. /* SPI multiblock writes terminate using a special
  31185. * token, not a STOP_TRANSMISSION request.
  31186. */
  31187. diff -Nur linux-3.10.33/drivers/mmc/core/sd.c linux-raspberry-pi/drivers/mmc/core/sd.c
  31188. --- linux-3.10.33/drivers/mmc/core/sd.c 2014-03-07 06:58:45.000000000 +0100
  31189. +++ linux-raspberry-pi/drivers/mmc/core/sd.c 2014-03-13 12:46:20.800060474 +0100
  31190. @@ -13,6 +13,8 @@
  31191. #include <linux/err.h>
  31192. #include <linux/slab.h>
  31193. #include <linux/stat.h>
  31194. +#include <linux/jiffies.h>
  31195. +#include <linux/nmi.h>
  31196. #include <linux/mmc/host.h>
  31197. #include <linux/mmc/card.h>
  31198. @@ -58,6 +60,15 @@
  31199. __res & __mask; \
  31200. })
  31201. +// timeout for tries
  31202. +static const unsigned long retry_timeout_ms= 10*1000;
  31203. +
  31204. +// try at least 10 times, even if timeout is reached
  31205. +static const int retry_min_tries= 10;
  31206. +
  31207. +// delay between tries
  31208. +static const unsigned long retry_delay_ms= 10;
  31209. +
  31210. /*
  31211. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  31212. */
  31213. @@ -210,12 +221,62 @@
  31214. }
  31215. /*
  31216. - * Fetch and process SD Status register.
  31217. + * Fetch and process SD Configuration Register.
  31218. + */
  31219. +static int mmc_read_scr(struct mmc_card *card)
  31220. +{
  31221. + unsigned long timeout_at;
  31222. + int err, tries;
  31223. +
  31224. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  31225. + tries= 0;
  31226. +
  31227. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  31228. + {
  31229. + unsigned long delay_at;
  31230. + tries++;
  31231. +
  31232. + err = mmc_app_send_scr(card, card->raw_scr);
  31233. + if( !err )
  31234. + break; // success!!!
  31235. +
  31236. + touch_nmi_watchdog(); // we are still alive!
  31237. +
  31238. + // delay
  31239. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  31240. + while( time_before( jiffies, delay_at ) )
  31241. + {
  31242. + mdelay( 1 );
  31243. + touch_nmi_watchdog(); // we are still alive!
  31244. + }
  31245. + }
  31246. +
  31247. + if( err)
  31248. + {
  31249. + pr_err("%s: failed to read SD Configuration register (SCR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
  31250. + return err;
  31251. + }
  31252. +
  31253. + if( tries > 1 )
  31254. + {
  31255. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  31256. + }
  31257. +
  31258. + err = mmc_decode_scr(card);
  31259. + if (err)
  31260. + return err;
  31261. +
  31262. + return err;
  31263. +}
  31264. +
  31265. +/*
  31266. + * Fetch and process SD Status Register.
  31267. */
  31268. static int mmc_read_ssr(struct mmc_card *card)
  31269. {
  31270. + unsigned long timeout_at;
  31271. unsigned int au, es, et, eo;
  31272. - int err, i;
  31273. + int err, i, tries;
  31274. u32 *ssr;
  31275. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  31276. @@ -227,15 +288,41 @@
  31277. ssr = kmalloc(64, GFP_KERNEL);
  31278. if (!ssr)
  31279. return -ENOMEM;
  31280. -
  31281. - err = mmc_app_sd_status(card, ssr);
  31282. - if (err) {
  31283. - pr_warning("%s: problem reading SD Status "
  31284. - "register.\n", mmc_hostname(card->host));
  31285. - err = 0;
  31286. +
  31287. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  31288. + tries= 0;
  31289. +
  31290. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  31291. + {
  31292. + unsigned long delay_at;
  31293. + tries++;
  31294. +
  31295. + err= mmc_app_sd_status(card, ssr);
  31296. + if( !err )
  31297. + break; // sucess!!!
  31298. +
  31299. + touch_nmi_watchdog(); // we are still alive!
  31300. +
  31301. + // delay
  31302. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  31303. + while( time_before( jiffies, delay_at ) )
  31304. + {
  31305. + mdelay( 1 );
  31306. + touch_nmi_watchdog(); // we are still alive!
  31307. + }
  31308. + }
  31309. +
  31310. + if( err)
  31311. + {
  31312. + pr_err("%s: failed to read SD Status register (SSR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
  31313. goto out;
  31314. }
  31315. + if( tries > 1 )
  31316. + {
  31317. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  31318. + }
  31319. +
  31320. for (i = 0; i < 16; i++)
  31321. ssr[i] = be32_to_cpu(ssr[i]);
  31322. @@ -808,15 +895,11 @@
  31323. if (!reinit) {
  31324. /*
  31325. - * Fetch SCR from card.
  31326. + * Fetch and decode SD Configuration register.
  31327. */
  31328. - err = mmc_app_send_scr(card, card->raw_scr);
  31329. - if (err)
  31330. - return err;
  31331. -
  31332. - err = mmc_decode_scr(card);
  31333. - if (err)
  31334. - return err;
  31335. + err = mmc_read_scr(card);
  31336. + if( err )
  31337. + return err;
  31338. /*
  31339. * Fetch and process SD Status register.
  31340. diff -Nur linux-3.10.33/drivers/mmc/host/Kconfig linux-raspberry-pi/drivers/mmc/host/Kconfig
  31341. --- linux-3.10.33/drivers/mmc/host/Kconfig 2014-03-07 06:58:45.000000000 +0100
  31342. +++ linux-raspberry-pi/drivers/mmc/host/Kconfig 2014-03-13 12:46:20.804060482 +0100
  31343. @@ -249,6 +249,27 @@
  31344. YMMV.
  31345. +config MMC_SDHCI_BCM2708
  31346. + tristate "SDHCI support on BCM2708"
  31347. + depends on MMC_SDHCI && MACH_BCM2708
  31348. + select MMC_SDHCI_IO_ACCESSORS
  31349. + help
  31350. + This selects the Secure Digital Host Controller Interface (SDHCI)
  31351. + often referrered to as the eMMC block.
  31352. +
  31353. + If you have a controller with this interface, say Y or M here.
  31354. +
  31355. + If unsure, say N.
  31356. +
  31357. +config MMC_SDHCI_BCM2708_DMA
  31358. + bool "DMA support on BCM2708 Arasan controller"
  31359. + depends on MMC_SDHCI_BCM2708
  31360. + help
  31361. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  31362. + based chips.
  31363. +
  31364. + If unsure, say N.
  31365. +
  31366. config MMC_SDHCI_BCM2835
  31367. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  31368. depends on ARCH_BCM2835
  31369. diff -Nur linux-3.10.33/drivers/mmc/host/Makefile linux-raspberry-pi/drivers/mmc/host/Makefile
  31370. --- linux-3.10.33/drivers/mmc/host/Makefile 2014-03-07 06:58:45.000000000 +0100
  31371. +++ linux-raspberry-pi/drivers/mmc/host/Makefile 2014-03-13 12:46:20.804060482 +0100
  31372. @@ -15,6 +15,7 @@
  31373. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  31374. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  31375. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  31376. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  31377. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  31378. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  31379. obj-$(CONFIG_MMC_OMAP) += omap.o
  31380. diff -Nur linux-3.10.33/drivers/mmc/host/sdhci-bcm2708.c linux-raspberry-pi/drivers/mmc/host/sdhci-bcm2708.c
  31381. --- linux-3.10.33/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  31382. +++ linux-raspberry-pi/drivers/mmc/host/sdhci-bcm2708.c 2014-03-13 12:46:21.004060883 +0100
  31383. @@ -0,0 +1,1410 @@
  31384. +/*
  31385. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  31386. + * Copyright (c) 2010 Broadcom
  31387. + *
  31388. + * This program is free software; you can redistribute it and/or modify
  31389. + * it under the terms of the GNU General Public License version 2 as
  31390. + * published by the Free Software Foundation.
  31391. + *
  31392. + * This program is distributed in the hope that it will be useful,
  31393. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31394. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31395. + * GNU General Public License for more details.
  31396. + *
  31397. + * You should have received a copy of the GNU General Public License
  31398. + * along with this program; if not, write to the Free Software
  31399. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31400. + */
  31401. +
  31402. +/* Supports:
  31403. + * SDHCI platform device - Arasan SD controller in BCM2708
  31404. + *
  31405. + * Inspired by sdhci-pci.c, by Pierre Ossman
  31406. + */
  31407. +
  31408. +#include <linux/delay.h>
  31409. +#include <linux/highmem.h>
  31410. +#include <linux/platform_device.h>
  31411. +#include <linux/module.h>
  31412. +#include <linux/mmc/mmc.h>
  31413. +#include <linux/mmc/host.h>
  31414. +#include <linux/mmc/sd.h>
  31415. +
  31416. +#include <linux/io.h>
  31417. +#include <linux/dma-mapping.h>
  31418. +#include <mach/dma.h>
  31419. +
  31420. +#include "sdhci.h"
  31421. +
  31422. +/*****************************************************************************\
  31423. + * *
  31424. + * Configuration *
  31425. + * *
  31426. +\*****************************************************************************/
  31427. +
  31428. +#define DRIVER_NAME "bcm2708_sdhci"
  31429. +
  31430. +/* for the time being insist on DMA mode - PIO seems not to work */
  31431. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  31432. +#warning Non-DMA (PIO) version of this driver currently unavailable
  31433. +#endif
  31434. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  31435. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  31436. +
  31437. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31438. +/* #define CHECK_DMA_USE */
  31439. +#endif
  31440. +//#define LOG_REGISTERS
  31441. +
  31442. +#define USE_SCHED_TIME
  31443. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  31444. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  31445. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  31446. +
  31447. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  31448. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  31449. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  31450. +
  31451. +/*! TODO: obtain these from the physical address */
  31452. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  31453. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  31454. +
  31455. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  31456. +
  31457. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  31458. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  31459. +
  31460. +#define REG_EXRDFIFO_EN 0x80
  31461. +#define REG_EXRDFIFO_CFG 0x84
  31462. +
  31463. +int cycle_delay=2;
  31464. +
  31465. +/*****************************************************************************\
  31466. + * *
  31467. + * Debug *
  31468. + * *
  31469. +\*****************************************************************************/
  31470. +
  31471. +
  31472. +
  31473. +#define DBG(f, x...) \
  31474. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  31475. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  31476. +
  31477. +
  31478. +/*****************************************************************************\
  31479. + * *
  31480. + * High Precision Time *
  31481. + * *
  31482. +\*****************************************************************************/
  31483. +
  31484. +#ifdef USE_SCHED_TIME
  31485. +
  31486. +#include <mach/frc.h>
  31487. +
  31488. +typedef unsigned long hptime_t;
  31489. +
  31490. +#define FMT_HPT "lu"
  31491. +
  31492. +static inline hptime_t hptime(void)
  31493. +{
  31494. + return frc_clock_ticks32();
  31495. +}
  31496. +
  31497. +#define HPTIME_CLK_NS 1000ul
  31498. +
  31499. +#else
  31500. +
  31501. +typedef unsigned long hptime_t;
  31502. +
  31503. +#define FMT_HPT "lu"
  31504. +
  31505. +static inline hptime_t hptime(void)
  31506. +{
  31507. + return jiffies;
  31508. +}
  31509. +
  31510. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  31511. +
  31512. +#endif
  31513. +
  31514. +static inline unsigned long int since_ns(hptime_t t)
  31515. +{
  31516. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  31517. +}
  31518. +
  31519. +static bool allow_highspeed = 1;
  31520. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  31521. +static bool sync_after_dma = 1;
  31522. +static bool missing_status = 1;
  31523. +static bool spurious_crc_acmd51 = 0;
  31524. +bool enable_llm = 1;
  31525. +bool extra_messages = 0;
  31526. +
  31527. +#if 0
  31528. +static void hptime_test(void)
  31529. +{
  31530. + hptime_t now;
  31531. + hptime_t later;
  31532. +
  31533. + now = hptime();
  31534. + msleep(10);
  31535. + later = hptime();
  31536. +
  31537. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  31538. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  31539. + later-now, now, later,
  31540. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  31541. +
  31542. + now = hptime();
  31543. + msleep(1000);
  31544. + later = hptime();
  31545. +
  31546. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  31547. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  31548. + later-now, now, later,
  31549. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  31550. +}
  31551. +#endif
  31552. +
  31553. +/*****************************************************************************\
  31554. + * *
  31555. + * SDHCI core callbacks *
  31556. + * *
  31557. +\*****************************************************************************/
  31558. +
  31559. +
  31560. +#ifdef CHECK_DMA_USE
  31561. +/*#define CHECK_DMA_REG_USE*/
  31562. +#endif
  31563. +
  31564. +#ifdef CHECK_DMA_REG_USE
  31565. +/* we don't expect anything to be using these registers during a
  31566. + DMA (except the IRQ status) - so check */
  31567. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  31568. +#else
  31569. +#define check_dma_reg_use(host, reg)
  31570. +#endif
  31571. +
  31572. +
  31573. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  31574. +{
  31575. + return readl(host->ioaddr + reg);
  31576. +}
  31577. +
  31578. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  31579. +{
  31580. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  31581. +
  31582. +#ifdef LOG_REGISTERS
  31583. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  31584. + mmc_hostname(host->mmc), reg, l);
  31585. +#endif
  31586. + check_dma_reg_use(host, reg);
  31587. +
  31588. + return l;
  31589. +}
  31590. +
  31591. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  31592. +{
  31593. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31594. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  31595. +
  31596. +#ifdef LOG_REGISTERS
  31597. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  31598. + mmc_hostname(host->mmc), reg, w);
  31599. +#endif
  31600. + check_dma_reg_use(host, reg);
  31601. +
  31602. + return (u16)w;
  31603. +}
  31604. +
  31605. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  31606. +{
  31607. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31608. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  31609. +
  31610. +#ifdef LOG_REGISTERS
  31611. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  31612. + mmc_hostname(host->mmc), reg, b);
  31613. +#endif
  31614. + check_dma_reg_use(host, reg);
  31615. +
  31616. + return (u8)b;
  31617. +}
  31618. +
  31619. +
  31620. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  31621. +{
  31622. + u32 ier;
  31623. +
  31624. +#if USE_SPACED_WRITES_2CLK
  31625. + static bool timeout_disabled = false;
  31626. + unsigned int ns_2clk = 0;
  31627. +
  31628. + /* The Arasan has a bugette whereby it may lose the content of
  31629. + * successive writes to registers that are within two SD-card clock
  31630. + * cycles of each other (a clock domain crossing problem).
  31631. + * It seems, however, that the data register does not have this problem.
  31632. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  31633. + * too)
  31634. + */
  31635. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  31636. + /* host->clock is the clock freq in Hz */
  31637. + static hptime_t last_write_hpt;
  31638. + hptime_t now = hptime();
  31639. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  31640. +
  31641. + if (now == last_write_hpt || now == last_write_hpt+1) {
  31642. + /* we can't guarantee any significant time has
  31643. + * passed - we'll have to wait anyway ! */
  31644. + ndelay(ns_2clk);
  31645. + } else
  31646. + {
  31647. + /* we must have waited at least this many ns: */
  31648. + unsigned int ns_wait = HPTIME_CLK_NS *
  31649. + (last_write_hpt - now - 1);
  31650. + if (ns_wait < ns_2clk)
  31651. + ndelay(ns_2clk - ns_wait);
  31652. + }
  31653. + last_write_hpt = now;
  31654. + }
  31655. +#if USE_SOFTWARE_TIMEOUTS
  31656. + /* The Arasan is clocked for timeouts using the SD clock which is too
  31657. + * fast for ERASE commands and causes issues. So we disable timeouts
  31658. + * for ERASE */
  31659. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  31660. + reg == (SDHCI_COMMAND & ~3)) {
  31661. + mod_timer(&host->timer,
  31662. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  31663. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31664. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  31665. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31666. + timeout_disabled = true;
  31667. + ndelay(ns_2clk);
  31668. + } else if (timeout_disabled) {
  31669. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31670. + ier |= SDHCI_INT_DATA_TIMEOUT;
  31671. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31672. + timeout_disabled = false;
  31673. + ndelay(ns_2clk);
  31674. + }
  31675. +#endif
  31676. + writel(val, host->ioaddr + reg);
  31677. +#else
  31678. + void __iomem * regaddr = host->ioaddr + reg;
  31679. +
  31680. + writel(val, regaddr);
  31681. +
  31682. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  31683. + {
  31684. + int timeout = 100000;
  31685. + while (val != readl(regaddr) && --timeout > 0)
  31686. + continue;
  31687. +
  31688. + if (timeout <= 0)
  31689. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  31690. + "always gives 0x%X\n",
  31691. + mmc_hostname(host->mmc),
  31692. + val, reg, readl(regaddr));
  31693. + BUG_ON(timeout <= 0);
  31694. + }
  31695. +#endif
  31696. +}
  31697. +
  31698. +
  31699. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  31700. +{
  31701. +#ifdef LOG_REGISTERS
  31702. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  31703. + mmc_hostname(host->mmc), reg, val);
  31704. +#endif
  31705. + check_dma_reg_use(host, reg);
  31706. +
  31707. + sdhci_bcm2708_raw_writel(host, val, reg);
  31708. +}
  31709. +
  31710. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  31711. +{
  31712. + static u32 shadow = 0;
  31713. +
  31714. + u32 p = reg == SDHCI_COMMAND ? shadow :
  31715. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  31716. + u32 s = reg << 3 & 0x18;
  31717. + u32 l = val << s;
  31718. + u32 m = 0xffff << s;
  31719. +
  31720. +#ifdef LOG_REGISTERS
  31721. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  31722. + mmc_hostname(host->mmc), reg, val);
  31723. +#endif
  31724. +
  31725. + if (reg == SDHCI_TRANSFER_MODE)
  31726. + shadow = (p & ~m) | l;
  31727. + else {
  31728. + check_dma_reg_use(host, reg);
  31729. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31730. + }
  31731. +}
  31732. +
  31733. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  31734. +{
  31735. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31736. + u32 s = reg << 3 & 0x18;
  31737. + u32 l = val << s;
  31738. + u32 m = 0xff << s;
  31739. +
  31740. +#ifdef LOG_REGISTERS
  31741. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  31742. + mmc_hostname(host->mmc), reg, val);
  31743. +#endif
  31744. +
  31745. + check_dma_reg_use(host, reg);
  31746. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31747. +}
  31748. +
  31749. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  31750. +{
  31751. + return emmc_clock_freq;
  31752. +}
  31753. +
  31754. +/*****************************************************************************\
  31755. + * *
  31756. + * DMA Operation *
  31757. + * *
  31758. +\*****************************************************************************/
  31759. +
  31760. +struct sdhci_bcm2708_priv {
  31761. + int dma_chan;
  31762. + int dma_irq;
  31763. + void __iomem *dma_chan_base;
  31764. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  31765. + dma_addr_t cb_handle;
  31766. + /* tracking scatter gather progress */
  31767. + unsigned sg_ix; /* scatter gather list index */
  31768. + unsigned sg_done; /* bytes in current sg_ix done */
  31769. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31770. + unsigned char dma_wanted; /* DMA transfer requested */
  31771. + unsigned char dma_waits; /* wait states in DMAs */
  31772. +#ifdef CHECK_DMA_USE
  31773. + unsigned char dmas_pending; /* no of unfinished DMAs */
  31774. + hptime_t when_started;
  31775. + hptime_t when_reset;
  31776. + hptime_t when_stopped;
  31777. +#endif
  31778. +#endif
  31779. + /* signalling the end of a transfer */
  31780. + void (*complete)(struct sdhci_host *);
  31781. +};
  31782. +
  31783. +#define SDHCI_HOST_PRIV(host) \
  31784. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  31785. +
  31786. +
  31787. +
  31788. +#ifdef CHECK_DMA_REG_USE
  31789. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  31790. +{
  31791. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31792. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  31793. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  31794. + mmc_hostname(host->mmc), reg);
  31795. + }
  31796. +}
  31797. +#endif
  31798. +
  31799. +
  31800. +
  31801. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31802. +
  31803. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  31804. +{
  31805. + u32 ier;
  31806. +
  31807. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  31808. + ier &= ~clear;
  31809. + ier |= set;
  31810. + /* change which requests generate IRQs - makes no difference to
  31811. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  31812. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  31813. +}
  31814. +
  31815. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  31816. +{
  31817. + sdhci_clear_set_irqgen(host, 0, irqs);
  31818. +}
  31819. +
  31820. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  31821. +{
  31822. + sdhci_clear_set_irqgen(host, irqs, 0);
  31823. +}
  31824. +
  31825. +
  31826. +
  31827. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  31828. + int ix,
  31829. + dma_addr_t dma_addr, unsigned len,
  31830. + int /*bool*/ is_last)
  31831. +{
  31832. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31833. + unsigned char dmawaits = host->dma_waits;
  31834. +
  31835. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31836. + BCM2708_DMA_WAITS(dmawaits) |
  31837. + BCM2708_DMA_S_DREQ |
  31838. + BCM2708_DMA_D_WIDTH |
  31839. + BCM2708_DMA_D_INC;
  31840. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31841. + cb->dst = dma_addr;
  31842. + cb->length = len;
  31843. + cb->stride = 0;
  31844. +
  31845. + if (is_last) {
  31846. + cb->info |= BCM2708_DMA_INT_EN |
  31847. + BCM2708_DMA_WAIT_RESP;
  31848. + cb->next = 0;
  31849. + } else
  31850. + cb->next = host->cb_handle +
  31851. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31852. +
  31853. + cb->pad[0] = 0;
  31854. + cb->pad[1] = 0;
  31855. +}
  31856. +
  31857. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  31858. + int ix,
  31859. + dma_addr_t dma_addr, unsigned len,
  31860. + int /*bool*/ is_last)
  31861. +{
  31862. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31863. + unsigned char dmawaits = host->dma_waits;
  31864. +
  31865. + /* We can make arbitrarily large writes as long as we specify DREQ to
  31866. + pace the delivery of bytes to the Arasan hardware */
  31867. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31868. + BCM2708_DMA_WAITS(dmawaits) |
  31869. + BCM2708_DMA_D_DREQ |
  31870. + BCM2708_DMA_S_WIDTH |
  31871. + BCM2708_DMA_S_INC;
  31872. + cb->src = dma_addr;
  31873. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31874. + cb->length = len;
  31875. + cb->stride = 0;
  31876. +
  31877. + if (is_last) {
  31878. + cb->info |= BCM2708_DMA_INT_EN |
  31879. + BCM2708_DMA_WAIT_RESP;
  31880. + cb->next = 0;
  31881. + } else
  31882. + cb->next = host->cb_handle +
  31883. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31884. +
  31885. + cb->pad[0] = 0;
  31886. + cb->pad[1] = 0;
  31887. +}
  31888. +
  31889. +
  31890. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  31891. +{
  31892. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31893. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  31894. +
  31895. + BUG_ON(host_priv->dma_wanted);
  31896. +#ifdef CHECK_DMA_USE
  31897. + if (host_priv->dma_wanted)
  31898. + printk(KERN_ERR "%s: DMA already in progress - "
  31899. + "now %"FMT_HPT", last started %lu "
  31900. + "reset %lu stopped %lu\n",
  31901. + mmc_hostname(host->mmc),
  31902. + hptime(), since_ns(host_priv->when_started),
  31903. + since_ns(host_priv->when_reset),
  31904. + since_ns(host_priv->when_stopped));
  31905. + else if (host_priv->dmas_pending > 0)
  31906. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  31907. + "already in progress - "
  31908. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  31909. + mmc_hostname(host->mmc),
  31910. + host_priv->dmas_pending,
  31911. + hptime(), since_ns(host_priv->when_started),
  31912. + since_ns(host_priv->when_reset),
  31913. + since_ns(host_priv->when_stopped));
  31914. + host_priv->dmas_pending += 1;
  31915. + host_priv->when_started = hptime();
  31916. +#endif
  31917. + host_priv->dma_wanted = 1;
  31918. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  31919. + host_priv->cb_handle);
  31920. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  31921. +}
  31922. +
  31923. +
  31924. +static void
  31925. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31926. +{
  31927. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31928. +
  31929. + DBG("PDMA to read %d bytes\n", len);
  31930. + host_priv->sg_done += len;
  31931. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31932. + schci_bcm2708_dma_go(host);
  31933. +}
  31934. +
  31935. +
  31936. +static void
  31937. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31938. +{
  31939. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31940. +
  31941. + DBG("PDMA to write %d bytes\n", len);
  31942. + //BUG_ON(0 != (len & 0x1ff));
  31943. +
  31944. + host_priv->sg_done += len;
  31945. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31946. + schci_bcm2708_dma_go(host);
  31947. +}
  31948. +
  31949. +/*! space is avaiable to receive into or data is available to write
  31950. + Platform DMA exported function
  31951. +*/
  31952. +void
  31953. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  31954. + void(*completion_callback)(struct sdhci_host *host))
  31955. +{
  31956. + struct mmc_data *data = host->data;
  31957. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31958. + int sg_ix;
  31959. + size_t bytes;
  31960. + dma_addr_t addr;
  31961. +
  31962. + BUG_ON(NULL == data);
  31963. + BUG_ON(0 == data->blksz);
  31964. +
  31965. + host_priv->complete = completion_callback;
  31966. +
  31967. + sg_ix = host_priv->sg_ix;
  31968. + BUG_ON(sg_ix >= data->sg_len);
  31969. +
  31970. + /* we can DMA blocks larger than blksz - it may hang the DMA
  31971. + channel but we are its only user */
  31972. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  31973. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  31974. +
  31975. + if (bytes > 0) {
  31976. + /* We're going to poll for read/write available state until
  31977. + we finish this DMA
  31978. + */
  31979. +
  31980. + if (data->flags & MMC_DATA_READ) {
  31981. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  31982. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31983. + SDHCI_INT_SPACE_AVAIL);
  31984. + sdhci_platdma_read(host, addr, bytes);
  31985. + }
  31986. + } else {
  31987. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  31988. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31989. + SDHCI_INT_SPACE_AVAIL);
  31990. + sdhci_platdma_write(host, addr, bytes);
  31991. + }
  31992. + }
  31993. + }
  31994. + /* else:
  31995. + we have run out of bytes that need transferring (e.g. we may be in
  31996. + the middle of the last DMA transfer), or
  31997. + it is also possible that we've been called when another IRQ is
  31998. + signalled, even though we've turned off signalling of our own IRQ */
  31999. +
  32000. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  32001. + /* don't let the main sdhci driver act on this .. we'll deal with it
  32002. + when we respond to the DMA - if one is currently in progress */
  32003. +}
  32004. +
  32005. +/* is it possible to DMA the given mmc_data structure?
  32006. + Platform DMA exported function
  32007. +*/
  32008. +int /*bool*/
  32009. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32010. +{
  32011. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32012. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  32013. +
  32014. + if (!ok)
  32015. + DBG("Reverting to PIO - bad cache alignment\n");
  32016. +
  32017. + else {
  32018. + host_priv->sg_ix = 0; /* first SG index */
  32019. + host_priv->sg_done = 0; /* no bytes done */
  32020. + }
  32021. +
  32022. + return ok;
  32023. +}
  32024. +
  32025. +#include <mach/arm_control.h> //GRAYG
  32026. +/*! the current SD transacton has been abandonned
  32027. + We need to tidy up if we were in the middle of a DMA
  32028. + Platform DMA exported function
  32029. +*/
  32030. +void
  32031. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32032. +{
  32033. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32034. +// unsigned long flags;
  32035. +
  32036. + BUG_ON(NULL == host);
  32037. +
  32038. +// spin_lock_irqsave(&host->lock, flags);
  32039. +
  32040. + if (host_priv->dma_wanted) {
  32041. + if (NULL == data) {
  32042. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  32043. + mmc_hostname(host->mmc));
  32044. + BUG_ON(NULL == data);
  32045. + } else {
  32046. + struct scatterlist *sg;
  32047. + int sg_len;
  32048. + int sg_todo;
  32049. + int rc;
  32050. + unsigned long cs;
  32051. +
  32052. + sg = data->sg;
  32053. + sg_len = data->sg_len;
  32054. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  32055. +
  32056. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  32057. +
  32058. + if (!(BCM2708_DMA_ACTIVE & cs))
  32059. + {
  32060. + if (extra_messages)
  32061. + printk(KERN_INFO "%s: missed completion of "
  32062. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  32063. + "ignoring it\n",
  32064. + mmc_hostname(host->mmc),
  32065. + host->last_cmdop,
  32066. + host_priv->sg_done, sg_todo,
  32067. + host_priv->sg_ix+1, sg_len);
  32068. + }
  32069. + else
  32070. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  32071. + "DMA before %d/%d [%d]/[%d] complete\n",
  32072. + mmc_hostname(host->mmc),
  32073. + host->last_cmdop,
  32074. + host_priv->sg_done, sg_todo,
  32075. + host_priv->sg_ix+1, sg_len);
  32076. +#ifdef CHECK_DMA_USE
  32077. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  32078. + "last reset %lu last stopped %lu\n",
  32079. + mmc_hostname(host->mmc),
  32080. + hptime(), since_ns(host_priv->when_started),
  32081. + since_ns(host_priv->when_reset),
  32082. + since_ns(host_priv->when_stopped));
  32083. + { unsigned long info, debug;
  32084. + void __iomem *base;
  32085. + unsigned long pend0, pend1, pend2;
  32086. +
  32087. + base = host_priv->dma_chan_base;
  32088. + cs = readl(base + BCM2708_DMA_CS);
  32089. + info = readl(base + BCM2708_DMA_INFO);
  32090. + debug = readl(base + BCM2708_DMA_DEBUG);
  32091. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  32092. + "DEBUG=%08lX\n",
  32093. + mmc_hostname(host->mmc),
  32094. + host_priv->dma_chan,
  32095. + cs, info, debug);
  32096. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  32097. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  32098. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  32099. +
  32100. + printk(KERN_INFO "%s: PEND0=%08lX "
  32101. + "PEND1=%08lX PEND2=%08lX\n",
  32102. + mmc_hostname(host->mmc),
  32103. + pend0, pend1, pend2);
  32104. +
  32105. + //gintsts = readl(__io_address(GINTSTS));
  32106. + //gintmsk = readl(__io_address(GINTMSK));
  32107. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  32108. + // "GINTMSK=%08lX\n",
  32109. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  32110. + }
  32111. +#endif
  32112. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  32113. + BUG_ON(rc != 0);
  32114. + }
  32115. + host_priv->dma_wanted = 0;
  32116. +#ifdef CHECK_DMA_USE
  32117. + host_priv->when_reset = hptime();
  32118. +#endif
  32119. + }
  32120. +
  32121. +// spin_unlock_irqrestore(&host->lock, flags);
  32122. +}
  32123. +
  32124. +
  32125. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  32126. + u32 dma_cs)
  32127. +{
  32128. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32129. + struct mmc_data *data;
  32130. + struct scatterlist *sg;
  32131. + int sg_len;
  32132. + int sg_ix;
  32133. + int sg_todo;
  32134. +// unsigned long flags;
  32135. +
  32136. + BUG_ON(NULL == host);
  32137. +
  32138. +// spin_lock_irqsave(&host->lock, flags);
  32139. + data = host->data;
  32140. +
  32141. +#ifdef CHECK_DMA_USE
  32142. + if (host_priv->dmas_pending <= 0)
  32143. + DBG("on completion no DMA in progress - "
  32144. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  32145. + hptime(), since_ns(host_priv->when_started),
  32146. + since_ns(host_priv->when_reset),
  32147. + since_ns(host_priv->when_stopped));
  32148. + else if (host_priv->dmas_pending > 1)
  32149. + DBG("still %d DMA in progress after completion - "
  32150. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  32151. + host_priv->dmas_pending - 1,
  32152. + hptime(), since_ns(host_priv->when_started),
  32153. + since_ns(host_priv->when_reset),
  32154. + since_ns(host_priv->when_stopped));
  32155. + BUG_ON(host_priv->dmas_pending <= 0);
  32156. + host_priv->dmas_pending -= 1;
  32157. + host_priv->when_stopped = hptime();
  32158. +#endif
  32159. + host_priv->dma_wanted = 0;
  32160. +
  32161. + if (NULL == data) {
  32162. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  32163. +// spin_unlock_irqrestore(&host->lock, flags);
  32164. + return;
  32165. + }
  32166. + sg = data->sg;
  32167. + sg_len = data->sg_len;
  32168. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  32169. +
  32170. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  32171. + host_priv->sg_done, sg_todo,
  32172. + host_priv->sg_ix+1, sg_len);
  32173. +
  32174. + BUG_ON(host_priv->sg_done > sg_todo);
  32175. +
  32176. + if (host_priv->sg_done >= sg_todo) {
  32177. + host_priv->sg_ix++;
  32178. + host_priv->sg_done = 0;
  32179. + }
  32180. +
  32181. + sg_ix = host_priv->sg_ix;
  32182. + if (sg_ix < sg_len) {
  32183. + u32 irq_mask;
  32184. + /* Set off next DMA if we've got the capacity */
  32185. +
  32186. + if (data->flags & MMC_DATA_READ)
  32187. + irq_mask = SDHCI_INT_DATA_AVAIL;
  32188. + else
  32189. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  32190. +
  32191. + /* We have to use the interrupt status register on the BCM2708
  32192. + rather than the SDHCI_PRESENT_STATE register because latency
  32193. + in the glue logic means that the information retrieved from
  32194. + the latter is not always up-to-date w.r.t the DMA engine -
  32195. + it may not indicate that a read or a write is ready yet */
  32196. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  32197. + irq_mask) {
  32198. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  32199. + host_priv->sg_done;
  32200. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  32201. + host_priv->sg_done;
  32202. +
  32203. + /* acknowledge interrupt */
  32204. + sdhci_bcm2708_raw_writel(host, irq_mask,
  32205. + SDHCI_INT_STATUS);
  32206. +
  32207. + BUG_ON(0 == bytes);
  32208. +
  32209. + if (data->flags & MMC_DATA_READ)
  32210. + sdhci_platdma_read(host, addr, bytes);
  32211. + else
  32212. + sdhci_platdma_write(host, addr, bytes);
  32213. + } else {
  32214. + DBG("PDMA - wait avail\n");
  32215. + /* may generate an IRQ if already present */
  32216. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  32217. + SDHCI_INT_SPACE_AVAIL);
  32218. + }
  32219. + } else {
  32220. + if (sync_after_dma) {
  32221. + /* On the Arasan controller the stop command (which will be
  32222. + scheduled after this completes) does not seem to work
  32223. + properly if we allow it to be issued when we are
  32224. + transferring data to/from the SD card.
  32225. + We get CRC and DEND errors unless we wait for
  32226. + the SD controller to finish reading/writing to the card. */
  32227. + u32 state_mask;
  32228. + int timeout=3*1000*1000;
  32229. +
  32230. + DBG("PDMA over - sync card\n");
  32231. + if (data->flags & MMC_DATA_READ)
  32232. + state_mask = SDHCI_DOING_READ;
  32233. + else
  32234. + state_mask = SDHCI_DOING_WRITE;
  32235. +
  32236. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  32237. + & state_mask) && --timeout > 0)
  32238. + {
  32239. + udelay(1);
  32240. + continue;
  32241. + }
  32242. + if (timeout <= 0)
  32243. + printk(KERN_ERR"%s: final %s to SD card still "
  32244. + "running\n",
  32245. + mmc_hostname(host->mmc),
  32246. + data->flags & MMC_DATA_READ? "read": "write");
  32247. + }
  32248. + if (host_priv->complete) {
  32249. + (*host_priv->complete)(host);
  32250. + DBG("PDMA %s complete\n",
  32251. + data->flags & MMC_DATA_READ?"read":"write");
  32252. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  32253. + SDHCI_INT_SPACE_AVAIL);
  32254. + }
  32255. + }
  32256. +// spin_unlock_irqrestore(&host->lock, flags);
  32257. +}
  32258. +
  32259. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  32260. +{
  32261. + irqreturn_t result = IRQ_NONE;
  32262. + struct sdhci_host *host = dev_id;
  32263. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32264. + u32 dma_cs; /* control and status register */
  32265. +
  32266. + BUG_ON(NULL == dev_id);
  32267. + BUG_ON(NULL == host_priv->dma_chan_base);
  32268. +
  32269. + sdhci_spin_lock(host);
  32270. +
  32271. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  32272. +
  32273. + if (dma_cs & BCM2708_DMA_ERR) {
  32274. + unsigned long debug;
  32275. + debug = readl(host_priv->dma_chan_base +
  32276. + BCM2708_DMA_DEBUG);
  32277. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  32278. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  32279. + (unsigned long)debug);
  32280. + /* reset error */
  32281. + writel(debug, host_priv->dma_chan_base +
  32282. + BCM2708_DMA_DEBUG);
  32283. + }
  32284. + if (dma_cs & BCM2708_DMA_INT) {
  32285. + /* acknowledge interrupt */
  32286. + writel(BCM2708_DMA_INT,
  32287. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  32288. +
  32289. + dsb(); /* ARM data synchronization (push) operation */
  32290. +
  32291. + if (!host_priv->dma_wanted) {
  32292. + /* ignore this interrupt - it was reset */
  32293. + if (extra_messages)
  32294. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  32295. + "results were reset\n",
  32296. + mmc_hostname(host->mmc), dma_cs);
  32297. +#ifdef CHECK_DMA_USE
  32298. + printk(KERN_INFO "%s: now %"FMT_HPT
  32299. + " started %lu reset %lu stopped %lu\n",
  32300. + mmc_hostname(host->mmc), hptime(),
  32301. + since_ns(host_priv->when_started),
  32302. + since_ns(host_priv->when_reset),
  32303. + since_ns(host_priv->when_stopped));
  32304. + host_priv->dmas_pending--;
  32305. +#endif
  32306. + } else
  32307. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  32308. +
  32309. + result = IRQ_HANDLED;
  32310. + }
  32311. + sdhci_spin_unlock(host);
  32312. +
  32313. + return result;
  32314. +}
  32315. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  32316. +
  32317. +
  32318. +/***************************************************************************** \
  32319. + * *
  32320. + * Device Attributes *
  32321. + * *
  32322. +\*****************************************************************************/
  32323. +
  32324. +
  32325. +/**
  32326. + * Show the DMA-using status
  32327. + */
  32328. +static ssize_t attr_dma_show(struct device *_dev,
  32329. + struct device_attribute *attr, char *buf)
  32330. +{
  32331. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32332. +
  32333. + if (host) {
  32334. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  32335. + return sprintf(buf, "%d\n", use_dma);
  32336. + } else
  32337. + return -EINVAL;
  32338. +}
  32339. +
  32340. +/**
  32341. + * Set the DMA-using status
  32342. + */
  32343. +static ssize_t attr_dma_store(struct device *_dev,
  32344. + struct device_attribute *attr,
  32345. + const char *buf, size_t count)
  32346. +{
  32347. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32348. +
  32349. + if (host) {
  32350. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32351. + int on = simple_strtol(buf, NULL, 0);
  32352. + if (on) {
  32353. + host->flags |= SDHCI_USE_PLATDMA;
  32354. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  32355. + printk(KERN_INFO "%s: DMA enabled\n",
  32356. + mmc_hostname(host->mmc));
  32357. + } else {
  32358. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  32359. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  32360. + printk(KERN_INFO "%s: DMA disabled\n",
  32361. + mmc_hostname(host->mmc));
  32362. + }
  32363. +#endif
  32364. + return count;
  32365. + } else
  32366. + return -EINVAL;
  32367. +}
  32368. +
  32369. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  32370. +
  32371. +
  32372. +/**
  32373. + * Show the DMA wait states used
  32374. + */
  32375. +static ssize_t attr_dmawait_show(struct device *_dev,
  32376. + struct device_attribute *attr, char *buf)
  32377. +{
  32378. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32379. +
  32380. + if (host) {
  32381. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32382. + int dmawait = host_priv->dma_waits;
  32383. + return sprintf(buf, "%d\n", dmawait);
  32384. + } else
  32385. + return -EINVAL;
  32386. +}
  32387. +
  32388. +/**
  32389. + * Set the DMA wait state used
  32390. + */
  32391. +static ssize_t attr_dmawait_store(struct device *_dev,
  32392. + struct device_attribute *attr,
  32393. + const char *buf, size_t count)
  32394. +{
  32395. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32396. +
  32397. + if (host) {
  32398. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32399. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32400. + int dma_waits = simple_strtol(buf, NULL, 0);
  32401. + if (dma_waits >= 0 && dma_waits < 32)
  32402. + host_priv->dma_waits = dma_waits;
  32403. + else
  32404. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  32405. + mmc_hostname(host->mmc), dma_waits);
  32406. +#endif
  32407. + return count;
  32408. + } else
  32409. + return -EINVAL;
  32410. +}
  32411. +
  32412. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  32413. + attr_dmawait_show, attr_dmawait_store);
  32414. +
  32415. +
  32416. +/**
  32417. + * Show the DMA-using status
  32418. + */
  32419. +static ssize_t attr_status_show(struct device *_dev,
  32420. + struct device_attribute *attr, char *buf)
  32421. +{
  32422. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32423. +
  32424. + if (host) {
  32425. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32426. + return sprintf(buf,
  32427. + "present: yes\n"
  32428. + "power: %s\n"
  32429. + "clock: %u Hz\n"
  32430. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32431. + "dma: %s (%d waits)\n",
  32432. +#else
  32433. + "dma: unconfigured\n",
  32434. +#endif
  32435. + "always on",
  32436. + host->clock
  32437. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32438. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  32439. + , host_priv->dma_waits
  32440. +#endif
  32441. + );
  32442. + } else
  32443. + return -EINVAL;
  32444. +}
  32445. +
  32446. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  32447. +
  32448. +/***************************************************************************** \
  32449. + * *
  32450. + * Power Management *
  32451. + * *
  32452. +\*****************************************************************************/
  32453. +
  32454. +
  32455. +#ifdef CONFIG_PM
  32456. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  32457. +{
  32458. + struct sdhci_host *host = (struct sdhci_host *)
  32459. + platform_get_drvdata(dev);
  32460. + int ret = 0;
  32461. +
  32462. + if (host->mmc) {
  32463. + ret = mmc_suspend_host(host->mmc);
  32464. + }
  32465. +
  32466. + return ret;
  32467. +}
  32468. +
  32469. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  32470. +{
  32471. + struct sdhci_host *host = (struct sdhci_host *)
  32472. + platform_get_drvdata(dev);
  32473. + int ret = 0;
  32474. +
  32475. + if (host->mmc) {
  32476. + ret = mmc_resume_host(host->mmc);
  32477. + }
  32478. +
  32479. + return ret;
  32480. +}
  32481. +#endif
  32482. +
  32483. +
  32484. +/*****************************************************************************\
  32485. + * *
  32486. + * Device quirk functions. Implemented as local ops because the flags *
  32487. + * field is out of space with newer kernels. This implementation can be *
  32488. + * back ported to older kernels as well. *
  32489. +\****************************************************************************/
  32490. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  32491. +{
  32492. + return 1;
  32493. +}
  32494. +
  32495. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  32496. +{
  32497. + return 1;
  32498. +}
  32499. +
  32500. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  32501. +{
  32502. + return 1;
  32503. +}
  32504. +
  32505. +/***************************************************************************** \
  32506. + * *
  32507. + * Device ops *
  32508. + * *
  32509. +\*****************************************************************************/
  32510. +
  32511. +static struct sdhci_ops sdhci_bcm2708_ops = {
  32512. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  32513. + .read_l = sdhci_bcm2708_readl,
  32514. + .read_w = sdhci_bcm2708_readw,
  32515. + .read_b = sdhci_bcm2708_readb,
  32516. + .write_l = sdhci_bcm2708_writel,
  32517. + .write_w = sdhci_bcm2708_writew,
  32518. + .write_b = sdhci_bcm2708_writeb,
  32519. +#else
  32520. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  32521. +#endif
  32522. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  32523. +
  32524. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32525. + // Platform DMA operations
  32526. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  32527. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  32528. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  32529. +#endif
  32530. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  32531. +};
  32532. +
  32533. +/*****************************************************************************\
  32534. + * *
  32535. + * Device probing/removal *
  32536. + * *
  32537. +\*****************************************************************************/
  32538. +
  32539. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  32540. +{
  32541. + struct sdhci_host *host;
  32542. + struct resource *iomem;
  32543. + struct sdhci_bcm2708_priv *host_priv;
  32544. + int ret;
  32545. +
  32546. + BUG_ON(pdev == NULL);
  32547. +
  32548. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32549. + if (!iomem) {
  32550. + ret = -ENOMEM;
  32551. + goto err;
  32552. + }
  32553. +
  32554. + if (resource_size(iomem) != 0x100)
  32555. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  32556. + "experience problems.\n");
  32557. +
  32558. + if (pdev->dev.parent)
  32559. + host = sdhci_alloc_host(pdev->dev.parent,
  32560. + sizeof(struct sdhci_bcm2708_priv));
  32561. + else
  32562. + host = sdhci_alloc_host(&pdev->dev,
  32563. + sizeof(struct sdhci_bcm2708_priv));
  32564. +
  32565. + if (IS_ERR(host)) {
  32566. + ret = PTR_ERR(host);
  32567. + goto err;
  32568. + }
  32569. + if (missing_status) {
  32570. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  32571. + }
  32572. +
  32573. + if( spurious_crc_acmd51 ) {
  32574. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  32575. + }
  32576. +
  32577. +
  32578. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  32579. +
  32580. + host->hw_name = "BCM2708_Arasan";
  32581. + host->ops = &sdhci_bcm2708_ops;
  32582. + host->irq = platform_get_irq(pdev, 0);
  32583. + host->second_irq = 0;
  32584. +
  32585. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  32586. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  32587. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  32588. + SDHCI_QUIRK_MISSING_CAPS |
  32589. + SDHCI_QUIRK_NO_HISPD_BIT |
  32590. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  32591. +
  32592. +
  32593. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32594. + host->flags = SDHCI_USE_PLATDMA;
  32595. +#endif
  32596. +
  32597. + if (!request_mem_region(iomem->start, resource_size(iomem),
  32598. + mmc_hostname(host->mmc))) {
  32599. + dev_err(&pdev->dev, "cannot request region\n");
  32600. + ret = -EBUSY;
  32601. + goto err_request;
  32602. + }
  32603. +
  32604. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  32605. + if (!host->ioaddr) {
  32606. + dev_err(&pdev->dev, "failed to remap registers\n");
  32607. + ret = -ENOMEM;
  32608. + goto err_remap;
  32609. + }
  32610. +
  32611. + host_priv = SDHCI_HOST_PRIV(host);
  32612. +
  32613. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32614. + host_priv->dma_wanted = 0;
  32615. +#ifdef CHECK_DMA_USE
  32616. + host_priv->dmas_pending = 0;
  32617. + host_priv->when_started = 0;
  32618. + host_priv->when_reset = 0;
  32619. + host_priv->when_stopped = 0;
  32620. +#endif
  32621. + host_priv->sg_ix = 0;
  32622. + host_priv->sg_done = 0;
  32623. + host_priv->complete = NULL;
  32624. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  32625. +
  32626. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  32627. + &host_priv->cb_handle,
  32628. + GFP_KERNEL);
  32629. + if (!host_priv->cb_base) {
  32630. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  32631. + ret = -ENOMEM;
  32632. + goto err_alloc_cb;
  32633. + }
  32634. +
  32635. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  32636. + &host_priv->dma_chan_base,
  32637. + &host_priv->dma_irq);
  32638. + if (ret < 0) {
  32639. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  32640. + goto err_add_dma;
  32641. + }
  32642. + host_priv->dma_chan = ret;
  32643. +
  32644. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,0,//IRQF_SHARED,
  32645. + DRIVER_NAME " (dma)", host);
  32646. + if (ret) {
  32647. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  32648. + goto err_add_dma_irq;
  32649. + }
  32650. + host->second_irq = host_priv->dma_irq;
  32651. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  32652. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  32653. + host_priv->dma_chan, host_priv->dma_chan_base,
  32654. + host_priv->dma_irq);
  32655. +
  32656. + // we support 3.3V
  32657. + host->caps |= SDHCI_CAN_VDD_330;
  32658. + if (allow_highspeed)
  32659. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  32660. +
  32661. + /* single block writes cause data loss with some SD cards! */
  32662. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  32663. +#endif
  32664. +
  32665. + ret = sdhci_add_host(host);
  32666. + if (ret)
  32667. + goto err_add_host;
  32668. +
  32669. + platform_set_drvdata(pdev, host);
  32670. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  32671. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  32672. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  32673. +
  32674. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32675. + /* enable extension fifo for paced DMA transfers */
  32676. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  32677. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  32678. +#endif
  32679. +
  32680. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  32681. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  32682. + host_priv->dma_chan, host_priv->dma_irq);
  32683. +
  32684. + return 0;
  32685. +
  32686. +err_add_host:
  32687. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32688. + free_irq(host_priv->dma_irq, host);
  32689. +err_add_dma_irq:
  32690. + bcm_dma_chan_free(host_priv->dma_chan);
  32691. +err_add_dma:
  32692. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32693. + host_priv->cb_handle);
  32694. +err_alloc_cb:
  32695. +#endif
  32696. + iounmap(host->ioaddr);
  32697. +err_remap:
  32698. + release_mem_region(iomem->start, resource_size(iomem));
  32699. +err_request:
  32700. + sdhci_free_host(host);
  32701. +err:
  32702. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  32703. + return ret;
  32704. +}
  32705. +
  32706. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  32707. +{
  32708. + struct sdhci_host *host = platform_get_drvdata(pdev);
  32709. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32710. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32711. + int dead;
  32712. + u32 scratch;
  32713. +
  32714. + dead = 0;
  32715. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  32716. + if (scratch == (u32)-1)
  32717. + dead = 1;
  32718. +
  32719. + device_remove_file(&pdev->dev, &dev_attr_status);
  32720. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  32721. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  32722. +
  32723. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32724. + free_irq(host_priv->dma_irq, host);
  32725. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32726. + host_priv->cb_handle);
  32727. +#endif
  32728. + sdhci_remove_host(host, dead);
  32729. + iounmap(host->ioaddr);
  32730. + release_mem_region(iomem->start, resource_size(iomem));
  32731. + sdhci_free_host(host);
  32732. + platform_set_drvdata(pdev, NULL);
  32733. +
  32734. + return 0;
  32735. +}
  32736. +
  32737. +static struct platform_driver sdhci_bcm2708_driver = {
  32738. + .driver = {
  32739. + .name = DRIVER_NAME,
  32740. + .owner = THIS_MODULE,
  32741. + },
  32742. + .probe = sdhci_bcm2708_probe,
  32743. + .remove = sdhci_bcm2708_remove,
  32744. +
  32745. +#ifdef CONFIG_PM
  32746. + .suspend = sdhci_bcm2708_suspend,
  32747. + .resume = sdhci_bcm2708_resume,
  32748. +#endif
  32749. +
  32750. +};
  32751. +
  32752. +/*****************************************************************************\
  32753. + * *
  32754. + * Driver init/exit *
  32755. + * *
  32756. +\*****************************************************************************/
  32757. +
  32758. +static int __init sdhci_drv_init(void)
  32759. +{
  32760. + return platform_driver_register(&sdhci_bcm2708_driver);
  32761. +}
  32762. +
  32763. +static void __exit sdhci_drv_exit(void)
  32764. +{
  32765. + platform_driver_unregister(&sdhci_bcm2708_driver);
  32766. +}
  32767. +
  32768. +module_init(sdhci_drv_init);
  32769. +module_exit(sdhci_drv_exit);
  32770. +
  32771. +module_param(allow_highspeed, bool, 0444);
  32772. +module_param(emmc_clock_freq, int, 0444);
  32773. +module_param(sync_after_dma, bool, 0444);
  32774. +module_param(missing_status, bool, 0444);
  32775. +module_param(spurious_crc_acmd51, bool, 0444);
  32776. +module_param(enable_llm, bool, 0444);
  32777. +module_param(cycle_delay, int, 0444);
  32778. +module_param(extra_messages, bool, 0444);
  32779. +
  32780. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  32781. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  32782. +MODULE_LICENSE("GPL v2");
  32783. +MODULE_ALIAS("platform:"DRIVER_NAME);
  32784. +
  32785. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  32786. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  32787. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  32788. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  32789. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  32790. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  32791. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  32792. +
  32793. +
  32794. diff -Nur linux-3.10.33/drivers/mmc/host/sdhci.c linux-raspberry-pi/drivers/mmc/host/sdhci.c
  32795. --- linux-3.10.33/drivers/mmc/host/sdhci.c 2014-03-07 06:58:45.000000000 +0100
  32796. +++ linux-raspberry-pi/drivers/mmc/host/sdhci.c 2014-03-13 12:46:21.008060891 +0100
  32797. @@ -28,6 +28,7 @@
  32798. #include <linux/mmc/mmc.h>
  32799. #include <linux/mmc/host.h>
  32800. #include <linux/mmc/card.h>
  32801. +#include <linux/mmc/sd.h>
  32802. #include <linux/mmc/slot-gpio.h>
  32803. #include "sdhci.h"
  32804. @@ -123,6 +124,99 @@
  32805. * Low level functions *
  32806. * *
  32807. \*****************************************************************************/
  32808. +extern bool enable_llm;
  32809. +static int sdhci_locked=0;
  32810. +void sdhci_spin_lock(struct sdhci_host *host)
  32811. +{
  32812. + spin_lock(&host->lock);
  32813. +#ifdef CONFIG_PREEMPT
  32814. + if(enable_llm)
  32815. + {
  32816. + disable_irq_nosync(host->irq);
  32817. + if(host->second_irq)
  32818. + disable_irq_nosync(host->second_irq);
  32819. + local_irq_enable();
  32820. + }
  32821. +#endif
  32822. +}
  32823. +
  32824. +void sdhci_spin_unlock(struct sdhci_host *host)
  32825. +{
  32826. +#ifdef CONFIG_PREEMPT
  32827. + if(enable_llm)
  32828. + {
  32829. + local_irq_disable();
  32830. + if(host->second_irq)
  32831. + enable_irq(host->second_irq);
  32832. + enable_irq(host->irq);
  32833. + }
  32834. +#endif
  32835. + spin_unlock(&host->lock);
  32836. +}
  32837. +
  32838. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  32839. +{
  32840. +#ifdef CONFIG_PREEMPT
  32841. + if(enable_llm)
  32842. + {
  32843. + while(sdhci_locked)
  32844. + {
  32845. + preempt_schedule();
  32846. + }
  32847. + spin_lock_irqsave(&host->lock,*flags);
  32848. + disable_irq(host->irq);
  32849. + if(host->second_irq)
  32850. + disable_irq(host->second_irq);
  32851. + local_irq_enable();
  32852. + }
  32853. + else
  32854. +#endif
  32855. + spin_lock_irqsave(&host->lock,*flags);
  32856. +}
  32857. +
  32858. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  32859. +{
  32860. +#ifdef CONFIG_PREEMPT
  32861. + if(enable_llm)
  32862. + {
  32863. + local_irq_disable();
  32864. + if(host->second_irq)
  32865. + enable_irq(host->second_irq);
  32866. + enable_irq(host->irq);
  32867. + }
  32868. +#endif
  32869. + spin_unlock_irqrestore(&host->lock,flags);
  32870. +}
  32871. +
  32872. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  32873. +{
  32874. +#ifdef CONFIG_PREEMPT
  32875. + if(enable_llm)
  32876. + {
  32877. + sdhci_locked = 1;
  32878. + preempt_enable();
  32879. + }
  32880. +#endif
  32881. +}
  32882. +
  32883. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  32884. +{
  32885. +#ifdef CONFIG_PREEMPT
  32886. + if(enable_llm)
  32887. + {
  32888. + preempt_disable();
  32889. + sdhci_locked = 0;
  32890. + }
  32891. +#endif
  32892. +}
  32893. +
  32894. +
  32895. +#undef spin_lock_irqsave
  32896. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  32897. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  32898. +
  32899. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  32900. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  32901. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  32902. {
  32903. @@ -315,7 +409,7 @@
  32904. u32 uninitialized_var(scratch);
  32905. u8 *buf;
  32906. - DBG("PIO reading\n");
  32907. + DBG("PIO reading %db\n", host->data->blksz);
  32908. blksize = host->data->blksz;
  32909. chunk = 0;
  32910. @@ -360,7 +454,7 @@
  32911. u32 scratch;
  32912. u8 *buf;
  32913. - DBG("PIO writing\n");
  32914. + DBG("PIO writing %db\n", host->data->blksz);
  32915. blksize = host->data->blksz;
  32916. chunk = 0;
  32917. @@ -399,19 +493,28 @@
  32918. local_irq_restore(flags);
  32919. }
  32920. -static void sdhci_transfer_pio(struct sdhci_host *host)
  32921. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  32922. {
  32923. u32 mask;
  32924. + u32 state = 0;
  32925. + u32 intmask;
  32926. + int available;
  32927. BUG_ON(!host->data);
  32928. if (host->blocks == 0)
  32929. return;
  32930. - if (host->data->flags & MMC_DATA_READ)
  32931. + if (host->data->flags & MMC_DATA_READ) {
  32932. mask = SDHCI_DATA_AVAILABLE;
  32933. - else
  32934. + intmask = SDHCI_INT_DATA_AVAIL;
  32935. + } else {
  32936. mask = SDHCI_SPACE_AVAILABLE;
  32937. + intmask = SDHCI_INT_SPACE_AVAIL;
  32938. + }
  32939. +
  32940. + /* initially we can see whether we can procede using intstate */
  32941. + available = (intstate & intmask);
  32942. /*
  32943. * Some controllers (JMicron JMB38x) mess up the buffer bits
  32944. @@ -422,7 +525,7 @@
  32945. (host->data->blocks == 1))
  32946. mask = ~0;
  32947. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  32948. + while (available) {
  32949. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  32950. udelay(100);
  32951. @@ -434,9 +537,12 @@
  32952. host->blocks--;
  32953. if (host->blocks == 0)
  32954. break;
  32955. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  32956. + available = state & mask;
  32957. + break;
  32958. }
  32959. - DBG("PIO transfer complete.\n");
  32960. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  32961. }
  32962. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  32963. @@ -709,7 +815,9 @@
  32964. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  32965. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  32966. - if (host->flags & SDHCI_REQ_USE_DMA)
  32967. + /* platform DMA will begin on receipt of PIO irqs */
  32968. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32969. + !(host->flags & SDHCI_USE_PLATDMA))
  32970. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  32971. else
  32972. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  32973. @@ -741,44 +849,25 @@
  32974. host->data_early = 0;
  32975. host->data->bytes_xfered = 0;
  32976. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  32977. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  32978. host->flags |= SDHCI_REQ_USE_DMA;
  32979. /*
  32980. * FIXME: This doesn't account for merging when mapping the
  32981. * scatterlist.
  32982. */
  32983. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32984. - int broken, i;
  32985. - struct scatterlist *sg;
  32986. -
  32987. - broken = 0;
  32988. - if (host->flags & SDHCI_USE_ADMA) {
  32989. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  32990. - broken = 1;
  32991. - } else {
  32992. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  32993. - broken = 1;
  32994. - }
  32995. -
  32996. - if (unlikely(broken)) {
  32997. - for_each_sg(data->sg, sg, data->sg_len, i) {
  32998. - if (sg->length & 0x3) {
  32999. - DBG("Reverting to PIO because of "
  33000. - "transfer size (%d)\n",
  33001. - sg->length);
  33002. - host->flags &= ~SDHCI_REQ_USE_DMA;
  33003. - break;
  33004. - }
  33005. - }
  33006. - }
  33007. - }
  33008. /*
  33009. * The assumption here being that alignment is the same after
  33010. * translation to device address space.
  33011. */
  33012. - if (host->flags & SDHCI_REQ_USE_DMA) {
  33013. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  33014. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  33015. +
  33016. + if (! sdhci_platdma_dmaable(host, data))
  33017. + host->flags &= ~SDHCI_REQ_USE_DMA;
  33018. +
  33019. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  33020. int broken, i;
  33021. struct scatterlist *sg;
  33022. @@ -837,7 +926,8 @@
  33023. */
  33024. WARN_ON(1);
  33025. host->flags &= ~SDHCI_REQ_USE_DMA;
  33026. - } else {
  33027. + } else
  33028. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  33029. WARN_ON(sg_cnt != 1);
  33030. sdhci_writel(host, sg_dma_address(data->sg),
  33031. SDHCI_DMA_ADDRESS);
  33032. @@ -853,11 +943,13 @@
  33033. if (host->version >= SDHCI_SPEC_200) {
  33034. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  33035. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  33036. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  33037. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  33038. (host->flags & SDHCI_USE_ADMA))
  33039. ctrl |= SDHCI_CTRL_ADMA32;
  33040. else
  33041. ctrl |= SDHCI_CTRL_SDMA;
  33042. + }
  33043. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  33044. }
  33045. @@ -909,7 +1001,8 @@
  33046. if (data->flags & MMC_DATA_READ)
  33047. mode |= SDHCI_TRNS_READ;
  33048. - if (host->flags & SDHCI_REQ_USE_DMA)
  33049. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  33050. + !(host->flags & SDHCI_USE_PLATDMA))
  33051. mode |= SDHCI_TRNS_DMA;
  33052. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  33053. @@ -925,13 +1018,16 @@
  33054. host->data = NULL;
  33055. if (host->flags & SDHCI_REQ_USE_DMA) {
  33056. - if (host->flags & SDHCI_USE_ADMA)
  33057. - sdhci_adma_table_post(host, data);
  33058. - else {
  33059. + /* we may have to abandon an ongoing platform DMA */
  33060. + if (host->flags & SDHCI_USE_PLATDMA)
  33061. + sdhci_platdma_reset(host, data);
  33062. +
  33063. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  33064. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  33065. data->sg_len, (data->flags & MMC_DATA_READ) ?
  33066. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  33067. - }
  33068. + } else if (host->flags & SDHCI_USE_ADMA)
  33069. + sdhci_adma_table_post(host, data);
  33070. }
  33071. /*
  33072. @@ -984,6 +1080,12 @@
  33073. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  33074. mask |= SDHCI_DATA_INHIBIT;
  33075. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  33076. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  33077. + // which might cause the STATUS command to get stuck when a data operation is in flow
  33078. + mask |= SDHCI_DATA_INHIBIT;
  33079. + }
  33080. +
  33081. /* We shouldn't wait for data inihibit for stop commands, even
  33082. though they might use busy signaling */
  33083. if (host->mrq->data && (cmd == host->mrq->data->stop))
  33084. @@ -999,12 +1101,20 @@
  33085. return;
  33086. }
  33087. timeout--;
  33088. + sdhci_spin_enable_schedule(host);
  33089. mdelay(1);
  33090. + sdhci_spin_disable_schedule(host);
  33091. }
  33092. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  33093. + sdhci_readl(host, SDHCI_INT_STATUS));
  33094. mod_timer(&host->timer, jiffies + 10 * HZ);
  33095. host->cmd = cmd;
  33096. + if (host->last_cmdop == MMC_APP_CMD)
  33097. + host->last_cmdop = -cmd->opcode;
  33098. + else
  33099. + host->last_cmdop = cmd->opcode;
  33100. sdhci_prepare_data(host, cmd);
  33101. @@ -1220,7 +1330,9 @@
  33102. return;
  33103. }
  33104. timeout--;
  33105. + sdhci_spin_enable_schedule(host);
  33106. mdelay(1);
  33107. + sdhci_spin_disable_schedule(host);
  33108. }
  33109. clk |= SDHCI_CLOCK_CARD_EN;
  33110. @@ -2164,7 +2276,7 @@
  33111. if (host->mrq) {
  33112. pr_err("%s: Timeout waiting for hardware "
  33113. - "interrupt.\n", mmc_hostname(host->mmc));
  33114. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  33115. sdhci_dumpregs(host);
  33116. if (host->data) {
  33117. @@ -2209,10 +2321,13 @@
  33118. BUG_ON(intmask == 0);
  33119. if (!host->cmd) {
  33120. + if (!(host->ops->extra_ints)) {
  33121. pr_err("%s: Got command interrupt 0x%08x even "
  33122. "though no command operation was in progress.\n",
  33123. mmc_hostname(host->mmc), (unsigned)intmask);
  33124. sdhci_dumpregs(host);
  33125. + } else
  33126. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  33127. return;
  33128. }
  33129. @@ -2282,6 +2397,19 @@
  33130. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  33131. #endif
  33132. +static void sdhci_data_end(struct sdhci_host *host)
  33133. +{
  33134. + if (host->cmd) {
  33135. + /*
  33136. + * Data managed to finish before the
  33137. + * command completed. Make sure we do
  33138. + * things in the proper order.
  33139. + */
  33140. + host->data_early = 1;
  33141. + } else
  33142. + sdhci_finish_data(host);
  33143. +}
  33144. +
  33145. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  33146. {
  33147. u32 command;
  33148. @@ -2311,23 +2439,39 @@
  33149. }
  33150. }
  33151. + if (!(host->ops->extra_ints)) {
  33152. pr_err("%s: Got data interrupt 0x%08x even "
  33153. "though no data operation was in progress.\n",
  33154. mmc_hostname(host->mmc), (unsigned)intmask);
  33155. sdhci_dumpregs(host);
  33156. + } else
  33157. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  33158. return;
  33159. }
  33160. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  33161. host->data->error = -ETIMEDOUT;
  33162. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  33163. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  33164. + DBG("end error in cmd %d\n", host->last_cmdop);
  33165. + if (host->ops->spurious_crc_acmd51 &&
  33166. + host->last_cmdop == -SD_APP_SEND_SCR) {
  33167. + DBG("ignoring spurious data_end_bit error\n");
  33168. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  33169. + } else
  33170. host->data->error = -EILSEQ;
  33171. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  33172. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  33173. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  33174. - != MMC_BUS_TEST_R)
  33175. + != MMC_BUS_TEST_R) {
  33176. + DBG("crc error in cmd %d\n", host->last_cmdop);
  33177. + if (host->ops->spurious_crc_acmd51 &&
  33178. + host->last_cmdop == -SD_APP_SEND_SCR) {
  33179. + DBG("ignoring spurious data_crc_bit error\n");
  33180. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  33181. + } else {
  33182. host->data->error = -EILSEQ;
  33183. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  33184. + }
  33185. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  33186. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  33187. sdhci_show_adma_error(host);
  33188. host->data->error = -EIO;
  33189. @@ -2335,11 +2479,18 @@
  33190. host->ops->adma_workaround(host, intmask);
  33191. }
  33192. - if (host->data->error)
  33193. + if (host->data->error) {
  33194. + DBG("finish request early on error %d\n", host->data->error);
  33195. sdhci_finish_data(host);
  33196. - else {
  33197. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  33198. - sdhci_transfer_pio(host);
  33199. + } else {
  33200. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  33201. + if (host->flags & SDHCI_REQ_USE_DMA) {
  33202. + /* possible only in PLATDMA mode */
  33203. + sdhci_platdma_avail(host, &intmask,
  33204. + &sdhci_data_end);
  33205. + } else
  33206. + sdhci_transfer_pio(host, intmask);
  33207. + }
  33208. /*
  33209. * We currently don't do anything fancy with DMA
  33210. @@ -2368,18 +2519,8 @@
  33211. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  33212. }
  33213. - if (intmask & SDHCI_INT_DATA_END) {
  33214. - if (host->cmd) {
  33215. - /*
  33216. - * Data managed to finish before the
  33217. - * command completed. Make sure we do
  33218. - * things in the proper order.
  33219. - */
  33220. - host->data_early = 1;
  33221. - } else {
  33222. - sdhci_finish_data(host);
  33223. - }
  33224. - }
  33225. + if (intmask & SDHCI_INT_DATA_END)
  33226. + sdhci_data_end(host);
  33227. }
  33228. }
  33229. @@ -2435,6 +2576,22 @@
  33230. tasklet_schedule(&host->card_tasklet);
  33231. }
  33232. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  33233. + DBG("controller reports error 0x%x -"
  33234. + "%s%s%s%s%s%s%s%s%s%s",
  33235. + intmask,
  33236. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  33237. + intmask & SDHCI_INT_CRC ? " crc": "",
  33238. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  33239. + intmask & SDHCI_INT_INDEX? " index": "",
  33240. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  33241. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  33242. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  33243. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  33244. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  33245. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  33246. + );
  33247. +
  33248. if (intmask & SDHCI_INT_CMD_MASK) {
  33249. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  33250. SDHCI_INT_STATUS);
  33251. @@ -2449,7 +2606,13 @@
  33252. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  33253. - intmask &= ~SDHCI_INT_ERROR;
  33254. + if (intmask & SDHCI_INT_ERROR_MASK) {
  33255. + /* collect any uncovered errors */
  33256. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  33257. + SDHCI_INT_STATUS);
  33258. + }
  33259. +
  33260. + intmask &= ~SDHCI_INT_ERROR_MASK;
  33261. if (intmask & SDHCI_INT_BUS_POWER) {
  33262. pr_err("%s: Card is consuming too much power!\n",
  33263. @@ -2569,7 +2732,8 @@
  33264. {
  33265. int ret;
  33266. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  33267. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  33268. + SDHCI_USE_PLATDMA)) {
  33269. if (host->ops->enable_dma)
  33270. host->ops->enable_dma(host);
  33271. }
  33272. @@ -2785,14 +2949,16 @@
  33273. host->flags &= ~SDHCI_USE_ADMA;
  33274. }
  33275. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  33276. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  33277. + SDHCI_USE_PLATDMA)) {
  33278. if (host->ops->enable_dma) {
  33279. if (host->ops->enable_dma(host)) {
  33280. pr_warning("%s: No suitable DMA "
  33281. "available. Falling back to PIO.\n",
  33282. mmc_hostname(mmc));
  33283. host->flags &=
  33284. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  33285. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  33286. + SDHCI_USE_PLATDMA);
  33287. }
  33288. }
  33289. }
  33290. @@ -3174,7 +3340,7 @@
  33291. host->tuning_timer.function = sdhci_tuning_timer;
  33292. }
  33293. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  33294. + ret = request_irq(host->irq, sdhci_irq, 0,//IRQF_SHARED,
  33295. mmc_hostname(mmc), host);
  33296. if (ret) {
  33297. pr_err("%s: Failed to request IRQ %d: %d\n",
  33298. @@ -3210,6 +3376,7 @@
  33299. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  33300. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  33301. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  33302. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  33303. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  33304. diff -Nur linux-3.10.33/drivers/mmc/host/sdhci.h linux-raspberry-pi/drivers/mmc/host/sdhci.h
  33305. --- linux-3.10.33/drivers/mmc/host/sdhci.h 2014-03-07 06:58:45.000000000 +0100
  33306. +++ linux-raspberry-pi/drivers/mmc/host/sdhci.h 2014-03-13 12:46:21.008060891 +0100
  33307. @@ -289,6 +289,18 @@
  33308. void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
  33309. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  33310. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  33311. +
  33312. + int (*pdma_able)(struct sdhci_host *host,
  33313. + struct mmc_data *data);
  33314. + void (*pdma_avail)(struct sdhci_host *host,
  33315. + unsigned int *ref_intmask,
  33316. + void(*complete)(struct sdhci_host *));
  33317. + void (*pdma_reset)(struct sdhci_host *host,
  33318. + struct mmc_data *data);
  33319. + unsigned int (*extra_ints)(struct sdhci_host *host);
  33320. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  33321. + unsigned int (*missing_status)(struct sdhci_host *host);
  33322. +
  33323. void (*hw_reset)(struct sdhci_host *host);
  33324. void (*platform_suspend)(struct sdhci_host *host);
  33325. void (*platform_resume)(struct sdhci_host *host);
  33326. @@ -399,9 +411,38 @@
  33327. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  33328. #endif
  33329. +static inline int /*bool*/
  33330. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  33331. +{
  33332. + if (host->ops->pdma_able)
  33333. + return host->ops->pdma_able(host, data);
  33334. + else
  33335. + return 1;
  33336. +}
  33337. +static inline void
  33338. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  33339. + void(*completion_callback)(struct sdhci_host *))
  33340. +{
  33341. + if (host->ops->pdma_avail)
  33342. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  33343. +}
  33344. +
  33345. +static inline void
  33346. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  33347. +{
  33348. + if (host->ops->pdma_reset)
  33349. + host->ops->pdma_reset(host, data);
  33350. +}
  33351. +
  33352. #ifdef CONFIG_PM_RUNTIME
  33353. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  33354. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  33355. #endif
  33356. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  33357. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  33358. +extern void sdhci_spin_lock(struct sdhci_host *host);
  33359. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  33360. +
  33361. +
  33362. #endif /* __SDHCI_HW_H */
  33363. diff -Nur linux-3.10.33/drivers/net/usb/smsc95xx.c linux-raspberry-pi/drivers/net/usb/smsc95xx.c
  33364. --- linux-3.10.33/drivers/net/usb/smsc95xx.c 2014-03-07 06:58:45.000000000 +0100
  33365. +++ linux-raspberry-pi/drivers/net/usb/smsc95xx.c 2014-03-13 12:46:25.472069833 +0100
  33366. @@ -61,6 +61,7 @@
  33367. #define SUSPEND_SUSPEND3 (0x08)
  33368. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  33369. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  33370. +#define MAC_ADDR_LEN (6)
  33371. struct smsc95xx_priv {
  33372. u32 mac_cr;
  33373. @@ -76,6 +77,10 @@
  33374. module_param(turbo_mode, bool, 0644);
  33375. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  33376. +static char *macaddr = ":";
  33377. +module_param(macaddr, charp, 0);
  33378. +MODULE_PARM_DESC(macaddr, "MAC address");
  33379. +
  33380. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  33381. u32 *data, int in_pm)
  33382. {
  33383. @@ -765,8 +770,59 @@
  33384. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  33385. }
  33386. +/* Check the macaddr module parameter for a MAC address */
  33387. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  33388. +{
  33389. + int i, j, got_num, num;
  33390. + u8 mtbl[MAC_ADDR_LEN];
  33391. +
  33392. + if (macaddr[0] == ':')
  33393. + return 0;
  33394. +
  33395. + i = 0;
  33396. + j = 0;
  33397. + num = 0;
  33398. + got_num = 0;
  33399. + while (j < MAC_ADDR_LEN) {
  33400. + if (macaddr[i] && macaddr[i] != ':') {
  33401. + got_num++;
  33402. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  33403. + num = num * 16 + macaddr[i] - '0';
  33404. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  33405. + num = num * 16 + 10 + macaddr[i] - 'A';
  33406. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  33407. + num = num * 16 + 10 + macaddr[i] - 'a';
  33408. + else
  33409. + break;
  33410. + i++;
  33411. + } else if (got_num == 2) {
  33412. + mtbl[j++] = (u8) num;
  33413. + num = 0;
  33414. + got_num = 0;
  33415. + i++;
  33416. + } else {
  33417. + break;
  33418. + }
  33419. + }
  33420. +
  33421. + if (j == MAC_ADDR_LEN) {
  33422. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  33423. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  33424. + mtbl[3], mtbl[4], mtbl[5]);
  33425. + for (i = 0; i < MAC_ADDR_LEN; i++)
  33426. + dev_mac[i] = mtbl[i];
  33427. + return 1;
  33428. + } else {
  33429. + return 0;
  33430. + }
  33431. +}
  33432. +
  33433. static void smsc95xx_init_mac_address(struct usbnet *dev)
  33434. {
  33435. + /* Check module parameters */
  33436. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  33437. + return;
  33438. +
  33439. /* try reading mac address from EEPROM */
  33440. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  33441. dev->net->dev_addr) == 0) {
  33442. diff -Nur linux-3.10.33/drivers/net/wireless/ath/ath9k/hif_usb.c linux-raspberry-pi/drivers/net/wireless/ath/ath9k/hif_usb.c
  33443. --- linux-3.10.33/drivers/net/wireless/ath/ath9k/hif_usb.c 2014-03-07 06:58:45.000000000 +0100
  33444. +++ linux-raspberry-pi/drivers/net/wireless/ath/ath9k/hif_usb.c 2014-03-13 12:46:25.532069953 +0100
  33445. @@ -37,9 +37,11 @@
  33446. { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */
  33447. { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
  33448. { USB_DEVICE(0x040D, 0x3801) }, /* VIA */
  33449. + { USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */
  33450. { USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */
  33451. { USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */
  33452. { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */
  33453. + { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */
  33454. { USB_DEVICE(0x0cf3, 0x7015),
  33455. .driver_info = AR9287_USB }, /* Atheros */
  33456. diff -Nur linux-3.10.33/drivers/net/wireless/Makefile linux-raspberry-pi/drivers/net/wireless/Makefile
  33457. --- linux-3.10.33/drivers/net/wireless/Makefile 2014-03-07 06:58:45.000000000 +0100
  33458. +++ linux-raspberry-pi/drivers/net/wireless/Makefile 2014-03-13 12:47:52.768245516 +0100
  33459. @@ -23,7 +23,6 @@
  33460. obj-$(CONFIG_B43LEGACY) += b43legacy/
  33461. obj-$(CONFIG_ZD1211RW) += zd1211rw/
  33462. obj-$(CONFIG_RTL8180) += rtl818x/
  33463. -obj-$(CONFIG_RTL8187) += rtl818x/
  33464. obj-$(CONFIG_RTLWIFI) += rtlwifi/
  33465. # 16-bit wireless PCMCIA client drivers
  33466. @@ -57,3 +56,4 @@
  33467. obj-$(CONFIG_BRCMFMAC) += brcm80211/
  33468. obj-$(CONFIG_BRCMSMAC) += brcm80211/
  33469. +obj-$(CONFIG_RTL8192CU) += rtl8192cu/
  33470. diff -Nur linux-3.10.33/drivers/net/wireless/rt2x00/rt2800.h linux-raspberry-pi/drivers/net/wireless/rt2x00/rt2800.h
  33471. --- linux-3.10.33/drivers/net/wireless/rt2x00/rt2800.h 2014-03-07 06:58:45.000000000 +0100
  33472. +++ linux-raspberry-pi/drivers/net/wireless/rt2x00/rt2800.h 2014-03-13 12:46:27.364073623 +0100
  33473. @@ -70,6 +70,7 @@
  33474. #define RF3322 0x000c
  33475. #define RF3053 0x000d
  33476. #define RF5592 0x000f
  33477. +#define RF3070 0x3070
  33478. #define RF3290 0x3290
  33479. #define RF5360 0x5360
  33480. #define RF5370 0x5370
  33481. diff -Nur linux-3.10.33/drivers/net/wireless/rt2x00/rt2800lib.c linux-raspberry-pi/drivers/net/wireless/rt2x00/rt2800lib.c
  33482. --- linux-3.10.33/drivers/net/wireless/rt2x00/rt2800lib.c 2014-03-07 06:58:45.000000000 +0100
  33483. +++ linux-raspberry-pi/drivers/net/wireless/rt2x00/rt2800lib.c 2014-03-13 12:46:27.364073623 +0100
  33484. @@ -2599,6 +2599,7 @@
  33485. break;
  33486. case RF5360:
  33487. case RF5370:
  33488. + case RF3070:
  33489. case RF5372:
  33490. case RF5390:
  33491. case RF5392:
  33492. @@ -2615,6 +2616,7 @@
  33493. rt2x00_rf(rt2x00dev, RF3322) ||
  33494. rt2x00_rf(rt2x00dev, RF5360) ||
  33495. rt2x00_rf(rt2x00dev, RF5370) ||
  33496. + rt2x00_rf(rt2x00dev, RF3070) ||
  33497. rt2x00_rf(rt2x00dev, RF5372) ||
  33498. rt2x00_rf(rt2x00dev, RF5390) ||
  33499. rt2x00_rf(rt2x00dev, RF5392)) {
  33500. @@ -3206,6 +3208,7 @@
  33501. case RF3290:
  33502. case RF5360:
  33503. case RF5370:
  33504. + case RF3070:
  33505. case RF5372:
  33506. case RF5390:
  33507. case RF5392:
  33508. @@ -5524,6 +5527,7 @@
  33509. case RF3322:
  33510. case RF5360:
  33511. case RF5370:
  33512. + case RF3070:
  33513. case RF5372:
  33514. case RF5390:
  33515. case RF5392:
  33516. @@ -5979,6 +5983,7 @@
  33517. rt2x00_rf(rt2x00dev, RF3322) ||
  33518. rt2x00_rf(rt2x00dev, RF5360) ||
  33519. rt2x00_rf(rt2x00dev, RF5370) ||
  33520. + rt2x00_rf(rt2x00dev, RF3070) ||
  33521. rt2x00_rf(rt2x00dev, RF5372) ||
  33522. rt2x00_rf(rt2x00dev, RF5390) ||
  33523. rt2x00_rf(rt2x00dev, RF5392)) {
  33524. @@ -6081,6 +6086,7 @@
  33525. case RF3290:
  33526. case RF5360:
  33527. case RF5370:
  33528. + case RF3070:
  33529. case RF5372:
  33530. case RF5390:
  33531. case RF5392:
  33532. diff -Nur linux-3.10.33/drivers/spi/Kconfig linux-raspberry-pi/drivers/spi/Kconfig
  33533. --- linux-3.10.33/drivers/spi/Kconfig 2014-03-07 06:58:45.000000000 +0100
  33534. +++ linux-raspberry-pi/drivers/spi/Kconfig 2014-03-13 12:46:31.776082466 +0100
  33535. @@ -86,6 +86,14 @@
  33536. is for the regular SPI controller. Slave mode operation is not also
  33537. not supported.
  33538. +config SPI_BCM2708
  33539. + tristate "BCM2708 SPI controller driver (SPI0)"
  33540. + depends on MACH_BCM2708
  33541. + help
  33542. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  33543. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  33544. + device.
  33545. +
  33546. config SPI_BFIN5XX
  33547. tristate "SPI controller driver for ADI Blackfin5xx"
  33548. depends on BLACKFIN
  33549. diff -Nur linux-3.10.33/drivers/spi/Makefile linux-raspberry-pi/drivers/spi/Makefile
  33550. --- linux-3.10.33/drivers/spi/Makefile 2014-03-07 06:58:45.000000000 +0100
  33551. +++ linux-raspberry-pi/drivers/spi/Makefile 2014-03-13 12:46:31.776082466 +0100
  33552. @@ -17,6 +17,7 @@
  33553. obj-$(CONFIG_SPI_BCM2835) += spi-bcm2835.o
  33554. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  33555. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  33556. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  33557. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  33558. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  33559. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  33560. diff -Nur linux-3.10.33/drivers/spi/spi-bcm2708.c linux-raspberry-pi/drivers/spi/spi-bcm2708.c
  33561. --- linux-3.10.33/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  33562. +++ linux-raspberry-pi/drivers/spi/spi-bcm2708.c 2014-03-13 12:46:31.776082466 +0100
  33563. @@ -0,0 +1,626 @@
  33564. +/*
  33565. + * Driver for Broadcom BCM2708 SPI Controllers
  33566. + *
  33567. + * Copyright (C) 2012 Chris Boot
  33568. + *
  33569. + * This driver is inspired by:
  33570. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  33571. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  33572. + *
  33573. + * This program is free software; you can redistribute it and/or modify
  33574. + * it under the terms of the GNU General Public License as published by
  33575. + * the Free Software Foundation; either version 2 of the License, or
  33576. + * (at your option) any later version.
  33577. + *
  33578. + * This program is distributed in the hope that it will be useful,
  33579. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33580. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33581. + * GNU General Public License for more details.
  33582. + *
  33583. + * You should have received a copy of the GNU General Public License
  33584. + * along with this program; if not, write to the Free Software
  33585. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  33586. + */
  33587. +
  33588. +#include <linux/kernel.h>
  33589. +#include <linux/module.h>
  33590. +#include <linux/spinlock.h>
  33591. +#include <linux/clk.h>
  33592. +#include <linux/err.h>
  33593. +#include <linux/platform_device.h>
  33594. +#include <linux/io.h>
  33595. +#include <linux/spi/spi.h>
  33596. +#include <linux/interrupt.h>
  33597. +#include <linux/delay.h>
  33598. +#include <linux/log2.h>
  33599. +#include <linux/sched.h>
  33600. +#include <linux/wait.h>
  33601. +
  33602. +/* SPI register offsets */
  33603. +#define SPI_CS 0x00
  33604. +#define SPI_FIFO 0x04
  33605. +#define SPI_CLK 0x08
  33606. +#define SPI_DLEN 0x0c
  33607. +#define SPI_LTOH 0x10
  33608. +#define SPI_DC 0x14
  33609. +
  33610. +/* Bitfields in CS */
  33611. +#define SPI_CS_LEN_LONG 0x02000000
  33612. +#define SPI_CS_DMA_LEN 0x01000000
  33613. +#define SPI_CS_CSPOL2 0x00800000
  33614. +#define SPI_CS_CSPOL1 0x00400000
  33615. +#define SPI_CS_CSPOL0 0x00200000
  33616. +#define SPI_CS_RXF 0x00100000
  33617. +#define SPI_CS_RXR 0x00080000
  33618. +#define SPI_CS_TXD 0x00040000
  33619. +#define SPI_CS_RXD 0x00020000
  33620. +#define SPI_CS_DONE 0x00010000
  33621. +#define SPI_CS_LEN 0x00002000
  33622. +#define SPI_CS_REN 0x00001000
  33623. +#define SPI_CS_ADCS 0x00000800
  33624. +#define SPI_CS_INTR 0x00000400
  33625. +#define SPI_CS_INTD 0x00000200
  33626. +#define SPI_CS_DMAEN 0x00000100
  33627. +#define SPI_CS_TA 0x00000080
  33628. +#define SPI_CS_CSPOL 0x00000040
  33629. +#define SPI_CS_CLEAR_RX 0x00000020
  33630. +#define SPI_CS_CLEAR_TX 0x00000010
  33631. +#define SPI_CS_CPOL 0x00000008
  33632. +#define SPI_CS_CPHA 0x00000004
  33633. +#define SPI_CS_CS_10 0x00000002
  33634. +#define SPI_CS_CS_01 0x00000001
  33635. +
  33636. +#define SPI_TIMEOUT_MS 150
  33637. +
  33638. +#define DRV_NAME "bcm2708_spi"
  33639. +
  33640. +struct bcm2708_spi {
  33641. + spinlock_t lock;
  33642. + void __iomem *base;
  33643. + int irq;
  33644. + struct clk *clk;
  33645. + bool stopping;
  33646. +
  33647. + struct list_head queue;
  33648. + struct workqueue_struct *workq;
  33649. + struct work_struct work;
  33650. + struct completion done;
  33651. +
  33652. + const u8 *tx_buf;
  33653. + u8 *rx_buf;
  33654. + int len;
  33655. +};
  33656. +
  33657. +struct bcm2708_spi_state {
  33658. + u32 cs;
  33659. + u16 cdiv;
  33660. +};
  33661. +
  33662. +/*
  33663. + * This function sets the ALT mode on the SPI pins so that we can use them with
  33664. + * the SPI hardware.
  33665. + *
  33666. + * FIXME: This is a hack. Use pinmux / pinctrl.
  33667. + */
  33668. +static void bcm2708_init_pinmode(void)
  33669. +{
  33670. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  33671. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  33672. +
  33673. + int pin;
  33674. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  33675. +
  33676. + /* SPI is on GPIO 7..11 */
  33677. + for (pin = 7; pin <= 11; pin++) {
  33678. + INP_GPIO(pin); /* set mode to GPIO input first */
  33679. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  33680. + }
  33681. +
  33682. + iounmap(gpio);
  33683. +
  33684. +#undef INP_GPIO
  33685. +#undef SET_GPIO_ALT
  33686. +}
  33687. +
  33688. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  33689. +{
  33690. + return readl(bs->base + reg);
  33691. +}
  33692. +
  33693. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  33694. +{
  33695. + writel(val, bs->base + reg);
  33696. +}
  33697. +
  33698. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  33699. +{
  33700. + u8 byte;
  33701. +
  33702. + while (len--) {
  33703. + byte = bcm2708_rd(bs, SPI_FIFO);
  33704. + if (bs->rx_buf)
  33705. + *bs->rx_buf++ = byte;
  33706. + }
  33707. +}
  33708. +
  33709. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  33710. +{
  33711. + u8 byte;
  33712. + u16 val;
  33713. +
  33714. + if (len > bs->len)
  33715. + len = bs->len;
  33716. +
  33717. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  33718. + /* LoSSI mode */
  33719. + if (unlikely(len % 2)) {
  33720. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  33721. + bs->len = 0;
  33722. + return;
  33723. + }
  33724. + while (len) {
  33725. + if (bs->tx_buf) {
  33726. + val = *(const u16 *)bs->tx_buf;
  33727. + bs->tx_buf += 2;
  33728. + } else
  33729. + val = 0;
  33730. + bcm2708_wr(bs, SPI_FIFO, val);
  33731. + bs->len -= 2;
  33732. + len -= 2;
  33733. + }
  33734. + return;
  33735. + }
  33736. +
  33737. + while (len--) {
  33738. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  33739. + bcm2708_wr(bs, SPI_FIFO, byte);
  33740. + bs->len--;
  33741. + }
  33742. +}
  33743. +
  33744. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  33745. +{
  33746. + struct spi_master *master = dev_id;
  33747. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33748. + u32 cs;
  33749. +
  33750. + spin_lock(&bs->lock);
  33751. +
  33752. + cs = bcm2708_rd(bs, SPI_CS);
  33753. +
  33754. + if (cs & SPI_CS_DONE) {
  33755. + if (bs->len) { /* first interrupt in a transfer */
  33756. + /* fill the TX fifo with up to 16 bytes */
  33757. + bcm2708_wr_fifo(bs, 16);
  33758. + } else { /* transfer complete */
  33759. + /* disable interrupts */
  33760. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  33761. + bcm2708_wr(bs, SPI_CS, cs);
  33762. +
  33763. + /* drain RX FIFO */
  33764. + while (cs & SPI_CS_RXD) {
  33765. + bcm2708_rd_fifo(bs, 1);
  33766. + cs = bcm2708_rd(bs, SPI_CS);
  33767. + }
  33768. +
  33769. + /* wake up our bh */
  33770. + complete(&bs->done);
  33771. + }
  33772. + } else if (cs & SPI_CS_RXR) {
  33773. + /* read 12 bytes of data */
  33774. + bcm2708_rd_fifo(bs, 12);
  33775. +
  33776. + /* write up to 12 bytes */
  33777. + bcm2708_wr_fifo(bs, 12);
  33778. + }
  33779. +
  33780. + spin_unlock(&bs->lock);
  33781. +
  33782. + return IRQ_HANDLED;
  33783. +}
  33784. +
  33785. +static int bcm2708_setup_state(struct spi_master *master,
  33786. + struct device *dev, struct bcm2708_spi_state *state,
  33787. + u32 hz, u8 csel, u8 mode, u8 bpw)
  33788. +{
  33789. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33790. + int cdiv;
  33791. + unsigned long bus_hz;
  33792. + u32 cs = 0;
  33793. +
  33794. + bus_hz = clk_get_rate(bs->clk);
  33795. +
  33796. + if (hz >= bus_hz) {
  33797. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  33798. + } else if (hz) {
  33799. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  33800. +
  33801. + /* CDIV must be a power of 2, so round up */
  33802. + cdiv = roundup_pow_of_two(cdiv);
  33803. +
  33804. + if (cdiv > 65536) {
  33805. + dev_dbg(dev,
  33806. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  33807. + hz, cdiv, bus_hz / 65536);
  33808. + return -EINVAL;
  33809. + } else if (cdiv == 65536) {
  33810. + cdiv = 0;
  33811. + } else if (cdiv == 1) {
  33812. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  33813. + }
  33814. + } else {
  33815. + cdiv = 0;
  33816. + }
  33817. +
  33818. + switch (bpw) {
  33819. + case 8:
  33820. + break;
  33821. + case 9:
  33822. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  33823. + cs |= SPI_CS_LEN;
  33824. + break;
  33825. + default:
  33826. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  33827. + bpw);
  33828. + return -EINVAL;
  33829. + }
  33830. +
  33831. + if (mode & SPI_CPOL)
  33832. + cs |= SPI_CS_CPOL;
  33833. + if (mode & SPI_CPHA)
  33834. + cs |= SPI_CS_CPHA;
  33835. +
  33836. + if (!(mode & SPI_NO_CS)) {
  33837. + if (mode & SPI_CS_HIGH) {
  33838. + cs |= SPI_CS_CSPOL;
  33839. + cs |= SPI_CS_CSPOL0 << csel;
  33840. + }
  33841. +
  33842. + cs |= csel;
  33843. + } else {
  33844. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  33845. + }
  33846. +
  33847. + if (state) {
  33848. + state->cs = cs;
  33849. + state->cdiv = cdiv;
  33850. + dev_dbg(dev, "setup: want %d Hz; "
  33851. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  33852. + "mode %u: cs 0x%08X\n",
  33853. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  33854. + }
  33855. +
  33856. + return 0;
  33857. +}
  33858. +
  33859. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  33860. + struct spi_message *msg, struct spi_transfer *xfer)
  33861. +{
  33862. + struct spi_device *spi = msg->spi;
  33863. + struct bcm2708_spi_state state, *stp;
  33864. + int ret;
  33865. + u32 cs;
  33866. +
  33867. + if (bs->stopping)
  33868. + return -ESHUTDOWN;
  33869. +
  33870. + if (xfer->bits_per_word || xfer->speed_hz) {
  33871. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  33872. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  33873. + spi->chip_select, spi->mode,
  33874. + xfer->bits_per_word ? xfer->bits_per_word :
  33875. + spi->bits_per_word);
  33876. + if (ret)
  33877. + return ret;
  33878. +
  33879. + stp = &state;
  33880. + } else {
  33881. + stp = spi->controller_state;
  33882. + }
  33883. +
  33884. + INIT_COMPLETION(bs->done);
  33885. + bs->tx_buf = xfer->tx_buf;
  33886. + bs->rx_buf = xfer->rx_buf;
  33887. + bs->len = xfer->len;
  33888. +
  33889. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  33890. +
  33891. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  33892. + bcm2708_wr(bs, SPI_CS, cs);
  33893. +
  33894. + ret = wait_for_completion_timeout(&bs->done,
  33895. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  33896. + if (ret == 0) {
  33897. + dev_err(&spi->dev, "transfer timed out\n");
  33898. + return -ETIMEDOUT;
  33899. + }
  33900. +
  33901. + if (xfer->delay_usecs)
  33902. + udelay(xfer->delay_usecs);
  33903. +
  33904. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  33905. + xfer->cs_change) {
  33906. + /* clear TA and interrupt flags */
  33907. + bcm2708_wr(bs, SPI_CS, stp->cs);
  33908. + }
  33909. +
  33910. + msg->actual_length += (xfer->len - bs->len);
  33911. +
  33912. + return 0;
  33913. +}
  33914. +
  33915. +static void bcm2708_work(struct work_struct *work)
  33916. +{
  33917. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  33918. + unsigned long flags;
  33919. + struct spi_message *msg;
  33920. + struct spi_transfer *xfer;
  33921. + int status = 0;
  33922. +
  33923. + spin_lock_irqsave(&bs->lock, flags);
  33924. + while (!list_empty(&bs->queue)) {
  33925. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  33926. + list_del_init(&msg->queue);
  33927. + spin_unlock_irqrestore(&bs->lock, flags);
  33928. +
  33929. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33930. + status = bcm2708_process_transfer(bs, msg, xfer);
  33931. + if (status)
  33932. + break;
  33933. + }
  33934. +
  33935. + msg->status = status;
  33936. + msg->complete(msg->context);
  33937. +
  33938. + spin_lock_irqsave(&bs->lock, flags);
  33939. + }
  33940. + spin_unlock_irqrestore(&bs->lock, flags);
  33941. +}
  33942. +
  33943. +static int bcm2708_spi_setup(struct spi_device *spi)
  33944. +{
  33945. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33946. + struct bcm2708_spi_state *state;
  33947. + int ret;
  33948. +
  33949. + if (bs->stopping)
  33950. + return -ESHUTDOWN;
  33951. +
  33952. + if (!(spi->mode & SPI_NO_CS) &&
  33953. + (spi->chip_select > spi->master->num_chipselect)) {
  33954. + dev_dbg(&spi->dev,
  33955. + "setup: invalid chipselect %u (%u defined)\n",
  33956. + spi->chip_select, spi->master->num_chipselect);
  33957. + return -EINVAL;
  33958. + }
  33959. +
  33960. + state = spi->controller_state;
  33961. + if (!state) {
  33962. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  33963. + if (!state)
  33964. + return -ENOMEM;
  33965. +
  33966. + spi->controller_state = state;
  33967. + }
  33968. +
  33969. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  33970. + spi->max_speed_hz, spi->chip_select, spi->mode,
  33971. + spi->bits_per_word);
  33972. + if (ret < 0) {
  33973. + kfree(state);
  33974. + spi->controller_state = NULL;
  33975. + return ret;
  33976. + }
  33977. +
  33978. + dev_dbg(&spi->dev,
  33979. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  33980. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  33981. + spi->mode, state->cs, state->cdiv);
  33982. +
  33983. + return 0;
  33984. +}
  33985. +
  33986. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  33987. +{
  33988. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33989. + struct spi_transfer *xfer;
  33990. + int ret;
  33991. + unsigned long flags;
  33992. +
  33993. + if (unlikely(list_empty(&msg->transfers)))
  33994. + return -EINVAL;
  33995. +
  33996. + if (bs->stopping)
  33997. + return -ESHUTDOWN;
  33998. +
  33999. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  34000. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  34001. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  34002. + return -EINVAL;
  34003. + }
  34004. +
  34005. + if (!xfer->bits_per_word || xfer->speed_hz)
  34006. + continue;
  34007. +
  34008. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  34009. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  34010. + spi->chip_select, spi->mode,
  34011. + xfer->bits_per_word ? xfer->bits_per_word :
  34012. + spi->bits_per_word);
  34013. + if (ret)
  34014. + return ret;
  34015. + }
  34016. +
  34017. + msg->status = -EINPROGRESS;
  34018. + msg->actual_length = 0;
  34019. +
  34020. + spin_lock_irqsave(&bs->lock, flags);
  34021. + list_add_tail(&msg->queue, &bs->queue);
  34022. + queue_work(bs->workq, &bs->work);
  34023. + spin_unlock_irqrestore(&bs->lock, flags);
  34024. +
  34025. + return 0;
  34026. +}
  34027. +
  34028. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  34029. +{
  34030. + if (spi->controller_state) {
  34031. + kfree(spi->controller_state);
  34032. + spi->controller_state = NULL;
  34033. + }
  34034. +}
  34035. +
  34036. +static int bcm2708_spi_probe(struct platform_device *pdev)
  34037. +{
  34038. + struct resource *regs;
  34039. + int irq, err = -ENOMEM;
  34040. + struct clk *clk;
  34041. + struct spi_master *master;
  34042. + struct bcm2708_spi *bs;
  34043. +
  34044. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34045. + if (!regs) {
  34046. + dev_err(&pdev->dev, "could not get IO memory\n");
  34047. + return -ENXIO;
  34048. + }
  34049. +
  34050. + irq = platform_get_irq(pdev, 0);
  34051. + if (irq < 0) {
  34052. + dev_err(&pdev->dev, "could not get IRQ\n");
  34053. + return irq;
  34054. + }
  34055. +
  34056. + clk = clk_get(&pdev->dev, NULL);
  34057. + if (IS_ERR(clk)) {
  34058. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  34059. + return PTR_ERR(clk);
  34060. + }
  34061. +
  34062. + bcm2708_init_pinmode();
  34063. +
  34064. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  34065. + if (!master) {
  34066. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  34067. + goto out_clk_put;
  34068. + }
  34069. +
  34070. + /* the spi->mode bits understood by this driver: */
  34071. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  34072. +
  34073. + master->bus_num = pdev->id;
  34074. + master->num_chipselect = 3;
  34075. + master->setup = bcm2708_spi_setup;
  34076. + master->transfer = bcm2708_spi_transfer;
  34077. + master->cleanup = bcm2708_spi_cleanup;
  34078. + platform_set_drvdata(pdev, master);
  34079. +
  34080. + bs = spi_master_get_devdata(master);
  34081. +
  34082. + spin_lock_init(&bs->lock);
  34083. + INIT_LIST_HEAD(&bs->queue);
  34084. + init_completion(&bs->done);
  34085. + INIT_WORK(&bs->work, bcm2708_work);
  34086. +
  34087. + bs->base = ioremap(regs->start, resource_size(regs));
  34088. + if (!bs->base) {
  34089. + dev_err(&pdev->dev, "could not remap memory\n");
  34090. + goto out_master_put;
  34091. + }
  34092. +
  34093. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  34094. + if (!bs->workq) {
  34095. + dev_err(&pdev->dev, "could not create workqueue\n");
  34096. + goto out_iounmap;
  34097. + }
  34098. +
  34099. + bs->irq = irq;
  34100. + bs->clk = clk;
  34101. + bs->stopping = false;
  34102. +
  34103. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  34104. + master);
  34105. + if (err) {
  34106. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  34107. + goto out_workqueue;
  34108. + }
  34109. +
  34110. + /* initialise the hardware */
  34111. + clk_enable(clk);
  34112. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34113. +
  34114. + err = spi_register_master(master);
  34115. + if (err) {
  34116. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  34117. + goto out_free_irq;
  34118. + }
  34119. +
  34120. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  34121. + (unsigned long)regs->start, irq);
  34122. +
  34123. + return 0;
  34124. +
  34125. +out_free_irq:
  34126. + free_irq(bs->irq, master);
  34127. +out_workqueue:
  34128. + destroy_workqueue(bs->workq);
  34129. +out_iounmap:
  34130. + iounmap(bs->base);
  34131. +out_master_put:
  34132. + spi_master_put(master);
  34133. +out_clk_put:
  34134. + clk_put(clk);
  34135. + return err;
  34136. +}
  34137. +
  34138. +static int bcm2708_spi_remove(struct platform_device *pdev)
  34139. +{
  34140. + struct spi_master *master = platform_get_drvdata(pdev);
  34141. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  34142. +
  34143. + /* reset the hardware and block queue progress */
  34144. + spin_lock_irq(&bs->lock);
  34145. + bs->stopping = true;
  34146. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34147. + spin_unlock_irq(&bs->lock);
  34148. +
  34149. + flush_work_sync(&bs->work);
  34150. +
  34151. + clk_disable(bs->clk);
  34152. + clk_put(bs->clk);
  34153. + free_irq(bs->irq, master);
  34154. + iounmap(bs->base);
  34155. +
  34156. + spi_unregister_master(master);
  34157. +
  34158. + return 0;
  34159. +}
  34160. +
  34161. +static struct platform_driver bcm2708_spi_driver = {
  34162. + .driver = {
  34163. + .name = DRV_NAME,
  34164. + .owner = THIS_MODULE,
  34165. + },
  34166. + .probe = bcm2708_spi_probe,
  34167. + .remove = bcm2708_spi_remove,
  34168. +};
  34169. +
  34170. +
  34171. +static int __init bcm2708_spi_init(void)
  34172. +{
  34173. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  34174. +}
  34175. +module_init(bcm2708_spi_init);
  34176. +
  34177. +static void __exit bcm2708_spi_exit(void)
  34178. +{
  34179. + platform_driver_unregister(&bcm2708_spi_driver);
  34180. +}
  34181. +module_exit(bcm2708_spi_exit);
  34182. +
  34183. +
  34184. +//module_platform_driver(bcm2708_spi_driver);
  34185. +
  34186. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  34187. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  34188. +MODULE_LICENSE("GPL v2");
  34189. +MODULE_ALIAS("platform:" DRV_NAME);
  34190. diff -Nur linux-3.10.33/drivers/staging/media/lirc/Kconfig linux-raspberry-pi/drivers/staging/media/lirc/Kconfig
  34191. --- linux-3.10.33/drivers/staging/media/lirc/Kconfig 2014-03-07 06:58:45.000000000 +0100
  34192. +++ linux-raspberry-pi/drivers/staging/media/lirc/Kconfig 2014-03-13 12:46:33.700086324 +0100
  34193. @@ -38,6 +38,12 @@
  34194. help
  34195. Driver for Homebrew Parallel Port Receivers
  34196. +config LIRC_RPI
  34197. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  34198. + depends on LIRC
  34199. + help
  34200. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  34201. +
  34202. config LIRC_SASEM
  34203. tristate "Sasem USB IR Remote"
  34204. depends on LIRC && USB
  34205. diff -Nur linux-3.10.33/drivers/staging/media/lirc/lirc_rpi.c linux-raspberry-pi/drivers/staging/media/lirc/lirc_rpi.c
  34206. --- linux-3.10.33/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  34207. +++ linux-raspberry-pi/drivers/staging/media/lirc/lirc_rpi.c 2014-03-13 12:46:33.700086324 +0100
  34208. @@ -0,0 +1,693 @@
  34209. +/*
  34210. + * lirc_rpi.c
  34211. + *
  34212. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  34213. + * (space-lengths) (just like the lirc_serial driver does)
  34214. + * between GPIO interrupt events on the Raspberry Pi.
  34215. + * Lots of code has been taken from the lirc_serial module,
  34216. + * so I would like say thanks to the authors.
  34217. + *
  34218. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  34219. + * Michael Bishop <cleverca22@gmail.com>
  34220. + * This program is free software; you can redistribute it and/or modify
  34221. + * it under the terms of the GNU General Public License as published by
  34222. + * the Free Software Foundation; either version 2 of the License, or
  34223. + * (at your option) any later version.
  34224. + *
  34225. + * This program is distributed in the hope that it will be useful,
  34226. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34227. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34228. + * GNU General Public License for more details.
  34229. + *
  34230. + * You should have received a copy of the GNU General Public License
  34231. + * along with this program; if not, write to the Free Software
  34232. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  34233. + */
  34234. +
  34235. +#include <linux/module.h>
  34236. +#include <linux/errno.h>
  34237. +#include <linux/interrupt.h>
  34238. +#include <linux/sched.h>
  34239. +#include <linux/kernel.h>
  34240. +#include <linux/time.h>
  34241. +#include <linux/string.h>
  34242. +#include <linux/delay.h>
  34243. +#include <linux/platform_device.h>
  34244. +#include <linux/irq.h>
  34245. +#include <linux/spinlock.h>
  34246. +#include <media/lirc.h>
  34247. +#include <media/lirc_dev.h>
  34248. +#include <linux/gpio.h>
  34249. +
  34250. +#define LIRC_DRIVER_NAME "lirc_rpi"
  34251. +#define RBUF_LEN 256
  34252. +#define LIRC_TRANSMITTER_LATENCY 256
  34253. +
  34254. +#ifndef MAX_UDELAY_MS
  34255. +#define MAX_UDELAY_US 5000
  34256. +#else
  34257. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  34258. +#endif
  34259. +
  34260. +#define dprintk(fmt, args...) \
  34261. + do { \
  34262. + if (debug) \
  34263. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  34264. + fmt, ## args); \
  34265. + } while (0)
  34266. +
  34267. +/* module parameters */
  34268. +
  34269. +/* set the default GPIO input pin */
  34270. +static int gpio_in_pin = 18;
  34271. +/* set the default GPIO output pin */
  34272. +static int gpio_out_pin = 17;
  34273. +/* enable debugging messages */
  34274. +static bool debug;
  34275. +/* -1 = auto, 0 = active high, 1 = active low */
  34276. +static int sense = -1;
  34277. +/* use softcarrier by default */
  34278. +static bool softcarrier = 1;
  34279. +/* 0 = do not invert output, 1 = invert output */
  34280. +static bool invert = 0;
  34281. +
  34282. +struct gpio_chip *gpiochip;
  34283. +struct irq_chip *irqchip;
  34284. +struct irq_data *irqdata;
  34285. +
  34286. +/* forward declarations */
  34287. +static long send_pulse(unsigned long length);
  34288. +static void send_space(long length);
  34289. +static void lirc_rpi_exit(void);
  34290. +
  34291. +int valid_gpio_pins[] = { 0, 1, 4, 8, 7, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23,
  34292. + 24, 25 };
  34293. +
  34294. +static struct platform_device *lirc_rpi_dev;
  34295. +static struct timeval lasttv = { 0, 0 };
  34296. +static struct lirc_buffer rbuf;
  34297. +static spinlock_t lock;
  34298. +
  34299. +/* initialized/set in init_timing_params() */
  34300. +static unsigned int freq = 38000;
  34301. +static unsigned int duty_cycle = 50;
  34302. +static unsigned long period;
  34303. +static unsigned long pulse_width;
  34304. +static unsigned long space_width;
  34305. +
  34306. +static void safe_udelay(unsigned long usecs)
  34307. +{
  34308. + while (usecs > MAX_UDELAY_US) {
  34309. + udelay(MAX_UDELAY_US);
  34310. + usecs -= MAX_UDELAY_US;
  34311. + }
  34312. + udelay(usecs);
  34313. +}
  34314. +
  34315. +static int init_timing_params(unsigned int new_duty_cycle,
  34316. + unsigned int new_freq)
  34317. +{
  34318. + /*
  34319. + * period, pulse/space width are kept with 8 binary places -
  34320. + * IE multiplied by 256.
  34321. + */
  34322. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  34323. + LIRC_TRANSMITTER_LATENCY)
  34324. + return -EINVAL;
  34325. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  34326. + LIRC_TRANSMITTER_LATENCY)
  34327. + return -EINVAL;
  34328. + duty_cycle = new_duty_cycle;
  34329. + freq = new_freq;
  34330. + period = 256 * 1000000L / freq;
  34331. + pulse_width = period * duty_cycle / 100;
  34332. + space_width = period - pulse_width;
  34333. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  34334. + "space=%ld\n", freq, pulse_width, space_width);
  34335. + return 0;
  34336. +}
  34337. +
  34338. +static long send_pulse_softcarrier(unsigned long length)
  34339. +{
  34340. + int flag;
  34341. + unsigned long actual, target, d;
  34342. +
  34343. + length <<= 8;
  34344. +
  34345. + actual = 0; target = 0; flag = 0;
  34346. + while (actual < length) {
  34347. + if (flag) {
  34348. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34349. + target += space_width;
  34350. + } else {
  34351. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  34352. + target += pulse_width;
  34353. + }
  34354. + d = (target - actual -
  34355. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  34356. + /*
  34357. + * Note - we've checked in ioctl that the pulse/space
  34358. + * widths are big enough so that d is > 0
  34359. + */
  34360. + udelay(d);
  34361. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  34362. + flag = !flag;
  34363. + }
  34364. + return (actual-length) >> 8;
  34365. +}
  34366. +
  34367. +static long send_pulse(unsigned long length)
  34368. +{
  34369. + if (length <= 0)
  34370. + return 0;
  34371. +
  34372. + if (softcarrier) {
  34373. + return send_pulse_softcarrier(length);
  34374. + } else {
  34375. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  34376. + safe_udelay(length);
  34377. + return 0;
  34378. + }
  34379. +}
  34380. +
  34381. +static void send_space(long length)
  34382. +{
  34383. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34384. + if (length <= 0)
  34385. + return;
  34386. + safe_udelay(length);
  34387. +}
  34388. +
  34389. +static void rbwrite(int l)
  34390. +{
  34391. + if (lirc_buffer_full(&rbuf)) {
  34392. + /* no new signals will be accepted */
  34393. + dprintk("Buffer overrun\n");
  34394. + return;
  34395. + }
  34396. + lirc_buffer_write(&rbuf, (void *)&l);
  34397. +}
  34398. +
  34399. +static void frbwrite(int l)
  34400. +{
  34401. + /* simple noise filter */
  34402. + static int pulse, space;
  34403. + static unsigned int ptr;
  34404. +
  34405. + if (ptr > 0 && (l & PULSE_BIT)) {
  34406. + pulse += l & PULSE_MASK;
  34407. + if (pulse > 250) {
  34408. + rbwrite(space);
  34409. + rbwrite(pulse | PULSE_BIT);
  34410. + ptr = 0;
  34411. + pulse = 0;
  34412. + }
  34413. + return;
  34414. + }
  34415. + if (!(l & PULSE_BIT)) {
  34416. + if (ptr == 0) {
  34417. + if (l > 20000) {
  34418. + space = l;
  34419. + ptr++;
  34420. + return;
  34421. + }
  34422. + } else {
  34423. + if (l > 20000) {
  34424. + space += pulse;
  34425. + if (space > PULSE_MASK)
  34426. + space = PULSE_MASK;
  34427. + space += l;
  34428. + if (space > PULSE_MASK)
  34429. + space = PULSE_MASK;
  34430. + pulse = 0;
  34431. + return;
  34432. + }
  34433. + rbwrite(space);
  34434. + rbwrite(pulse | PULSE_BIT);
  34435. + ptr = 0;
  34436. + pulse = 0;
  34437. + }
  34438. + }
  34439. + rbwrite(l);
  34440. +}
  34441. +
  34442. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  34443. +{
  34444. + struct timeval tv;
  34445. + long deltv;
  34446. + int data;
  34447. + int signal;
  34448. +
  34449. + /* use the GPIO signal level */
  34450. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  34451. +
  34452. + /* unmask the irq */
  34453. + irqchip->irq_unmask(irqdata);
  34454. +
  34455. + if (sense != -1) {
  34456. + /* get current time */
  34457. + do_gettimeofday(&tv);
  34458. +
  34459. + /* calc time since last interrupt in microseconds */
  34460. + deltv = tv.tv_sec-lasttv.tv_sec;
  34461. + if (tv.tv_sec < lasttv.tv_sec ||
  34462. + (tv.tv_sec == lasttv.tv_sec &&
  34463. + tv.tv_usec < lasttv.tv_usec)) {
  34464. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34465. + ": AIEEEE: your clock just jumped backwards\n");
  34466. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34467. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  34468. + tv.tv_sec, lasttv.tv_sec,
  34469. + tv.tv_usec, lasttv.tv_usec);
  34470. + data = PULSE_MASK;
  34471. + } else if (deltv > 15) {
  34472. + data = PULSE_MASK; /* really long time */
  34473. + if (!(signal^sense)) {
  34474. + /* sanity check */
  34475. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34476. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  34477. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  34478. + tv.tv_usec, lasttv.tv_usec);
  34479. + /*
  34480. + * detecting pulse while this
  34481. + * MUST be a space!
  34482. + */
  34483. + sense = sense ? 0 : 1;
  34484. + }
  34485. + } else {
  34486. + data = (int) (deltv*1000000 +
  34487. + (tv.tv_usec - lasttv.tv_usec));
  34488. + }
  34489. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  34490. + lasttv = tv;
  34491. + wake_up_interruptible(&rbuf.wait_poll);
  34492. + }
  34493. +
  34494. + return IRQ_HANDLED;
  34495. +}
  34496. +
  34497. +static int is_right_chip(struct gpio_chip *chip, void *data)
  34498. +{
  34499. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  34500. +
  34501. + if (strcmp(data, chip->label) == 0)
  34502. + return 1;
  34503. + return 0;
  34504. +}
  34505. +
  34506. +static int init_port(void)
  34507. +{
  34508. + int i, nlow, nhigh, ret, irq;
  34509. +
  34510. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  34511. +
  34512. + if (!gpiochip)
  34513. + return -ENODEV;
  34514. +
  34515. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  34516. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34517. + ": cant claim gpio pin %d\n", gpio_out_pin);
  34518. + ret = -ENODEV;
  34519. + goto exit_init_port;
  34520. + }
  34521. +
  34522. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  34523. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34524. + ": cant claim gpio pin %d\n", gpio_in_pin);
  34525. + ret = -ENODEV;
  34526. + goto exit_gpio_free_out_pin;
  34527. + }
  34528. +
  34529. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  34530. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  34531. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34532. +
  34533. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  34534. + dprintk("to_irq %d\n", irq);
  34535. + irqdata = irq_get_irq_data(irq);
  34536. +
  34537. + if (irqdata && irqdata->chip) {
  34538. + irqchip = irqdata->chip;
  34539. + } else {
  34540. + ret = -ENODEV;
  34541. + goto exit_gpio_free_in_pin;
  34542. + }
  34543. +
  34544. + /* if pin is high, then this must be an active low receiver. */
  34545. + if (sense == -1) {
  34546. + /* wait 1/2 sec for the power supply */
  34547. + msleep(500);
  34548. +
  34549. + /*
  34550. + * probe 9 times every 0.04s, collect "votes" for
  34551. + * active high/low
  34552. + */
  34553. + nlow = 0;
  34554. + nhigh = 0;
  34555. + for (i = 0; i < 9; i++) {
  34556. + if (gpiochip->get(gpiochip, gpio_in_pin))
  34557. + nlow++;
  34558. + else
  34559. + nhigh++;
  34560. + msleep(40);
  34561. + }
  34562. + sense = (nlow >= nhigh ? 1 : 0);
  34563. + printk(KERN_INFO LIRC_DRIVER_NAME
  34564. + ": auto-detected active %s receiver on GPIO pin %d\n",
  34565. + sense ? "low" : "high", gpio_in_pin);
  34566. + } else {
  34567. + printk(KERN_INFO LIRC_DRIVER_NAME
  34568. + ": manually using active %s receiver on GPIO pin %d\n",
  34569. + sense ? "low" : "high", gpio_in_pin);
  34570. + }
  34571. +
  34572. + return 0;
  34573. +
  34574. + exit_gpio_free_in_pin:
  34575. + gpio_free(gpio_in_pin);
  34576. +
  34577. + exit_gpio_free_out_pin:
  34578. + gpio_free(gpio_out_pin);
  34579. +
  34580. + exit_init_port:
  34581. + return ret;
  34582. +}
  34583. +
  34584. +// called when the character device is opened
  34585. +static int set_use_inc(void *data)
  34586. +{
  34587. + int result;
  34588. + unsigned long flags;
  34589. +
  34590. + /* initialize timestamp */
  34591. + do_gettimeofday(&lasttv);
  34592. +
  34593. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  34594. + (irq_handler_t) irq_handler, 0,
  34595. + LIRC_DRIVER_NAME, (void*) 0);
  34596. +
  34597. + switch (result) {
  34598. + case -EBUSY:
  34599. + printk(KERN_ERR LIRC_DRIVER_NAME
  34600. + ": IRQ %d is busy\n",
  34601. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34602. + return -EBUSY;
  34603. + case -EINVAL:
  34604. + printk(KERN_ERR LIRC_DRIVER_NAME
  34605. + ": Bad irq number or handler\n");
  34606. + return -EINVAL;
  34607. + default:
  34608. + dprintk("Interrupt %d obtained\n",
  34609. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34610. + break;
  34611. + };
  34612. +
  34613. + /* initialize pulse/space widths */
  34614. + init_timing_params(duty_cycle, freq);
  34615. +
  34616. + spin_lock_irqsave(&lock, flags);
  34617. +
  34618. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  34619. + irqchip->irq_set_type(irqdata,
  34620. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  34621. +
  34622. + /* unmask the irq */
  34623. + irqchip->irq_unmask(irqdata);
  34624. +
  34625. + spin_unlock_irqrestore(&lock, flags);
  34626. +
  34627. + return 0;
  34628. +}
  34629. +
  34630. +static void set_use_dec(void *data)
  34631. +{
  34632. + unsigned long flags;
  34633. +
  34634. + spin_lock_irqsave(&lock, flags);
  34635. +
  34636. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  34637. + irqchip->irq_set_type(irqdata, 0);
  34638. + irqchip->irq_mask(irqdata);
  34639. +
  34640. + spin_unlock_irqrestore(&lock, flags);
  34641. +
  34642. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  34643. +
  34644. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  34645. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  34646. +}
  34647. +
  34648. +static ssize_t lirc_write(struct file *file, const char *buf,
  34649. + size_t n, loff_t *ppos)
  34650. +{
  34651. + int i, count;
  34652. + unsigned long flags;
  34653. + long delta = 0;
  34654. + int *wbuf;
  34655. +
  34656. + count = n / sizeof(int);
  34657. + if (n % sizeof(int) || count % 2 == 0)
  34658. + return -EINVAL;
  34659. + wbuf = memdup_user(buf, n);
  34660. + if (IS_ERR(wbuf))
  34661. + return PTR_ERR(wbuf);
  34662. + spin_lock_irqsave(&lock, flags);
  34663. +
  34664. + for (i = 0; i < count; i++) {
  34665. + if (i%2)
  34666. + send_space(wbuf[i] - delta);
  34667. + else
  34668. + delta = send_pulse(wbuf[i]);
  34669. + }
  34670. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34671. +
  34672. + spin_unlock_irqrestore(&lock, flags);
  34673. + kfree(wbuf);
  34674. + return n;
  34675. +}
  34676. +
  34677. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  34678. +{
  34679. + int result;
  34680. + __u32 value;
  34681. +
  34682. + switch (cmd) {
  34683. + case LIRC_GET_SEND_MODE:
  34684. + return -ENOIOCTLCMD;
  34685. + break;
  34686. +
  34687. + case LIRC_SET_SEND_MODE:
  34688. + result = get_user(value, (__u32 *) arg);
  34689. + if (result)
  34690. + return result;
  34691. + /* only LIRC_MODE_PULSE supported */
  34692. + if (value != LIRC_MODE_PULSE)
  34693. + return -ENOSYS;
  34694. + break;
  34695. +
  34696. + case LIRC_GET_LENGTH:
  34697. + return -ENOSYS;
  34698. + break;
  34699. +
  34700. + case LIRC_SET_SEND_DUTY_CYCLE:
  34701. + dprintk("SET_SEND_DUTY_CYCLE\n");
  34702. + result = get_user(value, (__u32 *) arg);
  34703. + if (result)
  34704. + return result;
  34705. + if (value <= 0 || value > 100)
  34706. + return -EINVAL;
  34707. + return init_timing_params(value, freq);
  34708. + break;
  34709. +
  34710. + case LIRC_SET_SEND_CARRIER:
  34711. + dprintk("SET_SEND_CARRIER\n");
  34712. + result = get_user(value, (__u32 *) arg);
  34713. + if (result)
  34714. + return result;
  34715. + if (value > 500000 || value < 20000)
  34716. + return -EINVAL;
  34717. + return init_timing_params(duty_cycle, value);
  34718. + break;
  34719. +
  34720. + default:
  34721. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  34722. + }
  34723. + return 0;
  34724. +}
  34725. +
  34726. +static const struct file_operations lirc_fops = {
  34727. + .owner = THIS_MODULE,
  34728. + .write = lirc_write,
  34729. + .unlocked_ioctl = lirc_ioctl,
  34730. + .read = lirc_dev_fop_read,
  34731. + .poll = lirc_dev_fop_poll,
  34732. + .open = lirc_dev_fop_open,
  34733. + .release = lirc_dev_fop_close,
  34734. + .llseek = no_llseek,
  34735. +};
  34736. +
  34737. +static struct lirc_driver driver = {
  34738. + .name = LIRC_DRIVER_NAME,
  34739. + .minor = -1,
  34740. + .code_length = 1,
  34741. + .sample_rate = 0,
  34742. + .data = NULL,
  34743. + .add_to_buf = NULL,
  34744. + .rbuf = &rbuf,
  34745. + .set_use_inc = set_use_inc,
  34746. + .set_use_dec = set_use_dec,
  34747. + .fops = &lirc_fops,
  34748. + .dev = NULL,
  34749. + .owner = THIS_MODULE,
  34750. +};
  34751. +
  34752. +static struct platform_driver lirc_rpi_driver = {
  34753. + .driver = {
  34754. + .name = LIRC_DRIVER_NAME,
  34755. + .owner = THIS_MODULE,
  34756. + },
  34757. +};
  34758. +
  34759. +static int __init lirc_rpi_init(void)
  34760. +{
  34761. + int result;
  34762. +
  34763. + /* Init read buffer. */
  34764. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  34765. + if (result < 0)
  34766. + return -ENOMEM;
  34767. +
  34768. + result = platform_driver_register(&lirc_rpi_driver);
  34769. + if (result) {
  34770. + printk(KERN_ERR LIRC_DRIVER_NAME
  34771. + ": lirc register returned %d\n", result);
  34772. + goto exit_buffer_free;
  34773. + }
  34774. +
  34775. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  34776. + if (!lirc_rpi_dev) {
  34777. + result = -ENOMEM;
  34778. + goto exit_driver_unregister;
  34779. + }
  34780. +
  34781. + result = platform_device_add(lirc_rpi_dev);
  34782. + if (result)
  34783. + goto exit_device_put;
  34784. +
  34785. + return 0;
  34786. +
  34787. + exit_device_put:
  34788. + platform_device_put(lirc_rpi_dev);
  34789. +
  34790. + exit_driver_unregister:
  34791. + platform_driver_unregister(&lirc_rpi_driver);
  34792. +
  34793. + exit_buffer_free:
  34794. + lirc_buffer_free(&rbuf);
  34795. +
  34796. + return result;
  34797. +}
  34798. +
  34799. +static void lirc_rpi_exit(void)
  34800. +{
  34801. + platform_device_unregister(lirc_rpi_dev);
  34802. + platform_driver_unregister(&lirc_rpi_driver);
  34803. + lirc_buffer_free(&rbuf);
  34804. +}
  34805. +
  34806. +static int __init lirc_rpi_init_module(void)
  34807. +{
  34808. + int result, i;
  34809. +
  34810. + result = lirc_rpi_init();
  34811. + if (result)
  34812. + return result;
  34813. +
  34814. + /* check if the module received valid gpio pin numbers */
  34815. + result = 0;
  34816. + if (gpio_in_pin != gpio_out_pin) {
  34817. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  34818. + if (gpio_in_pin == valid_gpio_pins[i] ||
  34819. + gpio_out_pin == valid_gpio_pins[i]) {
  34820. + result++;
  34821. + }
  34822. + }
  34823. + }
  34824. +
  34825. + if (result != 2) {
  34826. + result = -EINVAL;
  34827. + printk(KERN_ERR LIRC_DRIVER_NAME
  34828. + ": invalid GPIO pin(s) specified!\n");
  34829. + goto exit_rpi;
  34830. + }
  34831. +
  34832. + result = init_port();
  34833. + if (result < 0)
  34834. + goto exit_rpi;
  34835. +
  34836. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  34837. + LIRC_CAN_SET_SEND_CARRIER |
  34838. + LIRC_CAN_SEND_PULSE |
  34839. + LIRC_CAN_REC_MODE2;
  34840. +
  34841. + driver.dev = &lirc_rpi_dev->dev;
  34842. + driver.minor = lirc_register_driver(&driver);
  34843. +
  34844. + if (driver.minor < 0) {
  34845. + printk(KERN_ERR LIRC_DRIVER_NAME
  34846. + ": device registration failed with %d\n", result);
  34847. + result = -EIO;
  34848. + goto exit_rpi;
  34849. + }
  34850. +
  34851. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  34852. +
  34853. + return 0;
  34854. +
  34855. + exit_rpi:
  34856. + lirc_rpi_exit();
  34857. +
  34858. + return result;
  34859. +}
  34860. +
  34861. +static void __exit lirc_rpi_exit_module(void)
  34862. +{
  34863. + gpio_free(gpio_out_pin);
  34864. + gpio_free(gpio_in_pin);
  34865. +
  34866. + lirc_rpi_exit();
  34867. +
  34868. + lirc_unregister_driver(driver.minor);
  34869. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  34870. +}
  34871. +
  34872. +module_init(lirc_rpi_init_module);
  34873. +module_exit(lirc_rpi_exit_module);
  34874. +
  34875. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  34876. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  34877. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  34878. +MODULE_LICENSE("GPL");
  34879. +
  34880. +module_param(gpio_out_pin, int, S_IRUGO);
  34881. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  34882. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  34883. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  34884. +
  34885. +module_param(gpio_in_pin, int, S_IRUGO);
  34886. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  34887. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  34888. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  34889. +
  34890. +module_param(sense, int, S_IRUGO);
  34891. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  34892. + " (0 = active high, 1 = active low )");
  34893. +
  34894. +module_param(softcarrier, bool, S_IRUGO);
  34895. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  34896. +
  34897. +module_param(invert, bool, S_IRUGO);
  34898. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  34899. +
  34900. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  34901. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  34902. diff -Nur linux-3.10.33/drivers/staging/media/lirc/Makefile linux-raspberry-pi/drivers/staging/media/lirc/Makefile
  34903. --- linux-3.10.33/drivers/staging/media/lirc/Makefile 2014-03-07 06:58:45.000000000 +0100
  34904. +++ linux-raspberry-pi/drivers/staging/media/lirc/Makefile 2014-03-13 12:46:33.700086324 +0100
  34905. @@ -7,6 +7,7 @@
  34906. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  34907. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  34908. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  34909. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  34910. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  34911. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  34912. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  34913. diff -Nur linux-3.10.33/drivers/thermal/bcm2835-thermal.c linux-raspberry-pi/drivers/thermal/bcm2835-thermal.c
  34914. --- linux-3.10.33/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  34915. +++ linux-raspberry-pi/drivers/thermal/bcm2835-thermal.c 2014-03-13 12:46:37.912094770 +0100
  34916. @@ -0,0 +1,184 @@
  34917. +/*****************************************************************************
  34918. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  34919. +*
  34920. +* Unless you and Broadcom execute a separate written software license
  34921. +* agreement governing use of this software, this software is licensed to you
  34922. +* under the terms of the GNU General Public License version 2, available at
  34923. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  34924. +*
  34925. +* Notwithstanding the above, under no circumstances may you combine this
  34926. +* software in any way with any other Broadcom software provided under a
  34927. +* license other than the GPL, without Broadcom's express prior written
  34928. +* consent.
  34929. +*****************************************************************************/
  34930. +
  34931. +#include <linux/kernel.h>
  34932. +#include <linux/module.h>
  34933. +#include <linux/init.h>
  34934. +#include <linux/platform_device.h>
  34935. +#include <linux/slab.h>
  34936. +#include <linux/sysfs.h>
  34937. +#include <mach/vcio.h>
  34938. +#include <linux/thermal.h>
  34939. +
  34940. +
  34941. +/* --- DEFINITIONS --- */
  34942. +#define MODULE_NAME "bcm2835_thermal"
  34943. +
  34944. +/*#define THERMAL_DEBUG_ENABLE*/
  34945. +
  34946. +#ifdef THERMAL_DEBUG_ENABLE
  34947. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  34948. +#else
  34949. +#define print_debug(fmt,...)
  34950. +#endif
  34951. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  34952. +
  34953. +#define VC_TAG_GET_TEMP 0x00030006
  34954. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  34955. +
  34956. +typedef enum {
  34957. + TEMP,
  34958. + MAX_TEMP,
  34959. +} temp_type;
  34960. +
  34961. +/* --- STRUCTS --- */
  34962. +/* tag part of the message */
  34963. +struct vc_msg_tag {
  34964. + uint32_t tag_id; /* the tag ID for the temperature */
  34965. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  34966. + uint32_t request_code; /* identifies message as a request (should be 0) */
  34967. + uint32_t id; /* extra ID field (should be 0) */
  34968. + uint32_t val; /* returned value of the temperature */
  34969. +};
  34970. +
  34971. +/* message structure to be sent to videocore */
  34972. +struct vc_msg {
  34973. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  34974. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  34975. + struct vc_msg_tag tag; /* the tag structure above to make */
  34976. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  34977. +};
  34978. +
  34979. +struct bcm2835_thermal_data {
  34980. + struct thermal_zone_device *thermal_dev;
  34981. + struct vc_msg msg;
  34982. +};
  34983. +
  34984. +/* --- GLOBALS --- */
  34985. +static struct bcm2835_thermal_data bcm2835_data;
  34986. +
  34987. +/* Thermal Device Operations */
  34988. +static struct thermal_zone_device_ops ops;
  34989. +
  34990. +/* --- FUNCTIONS --- */
  34991. +
  34992. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  34993. +{
  34994. + int result = -1, retry = 3;
  34995. + print_debug("IN");
  34996. +
  34997. + *temp = 0;
  34998. + while (result != 0 && retry-- > 0) {
  34999. + /* wipe all previous message data */
  35000. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  35001. +
  35002. + /* prepare message */
  35003. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  35004. + bcm2835_data.msg.tag.buffer_size = 8;
  35005. + bcm2835_data.msg.tag.tag_id = tag_id;
  35006. +
  35007. + /* send the message */
  35008. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  35009. + print_debug("Got %stemperature as %u (%d,%x)\n", tag_id==VC_TAG_GET_MAX_TEMP ? "max ":"", (uint)bcm2835_data.msg.tag.val, result, bcm2835_data.msg.request_code);
  35010. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  35011. + result = -1;
  35012. + }
  35013. +
  35014. + /* check if it was all ok and return the rate in milli degrees C */
  35015. + if (result == 0)
  35016. + *temp = (uint)bcm2835_data.msg.tag.val;
  35017. + else
  35018. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  35019. + print_debug("OUT");
  35020. + return result;
  35021. +}
  35022. +
  35023. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  35024. +{
  35025. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  35026. +}
  35027. +
  35028. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  35029. +{
  35030. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  35031. +}
  35032. +
  35033. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  35034. +{
  35035. + *trip_type = THERMAL_TRIP_HOT;
  35036. + return 0;
  35037. +}
  35038. +
  35039. +
  35040. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  35041. +{
  35042. + *dev_mode = THERMAL_DEVICE_ENABLED;
  35043. + return 0;
  35044. +}
  35045. +
  35046. +
  35047. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  35048. +{
  35049. + print_debug("IN");
  35050. + print_debug("THERMAL Driver has been probed!");
  35051. +
  35052. + /* check that the device isn't null!*/
  35053. + if(pdev == NULL)
  35054. + {
  35055. + print_debug("Platform device is empty!");
  35056. + return -ENODEV;
  35057. + }
  35058. +
  35059. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  35060. + {
  35061. + print_debug("Unable to register the thermal device!");
  35062. + return -EFAULT;
  35063. + }
  35064. + return 0;
  35065. +}
  35066. +
  35067. +
  35068. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  35069. +{
  35070. + print_debug("IN");
  35071. +
  35072. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  35073. +
  35074. + print_debug("OUT");
  35075. +
  35076. + return 0;
  35077. +}
  35078. +
  35079. +static struct thermal_zone_device_ops ops = {
  35080. + .get_temp = bcm2835_get_temp,
  35081. + .get_trip_temp = bcm2835_get_max_temp,
  35082. + .get_trip_type = bcm2835_get_trip_type,
  35083. + .get_mode = bcm2835_get_mode,
  35084. +};
  35085. +
  35086. +/* Thermal Driver */
  35087. +static struct platform_driver bcm2835_thermal_driver = {
  35088. + .probe = bcm2835_thermal_probe,
  35089. + .remove = bcm2835_thermal_remove,
  35090. + .driver = {
  35091. + .name = "bcm2835_thermal",
  35092. + .owner = THIS_MODULE,
  35093. + },
  35094. +};
  35095. +
  35096. +MODULE_LICENSE("GPL");
  35097. +MODULE_AUTHOR("Dorian Peake");
  35098. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  35099. +
  35100. +module_platform_driver(bcm2835_thermal_driver);
  35101. diff -Nur linux-3.10.33/drivers/thermal/Kconfig linux-raspberry-pi/drivers/thermal/Kconfig
  35102. --- linux-3.10.33/drivers/thermal/Kconfig 2014-03-07 06:58:45.000000000 +0100
  35103. +++ linux-raspberry-pi/drivers/thermal/Kconfig 2014-03-13 12:46:37.912094770 +0100
  35104. @@ -169,4 +169,11 @@
  35105. enforce idle time which results in more package C-state residency. The
  35106. user interface is exposed via generic thermal framework.
  35107. +config THERMAL_BCM2835
  35108. + tristate "BCM2835 Thermal Driver"
  35109. + help
  35110. + This will enable temperature monitoring for the Broadcom BCM2835
  35111. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  35112. +
  35113. endif
  35114. +
  35115. diff -Nur linux-3.10.33/drivers/thermal/Makefile linux-raspberry-pi/drivers/thermal/Makefile
  35116. --- linux-3.10.33/drivers/thermal/Makefile 2014-03-07 06:58:45.000000000 +0100
  35117. +++ linux-raspberry-pi/drivers/thermal/Makefile 2014-03-13 12:46:37.912094770 +0100
  35118. @@ -23,4 +23,5 @@
  35119. obj-$(CONFIG_ARMADA_THERMAL) += armada_thermal.o
  35120. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  35121. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  35122. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  35123. diff -Nur linux-3.10.33/drivers/tty/serial/amba-pl011.c linux-raspberry-pi/drivers/tty/serial/amba-pl011.c
  35124. --- linux-3.10.33/drivers/tty/serial/amba-pl011.c 2014-03-07 06:58:45.000000000 +0100
  35125. +++ linux-raspberry-pi/drivers/tty/serial/amba-pl011.c 2014-03-13 12:46:38.336095622 +0100
  35126. @@ -84,7 +84,7 @@
  35127. static unsigned int get_fifosize_arm(unsigned int periphid)
  35128. {
  35129. - unsigned int rev = (periphid >> 20) & 0xf;
  35130. + unsigned int rev = 0; //(periphid >> 20) & 0xf;
  35131. return rev < 3 ? 16 : 32;
  35132. }
  35133. diff -Nur linux-3.10.33/drivers/usb/core/generic.c linux-raspberry-pi/drivers/usb/core/generic.c
  35134. --- linux-3.10.33/drivers/usb/core/generic.c 2014-03-07 06:58:45.000000000 +0100
  35135. +++ linux-raspberry-pi/drivers/usb/core/generic.c 2014-03-13 12:46:38.912096777 +0100
  35136. @@ -152,6 +152,7 @@
  35137. dev_warn(&udev->dev,
  35138. "no configuration chosen from %d choice%s\n",
  35139. num_configs, plural(num_configs));
  35140. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  35141. }
  35142. return i;
  35143. }
  35144. diff -Nur linux-3.10.33/drivers/usb/core/message.c linux-raspberry-pi/drivers/usb/core/message.c
  35145. --- linux-3.10.33/drivers/usb/core/message.c 2014-03-07 06:58:45.000000000 +0100
  35146. +++ linux-raspberry-pi/drivers/usb/core/message.c 2014-03-13 12:46:38.916096785 +0100
  35147. @@ -1875,6 +1875,85 @@
  35148. if (cp->string == NULL &&
  35149. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  35150. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  35151. +/* Uncomment this define to enable the HS Electrical Test support */
  35152. +#define DWC_HS_ELECT_TST 1
  35153. +#ifdef DWC_HS_ELECT_TST
  35154. + /* Here we implement the HS Electrical Test support. The
  35155. + * tester uses a vendor ID of 0x1A0A to indicate we should
  35156. + * run a special test sequence. The product ID tells us
  35157. + * which sequence to run. We invoke the test sequence by
  35158. + * sending a non-standard SetFeature command to our root
  35159. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  35160. + * recognize the command and perform the desired test
  35161. + * sequence.
  35162. + */
  35163. + if (dev->descriptor.idVendor == 0x1A0A) {
  35164. + /* HSOTG Electrical Test */
  35165. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  35166. +
  35167. + if (dev->bus && dev->bus->root_hub) {
  35168. + struct usb_device *hdev = dev->bus->root_hub;
  35169. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  35170. +
  35171. + switch (dev->descriptor.idProduct) {
  35172. + case 0x0101: /* TEST_SE0_NAK */
  35173. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  35174. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35175. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35176. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  35177. + break;
  35178. +
  35179. + case 0x0102: /* TEST_J */
  35180. + dev_warn(&dev->dev, "TEST_J\n");
  35181. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35182. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35183. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  35184. + break;
  35185. +
  35186. + case 0x0103: /* TEST_K */
  35187. + dev_warn(&dev->dev, "TEST_K\n");
  35188. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35189. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35190. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  35191. + break;
  35192. +
  35193. + case 0x0104: /* TEST_PACKET */
  35194. + dev_warn(&dev->dev, "TEST_PACKET\n");
  35195. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35196. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35197. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  35198. + break;
  35199. +
  35200. + case 0x0105: /* TEST_FORCE_ENABLE */
  35201. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  35202. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35203. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35204. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  35205. + break;
  35206. +
  35207. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  35208. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  35209. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35210. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35211. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  35212. + break;
  35213. +
  35214. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  35215. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  35216. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35217. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35218. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  35219. + break;
  35220. +
  35221. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  35222. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  35223. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35224. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35225. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  35226. + }
  35227. + }
  35228. + }
  35229. +#endif /* DWC_HS_ELECT_TST */
  35230. /* Now that the interfaces are installed, re-enable LPM. */
  35231. usb_unlocked_enable_lpm(dev);
  35232. diff -Nur linux-3.10.33/drivers/usb/core/otg_whitelist.h linux-raspberry-pi/drivers/usb/core/otg_whitelist.h
  35233. --- linux-3.10.33/drivers/usb/core/otg_whitelist.h 2014-03-07 06:58:45.000000000 +0100
  35234. +++ linux-raspberry-pi/drivers/usb/core/otg_whitelist.h 2014-03-13 12:46:38.916096785 +0100
  35235. @@ -19,33 +19,82 @@
  35236. static struct usb_device_id whitelist_table [] = {
  35237. /* hubs are optional in OTG, but very handy ... */
  35238. +#define CERT_WITHOUT_HUBS
  35239. +#if defined(CERT_WITHOUT_HUBS)
  35240. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  35241. +#else
  35242. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  35243. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  35244. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  35245. +#endif
  35246. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  35247. /* FIXME actually, printers are NOT supposed to use device classes;
  35248. * they're supposed to use interface classes...
  35249. */
  35250. -{ USB_DEVICE_INFO(7, 1, 1) },
  35251. -{ USB_DEVICE_INFO(7, 1, 2) },
  35252. -{ USB_DEVICE_INFO(7, 1, 3) },
  35253. +//{ USB_DEVICE_INFO(7, 1, 1) },
  35254. +//{ USB_DEVICE_INFO(7, 1, 2) },
  35255. +//{ USB_DEVICE_INFO(7, 1, 3) },
  35256. #endif
  35257. #ifdef CONFIG_USB_NET_CDCETHER
  35258. /* Linux-USB CDC Ethernet gadget */
  35259. -{ USB_DEVICE(0x0525, 0xa4a1), },
  35260. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  35261. /* Linux-USB CDC Ethernet + RNDIS gadget */
  35262. -{ USB_DEVICE(0x0525, 0xa4a2), },
  35263. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  35264. #endif
  35265. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  35266. /* gadget zero, for testing */
  35267. -{ USB_DEVICE(0x0525, 0xa4a0), },
  35268. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  35269. #endif
  35270. +
  35271. +/* OPT Tester */
  35272. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  35273. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  35274. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  35275. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  35276. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  35277. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  35278. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  35279. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  35280. +
  35281. +/* Sony cameras */
  35282. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  35283. +
  35284. +/* Memory Devices */
  35285. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  35286. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  35287. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  35288. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  35289. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  35290. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  35291. +
  35292. +/* HP Printers */
  35293. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  35294. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  35295. +
  35296. +/* Speakers */
  35297. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  35298. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  35299. { } /* Terminating entry */
  35300. };
  35301. +static inline void report_errors(struct usb_device *dev)
  35302. +{
  35303. + /* OTG MESSAGE: report errors here, customize to match your product */
  35304. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  35305. + le16_to_cpu(dev->descriptor.idVendor),
  35306. + le16_to_cpu(dev->descriptor.idProduct));
  35307. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  35308. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  35309. + } else {
  35310. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  35311. + }
  35312. +}
  35313. +
  35314. +
  35315. static int is_targeted(struct usb_device *dev)
  35316. {
  35317. struct usb_device_id *id = whitelist_table;
  35318. @@ -55,58 +104,83 @@
  35319. return 1;
  35320. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  35321. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  35322. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  35323. - return 0;
  35324. + if (dev->descriptor.idVendor == 0x1a0a &&
  35325. + dev->descriptor.idProduct == 0xbadd) {
  35326. + return 0;
  35327. + } else if (!enable_whitelist) {
  35328. + return 1;
  35329. + } else {
  35330. - /* NOTE: can't use usb_match_id() since interface caches
  35331. - * aren't set up yet. this is cut/paste from that code.
  35332. - */
  35333. - for (id = whitelist_table; id->match_flags; id++) {
  35334. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  35335. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  35336. - continue;
  35337. -
  35338. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  35339. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  35340. - continue;
  35341. -
  35342. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  35343. - greater than any unsigned number. */
  35344. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  35345. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  35346. - continue;
  35347. -
  35348. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  35349. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  35350. - continue;
  35351. -
  35352. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  35353. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  35354. - continue;
  35355. -
  35356. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  35357. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  35358. - continue;
  35359. -
  35360. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  35361. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  35362. - continue;
  35363. +#ifdef DEBUG
  35364. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  35365. + dev->descriptor.idVendor,
  35366. + dev->descriptor.idProduct,
  35367. + dev->descriptor.bDeviceClass,
  35368. + dev->descriptor.bDeviceSubClass,
  35369. + dev->descriptor.bDeviceProtocol);
  35370. +#endif
  35371. return 1;
  35372. + /* NOTE: can't use usb_match_id() since interface caches
  35373. + * aren't set up yet. this is cut/paste from that code.
  35374. + */
  35375. + for (id = whitelist_table; id->match_flags; id++) {
  35376. +#ifdef DEBUG
  35377. + dev_dbg(&dev->dev,
  35378. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  35379. + id->idVendor,
  35380. + id->idProduct,
  35381. + id->bDeviceClass,
  35382. + id->bDeviceSubClass,
  35383. + id->bDeviceProtocol);
  35384. +#endif
  35385. +
  35386. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  35387. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  35388. + continue;
  35389. +
  35390. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  35391. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  35392. + continue;
  35393. +
  35394. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  35395. + greater than any unsigned number. */
  35396. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  35397. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  35398. + continue;
  35399. +
  35400. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  35401. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  35402. + continue;
  35403. +
  35404. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  35405. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  35406. + continue;
  35407. +
  35408. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  35409. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  35410. + continue;
  35411. +
  35412. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  35413. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  35414. + continue;
  35415. +
  35416. + return 1;
  35417. + }
  35418. }
  35419. /* add other match criteria here ... */
  35420. -
  35421. - /* OTG MESSAGE: report errors here, customize to match your product */
  35422. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  35423. - le16_to_cpu(dev->descriptor.idVendor),
  35424. - le16_to_cpu(dev->descriptor.idProduct));
  35425. #ifdef CONFIG_USB_OTG_WHITELIST
  35426. + report_errors(dev);
  35427. return 0;
  35428. #else
  35429. - return 1;
  35430. + if (enable_whitelist) {
  35431. + report_errors(dev);
  35432. + return 0;
  35433. + } else {
  35434. + return 1;
  35435. + }
  35436. #endif
  35437. }
  35438. diff -Nur linux-3.10.33/drivers/usb/gadget/file_storage.c linux-raspberry-pi/drivers/usb/gadget/file_storage.c
  35439. --- linux-3.10.33/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  35440. +++ linux-raspberry-pi/drivers/usb/gadget/file_storage.c 2014-03-13 12:46:38.928096810 +0100
  35441. @@ -0,0 +1,3676 @@
  35442. +/*
  35443. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  35444. + *
  35445. + * Copyright (C) 2003-2008 Alan Stern
  35446. + * All rights reserved.
  35447. + *
  35448. + * Redistribution and use in source and binary forms, with or without
  35449. + * modification, are permitted provided that the following conditions
  35450. + * are met:
  35451. + * 1. Redistributions of source code must retain the above copyright
  35452. + * notice, this list of conditions, and the following disclaimer,
  35453. + * without modification.
  35454. + * 2. Redistributions in binary form must reproduce the above copyright
  35455. + * notice, this list of conditions and the following disclaimer in the
  35456. + * documentation and/or other materials provided with the distribution.
  35457. + * 3. The names of the above-listed copyright holders may not be used
  35458. + * to endorse or promote products derived from this software without
  35459. + * specific prior written permission.
  35460. + *
  35461. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35462. + * GNU General Public License ("GPL") as published by the Free Software
  35463. + * Foundation, either version 2 of that License or (at your option) any
  35464. + * later version.
  35465. + *
  35466. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35467. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35468. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35469. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35470. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35471. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35472. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35473. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35474. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35475. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35476. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35477. + */
  35478. +
  35479. +
  35480. +/*
  35481. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  35482. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  35483. + * to providing an example of a genuinely useful gadget driver for a USB
  35484. + * device, it also illustrates a technique of double-buffering for increased
  35485. + * throughput. Last but not least, it gives an easy way to probe the
  35486. + * behavior of the Mass Storage drivers in a USB host.
  35487. + *
  35488. + * Backing storage is provided by a regular file or a block device, specified
  35489. + * by the "file" module parameter. Access can be limited to read-only by
  35490. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  35491. + * access is always read-only.) The gadget will indicate that it has
  35492. + * removable media if the optional "removable" module parameter is set.
  35493. + *
  35494. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  35495. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  35496. + * by the optional "transport" module parameter. It also supports the
  35497. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  35498. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  35499. + * the optional "protocol" module parameter. In addition, the default
  35500. + * Vendor ID, Product ID, release number and serial number can be overridden.
  35501. + *
  35502. + * There is support for multiple logical units (LUNs), each of which has
  35503. + * its own backing file. The number of LUNs can be set using the optional
  35504. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  35505. + * files are specified using comma-separated lists for "file" and "ro".
  35506. + * The default number of LUNs is taken from the number of "file" elements;
  35507. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  35508. + * file must be specified for each LUN. If it is set, then an unspecified
  35509. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  35510. + * each LUN would be settable independently as a disk drive or a CD-ROM
  35511. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  35512. + * emulation includes a single data track and no audio tracks; hence there
  35513. + * need be only one backing file per LUN.
  35514. + *
  35515. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  35516. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  35517. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  35518. + * Support is included for both full-speed and high-speed operation.
  35519. + *
  35520. + * Note that the driver is slightly non-portable in that it assumes a
  35521. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  35522. + * interrupt-in endpoints. With most device controllers this isn't an
  35523. + * issue, but there may be some with hardware restrictions that prevent
  35524. + * a buffer from being used by more than one endpoint.
  35525. + *
  35526. + * Module options:
  35527. + *
  35528. + * file=filename[,filename...]
  35529. + * Required if "removable" is not set, names of
  35530. + * the files or block devices used for
  35531. + * backing storage
  35532. + * serial=HHHH... Required serial number (string of hex chars)
  35533. + * ro=b[,b...] Default false, booleans for read-only access
  35534. + * removable Default false, boolean for removable media
  35535. + * luns=N Default N = number of filenames, number of
  35536. + * LUNs to support
  35537. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  35538. + * in SCSI WRITE(10,12) commands
  35539. + * stall Default determined according to the type of
  35540. + * USB device controller (usually true),
  35541. + * boolean to permit the driver to halt
  35542. + * bulk endpoints
  35543. + * cdrom Default false, boolean for whether to emulate
  35544. + * a CD-ROM drive
  35545. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  35546. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  35547. + * ATAPI, QIC, UFI, 8070, or SCSI;
  35548. + * also 1 - 6)
  35549. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  35550. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  35551. + * release=0xRRRR Override the USB release number (bcdDevice)
  35552. + * buflen=N Default N=16384, buffer size used (will be
  35553. + * rounded down to a multiple of
  35554. + * PAGE_CACHE_SIZE)
  35555. + *
  35556. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  35557. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  35558. + * default values are used for everything else.
  35559. + *
  35560. + * The pathnames of the backing files and the ro settings are available in
  35561. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  35562. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  35563. + * these files will simulate ejecting/loading the medium (writing an empty
  35564. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  35565. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  35566. + * is being used.
  35567. + *
  35568. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  35569. + * The driver's SCSI command interface was based on the "Information
  35570. + * technology - Small Computer System Interface - 2" document from
  35571. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  35572. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  35573. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  35574. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  35575. + * document, Revision 1.0, December 14, 1998, available at
  35576. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  35577. + */
  35578. +
  35579. +
  35580. +/*
  35581. + * Driver Design
  35582. + *
  35583. + * The FSG driver is fairly straightforward. There is a main kernel
  35584. + * thread that handles most of the work. Interrupt routines field
  35585. + * callbacks from the controller driver: bulk- and interrupt-request
  35586. + * completion notifications, endpoint-0 events, and disconnect events.
  35587. + * Completion events are passed to the main thread by wakeup calls. Many
  35588. + * ep0 requests are handled at interrupt time, but SetInterface,
  35589. + * SetConfiguration, and device reset requests are forwarded to the
  35590. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  35591. + * should interrupt any ongoing file I/O operations).
  35592. + *
  35593. + * The thread's main routine implements the standard command/data/status
  35594. + * parts of a SCSI interaction. It and its subroutines are full of tests
  35595. + * for pending signals/exceptions -- all this polling is necessary since
  35596. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  35597. + * indication that the driver really wants to be running in userspace.)
  35598. + * An important point is that so long as the thread is alive it keeps an
  35599. + * open reference to the backing file. This will prevent unmounting
  35600. + * the backing file's underlying filesystem and could cause problems
  35601. + * during system shutdown, for example. To prevent such problems, the
  35602. + * thread catches INT, TERM, and KILL signals and converts them into
  35603. + * an EXIT exception.
  35604. + *
  35605. + * In normal operation the main thread is started during the gadget's
  35606. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  35607. + * exit when it receives a signal, and there's no point leaving the
  35608. + * gadget running when the thread is dead. So just before the thread
  35609. + * exits, it deregisters the gadget driver. This makes things a little
  35610. + * tricky: The driver is deregistered at two places, and the exiting
  35611. + * thread can indirectly call fsg_unbind() which in turn can tell the
  35612. + * thread to exit. The first problem is resolved through the use of the
  35613. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  35614. + * The second problem is resolved by having fsg_unbind() check
  35615. + * fsg->state; it won't try to stop the thread if the state is already
  35616. + * FSG_STATE_TERMINATED.
  35617. + *
  35618. + * To provide maximum throughput, the driver uses a circular pipeline of
  35619. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  35620. + * arbitrarily long; in practice the benefits don't justify having more
  35621. + * than 2 stages (i.e., double buffering). But it helps to think of the
  35622. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  35623. + * a bulk-out request pointer (since the buffer can be used for both
  35624. + * output and input -- directions always are given from the host's
  35625. + * point of view) as well as a pointer to the buffer and various state
  35626. + * variables.
  35627. + *
  35628. + * Use of the pipeline follows a simple protocol. There is a variable
  35629. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  35630. + * At any time that buffer head may still be in use from an earlier
  35631. + * request, so each buffer head has a state variable indicating whether
  35632. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  35633. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  35634. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  35635. + * head FULL when the I/O is complete. Then the buffer will be emptied
  35636. + * (again possibly by USB I/O, during which it is marked BUSY) and
  35637. + * finally marked EMPTY again (possibly by a completion routine).
  35638. + *
  35639. + * A module parameter tells the driver to avoid stalling the bulk
  35640. + * endpoints wherever the transport specification allows. This is
  35641. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  35642. + * halt on a bulk endpoint. However, under certain circumstances the
  35643. + * Bulk-only specification requires a stall. In such cases the driver
  35644. + * will halt the endpoint and set a flag indicating that it should clear
  35645. + * the halt in software during the next device reset. Hopefully this
  35646. + * will permit everything to work correctly. Furthermore, although the
  35647. + * specification allows the bulk-out endpoint to halt when the host sends
  35648. + * too much data, implementing this would cause an unavoidable race.
  35649. + * The driver will always use the "no-stall" approach for OUT transfers.
  35650. + *
  35651. + * One subtle point concerns sending status-stage responses for ep0
  35652. + * requests. Some of these requests, such as device reset, can involve
  35653. + * interrupting an ongoing file I/O operation, which might take an
  35654. + * arbitrarily long time. During that delay the host might give up on
  35655. + * the original ep0 request and issue a new one. When that happens the
  35656. + * driver should not notify the host about completion of the original
  35657. + * request, as the host will no longer be waiting for it. So the driver
  35658. + * assigns to each ep0 request a unique tag, and it keeps track of the
  35659. + * tag value of the request associated with a long-running exception
  35660. + * (device-reset, interface-change, or configuration-change). When the
  35661. + * exception handler is finished, the status-stage response is submitted
  35662. + * only if the current ep0 request tag is equal to the exception request
  35663. + * tag. Thus only the most recently received ep0 request will get a
  35664. + * status-stage response.
  35665. + *
  35666. + * Warning: This driver source file is too long. It ought to be split up
  35667. + * into a header file plus about 3 separate .c files, to handle the details
  35668. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  35669. + */
  35670. +
  35671. +
  35672. +/* #define VERBOSE_DEBUG */
  35673. +/* #define DUMP_MSGS */
  35674. +
  35675. +
  35676. +#include <linux/blkdev.h>
  35677. +#include <linux/completion.h>
  35678. +#include <linux/dcache.h>
  35679. +#include <linux/delay.h>
  35680. +#include <linux/device.h>
  35681. +#include <linux/fcntl.h>
  35682. +#include <linux/file.h>
  35683. +#include <linux/fs.h>
  35684. +#include <linux/kref.h>
  35685. +#include <linux/kthread.h>
  35686. +#include <linux/limits.h>
  35687. +#include <linux/module.h>
  35688. +#include <linux/rwsem.h>
  35689. +#include <linux/slab.h>
  35690. +#include <linux/spinlock.h>
  35691. +#include <linux/string.h>
  35692. +#include <linux/freezer.h>
  35693. +#include <linux/utsname.h>
  35694. +
  35695. +#include <linux/usb/ch9.h>
  35696. +#include <linux/usb/gadget.h>
  35697. +
  35698. +#include "gadget_chips.h"
  35699. +
  35700. +
  35701. +
  35702. +/*
  35703. + * Kbuild is not very cooperative with respect to linking separately
  35704. + * compiled library objects into one module. So for now we won't use
  35705. + * separate compilation ... ensuring init/exit sections work to shrink
  35706. + * the runtime footprint, and giving us at least some parts of what
  35707. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  35708. + */
  35709. +#include "usbstring.c"
  35710. +#include "config.c"
  35711. +#include "epautoconf.c"
  35712. +
  35713. +/*-------------------------------------------------------------------------*/
  35714. +
  35715. +#define DRIVER_DESC "File-backed Storage Gadget"
  35716. +#define DRIVER_NAME "g_file_storage"
  35717. +#define DRIVER_VERSION "1 September 2010"
  35718. +
  35719. +static char fsg_string_manufacturer[64];
  35720. +static const char fsg_string_product[] = DRIVER_DESC;
  35721. +static const char fsg_string_config[] = "Self-powered";
  35722. +static const char fsg_string_interface[] = "Mass Storage";
  35723. +
  35724. +
  35725. +#include "storage_common.c"
  35726. +
  35727. +
  35728. +MODULE_DESCRIPTION(DRIVER_DESC);
  35729. +MODULE_AUTHOR("Alan Stern");
  35730. +MODULE_LICENSE("Dual BSD/GPL");
  35731. +
  35732. +/*
  35733. + * This driver assumes self-powered hardware and has no way for users to
  35734. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  35735. + * and endpoint addresses.
  35736. + */
  35737. +
  35738. +
  35739. +/*-------------------------------------------------------------------------*/
  35740. +
  35741. +
  35742. +/* Encapsulate the module parameter settings */
  35743. +
  35744. +static struct {
  35745. + char *file[FSG_MAX_LUNS];
  35746. + char *serial;
  35747. + bool ro[FSG_MAX_LUNS];
  35748. + bool nofua[FSG_MAX_LUNS];
  35749. + unsigned int num_filenames;
  35750. + unsigned int num_ros;
  35751. + unsigned int num_nofuas;
  35752. + unsigned int nluns;
  35753. +
  35754. + bool removable;
  35755. + bool can_stall;
  35756. + bool cdrom;
  35757. +
  35758. + char *transport_parm;
  35759. + char *protocol_parm;
  35760. + unsigned short vendor;
  35761. + unsigned short product;
  35762. + unsigned short release;
  35763. + unsigned int buflen;
  35764. +
  35765. + int transport_type;
  35766. + char *transport_name;
  35767. + int protocol_type;
  35768. + char *protocol_name;
  35769. +
  35770. +} mod_data = { // Default values
  35771. + .transport_parm = "BBB",
  35772. + .protocol_parm = "SCSI",
  35773. + .removable = 0,
  35774. + .can_stall = 1,
  35775. + .cdrom = 0,
  35776. + .vendor = FSG_VENDOR_ID,
  35777. + .product = FSG_PRODUCT_ID,
  35778. + .release = 0xffff, // Use controller chip type
  35779. + .buflen = 16384,
  35780. + };
  35781. +
  35782. +
  35783. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  35784. + S_IRUGO);
  35785. +MODULE_PARM_DESC(file, "names of backing files or devices");
  35786. +
  35787. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  35788. +MODULE_PARM_DESC(serial, "USB serial number");
  35789. +
  35790. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  35791. +MODULE_PARM_DESC(ro, "true to force read-only");
  35792. +
  35793. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  35794. + S_IRUGO);
  35795. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  35796. +
  35797. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  35798. +MODULE_PARM_DESC(luns, "number of LUNs");
  35799. +
  35800. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  35801. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  35802. +
  35803. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  35804. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  35805. +
  35806. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  35807. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  35808. +
  35809. +/* In the non-TEST version, only the module parameters listed above
  35810. + * are available. */
  35811. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35812. +
  35813. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  35814. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  35815. +
  35816. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  35817. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  35818. + "8070, or SCSI)");
  35819. +
  35820. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  35821. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  35822. +
  35823. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  35824. +MODULE_PARM_DESC(product, "USB Product ID");
  35825. +
  35826. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  35827. +MODULE_PARM_DESC(release, "USB release number");
  35828. +
  35829. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  35830. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  35831. +
  35832. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35833. +
  35834. +
  35835. +/*
  35836. + * These definitions will permit the compiler to avoid generating code for
  35837. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  35838. + * can recognize when a test of a constant expression yields a dead code
  35839. + * path.
  35840. + */
  35841. +
  35842. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35843. +
  35844. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  35845. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  35846. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  35847. +
  35848. +#else
  35849. +
  35850. +#define transport_is_bbb() 1
  35851. +#define transport_is_cbi() 0
  35852. +#define protocol_is_scsi() 1
  35853. +
  35854. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35855. +
  35856. +
  35857. +/*-------------------------------------------------------------------------*/
  35858. +
  35859. +
  35860. +struct fsg_dev {
  35861. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  35862. + spinlock_t lock;
  35863. + struct usb_gadget *gadget;
  35864. +
  35865. + /* filesem protects: backing files in use */
  35866. + struct rw_semaphore filesem;
  35867. +
  35868. + /* reference counting: wait until all LUNs are released */
  35869. + struct kref ref;
  35870. +
  35871. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  35872. + struct usb_request *ep0req; // For control responses
  35873. + unsigned int ep0_req_tag;
  35874. + const char *ep0req_name;
  35875. +
  35876. + struct usb_request *intreq; // For interrupt responses
  35877. + int intreq_busy;
  35878. + struct fsg_buffhd *intr_buffhd;
  35879. +
  35880. + unsigned int bulk_out_maxpacket;
  35881. + enum fsg_state state; // For exception handling
  35882. + unsigned int exception_req_tag;
  35883. +
  35884. + u8 config, new_config;
  35885. +
  35886. + unsigned int running : 1;
  35887. + unsigned int bulk_in_enabled : 1;
  35888. + unsigned int bulk_out_enabled : 1;
  35889. + unsigned int intr_in_enabled : 1;
  35890. + unsigned int phase_error : 1;
  35891. + unsigned int short_packet_received : 1;
  35892. + unsigned int bad_lun_okay : 1;
  35893. +
  35894. + unsigned long atomic_bitflags;
  35895. +#define REGISTERED 0
  35896. +#define IGNORE_BULK_OUT 1
  35897. +#define SUSPENDED 2
  35898. +
  35899. + struct usb_ep *bulk_in;
  35900. + struct usb_ep *bulk_out;
  35901. + struct usb_ep *intr_in;
  35902. +
  35903. + struct fsg_buffhd *next_buffhd_to_fill;
  35904. + struct fsg_buffhd *next_buffhd_to_drain;
  35905. +
  35906. + int thread_wakeup_needed;
  35907. + struct completion thread_notifier;
  35908. + struct task_struct *thread_task;
  35909. +
  35910. + int cmnd_size;
  35911. + u8 cmnd[MAX_COMMAND_SIZE];
  35912. + enum data_direction data_dir;
  35913. + u32 data_size;
  35914. + u32 data_size_from_cmnd;
  35915. + u32 tag;
  35916. + unsigned int lun;
  35917. + u32 residue;
  35918. + u32 usb_amount_left;
  35919. +
  35920. + /* The CB protocol offers no way for a host to know when a command
  35921. + * has completed. As a result the next command may arrive early,
  35922. + * and we will still have to handle it. For that reason we need
  35923. + * a buffer to store new commands when using CB (or CBI, which
  35924. + * does not oblige a host to wait for command completion either). */
  35925. + int cbbuf_cmnd_size;
  35926. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  35927. +
  35928. + unsigned int nluns;
  35929. + struct fsg_lun *luns;
  35930. + struct fsg_lun *curlun;
  35931. + /* Must be the last entry */
  35932. + struct fsg_buffhd buffhds[];
  35933. +};
  35934. +
  35935. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  35936. +
  35937. +static int exception_in_progress(struct fsg_dev *fsg)
  35938. +{
  35939. + return (fsg->state > FSG_STATE_IDLE);
  35940. +}
  35941. +
  35942. +/* Make bulk-out requests be divisible by the maxpacket size */
  35943. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  35944. + struct fsg_buffhd *bh, unsigned int length)
  35945. +{
  35946. + unsigned int rem;
  35947. +
  35948. + bh->bulk_out_intended_length = length;
  35949. + rem = length % fsg->bulk_out_maxpacket;
  35950. + if (rem > 0)
  35951. + length += fsg->bulk_out_maxpacket - rem;
  35952. + bh->outreq->length = length;
  35953. +}
  35954. +
  35955. +static struct fsg_dev *the_fsg;
  35956. +static struct usb_gadget_driver fsg_driver;
  35957. +
  35958. +
  35959. +/*-------------------------------------------------------------------------*/
  35960. +
  35961. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  35962. +{
  35963. + const char *name;
  35964. +
  35965. + if (ep == fsg->bulk_in)
  35966. + name = "bulk-in";
  35967. + else if (ep == fsg->bulk_out)
  35968. + name = "bulk-out";
  35969. + else
  35970. + name = ep->name;
  35971. + DBG(fsg, "%s set halt\n", name);
  35972. + return usb_ep_set_halt(ep);
  35973. +}
  35974. +
  35975. +
  35976. +/*-------------------------------------------------------------------------*/
  35977. +
  35978. +/*
  35979. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  35980. + * descriptors are built on demand. Also the (static) config and interface
  35981. + * descriptors are adjusted during fsg_bind().
  35982. + */
  35983. +
  35984. +/* There is only one configuration. */
  35985. +#define CONFIG_VALUE 1
  35986. +
  35987. +static struct usb_device_descriptor
  35988. +device_desc = {
  35989. + .bLength = sizeof device_desc,
  35990. + .bDescriptorType = USB_DT_DEVICE,
  35991. +
  35992. + .bcdUSB = cpu_to_le16(0x0200),
  35993. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35994. +
  35995. + /* The next three values can be overridden by module parameters */
  35996. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  35997. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  35998. + .bcdDevice = cpu_to_le16(0xffff),
  35999. +
  36000. + .iManufacturer = FSG_STRING_MANUFACTURER,
  36001. + .iProduct = FSG_STRING_PRODUCT,
  36002. + .iSerialNumber = FSG_STRING_SERIAL,
  36003. + .bNumConfigurations = 1,
  36004. +};
  36005. +
  36006. +static struct usb_config_descriptor
  36007. +config_desc = {
  36008. + .bLength = sizeof config_desc,
  36009. + .bDescriptorType = USB_DT_CONFIG,
  36010. +
  36011. + /* wTotalLength computed by usb_gadget_config_buf() */
  36012. + .bNumInterfaces = 1,
  36013. + .bConfigurationValue = CONFIG_VALUE,
  36014. + .iConfiguration = FSG_STRING_CONFIG,
  36015. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  36016. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  36017. +};
  36018. +
  36019. +
  36020. +static struct usb_qualifier_descriptor
  36021. +dev_qualifier = {
  36022. + .bLength = sizeof dev_qualifier,
  36023. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  36024. +
  36025. + .bcdUSB = cpu_to_le16(0x0200),
  36026. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36027. +
  36028. + .bNumConfigurations = 1,
  36029. +};
  36030. +
  36031. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  36032. +{
  36033. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  36034. + buf += USB_DT_BOS_SIZE;
  36035. +
  36036. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  36037. + buf += USB_DT_USB_EXT_CAP_SIZE;
  36038. +
  36039. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  36040. +
  36041. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  36042. + + USB_DT_USB_EXT_CAP_SIZE;
  36043. +}
  36044. +
  36045. +/*
  36046. + * Config descriptors must agree with the code that sets configurations
  36047. + * and with code managing interfaces and their altsettings. They must
  36048. + * also handle different speeds and other-speed requests.
  36049. + */
  36050. +static int populate_config_buf(struct usb_gadget *gadget,
  36051. + u8 *buf, u8 type, unsigned index)
  36052. +{
  36053. + enum usb_device_speed speed = gadget->speed;
  36054. + int len;
  36055. + const struct usb_descriptor_header **function;
  36056. +
  36057. + if (index > 0)
  36058. + return -EINVAL;
  36059. +
  36060. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  36061. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  36062. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  36063. + ? (const struct usb_descriptor_header **)fsg_hs_function
  36064. + : (const struct usb_descriptor_header **)fsg_fs_function;
  36065. +
  36066. + /* for now, don't advertise srp-only devices */
  36067. + if (!gadget_is_otg(gadget))
  36068. + function++;
  36069. +
  36070. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  36071. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  36072. + return len;
  36073. +}
  36074. +
  36075. +
  36076. +/*-------------------------------------------------------------------------*/
  36077. +
  36078. +/* These routines may be called in process context or in_irq */
  36079. +
  36080. +/* Caller must hold fsg->lock */
  36081. +static void wakeup_thread(struct fsg_dev *fsg)
  36082. +{
  36083. + /* Tell the main thread that something has happened */
  36084. + fsg->thread_wakeup_needed = 1;
  36085. + if (fsg->thread_task)
  36086. + wake_up_process(fsg->thread_task);
  36087. +}
  36088. +
  36089. +
  36090. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  36091. +{
  36092. + unsigned long flags;
  36093. +
  36094. + /* Do nothing if a higher-priority exception is already in progress.
  36095. + * If a lower-or-equal priority exception is in progress, preempt it
  36096. + * and notify the main thread by sending it a signal. */
  36097. + spin_lock_irqsave(&fsg->lock, flags);
  36098. + if (fsg->state <= new_state) {
  36099. + fsg->exception_req_tag = fsg->ep0_req_tag;
  36100. + fsg->state = new_state;
  36101. + if (fsg->thread_task)
  36102. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  36103. + fsg->thread_task);
  36104. + }
  36105. + spin_unlock_irqrestore(&fsg->lock, flags);
  36106. +}
  36107. +
  36108. +
  36109. +/*-------------------------------------------------------------------------*/
  36110. +
  36111. +/* The disconnect callback and ep0 routines. These always run in_irq,
  36112. + * except that ep0_queue() is called in the main thread to acknowledge
  36113. + * completion of various requests: set config, set interface, and
  36114. + * Bulk-only device reset. */
  36115. +
  36116. +static void fsg_disconnect(struct usb_gadget *gadget)
  36117. +{
  36118. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36119. +
  36120. + DBG(fsg, "disconnect or port reset\n");
  36121. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  36122. +}
  36123. +
  36124. +
  36125. +static int ep0_queue(struct fsg_dev *fsg)
  36126. +{
  36127. + int rc;
  36128. +
  36129. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  36130. + if (rc != 0 && rc != -ESHUTDOWN) {
  36131. +
  36132. + /* We can't do much more than wait for a reset */
  36133. + WARNING(fsg, "error in submission: %s --> %d\n",
  36134. + fsg->ep0->name, rc);
  36135. + }
  36136. + return rc;
  36137. +}
  36138. +
  36139. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  36140. +{
  36141. + struct fsg_dev *fsg = ep->driver_data;
  36142. +
  36143. + if (req->actual > 0)
  36144. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  36145. + if (req->status || req->actual != req->length)
  36146. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36147. + req->status, req->actual, req->length);
  36148. + if (req->status == -ECONNRESET) // Request was cancelled
  36149. + usb_ep_fifo_flush(ep);
  36150. +
  36151. + if (req->status == 0 && req->context)
  36152. + ((fsg_routine_t) (req->context))(fsg);
  36153. +}
  36154. +
  36155. +
  36156. +/*-------------------------------------------------------------------------*/
  36157. +
  36158. +/* Bulk and interrupt endpoint completion handlers.
  36159. + * These always run in_irq. */
  36160. +
  36161. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  36162. +{
  36163. + struct fsg_dev *fsg = ep->driver_data;
  36164. + struct fsg_buffhd *bh = req->context;
  36165. +
  36166. + if (req->status || req->actual != req->length)
  36167. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36168. + req->status, req->actual, req->length);
  36169. + if (req->status == -ECONNRESET) // Request was cancelled
  36170. + usb_ep_fifo_flush(ep);
  36171. +
  36172. + /* Hold the lock while we update the request and buffer states */
  36173. + smp_wmb();
  36174. + spin_lock(&fsg->lock);
  36175. + bh->inreq_busy = 0;
  36176. + bh->state = BUF_STATE_EMPTY;
  36177. + wakeup_thread(fsg);
  36178. + spin_unlock(&fsg->lock);
  36179. +}
  36180. +
  36181. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  36182. +{
  36183. + struct fsg_dev *fsg = ep->driver_data;
  36184. + struct fsg_buffhd *bh = req->context;
  36185. +
  36186. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  36187. + if (req->status || req->actual != bh->bulk_out_intended_length)
  36188. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36189. + req->status, req->actual,
  36190. + bh->bulk_out_intended_length);
  36191. + if (req->status == -ECONNRESET) // Request was cancelled
  36192. + usb_ep_fifo_flush(ep);
  36193. +
  36194. + /* Hold the lock while we update the request and buffer states */
  36195. + smp_wmb();
  36196. + spin_lock(&fsg->lock);
  36197. + bh->outreq_busy = 0;
  36198. + bh->state = BUF_STATE_FULL;
  36199. + wakeup_thread(fsg);
  36200. + spin_unlock(&fsg->lock);
  36201. +}
  36202. +
  36203. +
  36204. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36205. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  36206. +{
  36207. + struct fsg_dev *fsg = ep->driver_data;
  36208. + struct fsg_buffhd *bh = req->context;
  36209. +
  36210. + if (req->status || req->actual != req->length)
  36211. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36212. + req->status, req->actual, req->length);
  36213. + if (req->status == -ECONNRESET) // Request was cancelled
  36214. + usb_ep_fifo_flush(ep);
  36215. +
  36216. + /* Hold the lock while we update the request and buffer states */
  36217. + smp_wmb();
  36218. + spin_lock(&fsg->lock);
  36219. + fsg->intreq_busy = 0;
  36220. + bh->state = BUF_STATE_EMPTY;
  36221. + wakeup_thread(fsg);
  36222. + spin_unlock(&fsg->lock);
  36223. +}
  36224. +
  36225. +#else
  36226. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  36227. +{}
  36228. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36229. +
  36230. +
  36231. +/*-------------------------------------------------------------------------*/
  36232. +
  36233. +/* Ep0 class-specific handlers. These always run in_irq. */
  36234. +
  36235. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36236. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36237. +{
  36238. + struct usb_request *req = fsg->ep0req;
  36239. + static u8 cbi_reset_cmnd[6] = {
  36240. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  36241. +
  36242. + /* Error in command transfer? */
  36243. + if (req->status || req->length != req->actual ||
  36244. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  36245. +
  36246. + /* Not all controllers allow a protocol stall after
  36247. + * receiving control-out data, but we'll try anyway. */
  36248. + fsg_set_halt(fsg, fsg->ep0);
  36249. + return; // Wait for reset
  36250. + }
  36251. +
  36252. + /* Is it the special reset command? */
  36253. + if (req->actual >= sizeof cbi_reset_cmnd &&
  36254. + memcmp(req->buf, cbi_reset_cmnd,
  36255. + sizeof cbi_reset_cmnd) == 0) {
  36256. +
  36257. + /* Raise an exception to stop the current operation
  36258. + * and reinitialize our state. */
  36259. + DBG(fsg, "cbi reset request\n");
  36260. + raise_exception(fsg, FSG_STATE_RESET);
  36261. + return;
  36262. + }
  36263. +
  36264. + VDBG(fsg, "CB[I] accept device-specific command\n");
  36265. + spin_lock(&fsg->lock);
  36266. +
  36267. + /* Save the command for later */
  36268. + if (fsg->cbbuf_cmnd_size)
  36269. + WARNING(fsg, "CB[I] overwriting previous command\n");
  36270. + fsg->cbbuf_cmnd_size = req->actual;
  36271. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  36272. +
  36273. + wakeup_thread(fsg);
  36274. + spin_unlock(&fsg->lock);
  36275. +}
  36276. +
  36277. +#else
  36278. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36279. +{}
  36280. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36281. +
  36282. +
  36283. +static int class_setup_req(struct fsg_dev *fsg,
  36284. + const struct usb_ctrlrequest *ctrl)
  36285. +{
  36286. + struct usb_request *req = fsg->ep0req;
  36287. + int value = -EOPNOTSUPP;
  36288. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  36289. + u16 w_value = le16_to_cpu(ctrl->wValue);
  36290. + u16 w_length = le16_to_cpu(ctrl->wLength);
  36291. +
  36292. + if (!fsg->config)
  36293. + return value;
  36294. +
  36295. + /* Handle Bulk-only class-specific requests */
  36296. + if (transport_is_bbb()) {
  36297. + switch (ctrl->bRequest) {
  36298. +
  36299. + case US_BULK_RESET_REQUEST:
  36300. + if (ctrl->bRequestType != (USB_DIR_OUT |
  36301. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36302. + break;
  36303. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  36304. + value = -EDOM;
  36305. + break;
  36306. + }
  36307. +
  36308. + /* Raise an exception to stop the current operation
  36309. + * and reinitialize our state. */
  36310. + DBG(fsg, "bulk reset request\n");
  36311. + raise_exception(fsg, FSG_STATE_RESET);
  36312. + value = DELAYED_STATUS;
  36313. + break;
  36314. +
  36315. + case US_BULK_GET_MAX_LUN:
  36316. + if (ctrl->bRequestType != (USB_DIR_IN |
  36317. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36318. + break;
  36319. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  36320. + value = -EDOM;
  36321. + break;
  36322. + }
  36323. + VDBG(fsg, "get max LUN\n");
  36324. + *(u8 *) req->buf = fsg->nluns - 1;
  36325. + value = 1;
  36326. + break;
  36327. + }
  36328. + }
  36329. +
  36330. + /* Handle CBI class-specific requests */
  36331. + else {
  36332. + switch (ctrl->bRequest) {
  36333. +
  36334. + case USB_CBI_ADSC_REQUEST:
  36335. + if (ctrl->bRequestType != (USB_DIR_OUT |
  36336. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36337. + break;
  36338. + if (w_index != 0 || w_value != 0) {
  36339. + value = -EDOM;
  36340. + break;
  36341. + }
  36342. + if (w_length > MAX_COMMAND_SIZE) {
  36343. + value = -EOVERFLOW;
  36344. + break;
  36345. + }
  36346. + value = w_length;
  36347. + fsg->ep0req->context = received_cbi_adsc;
  36348. + break;
  36349. + }
  36350. + }
  36351. +
  36352. + if (value == -EOPNOTSUPP)
  36353. + VDBG(fsg,
  36354. + "unknown class-specific control req "
  36355. + "%02x.%02x v%04x i%04x l%u\n",
  36356. + ctrl->bRequestType, ctrl->bRequest,
  36357. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  36358. + return value;
  36359. +}
  36360. +
  36361. +
  36362. +/*-------------------------------------------------------------------------*/
  36363. +
  36364. +/* Ep0 standard request handlers. These always run in_irq. */
  36365. +
  36366. +static int standard_setup_req(struct fsg_dev *fsg,
  36367. + const struct usb_ctrlrequest *ctrl)
  36368. +{
  36369. + struct usb_request *req = fsg->ep0req;
  36370. + int value = -EOPNOTSUPP;
  36371. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  36372. + u16 w_value = le16_to_cpu(ctrl->wValue);
  36373. +
  36374. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  36375. + * but config change events will also reconfigure hardware. */
  36376. + switch (ctrl->bRequest) {
  36377. +
  36378. + case USB_REQ_GET_DESCRIPTOR:
  36379. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36380. + USB_RECIP_DEVICE))
  36381. + break;
  36382. + switch (w_value >> 8) {
  36383. +
  36384. + case USB_DT_DEVICE:
  36385. + VDBG(fsg, "get device descriptor\n");
  36386. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  36387. + value = sizeof device_desc;
  36388. + memcpy(req->buf, &device_desc, value);
  36389. + break;
  36390. + case USB_DT_DEVICE_QUALIFIER:
  36391. + VDBG(fsg, "get device qualifier\n");
  36392. + if (!gadget_is_dualspeed(fsg->gadget) ||
  36393. + fsg->gadget->speed == USB_SPEED_SUPER)
  36394. + break;
  36395. + /*
  36396. + * Assume ep0 uses the same maxpacket value for both
  36397. + * speeds
  36398. + */
  36399. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  36400. + value = sizeof dev_qualifier;
  36401. + memcpy(req->buf, &dev_qualifier, value);
  36402. + break;
  36403. +
  36404. + case USB_DT_OTHER_SPEED_CONFIG:
  36405. + VDBG(fsg, "get other-speed config descriptor\n");
  36406. + if (!gadget_is_dualspeed(fsg->gadget) ||
  36407. + fsg->gadget->speed == USB_SPEED_SUPER)
  36408. + break;
  36409. + goto get_config;
  36410. + case USB_DT_CONFIG:
  36411. + VDBG(fsg, "get configuration descriptor\n");
  36412. +get_config:
  36413. + value = populate_config_buf(fsg->gadget,
  36414. + req->buf,
  36415. + w_value >> 8,
  36416. + w_value & 0xff);
  36417. + break;
  36418. +
  36419. + case USB_DT_STRING:
  36420. + VDBG(fsg, "get string descriptor\n");
  36421. +
  36422. + /* wIndex == language code */
  36423. + value = usb_gadget_get_string(&fsg_stringtab,
  36424. + w_value & 0xff, req->buf);
  36425. + break;
  36426. +
  36427. + case USB_DT_BOS:
  36428. + VDBG(fsg, "get bos descriptor\n");
  36429. +
  36430. + if (gadget_is_superspeed(fsg->gadget))
  36431. + value = populate_bos(fsg, req->buf);
  36432. + break;
  36433. + }
  36434. +
  36435. + break;
  36436. +
  36437. + /* One config, two speeds */
  36438. + case USB_REQ_SET_CONFIGURATION:
  36439. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  36440. + USB_RECIP_DEVICE))
  36441. + break;
  36442. + VDBG(fsg, "set configuration\n");
  36443. + if (w_value == CONFIG_VALUE || w_value == 0) {
  36444. + fsg->new_config = w_value;
  36445. +
  36446. + /* Raise an exception to wipe out previous transaction
  36447. + * state (queued bufs, etc) and set the new config. */
  36448. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  36449. + value = DELAYED_STATUS;
  36450. + }
  36451. + break;
  36452. + case USB_REQ_GET_CONFIGURATION:
  36453. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36454. + USB_RECIP_DEVICE))
  36455. + break;
  36456. + VDBG(fsg, "get configuration\n");
  36457. + *(u8 *) req->buf = fsg->config;
  36458. + value = 1;
  36459. + break;
  36460. +
  36461. + case USB_REQ_SET_INTERFACE:
  36462. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  36463. + USB_RECIP_INTERFACE))
  36464. + break;
  36465. + if (fsg->config && w_index == 0) {
  36466. +
  36467. + /* Raise an exception to wipe out previous transaction
  36468. + * state (queued bufs, etc) and install the new
  36469. + * interface altsetting. */
  36470. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  36471. + value = DELAYED_STATUS;
  36472. + }
  36473. + break;
  36474. + case USB_REQ_GET_INTERFACE:
  36475. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36476. + USB_RECIP_INTERFACE))
  36477. + break;
  36478. + if (!fsg->config)
  36479. + break;
  36480. + if (w_index != 0) {
  36481. + value = -EDOM;
  36482. + break;
  36483. + }
  36484. + VDBG(fsg, "get interface\n");
  36485. + *(u8 *) req->buf = 0;
  36486. + value = 1;
  36487. + break;
  36488. +
  36489. + default:
  36490. + VDBG(fsg,
  36491. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  36492. + ctrl->bRequestType, ctrl->bRequest,
  36493. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  36494. + }
  36495. +
  36496. + return value;
  36497. +}
  36498. +
  36499. +
  36500. +static int fsg_setup(struct usb_gadget *gadget,
  36501. + const struct usb_ctrlrequest *ctrl)
  36502. +{
  36503. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36504. + int rc;
  36505. + int w_length = le16_to_cpu(ctrl->wLength);
  36506. +
  36507. + ++fsg->ep0_req_tag; // Record arrival of a new request
  36508. + fsg->ep0req->context = NULL;
  36509. + fsg->ep0req->length = 0;
  36510. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  36511. +
  36512. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  36513. + rc = class_setup_req(fsg, ctrl);
  36514. + else
  36515. + rc = standard_setup_req(fsg, ctrl);
  36516. +
  36517. + /* Respond with data/status or defer until later? */
  36518. + if (rc >= 0 && rc != DELAYED_STATUS) {
  36519. + rc = min(rc, w_length);
  36520. + fsg->ep0req->length = rc;
  36521. + fsg->ep0req->zero = rc < w_length;
  36522. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  36523. + "ep0-in" : "ep0-out");
  36524. + rc = ep0_queue(fsg);
  36525. + }
  36526. +
  36527. + /* Device either stalls (rc < 0) or reports success */
  36528. + return rc;
  36529. +}
  36530. +
  36531. +
  36532. +/*-------------------------------------------------------------------------*/
  36533. +
  36534. +/* All the following routines run in process context */
  36535. +
  36536. +
  36537. +/* Use this for bulk or interrupt transfers, not ep0 */
  36538. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  36539. + struct usb_request *req, int *pbusy,
  36540. + enum fsg_buffer_state *state)
  36541. +{
  36542. + int rc;
  36543. +
  36544. + if (ep == fsg->bulk_in)
  36545. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  36546. + else if (ep == fsg->intr_in)
  36547. + dump_msg(fsg, "intr-in", req->buf, req->length);
  36548. +
  36549. + spin_lock_irq(&fsg->lock);
  36550. + *pbusy = 1;
  36551. + *state = BUF_STATE_BUSY;
  36552. + spin_unlock_irq(&fsg->lock);
  36553. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  36554. + if (rc != 0) {
  36555. + *pbusy = 0;
  36556. + *state = BUF_STATE_EMPTY;
  36557. +
  36558. + /* We can't do much more than wait for a reset */
  36559. +
  36560. + /* Note: currently the net2280 driver fails zero-length
  36561. + * submissions if DMA is enabled. */
  36562. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  36563. + req->length == 0))
  36564. + WARNING(fsg, "error in submission: %s --> %d\n",
  36565. + ep->name, rc);
  36566. + }
  36567. +}
  36568. +
  36569. +
  36570. +static int sleep_thread(struct fsg_dev *fsg)
  36571. +{
  36572. + int rc = 0;
  36573. +
  36574. + /* Wait until a signal arrives or we are woken up */
  36575. + for (;;) {
  36576. + try_to_freeze();
  36577. + set_current_state(TASK_INTERRUPTIBLE);
  36578. + if (signal_pending(current)) {
  36579. + rc = -EINTR;
  36580. + break;
  36581. + }
  36582. + if (fsg->thread_wakeup_needed)
  36583. + break;
  36584. + schedule();
  36585. + }
  36586. + __set_current_state(TASK_RUNNING);
  36587. + fsg->thread_wakeup_needed = 0;
  36588. + return rc;
  36589. +}
  36590. +
  36591. +
  36592. +/*-------------------------------------------------------------------------*/
  36593. +
  36594. +static int do_read(struct fsg_dev *fsg)
  36595. +{
  36596. + struct fsg_lun *curlun = fsg->curlun;
  36597. + u32 lba;
  36598. + struct fsg_buffhd *bh;
  36599. + int rc;
  36600. + u32 amount_left;
  36601. + loff_t file_offset, file_offset_tmp;
  36602. + unsigned int amount;
  36603. + ssize_t nread;
  36604. +
  36605. + /* Get the starting Logical Block Address and check that it's
  36606. + * not too big */
  36607. + if (fsg->cmnd[0] == READ_6)
  36608. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36609. + else {
  36610. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36611. +
  36612. + /* We allow DPO (Disable Page Out = don't save data in the
  36613. + * cache) and FUA (Force Unit Access = don't read from the
  36614. + * cache), but we don't implement them. */
  36615. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36616. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36617. + return -EINVAL;
  36618. + }
  36619. + }
  36620. + if (lba >= curlun->num_sectors) {
  36621. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36622. + return -EINVAL;
  36623. + }
  36624. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36625. +
  36626. + /* Carry out the file reads */
  36627. + amount_left = fsg->data_size_from_cmnd;
  36628. + if (unlikely(amount_left == 0))
  36629. + return -EIO; // No default reply
  36630. +
  36631. + for (;;) {
  36632. +
  36633. + /* Figure out how much we need to read:
  36634. + * Try to read the remaining amount.
  36635. + * But don't read more than the buffer size.
  36636. + * And don't try to read past the end of the file.
  36637. + */
  36638. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36639. + amount = min((loff_t) amount,
  36640. + curlun->file_length - file_offset);
  36641. +
  36642. + /* Wait for the next buffer to become available */
  36643. + bh = fsg->next_buffhd_to_fill;
  36644. + while (bh->state != BUF_STATE_EMPTY) {
  36645. + rc = sleep_thread(fsg);
  36646. + if (rc)
  36647. + return rc;
  36648. + }
  36649. +
  36650. + /* If we were asked to read past the end of file,
  36651. + * end with an empty buffer. */
  36652. + if (amount == 0) {
  36653. + curlun->sense_data =
  36654. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36655. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36656. + curlun->info_valid = 1;
  36657. + bh->inreq->length = 0;
  36658. + bh->state = BUF_STATE_FULL;
  36659. + break;
  36660. + }
  36661. +
  36662. + /* Perform the read */
  36663. + file_offset_tmp = file_offset;
  36664. + nread = vfs_read(curlun->filp,
  36665. + (char __user *) bh->buf,
  36666. + amount, &file_offset_tmp);
  36667. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36668. + (unsigned long long) file_offset,
  36669. + (int) nread);
  36670. + if (signal_pending(current))
  36671. + return -EINTR;
  36672. +
  36673. + if (nread < 0) {
  36674. + LDBG(curlun, "error in file read: %d\n",
  36675. + (int) nread);
  36676. + nread = 0;
  36677. + } else if (nread < amount) {
  36678. + LDBG(curlun, "partial file read: %d/%u\n",
  36679. + (int) nread, amount);
  36680. + nread = round_down(nread, curlun->blksize);
  36681. + }
  36682. + file_offset += nread;
  36683. + amount_left -= nread;
  36684. + fsg->residue -= nread;
  36685. +
  36686. + /* Except at the end of the transfer, nread will be
  36687. + * equal to the buffer size, which is divisible by the
  36688. + * bulk-in maxpacket size.
  36689. + */
  36690. + bh->inreq->length = nread;
  36691. + bh->state = BUF_STATE_FULL;
  36692. +
  36693. + /* If an error occurred, report it and its position */
  36694. + if (nread < amount) {
  36695. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36696. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36697. + curlun->info_valid = 1;
  36698. + break;
  36699. + }
  36700. +
  36701. + if (amount_left == 0)
  36702. + break; // No more left to read
  36703. +
  36704. + /* Send this buffer and go read some more */
  36705. + bh->inreq->zero = 0;
  36706. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36707. + &bh->inreq_busy, &bh->state);
  36708. + fsg->next_buffhd_to_fill = bh->next;
  36709. + }
  36710. +
  36711. + return -EIO; // No default reply
  36712. +}
  36713. +
  36714. +
  36715. +/*-------------------------------------------------------------------------*/
  36716. +
  36717. +static int do_write(struct fsg_dev *fsg)
  36718. +{
  36719. + struct fsg_lun *curlun = fsg->curlun;
  36720. + u32 lba;
  36721. + struct fsg_buffhd *bh;
  36722. + int get_some_more;
  36723. + u32 amount_left_to_req, amount_left_to_write;
  36724. + loff_t usb_offset, file_offset, file_offset_tmp;
  36725. + unsigned int amount;
  36726. + ssize_t nwritten;
  36727. + int rc;
  36728. +
  36729. + if (curlun->ro) {
  36730. + curlun->sense_data = SS_WRITE_PROTECTED;
  36731. + return -EINVAL;
  36732. + }
  36733. + spin_lock(&curlun->filp->f_lock);
  36734. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  36735. + spin_unlock(&curlun->filp->f_lock);
  36736. +
  36737. + /* Get the starting Logical Block Address and check that it's
  36738. + * not too big */
  36739. + if (fsg->cmnd[0] == WRITE_6)
  36740. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36741. + else {
  36742. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36743. +
  36744. + /* We allow DPO (Disable Page Out = don't save data in the
  36745. + * cache) and FUA (Force Unit Access = write directly to the
  36746. + * medium). We don't implement DPO; we implement FUA by
  36747. + * performing synchronous output. */
  36748. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36749. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36750. + return -EINVAL;
  36751. + }
  36752. + /* FUA */
  36753. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  36754. + spin_lock(&curlun->filp->f_lock);
  36755. + curlun->filp->f_flags |= O_DSYNC;
  36756. + spin_unlock(&curlun->filp->f_lock);
  36757. + }
  36758. + }
  36759. + if (lba >= curlun->num_sectors) {
  36760. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36761. + return -EINVAL;
  36762. + }
  36763. +
  36764. + /* Carry out the file writes */
  36765. + get_some_more = 1;
  36766. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  36767. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  36768. +
  36769. + while (amount_left_to_write > 0) {
  36770. +
  36771. + /* Queue a request for more data from the host */
  36772. + bh = fsg->next_buffhd_to_fill;
  36773. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  36774. +
  36775. + /* Figure out how much we want to get:
  36776. + * Try to get the remaining amount,
  36777. + * but not more than the buffer size.
  36778. + */
  36779. + amount = min(amount_left_to_req, mod_data.buflen);
  36780. +
  36781. + /* Beyond the end of the backing file? */
  36782. + if (usb_offset >= curlun->file_length) {
  36783. + get_some_more = 0;
  36784. + curlun->sense_data =
  36785. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36786. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  36787. + curlun->info_valid = 1;
  36788. + continue;
  36789. + }
  36790. +
  36791. + /* Get the next buffer */
  36792. + usb_offset += amount;
  36793. + fsg->usb_amount_left -= amount;
  36794. + amount_left_to_req -= amount;
  36795. + if (amount_left_to_req == 0)
  36796. + get_some_more = 0;
  36797. +
  36798. + /* Except at the end of the transfer, amount will be
  36799. + * equal to the buffer size, which is divisible by
  36800. + * the bulk-out maxpacket size.
  36801. + */
  36802. + set_bulk_out_req_length(fsg, bh, amount);
  36803. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36804. + &bh->outreq_busy, &bh->state);
  36805. + fsg->next_buffhd_to_fill = bh->next;
  36806. + continue;
  36807. + }
  36808. +
  36809. + /* Write the received data to the backing file */
  36810. + bh = fsg->next_buffhd_to_drain;
  36811. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  36812. + break; // We stopped early
  36813. + if (bh->state == BUF_STATE_FULL) {
  36814. + smp_rmb();
  36815. + fsg->next_buffhd_to_drain = bh->next;
  36816. + bh->state = BUF_STATE_EMPTY;
  36817. +
  36818. + /* Did something go wrong with the transfer? */
  36819. + if (bh->outreq->status != 0) {
  36820. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  36821. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36822. + curlun->info_valid = 1;
  36823. + break;
  36824. + }
  36825. +
  36826. + amount = bh->outreq->actual;
  36827. + if (curlun->file_length - file_offset < amount) {
  36828. + LERROR(curlun,
  36829. + "write %u @ %llu beyond end %llu\n",
  36830. + amount, (unsigned long long) file_offset,
  36831. + (unsigned long long) curlun->file_length);
  36832. + amount = curlun->file_length - file_offset;
  36833. + }
  36834. +
  36835. + /* Don't accept excess data. The spec doesn't say
  36836. + * what to do in this case. We'll ignore the error.
  36837. + */
  36838. + amount = min(amount, bh->bulk_out_intended_length);
  36839. +
  36840. + /* Don't write a partial block */
  36841. + amount = round_down(amount, curlun->blksize);
  36842. + if (amount == 0)
  36843. + goto empty_write;
  36844. +
  36845. + /* Perform the write */
  36846. + file_offset_tmp = file_offset;
  36847. + nwritten = vfs_write(curlun->filp,
  36848. + (char __user *) bh->buf,
  36849. + amount, &file_offset_tmp);
  36850. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  36851. + (unsigned long long) file_offset,
  36852. + (int) nwritten);
  36853. + if (signal_pending(current))
  36854. + return -EINTR; // Interrupted!
  36855. +
  36856. + if (nwritten < 0) {
  36857. + LDBG(curlun, "error in file write: %d\n",
  36858. + (int) nwritten);
  36859. + nwritten = 0;
  36860. + } else if (nwritten < amount) {
  36861. + LDBG(curlun, "partial file write: %d/%u\n",
  36862. + (int) nwritten, amount);
  36863. + nwritten = round_down(nwritten, curlun->blksize);
  36864. + }
  36865. + file_offset += nwritten;
  36866. + amount_left_to_write -= nwritten;
  36867. + fsg->residue -= nwritten;
  36868. +
  36869. + /* If an error occurred, report it and its position */
  36870. + if (nwritten < amount) {
  36871. + curlun->sense_data = SS_WRITE_ERROR;
  36872. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36873. + curlun->info_valid = 1;
  36874. + break;
  36875. + }
  36876. +
  36877. + empty_write:
  36878. + /* Did the host decide to stop early? */
  36879. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  36880. + fsg->short_packet_received = 1;
  36881. + break;
  36882. + }
  36883. + continue;
  36884. + }
  36885. +
  36886. + /* Wait for something to happen */
  36887. + rc = sleep_thread(fsg);
  36888. + if (rc)
  36889. + return rc;
  36890. + }
  36891. +
  36892. + return -EIO; // No default reply
  36893. +}
  36894. +
  36895. +
  36896. +/*-------------------------------------------------------------------------*/
  36897. +
  36898. +static int do_synchronize_cache(struct fsg_dev *fsg)
  36899. +{
  36900. + struct fsg_lun *curlun = fsg->curlun;
  36901. + int rc;
  36902. +
  36903. + /* We ignore the requested LBA and write out all file's
  36904. + * dirty data buffers. */
  36905. + rc = fsg_lun_fsync_sub(curlun);
  36906. + if (rc)
  36907. + curlun->sense_data = SS_WRITE_ERROR;
  36908. + return 0;
  36909. +}
  36910. +
  36911. +
  36912. +/*-------------------------------------------------------------------------*/
  36913. +
  36914. +static void invalidate_sub(struct fsg_lun *curlun)
  36915. +{
  36916. + struct file *filp = curlun->filp;
  36917. + struct inode *inode = filp->f_path.dentry->d_inode;
  36918. + unsigned long rc;
  36919. +
  36920. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  36921. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  36922. +}
  36923. +
  36924. +static int do_verify(struct fsg_dev *fsg)
  36925. +{
  36926. + struct fsg_lun *curlun = fsg->curlun;
  36927. + u32 lba;
  36928. + u32 verification_length;
  36929. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36930. + loff_t file_offset, file_offset_tmp;
  36931. + u32 amount_left;
  36932. + unsigned int amount;
  36933. + ssize_t nread;
  36934. +
  36935. + /* Get the starting Logical Block Address and check that it's
  36936. + * not too big */
  36937. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36938. + if (lba >= curlun->num_sectors) {
  36939. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36940. + return -EINVAL;
  36941. + }
  36942. +
  36943. + /* We allow DPO (Disable Page Out = don't save data in the
  36944. + * cache) but we don't implement it. */
  36945. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  36946. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36947. + return -EINVAL;
  36948. + }
  36949. +
  36950. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  36951. + if (unlikely(verification_length == 0))
  36952. + return -EIO; // No default reply
  36953. +
  36954. + /* Prepare to carry out the file verify */
  36955. + amount_left = verification_length << curlun->blkbits;
  36956. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36957. +
  36958. + /* Write out all the dirty buffers before invalidating them */
  36959. + fsg_lun_fsync_sub(curlun);
  36960. + if (signal_pending(current))
  36961. + return -EINTR;
  36962. +
  36963. + invalidate_sub(curlun);
  36964. + if (signal_pending(current))
  36965. + return -EINTR;
  36966. +
  36967. + /* Just try to read the requested blocks */
  36968. + while (amount_left > 0) {
  36969. +
  36970. + /* Figure out how much we need to read:
  36971. + * Try to read the remaining amount, but not more than
  36972. + * the buffer size.
  36973. + * And don't try to read past the end of the file.
  36974. + */
  36975. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36976. + amount = min((loff_t) amount,
  36977. + curlun->file_length - file_offset);
  36978. + if (amount == 0) {
  36979. + curlun->sense_data =
  36980. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36981. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36982. + curlun->info_valid = 1;
  36983. + break;
  36984. + }
  36985. +
  36986. + /* Perform the read */
  36987. + file_offset_tmp = file_offset;
  36988. + nread = vfs_read(curlun->filp,
  36989. + (char __user *) bh->buf,
  36990. + amount, &file_offset_tmp);
  36991. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36992. + (unsigned long long) file_offset,
  36993. + (int) nread);
  36994. + if (signal_pending(current))
  36995. + return -EINTR;
  36996. +
  36997. + if (nread < 0) {
  36998. + LDBG(curlun, "error in file verify: %d\n",
  36999. + (int) nread);
  37000. + nread = 0;
  37001. + } else if (nread < amount) {
  37002. + LDBG(curlun, "partial file verify: %d/%u\n",
  37003. + (int) nread, amount);
  37004. + nread = round_down(nread, curlun->blksize);
  37005. + }
  37006. + if (nread == 0) {
  37007. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  37008. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37009. + curlun->info_valid = 1;
  37010. + break;
  37011. + }
  37012. + file_offset += nread;
  37013. + amount_left -= nread;
  37014. + }
  37015. + return 0;
  37016. +}
  37017. +
  37018. +
  37019. +/*-------------------------------------------------------------------------*/
  37020. +
  37021. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37022. +{
  37023. + u8 *buf = (u8 *) bh->buf;
  37024. +
  37025. + static char vendor_id[] = "Linux ";
  37026. + static char product_disk_id[] = "File-Stor Gadget";
  37027. + static char product_cdrom_id[] = "File-CD Gadget ";
  37028. +
  37029. + if (!fsg->curlun) { // Unsupported LUNs are okay
  37030. + fsg->bad_lun_okay = 1;
  37031. + memset(buf, 0, 36);
  37032. + buf[0] = 0x7f; // Unsupported, no device-type
  37033. + buf[4] = 31; // Additional length
  37034. + return 36;
  37035. + }
  37036. +
  37037. + memset(buf, 0, 8);
  37038. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  37039. + if (mod_data.removable)
  37040. + buf[1] = 0x80;
  37041. + buf[2] = 2; // ANSI SCSI level 2
  37042. + buf[3] = 2; // SCSI-2 INQUIRY data format
  37043. + buf[4] = 31; // Additional length
  37044. + // No special options
  37045. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  37046. + (mod_data.cdrom ? product_cdrom_id :
  37047. + product_disk_id),
  37048. + mod_data.release);
  37049. + return 36;
  37050. +}
  37051. +
  37052. +
  37053. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37054. +{
  37055. + struct fsg_lun *curlun = fsg->curlun;
  37056. + u8 *buf = (u8 *) bh->buf;
  37057. + u32 sd, sdinfo;
  37058. + int valid;
  37059. +
  37060. + /*
  37061. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  37062. + *
  37063. + * If a REQUEST SENSE command is received from an initiator
  37064. + * with a pending unit attention condition (before the target
  37065. + * generates the contingent allegiance condition), then the
  37066. + * target shall either:
  37067. + * a) report any pending sense data and preserve the unit
  37068. + * attention condition on the logical unit, or,
  37069. + * b) report the unit attention condition, may discard any
  37070. + * pending sense data, and clear the unit attention
  37071. + * condition on the logical unit for that initiator.
  37072. + *
  37073. + * FSG normally uses option a); enable this code to use option b).
  37074. + */
  37075. +#if 0
  37076. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  37077. + curlun->sense_data = curlun->unit_attention_data;
  37078. + curlun->unit_attention_data = SS_NO_SENSE;
  37079. + }
  37080. +#endif
  37081. +
  37082. + if (!curlun) { // Unsupported LUNs are okay
  37083. + fsg->bad_lun_okay = 1;
  37084. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37085. + sdinfo = 0;
  37086. + valid = 0;
  37087. + } else {
  37088. + sd = curlun->sense_data;
  37089. + sdinfo = curlun->sense_data_info;
  37090. + valid = curlun->info_valid << 7;
  37091. + curlun->sense_data = SS_NO_SENSE;
  37092. + curlun->sense_data_info = 0;
  37093. + curlun->info_valid = 0;
  37094. + }
  37095. +
  37096. + memset(buf, 0, 18);
  37097. + buf[0] = valid | 0x70; // Valid, current error
  37098. + buf[2] = SK(sd);
  37099. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  37100. + buf[7] = 18 - 8; // Additional sense length
  37101. + buf[12] = ASC(sd);
  37102. + buf[13] = ASCQ(sd);
  37103. + return 18;
  37104. +}
  37105. +
  37106. +
  37107. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37108. +{
  37109. + struct fsg_lun *curlun = fsg->curlun;
  37110. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37111. + int pmi = fsg->cmnd[8];
  37112. + u8 *buf = (u8 *) bh->buf;
  37113. +
  37114. + /* Check the PMI and LBA fields */
  37115. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  37116. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37117. + return -EINVAL;
  37118. + }
  37119. +
  37120. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  37121. + /* Max logical block */
  37122. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37123. + return 8;
  37124. +}
  37125. +
  37126. +
  37127. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37128. +{
  37129. + struct fsg_lun *curlun = fsg->curlun;
  37130. + int msf = fsg->cmnd[1] & 0x02;
  37131. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37132. + u8 *buf = (u8 *) bh->buf;
  37133. +
  37134. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  37135. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37136. + return -EINVAL;
  37137. + }
  37138. + if (lba >= curlun->num_sectors) {
  37139. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37140. + return -EINVAL;
  37141. + }
  37142. +
  37143. + memset(buf, 0, 8);
  37144. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  37145. + store_cdrom_address(&buf[4], msf, lba);
  37146. + return 8;
  37147. +}
  37148. +
  37149. +
  37150. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37151. +{
  37152. + struct fsg_lun *curlun = fsg->curlun;
  37153. + int msf = fsg->cmnd[1] & 0x02;
  37154. + int start_track = fsg->cmnd[6];
  37155. + u8 *buf = (u8 *) bh->buf;
  37156. +
  37157. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  37158. + start_track > 1) {
  37159. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37160. + return -EINVAL;
  37161. + }
  37162. +
  37163. + memset(buf, 0, 20);
  37164. + buf[1] = (20-2); /* TOC data length */
  37165. + buf[2] = 1; /* First track number */
  37166. + buf[3] = 1; /* Last track number */
  37167. + buf[5] = 0x16; /* Data track, copying allowed */
  37168. + buf[6] = 0x01; /* Only track is number 1 */
  37169. + store_cdrom_address(&buf[8], msf, 0);
  37170. +
  37171. + buf[13] = 0x16; /* Lead-out track is data */
  37172. + buf[14] = 0xAA; /* Lead-out track number */
  37173. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  37174. + return 20;
  37175. +}
  37176. +
  37177. +
  37178. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37179. +{
  37180. + struct fsg_lun *curlun = fsg->curlun;
  37181. + int mscmnd = fsg->cmnd[0];
  37182. + u8 *buf = (u8 *) bh->buf;
  37183. + u8 *buf0 = buf;
  37184. + int pc, page_code;
  37185. + int changeable_values, all_pages;
  37186. + int valid_page = 0;
  37187. + int len, limit;
  37188. +
  37189. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  37190. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37191. + return -EINVAL;
  37192. + }
  37193. + pc = fsg->cmnd[2] >> 6;
  37194. + page_code = fsg->cmnd[2] & 0x3f;
  37195. + if (pc == 3) {
  37196. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  37197. + return -EINVAL;
  37198. + }
  37199. + changeable_values = (pc == 1);
  37200. + all_pages = (page_code == 0x3f);
  37201. +
  37202. + /* Write the mode parameter header. Fixed values are: default
  37203. + * medium type, no cache control (DPOFUA), and no block descriptors.
  37204. + * The only variable value is the WriteProtect bit. We will fill in
  37205. + * the mode data length later. */
  37206. + memset(buf, 0, 8);
  37207. + if (mscmnd == MODE_SENSE) {
  37208. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  37209. + buf += 4;
  37210. + limit = 255;
  37211. + } else { // MODE_SENSE_10
  37212. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  37213. + buf += 8;
  37214. + limit = 65535; // Should really be mod_data.buflen
  37215. + }
  37216. +
  37217. + /* No block descriptors */
  37218. +
  37219. + /* The mode pages, in numerical order. The only page we support
  37220. + * is the Caching page. */
  37221. + if (page_code == 0x08 || all_pages) {
  37222. + valid_page = 1;
  37223. + buf[0] = 0x08; // Page code
  37224. + buf[1] = 10; // Page length
  37225. + memset(buf+2, 0, 10); // None of the fields are changeable
  37226. +
  37227. + if (!changeable_values) {
  37228. + buf[2] = 0x04; // Write cache enable,
  37229. + // Read cache not disabled
  37230. + // No cache retention priorities
  37231. + put_unaligned_be16(0xffff, &buf[4]);
  37232. + /* Don't disable prefetch */
  37233. + /* Minimum prefetch = 0 */
  37234. + put_unaligned_be16(0xffff, &buf[8]);
  37235. + /* Maximum prefetch */
  37236. + put_unaligned_be16(0xffff, &buf[10]);
  37237. + /* Maximum prefetch ceiling */
  37238. + }
  37239. + buf += 12;
  37240. + }
  37241. +
  37242. + /* Check that a valid page was requested and the mode data length
  37243. + * isn't too long. */
  37244. + len = buf - buf0;
  37245. + if (!valid_page || len > limit) {
  37246. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37247. + return -EINVAL;
  37248. + }
  37249. +
  37250. + /* Store the mode data length */
  37251. + if (mscmnd == MODE_SENSE)
  37252. + buf0[0] = len - 1;
  37253. + else
  37254. + put_unaligned_be16(len - 2, buf0);
  37255. + return len;
  37256. +}
  37257. +
  37258. +
  37259. +static int do_start_stop(struct fsg_dev *fsg)
  37260. +{
  37261. + struct fsg_lun *curlun = fsg->curlun;
  37262. + int loej, start;
  37263. +
  37264. + if (!mod_data.removable) {
  37265. + curlun->sense_data = SS_INVALID_COMMAND;
  37266. + return -EINVAL;
  37267. + }
  37268. +
  37269. + // int immed = fsg->cmnd[1] & 0x01;
  37270. + loej = fsg->cmnd[4] & 0x02;
  37271. + start = fsg->cmnd[4] & 0x01;
  37272. +
  37273. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37274. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  37275. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  37276. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37277. + return -EINVAL;
  37278. + }
  37279. +
  37280. + if (!start) {
  37281. +
  37282. + /* Are we allowed to unload the media? */
  37283. + if (curlun->prevent_medium_removal) {
  37284. + LDBG(curlun, "unload attempt prevented\n");
  37285. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  37286. + return -EINVAL;
  37287. + }
  37288. + if (loej) { // Simulate an unload/eject
  37289. + up_read(&fsg->filesem);
  37290. + down_write(&fsg->filesem);
  37291. + fsg_lun_close(curlun);
  37292. + up_write(&fsg->filesem);
  37293. + down_read(&fsg->filesem);
  37294. + }
  37295. + } else {
  37296. +
  37297. + /* Our emulation doesn't support mounting; the medium is
  37298. + * available for use as soon as it is loaded. */
  37299. + if (!fsg_lun_is_open(curlun)) {
  37300. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37301. + return -EINVAL;
  37302. + }
  37303. + }
  37304. +#endif
  37305. + return 0;
  37306. +}
  37307. +
  37308. +
  37309. +static int do_prevent_allow(struct fsg_dev *fsg)
  37310. +{
  37311. + struct fsg_lun *curlun = fsg->curlun;
  37312. + int prevent;
  37313. +
  37314. + if (!mod_data.removable) {
  37315. + curlun->sense_data = SS_INVALID_COMMAND;
  37316. + return -EINVAL;
  37317. + }
  37318. +
  37319. + prevent = fsg->cmnd[4] & 0x01;
  37320. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  37321. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37322. + return -EINVAL;
  37323. + }
  37324. +
  37325. + if (curlun->prevent_medium_removal && !prevent)
  37326. + fsg_lun_fsync_sub(curlun);
  37327. + curlun->prevent_medium_removal = prevent;
  37328. + return 0;
  37329. +}
  37330. +
  37331. +
  37332. +static int do_read_format_capacities(struct fsg_dev *fsg,
  37333. + struct fsg_buffhd *bh)
  37334. +{
  37335. + struct fsg_lun *curlun = fsg->curlun;
  37336. + u8 *buf = (u8 *) bh->buf;
  37337. +
  37338. + buf[0] = buf[1] = buf[2] = 0;
  37339. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  37340. + buf += 4;
  37341. +
  37342. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  37343. + /* Number of blocks */
  37344. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37345. + buf[4] = 0x02; /* Current capacity */
  37346. + return 12;
  37347. +}
  37348. +
  37349. +
  37350. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37351. +{
  37352. + struct fsg_lun *curlun = fsg->curlun;
  37353. +
  37354. + /* We don't support MODE SELECT */
  37355. + curlun->sense_data = SS_INVALID_COMMAND;
  37356. + return -EINVAL;
  37357. +}
  37358. +
  37359. +
  37360. +/*-------------------------------------------------------------------------*/
  37361. +
  37362. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  37363. +{
  37364. + int rc;
  37365. +
  37366. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  37367. + if (rc == -EAGAIN)
  37368. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  37369. + while (rc != 0) {
  37370. + if (rc != -EAGAIN) {
  37371. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  37372. + rc = 0;
  37373. + break;
  37374. + }
  37375. +
  37376. + /* Wait for a short time and then try again */
  37377. + if (msleep_interruptible(100) != 0)
  37378. + return -EINTR;
  37379. + rc = usb_ep_set_halt(fsg->bulk_in);
  37380. + }
  37381. + return rc;
  37382. +}
  37383. +
  37384. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  37385. +{
  37386. + int rc;
  37387. +
  37388. + DBG(fsg, "bulk-in set wedge\n");
  37389. + rc = usb_ep_set_wedge(fsg->bulk_in);
  37390. + if (rc == -EAGAIN)
  37391. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  37392. + while (rc != 0) {
  37393. + if (rc != -EAGAIN) {
  37394. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  37395. + rc = 0;
  37396. + break;
  37397. + }
  37398. +
  37399. + /* Wait for a short time and then try again */
  37400. + if (msleep_interruptible(100) != 0)
  37401. + return -EINTR;
  37402. + rc = usb_ep_set_wedge(fsg->bulk_in);
  37403. + }
  37404. + return rc;
  37405. +}
  37406. +
  37407. +static int throw_away_data(struct fsg_dev *fsg)
  37408. +{
  37409. + struct fsg_buffhd *bh;
  37410. + u32 amount;
  37411. + int rc;
  37412. +
  37413. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  37414. + fsg->usb_amount_left > 0) {
  37415. +
  37416. + /* Throw away the data in a filled buffer */
  37417. + if (bh->state == BUF_STATE_FULL) {
  37418. + smp_rmb();
  37419. + bh->state = BUF_STATE_EMPTY;
  37420. + fsg->next_buffhd_to_drain = bh->next;
  37421. +
  37422. + /* A short packet or an error ends everything */
  37423. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  37424. + bh->outreq->status != 0) {
  37425. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37426. + return -EINTR;
  37427. + }
  37428. + continue;
  37429. + }
  37430. +
  37431. + /* Try to submit another request if we need one */
  37432. + bh = fsg->next_buffhd_to_fill;
  37433. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  37434. + amount = min(fsg->usb_amount_left,
  37435. + (u32) mod_data.buflen);
  37436. +
  37437. + /* Except at the end of the transfer, amount will be
  37438. + * equal to the buffer size, which is divisible by
  37439. + * the bulk-out maxpacket size.
  37440. + */
  37441. + set_bulk_out_req_length(fsg, bh, amount);
  37442. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37443. + &bh->outreq_busy, &bh->state);
  37444. + fsg->next_buffhd_to_fill = bh->next;
  37445. + fsg->usb_amount_left -= amount;
  37446. + continue;
  37447. + }
  37448. +
  37449. + /* Otherwise wait for something to happen */
  37450. + rc = sleep_thread(fsg);
  37451. + if (rc)
  37452. + return rc;
  37453. + }
  37454. + return 0;
  37455. +}
  37456. +
  37457. +
  37458. +static int finish_reply(struct fsg_dev *fsg)
  37459. +{
  37460. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  37461. + int rc = 0;
  37462. +
  37463. + switch (fsg->data_dir) {
  37464. + case DATA_DIR_NONE:
  37465. + break; // Nothing to send
  37466. +
  37467. + /* If we don't know whether the host wants to read or write,
  37468. + * this must be CB or CBI with an unknown command. We mustn't
  37469. + * try to send or receive any data. So stall both bulk pipes
  37470. + * if we can and wait for a reset. */
  37471. + case DATA_DIR_UNKNOWN:
  37472. + if (mod_data.can_stall) {
  37473. + fsg_set_halt(fsg, fsg->bulk_out);
  37474. + rc = halt_bulk_in_endpoint(fsg);
  37475. + }
  37476. + break;
  37477. +
  37478. + /* All but the last buffer of data must have already been sent */
  37479. + case DATA_DIR_TO_HOST:
  37480. + if (fsg->data_size == 0)
  37481. + ; // Nothing to send
  37482. +
  37483. + /* If there's no residue, simply send the last buffer */
  37484. + else if (fsg->residue == 0) {
  37485. + bh->inreq->zero = 0;
  37486. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37487. + &bh->inreq_busy, &bh->state);
  37488. + fsg->next_buffhd_to_fill = bh->next;
  37489. + }
  37490. +
  37491. + /* There is a residue. For CB and CBI, simply mark the end
  37492. + * of the data with a short packet. However, if we are
  37493. + * allowed to stall, there was no data at all (residue ==
  37494. + * data_size), and the command failed (invalid LUN or
  37495. + * sense data is set), then halt the bulk-in endpoint
  37496. + * instead. */
  37497. + else if (!transport_is_bbb()) {
  37498. + if (mod_data.can_stall &&
  37499. + fsg->residue == fsg->data_size &&
  37500. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  37501. + bh->state = BUF_STATE_EMPTY;
  37502. + rc = halt_bulk_in_endpoint(fsg);
  37503. + } else {
  37504. + bh->inreq->zero = 1;
  37505. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37506. + &bh->inreq_busy, &bh->state);
  37507. + fsg->next_buffhd_to_fill = bh->next;
  37508. + }
  37509. + }
  37510. +
  37511. + /*
  37512. + * For Bulk-only, mark the end of the data with a short
  37513. + * packet. If we are allowed to stall, halt the bulk-in
  37514. + * endpoint. (Note: This violates the Bulk-Only Transport
  37515. + * specification, which requires us to pad the data if we
  37516. + * don't halt the endpoint. Presumably nobody will mind.)
  37517. + */
  37518. + else {
  37519. + bh->inreq->zero = 1;
  37520. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37521. + &bh->inreq_busy, &bh->state);
  37522. + fsg->next_buffhd_to_fill = bh->next;
  37523. + if (mod_data.can_stall)
  37524. + rc = halt_bulk_in_endpoint(fsg);
  37525. + }
  37526. + break;
  37527. +
  37528. + /* We have processed all we want from the data the host has sent.
  37529. + * There may still be outstanding bulk-out requests. */
  37530. + case DATA_DIR_FROM_HOST:
  37531. + if (fsg->residue == 0)
  37532. + ; // Nothing to receive
  37533. +
  37534. + /* Did the host stop sending unexpectedly early? */
  37535. + else if (fsg->short_packet_received) {
  37536. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37537. + rc = -EINTR;
  37538. + }
  37539. +
  37540. + /* We haven't processed all the incoming data. Even though
  37541. + * we may be allowed to stall, doing so would cause a race.
  37542. + * The controller may already have ACK'ed all the remaining
  37543. + * bulk-out packets, in which case the host wouldn't see a
  37544. + * STALL. Not realizing the endpoint was halted, it wouldn't
  37545. + * clear the halt -- leading to problems later on. */
  37546. +#if 0
  37547. + else if (mod_data.can_stall) {
  37548. + fsg_set_halt(fsg, fsg->bulk_out);
  37549. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37550. + rc = -EINTR;
  37551. + }
  37552. +#endif
  37553. +
  37554. + /* We can't stall. Read in the excess data and throw it
  37555. + * all away. */
  37556. + else
  37557. + rc = throw_away_data(fsg);
  37558. + break;
  37559. + }
  37560. + return rc;
  37561. +}
  37562. +
  37563. +
  37564. +static int send_status(struct fsg_dev *fsg)
  37565. +{
  37566. + struct fsg_lun *curlun = fsg->curlun;
  37567. + struct fsg_buffhd *bh;
  37568. + int rc;
  37569. + u8 status = US_BULK_STAT_OK;
  37570. + u32 sd, sdinfo = 0;
  37571. +
  37572. + /* Wait for the next buffer to become available */
  37573. + bh = fsg->next_buffhd_to_fill;
  37574. + while (bh->state != BUF_STATE_EMPTY) {
  37575. + rc = sleep_thread(fsg);
  37576. + if (rc)
  37577. + return rc;
  37578. + }
  37579. +
  37580. + if (curlun) {
  37581. + sd = curlun->sense_data;
  37582. + sdinfo = curlun->sense_data_info;
  37583. + } else if (fsg->bad_lun_okay)
  37584. + sd = SS_NO_SENSE;
  37585. + else
  37586. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37587. +
  37588. + if (fsg->phase_error) {
  37589. + DBG(fsg, "sending phase-error status\n");
  37590. + status = US_BULK_STAT_PHASE;
  37591. + sd = SS_INVALID_COMMAND;
  37592. + } else if (sd != SS_NO_SENSE) {
  37593. + DBG(fsg, "sending command-failure status\n");
  37594. + status = US_BULK_STAT_FAIL;
  37595. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  37596. + " info x%x\n",
  37597. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  37598. + }
  37599. +
  37600. + if (transport_is_bbb()) {
  37601. + struct bulk_cs_wrap *csw = bh->buf;
  37602. +
  37603. + /* Store and send the Bulk-only CSW */
  37604. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  37605. + csw->Tag = fsg->tag;
  37606. + csw->Residue = cpu_to_le32(fsg->residue);
  37607. + csw->Status = status;
  37608. +
  37609. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  37610. + bh->inreq->zero = 0;
  37611. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37612. + &bh->inreq_busy, &bh->state);
  37613. +
  37614. + } else if (mod_data.transport_type == USB_PR_CB) {
  37615. +
  37616. + /* Control-Bulk transport has no status phase! */
  37617. + return 0;
  37618. +
  37619. + } else { // USB_PR_CBI
  37620. + struct interrupt_data *buf = bh->buf;
  37621. +
  37622. + /* Store and send the Interrupt data. UFI sends the ASC
  37623. + * and ASCQ bytes. Everything else sends a Type (which
  37624. + * is always 0) and the status Value. */
  37625. + if (mod_data.protocol_type == USB_SC_UFI) {
  37626. + buf->bType = ASC(sd);
  37627. + buf->bValue = ASCQ(sd);
  37628. + } else {
  37629. + buf->bType = 0;
  37630. + buf->bValue = status;
  37631. + }
  37632. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  37633. +
  37634. + fsg->intr_buffhd = bh; // Point to the right buffhd
  37635. + fsg->intreq->buf = bh->inreq->buf;
  37636. + fsg->intreq->context = bh;
  37637. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  37638. + &fsg->intreq_busy, &bh->state);
  37639. + }
  37640. +
  37641. + fsg->next_buffhd_to_fill = bh->next;
  37642. + return 0;
  37643. +}
  37644. +
  37645. +
  37646. +/*-------------------------------------------------------------------------*/
  37647. +
  37648. +/* Check whether the command is properly formed and whether its data size
  37649. + * and direction agree with the values we already have. */
  37650. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  37651. + enum data_direction data_dir, unsigned int mask,
  37652. + int needs_medium, const char *name)
  37653. +{
  37654. + int i;
  37655. + int lun = fsg->cmnd[1] >> 5;
  37656. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  37657. + char hdlen[20];
  37658. + struct fsg_lun *curlun;
  37659. +
  37660. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  37661. + * Transparent SCSI doesn't pad. */
  37662. + if (protocol_is_scsi())
  37663. + ;
  37664. +
  37665. + /* There's some disagreement as to whether RBC pads commands or not.
  37666. + * We'll play it safe and accept either form. */
  37667. + else if (mod_data.protocol_type == USB_SC_RBC) {
  37668. + if (fsg->cmnd_size == 12)
  37669. + cmnd_size = 12;
  37670. +
  37671. + /* All the other protocols pad to 12 bytes */
  37672. + } else
  37673. + cmnd_size = 12;
  37674. +
  37675. + hdlen[0] = 0;
  37676. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  37677. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  37678. + fsg->data_size);
  37679. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  37680. + name, cmnd_size, dirletter[(int) data_dir],
  37681. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  37682. +
  37683. + /* We can't reply at all until we know the correct data direction
  37684. + * and size. */
  37685. + if (fsg->data_size_from_cmnd == 0)
  37686. + data_dir = DATA_DIR_NONE;
  37687. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  37688. + fsg->data_dir = data_dir;
  37689. + fsg->data_size = fsg->data_size_from_cmnd;
  37690. +
  37691. + } else { // Bulk-only
  37692. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  37693. +
  37694. + /* Host data size < Device data size is a phase error.
  37695. + * Carry out the command, but only transfer as much
  37696. + * as we are allowed. */
  37697. + fsg->data_size_from_cmnd = fsg->data_size;
  37698. + fsg->phase_error = 1;
  37699. + }
  37700. + }
  37701. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  37702. +
  37703. + /* Conflicting data directions is a phase error */
  37704. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  37705. + fsg->phase_error = 1;
  37706. + return -EINVAL;
  37707. + }
  37708. +
  37709. + /* Verify the length of the command itself */
  37710. + if (cmnd_size != fsg->cmnd_size) {
  37711. +
  37712. + /* Special case workaround: There are plenty of buggy SCSI
  37713. + * implementations. Many have issues with cbw->Length
  37714. + * field passing a wrong command size. For those cases we
  37715. + * always try to work around the problem by using the length
  37716. + * sent by the host side provided it is at least as large
  37717. + * as the correct command length.
  37718. + * Examples of such cases would be MS-Windows, which issues
  37719. + * REQUEST SENSE with cbw->Length == 12 where it should
  37720. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  37721. + * REQUEST SENSE with cbw->Length == 10 where it should
  37722. + * be 6 as well.
  37723. + */
  37724. + if (cmnd_size <= fsg->cmnd_size) {
  37725. + DBG(fsg, "%s is buggy! Expected length %d "
  37726. + "but we got %d\n", name,
  37727. + cmnd_size, fsg->cmnd_size);
  37728. + cmnd_size = fsg->cmnd_size;
  37729. + } else {
  37730. + fsg->phase_error = 1;
  37731. + return -EINVAL;
  37732. + }
  37733. + }
  37734. +
  37735. + /* Check that the LUN values are consistent */
  37736. + if (transport_is_bbb()) {
  37737. + if (fsg->lun != lun)
  37738. + DBG(fsg, "using LUN %d from CBW, "
  37739. + "not LUN %d from CDB\n",
  37740. + fsg->lun, lun);
  37741. + }
  37742. +
  37743. + /* Check the LUN */
  37744. + curlun = fsg->curlun;
  37745. + if (curlun) {
  37746. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  37747. + curlun->sense_data = SS_NO_SENSE;
  37748. + curlun->sense_data_info = 0;
  37749. + curlun->info_valid = 0;
  37750. + }
  37751. + } else {
  37752. + fsg->bad_lun_okay = 0;
  37753. +
  37754. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  37755. + * to use unsupported LUNs; all others may not. */
  37756. + if (fsg->cmnd[0] != INQUIRY &&
  37757. + fsg->cmnd[0] != REQUEST_SENSE) {
  37758. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  37759. + return -EINVAL;
  37760. + }
  37761. + }
  37762. +
  37763. + /* If a unit attention condition exists, only INQUIRY and
  37764. + * REQUEST SENSE commands are allowed; anything else must fail. */
  37765. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  37766. + fsg->cmnd[0] != INQUIRY &&
  37767. + fsg->cmnd[0] != REQUEST_SENSE) {
  37768. + curlun->sense_data = curlun->unit_attention_data;
  37769. + curlun->unit_attention_data = SS_NO_SENSE;
  37770. + return -EINVAL;
  37771. + }
  37772. +
  37773. + /* Check that only command bytes listed in the mask are non-zero */
  37774. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  37775. + for (i = 1; i < cmnd_size; ++i) {
  37776. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  37777. + if (curlun)
  37778. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37779. + return -EINVAL;
  37780. + }
  37781. + }
  37782. +
  37783. + /* If the medium isn't mounted and the command needs to access
  37784. + * it, return an error. */
  37785. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  37786. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37787. + return -EINVAL;
  37788. + }
  37789. +
  37790. + return 0;
  37791. +}
  37792. +
  37793. +/* wrapper of check_command for data size in blocks handling */
  37794. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  37795. + enum data_direction data_dir, unsigned int mask,
  37796. + int needs_medium, const char *name)
  37797. +{
  37798. + if (fsg->curlun)
  37799. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  37800. + return check_command(fsg, cmnd_size, data_dir,
  37801. + mask, needs_medium, name);
  37802. +}
  37803. +
  37804. +static int do_scsi_command(struct fsg_dev *fsg)
  37805. +{
  37806. + struct fsg_buffhd *bh;
  37807. + int rc;
  37808. + int reply = -EINVAL;
  37809. + int i;
  37810. + static char unknown[16];
  37811. +
  37812. + dump_cdb(fsg);
  37813. +
  37814. + /* Wait for the next buffer to become available for data or status */
  37815. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  37816. + while (bh->state != BUF_STATE_EMPTY) {
  37817. + rc = sleep_thread(fsg);
  37818. + if (rc)
  37819. + return rc;
  37820. + }
  37821. + fsg->phase_error = 0;
  37822. + fsg->short_packet_received = 0;
  37823. +
  37824. + down_read(&fsg->filesem); // We're using the backing file
  37825. + switch (fsg->cmnd[0]) {
  37826. +
  37827. + case INQUIRY:
  37828. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37829. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37830. + (1<<4), 0,
  37831. + "INQUIRY")) == 0)
  37832. + reply = do_inquiry(fsg, bh);
  37833. + break;
  37834. +
  37835. + case MODE_SELECT:
  37836. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37837. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  37838. + (1<<1) | (1<<4), 0,
  37839. + "MODE SELECT(6)")) == 0)
  37840. + reply = do_mode_select(fsg, bh);
  37841. + break;
  37842. +
  37843. + case MODE_SELECT_10:
  37844. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37845. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  37846. + (1<<1) | (3<<7), 0,
  37847. + "MODE SELECT(10)")) == 0)
  37848. + reply = do_mode_select(fsg, bh);
  37849. + break;
  37850. +
  37851. + case MODE_SENSE:
  37852. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37853. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37854. + (1<<1) | (1<<2) | (1<<4), 0,
  37855. + "MODE SENSE(6)")) == 0)
  37856. + reply = do_mode_sense(fsg, bh);
  37857. + break;
  37858. +
  37859. + case MODE_SENSE_10:
  37860. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37861. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37862. + (1<<1) | (1<<2) | (3<<7), 0,
  37863. + "MODE SENSE(10)")) == 0)
  37864. + reply = do_mode_sense(fsg, bh);
  37865. + break;
  37866. +
  37867. + case ALLOW_MEDIUM_REMOVAL:
  37868. + fsg->data_size_from_cmnd = 0;
  37869. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37870. + (1<<4), 0,
  37871. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  37872. + reply = do_prevent_allow(fsg);
  37873. + break;
  37874. +
  37875. + case READ_6:
  37876. + i = fsg->cmnd[4];
  37877. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37878. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37879. + DATA_DIR_TO_HOST,
  37880. + (7<<1) | (1<<4), 1,
  37881. + "READ(6)")) == 0)
  37882. + reply = do_read(fsg);
  37883. + break;
  37884. +
  37885. + case READ_10:
  37886. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37887. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37888. + DATA_DIR_TO_HOST,
  37889. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37890. + "READ(10)")) == 0)
  37891. + reply = do_read(fsg);
  37892. + break;
  37893. +
  37894. + case READ_12:
  37895. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37896. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37897. + DATA_DIR_TO_HOST,
  37898. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37899. + "READ(12)")) == 0)
  37900. + reply = do_read(fsg);
  37901. + break;
  37902. +
  37903. + case READ_CAPACITY:
  37904. + fsg->data_size_from_cmnd = 8;
  37905. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37906. + (0xf<<2) | (1<<8), 1,
  37907. + "READ CAPACITY")) == 0)
  37908. + reply = do_read_capacity(fsg, bh);
  37909. + break;
  37910. +
  37911. + case READ_HEADER:
  37912. + if (!mod_data.cdrom)
  37913. + goto unknown_cmnd;
  37914. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37915. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37916. + (3<<7) | (0x1f<<1), 1,
  37917. + "READ HEADER")) == 0)
  37918. + reply = do_read_header(fsg, bh);
  37919. + break;
  37920. +
  37921. + case READ_TOC:
  37922. + if (!mod_data.cdrom)
  37923. + goto unknown_cmnd;
  37924. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37925. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37926. + (7<<6) | (1<<1), 1,
  37927. + "READ TOC")) == 0)
  37928. + reply = do_read_toc(fsg, bh);
  37929. + break;
  37930. +
  37931. + case READ_FORMAT_CAPACITIES:
  37932. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37933. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37934. + (3<<7), 1,
  37935. + "READ FORMAT CAPACITIES")) == 0)
  37936. + reply = do_read_format_capacities(fsg, bh);
  37937. + break;
  37938. +
  37939. + case REQUEST_SENSE:
  37940. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37941. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37942. + (1<<4), 0,
  37943. + "REQUEST SENSE")) == 0)
  37944. + reply = do_request_sense(fsg, bh);
  37945. + break;
  37946. +
  37947. + case START_STOP:
  37948. + fsg->data_size_from_cmnd = 0;
  37949. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37950. + (1<<1) | (1<<4), 0,
  37951. + "START-STOP UNIT")) == 0)
  37952. + reply = do_start_stop(fsg);
  37953. + break;
  37954. +
  37955. + case SYNCHRONIZE_CACHE:
  37956. + fsg->data_size_from_cmnd = 0;
  37957. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37958. + (0xf<<2) | (3<<7), 1,
  37959. + "SYNCHRONIZE CACHE")) == 0)
  37960. + reply = do_synchronize_cache(fsg);
  37961. + break;
  37962. +
  37963. + case TEST_UNIT_READY:
  37964. + fsg->data_size_from_cmnd = 0;
  37965. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  37966. + 0, 1,
  37967. + "TEST UNIT READY");
  37968. + break;
  37969. +
  37970. + /* Although optional, this command is used by MS-Windows. We
  37971. + * support a minimal version: BytChk must be 0. */
  37972. + case VERIFY:
  37973. + fsg->data_size_from_cmnd = 0;
  37974. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37975. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37976. + "VERIFY")) == 0)
  37977. + reply = do_verify(fsg);
  37978. + break;
  37979. +
  37980. + case WRITE_6:
  37981. + i = fsg->cmnd[4];
  37982. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37983. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37984. + DATA_DIR_FROM_HOST,
  37985. + (7<<1) | (1<<4), 1,
  37986. + "WRITE(6)")) == 0)
  37987. + reply = do_write(fsg);
  37988. + break;
  37989. +
  37990. + case WRITE_10:
  37991. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37992. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37993. + DATA_DIR_FROM_HOST,
  37994. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37995. + "WRITE(10)")) == 0)
  37996. + reply = do_write(fsg);
  37997. + break;
  37998. +
  37999. + case WRITE_12:
  38000. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  38001. + if ((reply = check_command_size_in_blocks(fsg, 12,
  38002. + DATA_DIR_FROM_HOST,
  38003. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  38004. + "WRITE(12)")) == 0)
  38005. + reply = do_write(fsg);
  38006. + break;
  38007. +
  38008. + /* Some mandatory commands that we recognize but don't implement.
  38009. + * They don't mean much in this setting. It's left as an exercise
  38010. + * for anyone interested to implement RESERVE and RELEASE in terms
  38011. + * of Posix locks. */
  38012. + case FORMAT_UNIT:
  38013. + case RELEASE:
  38014. + case RESERVE:
  38015. + case SEND_DIAGNOSTIC:
  38016. + // Fall through
  38017. +
  38018. + default:
  38019. + unknown_cmnd:
  38020. + fsg->data_size_from_cmnd = 0;
  38021. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  38022. + if ((reply = check_command(fsg, fsg->cmnd_size,
  38023. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  38024. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  38025. + reply = -EINVAL;
  38026. + }
  38027. + break;
  38028. + }
  38029. + up_read(&fsg->filesem);
  38030. +
  38031. + if (reply == -EINTR || signal_pending(current))
  38032. + return -EINTR;
  38033. +
  38034. + /* Set up the single reply buffer for finish_reply() */
  38035. + if (reply == -EINVAL)
  38036. + reply = 0; // Error reply length
  38037. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  38038. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  38039. + bh->inreq->length = reply;
  38040. + bh->state = BUF_STATE_FULL;
  38041. + fsg->residue -= reply;
  38042. + } // Otherwise it's already set
  38043. +
  38044. + return 0;
  38045. +}
  38046. +
  38047. +
  38048. +/*-------------------------------------------------------------------------*/
  38049. +
  38050. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  38051. +{
  38052. + struct usb_request *req = bh->outreq;
  38053. + struct bulk_cb_wrap *cbw = req->buf;
  38054. +
  38055. + /* Was this a real packet? Should it be ignored? */
  38056. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38057. + return -EINVAL;
  38058. +
  38059. + /* Is the CBW valid? */
  38060. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  38061. + cbw->Signature != cpu_to_le32(
  38062. + US_BULK_CB_SIGN)) {
  38063. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  38064. + req->actual,
  38065. + le32_to_cpu(cbw->Signature));
  38066. +
  38067. + /* The Bulk-only spec says we MUST stall the IN endpoint
  38068. + * (6.6.1), so it's unavoidable. It also says we must
  38069. + * retain this state until the next reset, but there's
  38070. + * no way to tell the controller driver it should ignore
  38071. + * Clear-Feature(HALT) requests.
  38072. + *
  38073. + * We aren't required to halt the OUT endpoint; instead
  38074. + * we can simply accept and discard any data received
  38075. + * until the next reset. */
  38076. + wedge_bulk_in_endpoint(fsg);
  38077. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38078. + return -EINVAL;
  38079. + }
  38080. +
  38081. + /* Is the CBW meaningful? */
  38082. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  38083. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  38084. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  38085. + "cmdlen %u\n",
  38086. + cbw->Lun, cbw->Flags, cbw->Length);
  38087. +
  38088. + /* We can do anything we want here, so let's stall the
  38089. + * bulk pipes if we are allowed to. */
  38090. + if (mod_data.can_stall) {
  38091. + fsg_set_halt(fsg, fsg->bulk_out);
  38092. + halt_bulk_in_endpoint(fsg);
  38093. + }
  38094. + return -EINVAL;
  38095. + }
  38096. +
  38097. + /* Save the command for later */
  38098. + fsg->cmnd_size = cbw->Length;
  38099. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  38100. + if (cbw->Flags & US_BULK_FLAG_IN)
  38101. + fsg->data_dir = DATA_DIR_TO_HOST;
  38102. + else
  38103. + fsg->data_dir = DATA_DIR_FROM_HOST;
  38104. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  38105. + if (fsg->data_size == 0)
  38106. + fsg->data_dir = DATA_DIR_NONE;
  38107. + fsg->lun = cbw->Lun;
  38108. + fsg->tag = cbw->Tag;
  38109. + return 0;
  38110. +}
  38111. +
  38112. +
  38113. +static int get_next_command(struct fsg_dev *fsg)
  38114. +{
  38115. + struct fsg_buffhd *bh;
  38116. + int rc = 0;
  38117. +
  38118. + if (transport_is_bbb()) {
  38119. +
  38120. + /* Wait for the next buffer to become available */
  38121. + bh = fsg->next_buffhd_to_fill;
  38122. + while (bh->state != BUF_STATE_EMPTY) {
  38123. + rc = sleep_thread(fsg);
  38124. + if (rc)
  38125. + return rc;
  38126. + }
  38127. +
  38128. + /* Queue a request to read a Bulk-only CBW */
  38129. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  38130. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  38131. + &bh->outreq_busy, &bh->state);
  38132. +
  38133. + /* We will drain the buffer in software, which means we
  38134. + * can reuse it for the next filling. No need to advance
  38135. + * next_buffhd_to_fill. */
  38136. +
  38137. + /* Wait for the CBW to arrive */
  38138. + while (bh->state != BUF_STATE_FULL) {
  38139. + rc = sleep_thread(fsg);
  38140. + if (rc)
  38141. + return rc;
  38142. + }
  38143. + smp_rmb();
  38144. + rc = received_cbw(fsg, bh);
  38145. + bh->state = BUF_STATE_EMPTY;
  38146. +
  38147. + } else { // USB_PR_CB or USB_PR_CBI
  38148. +
  38149. + /* Wait for the next command to arrive */
  38150. + while (fsg->cbbuf_cmnd_size == 0) {
  38151. + rc = sleep_thread(fsg);
  38152. + if (rc)
  38153. + return rc;
  38154. + }
  38155. +
  38156. + /* Is the previous status interrupt request still busy?
  38157. + * The host is allowed to skip reading the status,
  38158. + * so we must cancel it. */
  38159. + if (fsg->intreq_busy)
  38160. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38161. +
  38162. + /* Copy the command and mark the buffer empty */
  38163. + fsg->data_dir = DATA_DIR_UNKNOWN;
  38164. + spin_lock_irq(&fsg->lock);
  38165. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  38166. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  38167. + fsg->cbbuf_cmnd_size = 0;
  38168. + spin_unlock_irq(&fsg->lock);
  38169. +
  38170. + /* Use LUN from the command */
  38171. + fsg->lun = fsg->cmnd[1] >> 5;
  38172. + }
  38173. +
  38174. + /* Update current lun */
  38175. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  38176. + fsg->curlun = &fsg->luns[fsg->lun];
  38177. + else
  38178. + fsg->curlun = NULL;
  38179. +
  38180. + return rc;
  38181. +}
  38182. +
  38183. +
  38184. +/*-------------------------------------------------------------------------*/
  38185. +
  38186. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  38187. + const struct usb_endpoint_descriptor *d)
  38188. +{
  38189. + int rc;
  38190. +
  38191. + ep->driver_data = fsg;
  38192. + ep->desc = d;
  38193. + rc = usb_ep_enable(ep);
  38194. + if (rc)
  38195. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  38196. + return rc;
  38197. +}
  38198. +
  38199. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  38200. + struct usb_request **preq)
  38201. +{
  38202. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  38203. + if (*preq)
  38204. + return 0;
  38205. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  38206. + return -ENOMEM;
  38207. +}
  38208. +
  38209. +/*
  38210. + * Reset interface setting and re-init endpoint state (toggle etc).
  38211. + * Call with altsetting < 0 to disable the interface. The only other
  38212. + * available altsetting is 0, which enables the interface.
  38213. + */
  38214. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  38215. +{
  38216. + int rc = 0;
  38217. + int i;
  38218. + const struct usb_endpoint_descriptor *d;
  38219. +
  38220. + if (fsg->running)
  38221. + DBG(fsg, "reset interface\n");
  38222. +
  38223. +reset:
  38224. + /* Deallocate the requests */
  38225. + for (i = 0; i < fsg_num_buffers; ++i) {
  38226. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38227. +
  38228. + if (bh->inreq) {
  38229. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  38230. + bh->inreq = NULL;
  38231. + }
  38232. + if (bh->outreq) {
  38233. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  38234. + bh->outreq = NULL;
  38235. + }
  38236. + }
  38237. + if (fsg->intreq) {
  38238. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  38239. + fsg->intreq = NULL;
  38240. + }
  38241. +
  38242. + /* Disable the endpoints */
  38243. + if (fsg->bulk_in_enabled) {
  38244. + usb_ep_disable(fsg->bulk_in);
  38245. + fsg->bulk_in_enabled = 0;
  38246. + }
  38247. + if (fsg->bulk_out_enabled) {
  38248. + usb_ep_disable(fsg->bulk_out);
  38249. + fsg->bulk_out_enabled = 0;
  38250. + }
  38251. + if (fsg->intr_in_enabled) {
  38252. + usb_ep_disable(fsg->intr_in);
  38253. + fsg->intr_in_enabled = 0;
  38254. + }
  38255. +
  38256. + fsg->running = 0;
  38257. + if (altsetting < 0 || rc != 0)
  38258. + return rc;
  38259. +
  38260. + DBG(fsg, "set interface %d\n", altsetting);
  38261. +
  38262. + /* Enable the endpoints */
  38263. + d = fsg_ep_desc(fsg->gadget,
  38264. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  38265. + &fsg_ss_bulk_in_desc);
  38266. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  38267. + goto reset;
  38268. + fsg->bulk_in_enabled = 1;
  38269. +
  38270. + d = fsg_ep_desc(fsg->gadget,
  38271. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  38272. + &fsg_ss_bulk_out_desc);
  38273. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  38274. + goto reset;
  38275. + fsg->bulk_out_enabled = 1;
  38276. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  38277. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38278. +
  38279. + if (transport_is_cbi()) {
  38280. + d = fsg_ep_desc(fsg->gadget,
  38281. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  38282. + &fsg_ss_intr_in_desc);
  38283. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  38284. + goto reset;
  38285. + fsg->intr_in_enabled = 1;
  38286. + }
  38287. +
  38288. + /* Allocate the requests */
  38289. + for (i = 0; i < fsg_num_buffers; ++i) {
  38290. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38291. +
  38292. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  38293. + goto reset;
  38294. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  38295. + goto reset;
  38296. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  38297. + bh->inreq->context = bh->outreq->context = bh;
  38298. + bh->inreq->complete = bulk_in_complete;
  38299. + bh->outreq->complete = bulk_out_complete;
  38300. + }
  38301. + if (transport_is_cbi()) {
  38302. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  38303. + goto reset;
  38304. + fsg->intreq->complete = intr_in_complete;
  38305. + }
  38306. +
  38307. + fsg->running = 1;
  38308. + for (i = 0; i < fsg->nluns; ++i)
  38309. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  38310. + return rc;
  38311. +}
  38312. +
  38313. +
  38314. +/*
  38315. + * Change our operational configuration. This code must agree with the code
  38316. + * that returns config descriptors, and with interface altsetting code.
  38317. + *
  38318. + * It's also responsible for power management interactions. Some
  38319. + * configurations might not work with our current power sources.
  38320. + * For now we just assume the gadget is always self-powered.
  38321. + */
  38322. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  38323. +{
  38324. + int rc = 0;
  38325. +
  38326. + /* Disable the single interface */
  38327. + if (fsg->config != 0) {
  38328. + DBG(fsg, "reset config\n");
  38329. + fsg->config = 0;
  38330. + rc = do_set_interface(fsg, -1);
  38331. + }
  38332. +
  38333. + /* Enable the interface */
  38334. + if (new_config != 0) {
  38335. + fsg->config = new_config;
  38336. + if ((rc = do_set_interface(fsg, 0)) != 0)
  38337. + fsg->config = 0; // Reset on errors
  38338. + else
  38339. + INFO(fsg, "%s config #%d\n",
  38340. + usb_speed_string(fsg->gadget->speed),
  38341. + fsg->config);
  38342. + }
  38343. + return rc;
  38344. +}
  38345. +
  38346. +
  38347. +/*-------------------------------------------------------------------------*/
  38348. +
  38349. +static void handle_exception(struct fsg_dev *fsg)
  38350. +{
  38351. + siginfo_t info;
  38352. + int sig;
  38353. + int i;
  38354. + int num_active;
  38355. + struct fsg_buffhd *bh;
  38356. + enum fsg_state old_state;
  38357. + u8 new_config;
  38358. + struct fsg_lun *curlun;
  38359. + unsigned int exception_req_tag;
  38360. + int rc;
  38361. +
  38362. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  38363. + * into a high-priority EXIT exception. */
  38364. + for (;;) {
  38365. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  38366. + if (!sig)
  38367. + break;
  38368. + if (sig != SIGUSR1) {
  38369. + if (fsg->state < FSG_STATE_EXIT)
  38370. + DBG(fsg, "Main thread exiting on signal\n");
  38371. + raise_exception(fsg, FSG_STATE_EXIT);
  38372. + }
  38373. + }
  38374. +
  38375. + /* Cancel all the pending transfers */
  38376. + if (fsg->intreq_busy)
  38377. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38378. + for (i = 0; i < fsg_num_buffers; ++i) {
  38379. + bh = &fsg->buffhds[i];
  38380. + if (bh->inreq_busy)
  38381. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  38382. + if (bh->outreq_busy)
  38383. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  38384. + }
  38385. +
  38386. + /* Wait until everything is idle */
  38387. + for (;;) {
  38388. + num_active = fsg->intreq_busy;
  38389. + for (i = 0; i < fsg_num_buffers; ++i) {
  38390. + bh = &fsg->buffhds[i];
  38391. + num_active += bh->inreq_busy + bh->outreq_busy;
  38392. + }
  38393. + if (num_active == 0)
  38394. + break;
  38395. + if (sleep_thread(fsg))
  38396. + return;
  38397. + }
  38398. +
  38399. + /* Clear out the controller's fifos */
  38400. + if (fsg->bulk_in_enabled)
  38401. + usb_ep_fifo_flush(fsg->bulk_in);
  38402. + if (fsg->bulk_out_enabled)
  38403. + usb_ep_fifo_flush(fsg->bulk_out);
  38404. + if (fsg->intr_in_enabled)
  38405. + usb_ep_fifo_flush(fsg->intr_in);
  38406. +
  38407. + /* Reset the I/O buffer states and pointers, the SCSI
  38408. + * state, and the exception. Then invoke the handler. */
  38409. + spin_lock_irq(&fsg->lock);
  38410. +
  38411. + for (i = 0; i < fsg_num_buffers; ++i) {
  38412. + bh = &fsg->buffhds[i];
  38413. + bh->state = BUF_STATE_EMPTY;
  38414. + }
  38415. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  38416. + &fsg->buffhds[0];
  38417. +
  38418. + exception_req_tag = fsg->exception_req_tag;
  38419. + new_config = fsg->new_config;
  38420. + old_state = fsg->state;
  38421. +
  38422. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  38423. + fsg->state = FSG_STATE_STATUS_PHASE;
  38424. + else {
  38425. + for (i = 0; i < fsg->nluns; ++i) {
  38426. + curlun = &fsg->luns[i];
  38427. + curlun->prevent_medium_removal = 0;
  38428. + curlun->sense_data = curlun->unit_attention_data =
  38429. + SS_NO_SENSE;
  38430. + curlun->sense_data_info = 0;
  38431. + curlun->info_valid = 0;
  38432. + }
  38433. + fsg->state = FSG_STATE_IDLE;
  38434. + }
  38435. + spin_unlock_irq(&fsg->lock);
  38436. +
  38437. + /* Carry out any extra actions required for the exception */
  38438. + switch (old_state) {
  38439. + default:
  38440. + break;
  38441. +
  38442. + case FSG_STATE_ABORT_BULK_OUT:
  38443. + send_status(fsg);
  38444. + spin_lock_irq(&fsg->lock);
  38445. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  38446. + fsg->state = FSG_STATE_IDLE;
  38447. + spin_unlock_irq(&fsg->lock);
  38448. + break;
  38449. +
  38450. + case FSG_STATE_RESET:
  38451. + /* In case we were forced against our will to halt a
  38452. + * bulk endpoint, clear the halt now. (The SuperH UDC
  38453. + * requires this.) */
  38454. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38455. + usb_ep_clear_halt(fsg->bulk_in);
  38456. +
  38457. + if (transport_is_bbb()) {
  38458. + if (fsg->ep0_req_tag == exception_req_tag)
  38459. + ep0_queue(fsg); // Complete the status stage
  38460. +
  38461. + } else if (transport_is_cbi())
  38462. + send_status(fsg); // Status by interrupt pipe
  38463. +
  38464. + /* Technically this should go here, but it would only be
  38465. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  38466. + * CONFIG_CHANGE cases. */
  38467. + // for (i = 0; i < fsg->nluns; ++i)
  38468. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  38469. + break;
  38470. +
  38471. + case FSG_STATE_INTERFACE_CHANGE:
  38472. + rc = do_set_interface(fsg, 0);
  38473. + if (fsg->ep0_req_tag != exception_req_tag)
  38474. + break;
  38475. + if (rc != 0) // STALL on errors
  38476. + fsg_set_halt(fsg, fsg->ep0);
  38477. + else // Complete the status stage
  38478. + ep0_queue(fsg);
  38479. + break;
  38480. +
  38481. + case FSG_STATE_CONFIG_CHANGE:
  38482. + rc = do_set_config(fsg, new_config);
  38483. + if (fsg->ep0_req_tag != exception_req_tag)
  38484. + break;
  38485. + if (rc != 0) // STALL on errors
  38486. + fsg_set_halt(fsg, fsg->ep0);
  38487. + else // Complete the status stage
  38488. + ep0_queue(fsg);
  38489. + break;
  38490. +
  38491. + case FSG_STATE_DISCONNECT:
  38492. + for (i = 0; i < fsg->nluns; ++i)
  38493. + fsg_lun_fsync_sub(fsg->luns + i);
  38494. + do_set_config(fsg, 0); // Unconfigured state
  38495. + break;
  38496. +
  38497. + case FSG_STATE_EXIT:
  38498. + case FSG_STATE_TERMINATED:
  38499. + do_set_config(fsg, 0); // Free resources
  38500. + spin_lock_irq(&fsg->lock);
  38501. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  38502. + spin_unlock_irq(&fsg->lock);
  38503. + break;
  38504. + }
  38505. +}
  38506. +
  38507. +
  38508. +/*-------------------------------------------------------------------------*/
  38509. +
  38510. +static int fsg_main_thread(void *fsg_)
  38511. +{
  38512. + struct fsg_dev *fsg = fsg_;
  38513. +
  38514. + /* Allow the thread to be killed by a signal, but set the signal mask
  38515. + * to block everything but INT, TERM, KILL, and USR1. */
  38516. + allow_signal(SIGINT);
  38517. + allow_signal(SIGTERM);
  38518. + allow_signal(SIGKILL);
  38519. + allow_signal(SIGUSR1);
  38520. +
  38521. + /* Allow the thread to be frozen */
  38522. + set_freezable();
  38523. +
  38524. + /* Arrange for userspace references to be interpreted as kernel
  38525. + * pointers. That way we can pass a kernel pointer to a routine
  38526. + * that expects a __user pointer and it will work okay. */
  38527. + set_fs(get_ds());
  38528. +
  38529. + /* The main loop */
  38530. + while (fsg->state != FSG_STATE_TERMINATED) {
  38531. + if (exception_in_progress(fsg) || signal_pending(current)) {
  38532. + handle_exception(fsg);
  38533. + continue;
  38534. + }
  38535. +
  38536. + if (!fsg->running) {
  38537. + sleep_thread(fsg);
  38538. + continue;
  38539. + }
  38540. +
  38541. + if (get_next_command(fsg))
  38542. + continue;
  38543. +
  38544. + spin_lock_irq(&fsg->lock);
  38545. + if (!exception_in_progress(fsg))
  38546. + fsg->state = FSG_STATE_DATA_PHASE;
  38547. + spin_unlock_irq(&fsg->lock);
  38548. +
  38549. + if (do_scsi_command(fsg) || finish_reply(fsg))
  38550. + continue;
  38551. +
  38552. + spin_lock_irq(&fsg->lock);
  38553. + if (!exception_in_progress(fsg))
  38554. + fsg->state = FSG_STATE_STATUS_PHASE;
  38555. + spin_unlock_irq(&fsg->lock);
  38556. +
  38557. + if (send_status(fsg))
  38558. + continue;
  38559. +
  38560. + spin_lock_irq(&fsg->lock);
  38561. + if (!exception_in_progress(fsg))
  38562. + fsg->state = FSG_STATE_IDLE;
  38563. + spin_unlock_irq(&fsg->lock);
  38564. + }
  38565. +
  38566. + spin_lock_irq(&fsg->lock);
  38567. + fsg->thread_task = NULL;
  38568. + spin_unlock_irq(&fsg->lock);
  38569. +
  38570. + /* If we are exiting because of a signal, unregister the
  38571. + * gadget driver. */
  38572. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38573. + usb_gadget_unregister_driver(&fsg_driver);
  38574. +
  38575. + /* Let the unbind and cleanup routines know the thread has exited */
  38576. + complete_and_exit(&fsg->thread_notifier, 0);
  38577. +}
  38578. +
  38579. +
  38580. +/*-------------------------------------------------------------------------*/
  38581. +
  38582. +
  38583. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  38584. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  38585. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  38586. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  38587. +
  38588. +
  38589. +/*-------------------------------------------------------------------------*/
  38590. +
  38591. +static void fsg_release(struct kref *ref)
  38592. +{
  38593. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  38594. +
  38595. + kfree(fsg->luns);
  38596. + kfree(fsg);
  38597. +}
  38598. +
  38599. +static void lun_release(struct device *dev)
  38600. +{
  38601. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  38602. + struct fsg_dev *fsg =
  38603. + container_of(filesem, struct fsg_dev, filesem);
  38604. +
  38605. + kref_put(&fsg->ref, fsg_release);
  38606. +}
  38607. +
  38608. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  38609. +{
  38610. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38611. + int i;
  38612. + struct fsg_lun *curlun;
  38613. + struct usb_request *req = fsg->ep0req;
  38614. +
  38615. + DBG(fsg, "unbind\n");
  38616. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  38617. +
  38618. + /* If the thread isn't already dead, tell it to exit now */
  38619. + if (fsg->state != FSG_STATE_TERMINATED) {
  38620. + raise_exception(fsg, FSG_STATE_EXIT);
  38621. + wait_for_completion(&fsg->thread_notifier);
  38622. +
  38623. + /* The cleanup routine waits for this completion also */
  38624. + complete(&fsg->thread_notifier);
  38625. + }
  38626. +
  38627. + /* Unregister the sysfs attribute files and the LUNs */
  38628. + for (i = 0; i < fsg->nluns; ++i) {
  38629. + curlun = &fsg->luns[i];
  38630. + if (curlun->registered) {
  38631. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  38632. + device_remove_file(&curlun->dev, &dev_attr_ro);
  38633. + device_remove_file(&curlun->dev, &dev_attr_file);
  38634. + fsg_lun_close(curlun);
  38635. + device_unregister(&curlun->dev);
  38636. + curlun->registered = 0;
  38637. + }
  38638. + }
  38639. +
  38640. + /* Free the data buffers */
  38641. + for (i = 0; i < fsg_num_buffers; ++i)
  38642. + kfree(fsg->buffhds[i].buf);
  38643. +
  38644. + /* Free the request and buffer for endpoint 0 */
  38645. + if (req) {
  38646. + kfree(req->buf);
  38647. + usb_ep_free_request(fsg->ep0, req);
  38648. + }
  38649. +
  38650. + set_gadget_data(gadget, NULL);
  38651. +}
  38652. +
  38653. +
  38654. +static int __init check_parameters(struct fsg_dev *fsg)
  38655. +{
  38656. + int prot;
  38657. + int gcnum;
  38658. +
  38659. + /* Store the default values */
  38660. + mod_data.transport_type = USB_PR_BULK;
  38661. + mod_data.transport_name = "Bulk-only";
  38662. + mod_data.protocol_type = USB_SC_SCSI;
  38663. + mod_data.protocol_name = "Transparent SCSI";
  38664. +
  38665. + /* Some peripheral controllers are known not to be able to
  38666. + * halt bulk endpoints correctly. If one of them is present,
  38667. + * disable stalls.
  38668. + */
  38669. + if (gadget_is_at91(fsg->gadget))
  38670. + mod_data.can_stall = 0;
  38671. +
  38672. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  38673. + gcnum = usb_gadget_controller_number(fsg->gadget);
  38674. + if (gcnum >= 0)
  38675. + mod_data.release = 0x0300 + gcnum;
  38676. + else {
  38677. + WARNING(fsg, "controller '%s' not recognized\n",
  38678. + fsg->gadget->name);
  38679. + mod_data.release = 0x0399;
  38680. + }
  38681. + }
  38682. +
  38683. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  38684. +
  38685. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  38686. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  38687. + ; // Use default setting
  38688. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  38689. + mod_data.transport_type = USB_PR_CB;
  38690. + mod_data.transport_name = "Control-Bulk";
  38691. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  38692. + mod_data.transport_type = USB_PR_CBI;
  38693. + mod_data.transport_name = "Control-Bulk-Interrupt";
  38694. + } else {
  38695. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  38696. + return -EINVAL;
  38697. + }
  38698. +
  38699. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  38700. + prot == USB_SC_SCSI) {
  38701. + ; // Use default setting
  38702. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  38703. + prot == USB_SC_RBC) {
  38704. + mod_data.protocol_type = USB_SC_RBC;
  38705. + mod_data.protocol_name = "RBC";
  38706. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  38707. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  38708. + prot == USB_SC_8020) {
  38709. + mod_data.protocol_type = USB_SC_8020;
  38710. + mod_data.protocol_name = "8020i (ATAPI)";
  38711. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  38712. + prot == USB_SC_QIC) {
  38713. + mod_data.protocol_type = USB_SC_QIC;
  38714. + mod_data.protocol_name = "QIC-157";
  38715. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  38716. + prot == USB_SC_UFI) {
  38717. + mod_data.protocol_type = USB_SC_UFI;
  38718. + mod_data.protocol_name = "UFI";
  38719. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  38720. + prot == USB_SC_8070) {
  38721. + mod_data.protocol_type = USB_SC_8070;
  38722. + mod_data.protocol_name = "8070i";
  38723. + } else {
  38724. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  38725. + return -EINVAL;
  38726. + }
  38727. +
  38728. + mod_data.buflen &= PAGE_CACHE_MASK;
  38729. + if (mod_data.buflen <= 0) {
  38730. + ERROR(fsg, "invalid buflen\n");
  38731. + return -ETOOSMALL;
  38732. + }
  38733. +
  38734. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  38735. +
  38736. + /* Serial string handling.
  38737. + * On a real device, the serial string would be loaded
  38738. + * from permanent storage. */
  38739. + if (mod_data.serial) {
  38740. + const char *ch;
  38741. + unsigned len = 0;
  38742. +
  38743. + /* Sanity check :
  38744. + * The CB[I] specification limits the serial string to
  38745. + * 12 uppercase hexadecimal characters.
  38746. + * BBB need at least 12 uppercase hexadecimal characters,
  38747. + * with a maximum of 126. */
  38748. + for (ch = mod_data.serial; *ch; ++ch) {
  38749. + ++len;
  38750. + if ((*ch < '0' || *ch > '9') &&
  38751. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  38752. + WARNING(fsg,
  38753. + "Invalid serial string character: %c\n",
  38754. + *ch);
  38755. + goto no_serial;
  38756. + }
  38757. + }
  38758. + if (len > 126 ||
  38759. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  38760. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  38761. + WARNING(fsg, "Invalid serial string length!\n");
  38762. + goto no_serial;
  38763. + }
  38764. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  38765. + } else {
  38766. + WARNING(fsg, "No serial-number string provided!\n");
  38767. + no_serial:
  38768. + device_desc.iSerialNumber = 0;
  38769. + }
  38770. +
  38771. + return 0;
  38772. +}
  38773. +
  38774. +
  38775. +static int __init fsg_bind(struct usb_gadget *gadget)
  38776. +{
  38777. + struct fsg_dev *fsg = the_fsg;
  38778. + int rc;
  38779. + int i;
  38780. + struct fsg_lun *curlun;
  38781. + struct usb_ep *ep;
  38782. + struct usb_request *req;
  38783. + char *pathbuf, *p;
  38784. +
  38785. + fsg->gadget = gadget;
  38786. + set_gadget_data(gadget, fsg);
  38787. + fsg->ep0 = gadget->ep0;
  38788. + fsg->ep0->driver_data = fsg;
  38789. +
  38790. + if ((rc = check_parameters(fsg)) != 0)
  38791. + goto out;
  38792. +
  38793. + if (mod_data.removable) { // Enable the store_xxx attributes
  38794. + dev_attr_file.attr.mode = 0644;
  38795. + dev_attr_file.store = fsg_store_file;
  38796. + if (!mod_data.cdrom) {
  38797. + dev_attr_ro.attr.mode = 0644;
  38798. + dev_attr_ro.store = fsg_store_ro;
  38799. + }
  38800. + }
  38801. +
  38802. + /* Only for removable media? */
  38803. + dev_attr_nofua.attr.mode = 0644;
  38804. + dev_attr_nofua.store = fsg_store_nofua;
  38805. +
  38806. + /* Find out how many LUNs there should be */
  38807. + i = mod_data.nluns;
  38808. + if (i == 0)
  38809. + i = max(mod_data.num_filenames, 1u);
  38810. + if (i > FSG_MAX_LUNS) {
  38811. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  38812. + rc = -EINVAL;
  38813. + goto out;
  38814. + }
  38815. +
  38816. + /* Create the LUNs, open their backing files, and register the
  38817. + * LUN devices in sysfs. */
  38818. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  38819. + if (!fsg->luns) {
  38820. + rc = -ENOMEM;
  38821. + goto out;
  38822. + }
  38823. + fsg->nluns = i;
  38824. +
  38825. + for (i = 0; i < fsg->nluns; ++i) {
  38826. + curlun = &fsg->luns[i];
  38827. + curlun->cdrom = !!mod_data.cdrom;
  38828. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  38829. + curlun->initially_ro = curlun->ro;
  38830. + curlun->removable = mod_data.removable;
  38831. + curlun->nofua = mod_data.nofua[i];
  38832. + curlun->dev.release = lun_release;
  38833. + curlun->dev.parent = &gadget->dev;
  38834. + curlun->dev.driver = &fsg_driver.driver;
  38835. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  38836. + dev_set_name(&curlun->dev,"%s-lun%d",
  38837. + dev_name(&gadget->dev), i);
  38838. +
  38839. + kref_get(&fsg->ref);
  38840. + rc = device_register(&curlun->dev);
  38841. + if (rc) {
  38842. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  38843. + put_device(&curlun->dev);
  38844. + goto out;
  38845. + }
  38846. + curlun->registered = 1;
  38847. +
  38848. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  38849. + if (rc)
  38850. + goto out;
  38851. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  38852. + if (rc)
  38853. + goto out;
  38854. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  38855. + if (rc)
  38856. + goto out;
  38857. +
  38858. + if (mod_data.file[i] && *mod_data.file[i]) {
  38859. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  38860. + if (rc)
  38861. + goto out;
  38862. + } else if (!mod_data.removable) {
  38863. + ERROR(fsg, "no file given for LUN%d\n", i);
  38864. + rc = -EINVAL;
  38865. + goto out;
  38866. + }
  38867. + }
  38868. +
  38869. + /* Find all the endpoints we will use */
  38870. + usb_ep_autoconfig_reset(gadget);
  38871. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  38872. + if (!ep)
  38873. + goto autoconf_fail;
  38874. + ep->driver_data = fsg; // claim the endpoint
  38875. + fsg->bulk_in = ep;
  38876. +
  38877. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  38878. + if (!ep)
  38879. + goto autoconf_fail;
  38880. + ep->driver_data = fsg; // claim the endpoint
  38881. + fsg->bulk_out = ep;
  38882. +
  38883. + if (transport_is_cbi()) {
  38884. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  38885. + if (!ep)
  38886. + goto autoconf_fail;
  38887. + ep->driver_data = fsg; // claim the endpoint
  38888. + fsg->intr_in = ep;
  38889. + }
  38890. +
  38891. + /* Fix up the descriptors */
  38892. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  38893. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  38894. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  38895. +
  38896. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  38897. + fsg_intf_desc.bNumEndpoints = i;
  38898. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  38899. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  38900. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38901. +
  38902. + if (gadget_is_dualspeed(gadget)) {
  38903. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38904. +
  38905. + /* Assume endpoint addresses are the same for both speeds */
  38906. + fsg_hs_bulk_in_desc.bEndpointAddress =
  38907. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38908. + fsg_hs_bulk_out_desc.bEndpointAddress =
  38909. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38910. + fsg_hs_intr_in_desc.bEndpointAddress =
  38911. + fsg_fs_intr_in_desc.bEndpointAddress;
  38912. + }
  38913. +
  38914. + if (gadget_is_superspeed(gadget)) {
  38915. + unsigned max_burst;
  38916. +
  38917. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38918. +
  38919. + /* Calculate bMaxBurst, we know packet size is 1024 */
  38920. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  38921. +
  38922. + /* Assume endpoint addresses are the same for both speeds */
  38923. + fsg_ss_bulk_in_desc.bEndpointAddress =
  38924. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38925. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  38926. +
  38927. + fsg_ss_bulk_out_desc.bEndpointAddress =
  38928. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38929. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  38930. + }
  38931. +
  38932. + if (gadget_is_otg(gadget))
  38933. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  38934. +
  38935. + rc = -ENOMEM;
  38936. +
  38937. + /* Allocate the request and buffer for endpoint 0 */
  38938. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  38939. + if (!req)
  38940. + goto out;
  38941. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  38942. + if (!req->buf)
  38943. + goto out;
  38944. + req->complete = ep0_complete;
  38945. +
  38946. + /* Allocate the data buffers */
  38947. + for (i = 0; i < fsg_num_buffers; ++i) {
  38948. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38949. +
  38950. + /* Allocate for the bulk-in endpoint. We assume that
  38951. + * the buffer will also work with the bulk-out (and
  38952. + * interrupt-in) endpoint. */
  38953. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  38954. + if (!bh->buf)
  38955. + goto out;
  38956. + bh->next = bh + 1;
  38957. + }
  38958. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  38959. +
  38960. + /* This should reflect the actual gadget power source */
  38961. + usb_gadget_set_selfpowered(gadget);
  38962. +
  38963. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  38964. + "%s %s with %s",
  38965. + init_utsname()->sysname, init_utsname()->release,
  38966. + gadget->name);
  38967. +
  38968. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  38969. + "file-storage-gadget");
  38970. + if (IS_ERR(fsg->thread_task)) {
  38971. + rc = PTR_ERR(fsg->thread_task);
  38972. + goto out;
  38973. + }
  38974. +
  38975. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  38976. + INFO(fsg, "NOTE: This driver is deprecated. "
  38977. + "Consider using g_mass_storage instead.\n");
  38978. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  38979. +
  38980. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  38981. + for (i = 0; i < fsg->nluns; ++i) {
  38982. + curlun = &fsg->luns[i];
  38983. + if (fsg_lun_is_open(curlun)) {
  38984. + p = NULL;
  38985. + if (pathbuf) {
  38986. + p = d_path(&curlun->filp->f_path,
  38987. + pathbuf, PATH_MAX);
  38988. + if (IS_ERR(p))
  38989. + p = NULL;
  38990. + }
  38991. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  38992. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  38993. + }
  38994. + }
  38995. + kfree(pathbuf);
  38996. +
  38997. + DBG(fsg, "transport=%s (x%02x)\n",
  38998. + mod_data.transport_name, mod_data.transport_type);
  38999. + DBG(fsg, "protocol=%s (x%02x)\n",
  39000. + mod_data.protocol_name, mod_data.protocol_type);
  39001. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  39002. + mod_data.vendor, mod_data.product, mod_data.release);
  39003. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  39004. + mod_data.removable, mod_data.can_stall,
  39005. + mod_data.cdrom, mod_data.buflen);
  39006. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  39007. +
  39008. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  39009. +
  39010. + /* Tell the thread to start working */
  39011. + wake_up_process(fsg->thread_task);
  39012. + return 0;
  39013. +
  39014. +autoconf_fail:
  39015. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  39016. + rc = -ENOTSUPP;
  39017. +
  39018. +out:
  39019. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  39020. + fsg_unbind(gadget);
  39021. + complete(&fsg->thread_notifier);
  39022. + return rc;
  39023. +}
  39024. +
  39025. +
  39026. +/*-------------------------------------------------------------------------*/
  39027. +
  39028. +static void fsg_suspend(struct usb_gadget *gadget)
  39029. +{
  39030. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39031. +
  39032. + DBG(fsg, "suspend\n");
  39033. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  39034. +}
  39035. +
  39036. +static void fsg_resume(struct usb_gadget *gadget)
  39037. +{
  39038. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39039. +
  39040. + DBG(fsg, "resume\n");
  39041. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  39042. +}
  39043. +
  39044. +
  39045. +/*-------------------------------------------------------------------------*/
  39046. +
  39047. +static struct usb_gadget_driver fsg_driver = {
  39048. + .max_speed = USB_SPEED_SUPER,
  39049. + .function = (char *) fsg_string_product,
  39050. + .unbind = fsg_unbind,
  39051. + .disconnect = fsg_disconnect,
  39052. + .setup = fsg_setup,
  39053. + .suspend = fsg_suspend,
  39054. + .resume = fsg_resume,
  39055. +
  39056. + .driver = {
  39057. + .name = DRIVER_NAME,
  39058. + .owner = THIS_MODULE,
  39059. + // .release = ...
  39060. + // .suspend = ...
  39061. + // .resume = ...
  39062. + },
  39063. +};
  39064. +
  39065. +
  39066. +static int __init fsg_alloc(void)
  39067. +{
  39068. + struct fsg_dev *fsg;
  39069. +
  39070. + fsg = kzalloc(sizeof *fsg +
  39071. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  39072. +
  39073. + if (!fsg)
  39074. + return -ENOMEM;
  39075. + spin_lock_init(&fsg->lock);
  39076. + init_rwsem(&fsg->filesem);
  39077. + kref_init(&fsg->ref);
  39078. + init_completion(&fsg->thread_notifier);
  39079. +
  39080. + the_fsg = fsg;
  39081. + return 0;
  39082. +}
  39083. +
  39084. +
  39085. +static int __init fsg_init(void)
  39086. +{
  39087. + int rc;
  39088. + struct fsg_dev *fsg;
  39089. +
  39090. + rc = fsg_num_buffers_validate();
  39091. + if (rc != 0)
  39092. + return rc;
  39093. +
  39094. + if ((rc = fsg_alloc()) != 0)
  39095. + return rc;
  39096. + fsg = the_fsg;
  39097. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  39098. + kref_put(&fsg->ref, fsg_release);
  39099. + return rc;
  39100. +}
  39101. +module_init(fsg_init);
  39102. +
  39103. +
  39104. +static void __exit fsg_cleanup(void)
  39105. +{
  39106. + struct fsg_dev *fsg = the_fsg;
  39107. +
  39108. + /* Unregister the driver iff the thread hasn't already done so */
  39109. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  39110. + usb_gadget_unregister_driver(&fsg_driver);
  39111. +
  39112. + /* Wait for the thread to finish up */
  39113. + wait_for_completion(&fsg->thread_notifier);
  39114. +
  39115. + kref_put(&fsg->ref, fsg_release);
  39116. +}
  39117. +module_exit(fsg_cleanup);
  39118. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/changes.txt linux-raspberry-pi/drivers/usb/host/dwc_common_port/changes.txt
  39119. --- linux-3.10.33/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  39120. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/changes.txt 2014-03-13 12:46:38.980096914 +0100
  39121. @@ -0,0 +1,174 @@
  39122. +
  39123. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  39124. +IO context struct. The IO context struct should live in an os-dependent struct
  39125. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  39126. +named 'os_dep' embedded in the main device struct. So there these calls look
  39127. +like this:
  39128. +
  39129. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  39130. +
  39131. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  39132. + &pcd->dev_global_regs->dcfg, 0);
  39133. +
  39134. +Note that for the existing Linux driver ports, it is not necessary to actually
  39135. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  39136. +require an IO context, its macros for dwc_read_reg32() and friends do not
  39137. +use the context pointer, so it is optimized away by the compiler. But it is
  39138. +necessary to add the pointer parameter to all of the call sites, to be ready
  39139. +for any future ports (such as FreeBSD) which do require an IO context.
  39140. +
  39141. +
  39142. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  39143. +take an additional parameter, a pointer to a memory context. Examples:
  39144. +
  39145. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  39146. +
  39147. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  39148. +
  39149. +Again, for the Linux ports, it is not necessary to actually define the memctx
  39150. +member, but it is necessary to add the pointer parameter to all of the call
  39151. +sites.
  39152. +
  39153. +
  39154. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  39155. +
  39156. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  39157. +
  39158. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  39159. +
  39160. +
  39161. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  39162. +
  39163. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  39164. +
  39165. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  39166. +
  39167. +
  39168. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  39169. +
  39170. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  39171. +
  39172. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  39173. +
  39174. +
  39175. +Same for dwc_timer_alloc(). Example:
  39176. +
  39177. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  39178. + cb_func, cb_data);
  39179. +
  39180. +
  39181. +Same for dwc_waitq_alloc(). Example:
  39182. +
  39183. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  39184. +
  39185. +
  39186. +Same for dwc_thread_run(). Example:
  39187. +
  39188. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  39189. + "dwc_usb3_thd1", data);
  39190. +
  39191. +
  39192. +Same for dwc_workq_alloc(). Example:
  39193. +
  39194. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  39195. +
  39196. +
  39197. +Same for dwc_task_alloc(). Example:
  39198. +
  39199. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  39200. + cb_func, cb_data);
  39201. +
  39202. +
  39203. +In addition to the context pointer additions, a few core functions have had
  39204. +other changes made to their parameters:
  39205. +
  39206. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  39207. +has been changed from a uint64_t to a dwc_irqflags_t.
  39208. +
  39209. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  39210. +FreeBSD equivalent of that function requires it.
  39211. +
  39212. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  39213. +'char *name' parameter, to be consistent with dwc_thread_run() and
  39214. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  39215. +requires a unique name.
  39216. +
  39217. +
  39218. +Here is a complete list of the core functions that now take a pointer to a
  39219. +context as their first parameter:
  39220. +
  39221. + dwc_read_reg32
  39222. + dwc_read_reg64
  39223. + dwc_write_reg32
  39224. + dwc_write_reg64
  39225. + dwc_modify_reg32
  39226. + dwc_modify_reg64
  39227. + dwc_alloc
  39228. + dwc_alloc_atomic
  39229. + dwc_strdup
  39230. + dwc_free
  39231. + dwc_dma_alloc
  39232. + dwc_dma_free
  39233. + dwc_mutex_alloc
  39234. + dwc_mutex_free
  39235. + dwc_spinlock_alloc
  39236. + dwc_spinlock_free
  39237. + dwc_timer_alloc
  39238. + dwc_waitq_alloc
  39239. + dwc_thread_run
  39240. + dwc_workq_alloc
  39241. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  39242. +
  39243. +And here are the core functions that have other changes to their parameters:
  39244. +
  39245. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  39246. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  39247. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  39248. +
  39249. +
  39250. +
  39251. +The changes to the core functions also require some of the other library
  39252. +functions to change:
  39253. +
  39254. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  39255. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  39256. + (for mutex allocation) as the 2nd param.
  39257. +
  39258. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  39259. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  39260. + 'void *memctx' as the 1st param.
  39261. +
  39262. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  39263. + 'void *memctx' as the 1st param.
  39264. +
  39265. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  39266. +
  39267. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  39268. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  39269. + param, and also now returns an integer value that is non-zero if
  39270. + allocation of its data structures or work queue fails.
  39271. +
  39272. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  39273. +
  39274. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  39275. + param, and also now returns an integer value that is non-zero if
  39276. + allocation of its data structures fails.
  39277. +
  39278. +
  39279. +
  39280. +Other miscellaneous changes:
  39281. +
  39282. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  39283. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  39284. +
  39285. +The following #define's have been added to allow selectively compiling library
  39286. +features:
  39287. +
  39288. + DWC_CCLIB
  39289. + DWC_CRYPTOLIB
  39290. + DWC_NOTIFYLIB
  39291. + DWC_UTFLIB
  39292. +
  39293. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  39294. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  39295. +library code directly into a driver module, instead of as a standalone module.
  39296. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-raspberry-pi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  39297. --- linux-3.10.33/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  39298. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-03-13 12:46:39.096097148 +0100
  39299. @@ -0,0 +1,270 @@
  39300. +# Doxyfile 1.4.5
  39301. +
  39302. +#---------------------------------------------------------------------------
  39303. +# Project related configuration options
  39304. +#---------------------------------------------------------------------------
  39305. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  39306. +PROJECT_NUMBER =
  39307. +OUTPUT_DIRECTORY = doc
  39308. +CREATE_SUBDIRS = NO
  39309. +OUTPUT_LANGUAGE = English
  39310. +BRIEF_MEMBER_DESC = YES
  39311. +REPEAT_BRIEF = YES
  39312. +ABBREVIATE_BRIEF = "The $name class" \
  39313. + "The $name widget" \
  39314. + "The $name file" \
  39315. + is \
  39316. + provides \
  39317. + specifies \
  39318. + contains \
  39319. + represents \
  39320. + a \
  39321. + an \
  39322. + the
  39323. +ALWAYS_DETAILED_SEC = YES
  39324. +INLINE_INHERITED_MEMB = NO
  39325. +FULL_PATH_NAMES = NO
  39326. +STRIP_FROM_PATH = ..
  39327. +STRIP_FROM_INC_PATH =
  39328. +SHORT_NAMES = NO
  39329. +JAVADOC_AUTOBRIEF = YES
  39330. +MULTILINE_CPP_IS_BRIEF = NO
  39331. +DETAILS_AT_TOP = YES
  39332. +INHERIT_DOCS = YES
  39333. +SEPARATE_MEMBER_PAGES = NO
  39334. +TAB_SIZE = 8
  39335. +ALIASES =
  39336. +OPTIMIZE_OUTPUT_FOR_C = YES
  39337. +OPTIMIZE_OUTPUT_JAVA = NO
  39338. +BUILTIN_STL_SUPPORT = NO
  39339. +DISTRIBUTE_GROUP_DOC = NO
  39340. +SUBGROUPING = NO
  39341. +#---------------------------------------------------------------------------
  39342. +# Build related configuration options
  39343. +#---------------------------------------------------------------------------
  39344. +EXTRACT_ALL = NO
  39345. +EXTRACT_PRIVATE = NO
  39346. +EXTRACT_STATIC = YES
  39347. +EXTRACT_LOCAL_CLASSES = NO
  39348. +EXTRACT_LOCAL_METHODS = NO
  39349. +HIDE_UNDOC_MEMBERS = NO
  39350. +HIDE_UNDOC_CLASSES = NO
  39351. +HIDE_FRIEND_COMPOUNDS = NO
  39352. +HIDE_IN_BODY_DOCS = NO
  39353. +INTERNAL_DOCS = NO
  39354. +CASE_SENSE_NAMES = YES
  39355. +HIDE_SCOPE_NAMES = NO
  39356. +SHOW_INCLUDE_FILES = NO
  39357. +INLINE_INFO = YES
  39358. +SORT_MEMBER_DOCS = NO
  39359. +SORT_BRIEF_DOCS = NO
  39360. +SORT_BY_SCOPE_NAME = NO
  39361. +GENERATE_TODOLIST = YES
  39362. +GENERATE_TESTLIST = YES
  39363. +GENERATE_BUGLIST = YES
  39364. +GENERATE_DEPRECATEDLIST= YES
  39365. +ENABLED_SECTIONS =
  39366. +MAX_INITIALIZER_LINES = 30
  39367. +SHOW_USED_FILES = YES
  39368. +SHOW_DIRECTORIES = YES
  39369. +FILE_VERSION_FILTER =
  39370. +#---------------------------------------------------------------------------
  39371. +# configuration options related to warning and progress messages
  39372. +#---------------------------------------------------------------------------
  39373. +QUIET = YES
  39374. +WARNINGS = YES
  39375. +WARN_IF_UNDOCUMENTED = NO
  39376. +WARN_IF_DOC_ERROR = YES
  39377. +WARN_NO_PARAMDOC = YES
  39378. +WARN_FORMAT = "$file:$line: $text"
  39379. +WARN_LOGFILE =
  39380. +#---------------------------------------------------------------------------
  39381. +# configuration options related to the input files
  39382. +#---------------------------------------------------------------------------
  39383. +INPUT = .
  39384. +FILE_PATTERNS = *.c \
  39385. + *.cc \
  39386. + *.cxx \
  39387. + *.cpp \
  39388. + *.c++ \
  39389. + *.d \
  39390. + *.java \
  39391. + *.ii \
  39392. + *.ixx \
  39393. + *.ipp \
  39394. + *.i++ \
  39395. + *.inl \
  39396. + *.h \
  39397. + *.hh \
  39398. + *.hxx \
  39399. + *.hpp \
  39400. + *.h++ \
  39401. + *.idl \
  39402. + *.odl \
  39403. + *.cs \
  39404. + *.php \
  39405. + *.php3 \
  39406. + *.inc \
  39407. + *.m \
  39408. + *.mm \
  39409. + *.dox \
  39410. + *.py \
  39411. + *.C \
  39412. + *.CC \
  39413. + *.C++ \
  39414. + *.II \
  39415. + *.I++ \
  39416. + *.H \
  39417. + *.HH \
  39418. + *.H++ \
  39419. + *.CS \
  39420. + *.PHP \
  39421. + *.PHP3 \
  39422. + *.M \
  39423. + *.MM \
  39424. + *.PY
  39425. +RECURSIVE = NO
  39426. +EXCLUDE =
  39427. +EXCLUDE_SYMLINKS = NO
  39428. +EXCLUDE_PATTERNS =
  39429. +EXAMPLE_PATH =
  39430. +EXAMPLE_PATTERNS = *
  39431. +EXAMPLE_RECURSIVE = NO
  39432. +IMAGE_PATH =
  39433. +INPUT_FILTER =
  39434. +FILTER_PATTERNS =
  39435. +FILTER_SOURCE_FILES = NO
  39436. +#---------------------------------------------------------------------------
  39437. +# configuration options related to source browsing
  39438. +#---------------------------------------------------------------------------
  39439. +SOURCE_BROWSER = NO
  39440. +INLINE_SOURCES = NO
  39441. +STRIP_CODE_COMMENTS = YES
  39442. +REFERENCED_BY_RELATION = YES
  39443. +REFERENCES_RELATION = YES
  39444. +USE_HTAGS = NO
  39445. +VERBATIM_HEADERS = NO
  39446. +#---------------------------------------------------------------------------
  39447. +# configuration options related to the alphabetical class index
  39448. +#---------------------------------------------------------------------------
  39449. +ALPHABETICAL_INDEX = NO
  39450. +COLS_IN_ALPHA_INDEX = 5
  39451. +IGNORE_PREFIX =
  39452. +#---------------------------------------------------------------------------
  39453. +# configuration options related to the HTML output
  39454. +#---------------------------------------------------------------------------
  39455. +GENERATE_HTML = YES
  39456. +HTML_OUTPUT = html
  39457. +HTML_FILE_EXTENSION = .html
  39458. +HTML_HEADER =
  39459. +HTML_FOOTER =
  39460. +HTML_STYLESHEET =
  39461. +HTML_ALIGN_MEMBERS = YES
  39462. +GENERATE_HTMLHELP = NO
  39463. +CHM_FILE =
  39464. +HHC_LOCATION =
  39465. +GENERATE_CHI = NO
  39466. +BINARY_TOC = NO
  39467. +TOC_EXPAND = NO
  39468. +DISABLE_INDEX = NO
  39469. +ENUM_VALUES_PER_LINE = 4
  39470. +GENERATE_TREEVIEW = YES
  39471. +TREEVIEW_WIDTH = 250
  39472. +#---------------------------------------------------------------------------
  39473. +# configuration options related to the LaTeX output
  39474. +#---------------------------------------------------------------------------
  39475. +GENERATE_LATEX = NO
  39476. +LATEX_OUTPUT = latex
  39477. +LATEX_CMD_NAME = latex
  39478. +MAKEINDEX_CMD_NAME = makeindex
  39479. +COMPACT_LATEX = NO
  39480. +PAPER_TYPE = a4wide
  39481. +EXTRA_PACKAGES =
  39482. +LATEX_HEADER =
  39483. +PDF_HYPERLINKS = NO
  39484. +USE_PDFLATEX = NO
  39485. +LATEX_BATCHMODE = NO
  39486. +LATEX_HIDE_INDICES = NO
  39487. +#---------------------------------------------------------------------------
  39488. +# configuration options related to the RTF output
  39489. +#---------------------------------------------------------------------------
  39490. +GENERATE_RTF = NO
  39491. +RTF_OUTPUT = rtf
  39492. +COMPACT_RTF = NO
  39493. +RTF_HYPERLINKS = NO
  39494. +RTF_STYLESHEET_FILE =
  39495. +RTF_EXTENSIONS_FILE =
  39496. +#---------------------------------------------------------------------------
  39497. +# configuration options related to the man page output
  39498. +#---------------------------------------------------------------------------
  39499. +GENERATE_MAN = NO
  39500. +MAN_OUTPUT = man
  39501. +MAN_EXTENSION = .3
  39502. +MAN_LINKS = NO
  39503. +#---------------------------------------------------------------------------
  39504. +# configuration options related to the XML output
  39505. +#---------------------------------------------------------------------------
  39506. +GENERATE_XML = NO
  39507. +XML_OUTPUT = xml
  39508. +XML_SCHEMA =
  39509. +XML_DTD =
  39510. +XML_PROGRAMLISTING = YES
  39511. +#---------------------------------------------------------------------------
  39512. +# configuration options for the AutoGen Definitions output
  39513. +#---------------------------------------------------------------------------
  39514. +GENERATE_AUTOGEN_DEF = NO
  39515. +#---------------------------------------------------------------------------
  39516. +# configuration options related to the Perl module output
  39517. +#---------------------------------------------------------------------------
  39518. +GENERATE_PERLMOD = NO
  39519. +PERLMOD_LATEX = NO
  39520. +PERLMOD_PRETTY = YES
  39521. +PERLMOD_MAKEVAR_PREFIX =
  39522. +#---------------------------------------------------------------------------
  39523. +# Configuration options related to the preprocessor
  39524. +#---------------------------------------------------------------------------
  39525. +ENABLE_PREPROCESSING = YES
  39526. +MACRO_EXPANSION = NO
  39527. +EXPAND_ONLY_PREDEF = NO
  39528. +SEARCH_INCLUDES = YES
  39529. +INCLUDE_PATH =
  39530. +INCLUDE_FILE_PATTERNS =
  39531. +PREDEFINED = DEBUG DEBUG_MEMORY
  39532. +EXPAND_AS_DEFINED =
  39533. +SKIP_FUNCTION_MACROS = YES
  39534. +#---------------------------------------------------------------------------
  39535. +# Configuration::additions related to external references
  39536. +#---------------------------------------------------------------------------
  39537. +TAGFILES =
  39538. +GENERATE_TAGFILE =
  39539. +ALLEXTERNALS = NO
  39540. +EXTERNAL_GROUPS = YES
  39541. +PERL_PATH = /usr/bin/perl
  39542. +#---------------------------------------------------------------------------
  39543. +# Configuration options related to the dot tool
  39544. +#---------------------------------------------------------------------------
  39545. +CLASS_DIAGRAMS = YES
  39546. +HIDE_UNDOC_RELATIONS = YES
  39547. +HAVE_DOT = NO
  39548. +CLASS_GRAPH = YES
  39549. +COLLABORATION_GRAPH = YES
  39550. +GROUP_GRAPHS = YES
  39551. +UML_LOOK = NO
  39552. +TEMPLATE_RELATIONS = NO
  39553. +INCLUDE_GRAPH = NO
  39554. +INCLUDED_BY_GRAPH = YES
  39555. +CALL_GRAPH = NO
  39556. +GRAPHICAL_HIERARCHY = YES
  39557. +DIRECTORY_GRAPH = YES
  39558. +DOT_IMAGE_FORMAT = png
  39559. +DOT_PATH =
  39560. +DOTFILE_DIRS =
  39561. +MAX_DOT_GRAPH_DEPTH = 1000
  39562. +DOT_TRANSPARENT = NO
  39563. +DOT_MULTI_TARGETS = NO
  39564. +GENERATE_LEGEND = YES
  39565. +DOT_CLEANUP = YES
  39566. +#---------------------------------------------------------------------------
  39567. +# Configuration::additions related to the search engine
  39568. +#---------------------------------------------------------------------------
  39569. +SEARCHENGINE = NO
  39570. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_cc.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_cc.c
  39571. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  39572. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-03-13 12:46:39.096097148 +0100
  39573. @@ -0,0 +1,532 @@
  39574. +/* =========================================================================
  39575. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  39576. + * $Revision: #4 $
  39577. + * $Date: 2010/11/04 $
  39578. + * $Change: 1621692 $
  39579. + *
  39580. + * Synopsys Portability Library Software and documentation
  39581. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39582. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39583. + * between Synopsys and you.
  39584. + *
  39585. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39586. + * under any End User Software License Agreement or Agreement for
  39587. + * Licensed Product with Synopsys or any supplement thereto. You are
  39588. + * permitted to use and redistribute this Software in source and binary
  39589. + * forms, with or without modification, provided that redistributions
  39590. + * of source code must retain this notice. You may not view, use,
  39591. + * disclose, copy or distribute this file or any information contained
  39592. + * herein except pursuant to this license grant from Synopsys. If you
  39593. + * do not agree with this notice, including the disclaimer below, then
  39594. + * you are not authorized to use the Software.
  39595. + *
  39596. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39597. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39598. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39599. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39600. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39601. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39602. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39603. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39604. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39605. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39606. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39607. + * DAMAGE.
  39608. + * ========================================================================= */
  39609. +#ifdef DWC_CCLIB
  39610. +
  39611. +#include "dwc_cc.h"
  39612. +
  39613. +typedef struct dwc_cc
  39614. +{
  39615. + uint32_t uid;
  39616. + uint8_t chid[16];
  39617. + uint8_t cdid[16];
  39618. + uint8_t ck[16];
  39619. + uint8_t *name;
  39620. + uint8_t length;
  39621. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  39622. +} dwc_cc_t;
  39623. +
  39624. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  39625. +
  39626. +/** The main structure for CC management. */
  39627. +struct dwc_cc_if
  39628. +{
  39629. + dwc_mutex_t *mutex;
  39630. + char *filename;
  39631. +
  39632. + unsigned is_host:1;
  39633. +
  39634. + dwc_notifier_t *notifier;
  39635. +
  39636. + struct context_list list;
  39637. +};
  39638. +
  39639. +#ifdef DEBUG
  39640. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  39641. +{
  39642. + int i;
  39643. + DWC_PRINTF("%s: ", name);
  39644. + for (i=0; i<len; i++) {
  39645. + DWC_PRINTF("%02x ", bytes[i]);
  39646. + }
  39647. + DWC_PRINTF("\n");
  39648. +}
  39649. +#else
  39650. +#define dump_bytes(x...)
  39651. +#endif
  39652. +
  39653. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  39654. +{
  39655. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  39656. + if (!cc) {
  39657. + return NULL;
  39658. + }
  39659. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  39660. +
  39661. + if (name) {
  39662. + cc->length = length;
  39663. + cc->name = dwc_alloc(mem_ctx, length);
  39664. + if (!cc->name) {
  39665. + dwc_free(mem_ctx, cc);
  39666. + return NULL;
  39667. + }
  39668. +
  39669. + DWC_MEMCPY(cc->name, name, length);
  39670. + }
  39671. +
  39672. + return cc;
  39673. +}
  39674. +
  39675. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  39676. +{
  39677. + if (cc->name) {
  39678. + dwc_free(mem_ctx, cc->name);
  39679. + }
  39680. + dwc_free(mem_ctx, cc);
  39681. +}
  39682. +
  39683. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  39684. +{
  39685. + uint32_t uid = 0;
  39686. + dwc_cc_t *cc;
  39687. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39688. + if (cc->uid > uid) {
  39689. + uid = cc->uid;
  39690. + }
  39691. + }
  39692. +
  39693. + if (uid == 0) {
  39694. + uid = 255;
  39695. + }
  39696. +
  39697. + return uid + 1;
  39698. +}
  39699. +
  39700. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  39701. +{
  39702. + dwc_cc_t *cc;
  39703. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39704. + if (cc->uid == uid) {
  39705. + return cc;
  39706. + }
  39707. + }
  39708. + return NULL;
  39709. +}
  39710. +
  39711. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  39712. +{
  39713. + unsigned int size = 0;
  39714. + dwc_cc_t *cc;
  39715. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39716. + size += (48 + 1);
  39717. + if (cc->name) {
  39718. + size += cc->length;
  39719. + }
  39720. + }
  39721. + return size;
  39722. +}
  39723. +
  39724. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39725. +{
  39726. + uint32_t uid = 0;
  39727. + dwc_cc_t *cc;
  39728. +
  39729. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39730. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  39731. + uid = cc->uid;
  39732. + break;
  39733. + }
  39734. + }
  39735. + return uid;
  39736. +}
  39737. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39738. +{
  39739. + uint32_t uid = 0;
  39740. + dwc_cc_t *cc;
  39741. +
  39742. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39743. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  39744. + uid = cc->uid;
  39745. + break;
  39746. + }
  39747. + }
  39748. + return uid;
  39749. +}
  39750. +
  39751. +/* Internal cc_add */
  39752. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39753. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39754. +{
  39755. + dwc_cc_t *cc;
  39756. + uint32_t uid;
  39757. +
  39758. + if (cc_if->is_host) {
  39759. + uid = cc_match_cdid(cc_if, cdid);
  39760. + }
  39761. + else {
  39762. + uid = cc_match_chid(cc_if, chid);
  39763. + }
  39764. +
  39765. + if (uid) {
  39766. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  39767. + cc = cc_find(cc_if, uid);
  39768. + }
  39769. + else {
  39770. + cc = alloc_cc(mem_ctx, name, length);
  39771. + cc->uid = next_uid(cc_if);
  39772. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  39773. + }
  39774. +
  39775. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39776. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39777. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39778. +
  39779. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  39780. + dump_bytes("CHID", cc->chid, 16);
  39781. + dump_bytes("CDID", cc->cdid, 16);
  39782. + dump_bytes("CK", cc->ck, 16);
  39783. + return cc->uid;
  39784. +}
  39785. +
  39786. +/* Internal cc_clear */
  39787. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39788. +{
  39789. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  39790. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  39791. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39792. + free_cc(mem_ctx, cc);
  39793. + }
  39794. +}
  39795. +
  39796. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39797. + dwc_notifier_t *notifier, unsigned is_host)
  39798. +{
  39799. + dwc_cc_if_t *cc_if = NULL;
  39800. +
  39801. + /* Allocate a common_cc_if structure */
  39802. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  39803. +
  39804. + if (!cc_if)
  39805. + return NULL;
  39806. +
  39807. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39808. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  39809. +#else
  39810. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  39811. +#endif
  39812. + if (!cc_if->mutex) {
  39813. + dwc_free(mem_ctx, cc_if);
  39814. + return NULL;
  39815. + }
  39816. +
  39817. + DWC_CIRCLEQ_INIT(&cc_if->list);
  39818. + cc_if->is_host = is_host;
  39819. + cc_if->notifier = notifier;
  39820. + return cc_if;
  39821. +}
  39822. +
  39823. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  39824. +{
  39825. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39826. + DWC_MUTEX_FREE(cc_if->mutex);
  39827. +#else
  39828. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  39829. +#endif
  39830. + cc_clear(mem_ctx, cc_if);
  39831. + dwc_free(mem_ctx, cc_if);
  39832. +}
  39833. +
  39834. +static void cc_changed(dwc_cc_if_t *cc_if)
  39835. +{
  39836. + if (cc_if->notifier) {
  39837. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  39838. + }
  39839. +}
  39840. +
  39841. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39842. +{
  39843. + DWC_MUTEX_LOCK(cc_if->mutex);
  39844. + cc_clear(mem_ctx, cc_if);
  39845. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39846. + cc_changed(cc_if);
  39847. +}
  39848. +
  39849. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39850. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39851. +{
  39852. + uint32_t uid;
  39853. +
  39854. + DWC_MUTEX_LOCK(cc_if->mutex);
  39855. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  39856. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39857. + cc_changed(cc_if);
  39858. +
  39859. + return uid;
  39860. +}
  39861. +
  39862. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  39863. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39864. +{
  39865. + dwc_cc_t* cc;
  39866. +
  39867. + DWC_DEBUGC("Change connection context %d", id);
  39868. +
  39869. + DWC_MUTEX_LOCK(cc_if->mutex);
  39870. + cc = cc_find(cc_if, id);
  39871. + if (!cc) {
  39872. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39873. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39874. + return;
  39875. + }
  39876. +
  39877. + if (chid) {
  39878. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39879. + }
  39880. + if (cdid) {
  39881. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39882. + }
  39883. + if (ck) {
  39884. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39885. + }
  39886. +
  39887. + if (name) {
  39888. + if (cc->name) {
  39889. + dwc_free(mem_ctx, cc->name);
  39890. + }
  39891. + cc->name = dwc_alloc(mem_ctx, length);
  39892. + if (!cc->name) {
  39893. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  39894. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39895. + return;
  39896. + }
  39897. + cc->length = length;
  39898. + DWC_MEMCPY(cc->name, name, length);
  39899. + }
  39900. +
  39901. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39902. +
  39903. + cc_changed(cc_if);
  39904. +
  39905. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  39906. + dump_bytes("New CHID", cc->chid, 16);
  39907. + dump_bytes("New CDID", cc->cdid, 16);
  39908. + dump_bytes("New CK", cc->ck, 16);
  39909. +}
  39910. +
  39911. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  39912. +{
  39913. + dwc_cc_t *cc;
  39914. +
  39915. + DWC_DEBUGC("Removing connection context %d", id);
  39916. +
  39917. + DWC_MUTEX_LOCK(cc_if->mutex);
  39918. + cc = cc_find(cc_if, id);
  39919. + if (!cc) {
  39920. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39921. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39922. + return;
  39923. + }
  39924. +
  39925. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39926. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39927. + free_cc(mem_ctx, cc);
  39928. +
  39929. + cc_changed(cc_if);
  39930. +}
  39931. +
  39932. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  39933. +{
  39934. + uint8_t *buf, *x;
  39935. + uint8_t zero = 0;
  39936. + dwc_cc_t *cc;
  39937. +
  39938. + DWC_MUTEX_LOCK(cc_if->mutex);
  39939. + *length = cc_data_size(cc_if);
  39940. + if (!(*length)) {
  39941. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39942. + return NULL;
  39943. + }
  39944. +
  39945. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  39946. +
  39947. + buf = dwc_alloc(mem_ctx, *length);
  39948. + if (!buf) {
  39949. + *length = 0;
  39950. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39951. + return NULL;
  39952. + }
  39953. +
  39954. + x = buf;
  39955. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39956. + DWC_MEMCPY(x, cc->chid, 16);
  39957. + x += 16;
  39958. + DWC_MEMCPY(x, cc->cdid, 16);
  39959. + x += 16;
  39960. + DWC_MEMCPY(x, cc->ck, 16);
  39961. + x += 16;
  39962. + if (cc->name) {
  39963. + DWC_MEMCPY(x, &cc->length, 1);
  39964. + x += 1;
  39965. + DWC_MEMCPY(x, cc->name, cc->length);
  39966. + x += cc->length;
  39967. + }
  39968. + else {
  39969. + DWC_MEMCPY(x, &zero, 1);
  39970. + x += 1;
  39971. + }
  39972. + }
  39973. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39974. +
  39975. + return buf;
  39976. +}
  39977. +
  39978. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  39979. +{
  39980. + uint8_t name_length;
  39981. + uint8_t *name;
  39982. + uint8_t *chid;
  39983. + uint8_t *cdid;
  39984. + uint8_t *ck;
  39985. + uint32_t i = 0;
  39986. +
  39987. + DWC_MUTEX_LOCK(cc_if->mutex);
  39988. + cc_clear(mem_ctx, cc_if);
  39989. +
  39990. + while (i < length) {
  39991. + chid = &data[i];
  39992. + i += 16;
  39993. + cdid = &data[i];
  39994. + i += 16;
  39995. + ck = &data[i];
  39996. + i += 16;
  39997. +
  39998. + name_length = data[i];
  39999. + i ++;
  40000. +
  40001. + if (name_length) {
  40002. + name = &data[i];
  40003. + i += name_length;
  40004. + }
  40005. + else {
  40006. + name = NULL;
  40007. + }
  40008. +
  40009. + /* check to see if we haven't overflown the buffer */
  40010. + if (i > length) {
  40011. + DWC_ERROR("Data format error while attempting to load CCs "
  40012. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  40013. + break;
  40014. + }
  40015. +
  40016. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  40017. + }
  40018. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40019. +
  40020. + cc_changed(cc_if);
  40021. +}
  40022. +
  40023. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  40024. +{
  40025. + uint32_t uid = 0;
  40026. +
  40027. + DWC_MUTEX_LOCK(cc_if->mutex);
  40028. + uid = cc_match_chid(cc_if, chid);
  40029. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40030. + return uid;
  40031. +}
  40032. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  40033. +{
  40034. + uint32_t uid = 0;
  40035. +
  40036. + DWC_MUTEX_LOCK(cc_if->mutex);
  40037. + uid = cc_match_cdid(cc_if, cdid);
  40038. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40039. + return uid;
  40040. +}
  40041. +
  40042. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  40043. +{
  40044. + uint8_t *ck = NULL;
  40045. + dwc_cc_t *cc;
  40046. +
  40047. + DWC_MUTEX_LOCK(cc_if->mutex);
  40048. + cc = cc_find(cc_if, id);
  40049. + if (cc) {
  40050. + ck = cc->ck;
  40051. + }
  40052. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40053. +
  40054. + return ck;
  40055. +
  40056. +}
  40057. +
  40058. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  40059. +{
  40060. + uint8_t *retval = NULL;
  40061. + dwc_cc_t *cc;
  40062. +
  40063. + DWC_MUTEX_LOCK(cc_if->mutex);
  40064. + cc = cc_find(cc_if, id);
  40065. + if (cc) {
  40066. + retval = cc->chid;
  40067. + }
  40068. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40069. +
  40070. + return retval;
  40071. +}
  40072. +
  40073. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  40074. +{
  40075. + uint8_t *retval = NULL;
  40076. + dwc_cc_t *cc;
  40077. +
  40078. + DWC_MUTEX_LOCK(cc_if->mutex);
  40079. + cc = cc_find(cc_if, id);
  40080. + if (cc) {
  40081. + retval = cc->cdid;
  40082. + }
  40083. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40084. +
  40085. + return retval;
  40086. +}
  40087. +
  40088. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  40089. +{
  40090. + uint8_t *retval = NULL;
  40091. + dwc_cc_t *cc;
  40092. +
  40093. + DWC_MUTEX_LOCK(cc_if->mutex);
  40094. + *length = 0;
  40095. + cc = cc_find(cc_if, id);
  40096. + if (cc) {
  40097. + *length = cc->length;
  40098. + retval = cc->name;
  40099. + }
  40100. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40101. +
  40102. + return retval;
  40103. +}
  40104. +
  40105. +#endif /* DWC_CCLIB */
  40106. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_cc.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_cc.h
  40107. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  40108. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-03-13 12:46:39.096097148 +0100
  40109. @@ -0,0 +1,225 @@
  40110. +/* =========================================================================
  40111. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  40112. + * $Revision: #4 $
  40113. + * $Date: 2010/09/28 $
  40114. + * $Change: 1596182 $
  40115. + *
  40116. + * Synopsys Portability Library Software and documentation
  40117. + * (hereinafter, "Software") is an Unsupported proprietary work of
  40118. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  40119. + * between Synopsys and you.
  40120. + *
  40121. + * The Software IS NOT an item of Licensed Software or Licensed Product
  40122. + * under any End User Software License Agreement or Agreement for
  40123. + * Licensed Product with Synopsys or any supplement thereto. You are
  40124. + * permitted to use and redistribute this Software in source and binary
  40125. + * forms, with or without modification, provided that redistributions
  40126. + * of source code must retain this notice. You may not view, use,
  40127. + * disclose, copy or distribute this file or any information contained
  40128. + * herein except pursuant to this license grant from Synopsys. If you
  40129. + * do not agree with this notice, including the disclaimer below, then
  40130. + * you are not authorized to use the Software.
  40131. + *
  40132. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  40133. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40134. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40135. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  40136. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40137. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40138. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40139. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  40140. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40141. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  40142. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40143. + * DAMAGE.
  40144. + * ========================================================================= */
  40145. +#ifndef _DWC_CC_H_
  40146. +#define _DWC_CC_H_
  40147. +
  40148. +#ifdef __cplusplus
  40149. +extern "C" {
  40150. +#endif
  40151. +
  40152. +/** @file
  40153. + *
  40154. + * This file defines the Context Context library.
  40155. + *
  40156. + * The main data structure is dwc_cc_if_t which is returned by either the
  40157. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  40158. + * function. The data structure is opaque and should only be manipulated via the
  40159. + * functions provied in this API.
  40160. + *
  40161. + * It manages a list of connection contexts and operations can be performed to
  40162. + * add, remove, query, search, and change, those contexts. Additionally,
  40163. + * a dwc_notifier_t object can be requested from the manager so that
  40164. + * the user can be notified whenever the context list has changed.
  40165. + */
  40166. +
  40167. +#include "dwc_os.h"
  40168. +#include "dwc_list.h"
  40169. +#include "dwc_notifier.h"
  40170. +
  40171. +
  40172. +/* Notifications */
  40173. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  40174. +
  40175. +struct dwc_cc_if;
  40176. +typedef struct dwc_cc_if dwc_cc_if_t;
  40177. +
  40178. +
  40179. +/** @name Connection Context Operations */
  40180. +/** @{ */
  40181. +
  40182. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  40183. + * fields to default values, and returns a pointer to the structure or NULL on
  40184. + * error. */
  40185. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  40186. + dwc_notifier_t *notifier, unsigned is_host);
  40187. +
  40188. +/** Frees the memory for the specified CC structure allocated from
  40189. + * dwc_cc_if_alloc(). */
  40190. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  40191. +
  40192. +/** Removes all contexts from the connection context list */
  40193. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  40194. +
  40195. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  40196. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  40197. + * not overwritten.
  40198. + *
  40199. + * @param cc_if The cc_if structure.
  40200. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  40201. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  40202. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  40203. + * @param name An optional host friendly name as defined in the association model
  40204. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  40205. + * @param length The length othe unicode string.
  40206. + * @return A unique identifier used to refer to this context that is valid for
  40207. + * as long as this context is still in the list. */
  40208. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  40209. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  40210. + uint8_t length);
  40211. +
  40212. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  40213. + * list, preserving any accumulated statistics. This would typically be called
  40214. + * if the host decideds to change the context with a SET_CONNECTION request.
  40215. + *
  40216. + * @param cc_if The cc_if structure.
  40217. + * @param id The identifier of the connection context.
  40218. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  40219. + * indicates no change.
  40220. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  40221. + * indicates no change.
  40222. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  40223. + * indicates no change.
  40224. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  40225. + * @param length Length of name. */
  40226. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  40227. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  40228. + uint8_t *name, uint8_t length);
  40229. +
  40230. +/** Remove the specified connection context.
  40231. + * @param cc_if The cc_if structure.
  40232. + * @param id The identifier of the connection context to remove. */
  40233. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  40234. +
  40235. +/** Get a binary block of data for the connection context list and attributes.
  40236. + * This data can be used by the OS specific driver to save the connection
  40237. + * context list into non-volatile memory.
  40238. + *
  40239. + * @param cc_if The cc_if structure.
  40240. + * @param length Return the length of the data buffer.
  40241. + * @return A pointer to the data buffer. The memory for this buffer should be
  40242. + * freed with DWC_FREE() after use. */
  40243. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  40244. + unsigned int *length);
  40245. +
  40246. +/** Restore the connection context list from the binary data that was previously
  40247. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  40248. + * driver to load a connection context list from non-volatile memory.
  40249. + *
  40250. + * @param cc_if The cc_if structure.
  40251. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  40252. + * @param length The length of the data. */
  40253. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  40254. + uint8_t *data, unsigned int length);
  40255. +
  40256. +/** Find the connection context from the specified CHID.
  40257. + *
  40258. + * @param cc_if The cc_if structure.
  40259. + * @param chid A pointer to the CHID data.
  40260. + * @return A non-zero identifier of the connection context if the CHID matches.
  40261. + * Otherwise returns 0. */
  40262. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  40263. +
  40264. +/** Find the connection context from the specified CDID.
  40265. + *
  40266. + * @param cc_if The cc_if structure.
  40267. + * @param cdid A pointer to the CDID data.
  40268. + * @return A non-zero identifier of the connection context if the CHID matches.
  40269. + * Otherwise returns 0. */
  40270. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  40271. +
  40272. +/** Retrieve the CK from the specified connection context.
  40273. + *
  40274. + * @param cc_if The cc_if structure.
  40275. + * @param id The identifier of the connection context.
  40276. + * @return A pointer to the CK data. The memory does not need to be freed. */
  40277. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  40278. +
  40279. +/** Retrieve the CHID from the specified connection context.
  40280. + *
  40281. + * @param cc_if The cc_if structure.
  40282. + * @param id The identifier of the connection context.
  40283. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  40284. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  40285. +
  40286. +/** Retrieve the CDID from the specified connection context.
  40287. + *
  40288. + * @param cc_if The cc_if structure.
  40289. + * @param id The identifier of the connection context.
  40290. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  40291. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  40292. +
  40293. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  40294. +
  40295. +/** Checks a buffer for non-zero.
  40296. + * @param id A pointer to a 16 byte buffer.
  40297. + * @return true if the 16 byte value is non-zero. */
  40298. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  40299. + int i;
  40300. + for (i=0; i<16; i++) {
  40301. + if (id[i]) return 1;
  40302. + }
  40303. + return 0;
  40304. +}
  40305. +
  40306. +/** Checks a buffer for zero.
  40307. + * @param id A pointer to a 16 byte buffer.
  40308. + * @return true if the 16 byte value is zero. */
  40309. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  40310. + return !dwc_assoc_is_not_zero_id(id);
  40311. +}
  40312. +
  40313. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  40314. + * buffer. */
  40315. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  40316. + char *ptr = buffer;
  40317. + int i;
  40318. + for (i=0; i<16; i++) {
  40319. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  40320. + if (i < 15) {
  40321. + ptr += DWC_SPRINTF(ptr, " ");
  40322. + }
  40323. + }
  40324. + return ptr - buffer;
  40325. +}
  40326. +
  40327. +/** @} */
  40328. +
  40329. +#ifdef __cplusplus
  40330. +}
  40331. +#endif
  40332. +
  40333. +#endif /* _DWC_CC_H_ */
  40334. +
  40335. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  40336. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  40337. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-03-13 12:46:39.096097148 +0100
  40338. @@ -0,0 +1,1308 @@
  40339. +#include "dwc_os.h"
  40340. +#include "dwc_list.h"
  40341. +
  40342. +#ifdef DWC_CCLIB
  40343. +# include "dwc_cc.h"
  40344. +#endif
  40345. +
  40346. +#ifdef DWC_CRYPTOLIB
  40347. +# include "dwc_modpow.h"
  40348. +# include "dwc_dh.h"
  40349. +# include "dwc_crypto.h"
  40350. +#endif
  40351. +
  40352. +#ifdef DWC_NOTIFYLIB
  40353. +# include "dwc_notifier.h"
  40354. +#endif
  40355. +
  40356. +/* OS-Level Implementations */
  40357. +
  40358. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  40359. +
  40360. +
  40361. +/* MISC */
  40362. +
  40363. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40364. +{
  40365. + return memset(dest, byte, size);
  40366. +}
  40367. +
  40368. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40369. +{
  40370. + return memcpy(dest, src, size);
  40371. +}
  40372. +
  40373. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40374. +{
  40375. + bcopy(src, dest, size);
  40376. + return dest;
  40377. +}
  40378. +
  40379. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40380. +{
  40381. + return memcmp(m1, m2, size);
  40382. +}
  40383. +
  40384. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40385. +{
  40386. + return strncmp(s1, s2, size);
  40387. +}
  40388. +
  40389. +int DWC_STRCMP(void *s1, void *s2)
  40390. +{
  40391. + return strcmp(s1, s2);
  40392. +}
  40393. +
  40394. +int DWC_STRLEN(char const *str)
  40395. +{
  40396. + return strlen(str);
  40397. +}
  40398. +
  40399. +char *DWC_STRCPY(char *to, char const *from)
  40400. +{
  40401. + return strcpy(to, from);
  40402. +}
  40403. +
  40404. +char *DWC_STRDUP(char const *str)
  40405. +{
  40406. + int len = DWC_STRLEN(str) + 1;
  40407. + char *new = DWC_ALLOC_ATOMIC(len);
  40408. +
  40409. + if (!new) {
  40410. + return NULL;
  40411. + }
  40412. +
  40413. + DWC_MEMCPY(new, str, len);
  40414. + return new;
  40415. +}
  40416. +
  40417. +int DWC_ATOI(char *str, int32_t *value)
  40418. +{
  40419. + char *end = NULL;
  40420. +
  40421. + *value = strtol(str, &end, 0);
  40422. + if (*end == '\0') {
  40423. + return 0;
  40424. + }
  40425. +
  40426. + return -1;
  40427. +}
  40428. +
  40429. +int DWC_ATOUI(char *str, uint32_t *value)
  40430. +{
  40431. + char *end = NULL;
  40432. +
  40433. + *value = strtoul(str, &end, 0);
  40434. + if (*end == '\0') {
  40435. + return 0;
  40436. + }
  40437. +
  40438. + return -1;
  40439. +}
  40440. +
  40441. +
  40442. +#ifdef DWC_UTFLIB
  40443. +/* From usbstring.c */
  40444. +
  40445. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40446. +{
  40447. + int count = 0;
  40448. + u8 c;
  40449. + u16 uchar;
  40450. +
  40451. + /* this insists on correct encodings, though not minimal ones.
  40452. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40453. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40454. + */
  40455. + while (len != 0 && (c = (u8) *s++) != 0) {
  40456. + if (unlikely(c & 0x80)) {
  40457. + // 2-byte sequence:
  40458. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40459. + if ((c & 0xe0) == 0xc0) {
  40460. + uchar = (c & 0x1f) << 6;
  40461. +
  40462. + c = (u8) *s++;
  40463. + if ((c & 0xc0) != 0xc0)
  40464. + goto fail;
  40465. + c &= 0x3f;
  40466. + uchar |= c;
  40467. +
  40468. + // 3-byte sequence (most CJKV characters):
  40469. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40470. + } else if ((c & 0xf0) == 0xe0) {
  40471. + uchar = (c & 0x0f) << 12;
  40472. +
  40473. + c = (u8) *s++;
  40474. + if ((c & 0xc0) != 0xc0)
  40475. + goto fail;
  40476. + c &= 0x3f;
  40477. + uchar |= c << 6;
  40478. +
  40479. + c = (u8) *s++;
  40480. + if ((c & 0xc0) != 0xc0)
  40481. + goto fail;
  40482. + c &= 0x3f;
  40483. + uchar |= c;
  40484. +
  40485. + /* no bogus surrogates */
  40486. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40487. + goto fail;
  40488. +
  40489. + // 4-byte sequence (surrogate pairs, currently rare):
  40490. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40491. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40492. + // (uuuuu = wwww + 1)
  40493. + // FIXME accept the surrogate code points (only)
  40494. + } else
  40495. + goto fail;
  40496. + } else
  40497. + uchar = c;
  40498. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40499. + count++;
  40500. + len--;
  40501. + }
  40502. + return count;
  40503. +fail:
  40504. + return -1;
  40505. +}
  40506. +
  40507. +#endif /* DWC_UTFLIB */
  40508. +
  40509. +
  40510. +/* dwc_debug.h */
  40511. +
  40512. +dwc_bool_t DWC_IN_IRQ(void)
  40513. +{
  40514. +// return in_irq();
  40515. + return 0;
  40516. +}
  40517. +
  40518. +dwc_bool_t DWC_IN_BH(void)
  40519. +{
  40520. +// return in_softirq();
  40521. + return 0;
  40522. +}
  40523. +
  40524. +void DWC_VPRINTF(char *format, va_list args)
  40525. +{
  40526. + vprintf(format, args);
  40527. +}
  40528. +
  40529. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40530. +{
  40531. + return vsnprintf(str, size, format, args);
  40532. +}
  40533. +
  40534. +void DWC_PRINTF(char *format, ...)
  40535. +{
  40536. + va_list args;
  40537. +
  40538. + va_start(args, format);
  40539. + DWC_VPRINTF(format, args);
  40540. + va_end(args);
  40541. +}
  40542. +
  40543. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40544. +{
  40545. + int retval;
  40546. + va_list args;
  40547. +
  40548. + va_start(args, format);
  40549. + retval = vsprintf(buffer, format, args);
  40550. + va_end(args);
  40551. + return retval;
  40552. +}
  40553. +
  40554. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40555. +{
  40556. + int retval;
  40557. + va_list args;
  40558. +
  40559. + va_start(args, format);
  40560. + retval = vsnprintf(buffer, size, format, args);
  40561. + va_end(args);
  40562. + return retval;
  40563. +}
  40564. +
  40565. +void __DWC_WARN(char *format, ...)
  40566. +{
  40567. + va_list args;
  40568. +
  40569. + va_start(args, format);
  40570. + DWC_VPRINTF(format, args);
  40571. + va_end(args);
  40572. +}
  40573. +
  40574. +void __DWC_ERROR(char *format, ...)
  40575. +{
  40576. + va_list args;
  40577. +
  40578. + va_start(args, format);
  40579. + DWC_VPRINTF(format, args);
  40580. + va_end(args);
  40581. +}
  40582. +
  40583. +void DWC_EXCEPTION(char *format, ...)
  40584. +{
  40585. + va_list args;
  40586. +
  40587. + va_start(args, format);
  40588. + DWC_VPRINTF(format, args);
  40589. + va_end(args);
  40590. +// BUG_ON(1); ???
  40591. +}
  40592. +
  40593. +#ifdef DEBUG
  40594. +void __DWC_DEBUG(char *format, ...)
  40595. +{
  40596. + va_list args;
  40597. +
  40598. + va_start(args, format);
  40599. + DWC_VPRINTF(format, args);
  40600. + va_end(args);
  40601. +}
  40602. +#endif
  40603. +
  40604. +
  40605. +/* dwc_mem.h */
  40606. +
  40607. +#if 0
  40608. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  40609. + uint32_t align,
  40610. + uint32_t alloc)
  40611. +{
  40612. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  40613. + size, align, alloc);
  40614. + return (dwc_pool_t *)pool;
  40615. +}
  40616. +
  40617. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  40618. +{
  40619. + dma_pool_destroy((struct dma_pool *)pool);
  40620. +}
  40621. +
  40622. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40623. +{
  40624. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  40625. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  40626. +}
  40627. +
  40628. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40629. +{
  40630. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  40631. + memset(..);
  40632. +}
  40633. +
  40634. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  40635. +{
  40636. + dma_pool_free(pool, vaddr, daddr);
  40637. +}
  40638. +#endif
  40639. +
  40640. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  40641. +{
  40642. + if (error)
  40643. + return;
  40644. + *(bus_addr_t *)arg = segs[0].ds_addr;
  40645. +}
  40646. +
  40647. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  40648. +{
  40649. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40650. + int error;
  40651. +
  40652. + error = bus_dma_tag_create(
  40653. +#if __FreeBSD_version >= 700000
  40654. + bus_get_dma_tag(dma->dev), /* parent */
  40655. +#else
  40656. + NULL, /* parent */
  40657. +#endif
  40658. + 4, 0, /* alignment, bounds */
  40659. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  40660. + BUS_SPACE_MAXADDR, /* highaddr */
  40661. + NULL, NULL, /* filter, filterarg */
  40662. + size, /* maxsize */
  40663. + 1, /* nsegments */
  40664. + size, /* maxsegsize */
  40665. + 0, /* flags */
  40666. + NULL, /* lockfunc */
  40667. + NULL, /* lockarg */
  40668. + &dma->dma_tag);
  40669. + if (error) {
  40670. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  40671. + __func__, error);
  40672. + goto fail_0;
  40673. + }
  40674. +
  40675. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  40676. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  40677. + if (error) {
  40678. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  40679. + __func__, (uintmax_t)size, error);
  40680. + goto fail_1;
  40681. + }
  40682. +
  40683. + dma->dma_paddr = 0;
  40684. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  40685. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  40686. + if (error || dma->dma_paddr == 0) {
  40687. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  40688. + __func__, error);
  40689. + goto fail_2;
  40690. + }
  40691. +
  40692. + *dma_addr = dma->dma_paddr;
  40693. + return dma->dma_vaddr;
  40694. +
  40695. +fail_2:
  40696. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40697. +fail_1:
  40698. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40699. + bus_dma_tag_destroy(dma->dma_tag);
  40700. +fail_0:
  40701. + dma->dma_map = NULL;
  40702. + dma->dma_tag = NULL;
  40703. +
  40704. + return NULL;
  40705. +}
  40706. +
  40707. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  40708. +{
  40709. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40710. +
  40711. + if (dma->dma_tag == NULL)
  40712. + return;
  40713. + if (dma->dma_map != NULL) {
  40714. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  40715. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  40716. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40717. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40718. + dma->dma_map = NULL;
  40719. + }
  40720. +
  40721. + bus_dma_tag_destroy(dma->dma_tag);
  40722. + dma->dma_tag = NULL;
  40723. +}
  40724. +
  40725. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  40726. +{
  40727. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  40728. +}
  40729. +
  40730. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  40731. +{
  40732. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  40733. +}
  40734. +
  40735. +void __DWC_FREE(void *mem_ctx, void *addr)
  40736. +{
  40737. + free(addr, M_DEVBUF);
  40738. +}
  40739. +
  40740. +
  40741. +#ifdef DWC_CRYPTOLIB
  40742. +/* dwc_crypto.h */
  40743. +
  40744. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  40745. +{
  40746. + get_random_bytes(buffer, length);
  40747. +}
  40748. +
  40749. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  40750. +{
  40751. + struct crypto_blkcipher *tfm;
  40752. + struct blkcipher_desc desc;
  40753. + struct scatterlist sgd;
  40754. + struct scatterlist sgs;
  40755. +
  40756. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  40757. + if (tfm == NULL) {
  40758. + printk("failed to load transform for aes CBC\n");
  40759. + return -1;
  40760. + }
  40761. +
  40762. + crypto_blkcipher_setkey(tfm, key, keylen);
  40763. + crypto_blkcipher_set_iv(tfm, iv, 16);
  40764. +
  40765. + sg_init_one(&sgd, out, messagelen);
  40766. + sg_init_one(&sgs, message, messagelen);
  40767. +
  40768. + desc.tfm = tfm;
  40769. + desc.flags = 0;
  40770. +
  40771. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  40772. + crypto_free_blkcipher(tfm);
  40773. + DWC_ERROR("AES CBC encryption failed");
  40774. + return -1;
  40775. + }
  40776. +
  40777. + crypto_free_blkcipher(tfm);
  40778. + return 0;
  40779. +}
  40780. +
  40781. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  40782. +{
  40783. + struct crypto_hash *tfm;
  40784. + struct hash_desc desc;
  40785. + struct scatterlist sg;
  40786. +
  40787. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  40788. + if (IS_ERR(tfm)) {
  40789. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  40790. + return 0;
  40791. + }
  40792. + desc.tfm = tfm;
  40793. + desc.flags = 0;
  40794. +
  40795. + sg_init_one(&sg, message, len);
  40796. + crypto_hash_digest(&desc, &sg, len, out);
  40797. + crypto_free_hash(tfm);
  40798. +
  40799. + return 1;
  40800. +}
  40801. +
  40802. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  40803. + uint8_t *key, uint32_t keylen, uint8_t *out)
  40804. +{
  40805. + struct crypto_hash *tfm;
  40806. + struct hash_desc desc;
  40807. + struct scatterlist sg;
  40808. +
  40809. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  40810. + if (IS_ERR(tfm)) {
  40811. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  40812. + return 0;
  40813. + }
  40814. + desc.tfm = tfm;
  40815. + desc.flags = 0;
  40816. +
  40817. + sg_init_one(&sg, message, messagelen);
  40818. + crypto_hash_setkey(tfm, key, keylen);
  40819. + crypto_hash_digest(&desc, &sg, messagelen, out);
  40820. + crypto_free_hash(tfm);
  40821. +
  40822. + return 1;
  40823. +}
  40824. +
  40825. +#endif /* DWC_CRYPTOLIB */
  40826. +
  40827. +
  40828. +/* Byte Ordering Conversions */
  40829. +
  40830. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  40831. +{
  40832. +#ifdef __LITTLE_ENDIAN
  40833. + return *p;
  40834. +#else
  40835. + uint8_t *u_p = (uint8_t *)p;
  40836. +
  40837. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40838. +#endif
  40839. +}
  40840. +
  40841. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  40842. +{
  40843. +#ifdef __BIG_ENDIAN
  40844. + return *p;
  40845. +#else
  40846. + uint8_t *u_p = (uint8_t *)p;
  40847. +
  40848. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40849. +#endif
  40850. +}
  40851. +
  40852. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  40853. +{
  40854. +#ifdef __LITTLE_ENDIAN
  40855. + return *p;
  40856. +#else
  40857. + uint8_t *u_p = (uint8_t *)p;
  40858. +
  40859. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40860. +#endif
  40861. +}
  40862. +
  40863. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  40864. +{
  40865. +#ifdef __BIG_ENDIAN
  40866. + return *p;
  40867. +#else
  40868. + uint8_t *u_p = (uint8_t *)p;
  40869. +
  40870. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40871. +#endif
  40872. +}
  40873. +
  40874. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  40875. +{
  40876. +#ifdef __LITTLE_ENDIAN
  40877. + return *p;
  40878. +#else
  40879. + uint8_t *u_p = (uint8_t *)p;
  40880. + return (u_p[1] | (u_p[0] << 8));
  40881. +#endif
  40882. +}
  40883. +
  40884. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  40885. +{
  40886. +#ifdef __BIG_ENDIAN
  40887. + return *p;
  40888. +#else
  40889. + uint8_t *u_p = (uint8_t *)p;
  40890. + return (u_p[1] | (u_p[0] << 8));
  40891. +#endif
  40892. +}
  40893. +
  40894. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  40895. +{
  40896. +#ifdef __LITTLE_ENDIAN
  40897. + return *p;
  40898. +#else
  40899. + uint8_t *u_p = (uint8_t *)p;
  40900. + return (u_p[1] | (u_p[0] << 8));
  40901. +#endif
  40902. +}
  40903. +
  40904. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  40905. +{
  40906. +#ifdef __BIG_ENDIAN
  40907. + return *p;
  40908. +#else
  40909. + uint8_t *u_p = (uint8_t *)p;
  40910. + return (u_p[1] | (u_p[0] << 8));
  40911. +#endif
  40912. +}
  40913. +
  40914. +
  40915. +/* Registers */
  40916. +
  40917. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  40918. +{
  40919. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40920. + bus_size_t ior = (bus_size_t)reg;
  40921. +
  40922. + return bus_space_read_4(io->iot, io->ioh, ior);
  40923. +}
  40924. +
  40925. +#if 0
  40926. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  40927. +{
  40928. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40929. + bus_size_t ior = (bus_size_t)reg;
  40930. +
  40931. + return bus_space_read_8(io->iot, io->ioh, ior);
  40932. +}
  40933. +#endif
  40934. +
  40935. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  40936. +{
  40937. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40938. + bus_size_t ior = (bus_size_t)reg;
  40939. +
  40940. + bus_space_write_4(io->iot, io->ioh, ior, value);
  40941. +}
  40942. +
  40943. +#if 0
  40944. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  40945. +{
  40946. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40947. + bus_size_t ior = (bus_size_t)reg;
  40948. +
  40949. + bus_space_write_8(io->iot, io->ioh, ior, value);
  40950. +}
  40951. +#endif
  40952. +
  40953. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  40954. + uint32_t set_mask)
  40955. +{
  40956. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40957. + bus_size_t ior = (bus_size_t)reg;
  40958. +
  40959. + bus_space_write_4(io->iot, io->ioh, ior,
  40960. + (bus_space_read_4(io->iot, io->ioh, ior) &
  40961. + ~clear_mask) | set_mask);
  40962. +}
  40963. +
  40964. +#if 0
  40965. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  40966. + uint64_t set_mask)
  40967. +{
  40968. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40969. + bus_size_t ior = (bus_size_t)reg;
  40970. +
  40971. + bus_space_write_8(io->iot, io->ioh, ior,
  40972. + (bus_space_read_8(io->iot, io->ioh, ior) &
  40973. + ~clear_mask) | set_mask);
  40974. +}
  40975. +#endif
  40976. +
  40977. +
  40978. +/* Locking */
  40979. +
  40980. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  40981. +{
  40982. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  40983. +
  40984. + if (!sl) {
  40985. + DWC_ERROR("Cannot allocate memory for spinlock");
  40986. + return NULL;
  40987. + }
  40988. +
  40989. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  40990. + return (dwc_spinlock_t *)sl;
  40991. +}
  40992. +
  40993. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  40994. +{
  40995. + struct mtx *sl = (struct mtx *)lock;
  40996. +
  40997. + mtx_destroy(sl);
  40998. + DWC_FREE(sl);
  40999. +}
  41000. +
  41001. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41002. +{
  41003. + mtx_lock_spin((struct mtx *)lock); // ???
  41004. +}
  41005. +
  41006. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41007. +{
  41008. + mtx_unlock_spin((struct mtx *)lock); // ???
  41009. +}
  41010. +
  41011. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41012. +{
  41013. + mtx_lock_spin((struct mtx *)lock);
  41014. +}
  41015. +
  41016. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41017. +{
  41018. + mtx_unlock_spin((struct mtx *)lock);
  41019. +}
  41020. +
  41021. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41022. +{
  41023. + struct mtx *m;
  41024. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  41025. +
  41026. + if (!mutex) {
  41027. + DWC_ERROR("Cannot allocate memory for mutex");
  41028. + return NULL;
  41029. + }
  41030. +
  41031. + m = (struct mtx *)mutex;
  41032. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  41033. + return mutex;
  41034. +}
  41035. +
  41036. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41037. +#else
  41038. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41039. +{
  41040. + mtx_destroy((struct mtx *)mutex);
  41041. + DWC_FREE(mutex);
  41042. +}
  41043. +#endif
  41044. +
  41045. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41046. +{
  41047. + struct mtx *m = (struct mtx *)mutex;
  41048. +
  41049. + mtx_lock(m);
  41050. +}
  41051. +
  41052. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41053. +{
  41054. + struct mtx *m = (struct mtx *)mutex;
  41055. +
  41056. + return mtx_trylock(m);
  41057. +}
  41058. +
  41059. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41060. +{
  41061. + struct mtx *m = (struct mtx *)mutex;
  41062. +
  41063. + mtx_unlock(m);
  41064. +}
  41065. +
  41066. +
  41067. +/* Timing */
  41068. +
  41069. +void DWC_UDELAY(uint32_t usecs)
  41070. +{
  41071. + DELAY(usecs);
  41072. +}
  41073. +
  41074. +void DWC_MDELAY(uint32_t msecs)
  41075. +{
  41076. + do {
  41077. + DELAY(1000);
  41078. + } while (--msecs);
  41079. +}
  41080. +
  41081. +void DWC_MSLEEP(uint32_t msecs)
  41082. +{
  41083. + struct timeval tv;
  41084. +
  41085. + tv.tv_sec = msecs / 1000;
  41086. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41087. + pause("dw3slp", tvtohz(&tv));
  41088. +}
  41089. +
  41090. +uint32_t DWC_TIME(void)
  41091. +{
  41092. + struct timeval tv;
  41093. +
  41094. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  41095. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  41096. +}
  41097. +
  41098. +
  41099. +/* Timers */
  41100. +
  41101. +struct dwc_timer {
  41102. + struct callout t;
  41103. + char *name;
  41104. + dwc_spinlock_t *lock;
  41105. + dwc_timer_callback_t cb;
  41106. + void *data;
  41107. +};
  41108. +
  41109. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41110. +{
  41111. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41112. +
  41113. + if (!t) {
  41114. + DWC_ERROR("Cannot allocate memory for timer");
  41115. + return NULL;
  41116. + }
  41117. +
  41118. + callout_init(&t->t, 1);
  41119. +
  41120. + t->name = DWC_STRDUP(name);
  41121. + if (!t->name) {
  41122. + DWC_ERROR("Cannot allocate memory for timer->name");
  41123. + goto no_name;
  41124. + }
  41125. +
  41126. + t->lock = DWC_SPINLOCK_ALLOC();
  41127. + if (!t->lock) {
  41128. + DWC_ERROR("Cannot allocate memory for lock");
  41129. + goto no_lock;
  41130. + }
  41131. +
  41132. + t->cb = cb;
  41133. + t->data = data;
  41134. +
  41135. + return t;
  41136. +
  41137. + no_lock:
  41138. + DWC_FREE(t->name);
  41139. + no_name:
  41140. + DWC_FREE(t);
  41141. +
  41142. + return NULL;
  41143. +}
  41144. +
  41145. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41146. +{
  41147. + callout_stop(&timer->t);
  41148. + DWC_SPINLOCK_FREE(timer->lock);
  41149. + DWC_FREE(timer->name);
  41150. + DWC_FREE(timer);
  41151. +}
  41152. +
  41153. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41154. +{
  41155. + struct timeval tv;
  41156. +
  41157. + tv.tv_sec = time / 1000;
  41158. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41159. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  41160. +}
  41161. +
  41162. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41163. +{
  41164. + callout_stop(&timer->t);
  41165. +}
  41166. +
  41167. +
  41168. +/* Wait Queues */
  41169. +
  41170. +struct dwc_waitq {
  41171. + struct mtx lock;
  41172. + int abort;
  41173. +};
  41174. +
  41175. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41176. +{
  41177. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41178. +
  41179. + if (!wq) {
  41180. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41181. + return NULL;
  41182. + }
  41183. +
  41184. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  41185. + wq->abort = 0;
  41186. +
  41187. + return wq;
  41188. +}
  41189. +
  41190. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  41191. +{
  41192. + mtx_destroy(&wq->lock);
  41193. + DWC_FREE(wq);
  41194. +}
  41195. +
  41196. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  41197. +{
  41198. +// intrmask_t ipl;
  41199. + int result = 0;
  41200. +
  41201. + mtx_lock(&wq->lock);
  41202. +// ipl = splbio();
  41203. +
  41204. + /* Skip the sleep if already aborted or triggered */
  41205. + if (!wq->abort && !cond(data)) {
  41206. +// splx(ipl);
  41207. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  41208. +// ipl = splbio();
  41209. + }
  41210. +
  41211. + if (result == ERESTART) { // signaled - restart
  41212. + result = -DWC_E_RESTART;
  41213. +
  41214. + } else if (result == EINTR) { // signaled - interrupt
  41215. + result = -DWC_E_ABORT;
  41216. +
  41217. + } else if (wq->abort) {
  41218. + result = -DWC_E_ABORT;
  41219. +
  41220. + } else {
  41221. + result = 0;
  41222. + }
  41223. +
  41224. + wq->abort = 0;
  41225. +// splx(ipl);
  41226. + mtx_unlock(&wq->lock);
  41227. + return result;
  41228. +}
  41229. +
  41230. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  41231. + void *data, int32_t msecs)
  41232. +{
  41233. + struct timeval tv, tv1, tv2;
  41234. +// intrmask_t ipl;
  41235. + int result = 0;
  41236. +
  41237. + tv.tv_sec = msecs / 1000;
  41238. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41239. +
  41240. + mtx_lock(&wq->lock);
  41241. +// ipl = splbio();
  41242. +
  41243. + /* Skip the sleep if already aborted or triggered */
  41244. + if (!wq->abort && !cond(data)) {
  41245. +// splx(ipl);
  41246. + getmicrouptime(&tv1);
  41247. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  41248. + getmicrouptime(&tv2);
  41249. +// ipl = splbio();
  41250. + }
  41251. +
  41252. + if (result == 0) { // awoken
  41253. + if (wq->abort) {
  41254. + result = -DWC_E_ABORT;
  41255. + } else {
  41256. + tv2.tv_usec -= tv1.tv_usec;
  41257. + if (tv2.tv_usec < 0) {
  41258. + tv2.tv_usec += 1000000;
  41259. + tv2.tv_sec--;
  41260. + }
  41261. +
  41262. + tv2.tv_sec -= tv1.tv_sec;
  41263. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  41264. + result = msecs - result;
  41265. + if (result <= 0)
  41266. + result = 1;
  41267. + }
  41268. + } else if (result == ERESTART) { // signaled - restart
  41269. + result = -DWC_E_RESTART;
  41270. +
  41271. + } else if (result == EINTR) { // signaled - interrupt
  41272. + result = -DWC_E_ABORT;
  41273. +
  41274. + } else { // timed out
  41275. + result = -DWC_E_TIMEOUT;
  41276. + }
  41277. +
  41278. + wq->abort = 0;
  41279. +// splx(ipl);
  41280. + mtx_unlock(&wq->lock);
  41281. + return result;
  41282. +}
  41283. +
  41284. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  41285. +{
  41286. + wakeup(wq);
  41287. +}
  41288. +
  41289. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  41290. +{
  41291. +// intrmask_t ipl;
  41292. +
  41293. + mtx_lock(&wq->lock);
  41294. +// ipl = splbio();
  41295. + wq->abort = 1;
  41296. + wakeup(wq);
  41297. +// splx(ipl);
  41298. + mtx_unlock(&wq->lock);
  41299. +}
  41300. +
  41301. +
  41302. +/* Threading */
  41303. +
  41304. +struct dwc_thread {
  41305. + struct proc *proc;
  41306. + int abort;
  41307. +};
  41308. +
  41309. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  41310. +{
  41311. + int retval;
  41312. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  41313. +
  41314. + if (!thread) {
  41315. + return NULL;
  41316. + }
  41317. +
  41318. + thread->abort = 0;
  41319. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  41320. + RFPROC | RFNOWAIT, 0, "%s", name);
  41321. + if (retval) {
  41322. + DWC_FREE(thread);
  41323. + return NULL;
  41324. + }
  41325. +
  41326. + return thread;
  41327. +}
  41328. +
  41329. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  41330. +{
  41331. + int retval;
  41332. +
  41333. + thread->abort = 1;
  41334. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  41335. +
  41336. + if (retval == 0) {
  41337. + /* DWC_THREAD_EXIT() will free the thread struct */
  41338. + return 0;
  41339. + }
  41340. +
  41341. + /* NOTE: We leak the thread struct if thread doesn't die */
  41342. +
  41343. + if (retval == EWOULDBLOCK) {
  41344. + return -DWC_E_TIMEOUT;
  41345. + }
  41346. +
  41347. + return -DWC_E_UNKNOWN;
  41348. +}
  41349. +
  41350. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  41351. +{
  41352. + return thread->abort;
  41353. +}
  41354. +
  41355. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  41356. +{
  41357. + wakeup(&thread->abort);
  41358. + DWC_FREE(thread);
  41359. + kthread_exit(0);
  41360. +}
  41361. +
  41362. +
  41363. +/* tasklets
  41364. + - Runs in interrupt context (cannot sleep)
  41365. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  41366. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  41367. + */
  41368. +struct dwc_tasklet {
  41369. + struct task t;
  41370. + dwc_tasklet_callback_t cb;
  41371. + void *data;
  41372. +};
  41373. +
  41374. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  41375. +{
  41376. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  41377. +
  41378. + task->cb(task->data);
  41379. +}
  41380. +
  41381. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  41382. +{
  41383. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  41384. +
  41385. + if (task) {
  41386. + task->cb = cb;
  41387. + task->data = data;
  41388. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  41389. + } else {
  41390. + DWC_ERROR("Cannot allocate memory for tasklet");
  41391. + }
  41392. +
  41393. + return task;
  41394. +}
  41395. +
  41396. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41397. +{
  41398. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  41399. + DWC_FREE(task);
  41400. +}
  41401. +
  41402. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41403. +{
  41404. + /* Uses predefined system queue */
  41405. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  41406. +}
  41407. +
  41408. +
  41409. +/* workqueues
  41410. + - Runs in process context (can sleep)
  41411. + */
  41412. +typedef struct work_container {
  41413. + dwc_work_callback_t cb;
  41414. + void *data;
  41415. + dwc_workq_t *wq;
  41416. + char *name;
  41417. + int hz;
  41418. +
  41419. +#ifdef DEBUG
  41420. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41421. +#endif
  41422. + struct task task;
  41423. +} work_container_t;
  41424. +
  41425. +#ifdef DEBUG
  41426. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41427. +#endif
  41428. +
  41429. +struct dwc_workq {
  41430. + struct taskqueue *taskq;
  41431. + dwc_spinlock_t *lock;
  41432. + dwc_waitq_t *waitq;
  41433. + int pending;
  41434. +
  41435. +#ifdef DEBUG
  41436. + struct work_container_queue entries;
  41437. +#endif
  41438. +};
  41439. +
  41440. +static void do_work(void *data, int pending) // what to do with pending ???
  41441. +{
  41442. + work_container_t *container = (work_container_t *)data;
  41443. + dwc_workq_t *wq = container->wq;
  41444. + dwc_irqflags_t flags;
  41445. +
  41446. + if (container->hz) {
  41447. + pause("dw3wrk", container->hz);
  41448. + }
  41449. +
  41450. + container->cb(container->data);
  41451. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  41452. +
  41453. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41454. +
  41455. +#ifdef DEBUG
  41456. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41457. +#endif
  41458. + if (container->name)
  41459. + DWC_FREE(container->name);
  41460. + DWC_FREE(container);
  41461. + wq->pending--;
  41462. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41463. + DWC_WAITQ_TRIGGER(wq->waitq);
  41464. +}
  41465. +
  41466. +static int work_done(void *data)
  41467. +{
  41468. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41469. +
  41470. + return workq->pending == 0;
  41471. +}
  41472. +
  41473. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41474. +{
  41475. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41476. +}
  41477. +
  41478. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41479. +{
  41480. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41481. +
  41482. + if (!wq) {
  41483. + DWC_ERROR("Cannot allocate memory for workqueue");
  41484. + return NULL;
  41485. + }
  41486. +
  41487. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  41488. + if (!wq->taskq) {
  41489. + DWC_ERROR("Cannot allocate memory for taskqueue");
  41490. + goto no_taskq;
  41491. + }
  41492. +
  41493. + wq->pending = 0;
  41494. +
  41495. + wq->lock = DWC_SPINLOCK_ALLOC();
  41496. + if (!wq->lock) {
  41497. + DWC_ERROR("Cannot allocate memory for spinlock");
  41498. + goto no_lock;
  41499. + }
  41500. +
  41501. + wq->waitq = DWC_WAITQ_ALLOC();
  41502. + if (!wq->waitq) {
  41503. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41504. + goto no_waitq;
  41505. + }
  41506. +
  41507. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  41508. +
  41509. +#ifdef DEBUG
  41510. + DWC_CIRCLEQ_INIT(&wq->entries);
  41511. +#endif
  41512. + return wq;
  41513. +
  41514. + no_waitq:
  41515. + DWC_SPINLOCK_FREE(wq->lock);
  41516. + no_lock:
  41517. + taskqueue_free(wq->taskq);
  41518. + no_taskq:
  41519. + DWC_FREE(wq);
  41520. +
  41521. + return NULL;
  41522. +}
  41523. +
  41524. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41525. +{
  41526. +#ifdef DEBUG
  41527. + dwc_irqflags_t flags;
  41528. +
  41529. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41530. +
  41531. + if (wq->pending != 0) {
  41532. + struct work_container *container;
  41533. +
  41534. + DWC_ERROR("Destroying work queue with pending work");
  41535. +
  41536. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  41537. + DWC_ERROR("Work %s still pending", container->name);
  41538. + }
  41539. + }
  41540. +
  41541. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41542. +#endif
  41543. + DWC_WAITQ_FREE(wq->waitq);
  41544. + DWC_SPINLOCK_FREE(wq->lock);
  41545. + taskqueue_free(wq->taskq);
  41546. + DWC_FREE(wq);
  41547. +}
  41548. +
  41549. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41550. + char *format, ...)
  41551. +{
  41552. + dwc_irqflags_t flags;
  41553. + work_container_t *container;
  41554. + static char name[128];
  41555. + va_list args;
  41556. +
  41557. + va_start(args, format);
  41558. + DWC_VSNPRINTF(name, 128, format, args);
  41559. + va_end(args);
  41560. +
  41561. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41562. + wq->pending++;
  41563. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41564. + DWC_WAITQ_TRIGGER(wq->waitq);
  41565. +
  41566. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41567. + if (!container) {
  41568. + DWC_ERROR("Cannot allocate memory for container");
  41569. + return;
  41570. + }
  41571. +
  41572. + container->name = DWC_STRDUP(name);
  41573. + if (!container->name) {
  41574. + DWC_ERROR("Cannot allocate memory for container->name");
  41575. + DWC_FREE(container);
  41576. + return;
  41577. + }
  41578. +
  41579. + container->cb = cb;
  41580. + container->data = data;
  41581. + container->wq = wq;
  41582. + container->hz = 0;
  41583. +
  41584. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41585. +
  41586. + TASK_INIT(&container->task, 0, do_work, container);
  41587. +
  41588. +#ifdef DEBUG
  41589. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41590. +#endif
  41591. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41592. +}
  41593. +
  41594. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41595. + void *data, uint32_t time, char *format, ...)
  41596. +{
  41597. + dwc_irqflags_t flags;
  41598. + work_container_t *container;
  41599. + static char name[128];
  41600. + struct timeval tv;
  41601. + va_list args;
  41602. +
  41603. + va_start(args, format);
  41604. + DWC_VSNPRINTF(name, 128, format, args);
  41605. + va_end(args);
  41606. +
  41607. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41608. + wq->pending++;
  41609. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41610. + DWC_WAITQ_TRIGGER(wq->waitq);
  41611. +
  41612. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41613. + if (!container) {
  41614. + DWC_ERROR("Cannot allocate memory for container");
  41615. + return;
  41616. + }
  41617. +
  41618. + container->name = DWC_STRDUP(name);
  41619. + if (!container->name) {
  41620. + DWC_ERROR("Cannot allocate memory for container->name");
  41621. + DWC_FREE(container);
  41622. + return;
  41623. + }
  41624. +
  41625. + container->cb = cb;
  41626. + container->data = data;
  41627. + container->wq = wq;
  41628. +
  41629. + tv.tv_sec = time / 1000;
  41630. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41631. + container->hz = tvtohz(&tv);
  41632. +
  41633. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41634. +
  41635. + TASK_INIT(&container->task, 0, do_work, container);
  41636. +
  41637. +#ifdef DEBUG
  41638. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41639. +#endif
  41640. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41641. +}
  41642. +
  41643. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41644. +{
  41645. + return wq->pending;
  41646. +}
  41647. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  41648. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  41649. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-03-13 12:46:39.480097919 +0100
  41650. @@ -0,0 +1,1431 @@
  41651. +#include <linux/kernel.h>
  41652. +#include <linux/init.h>
  41653. +#include <linux/module.h>
  41654. +#include <linux/kthread.h>
  41655. +
  41656. +#ifdef DWC_CCLIB
  41657. +# include "dwc_cc.h"
  41658. +#endif
  41659. +
  41660. +#ifdef DWC_CRYPTOLIB
  41661. +# include "dwc_modpow.h"
  41662. +# include "dwc_dh.h"
  41663. +# include "dwc_crypto.h"
  41664. +#endif
  41665. +
  41666. +#ifdef DWC_NOTIFYLIB
  41667. +# include "dwc_notifier.h"
  41668. +#endif
  41669. +
  41670. +/* OS-Level Implementations */
  41671. +
  41672. +/* This is the Linux kernel implementation of the DWC platform library. */
  41673. +#include <linux/moduleparam.h>
  41674. +#include <linux/ctype.h>
  41675. +#include <linux/crypto.h>
  41676. +#include <linux/delay.h>
  41677. +#include <linux/device.h>
  41678. +#include <linux/dma-mapping.h>
  41679. +#include <linux/cdev.h>
  41680. +#include <linux/errno.h>
  41681. +#include <linux/interrupt.h>
  41682. +#include <linux/jiffies.h>
  41683. +#include <linux/list.h>
  41684. +#include <linux/pci.h>
  41685. +#include <linux/random.h>
  41686. +#include <linux/scatterlist.h>
  41687. +#include <linux/slab.h>
  41688. +#include <linux/stat.h>
  41689. +#include <linux/string.h>
  41690. +#include <linux/timer.h>
  41691. +#include <linux/usb.h>
  41692. +
  41693. +#include <linux/version.h>
  41694. +
  41695. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  41696. +# include <linux/usb/gadget.h>
  41697. +#else
  41698. +# include <linux/usb_gadget.h>
  41699. +#endif
  41700. +
  41701. +#include <asm/io.h>
  41702. +#include <asm/page.h>
  41703. +#include <asm/uaccess.h>
  41704. +#include <asm/unaligned.h>
  41705. +
  41706. +#include "dwc_os.h"
  41707. +#include "dwc_list.h"
  41708. +
  41709. +
  41710. +/* MISC */
  41711. +
  41712. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  41713. +{
  41714. + return memset(dest, byte, size);
  41715. +}
  41716. +
  41717. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  41718. +{
  41719. + return memcpy(dest, src, size);
  41720. +}
  41721. +
  41722. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  41723. +{
  41724. + return memmove(dest, src, size);
  41725. +}
  41726. +
  41727. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  41728. +{
  41729. + return memcmp(m1, m2, size);
  41730. +}
  41731. +
  41732. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  41733. +{
  41734. + return strncmp(s1, s2, size);
  41735. +}
  41736. +
  41737. +int DWC_STRCMP(void *s1, void *s2)
  41738. +{
  41739. + return strcmp(s1, s2);
  41740. +}
  41741. +
  41742. +int DWC_STRLEN(char const *str)
  41743. +{
  41744. + return strlen(str);
  41745. +}
  41746. +
  41747. +char *DWC_STRCPY(char *to, char const *from)
  41748. +{
  41749. + return strcpy(to, from);
  41750. +}
  41751. +
  41752. +char *DWC_STRDUP(char const *str)
  41753. +{
  41754. + int len = DWC_STRLEN(str) + 1;
  41755. + char *new = DWC_ALLOC_ATOMIC(len);
  41756. +
  41757. + if (!new) {
  41758. + return NULL;
  41759. + }
  41760. +
  41761. + DWC_MEMCPY(new, str, len);
  41762. + return new;
  41763. +}
  41764. +
  41765. +int DWC_ATOI(const char *str, int32_t *value)
  41766. +{
  41767. + char *end = NULL;
  41768. +
  41769. + *value = simple_strtol(str, &end, 0);
  41770. + if (*end == '\0') {
  41771. + return 0;
  41772. + }
  41773. +
  41774. + return -1;
  41775. +}
  41776. +
  41777. +int DWC_ATOUI(const char *str, uint32_t *value)
  41778. +{
  41779. + char *end = NULL;
  41780. +
  41781. + *value = simple_strtoul(str, &end, 0);
  41782. + if (*end == '\0') {
  41783. + return 0;
  41784. + }
  41785. +
  41786. + return -1;
  41787. +}
  41788. +
  41789. +
  41790. +#ifdef DWC_UTFLIB
  41791. +/* From usbstring.c */
  41792. +
  41793. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  41794. +{
  41795. + int count = 0;
  41796. + u8 c;
  41797. + u16 uchar;
  41798. +
  41799. + /* this insists on correct encodings, though not minimal ones.
  41800. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  41801. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  41802. + */
  41803. + while (len != 0 && (c = (u8) *s++) != 0) {
  41804. + if (unlikely(c & 0x80)) {
  41805. + // 2-byte sequence:
  41806. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  41807. + if ((c & 0xe0) == 0xc0) {
  41808. + uchar = (c & 0x1f) << 6;
  41809. +
  41810. + c = (u8) *s++;
  41811. + if ((c & 0xc0) != 0xc0)
  41812. + goto fail;
  41813. + c &= 0x3f;
  41814. + uchar |= c;
  41815. +
  41816. + // 3-byte sequence (most CJKV characters):
  41817. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  41818. + } else if ((c & 0xf0) == 0xe0) {
  41819. + uchar = (c & 0x0f) << 12;
  41820. +
  41821. + c = (u8) *s++;
  41822. + if ((c & 0xc0) != 0xc0)
  41823. + goto fail;
  41824. + c &= 0x3f;
  41825. + uchar |= c << 6;
  41826. +
  41827. + c = (u8) *s++;
  41828. + if ((c & 0xc0) != 0xc0)
  41829. + goto fail;
  41830. + c &= 0x3f;
  41831. + uchar |= c;
  41832. +
  41833. + /* no bogus surrogates */
  41834. + if (0xd800 <= uchar && uchar <= 0xdfff)
  41835. + goto fail;
  41836. +
  41837. + // 4-byte sequence (surrogate pairs, currently rare):
  41838. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  41839. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  41840. + // (uuuuu = wwww + 1)
  41841. + // FIXME accept the surrogate code points (only)
  41842. + } else
  41843. + goto fail;
  41844. + } else
  41845. + uchar = c;
  41846. + put_unaligned (cpu_to_le16 (uchar), cp++);
  41847. + count++;
  41848. + len--;
  41849. + }
  41850. + return count;
  41851. +fail:
  41852. + return -1;
  41853. +}
  41854. +#endif /* DWC_UTFLIB */
  41855. +
  41856. +
  41857. +/* dwc_debug.h */
  41858. +
  41859. +dwc_bool_t DWC_IN_IRQ(void)
  41860. +{
  41861. + return in_irq();
  41862. +}
  41863. +
  41864. +dwc_bool_t DWC_IN_BH(void)
  41865. +{
  41866. + return in_softirq();
  41867. +}
  41868. +
  41869. +void DWC_VPRINTF(char *format, va_list args)
  41870. +{
  41871. + vprintk(format, args);
  41872. +}
  41873. +
  41874. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  41875. +{
  41876. + return vsnprintf(str, size, format, args);
  41877. +}
  41878. +
  41879. +void DWC_PRINTF(char *format, ...)
  41880. +{
  41881. + va_list args;
  41882. +
  41883. + va_start(args, format);
  41884. + DWC_VPRINTF(format, args);
  41885. + va_end(args);
  41886. +}
  41887. +
  41888. +int DWC_SPRINTF(char *buffer, char *format, ...)
  41889. +{
  41890. + int retval;
  41891. + va_list args;
  41892. +
  41893. + va_start(args, format);
  41894. + retval = vsprintf(buffer, format, args);
  41895. + va_end(args);
  41896. + return retval;
  41897. +}
  41898. +
  41899. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  41900. +{
  41901. + int retval;
  41902. + va_list args;
  41903. +
  41904. + va_start(args, format);
  41905. + retval = vsnprintf(buffer, size, format, args);
  41906. + va_end(args);
  41907. + return retval;
  41908. +}
  41909. +
  41910. +void __DWC_WARN(char *format, ...)
  41911. +{
  41912. + va_list args;
  41913. +
  41914. + va_start(args, format);
  41915. + DWC_PRINTF(KERN_WARNING);
  41916. + DWC_VPRINTF(format, args);
  41917. + va_end(args);
  41918. +}
  41919. +
  41920. +void __DWC_ERROR(char *format, ...)
  41921. +{
  41922. + va_list args;
  41923. +
  41924. + va_start(args, format);
  41925. + DWC_PRINTF(KERN_ERR);
  41926. + DWC_VPRINTF(format, args);
  41927. + va_end(args);
  41928. +}
  41929. +
  41930. +void DWC_EXCEPTION(char *format, ...)
  41931. +{
  41932. + va_list args;
  41933. +
  41934. + va_start(args, format);
  41935. + DWC_PRINTF(KERN_ERR);
  41936. + DWC_VPRINTF(format, args);
  41937. + va_end(args);
  41938. + BUG_ON(1);
  41939. +}
  41940. +
  41941. +#ifdef DEBUG
  41942. +void __DWC_DEBUG(char *format, ...)
  41943. +{
  41944. + va_list args;
  41945. +
  41946. + va_start(args, format);
  41947. + DWC_PRINTF(KERN_DEBUG);
  41948. + DWC_VPRINTF(format, args);
  41949. + va_end(args);
  41950. +}
  41951. +#endif
  41952. +
  41953. +
  41954. +/* dwc_mem.h */
  41955. +
  41956. +#if 0
  41957. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41958. + uint32_t align,
  41959. + uint32_t alloc)
  41960. +{
  41961. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41962. + size, align, alloc);
  41963. + return (dwc_pool_t *)pool;
  41964. +}
  41965. +
  41966. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41967. +{
  41968. + dma_pool_destroy((struct dma_pool *)pool);
  41969. +}
  41970. +
  41971. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41972. +{
  41973. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41974. +}
  41975. +
  41976. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41977. +{
  41978. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41979. + memset(..);
  41980. +}
  41981. +
  41982. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41983. +{
  41984. + dma_pool_free(pool, vaddr, daddr);
  41985. +}
  41986. +#endif
  41987. +
  41988. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41989. +{
  41990. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  41991. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  41992. +#else
  41993. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  41994. +#endif
  41995. + if (!buf) {
  41996. + return NULL;
  41997. + }
  41998. +
  41999. + memset(buf, 0, (size_t)size);
  42000. + return buf;
  42001. +}
  42002. +
  42003. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42004. +{
  42005. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  42006. + if (!buf) {
  42007. + return NULL;
  42008. + }
  42009. + memset(buf, 0, (size_t)size);
  42010. + return buf;
  42011. +}
  42012. +
  42013. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42014. +{
  42015. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  42016. +}
  42017. +
  42018. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42019. +{
  42020. + return kzalloc(size, GFP_KERNEL);
  42021. +}
  42022. +
  42023. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42024. +{
  42025. + return kzalloc(size, GFP_ATOMIC);
  42026. +}
  42027. +
  42028. +void __DWC_FREE(void *mem_ctx, void *addr)
  42029. +{
  42030. + kfree(addr);
  42031. +}
  42032. +
  42033. +
  42034. +#ifdef DWC_CRYPTOLIB
  42035. +/* dwc_crypto.h */
  42036. +
  42037. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42038. +{
  42039. + get_random_bytes(buffer, length);
  42040. +}
  42041. +
  42042. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42043. +{
  42044. + struct crypto_blkcipher *tfm;
  42045. + struct blkcipher_desc desc;
  42046. + struct scatterlist sgd;
  42047. + struct scatterlist sgs;
  42048. +
  42049. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42050. + if (tfm == NULL) {
  42051. + printk("failed to load transform for aes CBC\n");
  42052. + return -1;
  42053. + }
  42054. +
  42055. + crypto_blkcipher_setkey(tfm, key, keylen);
  42056. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42057. +
  42058. + sg_init_one(&sgd, out, messagelen);
  42059. + sg_init_one(&sgs, message, messagelen);
  42060. +
  42061. + desc.tfm = tfm;
  42062. + desc.flags = 0;
  42063. +
  42064. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42065. + crypto_free_blkcipher(tfm);
  42066. + DWC_ERROR("AES CBC encryption failed");
  42067. + return -1;
  42068. + }
  42069. +
  42070. + crypto_free_blkcipher(tfm);
  42071. + return 0;
  42072. +}
  42073. +
  42074. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42075. +{
  42076. + struct crypto_hash *tfm;
  42077. + struct hash_desc desc;
  42078. + struct scatterlist sg;
  42079. +
  42080. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42081. + if (IS_ERR(tfm)) {
  42082. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  42083. + return 0;
  42084. + }
  42085. + desc.tfm = tfm;
  42086. + desc.flags = 0;
  42087. +
  42088. + sg_init_one(&sg, message, len);
  42089. + crypto_hash_digest(&desc, &sg, len, out);
  42090. + crypto_free_hash(tfm);
  42091. +
  42092. + return 1;
  42093. +}
  42094. +
  42095. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42096. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42097. +{
  42098. + struct crypto_hash *tfm;
  42099. + struct hash_desc desc;
  42100. + struct scatterlist sg;
  42101. +
  42102. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42103. + if (IS_ERR(tfm)) {
  42104. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  42105. + return 0;
  42106. + }
  42107. + desc.tfm = tfm;
  42108. + desc.flags = 0;
  42109. +
  42110. + sg_init_one(&sg, message, messagelen);
  42111. + crypto_hash_setkey(tfm, key, keylen);
  42112. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42113. + crypto_free_hash(tfm);
  42114. +
  42115. + return 1;
  42116. +}
  42117. +#endif /* DWC_CRYPTOLIB */
  42118. +
  42119. +
  42120. +/* Byte Ordering Conversions */
  42121. +
  42122. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42123. +{
  42124. +#ifdef __LITTLE_ENDIAN
  42125. + return *p;
  42126. +#else
  42127. + uint8_t *u_p = (uint8_t *)p;
  42128. +
  42129. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42130. +#endif
  42131. +}
  42132. +
  42133. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42134. +{
  42135. +#ifdef __BIG_ENDIAN
  42136. + return *p;
  42137. +#else
  42138. + uint8_t *u_p = (uint8_t *)p;
  42139. +
  42140. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42141. +#endif
  42142. +}
  42143. +
  42144. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42145. +{
  42146. +#ifdef __LITTLE_ENDIAN
  42147. + return *p;
  42148. +#else
  42149. + uint8_t *u_p = (uint8_t *)p;
  42150. +
  42151. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42152. +#endif
  42153. +}
  42154. +
  42155. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42156. +{
  42157. +#ifdef __BIG_ENDIAN
  42158. + return *p;
  42159. +#else
  42160. + uint8_t *u_p = (uint8_t *)p;
  42161. +
  42162. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42163. +#endif
  42164. +}
  42165. +
  42166. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42167. +{
  42168. +#ifdef __LITTLE_ENDIAN
  42169. + return *p;
  42170. +#else
  42171. + uint8_t *u_p = (uint8_t *)p;
  42172. + return (u_p[1] | (u_p[0] << 8));
  42173. +#endif
  42174. +}
  42175. +
  42176. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42177. +{
  42178. +#ifdef __BIG_ENDIAN
  42179. + return *p;
  42180. +#else
  42181. + uint8_t *u_p = (uint8_t *)p;
  42182. + return (u_p[1] | (u_p[0] << 8));
  42183. +#endif
  42184. +}
  42185. +
  42186. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  42187. +{
  42188. +#ifdef __LITTLE_ENDIAN
  42189. + return *p;
  42190. +#else
  42191. + uint8_t *u_p = (uint8_t *)p;
  42192. + return (u_p[1] | (u_p[0] << 8));
  42193. +#endif
  42194. +}
  42195. +
  42196. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42197. +{
  42198. +#ifdef __BIG_ENDIAN
  42199. + return *p;
  42200. +#else
  42201. + uint8_t *u_p = (uint8_t *)p;
  42202. + return (u_p[1] | (u_p[0] << 8));
  42203. +#endif
  42204. +}
  42205. +
  42206. +
  42207. +/* Registers */
  42208. +
  42209. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  42210. +{
  42211. + return readl(reg);
  42212. +}
  42213. +
  42214. +#if 0
  42215. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  42216. +{
  42217. +}
  42218. +#endif
  42219. +
  42220. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  42221. +{
  42222. + writel(value, reg);
  42223. +}
  42224. +
  42225. +#if 0
  42226. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  42227. +{
  42228. +}
  42229. +#endif
  42230. +
  42231. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  42232. +{
  42233. + unsigned long flags;
  42234. +
  42235. + local_irq_save(flags);
  42236. + local_fiq_disable();
  42237. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  42238. + local_irq_restore(flags);
  42239. +}
  42240. +
  42241. +#if 0
  42242. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  42243. +{
  42244. +}
  42245. +#endif
  42246. +
  42247. +
  42248. +/* Locking */
  42249. +
  42250. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42251. +{
  42252. + spinlock_t *sl = (spinlock_t *)1;
  42253. +
  42254. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42255. + sl = DWC_ALLOC(sizeof(*sl));
  42256. + if (!sl) {
  42257. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  42258. + return NULL;
  42259. + }
  42260. +
  42261. + spin_lock_init(sl);
  42262. +#endif
  42263. + return (dwc_spinlock_t *)sl;
  42264. +}
  42265. +
  42266. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42267. +{
  42268. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42269. + DWC_FREE(lock);
  42270. +#endif
  42271. +}
  42272. +
  42273. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42274. +{
  42275. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42276. + spin_lock((spinlock_t *)lock);
  42277. +#endif
  42278. +}
  42279. +
  42280. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42281. +{
  42282. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42283. + spin_unlock((spinlock_t *)lock);
  42284. +#endif
  42285. +}
  42286. +
  42287. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42288. +{
  42289. + dwc_irqflags_t f;
  42290. +
  42291. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42292. + spin_lock_irqsave((spinlock_t *)lock, f);
  42293. +#else
  42294. + local_irq_save(f);
  42295. +#endif
  42296. + *flags = f;
  42297. +}
  42298. +
  42299. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42300. +{
  42301. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42302. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  42303. +#else
  42304. + local_irq_restore(flags);
  42305. +#endif
  42306. +}
  42307. +
  42308. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42309. +{
  42310. + struct mutex *m;
  42311. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  42312. +
  42313. + if (!mutex) {
  42314. + DWC_ERROR("Cannot allocate memory for mutex\n");
  42315. + return NULL;
  42316. + }
  42317. +
  42318. + m = (struct mutex *)mutex;
  42319. + mutex_init(m);
  42320. + return mutex;
  42321. +}
  42322. +
  42323. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42324. +#else
  42325. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42326. +{
  42327. + mutex_destroy((struct mutex *)mutex);
  42328. + DWC_FREE(mutex);
  42329. +}
  42330. +#endif
  42331. +
  42332. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42333. +{
  42334. + struct mutex *m = (struct mutex *)mutex;
  42335. + mutex_lock(m);
  42336. +}
  42337. +
  42338. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42339. +{
  42340. + struct mutex *m = (struct mutex *)mutex;
  42341. + return mutex_trylock(m);
  42342. +}
  42343. +
  42344. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42345. +{
  42346. + struct mutex *m = (struct mutex *)mutex;
  42347. + mutex_unlock(m);
  42348. +}
  42349. +
  42350. +
  42351. +/* Timing */
  42352. +
  42353. +void DWC_UDELAY(uint32_t usecs)
  42354. +{
  42355. + udelay(usecs);
  42356. +}
  42357. +
  42358. +void DWC_MDELAY(uint32_t msecs)
  42359. +{
  42360. + mdelay(msecs);
  42361. +}
  42362. +
  42363. +void DWC_MSLEEP(uint32_t msecs)
  42364. +{
  42365. + msleep(msecs);
  42366. +}
  42367. +
  42368. +uint32_t DWC_TIME(void)
  42369. +{
  42370. + return jiffies_to_msecs(jiffies);
  42371. +}
  42372. +
  42373. +
  42374. +/* Timers */
  42375. +
  42376. +struct dwc_timer {
  42377. + struct timer_list *t;
  42378. + char *name;
  42379. + dwc_timer_callback_t cb;
  42380. + void *data;
  42381. + uint8_t scheduled;
  42382. + dwc_spinlock_t *lock;
  42383. +};
  42384. +
  42385. +static void timer_callback(unsigned long data)
  42386. +{
  42387. + dwc_timer_t *timer = (dwc_timer_t *)data;
  42388. + dwc_irqflags_t flags;
  42389. +
  42390. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42391. + timer->scheduled = 0;
  42392. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42393. + DWC_DEBUGC("Timer %s callback", timer->name);
  42394. + timer->cb(timer->data);
  42395. +}
  42396. +
  42397. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42398. +{
  42399. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42400. +
  42401. + if (!t) {
  42402. + DWC_ERROR("Cannot allocate memory for timer");
  42403. + return NULL;
  42404. + }
  42405. +
  42406. + t->t = DWC_ALLOC(sizeof(*t->t));
  42407. + if (!t->t) {
  42408. + DWC_ERROR("Cannot allocate memory for timer->t");
  42409. + goto no_timer;
  42410. + }
  42411. +
  42412. + t->name = DWC_STRDUP(name);
  42413. + if (!t->name) {
  42414. + DWC_ERROR("Cannot allocate memory for timer->name");
  42415. + goto no_name;
  42416. + }
  42417. +
  42418. + t->lock = DWC_SPINLOCK_ALLOC();
  42419. + if (!t->lock) {
  42420. + DWC_ERROR("Cannot allocate memory for lock");
  42421. + goto no_lock;
  42422. + }
  42423. +
  42424. + t->scheduled = 0;
  42425. + t->t->base = &boot_tvec_bases;
  42426. + t->t->expires = jiffies;
  42427. + setup_timer(t->t, timer_callback, (unsigned long)t);
  42428. +
  42429. + t->cb = cb;
  42430. + t->data = data;
  42431. +
  42432. + return t;
  42433. +
  42434. + no_lock:
  42435. + DWC_FREE(t->name);
  42436. + no_name:
  42437. + DWC_FREE(t->t);
  42438. + no_timer:
  42439. + DWC_FREE(t);
  42440. + return NULL;
  42441. +}
  42442. +
  42443. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  42444. +{
  42445. + dwc_irqflags_t flags;
  42446. +
  42447. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42448. +
  42449. + if (timer->scheduled) {
  42450. + del_timer(timer->t);
  42451. + timer->scheduled = 0;
  42452. + }
  42453. +
  42454. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42455. + DWC_SPINLOCK_FREE(timer->lock);
  42456. + DWC_FREE(timer->t);
  42457. + DWC_FREE(timer->name);
  42458. + DWC_FREE(timer);
  42459. +}
  42460. +
  42461. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  42462. +{
  42463. + dwc_irqflags_t flags;
  42464. +
  42465. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42466. +
  42467. + if (!timer->scheduled) {
  42468. + timer->scheduled = 1;
  42469. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  42470. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  42471. + add_timer(timer->t);
  42472. + } else {
  42473. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  42474. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  42475. + }
  42476. +
  42477. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42478. +}
  42479. +
  42480. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  42481. +{
  42482. + del_timer(timer->t);
  42483. +}
  42484. +
  42485. +
  42486. +/* Wait Queues */
  42487. +
  42488. +struct dwc_waitq {
  42489. + wait_queue_head_t queue;
  42490. + int abort;
  42491. +};
  42492. +
  42493. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  42494. +{
  42495. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  42496. +
  42497. + if (!wq) {
  42498. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  42499. + return NULL;
  42500. + }
  42501. +
  42502. + init_waitqueue_head(&wq->queue);
  42503. + wq->abort = 0;
  42504. + return wq;
  42505. +}
  42506. +
  42507. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42508. +{
  42509. + DWC_FREE(wq);
  42510. +}
  42511. +
  42512. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42513. +{
  42514. + int result = wait_event_interruptible(wq->queue,
  42515. + cond(data) || wq->abort);
  42516. + if (result == -ERESTARTSYS) {
  42517. + wq->abort = 0;
  42518. + return -DWC_E_RESTART;
  42519. + }
  42520. +
  42521. + if (wq->abort == 1) {
  42522. + wq->abort = 0;
  42523. + return -DWC_E_ABORT;
  42524. + }
  42525. +
  42526. + wq->abort = 0;
  42527. +
  42528. + if (result == 0) {
  42529. + return 0;
  42530. + }
  42531. +
  42532. + return -DWC_E_UNKNOWN;
  42533. +}
  42534. +
  42535. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  42536. + void *data, int32_t msecs)
  42537. +{
  42538. + int32_t tmsecs;
  42539. + int result = wait_event_interruptible_timeout(wq->queue,
  42540. + cond(data) || wq->abort,
  42541. + msecs_to_jiffies(msecs));
  42542. + if (result == -ERESTARTSYS) {
  42543. + wq->abort = 0;
  42544. + return -DWC_E_RESTART;
  42545. + }
  42546. +
  42547. + if (wq->abort == 1) {
  42548. + wq->abort = 0;
  42549. + return -DWC_E_ABORT;
  42550. + }
  42551. +
  42552. + wq->abort = 0;
  42553. +
  42554. + if (result > 0) {
  42555. + tmsecs = jiffies_to_msecs(result);
  42556. + if (!tmsecs) {
  42557. + return 1;
  42558. + }
  42559. +
  42560. + return tmsecs;
  42561. + }
  42562. +
  42563. + if (result == 0) {
  42564. + return -DWC_E_TIMEOUT;
  42565. + }
  42566. +
  42567. + return -DWC_E_UNKNOWN;
  42568. +}
  42569. +
  42570. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  42571. +{
  42572. + wq->abort = 0;
  42573. + wake_up_interruptible(&wq->queue);
  42574. +}
  42575. +
  42576. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  42577. +{
  42578. + wq->abort = 1;
  42579. + wake_up_interruptible(&wq->queue);
  42580. +}
  42581. +
  42582. +
  42583. +/* Threading */
  42584. +
  42585. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  42586. +{
  42587. + struct task_struct *thread = kthread_run(func, data, name);
  42588. +
  42589. + if (thread == ERR_PTR(-ENOMEM)) {
  42590. + return NULL;
  42591. + }
  42592. +
  42593. + return (dwc_thread_t *)thread;
  42594. +}
  42595. +
  42596. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  42597. +{
  42598. + return kthread_stop((struct task_struct *)thread);
  42599. +}
  42600. +
  42601. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  42602. +{
  42603. + return kthread_should_stop();
  42604. +}
  42605. +
  42606. +
  42607. +/* tasklets
  42608. + - run in interrupt context (cannot sleep)
  42609. + - each tasklet runs on a single CPU
  42610. + - different tasklets can be running simultaneously on different CPUs
  42611. + */
  42612. +struct dwc_tasklet {
  42613. + struct tasklet_struct t;
  42614. + dwc_tasklet_callback_t cb;
  42615. + void *data;
  42616. +};
  42617. +
  42618. +static void tasklet_callback(unsigned long data)
  42619. +{
  42620. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  42621. + t->cb(t->data);
  42622. +}
  42623. +
  42624. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  42625. +{
  42626. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  42627. +
  42628. + if (t) {
  42629. + t->cb = cb;
  42630. + t->data = data;
  42631. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  42632. + } else {
  42633. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  42634. + }
  42635. +
  42636. + return t;
  42637. +}
  42638. +
  42639. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  42640. +{
  42641. + DWC_FREE(task);
  42642. +}
  42643. +
  42644. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  42645. +{
  42646. + tasklet_schedule(&task->t);
  42647. +}
  42648. +
  42649. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  42650. +{
  42651. + tasklet_hi_schedule(&task->t);
  42652. +}
  42653. +
  42654. +
  42655. +/* workqueues
  42656. + - run in process context (can sleep)
  42657. + */
  42658. +typedef struct work_container {
  42659. + dwc_work_callback_t cb;
  42660. + void *data;
  42661. + dwc_workq_t *wq;
  42662. + char *name;
  42663. +
  42664. +#ifdef DEBUG
  42665. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  42666. +#endif
  42667. + struct delayed_work work;
  42668. +} work_container_t;
  42669. +
  42670. +#ifdef DEBUG
  42671. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  42672. +#endif
  42673. +
  42674. +struct dwc_workq {
  42675. + struct workqueue_struct *wq;
  42676. + dwc_spinlock_t *lock;
  42677. + dwc_waitq_t *waitq;
  42678. + int pending;
  42679. +
  42680. +#ifdef DEBUG
  42681. + struct work_container_queue entries;
  42682. +#endif
  42683. +};
  42684. +
  42685. +static void do_work(struct work_struct *work)
  42686. +{
  42687. + dwc_irqflags_t flags;
  42688. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  42689. + work_container_t *container = container_of(dw, struct work_container, work);
  42690. + dwc_workq_t *wq = container->wq;
  42691. +
  42692. + container->cb(container->data);
  42693. +
  42694. +#ifdef DEBUG
  42695. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  42696. +#endif
  42697. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  42698. + if (container->name) {
  42699. + DWC_FREE(container->name);
  42700. + }
  42701. + DWC_FREE(container);
  42702. +
  42703. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42704. + wq->pending--;
  42705. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42706. + DWC_WAITQ_TRIGGER(wq->waitq);
  42707. +}
  42708. +
  42709. +static int work_done(void *data)
  42710. +{
  42711. + dwc_workq_t *workq = (dwc_workq_t *)data;
  42712. + return workq->pending == 0;
  42713. +}
  42714. +
  42715. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  42716. +{
  42717. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  42718. +}
  42719. +
  42720. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  42721. +{
  42722. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  42723. +
  42724. + if (!wq) {
  42725. + return NULL;
  42726. + }
  42727. +
  42728. + wq->wq = create_singlethread_workqueue(name);
  42729. + if (!wq->wq) {
  42730. + goto no_wq;
  42731. + }
  42732. +
  42733. + wq->pending = 0;
  42734. +
  42735. + wq->lock = DWC_SPINLOCK_ALLOC();
  42736. + if (!wq->lock) {
  42737. + goto no_lock;
  42738. + }
  42739. +
  42740. + wq->waitq = DWC_WAITQ_ALLOC();
  42741. + if (!wq->waitq) {
  42742. + goto no_waitq;
  42743. + }
  42744. +
  42745. +#ifdef DEBUG
  42746. + DWC_CIRCLEQ_INIT(&wq->entries);
  42747. +#endif
  42748. + return wq;
  42749. +
  42750. + no_waitq:
  42751. + DWC_SPINLOCK_FREE(wq->lock);
  42752. + no_lock:
  42753. + destroy_workqueue(wq->wq);
  42754. + no_wq:
  42755. + DWC_FREE(wq);
  42756. +
  42757. + return NULL;
  42758. +}
  42759. +
  42760. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  42761. +{
  42762. +#ifdef DEBUG
  42763. + if (wq->pending != 0) {
  42764. + struct work_container *wc;
  42765. + DWC_ERROR("Destroying work queue with pending work");
  42766. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  42767. + DWC_ERROR("Work %s still pending", wc->name);
  42768. + }
  42769. + }
  42770. +#endif
  42771. + destroy_workqueue(wq->wq);
  42772. + DWC_SPINLOCK_FREE(wq->lock);
  42773. + DWC_WAITQ_FREE(wq->waitq);
  42774. + DWC_FREE(wq);
  42775. +}
  42776. +
  42777. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  42778. + char *format, ...)
  42779. +{
  42780. + dwc_irqflags_t flags;
  42781. + work_container_t *container;
  42782. + static char name[128];
  42783. + va_list args;
  42784. +
  42785. + va_start(args, format);
  42786. + DWC_VSNPRINTF(name, 128, format, args);
  42787. + va_end(args);
  42788. +
  42789. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42790. + wq->pending++;
  42791. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42792. + DWC_WAITQ_TRIGGER(wq->waitq);
  42793. +
  42794. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42795. + if (!container) {
  42796. + DWC_ERROR("Cannot allocate memory for container\n");
  42797. + return;
  42798. + }
  42799. +
  42800. + container->name = DWC_STRDUP(name);
  42801. + if (!container->name) {
  42802. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42803. + DWC_FREE(container);
  42804. + return;
  42805. + }
  42806. +
  42807. + container->cb = cb;
  42808. + container->data = data;
  42809. + container->wq = wq;
  42810. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42811. + INIT_WORK(&container->work.work, do_work);
  42812. +
  42813. +#ifdef DEBUG
  42814. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42815. +#endif
  42816. + queue_work(wq->wq, &container->work.work);
  42817. +}
  42818. +
  42819. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  42820. + void *data, uint32_t time, char *format, ...)
  42821. +{
  42822. + dwc_irqflags_t flags;
  42823. + work_container_t *container;
  42824. + static char name[128];
  42825. + va_list args;
  42826. +
  42827. + va_start(args, format);
  42828. + DWC_VSNPRINTF(name, 128, format, args);
  42829. + va_end(args);
  42830. +
  42831. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42832. + wq->pending++;
  42833. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42834. + DWC_WAITQ_TRIGGER(wq->waitq);
  42835. +
  42836. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42837. + if (!container) {
  42838. + DWC_ERROR("Cannot allocate memory for container\n");
  42839. + return;
  42840. + }
  42841. +
  42842. + container->name = DWC_STRDUP(name);
  42843. + if (!container->name) {
  42844. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42845. + DWC_FREE(container);
  42846. + return;
  42847. + }
  42848. +
  42849. + container->cb = cb;
  42850. + container->data = data;
  42851. + container->wq = wq;
  42852. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42853. + INIT_DELAYED_WORK(&container->work, do_work);
  42854. +
  42855. +#ifdef DEBUG
  42856. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42857. +#endif
  42858. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  42859. +}
  42860. +
  42861. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  42862. +{
  42863. + return wq->pending;
  42864. +}
  42865. +
  42866. +
  42867. +#ifdef DWC_LIBMODULE
  42868. +
  42869. +#ifdef DWC_CCLIB
  42870. +/* CC */
  42871. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  42872. +EXPORT_SYMBOL(dwc_cc_if_free);
  42873. +EXPORT_SYMBOL(dwc_cc_clear);
  42874. +EXPORT_SYMBOL(dwc_cc_add);
  42875. +EXPORT_SYMBOL(dwc_cc_remove);
  42876. +EXPORT_SYMBOL(dwc_cc_change);
  42877. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  42878. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  42879. +EXPORT_SYMBOL(dwc_cc_match_chid);
  42880. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  42881. +EXPORT_SYMBOL(dwc_cc_ck);
  42882. +EXPORT_SYMBOL(dwc_cc_chid);
  42883. +EXPORT_SYMBOL(dwc_cc_cdid);
  42884. +EXPORT_SYMBOL(dwc_cc_name);
  42885. +#endif /* DWC_CCLIB */
  42886. +
  42887. +#ifdef DWC_CRYPTOLIB
  42888. +# ifndef CONFIG_MACH_IPMATE
  42889. +/* Modpow */
  42890. +EXPORT_SYMBOL(dwc_modpow);
  42891. +
  42892. +/* DH */
  42893. +EXPORT_SYMBOL(dwc_dh_modpow);
  42894. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  42895. +EXPORT_SYMBOL(dwc_dh_pk);
  42896. +# endif /* CONFIG_MACH_IPMATE */
  42897. +
  42898. +/* Crypto */
  42899. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  42900. +EXPORT_SYMBOL(dwc_wusb_cmf);
  42901. +EXPORT_SYMBOL(dwc_wusb_prf);
  42902. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  42903. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  42904. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  42905. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  42906. +#endif /* DWC_CRYPTOLIB */
  42907. +
  42908. +/* Notification */
  42909. +#ifdef DWC_NOTIFYLIB
  42910. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  42911. +EXPORT_SYMBOL(dwc_free_notification_manager);
  42912. +EXPORT_SYMBOL(dwc_register_notifier);
  42913. +EXPORT_SYMBOL(dwc_unregister_notifier);
  42914. +EXPORT_SYMBOL(dwc_add_observer);
  42915. +EXPORT_SYMBOL(dwc_remove_observer);
  42916. +EXPORT_SYMBOL(dwc_notify);
  42917. +#endif
  42918. +
  42919. +/* Memory Debugging Routines */
  42920. +#ifdef DWC_DEBUG_MEMORY
  42921. +EXPORT_SYMBOL(dwc_alloc_debug);
  42922. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  42923. +EXPORT_SYMBOL(dwc_free_debug);
  42924. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  42925. +EXPORT_SYMBOL(dwc_dma_free_debug);
  42926. +#endif
  42927. +
  42928. +EXPORT_SYMBOL(DWC_MEMSET);
  42929. +EXPORT_SYMBOL(DWC_MEMCPY);
  42930. +EXPORT_SYMBOL(DWC_MEMMOVE);
  42931. +EXPORT_SYMBOL(DWC_MEMCMP);
  42932. +EXPORT_SYMBOL(DWC_STRNCMP);
  42933. +EXPORT_SYMBOL(DWC_STRCMP);
  42934. +EXPORT_SYMBOL(DWC_STRLEN);
  42935. +EXPORT_SYMBOL(DWC_STRCPY);
  42936. +EXPORT_SYMBOL(DWC_STRDUP);
  42937. +EXPORT_SYMBOL(DWC_ATOI);
  42938. +EXPORT_SYMBOL(DWC_ATOUI);
  42939. +
  42940. +#ifdef DWC_UTFLIB
  42941. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  42942. +#endif /* DWC_UTFLIB */
  42943. +
  42944. +EXPORT_SYMBOL(DWC_IN_IRQ);
  42945. +EXPORT_SYMBOL(DWC_IN_BH);
  42946. +EXPORT_SYMBOL(DWC_VPRINTF);
  42947. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  42948. +EXPORT_SYMBOL(DWC_PRINTF);
  42949. +EXPORT_SYMBOL(DWC_SPRINTF);
  42950. +EXPORT_SYMBOL(DWC_SNPRINTF);
  42951. +EXPORT_SYMBOL(__DWC_WARN);
  42952. +EXPORT_SYMBOL(__DWC_ERROR);
  42953. +EXPORT_SYMBOL(DWC_EXCEPTION);
  42954. +
  42955. +#ifdef DEBUG
  42956. +EXPORT_SYMBOL(__DWC_DEBUG);
  42957. +#endif
  42958. +
  42959. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  42960. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  42961. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  42962. +EXPORT_SYMBOL(__DWC_ALLOC);
  42963. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  42964. +EXPORT_SYMBOL(__DWC_FREE);
  42965. +
  42966. +#ifdef DWC_CRYPTOLIB
  42967. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  42968. +EXPORT_SYMBOL(DWC_AES_CBC);
  42969. +EXPORT_SYMBOL(DWC_SHA256);
  42970. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  42971. +#endif
  42972. +
  42973. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  42974. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  42975. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  42976. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  42977. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  42978. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  42979. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  42980. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  42981. +EXPORT_SYMBOL(DWC_READ_REG32);
  42982. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  42983. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  42984. +
  42985. +#if 0
  42986. +EXPORT_SYMBOL(DWC_READ_REG64);
  42987. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  42988. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  42989. +#endif
  42990. +
  42991. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  42992. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  42993. +EXPORT_SYMBOL(DWC_SPINLOCK);
  42994. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  42995. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  42996. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  42997. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  42998. +
  42999. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  43000. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  43001. +#endif
  43002. +
  43003. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  43004. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  43005. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  43006. +EXPORT_SYMBOL(DWC_UDELAY);
  43007. +EXPORT_SYMBOL(DWC_MDELAY);
  43008. +EXPORT_SYMBOL(DWC_MSLEEP);
  43009. +EXPORT_SYMBOL(DWC_TIME);
  43010. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  43011. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  43012. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  43013. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  43014. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  43015. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  43016. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  43017. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  43018. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  43019. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  43020. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  43021. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  43022. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  43023. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  43024. +EXPORT_SYMBOL(DWC_TASK_FREE);
  43025. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  43026. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  43027. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  43028. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  43029. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  43030. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  43031. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  43032. +
  43033. +static int dwc_common_port_init_module(void)
  43034. +{
  43035. + int result = 0;
  43036. +
  43037. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  43038. +
  43039. +#ifdef DWC_DEBUG_MEMORY
  43040. + result = dwc_memory_debug_start(NULL);
  43041. + if (result) {
  43042. + printk(KERN_ERR
  43043. + "dwc_memory_debug_start() failed with error %d\n",
  43044. + result);
  43045. + return result;
  43046. + }
  43047. +#endif
  43048. +
  43049. +#ifdef DWC_NOTIFYLIB
  43050. + result = dwc_alloc_notification_manager(NULL, NULL);
  43051. + if (result) {
  43052. + printk(KERN_ERR
  43053. + "dwc_alloc_notification_manager() failed with error %d\n",
  43054. + result);
  43055. + return result;
  43056. + }
  43057. +#endif
  43058. + return result;
  43059. +}
  43060. +
  43061. +static void dwc_common_port_exit_module(void)
  43062. +{
  43063. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  43064. +
  43065. +#ifdef DWC_NOTIFYLIB
  43066. + dwc_free_notification_manager();
  43067. +#endif
  43068. +
  43069. +#ifdef DWC_DEBUG_MEMORY
  43070. + dwc_memory_debug_stop();
  43071. +#endif
  43072. +}
  43073. +
  43074. +module_init(dwc_common_port_init_module);
  43075. +module_exit(dwc_common_port_exit_module);
  43076. +
  43077. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  43078. +MODULE_AUTHOR("Synopsys Inc.");
  43079. +MODULE_LICENSE ("GPL");
  43080. +
  43081. +#endif /* DWC_LIBMODULE */
  43082. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  43083. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  43084. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-03-13 12:46:39.480097919 +0100
  43085. @@ -0,0 +1,1275 @@
  43086. +#include "dwc_os.h"
  43087. +#include "dwc_list.h"
  43088. +
  43089. +#ifdef DWC_CCLIB
  43090. +# include "dwc_cc.h"
  43091. +#endif
  43092. +
  43093. +#ifdef DWC_CRYPTOLIB
  43094. +# include "dwc_modpow.h"
  43095. +# include "dwc_dh.h"
  43096. +# include "dwc_crypto.h"
  43097. +#endif
  43098. +
  43099. +#ifdef DWC_NOTIFYLIB
  43100. +# include "dwc_notifier.h"
  43101. +#endif
  43102. +
  43103. +/* OS-Level Implementations */
  43104. +
  43105. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  43106. +
  43107. +
  43108. +/* MISC */
  43109. +
  43110. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  43111. +{
  43112. + return memset(dest, byte, size);
  43113. +}
  43114. +
  43115. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  43116. +{
  43117. + return memcpy(dest, src, size);
  43118. +}
  43119. +
  43120. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  43121. +{
  43122. + bcopy(src, dest, size);
  43123. + return dest;
  43124. +}
  43125. +
  43126. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  43127. +{
  43128. + return memcmp(m1, m2, size);
  43129. +}
  43130. +
  43131. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  43132. +{
  43133. + return strncmp(s1, s2, size);
  43134. +}
  43135. +
  43136. +int DWC_STRCMP(void *s1, void *s2)
  43137. +{
  43138. + return strcmp(s1, s2);
  43139. +}
  43140. +
  43141. +int DWC_STRLEN(char const *str)
  43142. +{
  43143. + return strlen(str);
  43144. +}
  43145. +
  43146. +char *DWC_STRCPY(char *to, char const *from)
  43147. +{
  43148. + return strcpy(to, from);
  43149. +}
  43150. +
  43151. +char *DWC_STRDUP(char const *str)
  43152. +{
  43153. + int len = DWC_STRLEN(str) + 1;
  43154. + char *new = DWC_ALLOC_ATOMIC(len);
  43155. +
  43156. + if (!new) {
  43157. + return NULL;
  43158. + }
  43159. +
  43160. + DWC_MEMCPY(new, str, len);
  43161. + return new;
  43162. +}
  43163. +
  43164. +int DWC_ATOI(char *str, int32_t *value)
  43165. +{
  43166. + char *end = NULL;
  43167. +
  43168. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  43169. + * should be equivalent on 2's complement machines
  43170. + */
  43171. + *value = strtoul(str, &end, 0);
  43172. + if (*end == '\0') {
  43173. + return 0;
  43174. + }
  43175. +
  43176. + return -1;
  43177. +}
  43178. +
  43179. +int DWC_ATOUI(char *str, uint32_t *value)
  43180. +{
  43181. + char *end = NULL;
  43182. +
  43183. + *value = strtoul(str, &end, 0);
  43184. + if (*end == '\0') {
  43185. + return 0;
  43186. + }
  43187. +
  43188. + return -1;
  43189. +}
  43190. +
  43191. +
  43192. +#ifdef DWC_UTFLIB
  43193. +/* From usbstring.c */
  43194. +
  43195. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  43196. +{
  43197. + int count = 0;
  43198. + u8 c;
  43199. + u16 uchar;
  43200. +
  43201. + /* this insists on correct encodings, though not minimal ones.
  43202. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  43203. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  43204. + */
  43205. + while (len != 0 && (c = (u8) *s++) != 0) {
  43206. + if (unlikely(c & 0x80)) {
  43207. + // 2-byte sequence:
  43208. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  43209. + if ((c & 0xe0) == 0xc0) {
  43210. + uchar = (c & 0x1f) << 6;
  43211. +
  43212. + c = (u8) *s++;
  43213. + if ((c & 0xc0) != 0xc0)
  43214. + goto fail;
  43215. + c &= 0x3f;
  43216. + uchar |= c;
  43217. +
  43218. + // 3-byte sequence (most CJKV characters):
  43219. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  43220. + } else if ((c & 0xf0) == 0xe0) {
  43221. + uchar = (c & 0x0f) << 12;
  43222. +
  43223. + c = (u8) *s++;
  43224. + if ((c & 0xc0) != 0xc0)
  43225. + goto fail;
  43226. + c &= 0x3f;
  43227. + uchar |= c << 6;
  43228. +
  43229. + c = (u8) *s++;
  43230. + if ((c & 0xc0) != 0xc0)
  43231. + goto fail;
  43232. + c &= 0x3f;
  43233. + uchar |= c;
  43234. +
  43235. + /* no bogus surrogates */
  43236. + if (0xd800 <= uchar && uchar <= 0xdfff)
  43237. + goto fail;
  43238. +
  43239. + // 4-byte sequence (surrogate pairs, currently rare):
  43240. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  43241. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  43242. + // (uuuuu = wwww + 1)
  43243. + // FIXME accept the surrogate code points (only)
  43244. + } else
  43245. + goto fail;
  43246. + } else
  43247. + uchar = c;
  43248. + put_unaligned (cpu_to_le16 (uchar), cp++);
  43249. + count++;
  43250. + len--;
  43251. + }
  43252. + return count;
  43253. +fail:
  43254. + return -1;
  43255. +}
  43256. +
  43257. +#endif /* DWC_UTFLIB */
  43258. +
  43259. +
  43260. +/* dwc_debug.h */
  43261. +
  43262. +dwc_bool_t DWC_IN_IRQ(void)
  43263. +{
  43264. +// return in_irq();
  43265. + return 0;
  43266. +}
  43267. +
  43268. +dwc_bool_t DWC_IN_BH(void)
  43269. +{
  43270. +// return in_softirq();
  43271. + return 0;
  43272. +}
  43273. +
  43274. +void DWC_VPRINTF(char *format, va_list args)
  43275. +{
  43276. + vprintf(format, args);
  43277. +}
  43278. +
  43279. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  43280. +{
  43281. + return vsnprintf(str, size, format, args);
  43282. +}
  43283. +
  43284. +void DWC_PRINTF(char *format, ...)
  43285. +{
  43286. + va_list args;
  43287. +
  43288. + va_start(args, format);
  43289. + DWC_VPRINTF(format, args);
  43290. + va_end(args);
  43291. +}
  43292. +
  43293. +int DWC_SPRINTF(char *buffer, char *format, ...)
  43294. +{
  43295. + int retval;
  43296. + va_list args;
  43297. +
  43298. + va_start(args, format);
  43299. + retval = vsprintf(buffer, format, args);
  43300. + va_end(args);
  43301. + return retval;
  43302. +}
  43303. +
  43304. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  43305. +{
  43306. + int retval;
  43307. + va_list args;
  43308. +
  43309. + va_start(args, format);
  43310. + retval = vsnprintf(buffer, size, format, args);
  43311. + va_end(args);
  43312. + return retval;
  43313. +}
  43314. +
  43315. +void __DWC_WARN(char *format, ...)
  43316. +{
  43317. + va_list args;
  43318. +
  43319. + va_start(args, format);
  43320. + DWC_VPRINTF(format, args);
  43321. + va_end(args);
  43322. +}
  43323. +
  43324. +void __DWC_ERROR(char *format, ...)
  43325. +{
  43326. + va_list args;
  43327. +
  43328. + va_start(args, format);
  43329. + DWC_VPRINTF(format, args);
  43330. + va_end(args);
  43331. +}
  43332. +
  43333. +void DWC_EXCEPTION(char *format, ...)
  43334. +{
  43335. + va_list args;
  43336. +
  43337. + va_start(args, format);
  43338. + DWC_VPRINTF(format, args);
  43339. + va_end(args);
  43340. +// BUG_ON(1); ???
  43341. +}
  43342. +
  43343. +#ifdef DEBUG
  43344. +void __DWC_DEBUG(char *format, ...)
  43345. +{
  43346. + va_list args;
  43347. +
  43348. + va_start(args, format);
  43349. + DWC_VPRINTF(format, args);
  43350. + va_end(args);
  43351. +}
  43352. +#endif
  43353. +
  43354. +
  43355. +/* dwc_mem.h */
  43356. +
  43357. +#if 0
  43358. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  43359. + uint32_t align,
  43360. + uint32_t alloc)
  43361. +{
  43362. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  43363. + size, align, alloc);
  43364. + return (dwc_pool_t *)pool;
  43365. +}
  43366. +
  43367. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  43368. +{
  43369. + dma_pool_destroy((struct dma_pool *)pool);
  43370. +}
  43371. +
  43372. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  43373. +{
  43374. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  43375. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  43376. +}
  43377. +
  43378. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  43379. +{
  43380. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  43381. + memset(..);
  43382. +}
  43383. +
  43384. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  43385. +{
  43386. + dma_pool_free(pool, vaddr, daddr);
  43387. +}
  43388. +#endif
  43389. +
  43390. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  43391. +{
  43392. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  43393. + int error;
  43394. +
  43395. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  43396. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  43397. + &dma->nsegs, BUS_DMA_NOWAIT);
  43398. + if (error) {
  43399. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  43400. + (uintmax_t)size, error);
  43401. + goto fail_0;
  43402. + }
  43403. +
  43404. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  43405. + (caddr_t *)&dma->dma_vaddr,
  43406. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  43407. + if (error) {
  43408. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  43409. + goto fail_1;
  43410. + }
  43411. +
  43412. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  43413. + BUS_DMA_NOWAIT, &dma->dma_map);
  43414. + if (error) {
  43415. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  43416. + goto fail_2;
  43417. + }
  43418. +
  43419. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  43420. + size, NULL, BUS_DMA_NOWAIT);
  43421. + if (error) {
  43422. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  43423. + goto fail_3;
  43424. + }
  43425. +
  43426. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  43427. + *dma_addr = dma->dma_paddr;
  43428. + return dma->dma_vaddr;
  43429. +
  43430. +fail_3:
  43431. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  43432. +fail_2:
  43433. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  43434. +fail_1:
  43435. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  43436. +fail_0:
  43437. + dma->dma_map = NULL;
  43438. + dma->dma_vaddr = NULL;
  43439. + dma->nsegs = 0;
  43440. +
  43441. + return NULL;
  43442. +}
  43443. +
  43444. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  43445. +{
  43446. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  43447. +
  43448. + if (dma->dma_map != NULL) {
  43449. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  43450. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  43451. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  43452. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  43453. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  43454. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  43455. + dma->dma_paddr = 0;
  43456. + dma->dma_map = NULL;
  43457. + dma->dma_vaddr = NULL;
  43458. + dma->nsegs = 0;
  43459. + }
  43460. +}
  43461. +
  43462. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  43463. +{
  43464. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  43465. +}
  43466. +
  43467. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  43468. +{
  43469. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  43470. +}
  43471. +
  43472. +void __DWC_FREE(void *mem_ctx, void *addr)
  43473. +{
  43474. + free(addr, M_DEVBUF);
  43475. +}
  43476. +
  43477. +
  43478. +#ifdef DWC_CRYPTOLIB
  43479. +/* dwc_crypto.h */
  43480. +
  43481. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  43482. +{
  43483. + get_random_bytes(buffer, length);
  43484. +}
  43485. +
  43486. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  43487. +{
  43488. + struct crypto_blkcipher *tfm;
  43489. + struct blkcipher_desc desc;
  43490. + struct scatterlist sgd;
  43491. + struct scatterlist sgs;
  43492. +
  43493. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  43494. + if (tfm == NULL) {
  43495. + printk("failed to load transform for aes CBC\n");
  43496. + return -1;
  43497. + }
  43498. +
  43499. + crypto_blkcipher_setkey(tfm, key, keylen);
  43500. + crypto_blkcipher_set_iv(tfm, iv, 16);
  43501. +
  43502. + sg_init_one(&sgd, out, messagelen);
  43503. + sg_init_one(&sgs, message, messagelen);
  43504. +
  43505. + desc.tfm = tfm;
  43506. + desc.flags = 0;
  43507. +
  43508. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  43509. + crypto_free_blkcipher(tfm);
  43510. + DWC_ERROR("AES CBC encryption failed");
  43511. + return -1;
  43512. + }
  43513. +
  43514. + crypto_free_blkcipher(tfm);
  43515. + return 0;
  43516. +}
  43517. +
  43518. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  43519. +{
  43520. + struct crypto_hash *tfm;
  43521. + struct hash_desc desc;
  43522. + struct scatterlist sg;
  43523. +
  43524. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  43525. + if (IS_ERR(tfm)) {
  43526. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  43527. + return 0;
  43528. + }
  43529. + desc.tfm = tfm;
  43530. + desc.flags = 0;
  43531. +
  43532. + sg_init_one(&sg, message, len);
  43533. + crypto_hash_digest(&desc, &sg, len, out);
  43534. + crypto_free_hash(tfm);
  43535. +
  43536. + return 1;
  43537. +}
  43538. +
  43539. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  43540. + uint8_t *key, uint32_t keylen, uint8_t *out)
  43541. +{
  43542. + struct crypto_hash *tfm;
  43543. + struct hash_desc desc;
  43544. + struct scatterlist sg;
  43545. +
  43546. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  43547. + if (IS_ERR(tfm)) {
  43548. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  43549. + return 0;
  43550. + }
  43551. + desc.tfm = tfm;
  43552. + desc.flags = 0;
  43553. +
  43554. + sg_init_one(&sg, message, messagelen);
  43555. + crypto_hash_setkey(tfm, key, keylen);
  43556. + crypto_hash_digest(&desc, &sg, messagelen, out);
  43557. + crypto_free_hash(tfm);
  43558. +
  43559. + return 1;
  43560. +}
  43561. +
  43562. +#endif /* DWC_CRYPTOLIB */
  43563. +
  43564. +
  43565. +/* Byte Ordering Conversions */
  43566. +
  43567. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  43568. +{
  43569. +#ifdef __LITTLE_ENDIAN
  43570. + return *p;
  43571. +#else
  43572. + uint8_t *u_p = (uint8_t *)p;
  43573. +
  43574. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43575. +#endif
  43576. +}
  43577. +
  43578. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  43579. +{
  43580. +#ifdef __BIG_ENDIAN
  43581. + return *p;
  43582. +#else
  43583. + uint8_t *u_p = (uint8_t *)p;
  43584. +
  43585. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43586. +#endif
  43587. +}
  43588. +
  43589. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  43590. +{
  43591. +#ifdef __LITTLE_ENDIAN
  43592. + return *p;
  43593. +#else
  43594. + uint8_t *u_p = (uint8_t *)p;
  43595. +
  43596. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43597. +#endif
  43598. +}
  43599. +
  43600. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  43601. +{
  43602. +#ifdef __BIG_ENDIAN
  43603. + return *p;
  43604. +#else
  43605. + uint8_t *u_p = (uint8_t *)p;
  43606. +
  43607. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43608. +#endif
  43609. +}
  43610. +
  43611. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  43612. +{
  43613. +#ifdef __LITTLE_ENDIAN
  43614. + return *p;
  43615. +#else
  43616. + uint8_t *u_p = (uint8_t *)p;
  43617. + return (u_p[1] | (u_p[0] << 8));
  43618. +#endif
  43619. +}
  43620. +
  43621. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  43622. +{
  43623. +#ifdef __BIG_ENDIAN
  43624. + return *p;
  43625. +#else
  43626. + uint8_t *u_p = (uint8_t *)p;
  43627. + return (u_p[1] | (u_p[0] << 8));
  43628. +#endif
  43629. +}
  43630. +
  43631. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  43632. +{
  43633. +#ifdef __LITTLE_ENDIAN
  43634. + return *p;
  43635. +#else
  43636. + uint8_t *u_p = (uint8_t *)p;
  43637. + return (u_p[1] | (u_p[0] << 8));
  43638. +#endif
  43639. +}
  43640. +
  43641. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  43642. +{
  43643. +#ifdef __BIG_ENDIAN
  43644. + return *p;
  43645. +#else
  43646. + uint8_t *u_p = (uint8_t *)p;
  43647. + return (u_p[1] | (u_p[0] << 8));
  43648. +#endif
  43649. +}
  43650. +
  43651. +
  43652. +/* Registers */
  43653. +
  43654. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  43655. +{
  43656. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43657. + bus_size_t ior = (bus_size_t)reg;
  43658. +
  43659. + return bus_space_read_4(io->iot, io->ioh, ior);
  43660. +}
  43661. +
  43662. +#if 0
  43663. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  43664. +{
  43665. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43666. + bus_size_t ior = (bus_size_t)reg;
  43667. +
  43668. + return bus_space_read_8(io->iot, io->ioh, ior);
  43669. +}
  43670. +#endif
  43671. +
  43672. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  43673. +{
  43674. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43675. + bus_size_t ior = (bus_size_t)reg;
  43676. +
  43677. + bus_space_write_4(io->iot, io->ioh, ior, value);
  43678. +}
  43679. +
  43680. +#if 0
  43681. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  43682. +{
  43683. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43684. + bus_size_t ior = (bus_size_t)reg;
  43685. +
  43686. + bus_space_write_8(io->iot, io->ioh, ior, value);
  43687. +}
  43688. +#endif
  43689. +
  43690. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  43691. + uint32_t set_mask)
  43692. +{
  43693. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43694. + bus_size_t ior = (bus_size_t)reg;
  43695. +
  43696. + bus_space_write_4(io->iot, io->ioh, ior,
  43697. + (bus_space_read_4(io->iot, io->ioh, ior) &
  43698. + ~clear_mask) | set_mask);
  43699. +}
  43700. +
  43701. +#if 0
  43702. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  43703. + uint64_t set_mask)
  43704. +{
  43705. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43706. + bus_size_t ior = (bus_size_t)reg;
  43707. +
  43708. + bus_space_write_8(io->iot, io->ioh, ior,
  43709. + (bus_space_read_8(io->iot, io->ioh, ior) &
  43710. + ~clear_mask) | set_mask);
  43711. +}
  43712. +#endif
  43713. +
  43714. +
  43715. +/* Locking */
  43716. +
  43717. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  43718. +{
  43719. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  43720. +
  43721. + if (!sl) {
  43722. + DWC_ERROR("Cannot allocate memory for spinlock");
  43723. + return NULL;
  43724. + }
  43725. +
  43726. + simple_lock_init(sl);
  43727. + return (dwc_spinlock_t *)sl;
  43728. +}
  43729. +
  43730. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  43731. +{
  43732. + struct simplelock *sl = (struct simplelock *)lock;
  43733. +
  43734. + DWC_FREE(sl);
  43735. +}
  43736. +
  43737. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  43738. +{
  43739. + simple_lock((struct simplelock *)lock);
  43740. +}
  43741. +
  43742. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  43743. +{
  43744. + simple_unlock((struct simplelock *)lock);
  43745. +}
  43746. +
  43747. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  43748. +{
  43749. + simple_lock((struct simplelock *)lock);
  43750. + *flags = splbio();
  43751. +}
  43752. +
  43753. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  43754. +{
  43755. + splx(flags);
  43756. + simple_unlock((struct simplelock *)lock);
  43757. +}
  43758. +
  43759. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  43760. +{
  43761. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  43762. +
  43763. + if (!mutex) {
  43764. + DWC_ERROR("Cannot allocate memory for mutex");
  43765. + return NULL;
  43766. + }
  43767. +
  43768. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  43769. + return mutex;
  43770. +}
  43771. +
  43772. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  43773. +#else
  43774. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  43775. +{
  43776. + DWC_FREE(mutex);
  43777. +}
  43778. +#endif
  43779. +
  43780. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  43781. +{
  43782. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  43783. +}
  43784. +
  43785. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  43786. +{
  43787. + int status;
  43788. +
  43789. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  43790. + return status == 0;
  43791. +}
  43792. +
  43793. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  43794. +{
  43795. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  43796. +}
  43797. +
  43798. +
  43799. +/* Timing */
  43800. +
  43801. +void DWC_UDELAY(uint32_t usecs)
  43802. +{
  43803. + DELAY(usecs);
  43804. +}
  43805. +
  43806. +void DWC_MDELAY(uint32_t msecs)
  43807. +{
  43808. + do {
  43809. + DELAY(1000);
  43810. + } while (--msecs);
  43811. +}
  43812. +
  43813. +void DWC_MSLEEP(uint32_t msecs)
  43814. +{
  43815. + struct timeval tv;
  43816. +
  43817. + tv.tv_sec = msecs / 1000;
  43818. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43819. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  43820. +}
  43821. +
  43822. +uint32_t DWC_TIME(void)
  43823. +{
  43824. + struct timeval tv;
  43825. +
  43826. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  43827. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  43828. +}
  43829. +
  43830. +
  43831. +/* Timers */
  43832. +
  43833. +struct dwc_timer {
  43834. + struct callout t;
  43835. + char *name;
  43836. + dwc_spinlock_t *lock;
  43837. + dwc_timer_callback_t cb;
  43838. + void *data;
  43839. +};
  43840. +
  43841. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  43842. +{
  43843. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  43844. +
  43845. + if (!t) {
  43846. + DWC_ERROR("Cannot allocate memory for timer");
  43847. + return NULL;
  43848. + }
  43849. +
  43850. + callout_init(&t->t);
  43851. +
  43852. + t->name = DWC_STRDUP(name);
  43853. + if (!t->name) {
  43854. + DWC_ERROR("Cannot allocate memory for timer->name");
  43855. + goto no_name;
  43856. + }
  43857. +
  43858. + t->lock = DWC_SPINLOCK_ALLOC();
  43859. + if (!t->lock) {
  43860. + DWC_ERROR("Cannot allocate memory for timer->lock");
  43861. + goto no_lock;
  43862. + }
  43863. +
  43864. + t->cb = cb;
  43865. + t->data = data;
  43866. +
  43867. + return t;
  43868. +
  43869. + no_lock:
  43870. + DWC_FREE(t->name);
  43871. + no_name:
  43872. + DWC_FREE(t);
  43873. +
  43874. + return NULL;
  43875. +}
  43876. +
  43877. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  43878. +{
  43879. + callout_stop(&timer->t);
  43880. + DWC_SPINLOCK_FREE(timer->lock);
  43881. + DWC_FREE(timer->name);
  43882. + DWC_FREE(timer);
  43883. +}
  43884. +
  43885. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  43886. +{
  43887. + struct timeval tv;
  43888. +
  43889. + tv.tv_sec = time / 1000;
  43890. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43891. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  43892. +}
  43893. +
  43894. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  43895. +{
  43896. + callout_stop(&timer->t);
  43897. +}
  43898. +
  43899. +
  43900. +/* Wait Queues */
  43901. +
  43902. +struct dwc_waitq {
  43903. + struct simplelock lock;
  43904. + int abort;
  43905. +};
  43906. +
  43907. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  43908. +{
  43909. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  43910. +
  43911. + if (!wq) {
  43912. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43913. + return NULL;
  43914. + }
  43915. +
  43916. + simple_lock_init(&wq->lock);
  43917. + wq->abort = 0;
  43918. +
  43919. + return wq;
  43920. +}
  43921. +
  43922. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  43923. +{
  43924. + DWC_FREE(wq);
  43925. +}
  43926. +
  43927. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  43928. +{
  43929. + int ipl;
  43930. + int result = 0;
  43931. +
  43932. + simple_lock(&wq->lock);
  43933. + ipl = splbio();
  43934. +
  43935. + /* Skip the sleep if already aborted or triggered */
  43936. + if (!wq->abort && !cond(data)) {
  43937. + splx(ipl);
  43938. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  43939. + ipl = splbio();
  43940. + }
  43941. +
  43942. + if (result == 0) { // awoken
  43943. + if (wq->abort) {
  43944. + wq->abort = 0;
  43945. + result = -DWC_E_ABORT;
  43946. + } else {
  43947. + result = 0;
  43948. + }
  43949. +
  43950. + splx(ipl);
  43951. + simple_unlock(&wq->lock);
  43952. + } else {
  43953. + wq->abort = 0;
  43954. + splx(ipl);
  43955. + simple_unlock(&wq->lock);
  43956. +
  43957. + if (result == ERESTART) { // signaled - restart
  43958. + result = -DWC_E_RESTART;
  43959. + } else { // signaled - must be EINTR
  43960. + result = -DWC_E_ABORT;
  43961. + }
  43962. + }
  43963. +
  43964. + return result;
  43965. +}
  43966. +
  43967. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  43968. + void *data, int32_t msecs)
  43969. +{
  43970. + struct timeval tv, tv1, tv2;
  43971. + int ipl;
  43972. + int result = 0;
  43973. +
  43974. + tv.tv_sec = msecs / 1000;
  43975. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43976. +
  43977. + simple_lock(&wq->lock);
  43978. + ipl = splbio();
  43979. +
  43980. + /* Skip the sleep if already aborted or triggered */
  43981. + if (!wq->abort && !cond(data)) {
  43982. + splx(ipl);
  43983. + getmicrouptime(&tv1);
  43984. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  43985. + getmicrouptime(&tv2);
  43986. + ipl = splbio();
  43987. + }
  43988. +
  43989. + if (result == 0) { // awoken
  43990. + if (wq->abort) {
  43991. + wq->abort = 0;
  43992. + splx(ipl);
  43993. + simple_unlock(&wq->lock);
  43994. + result = -DWC_E_ABORT;
  43995. + } else {
  43996. + splx(ipl);
  43997. + simple_unlock(&wq->lock);
  43998. +
  43999. + tv2.tv_usec -= tv1.tv_usec;
  44000. + if (tv2.tv_usec < 0) {
  44001. + tv2.tv_usec += 1000000;
  44002. + tv2.tv_sec--;
  44003. + }
  44004. +
  44005. + tv2.tv_sec -= tv1.tv_sec;
  44006. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  44007. + result = msecs - result;
  44008. + if (result <= 0)
  44009. + result = 1;
  44010. + }
  44011. + } else {
  44012. + wq->abort = 0;
  44013. + splx(ipl);
  44014. + simple_unlock(&wq->lock);
  44015. +
  44016. + if (result == ERESTART) { // signaled - restart
  44017. + result = -DWC_E_RESTART;
  44018. +
  44019. + } else if (result == EINTR) { // signaled - interrupt
  44020. + result = -DWC_E_ABORT;
  44021. +
  44022. + } else { // timed out
  44023. + result = -DWC_E_TIMEOUT;
  44024. + }
  44025. + }
  44026. +
  44027. + return result;
  44028. +}
  44029. +
  44030. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  44031. +{
  44032. + wakeup(wq);
  44033. +}
  44034. +
  44035. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  44036. +{
  44037. + int ipl;
  44038. +
  44039. + simple_lock(&wq->lock);
  44040. + ipl = splbio();
  44041. + wq->abort = 1;
  44042. + wakeup(wq);
  44043. + splx(ipl);
  44044. + simple_unlock(&wq->lock);
  44045. +}
  44046. +
  44047. +
  44048. +/* Threading */
  44049. +
  44050. +struct dwc_thread {
  44051. + struct proc *proc;
  44052. + int abort;
  44053. +};
  44054. +
  44055. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  44056. +{
  44057. + int retval;
  44058. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  44059. +
  44060. + if (!thread) {
  44061. + return NULL;
  44062. + }
  44063. +
  44064. + thread->abort = 0;
  44065. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  44066. + "%s", name);
  44067. + if (retval) {
  44068. + DWC_FREE(thread);
  44069. + return NULL;
  44070. + }
  44071. +
  44072. + return thread;
  44073. +}
  44074. +
  44075. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  44076. +{
  44077. + int retval;
  44078. +
  44079. + thread->abort = 1;
  44080. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  44081. +
  44082. + if (retval == 0) {
  44083. + /* DWC_THREAD_EXIT() will free the thread struct */
  44084. + return 0;
  44085. + }
  44086. +
  44087. + /* NOTE: We leak the thread struct if thread doesn't die */
  44088. +
  44089. + if (retval == EWOULDBLOCK) {
  44090. + return -DWC_E_TIMEOUT;
  44091. + }
  44092. +
  44093. + return -DWC_E_UNKNOWN;
  44094. +}
  44095. +
  44096. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  44097. +{
  44098. + return thread->abort;
  44099. +}
  44100. +
  44101. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  44102. +{
  44103. + wakeup(&thread->abort);
  44104. + DWC_FREE(thread);
  44105. + kthread_exit(0);
  44106. +}
  44107. +
  44108. +/* tasklets
  44109. + - Runs in interrupt context (cannot sleep)
  44110. + - Each tasklet runs on a single CPU
  44111. + - Different tasklets can be running simultaneously on different CPUs
  44112. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  44113. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  44114. + */
  44115. +struct dwc_tasklet {
  44116. + dwc_tasklet_callback_t cb;
  44117. + void *data;
  44118. +};
  44119. +
  44120. +static void tasklet_callback(void *data)
  44121. +{
  44122. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  44123. +
  44124. + task->cb(task->data);
  44125. +}
  44126. +
  44127. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  44128. +{
  44129. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  44130. +
  44131. + if (task) {
  44132. + task->cb = cb;
  44133. + task->data = data;
  44134. + } else {
  44135. + DWC_ERROR("Cannot allocate memory for tasklet");
  44136. + }
  44137. +
  44138. + return task;
  44139. +}
  44140. +
  44141. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  44142. +{
  44143. + DWC_FREE(task);
  44144. +}
  44145. +
  44146. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  44147. +{
  44148. + tasklet_callback(task);
  44149. +}
  44150. +
  44151. +
  44152. +/* workqueues
  44153. + - Runs in process context (can sleep)
  44154. + */
  44155. +typedef struct work_container {
  44156. + dwc_work_callback_t cb;
  44157. + void *data;
  44158. + dwc_workq_t *wq;
  44159. + char *name;
  44160. + int hz;
  44161. + struct work task;
  44162. +} work_container_t;
  44163. +
  44164. +struct dwc_workq {
  44165. + struct workqueue *taskq;
  44166. + dwc_spinlock_t *lock;
  44167. + dwc_waitq_t *waitq;
  44168. + int pending;
  44169. + struct work_container *container;
  44170. +};
  44171. +
  44172. +static void do_work(struct work *task, void *data)
  44173. +{
  44174. + dwc_workq_t *wq = (dwc_workq_t *)data;
  44175. + work_container_t *container = wq->container;
  44176. + dwc_irqflags_t flags;
  44177. +
  44178. + if (container->hz) {
  44179. + tsleep(container, 0, "dw3wrk", container->hz);
  44180. + }
  44181. +
  44182. + container->cb(container->data);
  44183. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  44184. +
  44185. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44186. + if (container->name)
  44187. + DWC_FREE(container->name);
  44188. + DWC_FREE(container);
  44189. + wq->pending--;
  44190. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44191. + DWC_WAITQ_TRIGGER(wq->waitq);
  44192. +}
  44193. +
  44194. +static int work_done(void *data)
  44195. +{
  44196. + dwc_workq_t *workq = (dwc_workq_t *)data;
  44197. +
  44198. + return workq->pending == 0;
  44199. +}
  44200. +
  44201. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  44202. +{
  44203. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  44204. +}
  44205. +
  44206. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  44207. +{
  44208. + int result;
  44209. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  44210. +
  44211. + if (!wq) {
  44212. + DWC_ERROR("Cannot allocate memory for workqueue");
  44213. + return NULL;
  44214. + }
  44215. +
  44216. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  44217. + IPL_BIO, 0);
  44218. + if (result) {
  44219. + DWC_ERROR("Cannot create workqueue");
  44220. + goto no_taskq;
  44221. + }
  44222. +
  44223. + wq->pending = 0;
  44224. +
  44225. + wq->lock = DWC_SPINLOCK_ALLOC();
  44226. + if (!wq->lock) {
  44227. + DWC_ERROR("Cannot allocate memory for spinlock");
  44228. + goto no_lock;
  44229. + }
  44230. +
  44231. + wq->waitq = DWC_WAITQ_ALLOC();
  44232. + if (!wq->waitq) {
  44233. + DWC_ERROR("Cannot allocate memory for waitqueue");
  44234. + goto no_waitq;
  44235. + }
  44236. +
  44237. + return wq;
  44238. +
  44239. + no_waitq:
  44240. + DWC_SPINLOCK_FREE(wq->lock);
  44241. + no_lock:
  44242. + workqueue_destroy(wq->taskq);
  44243. + no_taskq:
  44244. + DWC_FREE(wq);
  44245. +
  44246. + return NULL;
  44247. +}
  44248. +
  44249. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  44250. +{
  44251. +#ifdef DEBUG
  44252. + dwc_irqflags_t flags;
  44253. +
  44254. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44255. +
  44256. + if (wq->pending != 0) {
  44257. + struct work_container *container = wq->container;
  44258. +
  44259. + DWC_ERROR("Destroying work queue with pending work");
  44260. +
  44261. + if (container && container->name) {
  44262. + DWC_ERROR("Work %s still pending", container->name);
  44263. + }
  44264. + }
  44265. +
  44266. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44267. +#endif
  44268. + DWC_WAITQ_FREE(wq->waitq);
  44269. + DWC_SPINLOCK_FREE(wq->lock);
  44270. + workqueue_destroy(wq->taskq);
  44271. + DWC_FREE(wq);
  44272. +}
  44273. +
  44274. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  44275. + char *format, ...)
  44276. +{
  44277. + dwc_irqflags_t flags;
  44278. + work_container_t *container;
  44279. + static char name[128];
  44280. + va_list args;
  44281. +
  44282. + va_start(args, format);
  44283. + DWC_VSNPRINTF(name, 128, format, args);
  44284. + va_end(args);
  44285. +
  44286. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44287. + wq->pending++;
  44288. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44289. + DWC_WAITQ_TRIGGER(wq->waitq);
  44290. +
  44291. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  44292. + if (!container) {
  44293. + DWC_ERROR("Cannot allocate memory for container");
  44294. + return;
  44295. + }
  44296. +
  44297. + container->name = DWC_STRDUP(name);
  44298. + if (!container->name) {
  44299. + DWC_ERROR("Cannot allocate memory for container->name");
  44300. + DWC_FREE(container);
  44301. + return;
  44302. + }
  44303. +
  44304. + container->cb = cb;
  44305. + container->data = data;
  44306. + container->wq = wq;
  44307. + container->hz = 0;
  44308. + wq->container = container;
  44309. +
  44310. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  44311. + workqueue_enqueue(wq->taskq, &container->task);
  44312. +}
  44313. +
  44314. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  44315. + void *data, uint32_t time, char *format, ...)
  44316. +{
  44317. + dwc_irqflags_t flags;
  44318. + work_container_t *container;
  44319. + static char name[128];
  44320. + struct timeval tv;
  44321. + va_list args;
  44322. +
  44323. + va_start(args, format);
  44324. + DWC_VSNPRINTF(name, 128, format, args);
  44325. + va_end(args);
  44326. +
  44327. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44328. + wq->pending++;
  44329. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44330. + DWC_WAITQ_TRIGGER(wq->waitq);
  44331. +
  44332. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  44333. + if (!container) {
  44334. + DWC_ERROR("Cannot allocate memory for container");
  44335. + return;
  44336. + }
  44337. +
  44338. + container->name = DWC_STRDUP(name);
  44339. + if (!container->name) {
  44340. + DWC_ERROR("Cannot allocate memory for container->name");
  44341. + DWC_FREE(container);
  44342. + return;
  44343. + }
  44344. +
  44345. + container->cb = cb;
  44346. + container->data = data;
  44347. + container->wq = wq;
  44348. + tv.tv_sec = time / 1000;
  44349. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  44350. + container->hz = tvtohz(&tv);
  44351. + wq->container = container;
  44352. +
  44353. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  44354. + workqueue_enqueue(wq->taskq, &container->task);
  44355. +}
  44356. +
  44357. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  44358. +{
  44359. + return wq->pending;
  44360. +}
  44361. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  44362. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  44363. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-03-13 12:46:39.480097919 +0100
  44364. @@ -0,0 +1,308 @@
  44365. +/* =========================================================================
  44366. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  44367. + * $Revision: #5 $
  44368. + * $Date: 2010/09/28 $
  44369. + * $Change: 1596182 $
  44370. + *
  44371. + * Synopsys Portability Library Software and documentation
  44372. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44373. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44374. + * between Synopsys and you.
  44375. + *
  44376. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44377. + * under any End User Software License Agreement or Agreement for
  44378. + * Licensed Product with Synopsys or any supplement thereto. You are
  44379. + * permitted to use and redistribute this Software in source and binary
  44380. + * forms, with or without modification, provided that redistributions
  44381. + * of source code must retain this notice. You may not view, use,
  44382. + * disclose, copy or distribute this file or any information contained
  44383. + * herein except pursuant to this license grant from Synopsys. If you
  44384. + * do not agree with this notice, including the disclaimer below, then
  44385. + * you are not authorized to use the Software.
  44386. + *
  44387. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44388. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44389. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44390. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44391. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44392. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44393. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44394. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44395. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44396. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44397. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44398. + * DAMAGE.
  44399. + * ========================================================================= */
  44400. +
  44401. +/** @file
  44402. + * This file contains the WUSB cryptographic routines.
  44403. + */
  44404. +
  44405. +#ifdef DWC_CRYPTOLIB
  44406. +
  44407. +#include "dwc_crypto.h"
  44408. +#include "usb.h"
  44409. +
  44410. +#ifdef DEBUG
  44411. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  44412. +{
  44413. + int i;
  44414. + DWC_PRINTF("%s: ", name);
  44415. + for (i=0; i<len; i++) {
  44416. + DWC_PRINTF("%02x ", bytes[i]);
  44417. + }
  44418. + DWC_PRINTF("\n");
  44419. +}
  44420. +#else
  44421. +#define dump_bytes(x...)
  44422. +#endif
  44423. +
  44424. +/* Display a block */
  44425. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  44426. +{
  44427. +#ifdef DWC_DEBUG_CRYPTO
  44428. + int i, blksize = 16;
  44429. +
  44430. + DWC_DEBUG("%s", prefix);
  44431. +
  44432. + if (suffix == NULL) {
  44433. + suffix = "\n";
  44434. + blksize = a;
  44435. + }
  44436. +
  44437. + for (i = 0; i < blksize; i++)
  44438. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  44439. + DWC_PRINT(suffix);
  44440. +#endif
  44441. +}
  44442. +
  44443. +/**
  44444. + * Encrypts an array of bytes using the AES encryption engine.
  44445. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  44446. + * in-place.
  44447. + *
  44448. + * @return 0 on success, negative error code on error.
  44449. + */
  44450. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  44451. +{
  44452. + u8 block_t[16];
  44453. + DWC_MEMSET(block_t, 0, 16);
  44454. +
  44455. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  44456. +}
  44457. +
  44458. +/**
  44459. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  44460. + * This function takes a data string and returns the encrypted CBC
  44461. + * Counter-mode MIC.
  44462. + *
  44463. + * @param key The 128-bit symmetric key.
  44464. + * @param nonce The CCM nonce.
  44465. + * @param label The unique 14-byte ASCII text label.
  44466. + * @param bytes The byte array to be encrypted.
  44467. + * @param len Length of the byte array.
  44468. + * @param result Byte array to receive the 8-byte encrypted MIC.
  44469. + */
  44470. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44471. + char *label, u8 *bytes, int len, u8 *result)
  44472. +{
  44473. + u8 block_m[16];
  44474. + u8 block_x[16];
  44475. + u8 block_t[8];
  44476. + int idx, blkNum;
  44477. + u16 la = (u16)(len + 14);
  44478. +
  44479. + /* Set the AES-128 key */
  44480. + //dwc_aes_setkey(tfm, key, 16);
  44481. +
  44482. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  44483. + block_m[0] = 0x59;
  44484. + for (idx = 0; idx < 13; idx++)
  44485. + block_m[idx + 1] = nonce[idx];
  44486. + block_m[14] = 0;
  44487. + block_m[15] = 0;
  44488. +
  44489. + /* Produce the CBC IV */
  44490. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44491. + show_block(block_m, "CBC IV in: ", "\n", 0);
  44492. + show_block(block_x, "CBC IV out:", "\n", 0);
  44493. +
  44494. + /* Fill block B1 from l(a) = Blen + 14, and A */
  44495. + block_x[0] ^= (u8)(la >> 8);
  44496. + block_x[1] ^= (u8)la;
  44497. + for (idx = 0; idx < 14; idx++)
  44498. + block_x[idx + 2] ^= label[idx];
  44499. + show_block(block_x, "After xor: ", "b1\n", 16);
  44500. +
  44501. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44502. + show_block(block_x, "After AES: ", "b1\n", 16);
  44503. +
  44504. + idx = 0;
  44505. + blkNum = 0;
  44506. +
  44507. + /* Fill remaining blocks with B */
  44508. + while (len-- > 0) {
  44509. + block_x[idx] ^= *bytes++;
  44510. + if (++idx >= 16) {
  44511. + idx = 0;
  44512. + show_block(block_x, "After xor: ", "\n", blkNum);
  44513. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44514. + show_block(block_x, "After AES: ", "\n", blkNum);
  44515. + blkNum++;
  44516. + }
  44517. + }
  44518. +
  44519. + /* Handle partial last block */
  44520. + if (idx > 0) {
  44521. + show_block(block_x, "After xor: ", "\n", blkNum);
  44522. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44523. + show_block(block_x, "After AES: ", "\n", blkNum);
  44524. + }
  44525. +
  44526. + /* Save the MIC tag */
  44527. + DWC_MEMCPY(block_t, block_x, 8);
  44528. + show_block(block_t, "MIC tag : ", NULL, 8);
  44529. +
  44530. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  44531. + block_m[0] = 0x01;
  44532. + block_m[14] = 0;
  44533. + block_m[15] = 0;
  44534. +
  44535. + /* Encrypt the counter */
  44536. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44537. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  44538. +
  44539. + /* XOR with MIC tag */
  44540. + for (idx = 0; idx < 8; idx++) {
  44541. + block_t[idx] ^= block_x[idx];
  44542. + }
  44543. +
  44544. + /* Return result to caller */
  44545. + DWC_MEMCPY(result, block_t, 8);
  44546. + show_block(result, "CCM-MIC : ", NULL, 8);
  44547. +
  44548. +}
  44549. +
  44550. +/**
  44551. + * The PRF function described in section 6.5 of the WUSB spec. This function
  44552. + * concatenates MIC values returned from dwc_cmf() to create a value of
  44553. + * the requested length.
  44554. + *
  44555. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  44556. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  44557. + * @param result Byte array to receive the result.
  44558. + */
  44559. +void dwc_wusb_prf(int prf_len, u8 *key,
  44560. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  44561. +{
  44562. + int i;
  44563. +
  44564. + nonce[0] = 0;
  44565. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  44566. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  44567. + result += 8;
  44568. + }
  44569. +}
  44570. +
  44571. +/**
  44572. + * Fills in CCM Nonce per the WUSB spec.
  44573. + *
  44574. + * @param[in] haddr Host address.
  44575. + * @param[in] daddr Device address.
  44576. + * @param[in] tkid Session Key(PTK) identifier.
  44577. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  44578. + */
  44579. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44580. + uint8_t *nonce)
  44581. +{
  44582. +
  44583. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  44584. +
  44585. + DWC_MEMSET(&nonce[0], 0, 16);
  44586. +
  44587. + DWC_MEMCPY(&nonce[6], tkid, 3);
  44588. + nonce[9] = daddr & 0xFF;
  44589. + nonce[10] = (daddr >> 8) & 0xFF;
  44590. + nonce[11] = haddr & 0xFF;
  44591. + nonce[12] = (haddr >> 8) & 0xFF;
  44592. +
  44593. + dump_bytes("CCM nonce", nonce, 16);
  44594. +}
  44595. +
  44596. +/**
  44597. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  44598. + * Nonce.
  44599. + */
  44600. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  44601. +{
  44602. + uint8_t inonce[16];
  44603. + uint32_t temp[4];
  44604. +
  44605. + /* Fill in the Nonce */
  44606. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  44607. + inonce[9] = addr & 0xFF;
  44608. + inonce[10] = (addr >> 8) & 0xFF;
  44609. + inonce[11] = inonce[9];
  44610. + inonce[12] = inonce[10];
  44611. +
  44612. + /* Collect "randomness samples" */
  44613. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  44614. +
  44615. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  44616. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  44617. + nonce);
  44618. +}
  44619. +
  44620. +/**
  44621. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  44622. + * WUSB spec.
  44623. + *
  44624. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  44625. + * @param[in] mk Master Key to derive the session from
  44626. + * @param[in] hnonce Pointer to Host Nonce.
  44627. + * @param[in] dnonce Pointer to Device Nonce.
  44628. + * @param[out] kck Pointer to where the KCK output is to be written.
  44629. + * @param[out] ptk Pointer to where the PTK output is to be written.
  44630. + */
  44631. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  44632. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  44633. +{
  44634. + uint8_t idata[32];
  44635. + uint8_t odata[32];
  44636. +
  44637. + dump_bytes("ck", mk, 16);
  44638. + dump_bytes("hnonce", hnonce, 16);
  44639. + dump_bytes("dnonce", dnonce, 16);
  44640. +
  44641. + /* The data is the HNonce and DNonce concatenated */
  44642. + DWC_MEMCPY(&idata[0], hnonce, 16);
  44643. + DWC_MEMCPY(&idata[16], dnonce, 16);
  44644. +
  44645. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  44646. +
  44647. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  44648. + DWC_MEMCPY(kck, &odata[0], 16);
  44649. + DWC_MEMCPY(ptk, &odata[16], 16);
  44650. +
  44651. + dump_bytes("kck", kck, 16);
  44652. + dump_bytes("ptk", ptk, 16);
  44653. +}
  44654. +
  44655. +/**
  44656. + * Generates the Message Integrity Code over the Handshake data per the
  44657. + * WUSB spec.
  44658. + *
  44659. + * @param ccm_nonce Pointer to CCM Nonce.
  44660. + * @param kck Pointer to Key Confirmation Key.
  44661. + * @param data Pointer to Handshake data to be checked.
  44662. + * @param mic Pointer to where the MIC output is to be written.
  44663. + */
  44664. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  44665. + uint8_t *data, uint8_t *mic)
  44666. +{
  44667. +
  44668. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  44669. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  44670. +}
  44671. +
  44672. +#endif /* DWC_CRYPTOLIB */
  44673. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  44674. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  44675. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-03-13 12:46:39.480097919 +0100
  44676. @@ -0,0 +1,111 @@
  44677. +/* =========================================================================
  44678. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  44679. + * $Revision: #3 $
  44680. + * $Date: 2010/09/28 $
  44681. + * $Change: 1596182 $
  44682. + *
  44683. + * Synopsys Portability Library Software and documentation
  44684. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44685. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44686. + * between Synopsys and you.
  44687. + *
  44688. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44689. + * under any End User Software License Agreement or Agreement for
  44690. + * Licensed Product with Synopsys or any supplement thereto. You are
  44691. + * permitted to use and redistribute this Software in source and binary
  44692. + * forms, with or without modification, provided that redistributions
  44693. + * of source code must retain this notice. You may not view, use,
  44694. + * disclose, copy or distribute this file or any information contained
  44695. + * herein except pursuant to this license grant from Synopsys. If you
  44696. + * do not agree with this notice, including the disclaimer below, then
  44697. + * you are not authorized to use the Software.
  44698. + *
  44699. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44700. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44701. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44702. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44703. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44704. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44705. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44706. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44707. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44708. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44709. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44710. + * DAMAGE.
  44711. + * ========================================================================= */
  44712. +
  44713. +#ifndef _DWC_CRYPTO_H_
  44714. +#define _DWC_CRYPTO_H_
  44715. +
  44716. +#ifdef __cplusplus
  44717. +extern "C" {
  44718. +#endif
  44719. +
  44720. +/** @file
  44721. + *
  44722. + * This file contains declarations for the WUSB Cryptographic routines as
  44723. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  44724. + * modules.
  44725. + */
  44726. +
  44727. +#include "dwc_os.h"
  44728. +
  44729. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  44730. +
  44731. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44732. + char *label, u8 *bytes, int len, u8 *result);
  44733. +void dwc_wusb_prf(int prf_len, u8 *key,
  44734. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  44735. +
  44736. +/**
  44737. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  44738. + *
  44739. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44740. + */
  44741. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  44742. + char *label, u8 *bytes, int len, u8 *result)
  44743. +{
  44744. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  44745. +}
  44746. +
  44747. +/**
  44748. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  44749. + *
  44750. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44751. + */
  44752. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  44753. + char *label, u8 *bytes, int len, u8 *result)
  44754. +{
  44755. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  44756. +}
  44757. +
  44758. +/**
  44759. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  44760. + *
  44761. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44762. + */
  44763. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  44764. + char *label, u8 *bytes, int len, u8 *result)
  44765. +{
  44766. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  44767. +}
  44768. +
  44769. +
  44770. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44771. + uint8_t *nonce);
  44772. +void dwc_wusb_gen_nonce(uint16_t addr,
  44773. + uint8_t *nonce);
  44774. +
  44775. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  44776. + uint8_t *hnonce, uint8_t *dnonce,
  44777. + uint8_t *kck, uint8_t *ptk);
  44778. +
  44779. +
  44780. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  44781. + *kck, uint8_t *data, uint8_t *mic);
  44782. +
  44783. +#ifdef __cplusplus
  44784. +}
  44785. +#endif
  44786. +
  44787. +#endif /* _DWC_CRYPTO_H_ */
  44788. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_dh.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_dh.c
  44789. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  44790. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-03-13 12:46:39.480097919 +0100
  44791. @@ -0,0 +1,291 @@
  44792. +/* =========================================================================
  44793. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  44794. + * $Revision: #3 $
  44795. + * $Date: 2010/09/28 $
  44796. + * $Change: 1596182 $
  44797. + *
  44798. + * Synopsys Portability Library Software and documentation
  44799. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44800. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44801. + * between Synopsys and you.
  44802. + *
  44803. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44804. + * under any End User Software License Agreement or Agreement for
  44805. + * Licensed Product with Synopsys or any supplement thereto. You are
  44806. + * permitted to use and redistribute this Software in source and binary
  44807. + * forms, with or without modification, provided that redistributions
  44808. + * of source code must retain this notice. You may not view, use,
  44809. + * disclose, copy or distribute this file or any information contained
  44810. + * herein except pursuant to this license grant from Synopsys. If you
  44811. + * do not agree with this notice, including the disclaimer below, then
  44812. + * you are not authorized to use the Software.
  44813. + *
  44814. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44815. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44816. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44817. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44818. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44819. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44820. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44821. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44822. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44823. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44824. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44825. + * DAMAGE.
  44826. + * ========================================================================= */
  44827. +#ifdef DWC_CRYPTOLIB
  44828. +
  44829. +#ifndef CONFIG_MACH_IPMATE
  44830. +
  44831. +#include "dwc_dh.h"
  44832. +#include "dwc_modpow.h"
  44833. +
  44834. +#ifdef DEBUG
  44835. +/* This function prints out a buffer in the format described in the Association
  44836. + * Model specification. */
  44837. +static void dh_dump(char *str, void *_num, int len)
  44838. +{
  44839. + uint8_t *num = _num;
  44840. + int i;
  44841. + DWC_PRINTF("%s\n", str);
  44842. + for (i = 0; i < len; i ++) {
  44843. + DWC_PRINTF("%02x", num[i]);
  44844. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  44845. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  44846. + }
  44847. +
  44848. + DWC_PRINTF("\n");
  44849. +}
  44850. +#else
  44851. +#define dh_dump(_x...) do {; } while(0)
  44852. +#endif
  44853. +
  44854. +/* Constant g value */
  44855. +static __u32 dh_g[] = {
  44856. + 0x02000000,
  44857. +};
  44858. +
  44859. +/* Constant p value */
  44860. +static __u32 dh_p[] = {
  44861. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  44862. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  44863. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  44864. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  44865. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  44866. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  44867. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  44868. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  44869. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  44870. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  44871. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  44872. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  44873. +};
  44874. +
  44875. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  44876. +{
  44877. + uint8_t *in = _in;
  44878. + uint8_t *out = _out;
  44879. + int i;
  44880. + for (i=0; i<len; i++) {
  44881. + out[i] = in[len-1-i];
  44882. + }
  44883. +}
  44884. +
  44885. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  44886. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  44887. + * of 4. */
  44888. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44889. + void *exp, uint32_t exp_len,
  44890. + void *mod, uint32_t mod_len,
  44891. + void *out)
  44892. +{
  44893. + /* modpow() takes little endian numbers. AM uses big-endian. This
  44894. + * function swaps bytes of numbers before passing onto modpow. */
  44895. +
  44896. + int retval = 0;
  44897. + uint32_t *result;
  44898. +
  44899. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  44900. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  44901. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  44902. +
  44903. + dh_swap_bytes(num, &bignum_num[1], num_len);
  44904. + bignum_num[0] = num_len / 4;
  44905. +
  44906. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  44907. + bignum_exp[0] = exp_len / 4;
  44908. +
  44909. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  44910. + bignum_mod[0] = mod_len / 4;
  44911. +
  44912. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  44913. + if (!result) {
  44914. + retval = -1;
  44915. + goto dh_modpow_nomem;
  44916. + }
  44917. +
  44918. + dh_swap_bytes(&result[1], out, result[0] * 4);
  44919. + dwc_free(mem_ctx, result);
  44920. +
  44921. + dh_modpow_nomem:
  44922. + dwc_free(mem_ctx, bignum_num);
  44923. + dwc_free(mem_ctx, bignum_exp);
  44924. + dwc_free(mem_ctx, bignum_mod);
  44925. + return retval;
  44926. +}
  44927. +
  44928. +
  44929. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  44930. +{
  44931. + int retval;
  44932. + uint8_t m3[385];
  44933. +
  44934. +#ifndef DH_TEST_VECTORS
  44935. + DWC_RANDOM_BYTES(exp, 32);
  44936. +#endif
  44937. +
  44938. + /* Compute the pkd */
  44939. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  44940. + exp, 32,
  44941. + dh_p, 384, pk))) {
  44942. + return retval;
  44943. + }
  44944. +
  44945. + m3[384] = nd;
  44946. + DWC_MEMCPY(&m3[0], pk, 384);
  44947. + DWC_SHA256(m3, 385, hash);
  44948. +
  44949. + dh_dump("PK", pk, 384);
  44950. + dh_dump("SHA-256(M3)", hash, 32);
  44951. + return 0;
  44952. +}
  44953. +
  44954. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44955. + uint8_t *exp, int is_host,
  44956. + char *dd, uint8_t *ck, uint8_t *kdk)
  44957. +{
  44958. + int retval;
  44959. + uint8_t mv[784];
  44960. + uint8_t sha_result[32];
  44961. + uint8_t dhkey[384];
  44962. + uint8_t shared_secret[384];
  44963. + char *message;
  44964. + uint32_t vd;
  44965. +
  44966. + uint8_t *pk;
  44967. +
  44968. + if (is_host) {
  44969. + pk = pkd;
  44970. + }
  44971. + else {
  44972. + pk = pkh;
  44973. + }
  44974. +
  44975. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  44976. + exp, 32,
  44977. + dh_p, 384, shared_secret))) {
  44978. + return retval;
  44979. + }
  44980. + dh_dump("Shared Secret", shared_secret, 384);
  44981. +
  44982. + DWC_SHA256(shared_secret, 384, dhkey);
  44983. + dh_dump("DHKEY", dhkey, 384);
  44984. +
  44985. + DWC_MEMCPY(&mv[0], pkd, 384);
  44986. + DWC_MEMCPY(&mv[384], pkh, 384);
  44987. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  44988. + dh_dump("MV", mv, 784);
  44989. +
  44990. + DWC_SHA256(mv, 784, sha_result);
  44991. + dh_dump("SHA-256(MV)", sha_result, 32);
  44992. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  44993. +
  44994. + dh_swap_bytes(sha_result, &vd, 4);
  44995. +#ifdef DEBUG
  44996. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  44997. +#endif
  44998. +
  44999. + switch (nd) {
  45000. + case 2:
  45001. + vd = vd % 100;
  45002. + DWC_SPRINTF(dd, "%02d", vd);
  45003. + break;
  45004. + case 3:
  45005. + vd = vd % 1000;
  45006. + DWC_SPRINTF(dd, "%03d", vd);
  45007. + break;
  45008. + case 4:
  45009. + vd = vd % 10000;
  45010. + DWC_SPRINTF(dd, "%04d", vd);
  45011. + break;
  45012. + }
  45013. +#ifdef DEBUG
  45014. + DWC_PRINTF("Display Digits: %s\n", dd);
  45015. +#endif
  45016. +
  45017. + message = "connection key";
  45018. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45019. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  45020. + DWC_MEMCPY(ck, sha_result, 16);
  45021. +
  45022. + message = "key derivation key";
  45023. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45024. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  45025. + DWC_MEMCPY(kdk, sha_result, 32);
  45026. +
  45027. + return 0;
  45028. +}
  45029. +
  45030. +
  45031. +#ifdef DH_TEST_VECTORS
  45032. +
  45033. +static __u8 dh_a[] = {
  45034. + 0x44, 0x00, 0x51, 0xd6,
  45035. + 0xf0, 0xb5, 0x5e, 0xa9,
  45036. + 0x67, 0xab, 0x31, 0xc6,
  45037. + 0x8a, 0x8b, 0x5e, 0x37,
  45038. + 0xd9, 0x10, 0xda, 0xe0,
  45039. + 0xe2, 0xd4, 0x59, 0xa4,
  45040. + 0x86, 0x45, 0x9c, 0xaa,
  45041. + 0xdf, 0x36, 0x75, 0x16,
  45042. +};
  45043. +
  45044. +static __u8 dh_b[] = {
  45045. + 0x5d, 0xae, 0xc7, 0x86,
  45046. + 0x79, 0x80, 0xa3, 0x24,
  45047. + 0x8c, 0xe3, 0x57, 0x8f,
  45048. + 0xc7, 0x5f, 0x1b, 0x0f,
  45049. + 0x2d, 0xf8, 0x9d, 0x30,
  45050. + 0x6f, 0xa4, 0x52, 0xcd,
  45051. + 0xe0, 0x7a, 0x04, 0x8a,
  45052. + 0xde, 0xd9, 0x26, 0x56,
  45053. +};
  45054. +
  45055. +void dwc_run_dh_test_vectors(void *mem_ctx)
  45056. +{
  45057. + uint8_t pkd[384];
  45058. + uint8_t pkh[384];
  45059. + uint8_t hashd[32];
  45060. + uint8_t hashh[32];
  45061. + uint8_t ck[16];
  45062. + uint8_t kdk[32];
  45063. + char dd[5];
  45064. +
  45065. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  45066. +
  45067. + /* compute the PKd and SHA-256(PKd || Nd) */
  45068. + DWC_PRINTF("Computing PKd\n");
  45069. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  45070. +
  45071. + /* compute the PKd and SHA-256(PKh || Nd) */
  45072. + DWC_PRINTF("Computing PKh\n");
  45073. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  45074. +
  45075. + /* compute the dhkey */
  45076. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  45077. +}
  45078. +#endif /* DH_TEST_VECTORS */
  45079. +
  45080. +#endif /* !CONFIG_MACH_IPMATE */
  45081. +
  45082. +#endif /* DWC_CRYPTOLIB */
  45083. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_dh.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_dh.h
  45084. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  45085. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-03-13 12:46:39.480097919 +0100
  45086. @@ -0,0 +1,106 @@
  45087. +/* =========================================================================
  45088. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  45089. + * $Revision: #4 $
  45090. + * $Date: 2010/09/28 $
  45091. + * $Change: 1596182 $
  45092. + *
  45093. + * Synopsys Portability Library Software and documentation
  45094. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45095. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45096. + * between Synopsys and you.
  45097. + *
  45098. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45099. + * under any End User Software License Agreement or Agreement for
  45100. + * Licensed Product with Synopsys or any supplement thereto. You are
  45101. + * permitted to use and redistribute this Software in source and binary
  45102. + * forms, with or without modification, provided that redistributions
  45103. + * of source code must retain this notice. You may not view, use,
  45104. + * disclose, copy or distribute this file or any information contained
  45105. + * herein except pursuant to this license grant from Synopsys. If you
  45106. + * do not agree with this notice, including the disclaimer below, then
  45107. + * you are not authorized to use the Software.
  45108. + *
  45109. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45110. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45111. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45112. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45113. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45114. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45115. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45116. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45117. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45118. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45119. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45120. + * DAMAGE.
  45121. + * ========================================================================= */
  45122. +#ifndef _DWC_DH_H_
  45123. +#define _DWC_DH_H_
  45124. +
  45125. +#ifdef __cplusplus
  45126. +extern "C" {
  45127. +#endif
  45128. +
  45129. +#include "dwc_os.h"
  45130. +
  45131. +/** @file
  45132. + *
  45133. + * This file defines the common functions on device and host for performing
  45134. + * numeric association as defined in the WUSB spec. They are only to be
  45135. + * used internally by the DWC UWB modules. */
  45136. +
  45137. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  45138. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  45139. + uint8_t *key, uint32_t keylen,
  45140. + uint8_t *out);
  45141. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  45142. + void *exp, uint32_t exp_len,
  45143. + void *mod, uint32_t mod_len,
  45144. + void *out);
  45145. +
  45146. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  45147. + *
  45148. + * PK = g^exp mod p.
  45149. + *
  45150. + * Input:
  45151. + * Nd = Number of digits on the device.
  45152. + *
  45153. + * Output:
  45154. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  45155. + * used as either A or B.
  45156. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  45157. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  45158. + */
  45159. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  45160. +
  45161. +/** Computes the DHKEY, and VD.
  45162. + *
  45163. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  45164. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  45165. + *
  45166. + * Input:
  45167. + * pkd = The PKD value.
  45168. + * pkh = The PKH value.
  45169. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  45170. + * is_host = Set to non zero if a WUSB host is calling this function.
  45171. + *
  45172. + * Output:
  45173. +
  45174. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  45175. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  45176. + * null termination character. This buffer can be used directly for display.
  45177. + * ck = A 16-byte buffer to be filled with the CK.
  45178. + * kdk = A 32-byte buffer to be filled with the KDK.
  45179. + */
  45180. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45181. + uint8_t *exp, int is_host,
  45182. + char *dd, uint8_t *ck, uint8_t *kdk);
  45183. +
  45184. +#ifdef DH_TEST_VECTORS
  45185. +extern void dwc_run_dh_test_vectors(void);
  45186. +#endif
  45187. +
  45188. +#ifdef __cplusplus
  45189. +}
  45190. +#endif
  45191. +
  45192. +#endif /* _DWC_DH_H_ */
  45193. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_list.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_list.h
  45194. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  45195. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_list.h 2014-03-13 12:46:39.480097919 +0100
  45196. @@ -0,0 +1,594 @@
  45197. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  45198. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  45199. +
  45200. +/*
  45201. + * Copyright (c) 1991, 1993
  45202. + * The Regents of the University of California. All rights reserved.
  45203. + *
  45204. + * Redistribution and use in source and binary forms, with or without
  45205. + * modification, are permitted provided that the following conditions
  45206. + * are met:
  45207. + * 1. Redistributions of source code must retain the above copyright
  45208. + * notice, this list of conditions and the following disclaimer.
  45209. + * 2. Redistributions in binary form must reproduce the above copyright
  45210. + * notice, this list of conditions and the following disclaimer in the
  45211. + * documentation and/or other materials provided with the distribution.
  45212. + * 3. Neither the name of the University nor the names of its contributors
  45213. + * may be used to endorse or promote products derived from this software
  45214. + * without specific prior written permission.
  45215. + *
  45216. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  45217. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45218. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  45219. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  45220. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45221. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  45222. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45223. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45224. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  45225. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  45226. + * SUCH DAMAGE.
  45227. + *
  45228. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  45229. + */
  45230. +
  45231. +#ifndef _DWC_LIST_H_
  45232. +#define _DWC_LIST_H_
  45233. +
  45234. +#ifdef __cplusplus
  45235. +extern "C" {
  45236. +#endif
  45237. +
  45238. +/** @file
  45239. + *
  45240. + * This file defines linked list operations. It is derived from BSD with
  45241. + * only the MACRO names being prefixed with DWC_. This is because a few of
  45242. + * these names conflict with those on Linux. For documentation on use, see the
  45243. + * inline comments in the source code. The original license for this source
  45244. + * code applies and is preserved in the dwc_list.h source file.
  45245. + */
  45246. +
  45247. +/*
  45248. + * This file defines five types of data structures: singly-linked lists,
  45249. + * lists, simple queues, tail queues, and circular queues.
  45250. + *
  45251. + *
  45252. + * A singly-linked list is headed by a single forward pointer. The elements
  45253. + * are singly linked for minimum space and pointer manipulation overhead at
  45254. + * the expense of O(n) removal for arbitrary elements. New elements can be
  45255. + * added to the list after an existing element or at the head of the list.
  45256. + * Elements being removed from the head of the list should use the explicit
  45257. + * macro for this purpose for optimum efficiency. A singly-linked list may
  45258. + * only be traversed in the forward direction. Singly-linked lists are ideal
  45259. + * for applications with large datasets and few or no removals or for
  45260. + * implementing a LIFO queue.
  45261. + *
  45262. + * A list is headed by a single forward pointer (or an array of forward
  45263. + * pointers for a hash table header). The elements are doubly linked
  45264. + * so that an arbitrary element can be removed without a need to
  45265. + * traverse the list. New elements can be added to the list before
  45266. + * or after an existing element or at the head of the list. A list
  45267. + * may only be traversed in the forward direction.
  45268. + *
  45269. + * A simple queue is headed by a pair of pointers, one the head of the
  45270. + * list and the other to the tail of the list. The elements are singly
  45271. + * linked to save space, so elements can only be removed from the
  45272. + * head of the list. New elements can be added to the list before or after
  45273. + * an existing element, at the head of the list, or at the end of the
  45274. + * list. A simple queue may only be traversed in the forward direction.
  45275. + *
  45276. + * A tail queue is headed by a pair of pointers, one to the head of the
  45277. + * list and the other to the tail of the list. The elements are doubly
  45278. + * linked so that an arbitrary element can be removed without a need to
  45279. + * traverse the list. New elements can be added to the list before or
  45280. + * after an existing element, at the head of the list, or at the end of
  45281. + * the list. A tail queue may be traversed in either direction.
  45282. + *
  45283. + * A circle queue is headed by a pair of pointers, one to the head of the
  45284. + * list and the other to the tail of the list. The elements are doubly
  45285. + * linked so that an arbitrary element can be removed without a need to
  45286. + * traverse the list. New elements can be added to the list before or after
  45287. + * an existing element, at the head of the list, or at the end of the list.
  45288. + * A circle queue may be traversed in either direction, but has a more
  45289. + * complex end of list detection.
  45290. + *
  45291. + * For details on the use of these macros, see the queue(3) manual page.
  45292. + */
  45293. +
  45294. +/*
  45295. + * Double-linked List.
  45296. + */
  45297. +
  45298. +typedef struct dwc_list_link {
  45299. + struct dwc_list_link *next;
  45300. + struct dwc_list_link *prev;
  45301. +} dwc_list_link_t;
  45302. +
  45303. +#define DWC_LIST_INIT(link) do { \
  45304. + (link)->next = (link); \
  45305. + (link)->prev = (link); \
  45306. +} while (0)
  45307. +
  45308. +#define DWC_LIST_FIRST(link) ((link)->next)
  45309. +#define DWC_LIST_LAST(link) ((link)->prev)
  45310. +#define DWC_LIST_END(link) (link)
  45311. +#define DWC_LIST_NEXT(link) ((link)->next)
  45312. +#define DWC_LIST_PREV(link) ((link)->prev)
  45313. +#define DWC_LIST_EMPTY(link) \
  45314. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  45315. +#define DWC_LIST_ENTRY(link, type, field) \
  45316. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  45317. +
  45318. +#if 0
  45319. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  45320. + (link)->next = (list)->next; \
  45321. + (link)->prev = (list); \
  45322. + (list)->next->prev = (link); \
  45323. + (list)->next = (link); \
  45324. +} while (0)
  45325. +
  45326. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  45327. + (link)->next = (list); \
  45328. + (link)->prev = (list)->prev; \
  45329. + (list)->prev->next = (link); \
  45330. + (list)->prev = (link); \
  45331. +} while (0)
  45332. +#else
  45333. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  45334. + dwc_list_link_t *__next__ = (list)->next; \
  45335. + __next__->prev = (link); \
  45336. + (link)->next = __next__; \
  45337. + (link)->prev = (list); \
  45338. + (list)->next = (link); \
  45339. +} while (0)
  45340. +
  45341. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  45342. + dwc_list_link_t *__prev__ = (list)->prev; \
  45343. + (list)->prev = (link); \
  45344. + (link)->next = (list); \
  45345. + (link)->prev = __prev__; \
  45346. + __prev__->next = (link); \
  45347. +} while (0)
  45348. +#endif
  45349. +
  45350. +#if 0
  45351. +static inline void __list_add(struct list_head *new,
  45352. + struct list_head *prev,
  45353. + struct list_head *next)
  45354. +{
  45355. + next->prev = new;
  45356. + new->next = next;
  45357. + new->prev = prev;
  45358. + prev->next = new;
  45359. +}
  45360. +
  45361. +static inline void list_add(struct list_head *new, struct list_head *head)
  45362. +{
  45363. + __list_add(new, head, head->next);
  45364. +}
  45365. +
  45366. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  45367. +{
  45368. + __list_add(new, head->prev, head);
  45369. +}
  45370. +
  45371. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  45372. +{
  45373. + next->prev = prev;
  45374. + prev->next = next;
  45375. +}
  45376. +
  45377. +static inline void list_del(struct list_head *entry)
  45378. +{
  45379. + __list_del(entry->prev, entry->next);
  45380. + entry->next = LIST_POISON1;
  45381. + entry->prev = LIST_POISON2;
  45382. +}
  45383. +#endif
  45384. +
  45385. +#define DWC_LIST_REMOVE(link) do { \
  45386. + (link)->next->prev = (link)->prev; \
  45387. + (link)->prev->next = (link)->next; \
  45388. +} while (0)
  45389. +
  45390. +#define DWC_LIST_REMOVE_INIT(link) do { \
  45391. + DWC_LIST_REMOVE(link); \
  45392. + DWC_LIST_INIT(link); \
  45393. +} while (0)
  45394. +
  45395. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  45396. + DWC_LIST_REMOVE(link); \
  45397. + DWC_LIST_INSERT_HEAD(list, link); \
  45398. +} while (0)
  45399. +
  45400. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  45401. + DWC_LIST_REMOVE(link); \
  45402. + DWC_LIST_INSERT_TAIL(list, link); \
  45403. +} while (0)
  45404. +
  45405. +#define DWC_LIST_FOREACH(var, list) \
  45406. + for((var) = DWC_LIST_FIRST(list); \
  45407. + (var) != DWC_LIST_END(list); \
  45408. + (var) = DWC_LIST_NEXT(var))
  45409. +
  45410. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  45411. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  45412. + (var) != DWC_LIST_END(list); \
  45413. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  45414. +
  45415. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  45416. + for((var) = DWC_LIST_LAST(list); \
  45417. + (var) != DWC_LIST_END(list); \
  45418. + (var) = DWC_LIST_PREV(var))
  45419. +
  45420. +/*
  45421. + * Singly-linked List definitions.
  45422. + */
  45423. +#define DWC_SLIST_HEAD(name, type) \
  45424. +struct name { \
  45425. + struct type *slh_first; /* first element */ \
  45426. +}
  45427. +
  45428. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  45429. + { NULL }
  45430. +
  45431. +#define DWC_SLIST_ENTRY(type) \
  45432. +struct { \
  45433. + struct type *sle_next; /* next element */ \
  45434. +}
  45435. +
  45436. +/*
  45437. + * Singly-linked List access methods.
  45438. + */
  45439. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  45440. +#define DWC_SLIST_END(head) NULL
  45441. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  45442. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  45443. +
  45444. +#define DWC_SLIST_FOREACH(var, head, field) \
  45445. + for((var) = SLIST_FIRST(head); \
  45446. + (var) != SLIST_END(head); \
  45447. + (var) = SLIST_NEXT(var, field))
  45448. +
  45449. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  45450. + for((varp) = &SLIST_FIRST((head)); \
  45451. + ((var) = *(varp)) != SLIST_END(head); \
  45452. + (varp) = &SLIST_NEXT((var), field))
  45453. +
  45454. +/*
  45455. + * Singly-linked List functions.
  45456. + */
  45457. +#define DWC_SLIST_INIT(head) { \
  45458. + SLIST_FIRST(head) = SLIST_END(head); \
  45459. +}
  45460. +
  45461. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  45462. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  45463. + (slistelm)->field.sle_next = (elm); \
  45464. +} while (0)
  45465. +
  45466. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  45467. + (elm)->field.sle_next = (head)->slh_first; \
  45468. + (head)->slh_first = (elm); \
  45469. +} while (0)
  45470. +
  45471. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  45472. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  45473. +} while (0)
  45474. +
  45475. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  45476. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  45477. +} while (0)
  45478. +
  45479. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  45480. + if ((head)->slh_first == (elm)) { \
  45481. + SLIST_REMOVE_HEAD((head), field); \
  45482. + } \
  45483. + else { \
  45484. + struct type *curelm = (head)->slh_first; \
  45485. + while( curelm->field.sle_next != (elm) ) \
  45486. + curelm = curelm->field.sle_next; \
  45487. + curelm->field.sle_next = \
  45488. + curelm->field.sle_next->field.sle_next; \
  45489. + } \
  45490. +} while (0)
  45491. +
  45492. +/*
  45493. + * Simple queue definitions.
  45494. + */
  45495. +#define DWC_SIMPLEQ_HEAD(name, type) \
  45496. +struct name { \
  45497. + struct type *sqh_first; /* first element */ \
  45498. + struct type **sqh_last; /* addr of last next element */ \
  45499. +}
  45500. +
  45501. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  45502. + { NULL, &(head).sqh_first }
  45503. +
  45504. +#define DWC_SIMPLEQ_ENTRY(type) \
  45505. +struct { \
  45506. + struct type *sqe_next; /* next element */ \
  45507. +}
  45508. +
  45509. +/*
  45510. + * Simple queue access methods.
  45511. + */
  45512. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  45513. +#define DWC_SIMPLEQ_END(head) NULL
  45514. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  45515. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  45516. +
  45517. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  45518. + for((var) = SIMPLEQ_FIRST(head); \
  45519. + (var) != SIMPLEQ_END(head); \
  45520. + (var) = SIMPLEQ_NEXT(var, field))
  45521. +
  45522. +/*
  45523. + * Simple queue functions.
  45524. + */
  45525. +#define DWC_SIMPLEQ_INIT(head) do { \
  45526. + (head)->sqh_first = NULL; \
  45527. + (head)->sqh_last = &(head)->sqh_first; \
  45528. +} while (0)
  45529. +
  45530. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  45531. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  45532. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45533. + (head)->sqh_first = (elm); \
  45534. +} while (0)
  45535. +
  45536. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  45537. + (elm)->field.sqe_next = NULL; \
  45538. + *(head)->sqh_last = (elm); \
  45539. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45540. +} while (0)
  45541. +
  45542. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45543. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  45544. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45545. + (listelm)->field.sqe_next = (elm); \
  45546. +} while (0)
  45547. +
  45548. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  45549. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  45550. + (head)->sqh_last = &(head)->sqh_first; \
  45551. +} while (0)
  45552. +
  45553. +/*
  45554. + * Tail queue definitions.
  45555. + */
  45556. +#define DWC_TAILQ_HEAD(name, type) \
  45557. +struct name { \
  45558. + struct type *tqh_first; /* first element */ \
  45559. + struct type **tqh_last; /* addr of last next element */ \
  45560. +}
  45561. +
  45562. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  45563. + { NULL, &(head).tqh_first }
  45564. +
  45565. +#define DWC_TAILQ_ENTRY(type) \
  45566. +struct { \
  45567. + struct type *tqe_next; /* next element */ \
  45568. + struct type **tqe_prev; /* address of previous next element */ \
  45569. +}
  45570. +
  45571. +/*
  45572. + * tail queue access methods
  45573. + */
  45574. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  45575. +#define DWC_TAILQ_END(head) NULL
  45576. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  45577. +#define DWC_TAILQ_LAST(head, headname) \
  45578. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  45579. +/* XXX */
  45580. +#define DWC_TAILQ_PREV(elm, headname, field) \
  45581. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  45582. +#define DWC_TAILQ_EMPTY(head) \
  45583. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  45584. +
  45585. +#define DWC_TAILQ_FOREACH(var, head, field) \
  45586. + for ((var) = DWC_TAILQ_FIRST(head); \
  45587. + (var) != DWC_TAILQ_END(head); \
  45588. + (var) = DWC_TAILQ_NEXT(var, field))
  45589. +
  45590. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  45591. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  45592. + (var) != DWC_TAILQ_END(head); \
  45593. + (var) = DWC_TAILQ_PREV(var, headname, field))
  45594. +
  45595. +/*
  45596. + * Tail queue functions.
  45597. + */
  45598. +#define DWC_TAILQ_INIT(head) do { \
  45599. + (head)->tqh_first = NULL; \
  45600. + (head)->tqh_last = &(head)->tqh_first; \
  45601. +} while (0)
  45602. +
  45603. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  45604. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  45605. + (head)->tqh_first->field.tqe_prev = \
  45606. + &(elm)->field.tqe_next; \
  45607. + else \
  45608. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45609. + (head)->tqh_first = (elm); \
  45610. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  45611. +} while (0)
  45612. +
  45613. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  45614. + (elm)->field.tqe_next = NULL; \
  45615. + (elm)->field.tqe_prev = (head)->tqh_last; \
  45616. + *(head)->tqh_last = (elm); \
  45617. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45618. +} while (0)
  45619. +
  45620. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45621. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  45622. + (elm)->field.tqe_next->field.tqe_prev = \
  45623. + &(elm)->field.tqe_next; \
  45624. + else \
  45625. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45626. + (listelm)->field.tqe_next = (elm); \
  45627. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  45628. +} while (0)
  45629. +
  45630. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  45631. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  45632. + (elm)->field.tqe_next = (listelm); \
  45633. + *(listelm)->field.tqe_prev = (elm); \
  45634. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  45635. +} while (0)
  45636. +
  45637. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  45638. + if (((elm)->field.tqe_next) != NULL) \
  45639. + (elm)->field.tqe_next->field.tqe_prev = \
  45640. + (elm)->field.tqe_prev; \
  45641. + else \
  45642. + (head)->tqh_last = (elm)->field.tqe_prev; \
  45643. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  45644. +} while (0)
  45645. +
  45646. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  45647. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  45648. + (elm2)->field.tqe_next->field.tqe_prev = \
  45649. + &(elm2)->field.tqe_next; \
  45650. + else \
  45651. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  45652. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  45653. + *(elm2)->field.tqe_prev = (elm2); \
  45654. +} while (0)
  45655. +
  45656. +/*
  45657. + * Circular queue definitions.
  45658. + */
  45659. +#define DWC_CIRCLEQ_HEAD(name, type) \
  45660. +struct name { \
  45661. + struct type *cqh_first; /* first element */ \
  45662. + struct type *cqh_last; /* last element */ \
  45663. +}
  45664. +
  45665. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  45666. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  45667. +
  45668. +#define DWC_CIRCLEQ_ENTRY(type) \
  45669. +struct { \
  45670. + struct type *cqe_next; /* next element */ \
  45671. + struct type *cqe_prev; /* previous element */ \
  45672. +}
  45673. +
  45674. +/*
  45675. + * Circular queue access methods
  45676. + */
  45677. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  45678. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  45679. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  45680. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  45681. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  45682. +#define DWC_CIRCLEQ_EMPTY(head) \
  45683. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  45684. +
  45685. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  45686. +
  45687. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  45688. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  45689. + (var) != DWC_CIRCLEQ_END(head); \
  45690. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  45691. +
  45692. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  45693. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  45694. + (var) != DWC_CIRCLEQ_END(head); \
  45695. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  45696. +
  45697. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  45698. + for((var) = DWC_CIRCLEQ_LAST(head); \
  45699. + (var) != DWC_CIRCLEQ_END(head); \
  45700. + (var) = DWC_CIRCLEQ_PREV(var, field))
  45701. +
  45702. +/*
  45703. + * Circular queue functions.
  45704. + */
  45705. +#define DWC_CIRCLEQ_INIT(head) do { \
  45706. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  45707. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  45708. +} while (0)
  45709. +
  45710. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  45711. + (elm)->field.cqe_next = NULL; \
  45712. + (elm)->field.cqe_prev = NULL; \
  45713. +} while (0)
  45714. +
  45715. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45716. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  45717. + (elm)->field.cqe_prev = (listelm); \
  45718. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45719. + (head)->cqh_last = (elm); \
  45720. + else \
  45721. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  45722. + (listelm)->field.cqe_next = (elm); \
  45723. +} while (0)
  45724. +
  45725. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  45726. + (elm)->field.cqe_next = (listelm); \
  45727. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  45728. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45729. + (head)->cqh_first = (elm); \
  45730. + else \
  45731. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  45732. + (listelm)->field.cqe_prev = (elm); \
  45733. +} while (0)
  45734. +
  45735. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  45736. + (elm)->field.cqe_next = (head)->cqh_first; \
  45737. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  45738. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  45739. + (head)->cqh_last = (elm); \
  45740. + else \
  45741. + (head)->cqh_first->field.cqe_prev = (elm); \
  45742. + (head)->cqh_first = (elm); \
  45743. +} while (0)
  45744. +
  45745. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  45746. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  45747. + (elm)->field.cqe_prev = (head)->cqh_last; \
  45748. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  45749. + (head)->cqh_first = (elm); \
  45750. + else \
  45751. + (head)->cqh_last->field.cqe_next = (elm); \
  45752. + (head)->cqh_last = (elm); \
  45753. +} while (0)
  45754. +
  45755. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  45756. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45757. + (head)->cqh_last = (elm)->field.cqe_prev; \
  45758. + else \
  45759. + (elm)->field.cqe_next->field.cqe_prev = \
  45760. + (elm)->field.cqe_prev; \
  45761. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45762. + (head)->cqh_first = (elm)->field.cqe_next; \
  45763. + else \
  45764. + (elm)->field.cqe_prev->field.cqe_next = \
  45765. + (elm)->field.cqe_next; \
  45766. +} while (0)
  45767. +
  45768. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  45769. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  45770. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  45771. +} while (0)
  45772. +
  45773. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  45774. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  45775. + DWC_CIRCLEQ_END(head)) \
  45776. + (head).cqh_last = (elm2); \
  45777. + else \
  45778. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  45779. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  45780. + DWC_CIRCLEQ_END(head)) \
  45781. + (head).cqh_first = (elm2); \
  45782. + else \
  45783. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  45784. +} while (0)
  45785. +
  45786. +#ifdef __cplusplus
  45787. +}
  45788. +#endif
  45789. +
  45790. +#endif /* _DWC_LIST_H_ */
  45791. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_mem.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_mem.c
  45792. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  45793. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-03-13 12:46:39.480097919 +0100
  45794. @@ -0,0 +1,245 @@
  45795. +/* Memory Debugging */
  45796. +#ifdef DWC_DEBUG_MEMORY
  45797. +
  45798. +#include "dwc_os.h"
  45799. +#include "dwc_list.h"
  45800. +
  45801. +struct allocation {
  45802. + void *addr;
  45803. + void *ctx;
  45804. + char *func;
  45805. + int line;
  45806. + uint32_t size;
  45807. + int dma;
  45808. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  45809. +};
  45810. +
  45811. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  45812. +
  45813. +struct allocation_manager {
  45814. + void *mem_ctx;
  45815. + struct allocation_queue allocations;
  45816. +
  45817. + /* statistics */
  45818. + int num;
  45819. + int num_freed;
  45820. + int num_active;
  45821. + uint32_t total;
  45822. + uint32_t cur;
  45823. + uint32_t max;
  45824. +};
  45825. +
  45826. +static struct allocation_manager *manager = NULL;
  45827. +
  45828. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  45829. + int dma)
  45830. +{
  45831. + struct allocation *a;
  45832. +
  45833. + DWC_ASSERT(manager != NULL, "manager not allocated");
  45834. +
  45835. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  45836. + if (!a) {
  45837. + return -DWC_E_NO_MEMORY;
  45838. + }
  45839. +
  45840. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  45841. + if (!a->func) {
  45842. + __DWC_FREE(manager->mem_ctx, a);
  45843. + return -DWC_E_NO_MEMORY;
  45844. + }
  45845. +
  45846. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  45847. + a->addr = addr;
  45848. + a->ctx = ctx;
  45849. + a->line = line;
  45850. + a->size = size;
  45851. + a->dma = dma;
  45852. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  45853. +
  45854. + /* Update stats */
  45855. + manager->num++;
  45856. + manager->num_active++;
  45857. + manager->total += size;
  45858. + manager->cur += size;
  45859. +
  45860. + if (manager->max < manager->cur) {
  45861. + manager->max = manager->cur;
  45862. + }
  45863. +
  45864. + return 0;
  45865. +}
  45866. +
  45867. +static struct allocation *find_allocation(void *ctx, void *addr)
  45868. +{
  45869. + struct allocation *a;
  45870. +
  45871. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45872. + if (a->ctx == ctx && a->addr == addr) {
  45873. + return a;
  45874. + }
  45875. + }
  45876. +
  45877. + return NULL;
  45878. +}
  45879. +
  45880. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  45881. +{
  45882. + struct allocation *a = find_allocation(ctx, addr);
  45883. +
  45884. + if (!a) {
  45885. + DWC_ASSERT(0,
  45886. + "Free of address %p that was never allocated or already freed %s:%d",
  45887. + addr, func, line);
  45888. + return;
  45889. + }
  45890. +
  45891. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  45892. +
  45893. + manager->num_active--;
  45894. + manager->num_freed++;
  45895. + manager->cur -= a->size;
  45896. + __DWC_FREE(manager->mem_ctx, a->func);
  45897. + __DWC_FREE(manager->mem_ctx, a);
  45898. +}
  45899. +
  45900. +int dwc_memory_debug_start(void *mem_ctx)
  45901. +{
  45902. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  45903. +
  45904. + if (manager) {
  45905. + return -DWC_E_BUSY;
  45906. + }
  45907. +
  45908. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  45909. + if (!manager) {
  45910. + return -DWC_E_NO_MEMORY;
  45911. + }
  45912. +
  45913. + DWC_CIRCLEQ_INIT(&manager->allocations);
  45914. + manager->mem_ctx = mem_ctx;
  45915. + manager->num = 0;
  45916. + manager->num_freed = 0;
  45917. + manager->num_active = 0;
  45918. + manager->total = 0;
  45919. + manager->cur = 0;
  45920. + manager->max = 0;
  45921. +
  45922. + return 0;
  45923. +}
  45924. +
  45925. +void dwc_memory_debug_stop(void)
  45926. +{
  45927. + struct allocation *a;
  45928. +
  45929. + dwc_memory_debug_report();
  45930. +
  45931. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45932. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  45933. + free_allocation(a->ctx, a->addr, NULL, -1);
  45934. + }
  45935. +
  45936. + __DWC_FREE(manager->mem_ctx, manager);
  45937. +}
  45938. +
  45939. +void dwc_memory_debug_report(void)
  45940. +{
  45941. + struct allocation *a;
  45942. +
  45943. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  45944. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  45945. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  45946. + DWC_PRINTF("Active = %d\n", manager->num_active);
  45947. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  45948. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  45949. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  45950. + DWC_PRINTF("Unfreed allocations:\n");
  45951. +
  45952. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45953. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  45954. + a->addr, a->size, a->func, a->line, a->dma);
  45955. + }
  45956. +}
  45957. +
  45958. +/* The replacement functions */
  45959. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  45960. +{
  45961. + void *addr = __DWC_ALLOC(mem_ctx, size);
  45962. +
  45963. + if (!addr) {
  45964. + return NULL;
  45965. + }
  45966. +
  45967. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45968. + __DWC_FREE(mem_ctx, addr);
  45969. + return NULL;
  45970. + }
  45971. +
  45972. + return addr;
  45973. +}
  45974. +
  45975. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  45976. + int line)
  45977. +{
  45978. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  45979. +
  45980. + if (!addr) {
  45981. + return NULL;
  45982. + }
  45983. +
  45984. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45985. + __DWC_FREE(mem_ctx, addr);
  45986. + return NULL;
  45987. + }
  45988. +
  45989. + return addr;
  45990. +}
  45991. +
  45992. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  45993. +{
  45994. + free_allocation(mem_ctx, addr, func, line);
  45995. + __DWC_FREE(mem_ctx, addr);
  45996. +}
  45997. +
  45998. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  45999. + char const *func, int line)
  46000. +{
  46001. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  46002. +
  46003. + if (!addr) {
  46004. + return NULL;
  46005. + }
  46006. +
  46007. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46008. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46009. + return NULL;
  46010. + }
  46011. +
  46012. + return addr;
  46013. +}
  46014. +
  46015. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  46016. + dwc_dma_t *dma_addr, char const *func, int line)
  46017. +{
  46018. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  46019. +
  46020. + if (!addr) {
  46021. + return NULL;
  46022. + }
  46023. +
  46024. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46025. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46026. + return NULL;
  46027. + }
  46028. +
  46029. + return addr;
  46030. +}
  46031. +
  46032. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46033. + dwc_dma_t dma_addr, char const *func, int line)
  46034. +{
  46035. + free_allocation(dma_ctx, virt_addr, func, line);
  46036. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  46037. +}
  46038. +
  46039. +#endif /* DWC_DEBUG_MEMORY */
  46040. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  46041. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  46042. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-03-13 12:46:39.480097919 +0100
  46043. @@ -0,0 +1,636 @@
  46044. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  46045. + *
  46046. + * PuTTY is copyright 1997-2007 Simon Tatham.
  46047. + *
  46048. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  46049. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  46050. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  46051. + * Kuhn, and CORE SDI S.A.
  46052. + *
  46053. + * Permission is hereby granted, free of charge, to any person
  46054. + * obtaining a copy of this software and associated documentation files
  46055. + * (the "Software"), to deal in the Software without restriction,
  46056. + * including without limitation the rights to use, copy, modify, merge,
  46057. + * publish, distribute, sublicense, and/or sell copies of the Software,
  46058. + * and to permit persons to whom the Software is furnished to do so,
  46059. + * subject to the following conditions:
  46060. + *
  46061. + * The above copyright notice and this permission notice shall be
  46062. + * included in all copies or substantial portions of the Software.
  46063. +
  46064. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46065. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  46066. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  46067. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  46068. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  46069. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  46070. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  46071. + *
  46072. + */
  46073. +#ifdef DWC_CRYPTOLIB
  46074. +
  46075. +#ifndef CONFIG_MACH_IPMATE
  46076. +
  46077. +#include "dwc_modpow.h"
  46078. +
  46079. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  46080. +#define BIGNUM_TOP_BIT 0x80000000UL
  46081. +#define BIGNUM_INT_BITS 32
  46082. +
  46083. +
  46084. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  46085. +{
  46086. + void *p;
  46087. + size *= n;
  46088. + if (size == 0) size = 1;
  46089. + p = dwc_alloc(mem_ctx, size);
  46090. + return p;
  46091. +}
  46092. +
  46093. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  46094. +#define sfree dwc_free
  46095. +
  46096. +/*
  46097. + * Usage notes:
  46098. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  46099. + * subscripts, as some implementations object to this (see below).
  46100. + * * Note that none of the division methods below will cope if the
  46101. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  46102. + * to avoid this case.
  46103. + * If this condition occurs, in the case of the x86 DIV instruction,
  46104. + * an overflow exception will occur, which (according to a correspondent)
  46105. + * will manifest on Windows as something like
  46106. + * 0xC0000095: Integer overflow
  46107. + * The C variant won't give the right answer, either.
  46108. + */
  46109. +
  46110. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  46111. +
  46112. +#if defined __GNUC__ && defined __i386__
  46113. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  46114. + __asm__("div %2" : \
  46115. + "=d" (r), "=a" (q) : \
  46116. + "r" (w), "d" (hi), "a" (lo))
  46117. +#else
  46118. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  46119. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  46120. + q = n / w; \
  46121. + r = n % w; \
  46122. +} while (0)
  46123. +#endif
  46124. +
  46125. +// q = n / w;
  46126. +// r = n % w;
  46127. +
  46128. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  46129. +
  46130. +#define BIGNUM_INTERNAL
  46131. +
  46132. +static Bignum newbn(void *mem_ctx, int length)
  46133. +{
  46134. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  46135. + //if (!b)
  46136. + //abort(); /* FIXME */
  46137. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  46138. + b[0] = length;
  46139. + return b;
  46140. +}
  46141. +
  46142. +void freebn(void *mem_ctx, Bignum b)
  46143. +{
  46144. + /*
  46145. + * Burn the evidence, just in case.
  46146. + */
  46147. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  46148. + sfree(mem_ctx, b);
  46149. +}
  46150. +
  46151. +/*
  46152. + * Compute c = a * b.
  46153. + * Input is in the first len words of a and b.
  46154. + * Result is returned in the first 2*len words of c.
  46155. + */
  46156. +static void internal_mul(BignumInt *a, BignumInt *b,
  46157. + BignumInt *c, int len)
  46158. +{
  46159. + int i, j;
  46160. + BignumDblInt t;
  46161. +
  46162. + for (j = 0; j < 2 * len; j++)
  46163. + c[j] = 0;
  46164. +
  46165. + for (i = len - 1; i >= 0; i--) {
  46166. + t = 0;
  46167. + for (j = len - 1; j >= 0; j--) {
  46168. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  46169. + t += (BignumDblInt) c[i + j + 1];
  46170. + c[i + j + 1] = (BignumInt) t;
  46171. + t = t >> BIGNUM_INT_BITS;
  46172. + }
  46173. + c[i] = (BignumInt) t;
  46174. + }
  46175. +}
  46176. +
  46177. +static void internal_add_shifted(BignumInt *number,
  46178. + unsigned n, int shift)
  46179. +{
  46180. + int word = 1 + (shift / BIGNUM_INT_BITS);
  46181. + int bshift = shift % BIGNUM_INT_BITS;
  46182. + BignumDblInt addend;
  46183. +
  46184. + addend = (BignumDblInt)n << bshift;
  46185. +
  46186. + while (addend) {
  46187. + addend += number[word];
  46188. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  46189. + addend >>= BIGNUM_INT_BITS;
  46190. + word++;
  46191. + }
  46192. +}
  46193. +
  46194. +/*
  46195. + * Compute a = a % m.
  46196. + * Input in first alen words of a and first mlen words of m.
  46197. + * Output in first alen words of a
  46198. + * (of which first alen-mlen words will be zero).
  46199. + * The MSW of m MUST have its high bit set.
  46200. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  46201. + * rather than the internal bigendian format. Quotient parts are shifted
  46202. + * left by `qshift' before adding into quot.
  46203. + */
  46204. +static void internal_mod(BignumInt *a, int alen,
  46205. + BignumInt *m, int mlen,
  46206. + BignumInt *quot, int qshift)
  46207. +{
  46208. + BignumInt m0, m1;
  46209. + unsigned int h;
  46210. + int i, k;
  46211. +
  46212. + m0 = m[0];
  46213. + if (mlen > 1)
  46214. + m1 = m[1];
  46215. + else
  46216. + m1 = 0;
  46217. +
  46218. + for (i = 0; i <= alen - mlen; i++) {
  46219. + BignumDblInt t;
  46220. + unsigned int q, r, c, ai1;
  46221. +
  46222. + if (i == 0) {
  46223. + h = 0;
  46224. + } else {
  46225. + h = a[i - 1];
  46226. + a[i - 1] = 0;
  46227. + }
  46228. +
  46229. + if (i == alen - 1)
  46230. + ai1 = 0;
  46231. + else
  46232. + ai1 = a[i + 1];
  46233. +
  46234. + /* Find q = h:a[i] / m0 */
  46235. + if (h >= m0) {
  46236. + /*
  46237. + * Special case.
  46238. + *
  46239. + * To illustrate it, suppose a BignumInt is 8 bits, and
  46240. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  46241. + * our initial division will be 0xA123 / 0xA1, which
  46242. + * will give a quotient of 0x100 and a divide overflow.
  46243. + * However, the invariants in this division algorithm
  46244. + * are not violated, since the full number A1:23:... is
  46245. + * _less_ than the quotient prefix A1:B2:... and so the
  46246. + * following correction loop would have sorted it out.
  46247. + *
  46248. + * In this situation we set q to be the largest
  46249. + * quotient we _can_ stomach (0xFF, of course).
  46250. + */
  46251. + q = BIGNUM_INT_MASK;
  46252. + } else {
  46253. + /* Macro doesn't want an array subscript expression passed
  46254. + * into it (see definition), so use a temporary. */
  46255. + BignumInt tmplo = a[i];
  46256. + DIVMOD_WORD(q, r, h, tmplo, m0);
  46257. +
  46258. + /* Refine our estimate of q by looking at
  46259. + h:a[i]:a[i+1] / m0:m1 */
  46260. + t = MUL_WORD(m1, q);
  46261. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  46262. + q--;
  46263. + t -= m1;
  46264. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  46265. + if (r >= (BignumDblInt) m0 &&
  46266. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  46267. + }
  46268. + }
  46269. +
  46270. + /* Subtract q * m from a[i...] */
  46271. + c = 0;
  46272. + for (k = mlen - 1; k >= 0; k--) {
  46273. + t = MUL_WORD(q, m[k]);
  46274. + t += c;
  46275. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  46276. + if ((BignumInt) t > a[i + k])
  46277. + c++;
  46278. + a[i + k] -= (BignumInt) t;
  46279. + }
  46280. +
  46281. + /* Add back m in case of borrow */
  46282. + if (c != h) {
  46283. + t = 0;
  46284. + for (k = mlen - 1; k >= 0; k--) {
  46285. + t += m[k];
  46286. + t += a[i + k];
  46287. + a[i + k] = (BignumInt) t;
  46288. + t = t >> BIGNUM_INT_BITS;
  46289. + }
  46290. + q--;
  46291. + }
  46292. + if (quot)
  46293. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  46294. + }
  46295. +}
  46296. +
  46297. +/*
  46298. + * Compute p % mod.
  46299. + * The most significant word of mod MUST be non-zero.
  46300. + * We assume that the result array is the same size as the mod array.
  46301. + * We optionally write out a quotient if `quotient' is non-NULL.
  46302. + * We can avoid writing out the result if `result' is NULL.
  46303. + */
  46304. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  46305. +{
  46306. + BignumInt *n, *m;
  46307. + int mshift;
  46308. + int plen, mlen, i, j;
  46309. +
  46310. + /* Allocate m of size mlen, copy mod to m */
  46311. + /* We use big endian internally */
  46312. + mlen = mod[0];
  46313. + m = snewn(mem_ctx, mlen, BignumInt);
  46314. + //if (!m)
  46315. + //abort(); /* FIXME */
  46316. + for (j = 0; j < mlen; j++)
  46317. + m[j] = mod[mod[0] - j];
  46318. +
  46319. + /* Shift m left to make msb bit set */
  46320. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  46321. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  46322. + break;
  46323. + if (mshift) {
  46324. + for (i = 0; i < mlen - 1; i++)
  46325. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  46326. + m[mlen - 1] = m[mlen - 1] << mshift;
  46327. + }
  46328. +
  46329. + plen = p[0];
  46330. + /* Ensure plen > mlen */
  46331. + if (plen <= mlen)
  46332. + plen = mlen + 1;
  46333. +
  46334. + /* Allocate n of size plen, copy p to n */
  46335. + n = snewn(mem_ctx, plen, BignumInt);
  46336. + //if (!n)
  46337. + //abort(); /* FIXME */
  46338. + for (j = 0; j < plen; j++)
  46339. + n[j] = 0;
  46340. + for (j = 1; j <= (int)p[0]; j++)
  46341. + n[plen - j] = p[j];
  46342. +
  46343. + /* Main computation */
  46344. + internal_mod(n, plen, m, mlen, quotient, mshift);
  46345. +
  46346. + /* Fixup result in case the modulus was shifted */
  46347. + if (mshift) {
  46348. + for (i = plen - mlen - 1; i < plen - 1; i++)
  46349. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  46350. + n[plen - 1] = n[plen - 1] << mshift;
  46351. + internal_mod(n, plen, m, mlen, quotient, 0);
  46352. + for (i = plen - 1; i >= plen - mlen; i--)
  46353. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  46354. + }
  46355. +
  46356. + /* Copy result to buffer */
  46357. + if (result) {
  46358. + for (i = 1; i <= (int)result[0]; i++) {
  46359. + int j = plen - i;
  46360. + result[i] = j >= 0 ? n[j] : 0;
  46361. + }
  46362. + }
  46363. +
  46364. + /* Free temporary arrays */
  46365. + for (i = 0; i < mlen; i++)
  46366. + m[i] = 0;
  46367. + sfree(mem_ctx, m);
  46368. + for (i = 0; i < plen; i++)
  46369. + n[i] = 0;
  46370. + sfree(mem_ctx, n);
  46371. +}
  46372. +
  46373. +/*
  46374. + * Simple remainder.
  46375. + */
  46376. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  46377. +{
  46378. + Bignum r = newbn(mem_ctx, b[0]);
  46379. + bigdivmod(mem_ctx, a, b, r, NULL);
  46380. + return r;
  46381. +}
  46382. +
  46383. +/*
  46384. + * Compute (base ^ exp) % mod.
  46385. + */
  46386. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  46387. +{
  46388. + BignumInt *a, *b, *n, *m;
  46389. + int mshift;
  46390. + int mlen, i, j;
  46391. + Bignum base, result;
  46392. +
  46393. + /*
  46394. + * The most significant word of mod needs to be non-zero. It
  46395. + * should already be, but let's make sure.
  46396. + */
  46397. + //assert(mod[mod[0]] != 0);
  46398. +
  46399. + /*
  46400. + * Make sure the base is smaller than the modulus, by reducing
  46401. + * it modulo the modulus if not.
  46402. + */
  46403. + base = bigmod(mem_ctx, base_in, mod);
  46404. +
  46405. + /* Allocate m of size mlen, copy mod to m */
  46406. + /* We use big endian internally */
  46407. + mlen = mod[0];
  46408. + m = snewn(mem_ctx, mlen, BignumInt);
  46409. + //if (!m)
  46410. + //abort(); /* FIXME */
  46411. + for (j = 0; j < mlen; j++)
  46412. + m[j] = mod[mod[0] - j];
  46413. +
  46414. + /* Shift m left to make msb bit set */
  46415. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  46416. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  46417. + break;
  46418. + if (mshift) {
  46419. + for (i = 0; i < mlen - 1; i++)
  46420. + m[i] =
  46421. + (m[i] << mshift) | (m[i + 1] >>
  46422. + (BIGNUM_INT_BITS - mshift));
  46423. + m[mlen - 1] = m[mlen - 1] << mshift;
  46424. + }
  46425. +
  46426. + /* Allocate n of size mlen, copy base to n */
  46427. + n = snewn(mem_ctx, mlen, BignumInt);
  46428. + //if (!n)
  46429. + //abort(); /* FIXME */
  46430. + i = mlen - base[0];
  46431. + for (j = 0; j < i; j++)
  46432. + n[j] = 0;
  46433. + for (j = 0; j < base[0]; j++)
  46434. + n[i + j] = base[base[0] - j];
  46435. +
  46436. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  46437. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  46438. + //if (!a)
  46439. + //abort(); /* FIXME */
  46440. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  46441. + //if (!b)
  46442. + //abort(); /* FIXME */
  46443. + for (i = 0; i < 2 * mlen; i++)
  46444. + a[i] = 0;
  46445. + a[2 * mlen - 1] = 1;
  46446. +
  46447. + /* Skip leading zero bits of exp. */
  46448. + i = 0;
  46449. + j = BIGNUM_INT_BITS - 1;
  46450. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  46451. + j--;
  46452. + if (j < 0) {
  46453. + i++;
  46454. + j = BIGNUM_INT_BITS - 1;
  46455. + }
  46456. + }
  46457. +
  46458. + /* Main computation */
  46459. + while (i < exp[0]) {
  46460. + while (j >= 0) {
  46461. + internal_mul(a + mlen, a + mlen, b, mlen);
  46462. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  46463. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  46464. + internal_mul(b + mlen, n, a, mlen);
  46465. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  46466. + } else {
  46467. + BignumInt *t;
  46468. + t = a;
  46469. + a = b;
  46470. + b = t;
  46471. + }
  46472. + j--;
  46473. + }
  46474. + i++;
  46475. + j = BIGNUM_INT_BITS - 1;
  46476. + }
  46477. +
  46478. + /* Fixup result in case the modulus was shifted */
  46479. + if (mshift) {
  46480. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  46481. + a[i] =
  46482. + (a[i] << mshift) | (a[i + 1] >>
  46483. + (BIGNUM_INT_BITS - mshift));
  46484. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  46485. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  46486. + for (i = 2 * mlen - 1; i >= mlen; i--)
  46487. + a[i] =
  46488. + (a[i] >> mshift) | (a[i - 1] <<
  46489. + (BIGNUM_INT_BITS - mshift));
  46490. + }
  46491. +
  46492. + /* Copy result to buffer */
  46493. + result = newbn(mem_ctx, mod[0]);
  46494. + for (i = 0; i < mlen; i++)
  46495. + result[result[0] - i] = a[i + mlen];
  46496. + while (result[0] > 1 && result[result[0]] == 0)
  46497. + result[0]--;
  46498. +
  46499. + /* Free temporary arrays */
  46500. + for (i = 0; i < 2 * mlen; i++)
  46501. + a[i] = 0;
  46502. + sfree(mem_ctx, a);
  46503. + for (i = 0; i < 2 * mlen; i++)
  46504. + b[i] = 0;
  46505. + sfree(mem_ctx, b);
  46506. + for (i = 0; i < mlen; i++)
  46507. + m[i] = 0;
  46508. + sfree(mem_ctx, m);
  46509. + for (i = 0; i < mlen; i++)
  46510. + n[i] = 0;
  46511. + sfree(mem_ctx, n);
  46512. +
  46513. + freebn(mem_ctx, base);
  46514. +
  46515. + return result;
  46516. +}
  46517. +
  46518. +
  46519. +#ifdef UNITTEST
  46520. +
  46521. +static __u32 dh_p[] = {
  46522. + 96,
  46523. + 0xFFFFFFFF,
  46524. + 0xFFFFFFFF,
  46525. + 0xA93AD2CA,
  46526. + 0x4B82D120,
  46527. + 0xE0FD108E,
  46528. + 0x43DB5BFC,
  46529. + 0x74E5AB31,
  46530. + 0x08E24FA0,
  46531. + 0xBAD946E2,
  46532. + 0x770988C0,
  46533. + 0x7A615D6C,
  46534. + 0xBBE11757,
  46535. + 0x177B200C,
  46536. + 0x521F2B18,
  46537. + 0x3EC86A64,
  46538. + 0xD8760273,
  46539. + 0xD98A0864,
  46540. + 0xF12FFA06,
  46541. + 0x1AD2EE6B,
  46542. + 0xCEE3D226,
  46543. + 0x4A25619D,
  46544. + 0x1E8C94E0,
  46545. + 0xDB0933D7,
  46546. + 0xABF5AE8C,
  46547. + 0xA6E1E4C7,
  46548. + 0xB3970F85,
  46549. + 0x5D060C7D,
  46550. + 0x8AEA7157,
  46551. + 0x58DBEF0A,
  46552. + 0xECFB8504,
  46553. + 0xDF1CBA64,
  46554. + 0xA85521AB,
  46555. + 0x04507A33,
  46556. + 0xAD33170D,
  46557. + 0x8AAAC42D,
  46558. + 0x15728E5A,
  46559. + 0x98FA0510,
  46560. + 0x15D22618,
  46561. + 0xEA956AE5,
  46562. + 0x3995497C,
  46563. + 0x95581718,
  46564. + 0xDE2BCBF6,
  46565. + 0x6F4C52C9,
  46566. + 0xB5C55DF0,
  46567. + 0xEC07A28F,
  46568. + 0x9B2783A2,
  46569. + 0x180E8603,
  46570. + 0xE39E772C,
  46571. + 0x2E36CE3B,
  46572. + 0x32905E46,
  46573. + 0xCA18217C,
  46574. + 0xF1746C08,
  46575. + 0x4ABC9804,
  46576. + 0x670C354E,
  46577. + 0x7096966D,
  46578. + 0x9ED52907,
  46579. + 0x208552BB,
  46580. + 0x1C62F356,
  46581. + 0xDCA3AD96,
  46582. + 0x83655D23,
  46583. + 0xFD24CF5F,
  46584. + 0x69163FA8,
  46585. + 0x1C55D39A,
  46586. + 0x98DA4836,
  46587. + 0xA163BF05,
  46588. + 0xC2007CB8,
  46589. + 0xECE45B3D,
  46590. + 0x49286651,
  46591. + 0x7C4B1FE6,
  46592. + 0xAE9F2411,
  46593. + 0x5A899FA5,
  46594. + 0xEE386BFB,
  46595. + 0xF406B7ED,
  46596. + 0x0BFF5CB6,
  46597. + 0xA637ED6B,
  46598. + 0xF44C42E9,
  46599. + 0x625E7EC6,
  46600. + 0xE485B576,
  46601. + 0x6D51C245,
  46602. + 0x4FE1356D,
  46603. + 0xF25F1437,
  46604. + 0x302B0A6D,
  46605. + 0xCD3A431B,
  46606. + 0xEF9519B3,
  46607. + 0x8E3404DD,
  46608. + 0x514A0879,
  46609. + 0x3B139B22,
  46610. + 0x020BBEA6,
  46611. + 0x8A67CC74,
  46612. + 0x29024E08,
  46613. + 0x80DC1CD1,
  46614. + 0xC4C6628B,
  46615. + 0x2168C234,
  46616. + 0xC90FDAA2,
  46617. + 0xFFFFFFFF,
  46618. + 0xFFFFFFFF,
  46619. +};
  46620. +
  46621. +static __u32 dh_a[] = {
  46622. + 8,
  46623. + 0xdf367516,
  46624. + 0x86459caa,
  46625. + 0xe2d459a4,
  46626. + 0xd910dae0,
  46627. + 0x8a8b5e37,
  46628. + 0x67ab31c6,
  46629. + 0xf0b55ea9,
  46630. + 0x440051d6,
  46631. +};
  46632. +
  46633. +static __u32 dh_b[] = {
  46634. + 8,
  46635. + 0xded92656,
  46636. + 0xe07a048a,
  46637. + 0x6fa452cd,
  46638. + 0x2df89d30,
  46639. + 0xc75f1b0f,
  46640. + 0x8ce3578f,
  46641. + 0x7980a324,
  46642. + 0x5daec786,
  46643. +};
  46644. +
  46645. +static __u32 dh_g[] = {
  46646. + 1,
  46647. + 2,
  46648. +};
  46649. +
  46650. +int main(void)
  46651. +{
  46652. + int i;
  46653. + __u32 *k;
  46654. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  46655. +
  46656. + printf("\n\n");
  46657. + for (i=0; i<k[0]; i++) {
  46658. + __u32 word32 = k[k[0] - i];
  46659. + __u16 l = word32 & 0xffff;
  46660. + __u16 m = (word32 & 0xffff0000) >> 16;
  46661. + printf("%04x %04x ", m, l);
  46662. + if (!((i + 1)%13)) printf("\n");
  46663. + }
  46664. + printf("\n\n");
  46665. +
  46666. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  46667. + printf("PASS\n\n");
  46668. + }
  46669. + else {
  46670. + printf("FAIL\n\n");
  46671. + }
  46672. +
  46673. +}
  46674. +
  46675. +#endif /* UNITTEST */
  46676. +
  46677. +#endif /* CONFIG_MACH_IPMATE */
  46678. +
  46679. +#endif /*DWC_CRYPTOLIB */
  46680. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  46681. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  46682. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-03-13 12:46:39.480097919 +0100
  46683. @@ -0,0 +1,34 @@
  46684. +/*
  46685. + * dwc_modpow.h
  46686. + * See dwc_modpow.c for license and changes
  46687. + */
  46688. +#ifndef _DWC_MODPOW_H
  46689. +#define _DWC_MODPOW_H
  46690. +
  46691. +#ifdef __cplusplus
  46692. +extern "C" {
  46693. +#endif
  46694. +
  46695. +#include "dwc_os.h"
  46696. +
  46697. +/** @file
  46698. + *
  46699. + * This file defines the module exponentiation function which is only used
  46700. + * internally by the DWC UWB modules for calculation of PKs during numeric
  46701. + * association. The routine is taken from the PUTTY, an open source terminal
  46702. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  46703. + *
  46704. + */
  46705. +
  46706. +typedef uint32_t BignumInt;
  46707. +typedef uint64_t BignumDblInt;
  46708. +typedef BignumInt *Bignum;
  46709. +
  46710. +/* Compute modular exponentiaion */
  46711. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  46712. +
  46713. +#ifdef __cplusplus
  46714. +}
  46715. +#endif
  46716. +
  46717. +#endif /* _LINUX_BIGNUM_H */
  46718. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  46719. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  46720. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-03-13 12:46:39.480097919 +0100
  46721. @@ -0,0 +1,319 @@
  46722. +#ifdef DWC_NOTIFYLIB
  46723. +
  46724. +#include "dwc_notifier.h"
  46725. +#include "dwc_list.h"
  46726. +
  46727. +typedef struct dwc_observer {
  46728. + void *observer;
  46729. + dwc_notifier_callback_t callback;
  46730. + void *data;
  46731. + char *notification;
  46732. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  46733. +} observer_t;
  46734. +
  46735. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  46736. +
  46737. +typedef struct dwc_notifier {
  46738. + void *mem_ctx;
  46739. + void *object;
  46740. + struct observer_queue observers;
  46741. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  46742. +} notifier_t;
  46743. +
  46744. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  46745. +
  46746. +typedef struct manager {
  46747. + void *mem_ctx;
  46748. + void *wkq_ctx;
  46749. + dwc_workq_t *wq;
  46750. +// dwc_mutex_t *mutex;
  46751. + struct notifier_queue notifiers;
  46752. +} manager_t;
  46753. +
  46754. +static manager_t *manager = NULL;
  46755. +
  46756. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  46757. +{
  46758. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  46759. + if (!manager) {
  46760. + return -DWC_E_NO_MEMORY;
  46761. + }
  46762. +
  46763. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  46764. +
  46765. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  46766. + if (!manager->wq) {
  46767. + return -DWC_E_NO_MEMORY;
  46768. + }
  46769. +
  46770. + return 0;
  46771. +}
  46772. +
  46773. +static void free_manager(void)
  46774. +{
  46775. + dwc_workq_free(manager->wq);
  46776. +
  46777. + /* All notifiers must have unregistered themselves before this module
  46778. + * can be removed. Hitting this assertion indicates a programmer
  46779. + * error. */
  46780. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  46781. + "Notification manager being freed before all notifiers have been removed");
  46782. + dwc_free(manager->mem_ctx, manager);
  46783. +}
  46784. +
  46785. +#ifdef DEBUG
  46786. +static void dump_manager(void)
  46787. +{
  46788. + notifier_t *n;
  46789. + observer_t *o;
  46790. +
  46791. + DWC_ASSERT(manager, "Notification manager not found");
  46792. +
  46793. + DWC_DEBUG("List of all notifiers and observers:\n");
  46794. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46795. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  46796. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  46797. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  46798. + }
  46799. + }
  46800. +}
  46801. +#else
  46802. +#define dump_manager(...)
  46803. +#endif
  46804. +
  46805. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  46806. + dwc_notifier_callback_t callback, void *data)
  46807. +{
  46808. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  46809. +
  46810. + if (!new_observer) {
  46811. + return NULL;
  46812. + }
  46813. +
  46814. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  46815. + new_observer->observer = observer;
  46816. + new_observer->notification = notification;
  46817. + new_observer->callback = callback;
  46818. + new_observer->data = data;
  46819. + return new_observer;
  46820. +}
  46821. +
  46822. +static void free_observer(void *mem_ctx, observer_t *observer)
  46823. +{
  46824. + dwc_free(mem_ctx, observer);
  46825. +}
  46826. +
  46827. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  46828. +{
  46829. + notifier_t *notifier;
  46830. +
  46831. + if (!object) {
  46832. + return NULL;
  46833. + }
  46834. +
  46835. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  46836. + if (!notifier) {
  46837. + return NULL;
  46838. + }
  46839. +
  46840. + DWC_CIRCLEQ_INIT(&notifier->observers);
  46841. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  46842. +
  46843. + notifier->mem_ctx = mem_ctx;
  46844. + notifier->object = object;
  46845. + return notifier;
  46846. +}
  46847. +
  46848. +static void free_notifier(notifier_t *notifier)
  46849. +{
  46850. + observer_t *observer;
  46851. +
  46852. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  46853. + free_observer(notifier->mem_ctx, observer);
  46854. + }
  46855. +
  46856. + dwc_free(notifier->mem_ctx, notifier);
  46857. +}
  46858. +
  46859. +static notifier_t *find_notifier(void *object)
  46860. +{
  46861. + notifier_t *notifier;
  46862. +
  46863. + DWC_ASSERT(manager, "Notification manager not found");
  46864. +
  46865. + if (!object) {
  46866. + return NULL;
  46867. + }
  46868. +
  46869. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  46870. + if (notifier->object == object) {
  46871. + return notifier;
  46872. + }
  46873. + }
  46874. +
  46875. + return NULL;
  46876. +}
  46877. +
  46878. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  46879. +{
  46880. + return create_manager(mem_ctx, wkq_ctx);
  46881. +}
  46882. +
  46883. +void dwc_free_notification_manager(void)
  46884. +{
  46885. + free_manager();
  46886. +}
  46887. +
  46888. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  46889. +{
  46890. + notifier_t *notifier;
  46891. +
  46892. + DWC_ASSERT(manager, "Notification manager not found");
  46893. +
  46894. + notifier = find_notifier(object);
  46895. + if (notifier) {
  46896. + DWC_ERROR("Notifier %p is already registered\n", object);
  46897. + return NULL;
  46898. + }
  46899. +
  46900. + notifier = alloc_notifier(mem_ctx, object);
  46901. + if (!notifier) {
  46902. + return NULL;
  46903. + }
  46904. +
  46905. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  46906. +
  46907. + DWC_INFO("Notifier %p registered", object);
  46908. + dump_manager();
  46909. +
  46910. + return notifier;
  46911. +}
  46912. +
  46913. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  46914. +{
  46915. + DWC_ASSERT(manager, "Notification manager not found");
  46916. +
  46917. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  46918. + observer_t *o;
  46919. +
  46920. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  46921. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46922. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  46923. + }
  46924. +
  46925. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  46926. + "Notifier %p has active observers when removing", notifier);
  46927. + }
  46928. +
  46929. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  46930. + free_notifier(notifier);
  46931. +
  46932. + DWC_INFO("Notifier unregistered");
  46933. + dump_manager();
  46934. +}
  46935. +
  46936. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  46937. +int dwc_add_observer(void *observer, void *object, char *notification,
  46938. + dwc_notifier_callback_t callback, void *data)
  46939. +{
  46940. + notifier_t *notifier = find_notifier(object);
  46941. + observer_t *new_observer;
  46942. +
  46943. + if (!notifier) {
  46944. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  46945. + return -DWC_E_INVALID;
  46946. + }
  46947. +
  46948. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  46949. + if (!new_observer) {
  46950. + return -DWC_E_NO_MEMORY;
  46951. + }
  46952. +
  46953. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  46954. +
  46955. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  46956. + observer, object, notification, callback, data);
  46957. +
  46958. + dump_manager();
  46959. + return 0;
  46960. +}
  46961. +
  46962. +int dwc_remove_observer(void *observer)
  46963. +{
  46964. + notifier_t *n;
  46965. +
  46966. + DWC_ASSERT(manager, "Notification manager not found");
  46967. +
  46968. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46969. + observer_t *o;
  46970. + observer_t *o2;
  46971. +
  46972. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  46973. + if (o->observer == observer) {
  46974. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  46975. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  46976. + o->observer, n->object, o->notification);
  46977. + free_observer(n->mem_ctx, o);
  46978. + }
  46979. + }
  46980. + }
  46981. +
  46982. + dump_manager();
  46983. + return 0;
  46984. +}
  46985. +
  46986. +typedef struct callback_data {
  46987. + void *mem_ctx;
  46988. + dwc_notifier_callback_t cb;
  46989. + void *observer;
  46990. + void *data;
  46991. + void *object;
  46992. + char *notification;
  46993. + void *notification_data;
  46994. +} cb_data_t;
  46995. +
  46996. +static void cb_task(void *data)
  46997. +{
  46998. + cb_data_t *cb = (cb_data_t *)data;
  46999. +
  47000. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  47001. + dwc_free(cb->mem_ctx, cb);
  47002. +}
  47003. +
  47004. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  47005. +{
  47006. + observer_t *o;
  47007. +
  47008. + DWC_ASSERT(manager, "Notification manager not found");
  47009. +
  47010. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  47011. + int len = DWC_STRLEN(notification);
  47012. +
  47013. + if (DWC_STRLEN(o->notification) != len) {
  47014. + continue;
  47015. + }
  47016. +
  47017. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  47018. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  47019. +
  47020. + if (!cb_data) {
  47021. + DWC_ERROR("Failed to allocate callback data\n");
  47022. + return;
  47023. + }
  47024. +
  47025. + cb_data->mem_ctx = notifier->mem_ctx;
  47026. + cb_data->cb = o->callback;
  47027. + cb_data->observer = o->observer;
  47028. + cb_data->data = o->data;
  47029. + cb_data->object = notifier->object;
  47030. + cb_data->notification = notification;
  47031. + cb_data->notification_data = notification_data;
  47032. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  47033. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  47034. + "Notify callback from %p for Notification %s, to observer %p",
  47035. + cb_data->object, notification, cb_data->observer);
  47036. + }
  47037. + }
  47038. +}
  47039. +
  47040. +#endif /* DWC_NOTIFYLIB */
  47041. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  47042. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  47043. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-03-13 12:46:39.480097919 +0100
  47044. @@ -0,0 +1,122 @@
  47045. +
  47046. +#ifndef __DWC_NOTIFIER_H__
  47047. +#define __DWC_NOTIFIER_H__
  47048. +
  47049. +#ifdef __cplusplus
  47050. +extern "C" {
  47051. +#endif
  47052. +
  47053. +#include "dwc_os.h"
  47054. +
  47055. +/** @file
  47056. + *
  47057. + * A simple implementation of the Observer pattern. Any "module" can
  47058. + * register as an observer or notifier. The notion of "module" is abstract and
  47059. + * can mean anything used to identify either an observer or notifier. Usually
  47060. + * it will be a pointer to a data structure which contains some state, ie an
  47061. + * object.
  47062. + *
  47063. + * Before any notifiers can be added, the global notification manager must be
  47064. + * brought up with dwc_alloc_notification_manager().
  47065. + * dwc_free_notification_manager() will bring it down and free all resources.
  47066. + * These would typically be called upon module load and unload. The
  47067. + * notification manager is a single global instance that handles all registered
  47068. + * observable modules and observers so this should be done only once.
  47069. + *
  47070. + * A module can be observable by using Notifications to publicize some general
  47071. + * information about it's state or operation. It does not care who listens, or
  47072. + * even if anyone listens, or what they do with the information. The observable
  47073. + * modules do not need to know any information about it's observers or their
  47074. + * interface, or their state or data.
  47075. + *
  47076. + * Any module can register to emit Notifications. It should publish a list of
  47077. + * notifications that it can emit and their behavior, such as when they will get
  47078. + * triggered, and what information will be provided to the observer. Then it
  47079. + * should register itself as an observable module. See dwc_register_notifier().
  47080. + *
  47081. + * Any module can observe any observable, registered module, provided it has a
  47082. + * handle to the other module and knows what notifications to observe. See
  47083. + * dwc_add_observer().
  47084. + *
  47085. + * A function of type dwc_notifier_callback_t is called whenever a notification
  47086. + * is triggered with one or more observers observing it. This function is
  47087. + * called in it's own process so it may sleep or block if needed. It is
  47088. + * guaranteed to be called sometime after the notification has occurred and will
  47089. + * be called once per each time the notification is triggered. It will NOT be
  47090. + * called in the same process context used to trigger the notification.
  47091. + *
  47092. + * @section Limitiations
  47093. + *
  47094. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  47095. + * schedule too many processes too handle. Be aware of this limitation when
  47096. + * designing to use notifications, and only add notifications for appropriate
  47097. + * observable information.
  47098. + *
  47099. + * Also Notification callbacks are not synchronous. If you need to synchronize
  47100. + * the behavior between module/observer you must use other means. And perhaps
  47101. + * that will mean Notifications are not the proper solution.
  47102. + */
  47103. +
  47104. +struct dwc_notifier;
  47105. +typedef struct dwc_notifier dwc_notifier_t;
  47106. +
  47107. +/** The callback function must be of this type.
  47108. + *
  47109. + * @param object This is the object that is being observed.
  47110. + * @param notification This is the notification that was triggered.
  47111. + * @param observer This is the observer
  47112. + * @param notification_data This is notification-specific data that the notifier
  47113. + * has included in this notification. The value of this should be published in
  47114. + * the documentation of the observable module with the notifications.
  47115. + * @param user_data This is any custom data that the observer provided when
  47116. + * adding itself as an observer to the notification. */
  47117. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  47118. + void *notification_data, void *user_data);
  47119. +
  47120. +/** Brings up the notification manager. */
  47121. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  47122. +/** Brings down the notification manager. */
  47123. +extern void dwc_free_notification_manager(void);
  47124. +
  47125. +/** This function registers an observable module. A dwc_notifier_t object is
  47126. + * returned to the observable module. This is an opaque object that is used by
  47127. + * the observable module to trigger notifications. This object should only be
  47128. + * accessible to functions that are authorized to trigger notifications for this
  47129. + * module. Observers do not need this object. */
  47130. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  47131. +
  47132. +/** This function unregisters an observable module. All observers have to be
  47133. + * removed prior to unregistration. */
  47134. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  47135. +
  47136. +/** Add a module as an observer to the observable module. The observable module
  47137. + * needs to have previously registered with the notification manager.
  47138. + *
  47139. + * @param observer The observer module
  47140. + * @param object The module to observe
  47141. + * @param notification The notification to observe
  47142. + * @param callback The callback function to call
  47143. + * @param user_data Any additional user data to pass into the callback function */
  47144. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  47145. + dwc_notifier_callback_t callback, void *user_data);
  47146. +
  47147. +/** Removes the specified observer from all notifications that it is currently
  47148. + * observing. */
  47149. +extern int dwc_remove_observer(void *observer);
  47150. +
  47151. +/** This function triggers a Notification. It should be called by the
  47152. + * observable module, or any module or library which the observable module
  47153. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  47154. + *
  47155. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  47156. + * their own process context for each trigger. Callbacks can be blocking.
  47157. + * dwc_notify can be called from interrupt context if needed.
  47158. + *
  47159. + */
  47160. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  47161. +
  47162. +#ifdef __cplusplus
  47163. +}
  47164. +#endif
  47165. +
  47166. +#endif /* __DWC_NOTIFIER_H__ */
  47167. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_os.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_os.h
  47168. --- linux-3.10.33/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  47169. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/dwc_os.h 2014-03-13 12:46:39.480097919 +0100
  47170. @@ -0,0 +1,1262 @@
  47171. +/* =========================================================================
  47172. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  47173. + * $Revision: #14 $
  47174. + * $Date: 2010/11/04 $
  47175. + * $Change: 1621695 $
  47176. + *
  47177. + * Synopsys Portability Library Software and documentation
  47178. + * (hereinafter, "Software") is an Unsupported proprietary work of
  47179. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  47180. + * between Synopsys and you.
  47181. + *
  47182. + * The Software IS NOT an item of Licensed Software or Licensed Product
  47183. + * under any End User Software License Agreement or Agreement for
  47184. + * Licensed Product with Synopsys or any supplement thereto. You are
  47185. + * permitted to use and redistribute this Software in source and binary
  47186. + * forms, with or without modification, provided that redistributions
  47187. + * of source code must retain this notice. You may not view, use,
  47188. + * disclose, copy or distribute this file or any information contained
  47189. + * herein except pursuant to this license grant from Synopsys. If you
  47190. + * do not agree with this notice, including the disclaimer below, then
  47191. + * you are not authorized to use the Software.
  47192. + *
  47193. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  47194. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47195. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  47196. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  47197. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  47198. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  47199. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  47200. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  47201. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47202. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  47203. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  47204. + * DAMAGE.
  47205. + * ========================================================================= */
  47206. +#ifndef _DWC_OS_H_
  47207. +#define _DWC_OS_H_
  47208. +
  47209. +#ifdef __cplusplus
  47210. +extern "C" {
  47211. +#endif
  47212. +
  47213. +/** @file
  47214. + *
  47215. + * DWC portability library, low level os-wrapper functions
  47216. + *
  47217. + */
  47218. +
  47219. +/* These basic types need to be defined by some OS header file or custom header
  47220. + * file for your specific target architecture.
  47221. + *
  47222. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  47223. + *
  47224. + * Any custom or alternate header file must be added and enabled here.
  47225. + */
  47226. +
  47227. +#ifdef DWC_LINUX
  47228. +# include <linux/types.h>
  47229. +# ifdef CONFIG_DEBUG_MUTEXES
  47230. +# include <linux/mutex.h>
  47231. +# endif
  47232. +# include <linux/errno.h>
  47233. +# include <stdarg.h>
  47234. +#endif
  47235. +
  47236. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47237. +# include <os_dep.h>
  47238. +#endif
  47239. +
  47240. +
  47241. +/** @name Primitive Types and Values */
  47242. +
  47243. +/** We define a boolean type for consistency. Can be either YES or NO */
  47244. +typedef uint8_t dwc_bool_t;
  47245. +#define YES 1
  47246. +#define NO 0
  47247. +
  47248. +#ifdef DWC_LINUX
  47249. +
  47250. +/** @name Error Codes */
  47251. +#define DWC_E_INVALID EINVAL
  47252. +#define DWC_E_NO_MEMORY ENOMEM
  47253. +#define DWC_E_NO_DEVICE ENODEV
  47254. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  47255. +#define DWC_E_TIMEOUT ETIMEDOUT
  47256. +#define DWC_E_BUSY EBUSY
  47257. +#define DWC_E_AGAIN EAGAIN
  47258. +#define DWC_E_RESTART ERESTART
  47259. +#define DWC_E_ABORT ECONNABORTED
  47260. +#define DWC_E_SHUTDOWN ESHUTDOWN
  47261. +#define DWC_E_NO_DATA ENODATA
  47262. +#define DWC_E_DISCONNECT ECONNRESET
  47263. +#define DWC_E_UNKNOWN EINVAL
  47264. +#define DWC_E_NO_STREAM_RES ENOSR
  47265. +#define DWC_E_COMMUNICATION ECOMM
  47266. +#define DWC_E_OVERFLOW EOVERFLOW
  47267. +#define DWC_E_PROTOCOL EPROTO
  47268. +#define DWC_E_IN_PROGRESS EINPROGRESS
  47269. +#define DWC_E_PIPE EPIPE
  47270. +#define DWC_E_IO EIO
  47271. +#define DWC_E_NO_SPACE ENOSPC
  47272. +
  47273. +#else
  47274. +
  47275. +/** @name Error Codes */
  47276. +#define DWC_E_INVALID 1001
  47277. +#define DWC_E_NO_MEMORY 1002
  47278. +#define DWC_E_NO_DEVICE 1003
  47279. +#define DWC_E_NOT_SUPPORTED 1004
  47280. +#define DWC_E_TIMEOUT 1005
  47281. +#define DWC_E_BUSY 1006
  47282. +#define DWC_E_AGAIN 1007
  47283. +#define DWC_E_RESTART 1008
  47284. +#define DWC_E_ABORT 1009
  47285. +#define DWC_E_SHUTDOWN 1010
  47286. +#define DWC_E_NO_DATA 1011
  47287. +#define DWC_E_DISCONNECT 2000
  47288. +#define DWC_E_UNKNOWN 3000
  47289. +#define DWC_E_NO_STREAM_RES 4001
  47290. +#define DWC_E_COMMUNICATION 4002
  47291. +#define DWC_E_OVERFLOW 4003
  47292. +#define DWC_E_PROTOCOL 4004
  47293. +#define DWC_E_IN_PROGRESS 4005
  47294. +#define DWC_E_PIPE 4006
  47295. +#define DWC_E_IO 4007
  47296. +#define DWC_E_NO_SPACE 4008
  47297. +
  47298. +#endif
  47299. +
  47300. +
  47301. +/** @name Tracing/Logging Functions
  47302. + *
  47303. + * These function provide the capability to add tracing, debugging, and error
  47304. + * messages, as well exceptions as assertions. The WUDEV uses these
  47305. + * extensively. These could be logged to the main console, the serial port, an
  47306. + * internal buffer, etc. These functions could also be no-op if they are too
  47307. + * expensive on your system. By default undefining the DEBUG macro already
  47308. + * no-ops some of these functions. */
  47309. +
  47310. +/** Returns non-zero if in interrupt context. */
  47311. +extern dwc_bool_t DWC_IN_IRQ(void);
  47312. +#define dwc_in_irq DWC_IN_IRQ
  47313. +
  47314. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  47315. +static inline char *dwc_irq(void) {
  47316. + return DWC_IN_IRQ() ? "IRQ" : "";
  47317. +}
  47318. +
  47319. +/** Returns non-zero if in bottom-half context. */
  47320. +extern dwc_bool_t DWC_IN_BH(void);
  47321. +#define dwc_in_bh DWC_IN_BH
  47322. +
  47323. +/** Returns "BH" if DWC_IN_BH is true. */
  47324. +static inline char *dwc_bh(void) {
  47325. + return DWC_IN_BH() ? "BH" : "";
  47326. +}
  47327. +
  47328. +/**
  47329. + * A vprintf() clone. Just call vprintf if you've got it.
  47330. + */
  47331. +extern void DWC_VPRINTF(char *format, va_list args);
  47332. +#define dwc_vprintf DWC_VPRINTF
  47333. +
  47334. +/**
  47335. + * A vsnprintf() clone. Just call vprintf if you've got it.
  47336. + */
  47337. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  47338. +#define dwc_vsnprintf DWC_VSNPRINTF
  47339. +
  47340. +/**
  47341. + * printf() clone. Just call printf if you've go it.
  47342. + */
  47343. +extern void DWC_PRINTF(char *format, ...)
  47344. +/* This provides compiler level static checking of the parameters if you're
  47345. + * using GCC. */
  47346. +#ifdef __GNUC__
  47347. + __attribute__ ((format(printf, 1, 2)));
  47348. +#else
  47349. + ;
  47350. +#endif
  47351. +#define dwc_printf DWC_PRINTF
  47352. +
  47353. +/**
  47354. + * sprintf() clone. Just call sprintf if you've got it.
  47355. + */
  47356. +extern int DWC_SPRINTF(char *string, char *format, ...)
  47357. +#ifdef __GNUC__
  47358. + __attribute__ ((format(printf, 2, 3)));
  47359. +#else
  47360. + ;
  47361. +#endif
  47362. +#define dwc_sprintf DWC_SPRINTF
  47363. +
  47364. +/**
  47365. + * snprintf() clone. Just call snprintf if you've got it.
  47366. + */
  47367. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  47368. +#ifdef __GNUC__
  47369. + __attribute__ ((format(printf, 3, 4)));
  47370. +#else
  47371. + ;
  47372. +#endif
  47373. +#define dwc_snprintf DWC_SNPRINTF
  47374. +
  47375. +/**
  47376. + * Prints a WARNING message. On systems that don't differentiate between
  47377. + * warnings and regular log messages, just print it. Indicates that something
  47378. + * may be wrong with the driver. Works like printf().
  47379. + *
  47380. + * Use the DWC_WARN macro to call this function.
  47381. + */
  47382. +extern void __DWC_WARN(char *format, ...)
  47383. +#ifdef __GNUC__
  47384. + __attribute__ ((format(printf, 1, 2)));
  47385. +#else
  47386. + ;
  47387. +#endif
  47388. +
  47389. +/**
  47390. + * Prints an error message. On systems that don't differentiate between errors
  47391. + * and regular log messages, just print it. Indicates that something went wrong
  47392. + * with the driver. Works like printf().
  47393. + *
  47394. + * Use the DWC_ERROR macro to call this function.
  47395. + */
  47396. +extern void __DWC_ERROR(char *format, ...)
  47397. +#ifdef __GNUC__
  47398. + __attribute__ ((format(printf, 1, 2)));
  47399. +#else
  47400. + ;
  47401. +#endif
  47402. +
  47403. +/**
  47404. + * Prints an exception error message and takes some user-defined action such as
  47405. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  47406. + * abnormally wrong with the driver such as programmer error, or other
  47407. + * exceptional condition. It should not be ignored so even on systems without
  47408. + * printing capability, some action should be taken to notify the developer of
  47409. + * it. Works like printf().
  47410. + */
  47411. +extern void DWC_EXCEPTION(char *format, ...)
  47412. +#ifdef __GNUC__
  47413. + __attribute__ ((format(printf, 1, 2)));
  47414. +#else
  47415. + ;
  47416. +#endif
  47417. +#define dwc_exception DWC_EXCEPTION
  47418. +
  47419. +#ifndef DWC_OTG_DEBUG_LEV
  47420. +#define DWC_OTG_DEBUG_LEV 0
  47421. +#endif
  47422. +
  47423. +#ifdef DEBUG
  47424. +/**
  47425. + * Prints out a debug message. Used for logging/trace messages.
  47426. + *
  47427. + * Use the DWC_DEBUG macro to call this function
  47428. + */
  47429. +extern void __DWC_DEBUG(char *format, ...)
  47430. +#ifdef __GNUC__
  47431. + __attribute__ ((format(printf, 1, 2)));
  47432. +#else
  47433. + ;
  47434. +#endif
  47435. +#else
  47436. +#define __DWC_DEBUG printk
  47437. +#endif
  47438. +
  47439. +/**
  47440. + * Prints out a Debug message.
  47441. + */
  47442. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  47443. + __func__, dwc_irq(), ## _args)
  47444. +#define dwc_debug DWC_DEBUG
  47445. +/**
  47446. + * Prints out a Debug message if enabled at compile time.
  47447. + */
  47448. +#if DWC_OTG_DEBUG_LEV > 0
  47449. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  47450. +#else
  47451. +#define DWC_DEBUGC(_format, _args...)
  47452. +#endif
  47453. +#define dwc_debugc DWC_DEBUGC
  47454. +/**
  47455. + * Prints out an informative message.
  47456. + */
  47457. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  47458. + dwc_irq(), ## _args)
  47459. +#define dwc_info DWC_INFO
  47460. +/**
  47461. + * Prints out an informative message if enabled at compile time.
  47462. + */
  47463. +#if DWC_OTG_DEBUG_LEV > 1
  47464. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  47465. +#else
  47466. +#define DWC_INFOC(_format, _args...)
  47467. +#endif
  47468. +#define dwc_infoc DWC_INFOC
  47469. +/**
  47470. + * Prints out a warning message.
  47471. + */
  47472. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  47473. + dwc_irq(), __func__, __LINE__, ## _args)
  47474. +#define dwc_warn DWC_WARN
  47475. +/**
  47476. + * Prints out an error message.
  47477. + */
  47478. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  47479. + dwc_irq(), __func__, __LINE__, ## _args)
  47480. +#define dwc_error DWC_ERROR
  47481. +
  47482. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  47483. + dwc_irq(), __func__, __LINE__, ## _args)
  47484. +#define dwc_proto_error DWC_PROTO_ERROR
  47485. +
  47486. +#ifdef DEBUG
  47487. +/** Prints out a exception error message if the _expr expression fails. Disabled
  47488. + * if DEBUG is not enabled. */
  47489. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  47490. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  47491. + __FILE__, __LINE__, ## _args); } \
  47492. + } while (0)
  47493. +#else
  47494. +#define DWC_ASSERT(_x...)
  47495. +#endif
  47496. +#define dwc_assert DWC_ASSERT
  47497. +
  47498. +
  47499. +/** @name Byte Ordering
  47500. + * The following functions are for conversions between processor's byte ordering
  47501. + * and specific ordering you want.
  47502. + */
  47503. +
  47504. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  47505. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  47506. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  47507. +
  47508. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  47509. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  47510. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  47511. +
  47512. +/** Converts 32 bit little endian data to CPU byte ordering. */
  47513. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  47514. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  47515. +
  47516. +/** Converts 32 bit big endian data to CPU byte ordering. */
  47517. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  47518. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  47519. +
  47520. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  47521. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  47522. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  47523. +
  47524. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  47525. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  47526. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  47527. +
  47528. +/** Converts 16 bit little endian data to CPU byte ordering. */
  47529. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  47530. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  47531. +
  47532. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  47533. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  47534. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  47535. +
  47536. +
  47537. +/** @name Register Read/Write
  47538. + *
  47539. + * The following six functions should be implemented to read/write registers of
  47540. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  47541. + * The reg value is a pointer to the register calculated from the void *base
  47542. + * variable passed into the driver when it is started. */
  47543. +
  47544. +#ifdef DWC_LINUX
  47545. +/* Linux doesn't need any extra parameters for register read/write, so we
  47546. + * just throw away the IO context parameter.
  47547. + */
  47548. +/** Reads the content of a 32-bit register. */
  47549. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  47550. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  47551. +
  47552. +/** Reads the content of a 64-bit register. */
  47553. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  47554. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  47555. +
  47556. +/** Writes to a 32-bit register. */
  47557. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  47558. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  47559. +
  47560. +/** Writes to a 64-bit register. */
  47561. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  47562. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  47563. +
  47564. +/**
  47565. + * Modify bit values in a register. Using the
  47566. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47567. + */
  47568. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47569. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  47570. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47571. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  47572. +
  47573. +#endif /* DWC_LINUX */
  47574. +
  47575. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47576. +typedef struct dwc_ioctx {
  47577. + struct device *dev;
  47578. + bus_space_tag_t iot;
  47579. + bus_space_handle_t ioh;
  47580. +} dwc_ioctx_t;
  47581. +
  47582. +/** BSD needs two extra parameters for register read/write, so we pass
  47583. + * them in using the IO context parameter.
  47584. + */
  47585. +/** Reads the content of a 32-bit register. */
  47586. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  47587. +#define dwc_read_reg32 DWC_READ_REG32
  47588. +
  47589. +/** Reads the content of a 64-bit register. */
  47590. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  47591. +#define dwc_read_reg64 DWC_READ_REG64
  47592. +
  47593. +/** Writes to a 32-bit register. */
  47594. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  47595. +#define dwc_write_reg32 DWC_WRITE_REG32
  47596. +
  47597. +/** Writes to a 64-bit register. */
  47598. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  47599. +#define dwc_write_reg64 DWC_WRITE_REG64
  47600. +
  47601. +/**
  47602. + * Modify bit values in a register. Using the
  47603. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47604. + */
  47605. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47606. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  47607. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47608. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  47609. +
  47610. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47611. +
  47612. +/** @cond */
  47613. +
  47614. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  47615. + * register writes. */
  47616. +
  47617. +#ifdef DWC_LINUX
  47618. +
  47619. +# ifdef DWC_DEBUG_REGS
  47620. +
  47621. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47622. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47623. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47624. +} \
  47625. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47626. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47627. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47628. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47629. +}
  47630. +
  47631. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47632. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47633. + return DWC_READ_REG32(&container->regs->_reg); \
  47634. +} \
  47635. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47636. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47637. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47638. +}
  47639. +
  47640. +# else /* DWC_DEBUG_REGS */
  47641. +
  47642. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47643. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47644. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47645. +} \
  47646. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47647. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47648. +}
  47649. +
  47650. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47651. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47652. + return DWC_READ_REG32(&container->regs->_reg); \
  47653. +} \
  47654. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47655. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47656. +}
  47657. +
  47658. +# endif /* DWC_DEBUG_REGS */
  47659. +
  47660. +#endif /* DWC_LINUX */
  47661. +
  47662. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47663. +
  47664. +# ifdef DWC_DEBUG_REGS
  47665. +
  47666. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47667. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47668. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47669. +} \
  47670. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47671. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47672. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47673. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47674. +}
  47675. +
  47676. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47677. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47678. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47679. +} \
  47680. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47681. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47682. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47683. +}
  47684. +
  47685. +# else /* DWC_DEBUG_REGS */
  47686. +
  47687. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47688. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47689. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47690. +} \
  47691. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47692. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47693. +}
  47694. +
  47695. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47696. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47697. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47698. +} \
  47699. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47700. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47701. +}
  47702. +
  47703. +# endif /* DWC_DEBUG_REGS */
  47704. +
  47705. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47706. +
  47707. +/** @endcond */
  47708. +
  47709. +
  47710. +#ifdef DWC_CRYPTOLIB
  47711. +/** @name Crypto Functions
  47712. + *
  47713. + * These are the low-level cryptographic functions used by the driver. */
  47714. +
  47715. +/** Perform AES CBC */
  47716. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  47717. +#define dwc_aes_cbc DWC_AES_CBC
  47718. +
  47719. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  47720. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  47721. +#define dwc_random_bytes DWC_RANDOM_BYTES
  47722. +
  47723. +/** Perform the SHA-256 hash function */
  47724. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  47725. +#define dwc_sha256 DWC_SHA256
  47726. +
  47727. +/** Calculated the HMAC-SHA256 */
  47728. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  47729. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  47730. +
  47731. +#endif /* DWC_CRYPTOLIB */
  47732. +
  47733. +
  47734. +/** @name Memory Allocation
  47735. + *
  47736. + * These function provide access to memory allocation. There are only 2 DMA
  47737. + * functions and 3 Regular memory functions that need to be implemented. None
  47738. + * of the memory debugging routines need to be implemented. The allocation
  47739. + * routines all ZERO the contents of the memory.
  47740. + *
  47741. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  47742. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  47743. + * keeps track of how much memory the driver is using at any given time. */
  47744. +
  47745. +#define DWC_PAGE_SIZE 4096
  47746. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  47747. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  47748. +
  47749. +#define DWC_INVALID_DMA_ADDR 0x0
  47750. +
  47751. +#ifdef DWC_LINUX
  47752. +/** Type for a DMA address */
  47753. +typedef dma_addr_t dwc_dma_t;
  47754. +#endif
  47755. +
  47756. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47757. +typedef bus_addr_t dwc_dma_t;
  47758. +#endif
  47759. +
  47760. +#ifdef DWC_FREEBSD
  47761. +typedef struct dwc_dmactx {
  47762. + struct device *dev;
  47763. + bus_dma_tag_t dma_tag;
  47764. + bus_dmamap_t dma_map;
  47765. + bus_addr_t dma_paddr;
  47766. + void *dma_vaddr;
  47767. +} dwc_dmactx_t;
  47768. +#endif
  47769. +
  47770. +#ifdef DWC_NETBSD
  47771. +typedef struct dwc_dmactx {
  47772. + struct device *dev;
  47773. + bus_dma_tag_t dma_tag;
  47774. + bus_dmamap_t dma_map;
  47775. + bus_dma_segment_t segs[1];
  47776. + int nsegs;
  47777. + bus_addr_t dma_paddr;
  47778. + void *dma_vaddr;
  47779. +} dwc_dmactx_t;
  47780. +#endif
  47781. +
  47782. +/* @todo these functions will be added in the future */
  47783. +#if 0
  47784. +/**
  47785. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  47786. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  47787. + * boundary requirements specified.
  47788. + *
  47789. + * @param[in] size Specifies the size of the buffers that will be allocated from
  47790. + * this pool.
  47791. + * @param[in] align Specifies the byte alignment requirements of the buffers
  47792. + * allocated from this pool. Must be a power of 2.
  47793. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  47794. + * this pool must not cross.
  47795. + *
  47796. + * @returns A pointer to an internal opaque structure which is not to be
  47797. + * accessed outside of these library functions. Use this handle to specify
  47798. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  47799. + * when you are done with it.
  47800. + */
  47801. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  47802. +
  47803. +/**
  47804. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  47805. + */
  47806. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  47807. +
  47808. +/**
  47809. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  47810. + */
  47811. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  47812. +
  47813. +/**
  47814. + * Free a previously allocated buffer from the DMA pool.
  47815. + */
  47816. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  47817. +#endif
  47818. +
  47819. +/** Allocates a DMA capable buffer and zeroes its contents. */
  47820. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47821. +
  47822. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  47823. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47824. +
  47825. +/** Frees a previously allocated buffer. */
  47826. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  47827. +
  47828. +/** Allocates a block of memory and zeroes its contents. */
  47829. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  47830. +
  47831. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  47832. + * which can be used inside interrupt context. The size should be sufficiently
  47833. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  47834. + * __DWC_ALLOC if it is atomic. */
  47835. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  47836. +
  47837. +/** Frees a previously allocated buffer. */
  47838. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  47839. +
  47840. +#ifndef DWC_DEBUG_MEMORY
  47841. +
  47842. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  47843. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  47844. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  47845. +
  47846. +# ifdef DWC_LINUX
  47847. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  47848. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  47849. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  47850. +# endif
  47851. +
  47852. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47853. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  47854. +#define DWC_DMA_FREE __DWC_DMA_FREE
  47855. +# endif
  47856. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  47857. +
  47858. +#else /* DWC_DEBUG_MEMORY */
  47859. +
  47860. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47861. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47862. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  47863. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47864. + char const *func, int line);
  47865. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47866. + char const *func, int line);
  47867. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  47868. + dwc_dma_t dma_addr, char const *func, int line);
  47869. +
  47870. +extern int dwc_memory_debug_start(void *mem_ctx);
  47871. +extern void dwc_memory_debug_stop(void);
  47872. +extern void dwc_memory_debug_report(void);
  47873. +
  47874. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  47875. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  47876. + __func__, __LINE__)
  47877. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  47878. +
  47879. +# ifdef DWC_LINUX
  47880. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  47881. + _dma_, __func__, __LINE__)
  47882. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  47883. + _dma_, __func__, __LINE__)
  47884. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  47885. + _virt_, _dma_, __func__, __LINE__)
  47886. +# endif
  47887. +
  47888. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47889. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  47890. + _dma_, __func__, __LINE__)
  47891. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  47892. + _virt_, _dma_, __func__, __LINE__)
  47893. +# endif
  47894. +
  47895. +#endif /* DWC_DEBUG_MEMORY */
  47896. +
  47897. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  47898. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  47899. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  47900. +
  47901. +#ifdef DWC_LINUX
  47902. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  47903. + * just throw away the DMA context parameter.
  47904. + */
  47905. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  47906. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  47907. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  47908. +#endif
  47909. +
  47910. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47911. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  47912. + * them in using the DMA context parameter.
  47913. + */
  47914. +#define dwc_dma_alloc DWC_DMA_ALLOC
  47915. +#define dwc_dma_free DWC_DMA_FREE
  47916. +#endif
  47917. +
  47918. +
  47919. +/** @name Memory and String Processing */
  47920. +
  47921. +/** memset() clone */
  47922. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  47923. +#define dwc_memset DWC_MEMSET
  47924. +
  47925. +/** memcpy() clone */
  47926. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  47927. +#define dwc_memcpy DWC_MEMCPY
  47928. +
  47929. +/** memmove() clone */
  47930. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  47931. +#define dwc_memmove DWC_MEMMOVE
  47932. +
  47933. +/** memcmp() clone */
  47934. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  47935. +#define dwc_memcmp DWC_MEMCMP
  47936. +
  47937. +/** strcmp() clone */
  47938. +extern int DWC_STRCMP(void *s1, void *s2);
  47939. +#define dwc_strcmp DWC_STRCMP
  47940. +
  47941. +/** strncmp() clone */
  47942. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  47943. +#define dwc_strncmp DWC_STRNCMP
  47944. +
  47945. +/** strlen() clone, for NULL terminated ASCII strings */
  47946. +extern int DWC_STRLEN(char const *str);
  47947. +#define dwc_strlen DWC_STRLEN
  47948. +
  47949. +/** strcpy() clone, for NULL terminated ASCII strings */
  47950. +extern char *DWC_STRCPY(char *to, const char *from);
  47951. +#define dwc_strcpy DWC_STRCPY
  47952. +
  47953. +/** strdup() clone. If you wish to use memory allocation debugging, this
  47954. + * implementation of strdup should use the DWC_* memory routines instead of
  47955. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  47956. + * will not be seen by the debugging routines. */
  47957. +extern char *DWC_STRDUP(char const *str);
  47958. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  47959. +
  47960. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  47961. + * converted from the string str in base 10 unless the string begins with a "0x"
  47962. + * in which case it is base 16. String must be a NULL terminated sequence of
  47963. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  47964. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  47965. + * the number and end with a NULL character. If any invalid characters are
  47966. + * encountered or it returns with a negative error code and the results of the
  47967. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  47968. + * undefined. An example implementation using atoi() can be referenced from the
  47969. + * Linux implementation. */
  47970. +extern int DWC_ATOI(const char *str, int32_t *value);
  47971. +#define dwc_atoi DWC_ATOI
  47972. +
  47973. +/** Same as above but for unsigned. */
  47974. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  47975. +#define dwc_atoui DWC_ATOUI
  47976. +
  47977. +#ifdef DWC_UTFLIB
  47978. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  47979. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  47980. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  47981. +#endif
  47982. +
  47983. +
  47984. +/** @name Wait queues
  47985. + *
  47986. + * Wait queues provide a means of synchronizing between threads or processes. A
  47987. + * process can block on a waitq if some condition is not true, waiting for it to
  47988. + * become true. When the waitq is triggered all waiting process will get
  47989. + * unblocked and the condition will be check again. Waitqs should be triggered
  47990. + * every time a condition can potentially change.*/
  47991. +struct dwc_waitq;
  47992. +
  47993. +/** Type for a waitq */
  47994. +typedef struct dwc_waitq dwc_waitq_t;
  47995. +
  47996. +/** The type of waitq condition callback function. This is called every time
  47997. + * condition is evaluated. */
  47998. +typedef int (*dwc_waitq_condition_t)(void *data);
  47999. +
  48000. +/** Allocate a waitq */
  48001. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  48002. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  48003. +
  48004. +/** Free a waitq */
  48005. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  48006. +#define dwc_waitq_free DWC_WAITQ_FREE
  48007. +
  48008. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  48009. + * condition again. The function returns when the condition becomes true. The return value
  48010. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  48011. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  48012. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  48013. +
  48014. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  48015. + * check the condition again. The function returns when the condition become
  48016. + * true or the timeout has passed. The return value is 0 on condition true or
  48017. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  48018. + * error. */
  48019. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  48020. + void *data, int32_t msecs);
  48021. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  48022. +
  48023. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  48024. + * has potentially changed. */
  48025. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  48026. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  48027. +
  48028. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  48029. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  48030. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  48031. +
  48032. +
  48033. +/** @name Threads
  48034. + *
  48035. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  48036. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  48037. + * returns the value from the thread.
  48038. + */
  48039. +
  48040. +struct dwc_thread;
  48041. +
  48042. +/** Type for a thread */
  48043. +typedef struct dwc_thread dwc_thread_t;
  48044. +
  48045. +/** The thread function */
  48046. +typedef int (*dwc_thread_function_t)(void *data);
  48047. +
  48048. +/** Create a thread and start it running the thread_function. Returns a handle
  48049. + * to the thread */
  48050. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  48051. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  48052. +
  48053. +/** Stops a thread. Return the value returned by the thread. Or will return
  48054. + * DWC_ABORT if the thread never started. */
  48055. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  48056. +#define dwc_thread_stop DWC_THREAD_STOP
  48057. +
  48058. +/** Signifies to the thread that it must stop. */
  48059. +#ifdef DWC_LINUX
  48060. +/* Linux doesn't need any parameters for kthread_should_stop() */
  48061. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  48062. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  48063. +
  48064. +/* No thread_exit function in Linux */
  48065. +#define dwc_thread_exit(_thrd_)
  48066. +#endif
  48067. +
  48068. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48069. +/** BSD needs the thread pointer for kthread_suspend_check() */
  48070. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  48071. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  48072. +
  48073. +/** The thread must call this to exit. */
  48074. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  48075. +#define dwc_thread_exit DWC_THREAD_EXIT
  48076. +#endif
  48077. +
  48078. +
  48079. +/** @name Work queues
  48080. + *
  48081. + * Workqs are used to queue a callback function to be called at some later time,
  48082. + * in another thread. */
  48083. +struct dwc_workq;
  48084. +
  48085. +/** Type for a workq */
  48086. +typedef struct dwc_workq dwc_workq_t;
  48087. +
  48088. +/** The type of the callback function to be called. */
  48089. +typedef void (*dwc_work_callback_t)(void *data);
  48090. +
  48091. +/** Allocate a workq */
  48092. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  48093. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  48094. +
  48095. +/** Free a workq. All work must be completed before being freed. */
  48096. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  48097. +#define dwc_workq_free DWC_WORKQ_FREE
  48098. +
  48099. +/** Schedule a callback on the workq, passing in data. The function will be
  48100. + * scheduled at some later time. */
  48101. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  48102. + void *data, char *format, ...)
  48103. +#ifdef __GNUC__
  48104. + __attribute__ ((format(printf, 4, 5)));
  48105. +#else
  48106. + ;
  48107. +#endif
  48108. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  48109. +
  48110. +/** Schedule a callback on the workq, that will be called until at least
  48111. + * given number miliseconds have passed. */
  48112. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  48113. + void *data, uint32_t time, char *format, ...)
  48114. +#ifdef __GNUC__
  48115. + __attribute__ ((format(printf, 5, 6)));
  48116. +#else
  48117. + ;
  48118. +#endif
  48119. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  48120. +
  48121. +/** The number of processes in the workq */
  48122. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  48123. +#define dwc_workq_pending DWC_WORKQ_PENDING
  48124. +
  48125. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  48126. + * 0 on timeout. */
  48127. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  48128. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  48129. +
  48130. +
  48131. +/** @name Tasklets
  48132. + *
  48133. + */
  48134. +struct dwc_tasklet;
  48135. +
  48136. +/** Type for a tasklet */
  48137. +typedef struct dwc_tasklet dwc_tasklet_t;
  48138. +
  48139. +/** The type of the callback function to be called */
  48140. +typedef void (*dwc_tasklet_callback_t)(void *data);
  48141. +
  48142. +/** Allocates a tasklet */
  48143. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  48144. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  48145. +
  48146. +/** Frees a tasklet */
  48147. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  48148. +#define dwc_task_free DWC_TASK_FREE
  48149. +
  48150. +/** Schedules a tasklet to run */
  48151. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  48152. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  48153. +
  48154. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  48155. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  48156. +
  48157. +/** @name Timer
  48158. + *
  48159. + * Callbacks must be small and atomic.
  48160. + */
  48161. +struct dwc_timer;
  48162. +
  48163. +/** Type for a timer */
  48164. +typedef struct dwc_timer dwc_timer_t;
  48165. +
  48166. +/** The type of the callback function to be called */
  48167. +typedef void (*dwc_timer_callback_t)(void *data);
  48168. +
  48169. +/** Allocates a timer */
  48170. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  48171. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  48172. +
  48173. +/** Frees a timer */
  48174. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  48175. +#define dwc_timer_free DWC_TIMER_FREE
  48176. +
  48177. +/** Schedules the timer to run at time ms from now. And will repeat at every
  48178. + * repeat_interval msec therafter
  48179. + *
  48180. + * Modifies a timer that is still awaiting execution to a new expiration time.
  48181. + * The mod_time is added to the old time. */
  48182. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  48183. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  48184. +
  48185. +/** Disables the timer from execution. */
  48186. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  48187. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  48188. +
  48189. +
  48190. +/** @name Spinlocks
  48191. + *
  48192. + * These locks are used when the work between the lock/unlock is atomic and
  48193. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  48194. + * suitable to lock between interrupt/non-interrupt context. They also lock
  48195. + * between processes if you have multiple CPUs or Preemption. If you don't have
  48196. + * multiple CPUS or Preemption, then the you can simply implement the
  48197. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  48198. + * the work between the lock/unlock is atomic, the process context will never
  48199. + * change, and so you never have to lock between processes. */
  48200. +
  48201. +struct dwc_spinlock;
  48202. +
  48203. +/** Type for a spinlock */
  48204. +typedef struct dwc_spinlock dwc_spinlock_t;
  48205. +
  48206. +/** Type for the 'flags' argument to spinlock funtions */
  48207. +typedef unsigned long dwc_irqflags_t;
  48208. +
  48209. +/** Returns an initialized lock variable. This function should allocate and
  48210. + * initialize the OS-specific data structure used for locking. This data
  48211. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  48212. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  48213. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  48214. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  48215. +
  48216. +/** Frees an initialized lock variable. */
  48217. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  48218. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  48219. +
  48220. +/** Disables interrupts and blocks until it acquires the lock.
  48221. + *
  48222. + * @param lock Pointer to the spinlock.
  48223. + * @param flags Unsigned long for irq flags storage.
  48224. + */
  48225. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  48226. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  48227. +
  48228. +/** Re-enables the interrupt and releases the lock.
  48229. + *
  48230. + * @param lock Pointer to the spinlock.
  48231. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  48232. + * passed into DWC_LOCK.
  48233. + */
  48234. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  48235. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  48236. +
  48237. +/** Blocks until it acquires the lock.
  48238. + *
  48239. + * @param lock Pointer to the spinlock.
  48240. + */
  48241. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  48242. +#define dwc_spinlock DWC_SPINLOCK
  48243. +
  48244. +/** Releases the lock.
  48245. + *
  48246. + * @param lock Pointer to the spinlock.
  48247. + */
  48248. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  48249. +#define dwc_spinunlock DWC_SPINUNLOCK
  48250. +
  48251. +
  48252. +/** @name Mutexes
  48253. + *
  48254. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  48255. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  48256. + */
  48257. +
  48258. +struct dwc_mutex;
  48259. +
  48260. +/** Type for a mutex */
  48261. +typedef struct dwc_mutex dwc_mutex_t;
  48262. +
  48263. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  48264. + * the symbol to determine recursive locking. This makes it falsely think
  48265. + * recursive locking occurs. */
  48266. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  48267. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  48268. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  48269. + mutex_init((struct mutex *)__mutexp); \
  48270. +})
  48271. +#endif
  48272. +
  48273. +/** Allocate a mutex */
  48274. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  48275. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  48276. +
  48277. +/* For memory leak debugging when using Linux Mutex Debugging */
  48278. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  48279. +#define DWC_MUTEX_FREE(__mutexp) do { \
  48280. + mutex_destroy((struct mutex *)__mutexp); \
  48281. + DWC_FREE(__mutexp); \
  48282. +} while(0)
  48283. +#else
  48284. +/** Free a mutex */
  48285. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  48286. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  48287. +#endif
  48288. +
  48289. +/** Lock a mutex */
  48290. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  48291. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  48292. +
  48293. +/** Non-blocking lock returns 1 on successful lock. */
  48294. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  48295. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  48296. +
  48297. +/** Unlock a mutex */
  48298. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  48299. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  48300. +
  48301. +
  48302. +/** @name Time */
  48303. +
  48304. +/** Microsecond delay.
  48305. + *
  48306. + * @param usecs Microseconds to delay.
  48307. + */
  48308. +extern void DWC_UDELAY(uint32_t usecs);
  48309. +#define dwc_udelay DWC_UDELAY
  48310. +
  48311. +/** Millisecond delay.
  48312. + *
  48313. + * @param msecs Milliseconds to delay.
  48314. + */
  48315. +extern void DWC_MDELAY(uint32_t msecs);
  48316. +#define dwc_mdelay DWC_MDELAY
  48317. +
  48318. +/** Non-busy waiting.
  48319. + * Sleeps for specified number of milliseconds.
  48320. + *
  48321. + * @param msecs Milliseconds to sleep.
  48322. + */
  48323. +extern void DWC_MSLEEP(uint32_t msecs);
  48324. +#define dwc_msleep DWC_MSLEEP
  48325. +
  48326. +/**
  48327. + * Returns number of milliseconds since boot.
  48328. + */
  48329. +extern uint32_t DWC_TIME(void);
  48330. +#define dwc_time DWC_TIME
  48331. +
  48332. +
  48333. +
  48334. +
  48335. +/* @mainpage DWC Portability and Common Library
  48336. + *
  48337. + * This is the documentation for the DWC Portability and Common Library.
  48338. + *
  48339. + * @section intro Introduction
  48340. + *
  48341. + * The DWC Portability library consists of wrapper calls and data structures to
  48342. + * all low-level functions which are typically provided by the OS. The WUDEV
  48343. + * driver uses only these functions. In order to port the WUDEV driver, only
  48344. + * the functions in this library need to be re-implemented, with the same
  48345. + * behavior as documented here.
  48346. + *
  48347. + * The Common library consists of higher level functions, which rely only on
  48348. + * calling the functions from the DWC Portability library. These common
  48349. + * routines are shared across modules. Some of the common libraries need to be
  48350. + * used directly by the driver programmer when porting WUDEV. Such as the
  48351. + * parameter and notification libraries.
  48352. + *
  48353. + * @section low Portability Library OS Wrapper Functions
  48354. + *
  48355. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  48356. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  48357. + * these functions are included in the dwc_os.h file.
  48358. + *
  48359. + * There are many functions here covering a wide array of OS services. Please
  48360. + * see dwc_os.h for details, and implementation notes for each function.
  48361. + *
  48362. + * @section common Common Library Functions
  48363. + *
  48364. + * Any function starting with dwc and in all lowercase is a common library
  48365. + * routine. These functions have a portable implementation and do not need to
  48366. + * be reimplemented when porting. The common routines can be used by any
  48367. + * driver, and some must be used by the end user to control the drivers. For
  48368. + * example, you must use the Parameter common library in order to set the
  48369. + * parameters in the WUDEV module.
  48370. + *
  48371. + * The common libraries consist of the following:
  48372. + *
  48373. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  48374. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  48375. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  48376. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  48377. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  48378. + * - Modpow - Used internally only. See dwc_modpow.h
  48379. + * - DH - Used internally only. See dwc_dh.h
  48380. + * - Crypto - Used internally only. See dwc_crypto.h
  48381. + *
  48382. + *
  48383. + * @section prereq Prerequistes For dwc_os.h
  48384. + * @subsection types Data Types
  48385. + *
  48386. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  48387. + * compilation environment. These data types are:
  48388. + *
  48389. + * - uint8_t - unsigned 8-bit data type
  48390. + * - int8_t - signed 8-bit data type
  48391. + * - uint16_t - unsigned 16-bit data type
  48392. + * - int16_t - signed 16-bit data type
  48393. + * - uint32_t - unsigned 32-bit data type
  48394. + * - int32_t - signed 32-bit data type
  48395. + * - uint64_t - unsigned 64-bit data type
  48396. + * - int64_t - signed 64-bit data type
  48397. + *
  48398. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  48399. + * that is to modify the top of the file to include the appropriate header.
  48400. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  48401. + * defined, the correct header will be added. A standard header <stdint.h> is
  48402. + * also used for environments where standard C headers are available.
  48403. + *
  48404. + * @subsection stdarg Variable Arguments
  48405. + *
  48406. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  48407. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  48408. + * provided in your enviornment in order to use dwc_os.h with the debug and
  48409. + * tracing message functionality.
  48410. + *
  48411. + * @subsection thread Threading
  48412. + *
  48413. + * WUDEV Core must be run on an operating system that provides for multiple
  48414. + * threads/processes. Threading can be implemented in many ways, even in
  48415. + * embedded systems without an operating system. At the bare minimum, the
  48416. + * system should be able to start any number of processes at any time to handle
  48417. + * special work. It need not be a pre-emptive system. Process context can
  48418. + * change upon a call to a blocking function. The hardware interrupt context
  48419. + * that calls the module's ISR() function must be differentiable from process
  48420. + * context, even if your processes are impemented via a hardware interrupt.
  48421. + * Further locking mechanism between process must exist (or be implemented), and
  48422. + * process context must have a way to disable interrupts for a period of time to
  48423. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  48424. + * threading should be able to be implemented with the defined behavior.
  48425. + *
  48426. + */
  48427. +
  48428. +#ifdef __cplusplus
  48429. +}
  48430. +#endif
  48431. +
  48432. +#endif /* _DWC_OS_H_ */
  48433. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/Makefile linux-raspberry-pi/drivers/usb/host/dwc_common_port/Makefile
  48434. --- linux-3.10.33/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  48435. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/Makefile 2014-03-13 12:46:38.980096914 +0100
  48436. @@ -0,0 +1,58 @@
  48437. +#
  48438. +# Makefile for DWC_common library
  48439. +#
  48440. +
  48441. +ifneq ($(KERNELRELEASE),)
  48442. +
  48443. +ccflags-y += -DDWC_LINUX
  48444. +#ccflags-y += -DDEBUG
  48445. +#ccflags-y += -DDWC_DEBUG_REGS
  48446. +#ccflags-y += -DDWC_DEBUG_MEMORY
  48447. +
  48448. +ccflags-y += -DDWC_LIBMODULE
  48449. +ccflags-y += -DDWC_CCLIB
  48450. +#ccflags-y += -DDWC_CRYPTOLIB
  48451. +ccflags-y += -DDWC_NOTIFYLIB
  48452. +ccflags-y += -DDWC_UTFLIB
  48453. +
  48454. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  48455. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48456. + dwc_crypto.o dwc_notifier.o \
  48457. + dwc_common_linux.o dwc_mem.o
  48458. +
  48459. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  48460. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  48461. +
  48462. +ifneq ($(kernrel3),2.6.20)
  48463. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  48464. +ccflags-y += $(CPPFLAGS)
  48465. +endif
  48466. +
  48467. +else
  48468. +
  48469. +#ifeq ($(KDIR),)
  48470. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48471. +#endif
  48472. +
  48473. +ifeq ($(ARCH),)
  48474. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48475. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48476. +endif
  48477. +
  48478. +ifeq ($(DOXYGEN),)
  48479. +DOXYGEN := doxygen
  48480. +endif
  48481. +
  48482. +default:
  48483. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48484. +
  48485. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48486. + $(DOXYGEN) doc/doxygen.cfg
  48487. +
  48488. +tags: $(wildcard *.[hc])
  48489. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48490. +
  48491. +endif
  48492. +
  48493. +clean:
  48494. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48495. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-raspberry-pi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  48496. --- linux-3.10.33/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  48497. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-03-13 12:46:38.980096914 +0100
  48498. @@ -0,0 +1,17 @@
  48499. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  48500. +CFLAGS += -DDWC_FREEBSD
  48501. +CFLAGS += -DDEBUG
  48502. +#CFLAGS += -DDWC_DEBUG_REGS
  48503. +#CFLAGS += -DDWC_DEBUG_MEMORY
  48504. +
  48505. +#CFLAGS += -DDWC_LIBMODULE
  48506. +#CFLAGS += -DDWC_CCLIB
  48507. +#CFLAGS += -DDWC_CRYPTOLIB
  48508. +#CFLAGS += -DDWC_NOTIFYLIB
  48509. +#CFLAGS += -DDWC_UTFLIB
  48510. +
  48511. +KMOD = dwc_common_port_lib
  48512. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  48513. + dwc_common_fbsd.c dwc_mem.c
  48514. +
  48515. +.include <bsd.kmod.mk>
  48516. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/Makefile.linux linux-raspberry-pi/drivers/usb/host/dwc_common_port/Makefile.linux
  48517. --- linux-3.10.33/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  48518. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/Makefile.linux 2014-03-13 12:46:38.980096914 +0100
  48519. @@ -0,0 +1,49 @@
  48520. +#
  48521. +# Makefile for DWC_common library
  48522. +#
  48523. +ifneq ($(KERNELRELEASE),)
  48524. +
  48525. +ccflags-y += -DDWC_LINUX
  48526. +#ccflags-y += -DDEBUG
  48527. +#ccflags-y += -DDWC_DEBUG_REGS
  48528. +#ccflags-y += -DDWC_DEBUG_MEMORY
  48529. +
  48530. +ccflags-y += -DDWC_LIBMODULE
  48531. +ccflags-y += -DDWC_CCLIB
  48532. +ccflags-y += -DDWC_CRYPTOLIB
  48533. +ccflags-y += -DDWC_NOTIFYLIB
  48534. +ccflags-y += -DDWC_UTFLIB
  48535. +
  48536. +obj-m := dwc_common_port_lib.o
  48537. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48538. + dwc_crypto.o dwc_notifier.o \
  48539. + dwc_common_linux.o dwc_mem.o
  48540. +
  48541. +else
  48542. +
  48543. +ifeq ($(KDIR),)
  48544. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48545. +endif
  48546. +
  48547. +ifeq ($(ARCH),)
  48548. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48549. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48550. +endif
  48551. +
  48552. +ifeq ($(DOXYGEN),)
  48553. +DOXYGEN := doxygen
  48554. +endif
  48555. +
  48556. +default:
  48557. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48558. +
  48559. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48560. + $(DOXYGEN) doc/doxygen.cfg
  48561. +
  48562. +tags: $(wildcard *.[hc])
  48563. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48564. +
  48565. +endif
  48566. +
  48567. +clean:
  48568. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48569. diff -Nur linux-3.10.33/drivers/usb/host/dwc_common_port/usb.h linux-raspberry-pi/drivers/usb/host/dwc_common_port/usb.h
  48570. --- linux-3.10.33/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  48571. +++ linux-raspberry-pi/drivers/usb/host/dwc_common_port/usb.h 2014-03-13 12:46:39.480097919 +0100
  48572. @@ -0,0 +1,946 @@
  48573. +/*
  48574. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  48575. + * All rights reserved.
  48576. + *
  48577. + * This code is derived from software contributed to The NetBSD Foundation
  48578. + * by Lennart Augustsson (lennart@augustsson.net) at
  48579. + * Carlstedt Research & Technology.
  48580. + *
  48581. + * Redistribution and use in source and binary forms, with or without
  48582. + * modification, are permitted provided that the following conditions
  48583. + * are met:
  48584. + * 1. Redistributions of source code must retain the above copyright
  48585. + * notice, this list of conditions and the following disclaimer.
  48586. + * 2. Redistributions in binary form must reproduce the above copyright
  48587. + * notice, this list of conditions and the following disclaimer in the
  48588. + * documentation and/or other materials provided with the distribution.
  48589. + * 3. All advertising materials mentioning features or use of this software
  48590. + * must display the following acknowledgement:
  48591. + * This product includes software developed by the NetBSD
  48592. + * Foundation, Inc. and its contributors.
  48593. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  48594. + * contributors may be used to endorse or promote products derived
  48595. + * from this software without specific prior written permission.
  48596. + *
  48597. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  48598. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  48599. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48600. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  48601. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  48602. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  48603. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48604. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48605. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48606. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  48607. + * POSSIBILITY OF SUCH DAMAGE.
  48608. + */
  48609. +
  48610. +/* Modified by Synopsys, Inc, 12/12/2007 */
  48611. +
  48612. +
  48613. +#ifndef _USB_H_
  48614. +#define _USB_H_
  48615. +
  48616. +#ifdef __cplusplus
  48617. +extern "C" {
  48618. +#endif
  48619. +
  48620. +/*
  48621. + * The USB records contain some unaligned little-endian word
  48622. + * components. The U[SG]ETW macros take care of both the alignment
  48623. + * and endian problem and should always be used to access non-byte
  48624. + * values.
  48625. + */
  48626. +typedef u_int8_t uByte;
  48627. +typedef u_int8_t uWord[2];
  48628. +typedef u_int8_t uDWord[4];
  48629. +
  48630. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  48631. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  48632. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  48633. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  48634. +
  48635. +#if 1
  48636. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  48637. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  48638. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  48639. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  48640. + (w)[1] = (u_int8_t)((v) >> 8), \
  48641. + (w)[2] = (u_int8_t)((v) >> 16), \
  48642. + (w)[3] = (u_int8_t)((v) >> 24))
  48643. +#else
  48644. +/*
  48645. + * On little-endian machines that can handle unanliged accesses
  48646. + * (e.g. i386) these macros can be replaced by the following.
  48647. + */
  48648. +#define UGETW(w) (*(u_int16_t *)(w))
  48649. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  48650. +#define UGETDW(w) (*(u_int32_t *)(w))
  48651. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  48652. +#endif
  48653. +
  48654. +/*
  48655. + * Macros for accessing UAS IU fields, which are big-endian
  48656. + */
  48657. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  48658. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  48659. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  48660. + ((x) >> 8) & 0xff, (x) & 0xff }
  48661. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  48662. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  48663. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  48664. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  48665. + (w)[1] = (u_int8_t)((v) >> 16), \
  48666. + (w)[2] = (u_int8_t)((v) >> 8), \
  48667. + (w)[3] = (u_int8_t)(v))
  48668. +
  48669. +#define UPACKED __attribute__((__packed__))
  48670. +
  48671. +typedef struct {
  48672. + uByte bmRequestType;
  48673. + uByte bRequest;
  48674. + uWord wValue;
  48675. + uWord wIndex;
  48676. + uWord wLength;
  48677. +} UPACKED usb_device_request_t;
  48678. +
  48679. +#define UT_GET_DIR(a) ((a) & 0x80)
  48680. +#define UT_WRITE 0x00
  48681. +#define UT_READ 0x80
  48682. +
  48683. +#define UT_GET_TYPE(a) ((a) & 0x60)
  48684. +#define UT_STANDARD 0x00
  48685. +#define UT_CLASS 0x20
  48686. +#define UT_VENDOR 0x40
  48687. +
  48688. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  48689. +#define UT_DEVICE 0x00
  48690. +#define UT_INTERFACE 0x01
  48691. +#define UT_ENDPOINT 0x02
  48692. +#define UT_OTHER 0x03
  48693. +
  48694. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  48695. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  48696. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  48697. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  48698. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  48699. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  48700. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  48701. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  48702. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  48703. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  48704. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  48705. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  48706. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  48707. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  48708. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  48709. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  48710. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  48711. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  48712. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  48713. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  48714. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  48715. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  48716. +
  48717. +/* Requests */
  48718. +#define UR_GET_STATUS 0x00
  48719. +#define USTAT_STANDARD_STATUS 0x00
  48720. +#define WUSTAT_WUSB_FEATURE 0x01
  48721. +#define WUSTAT_CHANNEL_INFO 0x02
  48722. +#define WUSTAT_RECEIVED_DATA 0x03
  48723. +#define WUSTAT_MAS_AVAILABILITY 0x04
  48724. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  48725. +#define UR_CLEAR_FEATURE 0x01
  48726. +#define UR_SET_FEATURE 0x03
  48727. +#define UR_SET_AND_TEST_FEATURE 0x0c
  48728. +#define UR_SET_ADDRESS 0x05
  48729. +#define UR_GET_DESCRIPTOR 0x06
  48730. +#define UDESC_DEVICE 0x01
  48731. +#define UDESC_CONFIG 0x02
  48732. +#define UDESC_STRING 0x03
  48733. +#define UDESC_INTERFACE 0x04
  48734. +#define UDESC_ENDPOINT 0x05
  48735. +#define UDESC_SS_USB_COMPANION 0x30
  48736. +#define UDESC_DEVICE_QUALIFIER 0x06
  48737. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  48738. +#define UDESC_INTERFACE_POWER 0x08
  48739. +#define UDESC_OTG 0x09
  48740. +#define WUDESC_SECURITY 0x0c
  48741. +#define WUDESC_KEY 0x0d
  48742. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  48743. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  48744. +#define WUD_KEY_TYPE_ASSOC 0x01
  48745. +#define WUD_KEY_TYPE_GTK 0x02
  48746. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  48747. +#define WUD_KEY_ORIGIN_HOST 0x00
  48748. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  48749. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  48750. +#define WUDESC_BOS 0x0f
  48751. +#define WUDESC_DEVICE_CAPABILITY 0x10
  48752. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  48753. +#define UDESC_BOS 0x0f
  48754. +#define UDESC_DEVICE_CAPABILITY 0x10
  48755. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  48756. +#define UDESC_CS_CONFIG 0x22
  48757. +#define UDESC_CS_STRING 0x23
  48758. +#define UDESC_CS_INTERFACE 0x24
  48759. +#define UDESC_CS_ENDPOINT 0x25
  48760. +#define UDESC_HUB 0x29
  48761. +#define UR_SET_DESCRIPTOR 0x07
  48762. +#define UR_GET_CONFIG 0x08
  48763. +#define UR_SET_CONFIG 0x09
  48764. +#define UR_GET_INTERFACE 0x0a
  48765. +#define UR_SET_INTERFACE 0x0b
  48766. +#define UR_SYNCH_FRAME 0x0c
  48767. +#define WUR_SET_ENCRYPTION 0x0d
  48768. +#define WUR_GET_ENCRYPTION 0x0e
  48769. +#define WUR_SET_HANDSHAKE 0x0f
  48770. +#define WUR_GET_HANDSHAKE 0x10
  48771. +#define WUR_SET_CONNECTION 0x11
  48772. +#define WUR_SET_SECURITY_DATA 0x12
  48773. +#define WUR_GET_SECURITY_DATA 0x13
  48774. +#define WUR_SET_WUSB_DATA 0x14
  48775. +#define WUDATA_DRPIE_INFO 0x01
  48776. +#define WUDATA_TRANSMIT_DATA 0x02
  48777. +#define WUDATA_TRANSMIT_PARAMS 0x03
  48778. +#define WUDATA_RECEIVE_PARAMS 0x04
  48779. +#define WUDATA_TRANSMIT_POWER 0x05
  48780. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  48781. +#define WUR_LOOPBACK_DATA_READ 0x16
  48782. +#define WUR_SET_INTERFACE_DS 0x17
  48783. +
  48784. +/* Feature numbers */
  48785. +#define UF_ENDPOINT_HALT 0
  48786. +#define UF_DEVICE_REMOTE_WAKEUP 1
  48787. +#define UF_TEST_MODE 2
  48788. +#define UF_DEVICE_B_HNP_ENABLE 3
  48789. +#define UF_DEVICE_A_HNP_SUPPORT 4
  48790. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  48791. +#define WUF_WUSB 3
  48792. +#define WUF_TX_DRPIE 0x0
  48793. +#define WUF_DEV_XMIT_PACKET 0x1
  48794. +#define WUF_COUNT_PACKETS 0x2
  48795. +#define WUF_CAPTURE_PACKETS 0x3
  48796. +#define UF_FUNCTION_SUSPEND 0
  48797. +#define UF_U1_ENABLE 48
  48798. +#define UF_U2_ENABLE 49
  48799. +#define UF_LTM_ENABLE 50
  48800. +
  48801. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  48802. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  48803. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  48804. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  48805. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  48806. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  48807. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  48808. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  48809. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  48810. +
  48811. +#ifdef _MSC_VER
  48812. +#include <pshpack1.h>
  48813. +#endif
  48814. +
  48815. +typedef struct {
  48816. + uByte bLength;
  48817. + uByte bDescriptorType;
  48818. + uByte bDescriptorSubtype;
  48819. +} UPACKED usb_descriptor_t;
  48820. +
  48821. +typedef struct {
  48822. + uByte bLength;
  48823. + uByte bDescriptorType;
  48824. +} UPACKED usb_descriptor_header_t;
  48825. +
  48826. +typedef struct {
  48827. + uByte bLength;
  48828. + uByte bDescriptorType;
  48829. + uWord bcdUSB;
  48830. +#define UD_USB_2_0 0x0200
  48831. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  48832. + uByte bDeviceClass;
  48833. + uByte bDeviceSubClass;
  48834. + uByte bDeviceProtocol;
  48835. + uByte bMaxPacketSize;
  48836. + /* The fields below are not part of the initial descriptor. */
  48837. + uWord idVendor;
  48838. + uWord idProduct;
  48839. + uWord bcdDevice;
  48840. + uByte iManufacturer;
  48841. + uByte iProduct;
  48842. + uByte iSerialNumber;
  48843. + uByte bNumConfigurations;
  48844. +} UPACKED usb_device_descriptor_t;
  48845. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  48846. +
  48847. +typedef struct {
  48848. + uByte bLength;
  48849. + uByte bDescriptorType;
  48850. + uWord wTotalLength;
  48851. + uByte bNumInterface;
  48852. + uByte bConfigurationValue;
  48853. + uByte iConfiguration;
  48854. +#define UC_ATT_ONE (1 << 7) /* must be set */
  48855. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  48856. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  48857. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  48858. + uByte bmAttributes;
  48859. +#define UC_BUS_POWERED 0x80
  48860. +#define UC_SELF_POWERED 0x40
  48861. +#define UC_REMOTE_WAKEUP 0x20
  48862. + uByte bMaxPower; /* max current in 2 mA units */
  48863. +#define UC_POWER_FACTOR 2
  48864. +} UPACKED usb_config_descriptor_t;
  48865. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  48866. +
  48867. +typedef struct {
  48868. + uByte bLength;
  48869. + uByte bDescriptorType;
  48870. + uByte bInterfaceNumber;
  48871. + uByte bAlternateSetting;
  48872. + uByte bNumEndpoints;
  48873. + uByte bInterfaceClass;
  48874. + uByte bInterfaceSubClass;
  48875. + uByte bInterfaceProtocol;
  48876. + uByte iInterface;
  48877. +} UPACKED usb_interface_descriptor_t;
  48878. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  48879. +
  48880. +typedef struct {
  48881. + uByte bLength;
  48882. + uByte bDescriptorType;
  48883. + uByte bEndpointAddress;
  48884. +#define UE_GET_DIR(a) ((a) & 0x80)
  48885. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  48886. +#define UE_DIR_IN 0x80
  48887. +#define UE_DIR_OUT 0x00
  48888. +#define UE_ADDR 0x0f
  48889. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  48890. + uByte bmAttributes;
  48891. +#define UE_XFERTYPE 0x03
  48892. +#define UE_CONTROL 0x00
  48893. +#define UE_ISOCHRONOUS 0x01
  48894. +#define UE_BULK 0x02
  48895. +#define UE_INTERRUPT 0x03
  48896. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  48897. +#define UE_ISO_TYPE 0x0c
  48898. +#define UE_ISO_ASYNC 0x04
  48899. +#define UE_ISO_ADAPT 0x08
  48900. +#define UE_ISO_SYNC 0x0c
  48901. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  48902. + uWord wMaxPacketSize;
  48903. + uByte bInterval;
  48904. +} UPACKED usb_endpoint_descriptor_t;
  48905. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  48906. +
  48907. +typedef struct ss_endpoint_companion_descriptor {
  48908. + uByte bLength;
  48909. + uByte bDescriptorType;
  48910. + uByte bMaxBurst;
  48911. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  48912. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  48913. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  48914. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  48915. + uByte bmAttributes;
  48916. + uWord wBytesPerInterval;
  48917. +} UPACKED ss_endpoint_companion_descriptor_t;
  48918. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  48919. +
  48920. +typedef struct {
  48921. + uByte bLength;
  48922. + uByte bDescriptorType;
  48923. + uWord bString[127];
  48924. +} UPACKED usb_string_descriptor_t;
  48925. +#define USB_MAX_STRING_LEN 128
  48926. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  48927. +
  48928. +/* Hub specific request */
  48929. +#define UR_GET_BUS_STATE 0x02
  48930. +#define UR_CLEAR_TT_BUFFER 0x08
  48931. +#define UR_RESET_TT 0x09
  48932. +#define UR_GET_TT_STATE 0x0a
  48933. +#define UR_STOP_TT 0x0b
  48934. +
  48935. +/* Hub features */
  48936. +#define UHF_C_HUB_LOCAL_POWER 0
  48937. +#define UHF_C_HUB_OVER_CURRENT 1
  48938. +#define UHF_PORT_CONNECTION 0
  48939. +#define UHF_PORT_ENABLE 1
  48940. +#define UHF_PORT_SUSPEND 2
  48941. +#define UHF_PORT_OVER_CURRENT 3
  48942. +#define UHF_PORT_RESET 4
  48943. +#define UHF_PORT_L1 5
  48944. +#define UHF_PORT_POWER 8
  48945. +#define UHF_PORT_LOW_SPEED 9
  48946. +#define UHF_PORT_HIGH_SPEED 10
  48947. +#define UHF_C_PORT_CONNECTION 16
  48948. +#define UHF_C_PORT_ENABLE 17
  48949. +#define UHF_C_PORT_SUSPEND 18
  48950. +#define UHF_C_PORT_OVER_CURRENT 19
  48951. +#define UHF_C_PORT_RESET 20
  48952. +#define UHF_C_PORT_L1 23
  48953. +#define UHF_PORT_TEST 21
  48954. +#define UHF_PORT_INDICATOR 22
  48955. +
  48956. +typedef struct {
  48957. + uByte bDescLength;
  48958. + uByte bDescriptorType;
  48959. + uByte bNbrPorts;
  48960. + uWord wHubCharacteristics;
  48961. +#define UHD_PWR 0x0003
  48962. +#define UHD_PWR_GANGED 0x0000
  48963. +#define UHD_PWR_INDIVIDUAL 0x0001
  48964. +#define UHD_PWR_NO_SWITCH 0x0002
  48965. +#define UHD_COMPOUND 0x0004
  48966. +#define UHD_OC 0x0018
  48967. +#define UHD_OC_GLOBAL 0x0000
  48968. +#define UHD_OC_INDIVIDUAL 0x0008
  48969. +#define UHD_OC_NONE 0x0010
  48970. +#define UHD_TT_THINK 0x0060
  48971. +#define UHD_TT_THINK_8 0x0000
  48972. +#define UHD_TT_THINK_16 0x0020
  48973. +#define UHD_TT_THINK_24 0x0040
  48974. +#define UHD_TT_THINK_32 0x0060
  48975. +#define UHD_PORT_IND 0x0080
  48976. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  48977. +#define UHD_PWRON_FACTOR 2
  48978. + uByte bHubContrCurrent;
  48979. + uByte DeviceRemovable[32]; /* max 255 ports */
  48980. +#define UHD_NOT_REMOV(desc, i) \
  48981. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  48982. + /* deprecated */ uByte PortPowerCtrlMask[1];
  48983. +} UPACKED usb_hub_descriptor_t;
  48984. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  48985. +
  48986. +typedef struct {
  48987. + uByte bLength;
  48988. + uByte bDescriptorType;
  48989. + uWord bcdUSB;
  48990. + uByte bDeviceClass;
  48991. + uByte bDeviceSubClass;
  48992. + uByte bDeviceProtocol;
  48993. + uByte bMaxPacketSize0;
  48994. + uByte bNumConfigurations;
  48995. + uByte bReserved;
  48996. +} UPACKED usb_device_qualifier_t;
  48997. +#define USB_DEVICE_QUALIFIER_SIZE 10
  48998. +
  48999. +typedef struct {
  49000. + uByte bLength;
  49001. + uByte bDescriptorType;
  49002. + uByte bmAttributes;
  49003. +#define UOTG_SRP 0x01
  49004. +#define UOTG_HNP 0x02
  49005. +} UPACKED usb_otg_descriptor_t;
  49006. +
  49007. +/* OTG feature selectors */
  49008. +#define UOTG_B_HNP_ENABLE 3
  49009. +#define UOTG_A_HNP_SUPPORT 4
  49010. +#define UOTG_A_ALT_HNP_SUPPORT 5
  49011. +
  49012. +typedef struct {
  49013. + uWord wStatus;
  49014. +/* Device status flags */
  49015. +#define UDS_SELF_POWERED 0x0001
  49016. +#define UDS_REMOTE_WAKEUP 0x0002
  49017. +/* Endpoint status flags */
  49018. +#define UES_HALT 0x0001
  49019. +} UPACKED usb_status_t;
  49020. +
  49021. +typedef struct {
  49022. + uWord wHubStatus;
  49023. +#define UHS_LOCAL_POWER 0x0001
  49024. +#define UHS_OVER_CURRENT 0x0002
  49025. + uWord wHubChange;
  49026. +} UPACKED usb_hub_status_t;
  49027. +
  49028. +typedef struct {
  49029. + uWord wPortStatus;
  49030. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  49031. +#define UPS_PORT_ENABLED 0x0002
  49032. +#define UPS_SUSPEND 0x0004
  49033. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  49034. +#define UPS_RESET 0x0010
  49035. +#define UPS_PORT_POWER 0x0100
  49036. +#define UPS_LOW_SPEED 0x0200
  49037. +#define UPS_HIGH_SPEED 0x0400
  49038. +#define UPS_PORT_TEST 0x0800
  49039. +#define UPS_PORT_INDICATOR 0x1000
  49040. + uWord wPortChange;
  49041. +#define UPS_C_CONNECT_STATUS 0x0001
  49042. +#define UPS_C_PORT_ENABLED 0x0002
  49043. +#define UPS_C_SUSPEND 0x0004
  49044. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  49045. +#define UPS_C_PORT_RESET 0x0010
  49046. +} UPACKED usb_port_status_t;
  49047. +
  49048. +#ifdef _MSC_VER
  49049. +#include <poppack.h>
  49050. +#endif
  49051. +
  49052. +/* Device class codes */
  49053. +#define UDCLASS_IN_INTERFACE 0x00
  49054. +#define UDCLASS_COMM 0x02
  49055. +#define UDCLASS_HUB 0x09
  49056. +#define UDSUBCLASS_HUB 0x00
  49057. +#define UDPROTO_FSHUB 0x00
  49058. +#define UDPROTO_HSHUBSTT 0x01
  49059. +#define UDPROTO_HSHUBMTT 0x02
  49060. +#define UDCLASS_DIAGNOSTIC 0xdc
  49061. +#define UDCLASS_WIRELESS 0xe0
  49062. +#define UDSUBCLASS_RF 0x01
  49063. +#define UDPROTO_BLUETOOTH 0x01
  49064. +#define UDCLASS_VENDOR 0xff
  49065. +
  49066. +/* Interface class codes */
  49067. +#define UICLASS_UNSPEC 0x00
  49068. +
  49069. +#define UICLASS_AUDIO 0x01
  49070. +#define UISUBCLASS_AUDIOCONTROL 1
  49071. +#define UISUBCLASS_AUDIOSTREAM 2
  49072. +#define UISUBCLASS_MIDISTREAM 3
  49073. +
  49074. +#define UICLASS_CDC 0x02 /* communication */
  49075. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  49076. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  49077. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  49078. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  49079. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  49080. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  49081. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  49082. +#define UIPROTO_CDC_AT 1
  49083. +
  49084. +#define UICLASS_HID 0x03
  49085. +#define UISUBCLASS_BOOT 1
  49086. +#define UIPROTO_BOOT_KEYBOARD 1
  49087. +
  49088. +#define UICLASS_PHYSICAL 0x05
  49089. +
  49090. +#define UICLASS_IMAGE 0x06
  49091. +
  49092. +#define UICLASS_PRINTER 0x07
  49093. +#define UISUBCLASS_PRINTER 1
  49094. +#define UIPROTO_PRINTER_UNI 1
  49095. +#define UIPROTO_PRINTER_BI 2
  49096. +#define UIPROTO_PRINTER_1284 3
  49097. +
  49098. +#define UICLASS_MASS 0x08
  49099. +#define UISUBCLASS_RBC 1
  49100. +#define UISUBCLASS_SFF8020I 2
  49101. +#define UISUBCLASS_QIC157 3
  49102. +#define UISUBCLASS_UFI 4
  49103. +#define UISUBCLASS_SFF8070I 5
  49104. +#define UISUBCLASS_SCSI 6
  49105. +#define UIPROTO_MASS_CBI_I 0
  49106. +#define UIPROTO_MASS_CBI 1
  49107. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  49108. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  49109. +
  49110. +#define UICLASS_HUB 0x09
  49111. +#define UISUBCLASS_HUB 0
  49112. +#define UIPROTO_FSHUB 0
  49113. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  49114. +#define UIPROTO_HSHUBMTT 1
  49115. +
  49116. +#define UICLASS_CDC_DATA 0x0a
  49117. +#define UISUBCLASS_DATA 0
  49118. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  49119. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  49120. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  49121. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  49122. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  49123. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  49124. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  49125. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  49126. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  49127. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  49128. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  49129. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  49130. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  49131. +
  49132. +#define UICLASS_SMARTCARD 0x0b
  49133. +
  49134. +/*#define UICLASS_FIRM_UPD 0x0c*/
  49135. +
  49136. +#define UICLASS_SECURITY 0x0d
  49137. +
  49138. +#define UICLASS_DIAGNOSTIC 0xdc
  49139. +
  49140. +#define UICLASS_WIRELESS 0xe0
  49141. +#define UISUBCLASS_RF 0x01
  49142. +#define UIPROTO_BLUETOOTH 0x01
  49143. +
  49144. +#define UICLASS_APPL_SPEC 0xfe
  49145. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  49146. +#define UISUBCLASS_IRDA 2
  49147. +#define UIPROTO_IRDA 0
  49148. +
  49149. +#define UICLASS_VENDOR 0xff
  49150. +
  49151. +#define USB_HUB_MAX_DEPTH 5
  49152. +
  49153. +/*
  49154. + * Minimum time a device needs to be powered down to go through
  49155. + * a power cycle. XXX Are these time in the spec?
  49156. + */
  49157. +#define USB_POWER_DOWN_TIME 200 /* ms */
  49158. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  49159. +
  49160. +#if 0
  49161. +/* These are the values from the spec. */
  49162. +#define USB_PORT_RESET_DELAY 10 /* ms */
  49163. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  49164. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  49165. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  49166. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  49167. +#define USB_RESUME_DELAY (20*5) /* ms */
  49168. +#define USB_RESUME_WAIT 10 /* ms */
  49169. +#define USB_RESUME_RECOVERY 10 /* ms */
  49170. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  49171. +#else
  49172. +/* Allow for marginal (i.e. non-conforming) devices. */
  49173. +#define USB_PORT_RESET_DELAY 50 /* ms */
  49174. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  49175. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  49176. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  49177. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  49178. +#define USB_RESUME_DELAY (50*5) /* ms */
  49179. +#define USB_RESUME_WAIT 50 /* ms */
  49180. +#define USB_RESUME_RECOVERY 50 /* ms */
  49181. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  49182. +#endif
  49183. +
  49184. +#define USB_MIN_POWER 100 /* mA */
  49185. +#define USB_MAX_POWER 500 /* mA */
  49186. +
  49187. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  49188. +
  49189. +#define USB_UNCONFIG_NO 0
  49190. +#define USB_UNCONFIG_INDEX (-1)
  49191. +
  49192. +/*** ioctl() related stuff ***/
  49193. +
  49194. +struct usb_ctl_request {
  49195. + int ucr_addr;
  49196. + usb_device_request_t ucr_request;
  49197. + void *ucr_data;
  49198. + int ucr_flags;
  49199. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  49200. + int ucr_actlen; /* actual length transferred */
  49201. +};
  49202. +
  49203. +struct usb_alt_interface {
  49204. + int uai_config_index;
  49205. + int uai_interface_index;
  49206. + int uai_alt_no;
  49207. +};
  49208. +
  49209. +#define USB_CURRENT_CONFIG_INDEX (-1)
  49210. +#define USB_CURRENT_ALT_INDEX (-1)
  49211. +
  49212. +struct usb_config_desc {
  49213. + int ucd_config_index;
  49214. + usb_config_descriptor_t ucd_desc;
  49215. +};
  49216. +
  49217. +struct usb_interface_desc {
  49218. + int uid_config_index;
  49219. + int uid_interface_index;
  49220. + int uid_alt_index;
  49221. + usb_interface_descriptor_t uid_desc;
  49222. +};
  49223. +
  49224. +struct usb_endpoint_desc {
  49225. + int ued_config_index;
  49226. + int ued_interface_index;
  49227. + int ued_alt_index;
  49228. + int ued_endpoint_index;
  49229. + usb_endpoint_descriptor_t ued_desc;
  49230. +};
  49231. +
  49232. +struct usb_full_desc {
  49233. + int ufd_config_index;
  49234. + u_int ufd_size;
  49235. + u_char *ufd_data;
  49236. +};
  49237. +
  49238. +struct usb_string_desc {
  49239. + int usd_string_index;
  49240. + int usd_language_id;
  49241. + usb_string_descriptor_t usd_desc;
  49242. +};
  49243. +
  49244. +struct usb_ctl_report_desc {
  49245. + int ucrd_size;
  49246. + u_char ucrd_data[1024]; /* filled data size will vary */
  49247. +};
  49248. +
  49249. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  49250. +
  49251. +#define USB_MAX_DEVNAMES 4
  49252. +#define USB_MAX_DEVNAMELEN 16
  49253. +struct usb_device_info {
  49254. + u_int8_t udi_bus;
  49255. + u_int8_t udi_addr; /* device address */
  49256. + usb_event_cookie_t udi_cookie;
  49257. + char udi_product[USB_MAX_STRING_LEN];
  49258. + char udi_vendor[USB_MAX_STRING_LEN];
  49259. + char udi_release[8];
  49260. + u_int16_t udi_productNo;
  49261. + u_int16_t udi_vendorNo;
  49262. + u_int16_t udi_releaseNo;
  49263. + u_int8_t udi_class;
  49264. + u_int8_t udi_subclass;
  49265. + u_int8_t udi_protocol;
  49266. + u_int8_t udi_config;
  49267. + u_int8_t udi_speed;
  49268. +#define USB_SPEED_UNKNOWN 0
  49269. +#define USB_SPEED_LOW 1
  49270. +#define USB_SPEED_FULL 2
  49271. +#define USB_SPEED_HIGH 3
  49272. +#define USB_SPEED_VARIABLE 4
  49273. +#define USB_SPEED_SUPER 5
  49274. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  49275. + int udi_nports;
  49276. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  49277. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  49278. +#define USB_PORT_ENABLED 0xff
  49279. +#define USB_PORT_SUSPENDED 0xfe
  49280. +#define USB_PORT_POWERED 0xfd
  49281. +#define USB_PORT_DISABLED 0xfc
  49282. +};
  49283. +
  49284. +struct usb_ctl_report {
  49285. + int ucr_report;
  49286. + u_char ucr_data[1024]; /* filled data size will vary */
  49287. +};
  49288. +
  49289. +struct usb_device_stats {
  49290. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  49291. +};
  49292. +
  49293. +#define WUSB_MIN_IE 0x80
  49294. +#define WUSB_WCTA_IE 0x80
  49295. +#define WUSB_WCONNECTACK_IE 0x81
  49296. +#define WUSB_WHOSTINFO_IE 0x82
  49297. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  49298. +#define WUHI_CA_RECONN 0x00
  49299. +#define WUHI_CA_LIMITED 0x01
  49300. +#define WUHI_CA_ALL 0x03
  49301. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  49302. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  49303. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  49304. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  49305. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  49306. +#define WUSB_WWORK_IE 0x87
  49307. +#define WUSB_WCHANNEL_STOP_IE 0x88
  49308. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  49309. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  49310. +#define WUSB_WRESETDEVICE_IE 0x8B
  49311. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  49312. +#define WUSB_MAX_IE 0x8C
  49313. +
  49314. +/* Device Notification Types */
  49315. +
  49316. +#define WUSB_DN_MIN 0x01
  49317. +#define WUSB_DN_CONNECT 0x01
  49318. +# define WUSB_DA_OLDCONN 0x00
  49319. +# define WUSB_DA_NEWCONN 0x01
  49320. +# define WUSB_DA_SELF_BEACON 0x02
  49321. +# define WUSB_DA_DIR_BEACON 0x04
  49322. +# define WUSB_DA_NO_BEACON 0x06
  49323. +#define WUSB_DN_DISCONNECT 0x02
  49324. +#define WUSB_DN_EPRDY 0x03
  49325. +#define WUSB_DN_MASAVAILCHANGED 0x04
  49326. +#define WUSB_DN_REMOTEWAKEUP 0x05
  49327. +#define WUSB_DN_SLEEP 0x06
  49328. +#define WUSB_DN_ALIVE 0x07
  49329. +#define WUSB_DN_MAX 0x07
  49330. +
  49331. +#ifdef _MSC_VER
  49332. +#include <pshpack1.h>
  49333. +#endif
  49334. +
  49335. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  49336. +typedef struct wusb_hndshk_data {
  49337. + uByte bMessageNumber;
  49338. + uByte bStatus;
  49339. + uByte tTKID[3];
  49340. + uByte bReserved;
  49341. + uByte CDID[16];
  49342. + uByte Nonce[16];
  49343. + uByte MIC[8];
  49344. +} UPACKED wusb_hndshk_data_t;
  49345. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  49346. +
  49347. +/* WUSB Connection Context */
  49348. +typedef struct wusb_conn_context {
  49349. + uByte CHID [16];
  49350. + uByte CDID [16];
  49351. + uByte CK [16];
  49352. +} UPACKED wusb_conn_context_t;
  49353. +
  49354. +/* WUSB Security Descriptor */
  49355. +typedef struct wusb_security_desc {
  49356. + uByte bLength;
  49357. + uByte bDescriptorType;
  49358. + uWord wTotalLength;
  49359. + uByte bNumEncryptionTypes;
  49360. +} UPACKED wusb_security_desc_t;
  49361. +
  49362. +/* WUSB Encryption Type Descriptor */
  49363. +typedef struct wusb_encrypt_type_desc {
  49364. + uByte bLength;
  49365. + uByte bDescriptorType;
  49366. +
  49367. + uByte bEncryptionType;
  49368. +#define WUETD_UNSECURE 0
  49369. +#define WUETD_WIRED 1
  49370. +#define WUETD_CCM_1 2
  49371. +#define WUETD_RSA_1 3
  49372. +
  49373. + uByte bEncryptionValue;
  49374. + uByte bAuthKeyIndex;
  49375. +} UPACKED wusb_encrypt_type_desc_t;
  49376. +
  49377. +/* WUSB Key Descriptor */
  49378. +typedef struct wusb_key_desc {
  49379. + uByte bLength;
  49380. + uByte bDescriptorType;
  49381. + uByte tTKID[3];
  49382. + uByte bReserved;
  49383. + uByte KeyData[1]; /* variable length */
  49384. +} UPACKED wusb_key_desc_t;
  49385. +
  49386. +/* WUSB BOS Descriptor (Binary device Object Store) */
  49387. +typedef struct wusb_bos_desc {
  49388. + uByte bLength;
  49389. + uByte bDescriptorType;
  49390. + uWord wTotalLength;
  49391. + uByte bNumDeviceCaps;
  49392. +} UPACKED wusb_bos_desc_t;
  49393. +
  49394. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  49395. +typedef struct usb_dev_cap_20_ext_desc {
  49396. + uByte bLength;
  49397. + uByte bDescriptorType;
  49398. + uByte bDevCapabilityType;
  49399. +#define USB_20_EXT_LPM 0x02
  49400. + uDWord bmAttributes;
  49401. +} UPACKED usb_dev_cap_20_ext_desc_t;
  49402. +
  49403. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  49404. +typedef struct usb_dev_cap_ss_usb {
  49405. + uByte bLength;
  49406. + uByte bDescriptorType;
  49407. + uByte bDevCapabilityType;
  49408. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  49409. + uByte bmAttributes;
  49410. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  49411. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  49412. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  49413. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  49414. + uWord wSpeedsSupported;
  49415. + uByte bFunctionalitySupport;
  49416. + uByte bU1DevExitLat;
  49417. + uWord wU2DevExitLat;
  49418. +} UPACKED usb_dev_cap_ss_usb_t;
  49419. +
  49420. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  49421. +typedef struct usb_dev_cap_container_id {
  49422. + uByte bLength;
  49423. + uByte bDescriptorType;
  49424. + uByte bDevCapabilityType;
  49425. + uByte bReserved;
  49426. + uByte containerID[16];
  49427. +} UPACKED usb_dev_cap_container_id_t;
  49428. +
  49429. +/* Device Capability Type Codes */
  49430. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  49431. +
  49432. +/* Device Capability Descriptor */
  49433. +typedef struct wusb_dev_cap_desc {
  49434. + uByte bLength;
  49435. + uByte bDescriptorType;
  49436. + uByte bDevCapabilityType;
  49437. + uByte caps[1]; /* Variable length */
  49438. +} UPACKED wusb_dev_cap_desc_t;
  49439. +
  49440. +/* Device Capability Descriptor */
  49441. +typedef struct wusb_dev_cap_uwb_desc {
  49442. + uByte bLength;
  49443. + uByte bDescriptorType;
  49444. + uByte bDevCapabilityType;
  49445. + uByte bmAttributes;
  49446. + uWord wPHYRates; /* Bitmap */
  49447. + uByte bmTFITXPowerInfo;
  49448. + uByte bmFFITXPowerInfo;
  49449. + uWord bmBandGroup;
  49450. + uByte bReserved;
  49451. +} UPACKED wusb_dev_cap_uwb_desc_t;
  49452. +
  49453. +/* Wireless USB Endpoint Companion Descriptor */
  49454. +typedef struct wusb_endpoint_companion_desc {
  49455. + uByte bLength;
  49456. + uByte bDescriptorType;
  49457. + uByte bMaxBurst;
  49458. + uByte bMaxSequence;
  49459. + uWord wMaxStreamDelay;
  49460. + uWord wOverTheAirPacketSize;
  49461. + uByte bOverTheAirInterval;
  49462. + uByte bmCompAttributes;
  49463. +} UPACKED wusb_endpoint_companion_desc_t;
  49464. +
  49465. +/* Wireless USB Numeric Association M1 Data Structure */
  49466. +typedef struct wusb_m1_data {
  49467. + uByte version;
  49468. + uWord langId;
  49469. + uByte deviceFriendlyNameLength;
  49470. + uByte sha_256_m3[32];
  49471. + uByte deviceFriendlyName[256];
  49472. +} UPACKED wusb_m1_data_t;
  49473. +
  49474. +typedef struct wusb_m2_data {
  49475. + uByte version;
  49476. + uWord langId;
  49477. + uByte hostFriendlyNameLength;
  49478. + uByte pkh[384];
  49479. + uByte hostFriendlyName[256];
  49480. +} UPACKED wusb_m2_data_t;
  49481. +
  49482. +typedef struct wusb_m3_data {
  49483. + uByte pkd[384];
  49484. + uByte nd;
  49485. +} UPACKED wusb_m3_data_t;
  49486. +
  49487. +typedef struct wusb_m4_data {
  49488. + uDWord _attributeTypeIdAndLength_1;
  49489. + uWord associationTypeId;
  49490. +
  49491. + uDWord _attributeTypeIdAndLength_2;
  49492. + uWord associationSubTypeId;
  49493. +
  49494. + uDWord _attributeTypeIdAndLength_3;
  49495. + uDWord length;
  49496. +
  49497. + uDWord _attributeTypeIdAndLength_4;
  49498. + uDWord associationStatus;
  49499. +
  49500. + uDWord _attributeTypeIdAndLength_5;
  49501. + uByte chid[16];
  49502. +
  49503. + uDWord _attributeTypeIdAndLength_6;
  49504. + uByte cdid[16];
  49505. +
  49506. + uDWord _attributeTypeIdAndLength_7;
  49507. + uByte bandGroups[2];
  49508. +} UPACKED wusb_m4_data_t;
  49509. +
  49510. +#ifdef _MSC_VER
  49511. +#include <poppack.h>
  49512. +#endif
  49513. +
  49514. +#ifdef __cplusplus
  49515. +}
  49516. +#endif
  49517. +
  49518. +#endif /* _USB_H_ */
  49519. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-raspberry-pi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  49520. --- linux-3.10.33/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  49521. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-03-13 12:46:39.512097981 +0100
  49522. @@ -0,0 +1,224 @@
  49523. +# Doxyfile 1.3.9.1
  49524. +
  49525. +#---------------------------------------------------------------------------
  49526. +# Project related configuration options
  49527. +#---------------------------------------------------------------------------
  49528. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  49529. +PROJECT_NUMBER = v3.00a
  49530. +OUTPUT_DIRECTORY = ./doc/
  49531. +CREATE_SUBDIRS = NO
  49532. +OUTPUT_LANGUAGE = English
  49533. +BRIEF_MEMBER_DESC = YES
  49534. +REPEAT_BRIEF = YES
  49535. +ABBREVIATE_BRIEF = "The $name class" \
  49536. + "The $name widget" \
  49537. + "The $name file" \
  49538. + is \
  49539. + provides \
  49540. + specifies \
  49541. + contains \
  49542. + represents \
  49543. + a \
  49544. + an \
  49545. + the
  49546. +ALWAYS_DETAILED_SEC = NO
  49547. +INLINE_INHERITED_MEMB = NO
  49548. +FULL_PATH_NAMES = NO
  49549. +STRIP_FROM_PATH =
  49550. +STRIP_FROM_INC_PATH =
  49551. +SHORT_NAMES = NO
  49552. +JAVADOC_AUTOBRIEF = YES
  49553. +MULTILINE_CPP_IS_BRIEF = NO
  49554. +INHERIT_DOCS = YES
  49555. +DISTRIBUTE_GROUP_DOC = NO
  49556. +TAB_SIZE = 8
  49557. +ALIASES =
  49558. +OPTIMIZE_OUTPUT_FOR_C = YES
  49559. +OPTIMIZE_OUTPUT_JAVA = NO
  49560. +SUBGROUPING = YES
  49561. +#---------------------------------------------------------------------------
  49562. +# Build related configuration options
  49563. +#---------------------------------------------------------------------------
  49564. +EXTRACT_ALL = NO
  49565. +EXTRACT_PRIVATE = YES
  49566. +EXTRACT_STATIC = YES
  49567. +EXTRACT_LOCAL_CLASSES = YES
  49568. +EXTRACT_LOCAL_METHODS = NO
  49569. +HIDE_UNDOC_MEMBERS = NO
  49570. +HIDE_UNDOC_CLASSES = NO
  49571. +HIDE_FRIEND_COMPOUNDS = NO
  49572. +HIDE_IN_BODY_DOCS = NO
  49573. +INTERNAL_DOCS = NO
  49574. +CASE_SENSE_NAMES = NO
  49575. +HIDE_SCOPE_NAMES = NO
  49576. +SHOW_INCLUDE_FILES = YES
  49577. +INLINE_INFO = YES
  49578. +SORT_MEMBER_DOCS = NO
  49579. +SORT_BRIEF_DOCS = NO
  49580. +SORT_BY_SCOPE_NAME = NO
  49581. +GENERATE_TODOLIST = YES
  49582. +GENERATE_TESTLIST = YES
  49583. +GENERATE_BUGLIST = YES
  49584. +GENERATE_DEPRECATEDLIST= YES
  49585. +ENABLED_SECTIONS =
  49586. +MAX_INITIALIZER_LINES = 30
  49587. +SHOW_USED_FILES = YES
  49588. +SHOW_DIRECTORIES = YES
  49589. +#---------------------------------------------------------------------------
  49590. +# configuration options related to warning and progress messages
  49591. +#---------------------------------------------------------------------------
  49592. +QUIET = YES
  49593. +WARNINGS = YES
  49594. +WARN_IF_UNDOCUMENTED = NO
  49595. +WARN_IF_DOC_ERROR = YES
  49596. +WARN_FORMAT = "$file:$line: $text"
  49597. +WARN_LOGFILE =
  49598. +#---------------------------------------------------------------------------
  49599. +# configuration options related to the input files
  49600. +#---------------------------------------------------------------------------
  49601. +INPUT = .
  49602. +FILE_PATTERNS = *.c \
  49603. + *.h \
  49604. + ./linux/*.c \
  49605. + ./linux/*.h
  49606. +RECURSIVE = NO
  49607. +EXCLUDE = ./test/ \
  49608. + ./dwc_otg/.AppleDouble/
  49609. +EXCLUDE_SYMLINKS = YES
  49610. +EXCLUDE_PATTERNS = *.mod.*
  49611. +EXAMPLE_PATH =
  49612. +EXAMPLE_PATTERNS = *
  49613. +EXAMPLE_RECURSIVE = NO
  49614. +IMAGE_PATH =
  49615. +INPUT_FILTER =
  49616. +FILTER_PATTERNS =
  49617. +FILTER_SOURCE_FILES = NO
  49618. +#---------------------------------------------------------------------------
  49619. +# configuration options related to source browsing
  49620. +#---------------------------------------------------------------------------
  49621. +SOURCE_BROWSER = YES
  49622. +INLINE_SOURCES = NO
  49623. +STRIP_CODE_COMMENTS = YES
  49624. +REFERENCED_BY_RELATION = NO
  49625. +REFERENCES_RELATION = NO
  49626. +VERBATIM_HEADERS = NO
  49627. +#---------------------------------------------------------------------------
  49628. +# configuration options related to the alphabetical class index
  49629. +#---------------------------------------------------------------------------
  49630. +ALPHABETICAL_INDEX = NO
  49631. +COLS_IN_ALPHA_INDEX = 5
  49632. +IGNORE_PREFIX =
  49633. +#---------------------------------------------------------------------------
  49634. +# configuration options related to the HTML output
  49635. +#---------------------------------------------------------------------------
  49636. +GENERATE_HTML = YES
  49637. +HTML_OUTPUT = html
  49638. +HTML_FILE_EXTENSION = .html
  49639. +HTML_HEADER =
  49640. +HTML_FOOTER =
  49641. +HTML_STYLESHEET =
  49642. +HTML_ALIGN_MEMBERS = YES
  49643. +GENERATE_HTMLHELP = NO
  49644. +CHM_FILE =
  49645. +HHC_LOCATION =
  49646. +GENERATE_CHI = NO
  49647. +BINARY_TOC = NO
  49648. +TOC_EXPAND = NO
  49649. +DISABLE_INDEX = NO
  49650. +ENUM_VALUES_PER_LINE = 4
  49651. +GENERATE_TREEVIEW = YES
  49652. +TREEVIEW_WIDTH = 250
  49653. +#---------------------------------------------------------------------------
  49654. +# configuration options related to the LaTeX output
  49655. +#---------------------------------------------------------------------------
  49656. +GENERATE_LATEX = NO
  49657. +LATEX_OUTPUT = latex
  49658. +LATEX_CMD_NAME = latex
  49659. +MAKEINDEX_CMD_NAME = makeindex
  49660. +COMPACT_LATEX = NO
  49661. +PAPER_TYPE = a4wide
  49662. +EXTRA_PACKAGES =
  49663. +LATEX_HEADER =
  49664. +PDF_HYPERLINKS = NO
  49665. +USE_PDFLATEX = NO
  49666. +LATEX_BATCHMODE = NO
  49667. +LATEX_HIDE_INDICES = NO
  49668. +#---------------------------------------------------------------------------
  49669. +# configuration options related to the RTF output
  49670. +#---------------------------------------------------------------------------
  49671. +GENERATE_RTF = NO
  49672. +RTF_OUTPUT = rtf
  49673. +COMPACT_RTF = NO
  49674. +RTF_HYPERLINKS = NO
  49675. +RTF_STYLESHEET_FILE =
  49676. +RTF_EXTENSIONS_FILE =
  49677. +#---------------------------------------------------------------------------
  49678. +# configuration options related to the man page output
  49679. +#---------------------------------------------------------------------------
  49680. +GENERATE_MAN = NO
  49681. +MAN_OUTPUT = man
  49682. +MAN_EXTENSION = .3
  49683. +MAN_LINKS = NO
  49684. +#---------------------------------------------------------------------------
  49685. +# configuration options related to the XML output
  49686. +#---------------------------------------------------------------------------
  49687. +GENERATE_XML = NO
  49688. +XML_OUTPUT = xml
  49689. +XML_SCHEMA =
  49690. +XML_DTD =
  49691. +XML_PROGRAMLISTING = YES
  49692. +#---------------------------------------------------------------------------
  49693. +# configuration options for the AutoGen Definitions output
  49694. +#---------------------------------------------------------------------------
  49695. +GENERATE_AUTOGEN_DEF = NO
  49696. +#---------------------------------------------------------------------------
  49697. +# configuration options related to the Perl module output
  49698. +#---------------------------------------------------------------------------
  49699. +GENERATE_PERLMOD = NO
  49700. +PERLMOD_LATEX = NO
  49701. +PERLMOD_PRETTY = YES
  49702. +PERLMOD_MAKEVAR_PREFIX =
  49703. +#---------------------------------------------------------------------------
  49704. +# Configuration options related to the preprocessor
  49705. +#---------------------------------------------------------------------------
  49706. +ENABLE_PREPROCESSING = YES
  49707. +MACRO_EXPANSION = YES
  49708. +EXPAND_ONLY_PREDEF = YES
  49709. +SEARCH_INCLUDES = YES
  49710. +INCLUDE_PATH =
  49711. +INCLUDE_FILE_PATTERNS =
  49712. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  49713. +EXPAND_AS_DEFINED = DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW DWC_OTG_DEVICE_ATTR_BITFIELD_STORE DWC_OTG_DEVICE_ATTR_BITFIELD_RW DWC_OTG_DEVICE_ATTR_BITFIELD_RO DWC_OTG_DEVICE_ATTR_REG_SHOW DWC_OTG_DEVICE_ATTR_REG_STORE DWC_OTG_DEVICE_ATTR_REG32_RW DWC_OTG_DEVICE_ATTR_REG32_RO DWC_EN_ISOC
  49714. +SKIP_FUNCTION_MACROS = NO
  49715. +#---------------------------------------------------------------------------
  49716. +# Configuration::additions related to external references
  49717. +#---------------------------------------------------------------------------
  49718. +TAGFILES =
  49719. +GENERATE_TAGFILE =
  49720. +ALLEXTERNALS = NO
  49721. +EXTERNAL_GROUPS = YES
  49722. +PERL_PATH = /usr/bin/perl
  49723. +#---------------------------------------------------------------------------
  49724. +# Configuration options related to the dot tool
  49725. +#---------------------------------------------------------------------------
  49726. +CLASS_DIAGRAMS = YES
  49727. +HIDE_UNDOC_RELATIONS = YES
  49728. +HAVE_DOT = NO
  49729. +CLASS_GRAPH = YES
  49730. +COLLABORATION_GRAPH = YES
  49731. +UML_LOOK = NO
  49732. +TEMPLATE_RELATIONS = NO
  49733. +INCLUDE_GRAPH = YES
  49734. +INCLUDED_BY_GRAPH = YES
  49735. +CALL_GRAPH = NO
  49736. +GRAPHICAL_HIERARCHY = YES
  49737. +DOT_IMAGE_FORMAT = png
  49738. +DOT_PATH =
  49739. +DOTFILE_DIRS =
  49740. +MAX_DOT_GRAPH_DEPTH = 1000
  49741. +GENERATE_LEGEND = YES
  49742. +DOT_CLEANUP = YES
  49743. +#---------------------------------------------------------------------------
  49744. +# Configuration::additions related to the search engine
  49745. +#---------------------------------------------------------------------------
  49746. +SEARCHENGINE = NO
  49747. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dummy_audio.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dummy_audio.c
  49748. --- linux-3.10.33/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  49749. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dummy_audio.c 2014-03-13 12:46:39.512097981 +0100
  49750. @@ -0,0 +1,1575 @@
  49751. +/*
  49752. + * zero.c -- Gadget Zero, for USB development
  49753. + *
  49754. + * Copyright (C) 2003-2004 David Brownell
  49755. + * All rights reserved.
  49756. + *
  49757. + * Redistribution and use in source and binary forms, with or without
  49758. + * modification, are permitted provided that the following conditions
  49759. + * are met:
  49760. + * 1. Redistributions of source code must retain the above copyright
  49761. + * notice, this list of conditions, and the following disclaimer,
  49762. + * without modification.
  49763. + * 2. Redistributions in binary form must reproduce the above copyright
  49764. + * notice, this list of conditions and the following disclaimer in the
  49765. + * documentation and/or other materials provided with the distribution.
  49766. + * 3. The names of the above-listed copyright holders may not be used
  49767. + * to endorse or promote products derived from this software without
  49768. + * specific prior written permission.
  49769. + *
  49770. + * ALTERNATIVELY, this software may be distributed under the terms of the
  49771. + * GNU General Public License ("GPL") as published by the Free Software
  49772. + * Foundation, either version 2 of that License or (at your option) any
  49773. + * later version.
  49774. + *
  49775. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  49776. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  49777. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49778. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  49779. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  49780. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  49781. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  49782. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  49783. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  49784. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  49785. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49786. + */
  49787. +
  49788. +
  49789. +/*
  49790. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  49791. + * can write a hardware-agnostic gadget driver running inside a USB device.
  49792. + *
  49793. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  49794. + * affect most of the driver.
  49795. + *
  49796. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  49797. + * functional test of your device-side usb stack, or with "usb-skeleton".
  49798. + *
  49799. + * It supports two similar configurations. One sinks whatever the usb host
  49800. + * writes, and in return sources zeroes. The other loops whatever the host
  49801. + * writes back, so the host can read it. Module options include:
  49802. + *
  49803. + * buflen=N default N=4096, buffer size used
  49804. + * qlen=N default N=32, how many buffers in the loopback queue
  49805. + * loopdefault default false, list loopback config first
  49806. + *
  49807. + * Many drivers will only have one configuration, letting them be much
  49808. + * simpler if they also don't support high speed operation (like this
  49809. + * driver does).
  49810. + */
  49811. +
  49812. +#include <linux/config.h>
  49813. +#include <linux/module.h>
  49814. +#include <linux/kernel.h>
  49815. +#include <linux/delay.h>
  49816. +#include <linux/ioport.h>
  49817. +#include <linux/sched.h>
  49818. +#include <linux/slab.h>
  49819. +#include <linux/smp_lock.h>
  49820. +#include <linux/errno.h>
  49821. +#include <linux/init.h>
  49822. +#include <linux/timer.h>
  49823. +#include <linux/list.h>
  49824. +#include <linux/interrupt.h>
  49825. +#include <linux/uts.h>
  49826. +#include <linux/version.h>
  49827. +#include <linux/device.h>
  49828. +#include <linux/moduleparam.h>
  49829. +#include <linux/proc_fs.h>
  49830. +
  49831. +#include <asm/byteorder.h>
  49832. +#include <asm/io.h>
  49833. +#include <asm/irq.h>
  49834. +#include <asm/system.h>
  49835. +#include <asm/unaligned.h>
  49836. +
  49837. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  49838. +# include <linux/usb/ch9.h>
  49839. +#else
  49840. +# include <linux/usb_ch9.h>
  49841. +#endif
  49842. +
  49843. +#include <linux/usb_gadget.h>
  49844. +
  49845. +
  49846. +/*-------------------------------------------------------------------------*/
  49847. +/*-------------------------------------------------------------------------*/
  49848. +
  49849. +
  49850. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  49851. +{
  49852. + int count = 0;
  49853. + u8 c;
  49854. + u16 uchar;
  49855. +
  49856. + /* this insists on correct encodings, though not minimal ones.
  49857. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  49858. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  49859. + */
  49860. + while (len != 0 && (c = (u8) *s++) != 0) {
  49861. + if (unlikely(c & 0x80)) {
  49862. + // 2-byte sequence:
  49863. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  49864. + if ((c & 0xe0) == 0xc0) {
  49865. + uchar = (c & 0x1f) << 6;
  49866. +
  49867. + c = (u8) *s++;
  49868. + if ((c & 0xc0) != 0xc0)
  49869. + goto fail;
  49870. + c &= 0x3f;
  49871. + uchar |= c;
  49872. +
  49873. + // 3-byte sequence (most CJKV characters):
  49874. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  49875. + } else if ((c & 0xf0) == 0xe0) {
  49876. + uchar = (c & 0x0f) << 12;
  49877. +
  49878. + c = (u8) *s++;
  49879. + if ((c & 0xc0) != 0xc0)
  49880. + goto fail;
  49881. + c &= 0x3f;
  49882. + uchar |= c << 6;
  49883. +
  49884. + c = (u8) *s++;
  49885. + if ((c & 0xc0) != 0xc0)
  49886. + goto fail;
  49887. + c &= 0x3f;
  49888. + uchar |= c;
  49889. +
  49890. + /* no bogus surrogates */
  49891. + if (0xd800 <= uchar && uchar <= 0xdfff)
  49892. + goto fail;
  49893. +
  49894. + // 4-byte sequence (surrogate pairs, currently rare):
  49895. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  49896. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  49897. + // (uuuuu = wwww + 1)
  49898. + // FIXME accept the surrogate code points (only)
  49899. +
  49900. + } else
  49901. + goto fail;
  49902. + } else
  49903. + uchar = c;
  49904. + put_unaligned (cpu_to_le16 (uchar), cp++);
  49905. + count++;
  49906. + len--;
  49907. + }
  49908. + return count;
  49909. +fail:
  49910. + return -1;
  49911. +}
  49912. +
  49913. +
  49914. +/**
  49915. + * usb_gadget_get_string - fill out a string descriptor
  49916. + * @table: of c strings encoded using UTF-8
  49917. + * @id: string id, from low byte of wValue in get string descriptor
  49918. + * @buf: at least 256 bytes
  49919. + *
  49920. + * Finds the UTF-8 string matching the ID, and converts it into a
  49921. + * string descriptor in utf16-le.
  49922. + * Returns length of descriptor (always even) or negative errno
  49923. + *
  49924. + * If your driver needs stings in multiple languages, you'll probably
  49925. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  49926. + * using this routine after choosing which set of UTF-8 strings to use.
  49927. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  49928. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  49929. + * characters (which are also widely used in C strings).
  49930. + */
  49931. +int
  49932. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  49933. +{
  49934. + struct usb_string *s;
  49935. + int len;
  49936. +
  49937. + /* descriptor 0 has the language id */
  49938. + if (id == 0) {
  49939. + buf [0] = 4;
  49940. + buf [1] = USB_DT_STRING;
  49941. + buf [2] = (u8) table->language;
  49942. + buf [3] = (u8) (table->language >> 8);
  49943. + return 4;
  49944. + }
  49945. + for (s = table->strings; s && s->s; s++)
  49946. + if (s->id == id)
  49947. + break;
  49948. +
  49949. + /* unrecognized: stall. */
  49950. + if (!s || !s->s)
  49951. + return -EINVAL;
  49952. +
  49953. + /* string descriptors have length, tag, then UTF16-LE text */
  49954. + len = min ((size_t) 126, strlen (s->s));
  49955. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  49956. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  49957. + if (len < 0)
  49958. + return -EINVAL;
  49959. + buf [0] = (len + 1) * 2;
  49960. + buf [1] = USB_DT_STRING;
  49961. + return buf [0];
  49962. +}
  49963. +
  49964. +
  49965. +/*-------------------------------------------------------------------------*/
  49966. +/*-------------------------------------------------------------------------*/
  49967. +
  49968. +
  49969. +/**
  49970. + * usb_descriptor_fillbuf - fill buffer with descriptors
  49971. + * @buf: Buffer to be filled
  49972. + * @buflen: Size of buf
  49973. + * @src: Array of descriptor pointers, terminated by null pointer.
  49974. + *
  49975. + * Copies descriptors into the buffer, returning the length or a
  49976. + * negative error code if they can't all be copied. Useful when
  49977. + * assembling descriptors for an associated set of interfaces used
  49978. + * as part of configuring a composite device; or in other cases where
  49979. + * sets of descriptors need to be marshaled.
  49980. + */
  49981. +int
  49982. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  49983. + const struct usb_descriptor_header **src)
  49984. +{
  49985. + u8 *dest = buf;
  49986. +
  49987. + if (!src)
  49988. + return -EINVAL;
  49989. +
  49990. + /* fill buffer from src[] until null descriptor ptr */
  49991. + for (; 0 != *src; src++) {
  49992. + unsigned len = (*src)->bLength;
  49993. +
  49994. + if (len > buflen)
  49995. + return -EINVAL;
  49996. + memcpy(dest, *src, len);
  49997. + buflen -= len;
  49998. + dest += len;
  49999. + }
  50000. + return dest - (u8 *)buf;
  50001. +}
  50002. +
  50003. +
  50004. +/**
  50005. + * usb_gadget_config_buf - builts a complete configuration descriptor
  50006. + * @config: Header for the descriptor, including characteristics such
  50007. + * as power requirements and number of interfaces.
  50008. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  50009. + * endpoint, etc) defining all functions in this device configuration.
  50010. + * @buf: Buffer for the resulting configuration descriptor.
  50011. + * @length: Length of buffer. If this is not big enough to hold the
  50012. + * entire configuration descriptor, an error code will be returned.
  50013. + *
  50014. + * This copies descriptors into the response buffer, building a descriptor
  50015. + * for that configuration. It returns the buffer length or a negative
  50016. + * status code. The config.wTotalLength field is set to match the length
  50017. + * of the result, but other descriptor fields (including power usage and
  50018. + * interface count) must be set by the caller.
  50019. + *
  50020. + * Gadget drivers could use this when constructing a config descriptor
  50021. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  50022. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  50023. + */
  50024. +int usb_gadget_config_buf(
  50025. + const struct usb_config_descriptor *config,
  50026. + void *buf,
  50027. + unsigned length,
  50028. + const struct usb_descriptor_header **desc
  50029. +)
  50030. +{
  50031. + struct usb_config_descriptor *cp = buf;
  50032. + int len;
  50033. +
  50034. + /* config descriptor first */
  50035. + if (length < USB_DT_CONFIG_SIZE || !desc)
  50036. + return -EINVAL;
  50037. + *cp = *config;
  50038. +
  50039. + /* then interface/endpoint/class/vendor/... */
  50040. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  50041. + length - USB_DT_CONFIG_SIZE, desc);
  50042. + if (len < 0)
  50043. + return len;
  50044. + len += USB_DT_CONFIG_SIZE;
  50045. + if (len > 0xffff)
  50046. + return -EINVAL;
  50047. +
  50048. + /* patch up the config descriptor */
  50049. + cp->bLength = USB_DT_CONFIG_SIZE;
  50050. + cp->bDescriptorType = USB_DT_CONFIG;
  50051. + cp->wTotalLength = cpu_to_le16(len);
  50052. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  50053. + return len;
  50054. +}
  50055. +
  50056. +/*-------------------------------------------------------------------------*/
  50057. +/*-------------------------------------------------------------------------*/
  50058. +
  50059. +
  50060. +#define RBUF_LEN (1024*1024)
  50061. +static int rbuf_start;
  50062. +static int rbuf_len;
  50063. +static __u8 rbuf[RBUF_LEN];
  50064. +
  50065. +/*-------------------------------------------------------------------------*/
  50066. +
  50067. +#define DRIVER_VERSION "St Patrick's Day 2004"
  50068. +
  50069. +static const char shortname [] = "zero";
  50070. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  50071. +
  50072. +static const char source_sink [] = "source and sink data";
  50073. +static const char loopback [] = "loop input to output";
  50074. +
  50075. +/*-------------------------------------------------------------------------*/
  50076. +
  50077. +/*
  50078. + * driver assumes self-powered hardware, and
  50079. + * has no way for users to trigger remote wakeup.
  50080. + *
  50081. + * this version autoconfigures as much as possible,
  50082. + * which is reasonable for most "bulk-only" drivers.
  50083. + */
  50084. +static const char *EP_IN_NAME; /* source */
  50085. +static const char *EP_OUT_NAME; /* sink */
  50086. +
  50087. +/*-------------------------------------------------------------------------*/
  50088. +
  50089. +/* big enough to hold our biggest descriptor */
  50090. +#define USB_BUFSIZ 512
  50091. +
  50092. +struct zero_dev {
  50093. + spinlock_t lock;
  50094. + struct usb_gadget *gadget;
  50095. + struct usb_request *req; /* for control responses */
  50096. +
  50097. + /* when configured, we have one of two configs:
  50098. + * - source data (in to host) and sink it (out from host)
  50099. + * - or loop it back (out from host back in to host)
  50100. + */
  50101. + u8 config;
  50102. + struct usb_ep *in_ep, *out_ep;
  50103. +
  50104. + /* autoresume timer */
  50105. + struct timer_list resume;
  50106. +};
  50107. +
  50108. +#define xprintk(d,level,fmt,args...) \
  50109. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  50110. +
  50111. +#ifdef DEBUG
  50112. +#define DBG(dev,fmt,args...) \
  50113. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  50114. +#else
  50115. +#define DBG(dev,fmt,args...) \
  50116. + do { } while (0)
  50117. +#endif /* DEBUG */
  50118. +
  50119. +#ifdef VERBOSE
  50120. +#define VDBG DBG
  50121. +#else
  50122. +#define VDBG(dev,fmt,args...) \
  50123. + do { } while (0)
  50124. +#endif /* VERBOSE */
  50125. +
  50126. +#define ERROR(dev,fmt,args...) \
  50127. + xprintk(dev , KERN_ERR , fmt , ## args)
  50128. +#define WARN(dev,fmt,args...) \
  50129. + xprintk(dev , KERN_WARNING , fmt , ## args)
  50130. +#define INFO(dev,fmt,args...) \
  50131. + xprintk(dev , KERN_INFO , fmt , ## args)
  50132. +
  50133. +/*-------------------------------------------------------------------------*/
  50134. +
  50135. +static unsigned buflen = 4096;
  50136. +static unsigned qlen = 32;
  50137. +static unsigned pattern = 0;
  50138. +
  50139. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  50140. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  50141. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  50142. +
  50143. +/*
  50144. + * if it's nonzero, autoresume says how many seconds to wait
  50145. + * before trying to wake up the host after suspend.
  50146. + */
  50147. +static unsigned autoresume = 0;
  50148. +module_param (autoresume, uint, 0);
  50149. +
  50150. +/*
  50151. + * Normally the "loopback" configuration is second (index 1) so
  50152. + * it's not the default. Here's where to change that order, to
  50153. + * work better with hosts where config changes are problematic.
  50154. + * Or controllers (like superh) that only support one config.
  50155. + */
  50156. +static int loopdefault = 0;
  50157. +
  50158. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  50159. +
  50160. +/*-------------------------------------------------------------------------*/
  50161. +
  50162. +/* Thanks to NetChip Technologies for donating this product ID.
  50163. + *
  50164. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  50165. + * Instead: allocate your own, using normal USB-IF procedures.
  50166. + */
  50167. +#ifndef CONFIG_USB_ZERO_HNPTEST
  50168. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  50169. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  50170. +#else
  50171. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  50172. +#define DRIVER_PRODUCT_NUM 0xbadd
  50173. +#endif
  50174. +
  50175. +/*-------------------------------------------------------------------------*/
  50176. +
  50177. +/*
  50178. + * DESCRIPTORS ... most are static, but strings and (full)
  50179. + * configuration descriptors are built on demand.
  50180. + */
  50181. +
  50182. +/*
  50183. +#define STRING_MANUFACTURER 25
  50184. +#define STRING_PRODUCT 42
  50185. +#define STRING_SERIAL 101
  50186. +*/
  50187. +#define STRING_MANUFACTURER 1
  50188. +#define STRING_PRODUCT 2
  50189. +#define STRING_SERIAL 3
  50190. +
  50191. +#define STRING_SOURCE_SINK 250
  50192. +#define STRING_LOOPBACK 251
  50193. +
  50194. +/*
  50195. + * This device advertises two configurations; these numbers work
  50196. + * on a pxa250 as well as more flexible hardware.
  50197. + */
  50198. +#define CONFIG_SOURCE_SINK 3
  50199. +#define CONFIG_LOOPBACK 2
  50200. +
  50201. +/*
  50202. +static struct usb_device_descriptor
  50203. +device_desc = {
  50204. + .bLength = sizeof device_desc,
  50205. + .bDescriptorType = USB_DT_DEVICE,
  50206. +
  50207. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  50208. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  50209. +
  50210. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  50211. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  50212. + .iManufacturer = STRING_MANUFACTURER,
  50213. + .iProduct = STRING_PRODUCT,
  50214. + .iSerialNumber = STRING_SERIAL,
  50215. + .bNumConfigurations = 2,
  50216. +};
  50217. +*/
  50218. +static struct usb_device_descriptor
  50219. +device_desc = {
  50220. + .bLength = sizeof device_desc,
  50221. + .bDescriptorType = USB_DT_DEVICE,
  50222. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  50223. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  50224. + .bDeviceSubClass = 0,
  50225. + .bDeviceProtocol = 0,
  50226. + .bMaxPacketSize0 = 64,
  50227. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  50228. + .idVendor = __constant_cpu_to_le16 (0x0499),
  50229. + .idProduct = __constant_cpu_to_le16 (0x3002),
  50230. + .iManufacturer = STRING_MANUFACTURER,
  50231. + .iProduct = STRING_PRODUCT,
  50232. + .iSerialNumber = STRING_SERIAL,
  50233. + .bNumConfigurations = 1,
  50234. +};
  50235. +
  50236. +static struct usb_config_descriptor
  50237. +z_config = {
  50238. + .bLength = sizeof z_config,
  50239. + .bDescriptorType = USB_DT_CONFIG,
  50240. +
  50241. + /* compute wTotalLength on the fly */
  50242. + .bNumInterfaces = 2,
  50243. + .bConfigurationValue = 1,
  50244. + .iConfiguration = 0,
  50245. + .bmAttributes = 0x40,
  50246. + .bMaxPower = 0, /* self-powered */
  50247. +};
  50248. +
  50249. +
  50250. +static struct usb_otg_descriptor
  50251. +otg_descriptor = {
  50252. + .bLength = sizeof otg_descriptor,
  50253. + .bDescriptorType = USB_DT_OTG,
  50254. +
  50255. + .bmAttributes = USB_OTG_SRP,
  50256. +};
  50257. +
  50258. +/* one interface in each configuration */
  50259. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50260. +
  50261. +/*
  50262. + * usb 2.0 devices need to expose both high speed and full speed
  50263. + * descriptors, unless they only run at full speed.
  50264. + *
  50265. + * that means alternate endpoint descriptors (bigger packets)
  50266. + * and a "device qualifier" ... plus more construction options
  50267. + * for the config descriptor.
  50268. + */
  50269. +
  50270. +static struct usb_qualifier_descriptor
  50271. +dev_qualifier = {
  50272. + .bLength = sizeof dev_qualifier,
  50273. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  50274. +
  50275. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  50276. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  50277. +
  50278. + .bNumConfigurations = 2,
  50279. +};
  50280. +
  50281. +
  50282. +struct usb_cs_as_general_descriptor {
  50283. + __u8 bLength;
  50284. + __u8 bDescriptorType;
  50285. +
  50286. + __u8 bDescriptorSubType;
  50287. + __u8 bTerminalLink;
  50288. + __u8 bDelay;
  50289. + __u16 wFormatTag;
  50290. +} __attribute__ ((packed));
  50291. +
  50292. +struct usb_cs_as_format_descriptor {
  50293. + __u8 bLength;
  50294. + __u8 bDescriptorType;
  50295. +
  50296. + __u8 bDescriptorSubType;
  50297. + __u8 bFormatType;
  50298. + __u8 bNrChannels;
  50299. + __u8 bSubframeSize;
  50300. + __u8 bBitResolution;
  50301. + __u8 bSamfreqType;
  50302. + __u8 tLowerSamFreq[3];
  50303. + __u8 tUpperSamFreq[3];
  50304. +} __attribute__ ((packed));
  50305. +
  50306. +static const struct usb_interface_descriptor
  50307. +z_audio_control_if_desc = {
  50308. + .bLength = sizeof z_audio_control_if_desc,
  50309. + .bDescriptorType = USB_DT_INTERFACE,
  50310. + .bInterfaceNumber = 0,
  50311. + .bAlternateSetting = 0,
  50312. + .bNumEndpoints = 0,
  50313. + .bInterfaceClass = USB_CLASS_AUDIO,
  50314. + .bInterfaceSubClass = 0x1,
  50315. + .bInterfaceProtocol = 0,
  50316. + .iInterface = 0,
  50317. +};
  50318. +
  50319. +static const struct usb_interface_descriptor
  50320. +z_audio_if_desc = {
  50321. + .bLength = sizeof z_audio_if_desc,
  50322. + .bDescriptorType = USB_DT_INTERFACE,
  50323. + .bInterfaceNumber = 1,
  50324. + .bAlternateSetting = 0,
  50325. + .bNumEndpoints = 0,
  50326. + .bInterfaceClass = USB_CLASS_AUDIO,
  50327. + .bInterfaceSubClass = 0x2,
  50328. + .bInterfaceProtocol = 0,
  50329. + .iInterface = 0,
  50330. +};
  50331. +
  50332. +static const struct usb_interface_descriptor
  50333. +z_audio_if_desc2 = {
  50334. + .bLength = sizeof z_audio_if_desc,
  50335. + .bDescriptorType = USB_DT_INTERFACE,
  50336. + .bInterfaceNumber = 1,
  50337. + .bAlternateSetting = 1,
  50338. + .bNumEndpoints = 1,
  50339. + .bInterfaceClass = USB_CLASS_AUDIO,
  50340. + .bInterfaceSubClass = 0x2,
  50341. + .bInterfaceProtocol = 0,
  50342. + .iInterface = 0,
  50343. +};
  50344. +
  50345. +static const struct usb_cs_as_general_descriptor
  50346. +z_audio_cs_as_if_desc = {
  50347. + .bLength = 7,
  50348. + .bDescriptorType = 0x24,
  50349. +
  50350. + .bDescriptorSubType = 0x01,
  50351. + .bTerminalLink = 0x01,
  50352. + .bDelay = 0x0,
  50353. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  50354. +};
  50355. +
  50356. +
  50357. +static const struct usb_cs_as_format_descriptor
  50358. +z_audio_cs_as_format_desc = {
  50359. + .bLength = 0xe,
  50360. + .bDescriptorType = 0x24,
  50361. +
  50362. + .bDescriptorSubType = 2,
  50363. + .bFormatType = 1,
  50364. + .bNrChannels = 1,
  50365. + .bSubframeSize = 1,
  50366. + .bBitResolution = 8,
  50367. + .bSamfreqType = 0,
  50368. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  50369. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  50370. +};
  50371. +
  50372. +static const struct usb_endpoint_descriptor
  50373. +z_iso_ep = {
  50374. + .bLength = 0x09,
  50375. + .bDescriptorType = 0x05,
  50376. + .bEndpointAddress = 0x04,
  50377. + .bmAttributes = 0x09,
  50378. + .wMaxPacketSize = 0x0038,
  50379. + .bInterval = 0x01,
  50380. + .bRefresh = 0x00,
  50381. + .bSynchAddress = 0x00,
  50382. +};
  50383. +
  50384. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50385. +
  50386. +// 9 bytes
  50387. +static char z_ac_interface_header_desc[] =
  50388. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  50389. +
  50390. +// 12 bytes
  50391. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  50392. + 0x03, 0x00, 0x00, 0x00};
  50393. +// 13 bytes
  50394. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  50395. + 0x02, 0x00, 0x02, 0x00, 0x00};
  50396. +// 9 bytes
  50397. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  50398. + 0x00};
  50399. +
  50400. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  50401. + 0x00};
  50402. +
  50403. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50404. +
  50405. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  50406. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50407. +
  50408. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  50409. + 0x00};
  50410. +
  50411. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50412. +
  50413. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  50414. + 0x00};
  50415. +
  50416. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50417. +
  50418. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  50419. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50420. +
  50421. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  50422. + 0x00};
  50423. +
  50424. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50425. +
  50426. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  50427. + 0x00};
  50428. +
  50429. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50430. +
  50431. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  50432. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50433. +
  50434. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  50435. + 0x00};
  50436. +
  50437. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50438. +
  50439. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  50440. + 0x00};
  50441. +
  50442. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50443. +
  50444. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  50445. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50446. +
  50447. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  50448. + 0x00};
  50449. +
  50450. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50451. +
  50452. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  50453. + 0x00};
  50454. +
  50455. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50456. +
  50457. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  50458. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50459. +
  50460. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  50461. + 0x00};
  50462. +
  50463. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50464. +
  50465. +
  50466. +
  50467. +static const struct usb_descriptor_header *z_function [] = {
  50468. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  50469. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  50470. + (struct usb_descriptor_header *) &z_0,
  50471. + (struct usb_descriptor_header *) &z_1,
  50472. + (struct usb_descriptor_header *) &z_2,
  50473. + (struct usb_descriptor_header *) &z_audio_if_desc,
  50474. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  50475. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  50476. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  50477. + (struct usb_descriptor_header *) &z_iso_ep,
  50478. + (struct usb_descriptor_header *) &z_iso_ep2,
  50479. + (struct usb_descriptor_header *) &za_0,
  50480. + (struct usb_descriptor_header *) &za_1,
  50481. + (struct usb_descriptor_header *) &za_2,
  50482. + (struct usb_descriptor_header *) &za_3,
  50483. + (struct usb_descriptor_header *) &za_4,
  50484. + (struct usb_descriptor_header *) &za_5,
  50485. + (struct usb_descriptor_header *) &za_6,
  50486. + (struct usb_descriptor_header *) &za_7,
  50487. + (struct usb_descriptor_header *) &za_8,
  50488. + (struct usb_descriptor_header *) &za_9,
  50489. + (struct usb_descriptor_header *) &za_10,
  50490. + (struct usb_descriptor_header *) &za_11,
  50491. + (struct usb_descriptor_header *) &za_12,
  50492. + (struct usb_descriptor_header *) &za_13,
  50493. + (struct usb_descriptor_header *) &za_14,
  50494. + (struct usb_descriptor_header *) &za_15,
  50495. + (struct usb_descriptor_header *) &za_16,
  50496. + (struct usb_descriptor_header *) &za_17,
  50497. + (struct usb_descriptor_header *) &za_18,
  50498. + (struct usb_descriptor_header *) &za_19,
  50499. + (struct usb_descriptor_header *) &za_20,
  50500. + (struct usb_descriptor_header *) &za_21,
  50501. + (struct usb_descriptor_header *) &za_22,
  50502. + (struct usb_descriptor_header *) &za_23,
  50503. + (struct usb_descriptor_header *) &za_24,
  50504. + NULL,
  50505. +};
  50506. +
  50507. +/* maxpacket and other transfer characteristics vary by speed. */
  50508. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  50509. +
  50510. +#else
  50511. +
  50512. +/* if there's no high speed support, maxpacket doesn't change. */
  50513. +#define ep_desc(g,hs,fs) fs
  50514. +
  50515. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  50516. +
  50517. +static char manufacturer [40];
  50518. +//static char serial [40];
  50519. +static char serial [] = "Ser 00 em";
  50520. +
  50521. +/* static strings, in UTF-8 */
  50522. +static struct usb_string strings [] = {
  50523. + { STRING_MANUFACTURER, manufacturer, },
  50524. + { STRING_PRODUCT, longname, },
  50525. + { STRING_SERIAL, serial, },
  50526. + { STRING_LOOPBACK, loopback, },
  50527. + { STRING_SOURCE_SINK, source_sink, },
  50528. + { } /* end of list */
  50529. +};
  50530. +
  50531. +static struct usb_gadget_strings stringtab = {
  50532. + .language = 0x0409, /* en-us */
  50533. + .strings = strings,
  50534. +};
  50535. +
  50536. +/*
  50537. + * config descriptors are also handcrafted. these must agree with code
  50538. + * that sets configurations, and with code managing interfaces and their
  50539. + * altsettings. other complexity may come from:
  50540. + *
  50541. + * - high speed support, including "other speed config" rules
  50542. + * - multiple configurations
  50543. + * - interfaces with alternate settings
  50544. + * - embedded class or vendor-specific descriptors
  50545. + *
  50546. + * this handles high speed, and has a second config that could as easily
  50547. + * have been an alternate interface setting (on most hardware).
  50548. + *
  50549. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  50550. + * should include an altsetting to test interrupt transfers, including
  50551. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  50552. + * device?)
  50553. + */
  50554. +static int
  50555. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  50556. +{
  50557. + int len;
  50558. + const struct usb_descriptor_header **function;
  50559. +
  50560. + function = z_function;
  50561. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  50562. + if (len < 0)
  50563. + return len;
  50564. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  50565. + return len;
  50566. +}
  50567. +
  50568. +/*-------------------------------------------------------------------------*/
  50569. +
  50570. +static struct usb_request *
  50571. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  50572. +{
  50573. + struct usb_request *req;
  50574. +
  50575. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  50576. + if (req) {
  50577. + req->length = length;
  50578. + req->buf = usb_ep_alloc_buffer (ep, length,
  50579. + &req->dma, GFP_ATOMIC);
  50580. + if (!req->buf) {
  50581. + usb_ep_free_request (ep, req);
  50582. + req = NULL;
  50583. + }
  50584. + }
  50585. + return req;
  50586. +}
  50587. +
  50588. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  50589. +{
  50590. + if (req->buf)
  50591. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  50592. + usb_ep_free_request (ep, req);
  50593. +}
  50594. +
  50595. +/*-------------------------------------------------------------------------*/
  50596. +
  50597. +/* optionally require specific source/sink data patterns */
  50598. +
  50599. +static int
  50600. +check_read_data (
  50601. + struct zero_dev *dev,
  50602. + struct usb_ep *ep,
  50603. + struct usb_request *req
  50604. +)
  50605. +{
  50606. + unsigned i;
  50607. + u8 *buf = req->buf;
  50608. +
  50609. + for (i = 0; i < req->actual; i++, buf++) {
  50610. + switch (pattern) {
  50611. + /* all-zeroes has no synchronization issues */
  50612. + case 0:
  50613. + if (*buf == 0)
  50614. + continue;
  50615. + break;
  50616. + /* mod63 stays in sync with short-terminated transfers,
  50617. + * or otherwise when host and gadget agree on how large
  50618. + * each usb transfer request should be. resync is done
  50619. + * with set_interface or set_config.
  50620. + */
  50621. + case 1:
  50622. + if (*buf == (u8)(i % 63))
  50623. + continue;
  50624. + break;
  50625. + }
  50626. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  50627. + usb_ep_set_halt (ep);
  50628. + return -EINVAL;
  50629. + }
  50630. + return 0;
  50631. +}
  50632. +
  50633. +/*-------------------------------------------------------------------------*/
  50634. +
  50635. +static void zero_reset_config (struct zero_dev *dev)
  50636. +{
  50637. + if (dev->config == 0)
  50638. + return;
  50639. +
  50640. + DBG (dev, "reset config\n");
  50641. +
  50642. + /* just disable endpoints, forcing completion of pending i/o.
  50643. + * all our completion handlers free their requests in this case.
  50644. + */
  50645. + if (dev->in_ep) {
  50646. + usb_ep_disable (dev->in_ep);
  50647. + dev->in_ep = NULL;
  50648. + }
  50649. + if (dev->out_ep) {
  50650. + usb_ep_disable (dev->out_ep);
  50651. + dev->out_ep = NULL;
  50652. + }
  50653. + dev->config = 0;
  50654. + del_timer (&dev->resume);
  50655. +}
  50656. +
  50657. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  50658. +
  50659. +static void
  50660. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  50661. +{
  50662. + struct zero_dev *dev = ep->driver_data;
  50663. + int status = req->status;
  50664. + int i, j;
  50665. +
  50666. + switch (status) {
  50667. +
  50668. + case 0: /* normal completion? */
  50669. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  50670. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  50671. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  50672. + rbuf[j] = ((__u8*)req->buf)[i];
  50673. + j++;
  50674. + if (j >= RBUF_LEN) j=0;
  50675. + }
  50676. + rbuf_start = j;
  50677. + //printk ("\n\n");
  50678. +
  50679. + if (rbuf_len < RBUF_LEN) {
  50680. + rbuf_len += req->actual;
  50681. + if (rbuf_len > RBUF_LEN) {
  50682. + rbuf_len = RBUF_LEN;
  50683. + }
  50684. + }
  50685. +
  50686. + break;
  50687. +
  50688. + /* this endpoint is normally active while we're configured */
  50689. + case -ECONNABORTED: /* hardware forced ep reset */
  50690. + case -ECONNRESET: /* request dequeued */
  50691. + case -ESHUTDOWN: /* disconnect from host */
  50692. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  50693. + req->actual, req->length);
  50694. + if (ep == dev->out_ep)
  50695. + check_read_data (dev, ep, req);
  50696. + free_ep_req (ep, req);
  50697. + return;
  50698. +
  50699. + case -EOVERFLOW: /* buffer overrun on read means that
  50700. + * we didn't provide a big enough
  50701. + * buffer.
  50702. + */
  50703. + default:
  50704. +#if 1
  50705. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  50706. + status, req->actual, req->length);
  50707. +#endif
  50708. + case -EREMOTEIO: /* short read */
  50709. + break;
  50710. + }
  50711. +
  50712. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  50713. + if (status) {
  50714. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  50715. + ep->name, req->length, status);
  50716. + usb_ep_set_halt (ep);
  50717. + /* FIXME recover later ... somehow */
  50718. + }
  50719. +}
  50720. +
  50721. +static struct usb_request *
  50722. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  50723. +{
  50724. + struct usb_request *req;
  50725. + int status;
  50726. +
  50727. + req = alloc_ep_req (ep, 512);
  50728. + if (!req)
  50729. + return NULL;
  50730. +
  50731. + req->complete = zero_isoc_complete;
  50732. +
  50733. + status = usb_ep_queue (ep, req, gfp_flags);
  50734. + if (status) {
  50735. + struct zero_dev *dev = ep->driver_data;
  50736. +
  50737. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  50738. + free_ep_req (ep, req);
  50739. + req = NULL;
  50740. + }
  50741. +
  50742. + return req;
  50743. +}
  50744. +
  50745. +/* change our operational config. this code must agree with the code
  50746. + * that returns config descriptors, and altsetting code.
  50747. + *
  50748. + * it's also responsible for power management interactions. some
  50749. + * configurations might not work with our current power sources.
  50750. + *
  50751. + * note that some device controller hardware will constrain what this
  50752. + * code can do, perhaps by disallowing more than one configuration or
  50753. + * by limiting configuration choices (like the pxa2xx).
  50754. + */
  50755. +static int
  50756. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  50757. +{
  50758. + int result = 0;
  50759. + struct usb_gadget *gadget = dev->gadget;
  50760. + const struct usb_endpoint_descriptor *d;
  50761. + struct usb_ep *ep;
  50762. +
  50763. + if (number == dev->config)
  50764. + return 0;
  50765. +
  50766. + zero_reset_config (dev);
  50767. +
  50768. + gadget_for_each_ep (ep, gadget) {
  50769. +
  50770. + if (strcmp (ep->name, "ep4") == 0) {
  50771. +
  50772. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  50773. + result = usb_ep_enable (ep, d);
  50774. +
  50775. + if (result == 0) {
  50776. + ep->driver_data = dev;
  50777. + dev->in_ep = ep;
  50778. +
  50779. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  50780. +
  50781. + dev->in_ep = ep;
  50782. + continue;
  50783. + }
  50784. +
  50785. + usb_ep_disable (ep);
  50786. + result = -EIO;
  50787. + }
  50788. + }
  50789. +
  50790. + }
  50791. +
  50792. + dev->config = number;
  50793. + return result;
  50794. +}
  50795. +
  50796. +/*-------------------------------------------------------------------------*/
  50797. +
  50798. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  50799. +{
  50800. + if (req->status || req->actual != req->length)
  50801. + DBG ((struct zero_dev *) ep->driver_data,
  50802. + "setup complete --> %d, %d/%d\n",
  50803. + req->status, req->actual, req->length);
  50804. +}
  50805. +
  50806. +/*
  50807. + * The setup() callback implements all the ep0 functionality that's
  50808. + * not handled lower down, in hardware or the hardware driver (like
  50809. + * device and endpoint feature flags, and their status). It's all
  50810. + * housekeeping for the gadget function we're implementing. Most of
  50811. + * the work is in config-specific setup.
  50812. + */
  50813. +static int
  50814. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  50815. +{
  50816. + struct zero_dev *dev = get_gadget_data (gadget);
  50817. + struct usb_request *req = dev->req;
  50818. + int value = -EOPNOTSUPP;
  50819. +
  50820. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  50821. + * but config change events will reconfigure hardware.
  50822. + */
  50823. + req->zero = 0;
  50824. + switch (ctrl->bRequest) {
  50825. +
  50826. + case USB_REQ_GET_DESCRIPTOR:
  50827. +
  50828. + switch (ctrl->wValue >> 8) {
  50829. +
  50830. + case USB_DT_DEVICE:
  50831. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  50832. + memcpy (req->buf, &device_desc, value);
  50833. + break;
  50834. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50835. + case USB_DT_DEVICE_QUALIFIER:
  50836. + if (!gadget->is_dualspeed)
  50837. + break;
  50838. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  50839. + memcpy (req->buf, &dev_qualifier, value);
  50840. + break;
  50841. +
  50842. + case USB_DT_OTHER_SPEED_CONFIG:
  50843. + if (!gadget->is_dualspeed)
  50844. + break;
  50845. + // FALLTHROUGH
  50846. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  50847. + case USB_DT_CONFIG:
  50848. + value = config_buf (gadget, req->buf,
  50849. + ctrl->wValue >> 8,
  50850. + ctrl->wValue & 0xff);
  50851. + if (value >= 0)
  50852. + value = min (ctrl->wLength, (u16) value);
  50853. + break;
  50854. +
  50855. + case USB_DT_STRING:
  50856. + /* wIndex == language code.
  50857. + * this driver only handles one language, you can
  50858. + * add string tables for other languages, using
  50859. + * any UTF-8 characters
  50860. + */
  50861. + value = usb_gadget_get_string (&stringtab,
  50862. + ctrl->wValue & 0xff, req->buf);
  50863. + if (value >= 0) {
  50864. + value = min (ctrl->wLength, (u16) value);
  50865. + }
  50866. + break;
  50867. + }
  50868. + break;
  50869. +
  50870. + /* currently two configs, two speeds */
  50871. + case USB_REQ_SET_CONFIGURATION:
  50872. + if (ctrl->bRequestType != 0)
  50873. + goto unknown;
  50874. +
  50875. + spin_lock (&dev->lock);
  50876. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  50877. + spin_unlock (&dev->lock);
  50878. + break;
  50879. + case USB_REQ_GET_CONFIGURATION:
  50880. + if (ctrl->bRequestType != USB_DIR_IN)
  50881. + goto unknown;
  50882. + *(u8 *)req->buf = dev->config;
  50883. + value = min (ctrl->wLength, (u16) 1);
  50884. + break;
  50885. +
  50886. + /* until we add altsetting support, or other interfaces,
  50887. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  50888. + * and already killed pending endpoint I/O.
  50889. + */
  50890. + case USB_REQ_SET_INTERFACE:
  50891. +
  50892. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  50893. + goto unknown;
  50894. + spin_lock (&dev->lock);
  50895. + if (dev->config) {
  50896. + u8 config = dev->config;
  50897. +
  50898. + /* resets interface configuration, forgets about
  50899. + * previous transaction state (queued bufs, etc)
  50900. + * and re-inits endpoint state (toggle etc)
  50901. + * no response queued, just zero status == success.
  50902. + * if we had more than one interface we couldn't
  50903. + * use this "reset the config" shortcut.
  50904. + */
  50905. + zero_reset_config (dev);
  50906. + zero_set_config (dev, config, GFP_ATOMIC);
  50907. + value = 0;
  50908. + }
  50909. + spin_unlock (&dev->lock);
  50910. + break;
  50911. + case USB_REQ_GET_INTERFACE:
  50912. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  50913. + value = ctrl->wLength;
  50914. + break;
  50915. + }
  50916. + else {
  50917. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  50918. + goto unknown;
  50919. + if (!dev->config)
  50920. + break;
  50921. + if (ctrl->wIndex != 0) {
  50922. + value = -EDOM;
  50923. + break;
  50924. + }
  50925. + *(u8 *)req->buf = 0;
  50926. + value = min (ctrl->wLength, (u16) 1);
  50927. + }
  50928. + break;
  50929. +
  50930. + /*
  50931. + * These are the same vendor-specific requests supported by
  50932. + * Intel's USB 2.0 compliance test devices. We exceed that
  50933. + * device spec by allowing multiple-packet requests.
  50934. + */
  50935. + case 0x5b: /* control WRITE test -- fill the buffer */
  50936. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  50937. + goto unknown;
  50938. + if (ctrl->wValue || ctrl->wIndex)
  50939. + break;
  50940. + /* just read that many bytes into the buffer */
  50941. + if (ctrl->wLength > USB_BUFSIZ)
  50942. + break;
  50943. + value = ctrl->wLength;
  50944. + break;
  50945. + case 0x5c: /* control READ test -- return the buffer */
  50946. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  50947. + goto unknown;
  50948. + if (ctrl->wValue || ctrl->wIndex)
  50949. + break;
  50950. + /* expect those bytes are still in the buffer; send back */
  50951. + if (ctrl->wLength > USB_BUFSIZ
  50952. + || ctrl->wLength != req->length)
  50953. + break;
  50954. + value = ctrl->wLength;
  50955. + break;
  50956. +
  50957. + case 0x01: // SET_CUR
  50958. + case 0x02:
  50959. + case 0x03:
  50960. + case 0x04:
  50961. + case 0x05:
  50962. + value = ctrl->wLength;
  50963. + break;
  50964. + case 0x81:
  50965. + switch (ctrl->wValue) {
  50966. + case 0x0201:
  50967. + case 0x0202:
  50968. + ((u8*)req->buf)[0] = 0x00;
  50969. + ((u8*)req->buf)[1] = 0xe3;
  50970. + break;
  50971. + case 0x0300:
  50972. + case 0x0500:
  50973. + ((u8*)req->buf)[0] = 0x00;
  50974. + break;
  50975. + }
  50976. + //((u8*)req->buf)[0] = 0x81;
  50977. + //((u8*)req->buf)[1] = 0x81;
  50978. + value = ctrl->wLength;
  50979. + break;
  50980. + case 0x82:
  50981. + switch (ctrl->wValue) {
  50982. + case 0x0201:
  50983. + case 0x0202:
  50984. + ((u8*)req->buf)[0] = 0x00;
  50985. + ((u8*)req->buf)[1] = 0xc3;
  50986. + break;
  50987. + case 0x0300:
  50988. + case 0x0500:
  50989. + ((u8*)req->buf)[0] = 0x00;
  50990. + break;
  50991. + }
  50992. + //((u8*)req->buf)[0] = 0x82;
  50993. + //((u8*)req->buf)[1] = 0x82;
  50994. + value = ctrl->wLength;
  50995. + break;
  50996. + case 0x83:
  50997. + switch (ctrl->wValue) {
  50998. + case 0x0201:
  50999. + case 0x0202:
  51000. + ((u8*)req->buf)[0] = 0x00;
  51001. + ((u8*)req->buf)[1] = 0x00;
  51002. + break;
  51003. + case 0x0300:
  51004. + ((u8*)req->buf)[0] = 0x60;
  51005. + break;
  51006. + case 0x0500:
  51007. + ((u8*)req->buf)[0] = 0x18;
  51008. + break;
  51009. + }
  51010. + //((u8*)req->buf)[0] = 0x83;
  51011. + //((u8*)req->buf)[1] = 0x83;
  51012. + value = ctrl->wLength;
  51013. + break;
  51014. + case 0x84:
  51015. + switch (ctrl->wValue) {
  51016. + case 0x0201:
  51017. + case 0x0202:
  51018. + ((u8*)req->buf)[0] = 0x00;
  51019. + ((u8*)req->buf)[1] = 0x01;
  51020. + break;
  51021. + case 0x0300:
  51022. + case 0x0500:
  51023. + ((u8*)req->buf)[0] = 0x08;
  51024. + break;
  51025. + }
  51026. + //((u8*)req->buf)[0] = 0x84;
  51027. + //((u8*)req->buf)[1] = 0x84;
  51028. + value = ctrl->wLength;
  51029. + break;
  51030. + case 0x85:
  51031. + ((u8*)req->buf)[0] = 0x85;
  51032. + ((u8*)req->buf)[1] = 0x85;
  51033. + value = ctrl->wLength;
  51034. + break;
  51035. +
  51036. +
  51037. + default:
  51038. +unknown:
  51039. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  51040. + ctrl->bRequestType, ctrl->bRequest,
  51041. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  51042. + }
  51043. +
  51044. + /* respond with data transfer before status phase? */
  51045. + if (value >= 0) {
  51046. + req->length = value;
  51047. + req->zero = value < ctrl->wLength
  51048. + && (value % gadget->ep0->maxpacket) == 0;
  51049. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  51050. + if (value < 0) {
  51051. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  51052. + req->status = 0;
  51053. + zero_setup_complete (gadget->ep0, req);
  51054. + }
  51055. + }
  51056. +
  51057. + /* device either stalls (value < 0) or reports success */
  51058. + return value;
  51059. +}
  51060. +
  51061. +static void
  51062. +zero_disconnect (struct usb_gadget *gadget)
  51063. +{
  51064. + struct zero_dev *dev = get_gadget_data (gadget);
  51065. + unsigned long flags;
  51066. +
  51067. + spin_lock_irqsave (&dev->lock, flags);
  51068. + zero_reset_config (dev);
  51069. +
  51070. + /* a more significant application might have some non-usb
  51071. + * activities to quiesce here, saving resources like power
  51072. + * or pushing the notification up a network stack.
  51073. + */
  51074. + spin_unlock_irqrestore (&dev->lock, flags);
  51075. +
  51076. + /* next we may get setup() calls to enumerate new connections;
  51077. + * or an unbind() during shutdown (including removing module).
  51078. + */
  51079. +}
  51080. +
  51081. +static void
  51082. +zero_autoresume (unsigned long _dev)
  51083. +{
  51084. + struct zero_dev *dev = (struct zero_dev *) _dev;
  51085. + int status;
  51086. +
  51087. + /* normally the host would be woken up for something
  51088. + * more significant than just a timer firing...
  51089. + */
  51090. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  51091. + status = usb_gadget_wakeup (dev->gadget);
  51092. + DBG (dev, "wakeup --> %d\n", status);
  51093. + }
  51094. +}
  51095. +
  51096. +/*-------------------------------------------------------------------------*/
  51097. +
  51098. +static void
  51099. +zero_unbind (struct usb_gadget *gadget)
  51100. +{
  51101. + struct zero_dev *dev = get_gadget_data (gadget);
  51102. +
  51103. + DBG (dev, "unbind\n");
  51104. +
  51105. + /* we've already been disconnected ... no i/o is active */
  51106. + if (dev->req)
  51107. + free_ep_req (gadget->ep0, dev->req);
  51108. + del_timer_sync (&dev->resume);
  51109. + kfree (dev);
  51110. + set_gadget_data (gadget, NULL);
  51111. +}
  51112. +
  51113. +static int
  51114. +zero_bind (struct usb_gadget *gadget)
  51115. +{
  51116. + struct zero_dev *dev;
  51117. + //struct usb_ep *ep;
  51118. +
  51119. + printk("binding\n");
  51120. + /*
  51121. + * DRIVER POLICY CHOICE: you may want to do this differently.
  51122. + * One thing to avoid is reusing a bcdDevice revision code
  51123. + * with different host-visible configurations or behavior
  51124. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  51125. + */
  51126. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  51127. +
  51128. +
  51129. + /* ok, we made sense of the hardware ... */
  51130. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  51131. + if (!dev)
  51132. + return -ENOMEM;
  51133. + memset (dev, 0, sizeof *dev);
  51134. + spin_lock_init (&dev->lock);
  51135. + dev->gadget = gadget;
  51136. + set_gadget_data (gadget, dev);
  51137. +
  51138. + /* preallocate control response and buffer */
  51139. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  51140. + if (!dev->req)
  51141. + goto enomem;
  51142. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  51143. + &dev->req->dma, GFP_KERNEL);
  51144. + if (!dev->req->buf)
  51145. + goto enomem;
  51146. +
  51147. + dev->req->complete = zero_setup_complete;
  51148. +
  51149. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  51150. +
  51151. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51152. + /* assume ep0 uses the same value for both speeds ... */
  51153. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  51154. +
  51155. + /* and that all endpoints are dual-speed */
  51156. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  51157. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  51158. +#endif
  51159. +
  51160. + usb_gadget_set_selfpowered (gadget);
  51161. +
  51162. + init_timer (&dev->resume);
  51163. + dev->resume.function = zero_autoresume;
  51164. + dev->resume.data = (unsigned long) dev;
  51165. +
  51166. + gadget->ep0->driver_data = dev;
  51167. +
  51168. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  51169. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  51170. + EP_OUT_NAME, EP_IN_NAME);
  51171. +
  51172. + snprintf (manufacturer, sizeof manufacturer,
  51173. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  51174. + gadget->name);
  51175. +
  51176. + return 0;
  51177. +
  51178. +enomem:
  51179. + zero_unbind (gadget);
  51180. + return -ENOMEM;
  51181. +}
  51182. +
  51183. +/*-------------------------------------------------------------------------*/
  51184. +
  51185. +static void
  51186. +zero_suspend (struct usb_gadget *gadget)
  51187. +{
  51188. + struct zero_dev *dev = get_gadget_data (gadget);
  51189. +
  51190. + if (gadget->speed == USB_SPEED_UNKNOWN)
  51191. + return;
  51192. +
  51193. + if (autoresume) {
  51194. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  51195. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  51196. + } else
  51197. + DBG (dev, "suspend\n");
  51198. +}
  51199. +
  51200. +static void
  51201. +zero_resume (struct usb_gadget *gadget)
  51202. +{
  51203. + struct zero_dev *dev = get_gadget_data (gadget);
  51204. +
  51205. + DBG (dev, "resume\n");
  51206. + del_timer (&dev->resume);
  51207. +}
  51208. +
  51209. +
  51210. +/*-------------------------------------------------------------------------*/
  51211. +
  51212. +static struct usb_gadget_driver zero_driver = {
  51213. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51214. + .speed = USB_SPEED_HIGH,
  51215. +#else
  51216. + .speed = USB_SPEED_FULL,
  51217. +#endif
  51218. + .function = (char *) longname,
  51219. + .bind = zero_bind,
  51220. + .unbind = zero_unbind,
  51221. +
  51222. + .setup = zero_setup,
  51223. + .disconnect = zero_disconnect,
  51224. +
  51225. + .suspend = zero_suspend,
  51226. + .resume = zero_resume,
  51227. +
  51228. + .driver = {
  51229. + .name = (char *) shortname,
  51230. + // .shutdown = ...
  51231. + // .suspend = ...
  51232. + // .resume = ...
  51233. + },
  51234. +};
  51235. +
  51236. +MODULE_AUTHOR ("David Brownell");
  51237. +MODULE_LICENSE ("Dual BSD/GPL");
  51238. +
  51239. +static struct proc_dir_entry *pdir, *pfile;
  51240. +
  51241. +static int isoc_read_data (char *page, char **start,
  51242. + off_t off, int count,
  51243. + int *eof, void *data)
  51244. +{
  51245. + int i;
  51246. + static int c = 0;
  51247. + static int done = 0;
  51248. + static int s = 0;
  51249. +
  51250. +/*
  51251. + printk ("\ncount: %d\n", count);
  51252. + printk ("rbuf_start: %d\n", rbuf_start);
  51253. + printk ("rbuf_len: %d\n", rbuf_len);
  51254. + printk ("off: %d\n", off);
  51255. + printk ("start: %p\n\n", *start);
  51256. +*/
  51257. + if (done) {
  51258. + c = 0;
  51259. + done = 0;
  51260. + *eof = 1;
  51261. + return 0;
  51262. + }
  51263. +
  51264. + if (c == 0) {
  51265. + if (rbuf_len == RBUF_LEN)
  51266. + s = rbuf_start;
  51267. + else s = 0;
  51268. + }
  51269. +
  51270. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  51271. + page[i] = rbuf[(c+s) % RBUF_LEN];
  51272. + }
  51273. + *start = page;
  51274. +
  51275. + if (c >= rbuf_len) {
  51276. + *eof = 1;
  51277. + done = 1;
  51278. + }
  51279. +
  51280. +
  51281. + return i;
  51282. +}
  51283. +
  51284. +static int __init init (void)
  51285. +{
  51286. +
  51287. + int retval = 0;
  51288. +
  51289. + pdir = proc_mkdir("isoc_test", NULL);
  51290. + if(pdir == NULL) {
  51291. + retval = -ENOMEM;
  51292. + printk("Error creating dir\n");
  51293. + goto done;
  51294. + }
  51295. + pdir->owner = THIS_MODULE;
  51296. +
  51297. + pfile = create_proc_read_entry("isoc_data",
  51298. + 0444, pdir,
  51299. + isoc_read_data,
  51300. + NULL);
  51301. + if (pfile == NULL) {
  51302. + retval = -ENOMEM;
  51303. + printk("Error creating file\n");
  51304. + goto no_file;
  51305. + }
  51306. + pfile->owner = THIS_MODULE;
  51307. +
  51308. + return usb_gadget_register_driver (&zero_driver);
  51309. +
  51310. + no_file:
  51311. + remove_proc_entry("isoc_data", NULL);
  51312. + done:
  51313. + return retval;
  51314. +}
  51315. +module_init (init);
  51316. +
  51317. +static void __exit cleanup (void)
  51318. +{
  51319. +
  51320. + usb_gadget_unregister_driver (&zero_driver);
  51321. +
  51322. + remove_proc_entry("isoc_data", pdir);
  51323. + remove_proc_entry("isoc_test", NULL);
  51324. +}
  51325. +module_exit (cleanup);
  51326. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  51327. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  51328. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-03-13 12:46:39.512097981 +0100
  51329. @@ -0,0 +1,142 @@
  51330. +/* ==========================================================================
  51331. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51332. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51333. + * otherwise expressly agreed to in writing between Synopsys and you.
  51334. + *
  51335. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51336. + * any End User Software License Agreement or Agreement for Licensed Product
  51337. + * with Synopsys or any supplement thereto. You are permitted to use and
  51338. + * redistribute this Software in source and binary forms, with or without
  51339. + * modification, provided that redistributions of source code must retain this
  51340. + * notice. You may not view, use, disclose, copy or distribute this file or
  51341. + * any information contained herein except pursuant to this license grant from
  51342. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51343. + * below, then you are not authorized to use the Software.
  51344. + *
  51345. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51346. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51347. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51348. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51349. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51350. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51351. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51352. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51353. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51354. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51355. + * DAMAGE.
  51356. + * ========================================================================== */
  51357. +
  51358. +#if !defined(__DWC_CFI_COMMON_H__)
  51359. +#define __DWC_CFI_COMMON_H__
  51360. +
  51361. +//#include <linux/types.h>
  51362. +
  51363. +/**
  51364. + * @file
  51365. + *
  51366. + * This file contains the CFI specific common constants, interfaces
  51367. + * (functions and macros) and structures for Linux. No PCD specific
  51368. + * data structure or definition is to be included in this file.
  51369. + *
  51370. + */
  51371. +
  51372. +/** This is a request for all Core Features */
  51373. +#define VEN_CORE_GET_FEATURES 0xB1
  51374. +
  51375. +/** This is a request to get the value of a specific Core Feature */
  51376. +#define VEN_CORE_GET_FEATURE 0xB2
  51377. +
  51378. +/** This command allows the host to set the value of a specific Core Feature */
  51379. +#define VEN_CORE_SET_FEATURE 0xB3
  51380. +
  51381. +/** This command allows the host to set the default values of
  51382. + * either all or any specific Core Feature
  51383. + */
  51384. +#define VEN_CORE_RESET_FEATURES 0xB4
  51385. +
  51386. +/** This command forces the PCD to write the deferred values of a Core Features */
  51387. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  51388. +
  51389. +/** This request reads a DWORD value from a register at the specified offset */
  51390. +#define VEN_CORE_READ_REGISTER 0xB6
  51391. +
  51392. +/** This request writes a DWORD value into a register at the specified offset */
  51393. +#define VEN_CORE_WRITE_REGISTER 0xB7
  51394. +
  51395. +/** This structure is the header of the Core Features dataset returned to
  51396. + * the Host
  51397. + */
  51398. +struct cfi_all_features_header {
  51399. +/** The features header structure length is */
  51400. +#define CFI_ALL_FEATURES_HDR_LEN 8
  51401. + /**
  51402. + * The total length of the features dataset returned to the Host
  51403. + */
  51404. + uint16_t wTotalLen;
  51405. +
  51406. + /**
  51407. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  51408. + * This field identifies the version of the CFI Specification with which
  51409. + * the device is compliant.
  51410. + */
  51411. + uint16_t wVersion;
  51412. +
  51413. + /** The ID of the Core */
  51414. + uint16_t wCoreID;
  51415. +#define CFI_CORE_ID_UDC 1
  51416. +#define CFI_CORE_ID_OTG 2
  51417. +#define CFI_CORE_ID_WUDEV 3
  51418. +
  51419. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  51420. + uint16_t wNumFeatures;
  51421. +} UPACKED;
  51422. +
  51423. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  51424. +
  51425. +/** This structure is a header of the Core Feature descriptor dataset returned to
  51426. + * the Host after the VEN_CORE_GET_FEATURES request
  51427. + */
  51428. +struct cfi_feature_desc_header {
  51429. +#define CFI_FEATURE_DESC_HDR_LEN 8
  51430. +
  51431. + /** The feature ID */
  51432. + uint16_t wFeatureID;
  51433. +
  51434. + /** Length of this feature descriptor in bytes - including the
  51435. + * length of the feature name string
  51436. + */
  51437. + uint16_t wLength;
  51438. +
  51439. + /** The data length of this feature in bytes */
  51440. + uint16_t wDataLength;
  51441. +
  51442. + /**
  51443. + * Attributes of this features
  51444. + * D0: Access rights
  51445. + * 0 - Read/Write
  51446. + * 1 - Read only
  51447. + */
  51448. + uint8_t bmAttributes;
  51449. +#define CFI_FEATURE_ATTR_RO 1
  51450. +#define CFI_FEATURE_ATTR_RW 0
  51451. +
  51452. + /** Length of the feature name in bytes */
  51453. + uint8_t bNameLen;
  51454. +
  51455. + /** The feature name buffer */
  51456. + //uint8_t *name;
  51457. +} UPACKED;
  51458. +
  51459. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  51460. +
  51461. +/**
  51462. + * This structure describes a NULL terminated string referenced by its id field.
  51463. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  51464. + */
  51465. +struct cfi_string {
  51466. + uint16_t id;
  51467. + const uint8_t *s;
  51468. +};
  51469. +typedef struct cfi_string cfi_string_t;
  51470. +
  51471. +#endif
  51472. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  51473. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  51474. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-03-13 12:46:39.512097981 +0100
  51475. @@ -0,0 +1,854 @@
  51476. +/* ==========================================================================
  51477. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  51478. + * $Revision: #12 $
  51479. + * $Date: 2011/10/26 $
  51480. + * $Change: 1873028 $
  51481. + *
  51482. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51483. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51484. + * otherwise expressly agreed to in writing between Synopsys and you.
  51485. + *
  51486. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51487. + * any End User Software License Agreement or Agreement for Licensed Product
  51488. + * with Synopsys or any supplement thereto. You are permitted to use and
  51489. + * redistribute this Software in source and binary forms, with or without
  51490. + * modification, provided that redistributions of source code must retain this
  51491. + * notice. You may not view, use, disclose, copy or distribute this file or
  51492. + * any information contained herein except pursuant to this license grant from
  51493. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51494. + * below, then you are not authorized to use the Software.
  51495. + *
  51496. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51497. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51498. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51499. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51500. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51501. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51502. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51503. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51504. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51505. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51506. + * DAMAGE.
  51507. + * ========================================================================== */
  51508. +
  51509. +#include "dwc_os.h"
  51510. +#include "dwc_otg_regs.h"
  51511. +#include "dwc_otg_cil.h"
  51512. +#include "dwc_otg_adp.h"
  51513. +
  51514. +/** @file
  51515. + *
  51516. + * This file contains the most of the Attach Detect Protocol implementation for
  51517. + * the driver to support OTG Rev2.0.
  51518. + *
  51519. + */
  51520. +
  51521. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  51522. +{
  51523. + adpctl_data_t adpctl;
  51524. +
  51525. + adpctl.d32 = value;
  51526. + adpctl.b.ar = 0x2;
  51527. +
  51528. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51529. +
  51530. + while (adpctl.b.ar) {
  51531. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51532. + }
  51533. +
  51534. +}
  51535. +
  51536. +/**
  51537. + * Function is called to read ADP registers
  51538. + */
  51539. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  51540. +{
  51541. + adpctl_data_t adpctl;
  51542. +
  51543. + adpctl.d32 = 0;
  51544. + adpctl.b.ar = 0x1;
  51545. +
  51546. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51547. +
  51548. + while (adpctl.b.ar) {
  51549. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51550. + }
  51551. +
  51552. + return adpctl.d32;
  51553. +}
  51554. +
  51555. +/**
  51556. + * Function is called to read ADPCTL register and filter Write-clear bits
  51557. + */
  51558. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  51559. +{
  51560. + adpctl_data_t adpctl;
  51561. +
  51562. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51563. + adpctl.b.adp_tmout_int = 0;
  51564. + adpctl.b.adp_prb_int = 0;
  51565. + adpctl.b.adp_tmout_int = 0;
  51566. +
  51567. + return adpctl.d32;
  51568. +}
  51569. +
  51570. +/**
  51571. + * Function is called to write ADP registers
  51572. + */
  51573. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  51574. + uint32_t set)
  51575. +{
  51576. + dwc_otg_adp_write_reg(core_if,
  51577. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  51578. +}
  51579. +
  51580. +static void adp_sense_timeout(void *ptr)
  51581. +{
  51582. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51583. + core_if->adp.sense_timer_started = 0;
  51584. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  51585. + if (core_if->adp_enable) {
  51586. + dwc_otg_adp_sense_stop(core_if);
  51587. + dwc_otg_adp_probe_start(core_if);
  51588. + }
  51589. +}
  51590. +
  51591. +/**
  51592. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  51593. + */
  51594. +static void adp_vbuson_timeout(void *ptr)
  51595. +{
  51596. + gpwrdn_data_t gpwrdn;
  51597. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51598. + hprt0_data_t hprt0 = {.d32 = 0 };
  51599. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  51600. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  51601. + if (core_if) {
  51602. + core_if->adp.vbuson_timer_started = 0;
  51603. + /* Turn off vbus */
  51604. + hprt0.b.prtpwr = 1;
  51605. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  51606. + gpwrdn.d32 = 0;
  51607. +
  51608. + /* Power off the core */
  51609. + if (core_if->power_down == 2) {
  51610. + /* Enable Wakeup Logic */
  51611. +// gpwrdn.b.wkupactiv = 1;
  51612. + gpwrdn.b.pmuactv = 0;
  51613. + gpwrdn.b.pwrdnrstn = 1;
  51614. + gpwrdn.b.pwrdnclmp = 1;
  51615. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51616. + gpwrdn.d32);
  51617. +
  51618. + /* Suspend the Phy Clock */
  51619. + pcgcctl.b.stoppclk = 1;
  51620. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  51621. +
  51622. + /* Switch on VDD */
  51623. +// gpwrdn.b.wkupactiv = 1;
  51624. + gpwrdn.b.pmuactv = 1;
  51625. + gpwrdn.b.pwrdnrstn = 1;
  51626. + gpwrdn.b.pwrdnclmp = 1;
  51627. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51628. + gpwrdn.d32);
  51629. + } else {
  51630. + /* Enable Power Down Logic */
  51631. + gpwrdn.b.pmuintsel = 1;
  51632. + gpwrdn.b.pmuactv = 1;
  51633. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51634. + }
  51635. +
  51636. + /* Power off the core */
  51637. + if (core_if->power_down == 2) {
  51638. + gpwrdn.d32 = 0;
  51639. + gpwrdn.b.pwrdnswtch = 1;
  51640. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  51641. + gpwrdn.d32, 0);
  51642. + }
  51643. +
  51644. + /* Unmask SRP detected interrupt from Power Down Logic */
  51645. + gpwrdn.d32 = 0;
  51646. + gpwrdn.b.srp_det_msk = 1;
  51647. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51648. +
  51649. + dwc_otg_adp_probe_start(core_if);
  51650. + dwc_otg_dump_global_registers(core_if);
  51651. + dwc_otg_dump_host_registers(core_if);
  51652. + }
  51653. +
  51654. +}
  51655. +
  51656. +/**
  51657. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  51658. + * not asserted within 1.1 seconds.
  51659. + *
  51660. + * @param core_if the pointer to core_if strucure.
  51661. + */
  51662. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  51663. +{
  51664. + core_if->adp.vbuson_timer_started = 1;
  51665. + if (core_if->adp.vbuson_timer)
  51666. + {
  51667. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  51668. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  51669. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  51670. + } else {
  51671. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  51672. + }
  51673. +}
  51674. +
  51675. +#if 0
  51676. +/**
  51677. + * Masks all DWC OTG core interrupts
  51678. + *
  51679. + */
  51680. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  51681. +{
  51682. + int i;
  51683. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  51684. +
  51685. + /* Mask Host Interrupts */
  51686. +
  51687. + /* Clear and disable HCINTs */
  51688. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  51689. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  51690. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  51691. +
  51692. + }
  51693. +
  51694. + /* Clear and disable HAINT */
  51695. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  51696. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  51697. +
  51698. + /* Mask Device Interrupts */
  51699. + if (!core_if->multiproc_int_enable) {
  51700. + /* Clear and disable IN Endpoint interrupts */
  51701. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  51702. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  51703. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51704. + diepint, 0xFFFFFFFF);
  51705. + }
  51706. +
  51707. + /* Clear and disable OUT Endpoint interrupts */
  51708. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  51709. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  51710. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51711. + doepint, 0xFFFFFFFF);
  51712. + }
  51713. +
  51714. + /* Clear and disable DAINT */
  51715. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  51716. + 0xFFFFFFFF);
  51717. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  51718. + } else {
  51719. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  51720. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51721. + diepeachintmsk[i], 0);
  51722. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51723. + diepint, 0xFFFFFFFF);
  51724. + }
  51725. +
  51726. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  51727. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51728. + doepeachintmsk[i], 0);
  51729. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51730. + doepint, 0xFFFFFFFF);
  51731. + }
  51732. +
  51733. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  51734. + 0);
  51735. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  51736. + 0xFFFFFFFF);
  51737. +
  51738. + }
  51739. +
  51740. + /* Disable interrupts */
  51741. + ahbcfg.b.glblintrmsk = 1;
  51742. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  51743. +
  51744. + /* Disable all interrupts. */
  51745. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  51746. +
  51747. + /* Clear any pending interrupts */
  51748. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51749. +
  51750. + /* Clear any pending OTG Interrupts */
  51751. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  51752. +}
  51753. +
  51754. +/**
  51755. + * Unmask Port Connection Detected interrupt
  51756. + *
  51757. + */
  51758. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  51759. +{
  51760. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  51761. +
  51762. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  51763. +}
  51764. +#endif
  51765. +
  51766. +/**
  51767. + * Starts the ADP Probing
  51768. + *
  51769. + * @param core_if the pointer to core_if structure.
  51770. + */
  51771. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  51772. +{
  51773. +
  51774. + adpctl_data_t adpctl = {.d32 = 0};
  51775. + gpwrdn_data_t gpwrdn;
  51776. +#if 0
  51777. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  51778. + .b.adp_sns_int = 1, b.adp_tmout_int};
  51779. +#endif
  51780. + dwc_otg_disable_global_interrupts(core_if);
  51781. + DWC_PRINTF("ADP Probe Start\n");
  51782. + core_if->adp.probe_enabled = 1;
  51783. +
  51784. + adpctl.b.adpres = 1;
  51785. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51786. +
  51787. + while (adpctl.b.adpres) {
  51788. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51789. + }
  51790. +
  51791. + adpctl.d32 = 0;
  51792. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51793. +
  51794. + /* In Host mode unmask SRP detected interrupt */
  51795. + gpwrdn.d32 = 0;
  51796. + gpwrdn.b.sts_chngint_msk = 1;
  51797. + if (!gpwrdn.b.idsts) {
  51798. + gpwrdn.b.srp_det_msk = 1;
  51799. + }
  51800. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51801. +
  51802. + adpctl.b.adp_tmout_int_msk = 1;
  51803. + adpctl.b.adp_prb_int_msk = 1;
  51804. + adpctl.b.prb_dschg = 1;
  51805. + adpctl.b.prb_delta = 1;
  51806. + adpctl.b.prb_per = 1;
  51807. + adpctl.b.adpen = 1;
  51808. + adpctl.b.enaprb = 1;
  51809. +
  51810. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51811. + DWC_PRINTF("ADP Probe Finish\n");
  51812. + return 0;
  51813. +}
  51814. +
  51815. +/**
  51816. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  51817. + * within 3 seconds.
  51818. + *
  51819. + * @param core_if the pointer to core_if strucure.
  51820. + */
  51821. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  51822. +{
  51823. + core_if->adp.sense_timer_started = 1;
  51824. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  51825. +}
  51826. +
  51827. +/**
  51828. + * Starts the ADP Sense
  51829. + *
  51830. + * @param core_if the pointer to core_if strucure.
  51831. + */
  51832. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  51833. +{
  51834. + adpctl_data_t adpctl;
  51835. +
  51836. + DWC_PRINTF("ADP Sense Start\n");
  51837. +
  51838. + /* Unmask ADP sense interrupt and mask all other from the core */
  51839. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51840. + adpctl.b.adp_sns_int_msk = 1;
  51841. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51842. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  51843. +
  51844. + /* Set ADP reset bit*/
  51845. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51846. + adpctl.b.adpres = 1;
  51847. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51848. +
  51849. + while (adpctl.b.adpres) {
  51850. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51851. + }
  51852. +
  51853. + adpctl.b.adpres = 0;
  51854. + adpctl.b.adpen = 1;
  51855. + adpctl.b.enasns = 1;
  51856. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51857. +
  51858. + dwc_otg_adp_sense_timer_start(core_if);
  51859. +
  51860. + return 0;
  51861. +}
  51862. +
  51863. +/**
  51864. + * Stops the ADP Probing
  51865. + *
  51866. + * @param core_if the pointer to core_if strucure.
  51867. + */
  51868. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  51869. +{
  51870. +
  51871. + adpctl_data_t adpctl;
  51872. + DWC_PRINTF("Stop ADP probe\n");
  51873. + core_if->adp.probe_enabled = 0;
  51874. + core_if->adp.probe_counter = 0;
  51875. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51876. +
  51877. + adpctl.b.adpen = 0;
  51878. + adpctl.b.adp_prb_int = 1;
  51879. + adpctl.b.adp_tmout_int = 1;
  51880. + adpctl.b.adp_sns_int = 1;
  51881. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51882. +
  51883. + return 0;
  51884. +}
  51885. +
  51886. +/**
  51887. + * Stops the ADP Sensing
  51888. + *
  51889. + * @param core_if the pointer to core_if strucure.
  51890. + */
  51891. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  51892. +{
  51893. + adpctl_data_t adpctl;
  51894. +
  51895. + core_if->adp.sense_enabled = 0;
  51896. +
  51897. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51898. + adpctl.b.enasns = 0;
  51899. + adpctl.b.adp_sns_int = 1;
  51900. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51901. +
  51902. + return 0;
  51903. +}
  51904. +
  51905. +/**
  51906. + * Called to turn on the VBUS after initial ADP probe in host mode.
  51907. + * If port power was already enabled in cil_hcd_start function then
  51908. + * only schedule a timer.
  51909. + *
  51910. + * @param core_if the pointer to core_if structure.
  51911. + */
  51912. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  51913. +{
  51914. + hprt0_data_t hprt0 = {.d32 = 0 };
  51915. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51916. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  51917. +
  51918. + if (hprt0.b.prtpwr == 0) {
  51919. + hprt0.b.prtpwr = 1;
  51920. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51921. + }
  51922. +
  51923. + dwc_otg_adp_vbuson_timer_start(core_if);
  51924. +}
  51925. +
  51926. +/**
  51927. + * Called right after driver is loaded
  51928. + * to perform initial actions for ADP
  51929. + *
  51930. + * @param core_if the pointer to core_if structure.
  51931. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  51932. + */
  51933. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  51934. +{
  51935. + gpwrdn_data_t gpwrdn;
  51936. +
  51937. + DWC_PRINTF("ADP Initial Start\n");
  51938. + core_if->adp.adp_started = 1;
  51939. +
  51940. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51941. + dwc_otg_disable_global_interrupts(core_if);
  51942. + if (is_host) {
  51943. + DWC_PRINTF("HOST MODE\n");
  51944. + /* Enable Power Down Logic Interrupt*/
  51945. + gpwrdn.d32 = 0;
  51946. + gpwrdn.b.pmuintsel = 1;
  51947. + gpwrdn.b.pmuactv = 1;
  51948. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51949. + /* Initialize first ADP probe to obtain Ramp Time value */
  51950. + core_if->adp.initial_probe = 1;
  51951. + dwc_otg_adp_probe_start(core_if);
  51952. + } else {
  51953. + gotgctl_data_t gotgctl;
  51954. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51955. + DWC_PRINTF("DEVICE MODE\n");
  51956. + if (gotgctl.b.bsesvld == 0) {
  51957. + /* Enable Power Down Logic Interrupt*/
  51958. + gpwrdn.d32 = 0;
  51959. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  51960. + gpwrdn.b.pmuintsel = 1;
  51961. + gpwrdn.b.pmuactv = 1;
  51962. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51963. + core_if->adp.initial_probe = 1;
  51964. + dwc_otg_adp_probe_start(core_if);
  51965. + } else {
  51966. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  51967. + core_if->op_state = B_PERIPHERAL;
  51968. + dwc_otg_core_init(core_if);
  51969. + dwc_otg_enable_global_interrupts(core_if);
  51970. + cil_pcd_start(core_if);
  51971. + dwc_otg_dump_global_registers(core_if);
  51972. + dwc_otg_dump_dev_registers(core_if);
  51973. + }
  51974. + }
  51975. +}
  51976. +
  51977. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  51978. +{
  51979. + core_if->adp.adp_started = 0;
  51980. + core_if->adp.initial_probe = 0;
  51981. + core_if->adp.probe_timer_values[0] = -1;
  51982. + core_if->adp.probe_timer_values[1] = -1;
  51983. + core_if->adp.probe_enabled = 0;
  51984. + core_if->adp.sense_enabled = 0;
  51985. + core_if->adp.sense_timer_started = 0;
  51986. + core_if->adp.vbuson_timer_started = 0;
  51987. + core_if->adp.probe_counter = 0;
  51988. + core_if->adp.gpwrdn = 0;
  51989. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  51990. + /* Initialize timers */
  51991. + core_if->adp.sense_timer =
  51992. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  51993. + core_if->adp.vbuson_timer =
  51994. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  51995. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  51996. + {
  51997. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  51998. + }
  51999. +}
  52000. +
  52001. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  52002. +{
  52003. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  52004. + gpwrdn.b.pmuintsel = 1;
  52005. + gpwrdn.b.pmuactv = 1;
  52006. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52007. +
  52008. + if (core_if->adp.probe_enabled)
  52009. + dwc_otg_adp_probe_stop(core_if);
  52010. + if (core_if->adp.sense_enabled)
  52011. + dwc_otg_adp_sense_stop(core_if);
  52012. + if (core_if->adp.sense_timer_started)
  52013. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52014. + if (core_if->adp.vbuson_timer_started)
  52015. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  52016. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  52017. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  52018. +}
  52019. +
  52020. +/////////////////////////////////////////////////////////////////////
  52021. +////////////// ADP Interrupt Handlers ///////////////////////////////
  52022. +/////////////////////////////////////////////////////////////////////
  52023. +/**
  52024. + * This function sets Ramp Timer values
  52025. + */
  52026. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  52027. +{
  52028. + if (core_if->adp.probe_timer_values[0] == -1) {
  52029. + core_if->adp.probe_timer_values[0] = val;
  52030. + core_if->adp.probe_timer_values[1] = -1;
  52031. + return 1;
  52032. + } else {
  52033. + core_if->adp.probe_timer_values[1] =
  52034. + core_if->adp.probe_timer_values[0];
  52035. + core_if->adp.probe_timer_values[0] = val;
  52036. + return 0;
  52037. + }
  52038. +}
  52039. +
  52040. +/**
  52041. + * This function compares Ramp Timer values
  52042. + */
  52043. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  52044. +{
  52045. + uint32_t diff;
  52046. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  52047. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  52048. + else
  52049. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  52050. + if(diff < 2) {
  52051. + return 0;
  52052. + } else {
  52053. + return 1;
  52054. + }
  52055. +}
  52056. +
  52057. +/**
  52058. + * This function handles ADP Probe Interrupts
  52059. + */
  52060. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  52061. + uint32_t val)
  52062. +{
  52063. + adpctl_data_t adpctl = {.d32 = 0 };
  52064. + gpwrdn_data_t gpwrdn, temp;
  52065. + adpctl.d32 = val;
  52066. +
  52067. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52068. + core_if->adp.probe_counter++;
  52069. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52070. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  52071. + DWC_PRINTF("RTIM value is 0\n");
  52072. + goto exit;
  52073. + }
  52074. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  52075. + core_if->adp.initial_probe) {
  52076. + core_if->adp.initial_probe = 0;
  52077. + dwc_otg_adp_probe_stop(core_if);
  52078. + gpwrdn.d32 = 0;
  52079. + gpwrdn.b.pmuactv = 1;
  52080. + gpwrdn.b.pmuintsel = 1;
  52081. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52082. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52083. +
  52084. + /* check which value is for device mode and which for Host mode */
  52085. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52086. + /*
  52087. + * Turn on VBUS after initial ADP probe.
  52088. + */
  52089. + core_if->op_state = A_HOST;
  52090. + dwc_otg_enable_global_interrupts(core_if);
  52091. + DWC_SPINUNLOCK(core_if->lock);
  52092. + cil_hcd_start(core_if);
  52093. + dwc_otg_adp_turnon_vbus(core_if);
  52094. + DWC_SPINLOCK(core_if->lock);
  52095. + } else {
  52096. + /*
  52097. + * Initiate SRP after initial ADP probe.
  52098. + */
  52099. + dwc_otg_enable_global_interrupts(core_if);
  52100. + dwc_otg_initiate_srp(core_if);
  52101. + }
  52102. + } else if (core_if->adp.probe_counter > 2){
  52103. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52104. + if (compare_timer_values(core_if)) {
  52105. + DWC_PRINTF("Difference in timer values !!! \n");
  52106. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  52107. + dwc_otg_adp_probe_stop(core_if);
  52108. +
  52109. + /* Power on the core */
  52110. + if (core_if->power_down == 2) {
  52111. + gpwrdn.b.pwrdnswtch = 1;
  52112. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52113. + gpwrdn, 0, gpwrdn.d32);
  52114. + }
  52115. +
  52116. + /* check which value is for device mode and which for Host mode */
  52117. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52118. + /* Disable Interrupt from Power Down Logic */
  52119. + gpwrdn.d32 = 0;
  52120. + gpwrdn.b.pmuintsel = 1;
  52121. + gpwrdn.b.pmuactv = 1;
  52122. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52123. + gpwrdn, gpwrdn.d32, 0);
  52124. +
  52125. + /*
  52126. + * Initialize the Core for Host mode.
  52127. + */
  52128. + core_if->op_state = A_HOST;
  52129. + dwc_otg_core_init(core_if);
  52130. + dwc_otg_enable_global_interrupts(core_if);
  52131. + cil_hcd_start(core_if);
  52132. + } else {
  52133. + gotgctl_data_t gotgctl;
  52134. + /* Mask SRP detected interrupt from Power Down Logic */
  52135. + gpwrdn.d32 = 0;
  52136. + gpwrdn.b.srp_det_msk = 1;
  52137. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52138. + gpwrdn, gpwrdn.d32, 0);
  52139. +
  52140. + /* Disable Power Down Logic */
  52141. + gpwrdn.d32 = 0;
  52142. + gpwrdn.b.pmuintsel = 1;
  52143. + gpwrdn.b.pmuactv = 1;
  52144. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52145. + gpwrdn, gpwrdn.d32, 0);
  52146. +
  52147. + /*
  52148. + * Initialize the Core for Device mode.
  52149. + */
  52150. + core_if->op_state = B_PERIPHERAL;
  52151. + dwc_otg_core_init(core_if);
  52152. + dwc_otg_enable_global_interrupts(core_if);
  52153. + cil_pcd_start(core_if);
  52154. +
  52155. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52156. + if (!gotgctl.b.bsesvld) {
  52157. + dwc_otg_initiate_srp(core_if);
  52158. + }
  52159. + }
  52160. + }
  52161. + if (core_if->power_down == 2) {
  52162. + if (gpwrdn.b.bsessvld) {
  52163. + /* Mask SRP detected interrupt from Power Down Logic */
  52164. + gpwrdn.d32 = 0;
  52165. + gpwrdn.b.srp_det_msk = 1;
  52166. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52167. +
  52168. + /* Disable Power Down Logic */
  52169. + gpwrdn.d32 = 0;
  52170. + gpwrdn.b.pmuactv = 1;
  52171. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52172. +
  52173. + /*
  52174. + * Initialize the Core for Device mode.
  52175. + */
  52176. + core_if->op_state = B_PERIPHERAL;
  52177. + dwc_otg_core_init(core_if);
  52178. + dwc_otg_enable_global_interrupts(core_if);
  52179. + cil_pcd_start(core_if);
  52180. + }
  52181. + }
  52182. + }
  52183. +exit:
  52184. + /* Clear interrupt */
  52185. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52186. + adpctl.b.adp_prb_int = 1;
  52187. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52188. +
  52189. + return 0;
  52190. +}
  52191. +
  52192. +/**
  52193. + * This function hadles ADP Sense Interrupt
  52194. + */
  52195. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  52196. +{
  52197. + adpctl_data_t adpctl;
  52198. + /* Stop ADP Sense timer */
  52199. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52200. +
  52201. + /* Restart ADP Sense timer */
  52202. + dwc_otg_adp_sense_timer_start(core_if);
  52203. +
  52204. + /* Clear interrupt */
  52205. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52206. + adpctl.b.adp_sns_int = 1;
  52207. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52208. +
  52209. + return 0;
  52210. +}
  52211. +
  52212. +/**
  52213. + * This function handles ADP Probe Interrupts
  52214. + */
  52215. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  52216. + uint32_t val)
  52217. +{
  52218. + adpctl_data_t adpctl = {.d32 = 0 };
  52219. + adpctl.d32 = val;
  52220. + set_timer_value(core_if, adpctl.b.rtim);
  52221. +
  52222. + /* Clear interrupt */
  52223. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52224. + adpctl.b.adp_tmout_int = 1;
  52225. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52226. +
  52227. + return 0;
  52228. +}
  52229. +
  52230. +/**
  52231. + * ADP Interrupt handler.
  52232. + *
  52233. + */
  52234. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  52235. +{
  52236. + int retval = 0;
  52237. + adpctl_data_t adpctl = {.d32 = 0};
  52238. +
  52239. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52240. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  52241. +
  52242. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  52243. + DWC_PRINTF("ADP Sense interrupt\n");
  52244. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  52245. + }
  52246. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  52247. + DWC_PRINTF("ADP timeout interrupt\n");
  52248. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  52249. + }
  52250. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  52251. + DWC_PRINTF("ADP Probe interrupt\n");
  52252. + adpctl.b.adp_prb_int = 1;
  52253. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  52254. + }
  52255. +
  52256. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  52257. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52258. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  52259. +
  52260. + return retval;
  52261. +}
  52262. +
  52263. +/**
  52264. + *
  52265. + * @param core_if Programming view of DWC_otg controller.
  52266. + */
  52267. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  52268. +{
  52269. +
  52270. +#ifndef DWC_HOST_ONLY
  52271. + hprt0_data_t hprt0;
  52272. + gpwrdn_data_t gpwrdn;
  52273. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  52274. +
  52275. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52276. + /* check which value is for device mode and which for Host mode */
  52277. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  52278. + DWC_PRINTF("SRP: Host mode\n");
  52279. +
  52280. + if (core_if->adp_enable) {
  52281. + dwc_otg_adp_probe_stop(core_if);
  52282. +
  52283. + /* Power on the core */
  52284. + if (core_if->power_down == 2) {
  52285. + gpwrdn.b.pwrdnswtch = 1;
  52286. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52287. + gpwrdn, 0, gpwrdn.d32);
  52288. + }
  52289. +
  52290. + core_if->op_state = A_HOST;
  52291. + dwc_otg_core_init(core_if);
  52292. + dwc_otg_enable_global_interrupts(core_if);
  52293. + cil_hcd_start(core_if);
  52294. + }
  52295. +
  52296. + /* Turn on the port power bit. */
  52297. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  52298. + hprt0.b.prtpwr = 1;
  52299. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  52300. +
  52301. + /* Start the Connection timer. So a message can be displayed
  52302. + * if connect does not occur within 10 seconds. */
  52303. + cil_hcd_session_start(core_if);
  52304. + } else {
  52305. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  52306. + if (core_if->adp_enable) {
  52307. + dwc_otg_adp_probe_stop(core_if);
  52308. +
  52309. + /* Power on the core */
  52310. + if (core_if->power_down == 2) {
  52311. + gpwrdn.b.pwrdnswtch = 1;
  52312. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52313. + gpwrdn, 0, gpwrdn.d32);
  52314. + }
  52315. +
  52316. + gpwrdn.d32 = 0;
  52317. + gpwrdn.b.pmuactv = 0;
  52318. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  52319. + gpwrdn.d32);
  52320. +
  52321. + core_if->op_state = B_PERIPHERAL;
  52322. + dwc_otg_core_init(core_if);
  52323. + dwc_otg_enable_global_interrupts(core_if);
  52324. + cil_pcd_start(core_if);
  52325. + }
  52326. + }
  52327. +#endif
  52328. + return 1;
  52329. +}
  52330. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  52331. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  52332. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-03-13 12:46:39.512097981 +0100
  52333. @@ -0,0 +1,80 @@
  52334. +/* ==========================================================================
  52335. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  52336. + * $Revision: #7 $
  52337. + * $Date: 2011/10/24 $
  52338. + * $Change: 1871159 $
  52339. + *
  52340. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52341. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52342. + * otherwise expressly agreed to in writing between Synopsys and you.
  52343. + *
  52344. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52345. + * any End User Software License Agreement or Agreement for Licensed Product
  52346. + * with Synopsys or any supplement thereto. You are permitted to use and
  52347. + * redistribute this Software in source and binary forms, with or without
  52348. + * modification, provided that redistributions of source code must retain this
  52349. + * notice. You may not view, use, disclose, copy or distribute this file or
  52350. + * any information contained herein except pursuant to this license grant from
  52351. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52352. + * below, then you are not authorized to use the Software.
  52353. + *
  52354. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52355. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52356. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52357. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52358. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52359. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52360. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52361. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52362. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52363. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52364. + * DAMAGE.
  52365. + * ========================================================================== */
  52366. +
  52367. +#ifndef __DWC_OTG_ADP_H__
  52368. +#define __DWC_OTG_ADP_H__
  52369. +
  52370. +/**
  52371. + * @file
  52372. + *
  52373. + * This file contains the Attach Detect Protocol interfaces and defines
  52374. + * (functions) and structures for Linux.
  52375. + *
  52376. + */
  52377. +
  52378. +#define DWC_OTG_ADP_UNATTACHED 0
  52379. +#define DWC_OTG_ADP_ATTACHED 1
  52380. +#define DWC_OTG_ADP_UNKOWN 2
  52381. +
  52382. +typedef struct dwc_otg_adp {
  52383. + uint32_t adp_started;
  52384. + uint32_t initial_probe;
  52385. + int32_t probe_timer_values[2];
  52386. + uint32_t probe_enabled;
  52387. + uint32_t sense_enabled;
  52388. + dwc_timer_t *sense_timer;
  52389. + uint32_t sense_timer_started;
  52390. + dwc_timer_t *vbuson_timer;
  52391. + uint32_t vbuson_timer_started;
  52392. + uint32_t attached;
  52393. + uint32_t probe_counter;
  52394. + uint32_t gpwrdn;
  52395. +} dwc_otg_adp_t;
  52396. +
  52397. +/**
  52398. + * Attach Detect Protocol functions
  52399. + */
  52400. +
  52401. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  52402. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  52403. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  52404. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  52405. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  52406. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  52407. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  52408. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  52409. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  52410. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  52411. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  52412. +
  52413. +#endif //__DWC_OTG_ADP_H__
  52414. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  52415. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  52416. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-03-13 12:46:39.512097981 +0100
  52417. @@ -0,0 +1,1210 @@
  52418. +/* ==========================================================================
  52419. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  52420. + * $Revision: #44 $
  52421. + * $Date: 2010/11/29 $
  52422. + * $Change: 1636033 $
  52423. + *
  52424. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52425. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52426. + * otherwise expressly agreed to in writing between Synopsys and you.
  52427. + *
  52428. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52429. + * any End User Software License Agreement or Agreement for Licensed Product
  52430. + * with Synopsys or any supplement thereto. You are permitted to use and
  52431. + * redistribute this Software in source and binary forms, with or without
  52432. + * modification, provided that redistributions of source code must retain this
  52433. + * notice. You may not view, use, disclose, copy or distribute this file or
  52434. + * any information contained herein except pursuant to this license grant from
  52435. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52436. + * below, then you are not authorized to use the Software.
  52437. + *
  52438. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52439. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52440. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52441. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52442. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52443. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52444. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52445. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52446. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52447. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52448. + * DAMAGE.
  52449. + * ========================================================================== */
  52450. +
  52451. +/** @file
  52452. + *
  52453. + * The diagnostic interface will provide access to the controller for
  52454. + * bringing up the hardware and testing. The Linux driver attributes
  52455. + * feature will be used to provide the Linux Diagnostic
  52456. + * Interface. These attributes are accessed through sysfs.
  52457. + */
  52458. +
  52459. +/** @page "Linux Module Attributes"
  52460. + *
  52461. + * The Linux module attributes feature is used to provide the Linux
  52462. + * Diagnostic Interface. These attributes are accessed through sysfs.
  52463. + * The diagnostic interface will provide access to the controller for
  52464. + * bringing up the hardware and testing.
  52465. +
  52466. + The following table shows the attributes.
  52467. + <table>
  52468. + <tr>
  52469. + <td><b> Name</b></td>
  52470. + <td><b> Description</b></td>
  52471. + <td><b> Access</b></td>
  52472. + </tr>
  52473. +
  52474. + <tr>
  52475. + <td> mode </td>
  52476. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  52477. + <td> Read</td>
  52478. + </tr>
  52479. +
  52480. + <tr>
  52481. + <td> hnpcapable </td>
  52482. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  52483. + Read returns the current value.</td>
  52484. + <td> Read/Write</td>
  52485. + </tr>
  52486. +
  52487. + <tr>
  52488. + <td> srpcapable </td>
  52489. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  52490. + Read returns the current value.</td>
  52491. + <td> Read/Write</td>
  52492. + </tr>
  52493. +
  52494. + <tr>
  52495. + <td> hsic_connect </td>
  52496. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  52497. + Read returns the current value.</td>
  52498. + <td> Read/Write</td>
  52499. + </tr>
  52500. +
  52501. + <tr>
  52502. + <td> inv_sel_hsic </td>
  52503. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  52504. + Read returns the current value.</td>
  52505. + <td> Read/Write</td>
  52506. + </tr>
  52507. +
  52508. + <tr>
  52509. + <td> hnp </td>
  52510. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  52511. + <td> Read/Write</td>
  52512. + </tr>
  52513. +
  52514. + <tr>
  52515. + <td> srp </td>
  52516. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  52517. + <td> Read/Write</td>
  52518. + </tr>
  52519. +
  52520. + <tr>
  52521. + <td> buspower </td>
  52522. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  52523. + <td> Read/Write</td>
  52524. + </tr>
  52525. +
  52526. + <tr>
  52527. + <td> bussuspend </td>
  52528. + <td> Suspends the USB bus.</td>
  52529. + <td> Read/Write</td>
  52530. + </tr>
  52531. +
  52532. + <tr>
  52533. + <td> busconnected </td>
  52534. + <td> Gets the connection status of the bus</td>
  52535. + <td> Read</td>
  52536. + </tr>
  52537. +
  52538. + <tr>
  52539. + <td> gotgctl </td>
  52540. + <td> Gets or sets the Core Control Status Register.</td>
  52541. + <td> Read/Write</td>
  52542. + </tr>
  52543. +
  52544. + <tr>
  52545. + <td> gusbcfg </td>
  52546. + <td> Gets or sets the Core USB Configuration Register</td>
  52547. + <td> Read/Write</td>
  52548. + </tr>
  52549. +
  52550. + <tr>
  52551. + <td> grxfsiz </td>
  52552. + <td> Gets or sets the Receive FIFO Size Register</td>
  52553. + <td> Read/Write</td>
  52554. + </tr>
  52555. +
  52556. + <tr>
  52557. + <td> gnptxfsiz </td>
  52558. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  52559. + <td> Read/Write</td>
  52560. + </tr>
  52561. +
  52562. + <tr>
  52563. + <td> gpvndctl </td>
  52564. + <td> Gets or sets the PHY Vendor Control Register</td>
  52565. + <td> Read/Write</td>
  52566. + </tr>
  52567. +
  52568. + <tr>
  52569. + <td> ggpio </td>
  52570. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  52571. + or sets the upper 16 bits.</td>
  52572. + <td> Read/Write</td>
  52573. + </tr>
  52574. +
  52575. + <tr>
  52576. + <td> guid </td>
  52577. + <td> Gets or sets the value of the User ID Register</td>
  52578. + <td> Read/Write</td>
  52579. + </tr>
  52580. +
  52581. + <tr>
  52582. + <td> gsnpsid </td>
  52583. + <td> Gets the value of the Synopsys ID Regester</td>
  52584. + <td> Read</td>
  52585. + </tr>
  52586. +
  52587. + <tr>
  52588. + <td> devspeed </td>
  52589. + <td> Gets or sets the device speed setting in the DCFG register</td>
  52590. + <td> Read/Write</td>
  52591. + </tr>
  52592. +
  52593. + <tr>
  52594. + <td> enumspeed </td>
  52595. + <td> Gets the device enumeration Speed.</td>
  52596. + <td> Read</td>
  52597. + </tr>
  52598. +
  52599. + <tr>
  52600. + <td> hptxfsiz </td>
  52601. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  52602. + <td> Read</td>
  52603. + </tr>
  52604. +
  52605. + <tr>
  52606. + <td> hprt0 </td>
  52607. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  52608. + <td> Read/Write</td>
  52609. + </tr>
  52610. +
  52611. + <tr>
  52612. + <td> regoffset </td>
  52613. + <td> Sets the register offset for the next Register Access</td>
  52614. + <td> Read/Write</td>
  52615. + </tr>
  52616. +
  52617. + <tr>
  52618. + <td> regvalue </td>
  52619. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  52620. + <td> Read/Write</td>
  52621. + </tr>
  52622. +
  52623. + <tr>
  52624. + <td> remote_wakeup </td>
  52625. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  52626. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  52627. + Wakeup signalling bit in the Device Control Register is set for 1
  52628. + milli-second.</td>
  52629. + <td> Read/Write</td>
  52630. + </tr>
  52631. +
  52632. + <tr>
  52633. + <td> rem_wakeup_pwrdn </td>
  52634. + <td> On read, shows the status core - hibernated or not. On write, initiates
  52635. + a remote wakeup of the device from Hibernation. </td>
  52636. + <td> Read/Write</td>
  52637. + </tr>
  52638. +
  52639. + <tr>
  52640. + <td> mode_ch_tim_en </td>
  52641. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  52642. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  52643. + after Suspend or LPM. </td>
  52644. + <td> Read/Write</td>
  52645. + </tr>
  52646. +
  52647. + <tr>
  52648. + <td> fr_interval </td>
  52649. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  52650. + reload HFIR register during runtime. The application can write a value to this
  52651. + register only after the Port Enable bit of the Host Port Control and Status
  52652. + register (HPRT.PrtEnaPort) has been set </td>
  52653. + <td> Read/Write</td>
  52654. + </tr>
  52655. +
  52656. + <tr>
  52657. + <td> disconnect_us </td>
  52658. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  52659. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  52660. + <td> Read/Write</td>
  52661. + </tr>
  52662. +
  52663. + <tr>
  52664. + <td> regdump </td>
  52665. + <td> Dumps the contents of core registers.</td>
  52666. + <td> Read</td>
  52667. + </tr>
  52668. +
  52669. + <tr>
  52670. + <td> spramdump </td>
  52671. + <td> Dumps the contents of core registers.</td>
  52672. + <td> Read</td>
  52673. + </tr>
  52674. +
  52675. + <tr>
  52676. + <td> hcddump </td>
  52677. + <td> Dumps the current HCD state.</td>
  52678. + <td> Read</td>
  52679. + </tr>
  52680. +
  52681. + <tr>
  52682. + <td> hcd_frrem </td>
  52683. + <td> Shows the average value of the Frame Remaining
  52684. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  52685. + occurs. This can be used to determine the average interrupt latency. Also
  52686. + shows the average Frame Remaining value for start_transfer and the "a" and
  52687. + "b" sample points. The "a" and "b" sample points may be used during debugging
  52688. + bto determine how long it takes to execute a section of the HCD code.</td>
  52689. + <td> Read</td>
  52690. + </tr>
  52691. +
  52692. + <tr>
  52693. + <td> rd_reg_test </td>
  52694. + <td> Displays the time required to read the GNPTXFSIZ register many times
  52695. + (the output shows the number of times the register is read).
  52696. + <td> Read</td>
  52697. + </tr>
  52698. +
  52699. + <tr>
  52700. + <td> wr_reg_test </td>
  52701. + <td> Displays the time required to write the GNPTXFSIZ register many times
  52702. + (the output shows the number of times the register is written).
  52703. + <td> Read</td>
  52704. + </tr>
  52705. +
  52706. + <tr>
  52707. + <td> lpm_response </td>
  52708. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  52709. + <td> Write</td>
  52710. + </tr>
  52711. +
  52712. + <tr>
  52713. + <td> sleep_status </td>
  52714. + <td> Shows sleep status of device.
  52715. + <td> Read</td>
  52716. + </tr>
  52717. +
  52718. + </table>
  52719. +
  52720. + Example usage:
  52721. + To get the current mode:
  52722. + cat /sys/devices/lm0/mode
  52723. +
  52724. + To power down the USB:
  52725. + echo 0 > /sys/devices/lm0/buspower
  52726. + */
  52727. +
  52728. +#include "dwc_otg_os_dep.h"
  52729. +#include "dwc_os.h"
  52730. +#include "dwc_otg_driver.h"
  52731. +#include "dwc_otg_attr.h"
  52732. +#include "dwc_otg_core_if.h"
  52733. +#include "dwc_otg_pcd_if.h"
  52734. +#include "dwc_otg_hcd_if.h"
  52735. +
  52736. +/*
  52737. + * MACROs for defining sysfs attribute
  52738. + */
  52739. +#ifdef LM_INTERFACE
  52740. +
  52741. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52742. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52743. +{ \
  52744. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52745. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52746. + uint32_t val; \
  52747. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52748. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52749. +}
  52750. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52751. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52752. + const char *buf, size_t count) \
  52753. +{ \
  52754. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52755. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52756. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52757. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52758. + return count; \
  52759. +}
  52760. +
  52761. +#elif defined(PCI_INTERFACE)
  52762. +
  52763. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52764. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52765. +{ \
  52766. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52767. + uint32_t val; \
  52768. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52769. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52770. +}
  52771. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52772. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52773. + const char *buf, size_t count) \
  52774. +{ \
  52775. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52776. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52777. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52778. + return count; \
  52779. +}
  52780. +
  52781. +#elif defined(PLATFORM_INTERFACE)
  52782. +
  52783. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52784. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52785. +{ \
  52786. + struct platform_device *platform_dev = \
  52787. + container_of(_dev, struct platform_device, dev); \
  52788. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52789. + uint32_t val; \
  52790. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52791. + __func__, _dev, platform_dev, otg_dev); \
  52792. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52793. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52794. +}
  52795. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52796. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52797. + const char *buf, size_t count) \
  52798. +{ \
  52799. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52800. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52801. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52802. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52803. + return count; \
  52804. +}
  52805. +#endif
  52806. +
  52807. +/*
  52808. + * MACROs for defining sysfs attribute for 32-bit registers
  52809. + */
  52810. +#ifdef LM_INTERFACE
  52811. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52812. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52813. +{ \
  52814. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52815. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52816. + uint32_t val; \
  52817. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52818. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52819. +}
  52820. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52821. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52822. + const char *buf, size_t count) \
  52823. +{ \
  52824. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52825. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52826. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52827. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52828. + return count; \
  52829. +}
  52830. +#elif defined(PCI_INTERFACE)
  52831. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52832. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52833. +{ \
  52834. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52835. + uint32_t val; \
  52836. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52837. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52838. +}
  52839. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52840. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52841. + const char *buf, size_t count) \
  52842. +{ \
  52843. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52844. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52845. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52846. + return count; \
  52847. +}
  52848. +
  52849. +#elif defined(PLATFORM_INTERFACE)
  52850. +#include "dwc_otg_dbg.h"
  52851. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52852. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52853. +{ \
  52854. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52855. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52856. + uint32_t val; \
  52857. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52858. + __func__, _dev, platform_dev, otg_dev); \
  52859. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52860. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52861. +}
  52862. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52863. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52864. + const char *buf, size_t count) \
  52865. +{ \
  52866. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52867. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52868. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52869. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52870. + return count; \
  52871. +}
  52872. +
  52873. +#endif
  52874. +
  52875. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  52876. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52877. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52878. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52879. +
  52880. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  52881. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52882. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52883. +
  52884. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  52885. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52886. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52887. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52888. +
  52889. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  52890. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52891. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52892. +
  52893. +/** @name Functions for Show/Store of Attributes */
  52894. +/**@{*/
  52895. +
  52896. +/**
  52897. + * Helper function returning the otg_device structure of the given device
  52898. + */
  52899. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  52900. +{
  52901. + dwc_otg_device_t *otg_dev;
  52902. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  52903. + return otg_dev;
  52904. +}
  52905. +
  52906. +/**
  52907. + * Show the register offset of the Register Access.
  52908. + */
  52909. +static ssize_t regoffset_show(struct device *_dev,
  52910. + struct device_attribute *attr, char *buf)
  52911. +{
  52912. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52913. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  52914. + otg_dev->os_dep.reg_offset);
  52915. +}
  52916. +
  52917. +/**
  52918. + * Set the register offset for the next Register Access Read/Write
  52919. + */
  52920. +static ssize_t regoffset_store(struct device *_dev,
  52921. + struct device_attribute *attr,
  52922. + const char *buf, size_t count)
  52923. +{
  52924. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52925. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  52926. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  52927. + if (offset < SZ_256K) {
  52928. +#elif defined(PCI_INTERFACE)
  52929. + if (offset < 0x00040000) {
  52930. +#endif
  52931. + otg_dev->os_dep.reg_offset = offset;
  52932. + } else {
  52933. + dev_err(_dev, "invalid offset\n");
  52934. + }
  52935. +
  52936. + return count;
  52937. +}
  52938. +
  52939. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  52940. +
  52941. +/**
  52942. + * Show the value of the register at the offset in the reg_offset
  52943. + * attribute.
  52944. + */
  52945. +static ssize_t regvalue_show(struct device *_dev,
  52946. + struct device_attribute *attr, char *buf)
  52947. +{
  52948. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52949. + uint32_t val;
  52950. + volatile uint32_t *addr;
  52951. +
  52952. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52953. + /* Calculate the address */
  52954. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52955. + (uint8_t *) otg_dev->os_dep.base);
  52956. + val = DWC_READ_REG32(addr);
  52957. + return snprintf(buf,
  52958. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  52959. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  52960. + val);
  52961. + } else {
  52962. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  52963. + return sprintf(buf, "invalid offset\n");
  52964. + }
  52965. +}
  52966. +
  52967. +/**
  52968. + * Store the value in the register at the offset in the reg_offset
  52969. + * attribute.
  52970. + *
  52971. + */
  52972. +static ssize_t regvalue_store(struct device *_dev,
  52973. + struct device_attribute *attr,
  52974. + const char *buf, size_t count)
  52975. +{
  52976. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52977. + volatile uint32_t *addr;
  52978. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52979. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  52980. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52981. + /* Calculate the address */
  52982. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52983. + (uint8_t *) otg_dev->os_dep.base);
  52984. + DWC_WRITE_REG32(addr, val);
  52985. + } else {
  52986. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  52987. + otg_dev->os_dep.reg_offset);
  52988. + }
  52989. + return count;
  52990. +}
  52991. +
  52992. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  52993. +
  52994. +/*
  52995. + * Attributes
  52996. + */
  52997. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  52998. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  52999. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  53000. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  53001. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  53002. +
  53003. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53004. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53005. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  53006. +
  53007. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  53008. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  53009. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  53010. + "GUSBCFG");
  53011. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  53012. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  53013. + "GRXFSIZ");
  53014. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  53015. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  53016. + "GNPTXFSIZ");
  53017. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  53018. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  53019. + "GPVNDCTL");
  53020. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  53021. + &(otg_dev->core_if->core_global_regs->ggpio),
  53022. + "GGPIO");
  53023. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  53024. + "GUID");
  53025. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  53026. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  53027. + "GSNPSID");
  53028. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  53029. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  53030. +
  53031. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  53032. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  53033. + "HPTXFSIZ");
  53034. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  53035. +
  53036. +/**
  53037. + * @todo Add code to initiate the HNP.
  53038. + */
  53039. +/**
  53040. + * Show the HNP status bit
  53041. + */
  53042. +static ssize_t hnp_show(struct device *_dev,
  53043. + struct device_attribute *attr, char *buf)
  53044. +{
  53045. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53046. + return sprintf(buf, "HstNegScs = 0x%x\n",
  53047. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  53048. +}
  53049. +
  53050. +/**
  53051. + * Set the HNP Request bit
  53052. + */
  53053. +static ssize_t hnp_store(struct device *_dev,
  53054. + struct device_attribute *attr,
  53055. + const char *buf, size_t count)
  53056. +{
  53057. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53058. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53059. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  53060. + return count;
  53061. +}
  53062. +
  53063. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  53064. +
  53065. +/**
  53066. + * @todo Add code to initiate the SRP.
  53067. + */
  53068. +/**
  53069. + * Show the SRP status bit
  53070. + */
  53071. +static ssize_t srp_show(struct device *_dev,
  53072. + struct device_attribute *attr, char *buf)
  53073. +{
  53074. +#ifndef DWC_HOST_ONLY
  53075. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53076. + return sprintf(buf, "SesReqScs = 0x%x\n",
  53077. + dwc_otg_get_srpstatus(otg_dev->core_if));
  53078. +#else
  53079. + return sprintf(buf, "Host Only Mode!\n");
  53080. +#endif
  53081. +}
  53082. +
  53083. +/**
  53084. + * Set the SRP Request bit
  53085. + */
  53086. +static ssize_t srp_store(struct device *_dev,
  53087. + struct device_attribute *attr,
  53088. + const char *buf, size_t count)
  53089. +{
  53090. +#ifndef DWC_HOST_ONLY
  53091. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53092. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  53093. +#endif
  53094. + return count;
  53095. +}
  53096. +
  53097. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  53098. +
  53099. +/**
  53100. + * @todo Need to do more for power on/off?
  53101. + */
  53102. +/**
  53103. + * Show the Bus Power status
  53104. + */
  53105. +static ssize_t buspower_show(struct device *_dev,
  53106. + struct device_attribute *attr, char *buf)
  53107. +{
  53108. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53109. + return sprintf(buf, "Bus Power = 0x%x\n",
  53110. + dwc_otg_get_prtpower(otg_dev->core_if));
  53111. +}
  53112. +
  53113. +/**
  53114. + * Set the Bus Power status
  53115. + */
  53116. +static ssize_t buspower_store(struct device *_dev,
  53117. + struct device_attribute *attr,
  53118. + const char *buf, size_t count)
  53119. +{
  53120. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53121. + uint32_t on = simple_strtoul(buf, NULL, 16);
  53122. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  53123. + return count;
  53124. +}
  53125. +
  53126. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  53127. +
  53128. +/**
  53129. + * @todo Need to do more for suspend?
  53130. + */
  53131. +/**
  53132. + * Show the Bus Suspend status
  53133. + */
  53134. +static ssize_t bussuspend_show(struct device *_dev,
  53135. + struct device_attribute *attr, char *buf)
  53136. +{
  53137. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53138. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  53139. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  53140. +}
  53141. +
  53142. +/**
  53143. + * Set the Bus Suspend status
  53144. + */
  53145. +static ssize_t bussuspend_store(struct device *_dev,
  53146. + struct device_attribute *attr,
  53147. + const char *buf, size_t count)
  53148. +{
  53149. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53150. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53151. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  53152. + return count;
  53153. +}
  53154. +
  53155. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  53156. +
  53157. +/**
  53158. + * Show the Mode Change Ready Timer status
  53159. + */
  53160. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  53161. + struct device_attribute *attr, char *buf)
  53162. +{
  53163. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53164. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  53165. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  53166. +}
  53167. +
  53168. +/**
  53169. + * Set the Mode Change Ready Timer status
  53170. + */
  53171. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  53172. + struct device_attribute *attr,
  53173. + const char *buf, size_t count)
  53174. +{
  53175. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53176. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53177. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  53178. + return count;
  53179. +}
  53180. +
  53181. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  53182. +
  53183. +/**
  53184. + * Show the value of HFIR Frame Interval bitfield
  53185. + */
  53186. +static ssize_t fr_interval_show(struct device *_dev,
  53187. + struct device_attribute *attr, char *buf)
  53188. +{
  53189. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53190. + return sprintf(buf, "Frame Interval = 0x%x\n",
  53191. + dwc_otg_get_fr_interval(otg_dev->core_if));
  53192. +}
  53193. +
  53194. +/**
  53195. + * Set the HFIR Frame Interval value
  53196. + */
  53197. +static ssize_t fr_interval_store(struct device *_dev,
  53198. + struct device_attribute *attr,
  53199. + const char *buf, size_t count)
  53200. +{
  53201. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53202. + uint32_t in = simple_strtoul(buf, NULL, 10);
  53203. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  53204. + return count;
  53205. +}
  53206. +
  53207. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  53208. +
  53209. +/**
  53210. + * Show the status of Remote Wakeup.
  53211. + */
  53212. +static ssize_t remote_wakeup_show(struct device *_dev,
  53213. + struct device_attribute *attr, char *buf)
  53214. +{
  53215. +#ifndef DWC_HOST_ONLY
  53216. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53217. +
  53218. + return sprintf(buf,
  53219. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  53220. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  53221. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  53222. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  53223. +#else
  53224. + return sprintf(buf, "Host Only Mode!\n");
  53225. +#endif /* DWC_HOST_ONLY */
  53226. +}
  53227. +
  53228. +/**
  53229. + * Initiate a remote wakeup of the host. The Device control register
  53230. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  53231. + * flag is set.
  53232. + *
  53233. + */
  53234. +static ssize_t remote_wakeup_store(struct device *_dev,
  53235. + struct device_attribute *attr,
  53236. + const char *buf, size_t count)
  53237. +{
  53238. +#ifndef DWC_HOST_ONLY
  53239. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53240. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53241. +
  53242. + if (val & 1) {
  53243. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  53244. + } else {
  53245. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  53246. + }
  53247. +#endif /* DWC_HOST_ONLY */
  53248. + return count;
  53249. +}
  53250. +
  53251. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  53252. + remote_wakeup_store);
  53253. +
  53254. +/**
  53255. + * Show the whether core is hibernated or not.
  53256. + */
  53257. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  53258. + struct device_attribute *attr, char *buf)
  53259. +{
  53260. +#ifndef DWC_HOST_ONLY
  53261. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53262. +
  53263. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  53264. + DWC_PRINTF("Core is in hibernation\n");
  53265. + } else {
  53266. + DWC_PRINTF("Core is not in hibernation\n");
  53267. + }
  53268. +#endif /* DWC_HOST_ONLY */
  53269. + return 0;
  53270. +}
  53271. +
  53272. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  53273. + int rem_wakeup, int reset);
  53274. +
  53275. +/**
  53276. + * Initiate a remote wakeup of the device to exit from hibernation.
  53277. + */
  53278. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  53279. + struct device_attribute *attr,
  53280. + const char *buf, size_t count)
  53281. +{
  53282. +#ifndef DWC_HOST_ONLY
  53283. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53284. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  53285. +#endif
  53286. + return count;
  53287. +}
  53288. +
  53289. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  53290. + rem_wakeup_pwrdn_store);
  53291. +
  53292. +static ssize_t disconnect_us(struct device *_dev,
  53293. + struct device_attribute *attr,
  53294. + const char *buf, size_t count)
  53295. +{
  53296. +
  53297. +#ifndef DWC_HOST_ONLY
  53298. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53299. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53300. + DWC_PRINTF("The Passed value is %04x\n", val);
  53301. +
  53302. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  53303. +
  53304. +#endif /* DWC_HOST_ONLY */
  53305. + return count;
  53306. +}
  53307. +
  53308. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  53309. +
  53310. +/**
  53311. + * Dump global registers and either host or device registers (depending on the
  53312. + * current mode of the core).
  53313. + */
  53314. +static ssize_t regdump_show(struct device *_dev,
  53315. + struct device_attribute *attr, char *buf)
  53316. +{
  53317. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53318. +
  53319. + dwc_otg_dump_global_registers(otg_dev->core_if);
  53320. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  53321. + dwc_otg_dump_host_registers(otg_dev->core_if);
  53322. + } else {
  53323. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  53324. +
  53325. + }
  53326. + return sprintf(buf, "Register Dump\n");
  53327. +}
  53328. +
  53329. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  53330. +
  53331. +/**
  53332. + * Dump global registers and either host or device registers (depending on the
  53333. + * current mode of the core).
  53334. + */
  53335. +static ssize_t spramdump_show(struct device *_dev,
  53336. + struct device_attribute *attr, char *buf)
  53337. +{
  53338. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53339. +
  53340. + //dwc_otg_dump_spram(otg_dev->core_if);
  53341. +
  53342. + return sprintf(buf, "SPRAM Dump\n");
  53343. +}
  53344. +
  53345. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  53346. +
  53347. +/**
  53348. + * Dump the current hcd state.
  53349. + */
  53350. +static ssize_t hcddump_show(struct device *_dev,
  53351. + struct device_attribute *attr, char *buf)
  53352. +{
  53353. +#ifndef DWC_DEVICE_ONLY
  53354. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53355. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  53356. +#endif /* DWC_DEVICE_ONLY */
  53357. + return sprintf(buf, "HCD Dump\n");
  53358. +}
  53359. +
  53360. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  53361. +
  53362. +/**
  53363. + * Dump the average frame remaining at SOF. This can be used to
  53364. + * determine average interrupt latency. Frame remaining is also shown for
  53365. + * start transfer and two additional sample points.
  53366. + */
  53367. +static ssize_t hcd_frrem_show(struct device *_dev,
  53368. + struct device_attribute *attr, char *buf)
  53369. +{
  53370. +#ifndef DWC_DEVICE_ONLY
  53371. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53372. +
  53373. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  53374. +#endif /* DWC_DEVICE_ONLY */
  53375. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  53376. +}
  53377. +
  53378. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  53379. +
  53380. +/**
  53381. + * Displays the time required to read the GNPTXFSIZ register many times (the
  53382. + * output shows the number of times the register is read).
  53383. + */
  53384. +#define RW_REG_COUNT 10000000
  53385. +#define MSEC_PER_JIFFIE 1000/HZ
  53386. +static ssize_t rd_reg_test_show(struct device *_dev,
  53387. + struct device_attribute *attr, char *buf)
  53388. +{
  53389. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53390. + int i;
  53391. + int time;
  53392. + int start_jiffies;
  53393. +
  53394. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  53395. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  53396. + start_jiffies = jiffies;
  53397. + for (i = 0; i < RW_REG_COUNT; i++) {
  53398. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  53399. + }
  53400. + time = jiffies - start_jiffies;
  53401. + return sprintf(buf,
  53402. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  53403. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  53404. +}
  53405. +
  53406. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  53407. +
  53408. +/**
  53409. + * Displays the time required to write the GNPTXFSIZ register many times (the
  53410. + * output shows the number of times the register is written).
  53411. + */
  53412. +static ssize_t wr_reg_test_show(struct device *_dev,
  53413. + struct device_attribute *attr, char *buf)
  53414. +{
  53415. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53416. + uint32_t reg_val;
  53417. + int i;
  53418. + int time;
  53419. + int start_jiffies;
  53420. +
  53421. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  53422. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  53423. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  53424. + start_jiffies = jiffies;
  53425. + for (i = 0; i < RW_REG_COUNT; i++) {
  53426. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  53427. + }
  53428. + time = jiffies - start_jiffies;
  53429. + return sprintf(buf,
  53430. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  53431. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  53432. +}
  53433. +
  53434. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  53435. +
  53436. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53437. +
  53438. +/**
  53439. +* Show the lpm_response attribute.
  53440. +*/
  53441. +static ssize_t lpmresp_show(struct device *_dev,
  53442. + struct device_attribute *attr, char *buf)
  53443. +{
  53444. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53445. +
  53446. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  53447. + return sprintf(buf, "** LPM is DISABLED **\n");
  53448. +
  53449. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  53450. + return sprintf(buf, "** Current mode is not device mode\n");
  53451. + }
  53452. + return sprintf(buf, "lpm_response = %d\n",
  53453. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  53454. +}
  53455. +
  53456. +/**
  53457. +* Store the lpm_response attribute.
  53458. +*/
  53459. +static ssize_t lpmresp_store(struct device *_dev,
  53460. + struct device_attribute *attr,
  53461. + const char *buf, size_t count)
  53462. +{
  53463. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53464. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53465. +
  53466. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  53467. + return 0;
  53468. + }
  53469. +
  53470. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  53471. + return 0;
  53472. + }
  53473. +
  53474. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  53475. + return count;
  53476. +}
  53477. +
  53478. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  53479. +
  53480. +/**
  53481. +* Show the sleep_status attribute.
  53482. +*/
  53483. +static ssize_t sleepstatus_show(struct device *_dev,
  53484. + struct device_attribute *attr, char *buf)
  53485. +{
  53486. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53487. + return sprintf(buf, "Sleep Status = %d\n",
  53488. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  53489. +}
  53490. +
  53491. +/**
  53492. + * Store the sleep_status attribure.
  53493. + */
  53494. +static ssize_t sleepstatus_store(struct device *_dev,
  53495. + struct device_attribute *attr,
  53496. + const char *buf, size_t count)
  53497. +{
  53498. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53499. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  53500. +
  53501. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  53502. + if (dwc_otg_is_host_mode(core_if)) {
  53503. +
  53504. + DWC_PRINTF("Host initiated resume\n");
  53505. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  53506. + }
  53507. + }
  53508. +
  53509. + return count;
  53510. +}
  53511. +
  53512. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  53513. + sleepstatus_store);
  53514. +
  53515. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  53516. +
  53517. +/**@}*/
  53518. +
  53519. +/**
  53520. + * Create the device files
  53521. + */
  53522. +void dwc_otg_attr_create(
  53523. +#ifdef LM_INTERFACE
  53524. + struct lm_device *dev
  53525. +#elif defined(PCI_INTERFACE)
  53526. + struct pci_dev *dev
  53527. +#elif defined(PLATFORM_INTERFACE)
  53528. + struct platform_device *dev
  53529. +#endif
  53530. + )
  53531. +{
  53532. + int error;
  53533. +
  53534. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  53535. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  53536. + error = device_create_file(&dev->dev, &dev_attr_mode);
  53537. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  53538. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  53539. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  53540. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53541. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  53542. + error = device_create_file(&dev->dev, &dev_attr_srp);
  53543. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  53544. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  53545. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53546. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  53547. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  53548. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  53549. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  53550. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  53551. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  53552. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  53553. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  53554. + error = device_create_file(&dev->dev, &dev_attr_guid);
  53555. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  53556. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  53557. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  53558. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  53559. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  53560. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  53561. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53562. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  53563. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  53564. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  53565. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  53566. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  53567. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  53568. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  53569. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53570. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  53571. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  53572. +#endif
  53573. +}
  53574. +
  53575. +/**
  53576. + * Remove the device files
  53577. + */
  53578. +void dwc_otg_attr_remove(
  53579. +#ifdef LM_INTERFACE
  53580. + struct lm_device *dev
  53581. +#elif defined(PCI_INTERFACE)
  53582. + struct pci_dev *dev
  53583. +#elif defined(PLATFORM_INTERFACE)
  53584. + struct platform_device *dev
  53585. +#endif
  53586. + )
  53587. +{
  53588. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  53589. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  53590. + device_remove_file(&dev->dev, &dev_attr_mode);
  53591. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  53592. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  53593. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  53594. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53595. + device_remove_file(&dev->dev, &dev_attr_hnp);
  53596. + device_remove_file(&dev->dev, &dev_attr_srp);
  53597. + device_remove_file(&dev->dev, &dev_attr_buspower);
  53598. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  53599. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53600. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  53601. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  53602. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  53603. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  53604. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  53605. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  53606. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  53607. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  53608. + device_remove_file(&dev->dev, &dev_attr_guid);
  53609. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  53610. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  53611. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  53612. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  53613. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  53614. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  53615. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53616. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  53617. + device_remove_file(&dev->dev, &dev_attr_regdump);
  53618. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  53619. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  53620. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  53621. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  53622. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  53623. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53624. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  53625. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  53626. +#endif
  53627. +}
  53628. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  53629. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  53630. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-03-13 12:46:39.512097981 +0100
  53631. @@ -0,0 +1,89 @@
  53632. +/* ==========================================================================
  53633. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  53634. + * $Revision: #13 $
  53635. + * $Date: 2010/06/21 $
  53636. + * $Change: 1532021 $
  53637. + *
  53638. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53639. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53640. + * otherwise expressly agreed to in writing between Synopsys and you.
  53641. + *
  53642. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53643. + * any End User Software License Agreement or Agreement for Licensed Product
  53644. + * with Synopsys or any supplement thereto. You are permitted to use and
  53645. + * redistribute this Software in source and binary forms, with or without
  53646. + * modification, provided that redistributions of source code must retain this
  53647. + * notice. You may not view, use, disclose, copy or distribute this file or
  53648. + * any information contained herein except pursuant to this license grant from
  53649. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53650. + * below, then you are not authorized to use the Software.
  53651. + *
  53652. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53653. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53654. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53655. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53656. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53657. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53658. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53659. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53660. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53661. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53662. + * DAMAGE.
  53663. + * ========================================================================== */
  53664. +
  53665. +#if !defined(__DWC_OTG_ATTR_H__)
  53666. +#define __DWC_OTG_ATTR_H__
  53667. +
  53668. +/** @file
  53669. + * This file contains the interface to the Linux device attributes.
  53670. + */
  53671. +extern struct device_attribute dev_attr_regoffset;
  53672. +extern struct device_attribute dev_attr_regvalue;
  53673. +
  53674. +extern struct device_attribute dev_attr_mode;
  53675. +extern struct device_attribute dev_attr_hnpcapable;
  53676. +extern struct device_attribute dev_attr_srpcapable;
  53677. +extern struct device_attribute dev_attr_hnp;
  53678. +extern struct device_attribute dev_attr_srp;
  53679. +extern struct device_attribute dev_attr_buspower;
  53680. +extern struct device_attribute dev_attr_bussuspend;
  53681. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  53682. +extern struct device_attribute dev_attr_fr_interval;
  53683. +extern struct device_attribute dev_attr_busconnected;
  53684. +extern struct device_attribute dev_attr_gotgctl;
  53685. +extern struct device_attribute dev_attr_gusbcfg;
  53686. +extern struct device_attribute dev_attr_grxfsiz;
  53687. +extern struct device_attribute dev_attr_gnptxfsiz;
  53688. +extern struct device_attribute dev_attr_gpvndctl;
  53689. +extern struct device_attribute dev_attr_ggpio;
  53690. +extern struct device_attribute dev_attr_guid;
  53691. +extern struct device_attribute dev_attr_gsnpsid;
  53692. +extern struct device_attribute dev_attr_devspeed;
  53693. +extern struct device_attribute dev_attr_enumspeed;
  53694. +extern struct device_attribute dev_attr_hptxfsiz;
  53695. +extern struct device_attribute dev_attr_hprt0;
  53696. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53697. +extern struct device_attribute dev_attr_lpm_response;
  53698. +extern struct device_attribute devi_attr_sleep_status;
  53699. +#endif
  53700. +
  53701. +void dwc_otg_attr_create(
  53702. +#ifdef LM_INTERFACE
  53703. + struct lm_device *dev
  53704. +#elif defined(PCI_INTERFACE)
  53705. + struct pci_dev *dev
  53706. +#elif defined(PLATFORM_INTERFACE)
  53707. + struct platform_device *dev
  53708. +#endif
  53709. + );
  53710. +
  53711. +void dwc_otg_attr_remove(
  53712. +#ifdef LM_INTERFACE
  53713. + struct lm_device *dev
  53714. +#elif defined(PCI_INTERFACE)
  53715. + struct pci_dev *dev
  53716. +#elif defined(PLATFORM_INTERFACE)
  53717. + struct platform_device *dev
  53718. +#endif
  53719. + );
  53720. +#endif
  53721. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  53722. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  53723. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-03-13 12:46:39.512097981 +0100
  53724. @@ -0,0 +1,1876 @@
  53725. +/* ==========================================================================
  53726. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53727. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53728. + * otherwise expressly agreed to in writing between Synopsys and you.
  53729. + *
  53730. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53731. + * any End User Software License Agreement or Agreement for Licensed Product
  53732. + * with Synopsys or any supplement thereto. You are permitted to use and
  53733. + * redistribute this Software in source and binary forms, with or without
  53734. + * modification, provided that redistributions of source code must retain this
  53735. + * notice. You may not view, use, disclose, copy or distribute this file or
  53736. + * any information contained herein except pursuant to this license grant from
  53737. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53738. + * below, then you are not authorized to use the Software.
  53739. + *
  53740. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53741. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53742. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53743. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53744. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53745. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53746. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53747. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53748. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53749. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53750. + * DAMAGE.
  53751. + * ========================================================================== */
  53752. +
  53753. +/** @file
  53754. + *
  53755. + * This file contains the most of the CFI(Core Feature Interface)
  53756. + * implementation for the OTG.
  53757. + */
  53758. +
  53759. +#ifdef DWC_UTE_CFI
  53760. +
  53761. +#include "dwc_otg_pcd.h"
  53762. +#include "dwc_otg_cfi.h"
  53763. +
  53764. +/** This definition should actually migrate to the Portability Library */
  53765. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  53766. +
  53767. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  53768. +
  53769. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  53770. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53771. + struct dwc_otg_pcd *pcd,
  53772. + struct cfi_usb_ctrlrequest *ctrl_req);
  53773. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  53774. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53775. + struct cfi_usb_ctrlrequest *req);
  53776. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53777. + struct cfi_usb_ctrlrequest *req);
  53778. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53779. + struct cfi_usb_ctrlrequest *req);
  53780. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53781. + struct cfi_usb_ctrlrequest *req);
  53782. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  53783. +
  53784. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  53785. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  53786. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  53787. +
  53788. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  53789. +
  53790. +/** This is the header of the all features descriptor */
  53791. +static cfi_all_features_header_t all_props_desc_header = {
  53792. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  53793. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  53794. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  53795. +};
  53796. +
  53797. +/** This is an array of statically allocated feature descriptors */
  53798. +static cfi_feature_desc_header_t prop_descs[] = {
  53799. +
  53800. + /* FT_ID_DMA_MODE */
  53801. + {
  53802. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  53803. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53804. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  53805. + },
  53806. +
  53807. + /* FT_ID_DMA_BUFFER_SETUP */
  53808. + {
  53809. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  53810. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53811. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53812. + },
  53813. +
  53814. + /* FT_ID_DMA_BUFF_ALIGN */
  53815. + {
  53816. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  53817. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53818. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53819. + },
  53820. +
  53821. + /* FT_ID_DMA_CONCAT_SETUP */
  53822. + {
  53823. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  53824. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53825. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53826. + },
  53827. +
  53828. + /* FT_ID_DMA_CIRCULAR */
  53829. + {
  53830. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  53831. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53832. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53833. + },
  53834. +
  53835. + /* FT_ID_THRESHOLD_SETUP */
  53836. + {
  53837. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  53838. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53839. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53840. + },
  53841. +
  53842. + /* FT_ID_DFIFO_DEPTH */
  53843. + {
  53844. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  53845. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  53846. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53847. + },
  53848. +
  53849. + /* FT_ID_TX_FIFO_DEPTH */
  53850. + {
  53851. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  53852. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53853. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53854. + },
  53855. +
  53856. + /* FT_ID_RX_FIFO_DEPTH */
  53857. + {
  53858. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  53859. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53860. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53861. + }
  53862. +};
  53863. +
  53864. +/** The table of feature names */
  53865. +cfi_string_t prop_name_table[] = {
  53866. + {FT_ID_DMA_MODE, "dma_mode"},
  53867. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  53868. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  53869. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  53870. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  53871. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  53872. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  53873. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  53874. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  53875. + {}
  53876. +};
  53877. +
  53878. +/************************************************************************/
  53879. +
  53880. +/**
  53881. + * Returns the name of the feature by its ID
  53882. + * or NULL if no featute ID matches.
  53883. + *
  53884. + */
  53885. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  53886. +{
  53887. + cfi_string_t *pstr;
  53888. + *len = 0;
  53889. +
  53890. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  53891. + if (pstr->id == prop_id) {
  53892. + *len = DWC_STRLEN(pstr->s);
  53893. + return pstr->s;
  53894. + }
  53895. + }
  53896. + return NULL;
  53897. +}
  53898. +
  53899. +/**
  53900. + * This function handles all CFI specific control requests.
  53901. + *
  53902. + * Return a negative value to stall the DCE.
  53903. + */
  53904. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  53905. +{
  53906. + int retval = 0;
  53907. + dwc_otg_pcd_ep_t *ep = NULL;
  53908. + cfiobject_t *cfi = pcd->cfi;
  53909. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53910. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  53911. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  53912. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  53913. + uint32_t regaddr = 0;
  53914. + uint32_t regval = 0;
  53915. +
  53916. + /* Save this Control Request in the CFI object.
  53917. + * The data field will be assigned in the data stage completion CB function.
  53918. + */
  53919. + cfi->ctrl_req = *ctrl;
  53920. + cfi->ctrl_req.data = NULL;
  53921. +
  53922. + cfi->need_gadget_att = 0;
  53923. + cfi->need_status_in_complete = 0;
  53924. +
  53925. + switch (ctrl->bRequest) {
  53926. + case VEN_CORE_GET_FEATURES:
  53927. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  53928. + if (retval >= 0) {
  53929. + //dump_msg(cfi->buf_in.buf, retval);
  53930. + ep = &pcd->ep0;
  53931. +
  53932. + retval = min((uint16_t) retval, wLen);
  53933. + /* Transfer this buffer to the host through the EP0-IN EP */
  53934. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53935. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53936. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53937. + ep->dwc_ep.xfer_len = retval;
  53938. + ep->dwc_ep.xfer_count = 0;
  53939. + ep->dwc_ep.sent_zlp = 0;
  53940. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53941. +
  53942. + pcd->ep0_pending = 1;
  53943. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53944. + }
  53945. + retval = 0;
  53946. + break;
  53947. +
  53948. + case VEN_CORE_GET_FEATURE:
  53949. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  53950. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  53951. + pcd, ctrl);
  53952. + if (retval >= 0) {
  53953. + ep = &pcd->ep0;
  53954. +
  53955. + retval = min((uint16_t) retval, wLen);
  53956. + /* Transfer this buffer to the host through the EP0-IN EP */
  53957. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53958. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53959. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53960. + ep->dwc_ep.xfer_len = retval;
  53961. + ep->dwc_ep.xfer_count = 0;
  53962. + ep->dwc_ep.sent_zlp = 0;
  53963. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53964. +
  53965. + pcd->ep0_pending = 1;
  53966. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53967. + }
  53968. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  53969. + dump_msg(cfi->buf_in.buf, retval);
  53970. + break;
  53971. +
  53972. + case VEN_CORE_SET_FEATURE:
  53973. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  53974. + /* Set up an XFER to get the data stage of the control request,
  53975. + * which is the new value of the feature to be modified.
  53976. + */
  53977. + ep = &pcd->ep0;
  53978. + ep->dwc_ep.is_in = 0;
  53979. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53980. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53981. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53982. + ep->dwc_ep.xfer_len = wLen;
  53983. + ep->dwc_ep.xfer_count = 0;
  53984. + ep->dwc_ep.sent_zlp = 0;
  53985. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53986. +
  53987. + pcd->ep0_pending = 1;
  53988. + /* Read the control write's data stage */
  53989. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53990. + retval = 0;
  53991. + break;
  53992. +
  53993. + case VEN_CORE_RESET_FEATURES:
  53994. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  53995. + cfi->need_gadget_att = 1;
  53996. + cfi->need_status_in_complete = 1;
  53997. + retval = cfi_preproc_reset(pcd, ctrl);
  53998. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  53999. + break;
  54000. +
  54001. + case VEN_CORE_ACTIVATE_FEATURES:
  54002. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  54003. + break;
  54004. +
  54005. + case VEN_CORE_READ_REGISTER:
  54006. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  54007. + /* wValue optionally contains the HI WORD of the register offset and
  54008. + * wIndex contains the LOW WORD of the register offset
  54009. + */
  54010. + if (wValue == 0) {
  54011. + /* @TODO - MAS - fix the access to the base field */
  54012. + regaddr = 0;
  54013. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  54014. + //GET_CORE_IF(pcd)->co
  54015. + regaddr |= wIndex;
  54016. + } else {
  54017. + regaddr = (wValue << 16) | wIndex;
  54018. + }
  54019. +
  54020. + /* Read a 32-bit value of the memory at the regaddr */
  54021. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  54022. +
  54023. + ep = &pcd->ep0;
  54024. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  54025. + ep->dwc_ep.is_in = 1;
  54026. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54027. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54028. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54029. + ep->dwc_ep.xfer_len = wLen;
  54030. + ep->dwc_ep.xfer_count = 0;
  54031. + ep->dwc_ep.sent_zlp = 0;
  54032. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54033. +
  54034. + pcd->ep0_pending = 1;
  54035. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54036. + cfi->need_gadget_att = 0;
  54037. + retval = 0;
  54038. + break;
  54039. +
  54040. + case VEN_CORE_WRITE_REGISTER:
  54041. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  54042. + /* Set up an XFER to get the data stage of the control request,
  54043. + * which is the new value of the register to be modified.
  54044. + */
  54045. + ep = &pcd->ep0;
  54046. + ep->dwc_ep.is_in = 0;
  54047. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54048. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54049. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54050. + ep->dwc_ep.xfer_len = wLen;
  54051. + ep->dwc_ep.xfer_count = 0;
  54052. + ep->dwc_ep.sent_zlp = 0;
  54053. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54054. +
  54055. + pcd->ep0_pending = 1;
  54056. + /* Read the control write's data stage */
  54057. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54058. + retval = 0;
  54059. + break;
  54060. +
  54061. + default:
  54062. + retval = -DWC_E_NOT_SUPPORTED;
  54063. + break;
  54064. + }
  54065. +
  54066. + return retval;
  54067. +}
  54068. +
  54069. +/**
  54070. + * This function prepares the core features descriptors and copies its
  54071. + * raw representation into the buffer <buf>.
  54072. + *
  54073. + * The buffer structure is as follows:
  54074. + * all_features_header (8 bytes)
  54075. + * features_#1 (8 bytes + feature name string length)
  54076. + * features_#2 (8 bytes + feature name string length)
  54077. + * .....
  54078. + * features_#n - where n=the total count of feature descriptors
  54079. + */
  54080. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  54081. +{
  54082. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  54083. + cfi_feature_desc_header_t *prop;
  54084. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  54085. + cfi_all_features_header_t *tmp;
  54086. + uint8_t *tmpbuf = buf;
  54087. + const uint8_t *pname = NULL;
  54088. + int i, j, namelen = 0, totlen;
  54089. +
  54090. + /* Prepare and copy the core features into the buffer */
  54091. + CFI_INFO("%s:\n", __func__);
  54092. +
  54093. + tmp = (cfi_all_features_header_t *) tmpbuf;
  54094. + *tmp = *all_props_hdr;
  54095. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  54096. +
  54097. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  54098. + for (i = 0; i < j; i++, prop_hdr++) {
  54099. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  54100. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  54101. + *prop = *prop_hdr;
  54102. +
  54103. + prop->bNameLen = namelen;
  54104. + prop->wLength =
  54105. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  54106. + namelen);
  54107. +
  54108. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  54109. + dwc_memcpy(tmpbuf, pname, namelen);
  54110. + tmpbuf += namelen;
  54111. + }
  54112. +
  54113. + totlen = tmpbuf - buf;
  54114. +
  54115. + if (totlen > 0) {
  54116. + tmp = (cfi_all_features_header_t *) buf;
  54117. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  54118. + }
  54119. +
  54120. + return totlen;
  54121. +}
  54122. +
  54123. +/**
  54124. + * This function releases all the dynamic memory in the CFI object.
  54125. + */
  54126. +static void cfi_release(cfiobject_t * cfiobj)
  54127. +{
  54128. + cfi_ep_t *cfiep;
  54129. + dwc_list_link_t *tmp;
  54130. +
  54131. + CFI_INFO("%s\n", __func__);
  54132. +
  54133. + if (cfiobj->buf_in.buf) {
  54134. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  54135. + cfiobj->buf_in.addr);
  54136. + cfiobj->buf_in.buf = NULL;
  54137. + }
  54138. +
  54139. + if (cfiobj->buf_out.buf) {
  54140. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  54141. + cfiobj->buf_out.addr);
  54142. + cfiobj->buf_out.buf = NULL;
  54143. + }
  54144. +
  54145. + /* Free the Buffer Setup values for each EP */
  54146. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  54147. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  54148. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54149. + cfi_free_ep_bs_dyn_data(cfiep);
  54150. + }
  54151. +}
  54152. +
  54153. +/**
  54154. + * This function frees the dynamically allocated EP buffer setup data.
  54155. + */
  54156. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  54157. +{
  54158. + if (cfiep->bm_sg) {
  54159. + DWC_FREE(cfiep->bm_sg);
  54160. + cfiep->bm_sg = NULL;
  54161. + }
  54162. +
  54163. + if (cfiep->bm_align) {
  54164. + DWC_FREE(cfiep->bm_align);
  54165. + cfiep->bm_align = NULL;
  54166. + }
  54167. +
  54168. + if (cfiep->bm_concat) {
  54169. + if (NULL != cfiep->bm_concat->wTxBytes) {
  54170. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54171. + cfiep->bm_concat->wTxBytes = NULL;
  54172. + }
  54173. + DWC_FREE(cfiep->bm_concat);
  54174. + cfiep->bm_concat = NULL;
  54175. + }
  54176. +}
  54177. +
  54178. +/**
  54179. + * This function initializes the default values of the features
  54180. + * for a specific endpoint and should be called only once when
  54181. + * the EP is enabled first time.
  54182. + */
  54183. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  54184. +{
  54185. + int retval = 0;
  54186. +
  54187. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  54188. + if (NULL == cfiep->bm_sg) {
  54189. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  54190. + return -DWC_E_NO_MEMORY;
  54191. + }
  54192. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54193. +
  54194. + /* For the Concatenation feature's default value we do not allocate
  54195. + * memory for the wTxBytes field - it will be done in the set_feature_value
  54196. + * request handler.
  54197. + */
  54198. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  54199. + if (NULL == cfiep->bm_concat) {
  54200. + CFI_INFO
  54201. + ("Failed to allocate memory for CONCATENATION feature value\n");
  54202. + DWC_FREE(cfiep->bm_sg);
  54203. + return -DWC_E_NO_MEMORY;
  54204. + }
  54205. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54206. +
  54207. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  54208. + if (NULL == cfiep->bm_align) {
  54209. + CFI_INFO
  54210. + ("Failed to allocate memory for Alignment feature value\n");
  54211. + DWC_FREE(cfiep->bm_sg);
  54212. + DWC_FREE(cfiep->bm_concat);
  54213. + return -DWC_E_NO_MEMORY;
  54214. + }
  54215. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  54216. +
  54217. + return retval;
  54218. +}
  54219. +
  54220. +/**
  54221. + * The callback function that notifies the CFI on the activation of
  54222. + * an endpoint in the PCD. The following steps are done in this function:
  54223. + *
  54224. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  54225. + * active endpoint)
  54226. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  54227. + * Set the Buffer Mode to standard
  54228. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  54229. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  54230. + */
  54231. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54232. + struct dwc_otg_pcd_ep *ep)
  54233. +{
  54234. + cfi_ep_t *cfiep;
  54235. + int retval = -DWC_E_NOT_SUPPORTED;
  54236. +
  54237. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  54238. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  54239. + /* MAS - Check whether this endpoint already is in the list */
  54240. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  54241. +
  54242. + if (NULL == cfiep) {
  54243. + /* Allocate a cfi_ep_t object */
  54244. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  54245. + if (NULL == cfiep) {
  54246. + CFI_INFO
  54247. + ("Unable to allocate memory for <cfiep> in function %s\n",
  54248. + __func__);
  54249. + return -DWC_E_NO_MEMORY;
  54250. + }
  54251. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  54252. +
  54253. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  54254. + cfiep->ep = ep;
  54255. +
  54256. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  54257. + ep->dwc_ep.descs =
  54258. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  54259. + sizeof(dwc_otg_dma_desc_t),
  54260. + &ep->dwc_ep.descs_dma_addr);
  54261. +
  54262. + if (NULL == ep->dwc_ep.descs) {
  54263. + DWC_FREE(cfiep);
  54264. + return -DWC_E_NO_MEMORY;
  54265. + }
  54266. +
  54267. + DWC_LIST_INIT(&cfiep->lh);
  54268. +
  54269. + /* Set the buffer mode to BM_STANDARD. It will be modified
  54270. + * when building descriptors for a specific buffer mode */
  54271. + ep->dwc_ep.buff_mode = BM_STANDARD;
  54272. +
  54273. + /* Create and initialize the default values for this EP's Buffer modes */
  54274. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  54275. + return retval;
  54276. +
  54277. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  54278. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  54279. + retval = 0;
  54280. + } else { /* The sought EP already is in the list */
  54281. + CFI_INFO("%s: The sought EP already is in the list\n",
  54282. + __func__);
  54283. + }
  54284. +
  54285. + return retval;
  54286. +}
  54287. +
  54288. +/**
  54289. + * This function is called when the data stage of a 3-stage Control Write request
  54290. + * is complete.
  54291. + *
  54292. + */
  54293. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  54294. + struct dwc_otg_pcd *pcd)
  54295. +{
  54296. + uint32_t addr, reg_value;
  54297. + uint16_t wIndex, wValue;
  54298. + uint8_t bRequest;
  54299. + uint8_t *buf = cfi->buf_out.buf;
  54300. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  54301. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  54302. + int retval = -DWC_E_NOT_SUPPORTED;
  54303. +
  54304. + CFI_INFO("%s\n", __func__);
  54305. +
  54306. + bRequest = ctrl_req->bRequest;
  54307. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  54308. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  54309. +
  54310. + /*
  54311. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  54312. + * The request should be already saved in the command stage by now.
  54313. + */
  54314. + ctrl_req->data = cfi->buf_out.buf;
  54315. + cfi->need_status_in_complete = 0;
  54316. + cfi->need_gadget_att = 0;
  54317. +
  54318. + switch (bRequest) {
  54319. + case VEN_CORE_WRITE_REGISTER:
  54320. + /* The buffer contains raw data of the new value for the register */
  54321. + reg_value = *((uint32_t *) buf);
  54322. + if (wValue == 0) {
  54323. + addr = 0;
  54324. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  54325. + addr += wIndex;
  54326. + } else {
  54327. + addr = (wValue << 16) | wIndex;
  54328. + }
  54329. +
  54330. + //writel(reg_value, addr);
  54331. +
  54332. + retval = 0;
  54333. + cfi->need_status_in_complete = 1;
  54334. + break;
  54335. +
  54336. + case VEN_CORE_SET_FEATURE:
  54337. + /* The buffer contains raw data of the new value of the feature */
  54338. + retval = cfi_set_feature_value(pcd);
  54339. + if (retval < 0)
  54340. + return retval;
  54341. +
  54342. + cfi->need_status_in_complete = 1;
  54343. + break;
  54344. +
  54345. + default:
  54346. + break;
  54347. + }
  54348. +
  54349. + return retval;
  54350. +}
  54351. +
  54352. +/**
  54353. + * This function builds the DMA descriptors for the SG buffer mode.
  54354. + */
  54355. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54356. + dwc_otg_pcd_request_t * req)
  54357. +{
  54358. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54359. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  54360. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54361. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  54362. + dma_addr_t buff_addr = req->dma;
  54363. + int i;
  54364. + uint32_t txsize, off;
  54365. +
  54366. + txsize = sgval->wSize;
  54367. + off = sgval->bOffset;
  54368. +
  54369. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  54370. +// __func__, cfiep->ep->ep.name, txsize, off);
  54371. +
  54372. + for (i = 0; i < sgval->bCount; i++) {
  54373. + desc->status.b.bs = BS_HOST_BUSY;
  54374. + desc->buf = buff_addr;
  54375. + desc->status.b.l = 0;
  54376. + desc->status.b.ioc = 0;
  54377. + desc->status.b.sp = 0;
  54378. + desc->status.b.bytes = txsize;
  54379. + desc->status.b.bs = BS_HOST_READY;
  54380. +
  54381. + /* Set the next address of the buffer */
  54382. + buff_addr += txsize + off;
  54383. + desc_last = desc;
  54384. + desc++;
  54385. + }
  54386. +
  54387. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  54388. + desc_last->status.b.l = 1;
  54389. + desc_last->status.b.ioc = 1;
  54390. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  54391. + /* Save the last DMA descriptor pointer */
  54392. + cfiep->dma_desc_last = desc_last;
  54393. + cfiep->desc_count = sgval->bCount;
  54394. +}
  54395. +
  54396. +/**
  54397. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  54398. + */
  54399. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54400. + dwc_otg_pcd_request_t * req)
  54401. +{
  54402. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54403. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  54404. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54405. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  54406. + dma_addr_t buff_addr = req->dma;
  54407. + int i;
  54408. + uint16_t *txsize;
  54409. +
  54410. + txsize = concatval->wTxBytes;
  54411. +
  54412. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  54413. + desc->buf = buff_addr;
  54414. + desc->status.b.bs = BS_HOST_BUSY;
  54415. + desc->status.b.l = 0;
  54416. + desc->status.b.ioc = 0;
  54417. + desc->status.b.sp = 0;
  54418. + desc->status.b.bytes = *txsize;
  54419. + desc->status.b.bs = BS_HOST_READY;
  54420. +
  54421. + txsize++;
  54422. + /* Set the next address of the buffer */
  54423. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  54424. + desc_last = desc;
  54425. + desc++;
  54426. + }
  54427. +
  54428. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  54429. + desc_last->status.b.l = 1;
  54430. + desc_last->status.b.ioc = 1;
  54431. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  54432. + cfiep->dma_desc_last = desc_last;
  54433. + cfiep->desc_count = concatval->hdr.bDescCount;
  54434. +}
  54435. +
  54436. +/**
  54437. + * This function builds the DMA descriptors for the Circular buffer mode
  54438. + */
  54439. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54440. + dwc_otg_pcd_request_t * req)
  54441. +{
  54442. + /* @todo: MAS - add implementation when this feature needs to be tested */
  54443. +}
  54444. +
  54445. +/**
  54446. + * This function builds the DMA descriptors for the Alignment buffer mode
  54447. + */
  54448. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54449. + dwc_otg_pcd_request_t * req)
  54450. +{
  54451. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54452. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  54453. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54454. + dma_addr_t buff_addr = req->dma;
  54455. +
  54456. + desc->status.b.bs = BS_HOST_BUSY;
  54457. + desc->status.b.l = 1;
  54458. + desc->status.b.ioc = 1;
  54459. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  54460. + desc->status.b.bytes = req->length;
  54461. + /* Adjust the buffer alignment */
  54462. + desc->buf = (buff_addr + alignval->bAlign);
  54463. + desc->status.b.bs = BS_HOST_READY;
  54464. + cfiep->dma_desc_last = desc;
  54465. + cfiep->desc_count = 1;
  54466. +}
  54467. +
  54468. +/**
  54469. + * This function builds the DMA descriptors chain for different modes of the
  54470. + * buffer setup of an endpoint.
  54471. + */
  54472. +static void cfi_build_descriptors(struct cfiobject *cfi,
  54473. + struct dwc_otg_pcd *pcd,
  54474. + struct dwc_otg_pcd_ep *ep,
  54475. + dwc_otg_pcd_request_t * req)
  54476. +{
  54477. + cfi_ep_t *cfiep;
  54478. +
  54479. + /* Get the cfiep by the dwc_otg_pcd_ep */
  54480. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  54481. + if (NULL == cfiep) {
  54482. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  54483. + __func__);
  54484. + return;
  54485. + }
  54486. +
  54487. + cfiep->xfer_len = req->length;
  54488. +
  54489. + /* Iterate through all the DMA descriptors */
  54490. + switch (cfiep->ep->dwc_ep.buff_mode) {
  54491. + case BM_SG:
  54492. + cfi_build_sg_descs(cfi, cfiep, req);
  54493. + break;
  54494. +
  54495. + case BM_CONCAT:
  54496. + cfi_build_concat_descs(cfi, cfiep, req);
  54497. + break;
  54498. +
  54499. + case BM_CIRCULAR:
  54500. + cfi_build_circ_descs(cfi, cfiep, req);
  54501. + break;
  54502. +
  54503. + case BM_ALIGN:
  54504. + cfi_build_align_descs(cfi, cfiep, req);
  54505. + break;
  54506. +
  54507. + default:
  54508. + break;
  54509. + }
  54510. +}
  54511. +
  54512. +/**
  54513. + * Allocate DMA buffer for different Buffer modes.
  54514. + */
  54515. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54516. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  54517. + unsigned size, gfp_t flags)
  54518. +{
  54519. + return DWC_DMA_ALLOC(size, dma);
  54520. +}
  54521. +
  54522. +/**
  54523. + * This function initializes the CFI object.
  54524. + */
  54525. +int init_cfi(cfiobject_t * cfiobj)
  54526. +{
  54527. + CFI_INFO("%s\n", __func__);
  54528. +
  54529. + /* Allocate a buffer for IN XFERs */
  54530. + cfiobj->buf_in.buf =
  54531. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  54532. + if (NULL == cfiobj->buf_in.buf) {
  54533. + CFI_INFO("Unable to allocate buffer for INs\n");
  54534. + return -DWC_E_NO_MEMORY;
  54535. + }
  54536. +
  54537. + /* Allocate a buffer for OUT XFERs */
  54538. + cfiobj->buf_out.buf =
  54539. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  54540. + if (NULL == cfiobj->buf_out.buf) {
  54541. + CFI_INFO("Unable to allocate buffer for OUT\n");
  54542. + return -DWC_E_NO_MEMORY;
  54543. + }
  54544. +
  54545. + /* Initialize the callback function pointers */
  54546. + cfiobj->ops.release = cfi_release;
  54547. + cfiobj->ops.ep_enable = cfi_ep_enable;
  54548. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  54549. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  54550. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  54551. +
  54552. + /* Initialize the list of active endpoints in the CFI object */
  54553. + DWC_LIST_INIT(&cfiobj->active_eps);
  54554. +
  54555. + return 0;
  54556. +}
  54557. +
  54558. +/**
  54559. + * This function reads the required feature's current value into the buffer
  54560. + *
  54561. + * @retval: Returns negative as error, or the data length of the feature
  54562. + */
  54563. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  54564. + struct dwc_otg_pcd *pcd,
  54565. + struct cfi_usb_ctrlrequest *ctrl_req)
  54566. +{
  54567. + int retval = -DWC_E_NOT_SUPPORTED;
  54568. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  54569. + uint16_t dfifo, rxfifo, txfifo;
  54570. +
  54571. + switch (ctrl_req->wIndex) {
  54572. + /* Whether the DDMA is enabled or not */
  54573. + case FT_ID_DMA_MODE:
  54574. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  54575. + retval = 1;
  54576. + break;
  54577. +
  54578. + case FT_ID_DMA_BUFFER_SETUP:
  54579. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  54580. + break;
  54581. +
  54582. + case FT_ID_DMA_BUFF_ALIGN:
  54583. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  54584. + break;
  54585. +
  54586. + case FT_ID_DMA_CONCAT_SETUP:
  54587. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  54588. + break;
  54589. +
  54590. + case FT_ID_DMA_CIRCULAR:
  54591. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  54592. + break;
  54593. +
  54594. + case FT_ID_THRESHOLD_SETUP:
  54595. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  54596. + break;
  54597. +
  54598. + case FT_ID_DFIFO_DEPTH:
  54599. + dfifo = get_dfifo_size(coreif);
  54600. + *((uint16_t *) buf) = dfifo;
  54601. + retval = sizeof(uint16_t);
  54602. + break;
  54603. +
  54604. + case FT_ID_TX_FIFO_DEPTH:
  54605. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  54606. + if (retval >= 0) {
  54607. + txfifo = retval;
  54608. + *((uint16_t *) buf) = txfifo;
  54609. + retval = sizeof(uint16_t);
  54610. + }
  54611. + break;
  54612. +
  54613. + case FT_ID_RX_FIFO_DEPTH:
  54614. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  54615. + if (retval >= 0) {
  54616. + rxfifo = retval;
  54617. + *((uint16_t *) buf) = rxfifo;
  54618. + retval = sizeof(uint16_t);
  54619. + }
  54620. + break;
  54621. + }
  54622. +
  54623. + return retval;
  54624. +}
  54625. +
  54626. +/**
  54627. + * This function resets the SG for the specified EP to its default value
  54628. + */
  54629. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  54630. +{
  54631. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54632. + return 0;
  54633. +}
  54634. +
  54635. +/**
  54636. + * This function resets the Alignment for the specified EP to its default value
  54637. + */
  54638. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  54639. +{
  54640. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54641. + return 0;
  54642. +}
  54643. +
  54644. +/**
  54645. + * This function resets the Concatenation for the specified EP to its default value
  54646. + * This function will also set the value of the wTxBytes field to NULL after
  54647. + * freeing the memory previously allocated for this field.
  54648. + */
  54649. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  54650. +{
  54651. + /* First we need to free the wTxBytes field */
  54652. + if (cfiep->bm_concat->wTxBytes) {
  54653. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54654. + cfiep->bm_concat->wTxBytes = NULL;
  54655. + }
  54656. +
  54657. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54658. + return 0;
  54659. +}
  54660. +
  54661. +/**
  54662. + * This function resets all the buffer setups of the specified endpoint
  54663. + */
  54664. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  54665. +{
  54666. + cfi_reset_sg_val(cfiep);
  54667. + cfi_reset_align_val(cfiep);
  54668. + cfi_reset_concat_val(cfiep);
  54669. + return 0;
  54670. +}
  54671. +
  54672. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  54673. + uint8_t rx_rst, uint8_t tx_rst)
  54674. +{
  54675. + int retval = -DWC_E_INVALID;
  54676. + uint16_t tx_siz[15];
  54677. + uint16_t rx_siz = 0;
  54678. + dwc_otg_pcd_ep_t *ep = NULL;
  54679. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  54680. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54681. +
  54682. + if (rx_rst) {
  54683. + rx_siz = params->dev_rx_fifo_size;
  54684. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  54685. + }
  54686. +
  54687. + if (tx_rst) {
  54688. + if (ep_addr == 0) {
  54689. + int i;
  54690. +
  54691. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54692. + tx_siz[i] =
  54693. + core_if->core_params->dev_tx_fifo_size[i];
  54694. + core_if->core_params->dev_tx_fifo_size[i] =
  54695. + core_if->init_txfsiz[i];
  54696. + }
  54697. + } else {
  54698. +
  54699. + ep = get_ep_by_addr(pcd, ep_addr);
  54700. +
  54701. + if (NULL == ep) {
  54702. + CFI_INFO
  54703. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  54704. + __func__, ep_addr);
  54705. + return -DWC_E_INVALID;
  54706. + }
  54707. +
  54708. + tx_siz[0] =
  54709. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  54710. + 1];
  54711. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  54712. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  54713. + dwc_ep.tx_fifo_num -
  54714. + 1];
  54715. + }
  54716. + }
  54717. +
  54718. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54719. + retval = 0;
  54720. + } else {
  54721. + CFI_INFO
  54722. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  54723. + __func__);
  54724. + if (rx_rst) {
  54725. + params->dev_rx_fifo_size = rx_siz;
  54726. + }
  54727. +
  54728. + if (tx_rst) {
  54729. + if (ep_addr == 0) {
  54730. + int i;
  54731. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  54732. + i++) {
  54733. + core_if->
  54734. + core_params->dev_tx_fifo_size[i] =
  54735. + tx_siz[i];
  54736. + }
  54737. + } else {
  54738. + params->dev_tx_fifo_size[ep->
  54739. + dwc_ep.tx_fifo_num -
  54740. + 1] = tx_siz[0];
  54741. + }
  54742. + }
  54743. + retval = -DWC_E_INVALID;
  54744. + }
  54745. + return retval;
  54746. +}
  54747. +
  54748. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  54749. +{
  54750. + int retval = 0;
  54751. + cfi_ep_t *cfiep;
  54752. + cfiobject_t *cfi = pcd->cfi;
  54753. + dwc_list_link_t *tmp;
  54754. +
  54755. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  54756. + if (retval < 0) {
  54757. + return retval;
  54758. + }
  54759. +
  54760. + /* If the EP address is known then reset the features for only that EP */
  54761. + if (addr) {
  54762. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54763. + if (NULL == cfiep) {
  54764. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54765. + __func__, addr);
  54766. + return -DWC_E_INVALID;
  54767. + }
  54768. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54769. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54770. + }
  54771. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54772. + else {
  54773. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54774. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54775. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54776. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54777. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54778. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54779. + if (retval < 0) {
  54780. + CFI_INFO
  54781. + ("%s: Error resetting the feature Reset All\n",
  54782. + __func__);
  54783. + return retval;
  54784. + }
  54785. + }
  54786. + }
  54787. + return retval;
  54788. +}
  54789. +
  54790. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  54791. + uint8_t addr)
  54792. +{
  54793. + int retval = 0;
  54794. + cfi_ep_t *cfiep;
  54795. + cfiobject_t *cfi = pcd->cfi;
  54796. + dwc_list_link_t *tmp;
  54797. +
  54798. + /* If the EP address is known then reset the features for only that EP */
  54799. + if (addr) {
  54800. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54801. + if (NULL == cfiep) {
  54802. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54803. + __func__, addr);
  54804. + return -DWC_E_INVALID;
  54805. + }
  54806. + retval = cfi_reset_sg_val(cfiep);
  54807. + }
  54808. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54809. + else {
  54810. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54811. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54812. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54813. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54814. + retval = cfi_reset_sg_val(cfiep);
  54815. + if (retval < 0) {
  54816. + CFI_INFO
  54817. + ("%s: Error resetting the feature Buffer Setup\n",
  54818. + __func__);
  54819. + return retval;
  54820. + }
  54821. + }
  54822. + }
  54823. + return retval;
  54824. +}
  54825. +
  54826. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54827. +{
  54828. + int retval = 0;
  54829. + cfi_ep_t *cfiep;
  54830. + cfiobject_t *cfi = pcd->cfi;
  54831. + dwc_list_link_t *tmp;
  54832. +
  54833. + /* If the EP address is known then reset the features for only that EP */
  54834. + if (addr) {
  54835. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54836. + if (NULL == cfiep) {
  54837. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54838. + __func__, addr);
  54839. + return -DWC_E_INVALID;
  54840. + }
  54841. + retval = cfi_reset_concat_val(cfiep);
  54842. + }
  54843. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54844. + else {
  54845. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54846. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54847. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54848. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54849. + retval = cfi_reset_concat_val(cfiep);
  54850. + if (retval < 0) {
  54851. + CFI_INFO
  54852. + ("%s: Error resetting the feature Concatenation Value\n",
  54853. + __func__);
  54854. + return retval;
  54855. + }
  54856. + }
  54857. + }
  54858. + return retval;
  54859. +}
  54860. +
  54861. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54862. +{
  54863. + int retval = 0;
  54864. + cfi_ep_t *cfiep;
  54865. + cfiobject_t *cfi = pcd->cfi;
  54866. + dwc_list_link_t *tmp;
  54867. +
  54868. + /* If the EP address is known then reset the features for only that EP */
  54869. + if (addr) {
  54870. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54871. + if (NULL == cfiep) {
  54872. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54873. + __func__, addr);
  54874. + return -DWC_E_INVALID;
  54875. + }
  54876. + retval = cfi_reset_align_val(cfiep);
  54877. + }
  54878. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54879. + else {
  54880. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54881. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54882. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54883. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54884. + retval = cfi_reset_align_val(cfiep);
  54885. + if (retval < 0) {
  54886. + CFI_INFO
  54887. + ("%s: Error resetting the feature Aliignment Value\n",
  54888. + __func__);
  54889. + return retval;
  54890. + }
  54891. + }
  54892. + }
  54893. + return retval;
  54894. +
  54895. +}
  54896. +
  54897. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  54898. + struct cfi_usb_ctrlrequest *req)
  54899. +{
  54900. + int retval = 0;
  54901. +
  54902. + switch (req->wIndex) {
  54903. + case 0:
  54904. + /* Reset all features */
  54905. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  54906. + break;
  54907. +
  54908. + case FT_ID_DMA_BUFFER_SETUP:
  54909. + /* Reset the SG buffer setup */
  54910. + retval =
  54911. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  54912. + break;
  54913. +
  54914. + case FT_ID_DMA_CONCAT_SETUP:
  54915. + /* Reset the Concatenation buffer setup */
  54916. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  54917. + break;
  54918. +
  54919. + case FT_ID_DMA_BUFF_ALIGN:
  54920. + /* Reset the Alignment buffer setup */
  54921. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  54922. + break;
  54923. +
  54924. + case FT_ID_TX_FIFO_DEPTH:
  54925. + retval =
  54926. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  54927. + pcd->cfi->need_gadget_att = 0;
  54928. + break;
  54929. +
  54930. + case FT_ID_RX_FIFO_DEPTH:
  54931. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  54932. + pcd->cfi->need_gadget_att = 0;
  54933. + break;
  54934. + default:
  54935. + break;
  54936. + }
  54937. + return retval;
  54938. +}
  54939. +
  54940. +/**
  54941. + * This function sets a new value for the SG buffer setup.
  54942. + */
  54943. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54944. +{
  54945. + uint8_t inaddr, outaddr;
  54946. + cfi_ep_t *epin, *epout;
  54947. + ddma_sg_buffer_setup_t *psgval;
  54948. + uint32_t desccount, size;
  54949. +
  54950. + CFI_INFO("%s\n", __func__);
  54951. +
  54952. + psgval = (ddma_sg_buffer_setup_t *) buf;
  54953. + desccount = (uint32_t) psgval->bCount;
  54954. + size = (uint32_t) psgval->wSize;
  54955. +
  54956. + /* Check the DMA descriptor count */
  54957. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  54958. + CFI_INFO
  54959. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  54960. + __func__, MAX_DMA_DESCS_PER_EP);
  54961. + return -DWC_E_INVALID;
  54962. + }
  54963. +
  54964. + /* Check the DMA descriptor count */
  54965. +
  54966. + if (size == 0) {
  54967. +
  54968. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  54969. + __func__);
  54970. +
  54971. + return -DWC_E_INVALID;
  54972. +
  54973. + }
  54974. +
  54975. + inaddr = psgval->bInEndpointAddress;
  54976. + outaddr = psgval->bOutEndpointAddress;
  54977. +
  54978. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  54979. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  54980. +
  54981. + if (NULL == epin || NULL == epout) {
  54982. + CFI_INFO
  54983. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  54984. + __func__, inaddr, outaddr);
  54985. + return -DWC_E_INVALID;
  54986. + }
  54987. +
  54988. + epin->ep->dwc_ep.buff_mode = BM_SG;
  54989. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54990. +
  54991. + epout->ep->dwc_ep.buff_mode = BM_SG;
  54992. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54993. +
  54994. + return 0;
  54995. +}
  54996. +
  54997. +/**
  54998. + * This function sets a new value for the buffer Alignment setup.
  54999. + */
  55000. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55001. +{
  55002. + cfi_ep_t *ep;
  55003. + uint8_t addr;
  55004. + ddma_align_buffer_setup_t *palignval;
  55005. +
  55006. + palignval = (ddma_align_buffer_setup_t *) buf;
  55007. + addr = palignval->bEndpointAddress;
  55008. +
  55009. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55010. +
  55011. + if (NULL == ep) {
  55012. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55013. + __func__, addr);
  55014. + return -DWC_E_INVALID;
  55015. + }
  55016. +
  55017. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  55018. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  55019. +
  55020. + return 0;
  55021. +}
  55022. +
  55023. +/**
  55024. + * This function sets a new value for the Concatenation buffer setup.
  55025. + */
  55026. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55027. +{
  55028. + uint8_t addr;
  55029. + cfi_ep_t *ep;
  55030. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  55031. + uint16_t *pVals;
  55032. + uint32_t desccount;
  55033. + int i;
  55034. + uint16_t mps;
  55035. +
  55036. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  55037. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  55038. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  55039. +
  55040. + /* Check the DMA descriptor count */
  55041. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  55042. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  55043. + __func__, MAX_DMA_DESCS_PER_EP);
  55044. + return -DWC_E_INVALID;
  55045. + }
  55046. +
  55047. + addr = pConcatValHdr->bEndpointAddress;
  55048. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55049. + if (NULL == ep) {
  55050. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55051. + __func__, addr);
  55052. + return -DWC_E_INVALID;
  55053. + }
  55054. +
  55055. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  55056. +
  55057. +#if 0
  55058. + for (i = 0; i < desccount; i++) {
  55059. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  55060. + }
  55061. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  55062. +#endif
  55063. +
  55064. + /* Check the wTxSizes to be less than or equal to the mps */
  55065. + for (i = 0; i < desccount; i++) {
  55066. + if (pVals[i] > mps) {
  55067. + CFI_INFO
  55068. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  55069. + __func__, i, pVals[i]);
  55070. + return -DWC_E_INVALID;
  55071. + }
  55072. + }
  55073. +
  55074. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  55075. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  55076. +
  55077. + /* Free the previously allocated storage for the wTxBytes */
  55078. + if (ep->bm_concat->wTxBytes) {
  55079. + DWC_FREE(ep->bm_concat->wTxBytes);
  55080. + }
  55081. +
  55082. + /* Allocate a new storage for the wTxBytes field */
  55083. + ep->bm_concat->wTxBytes =
  55084. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55085. + if (NULL == ep->bm_concat->wTxBytes) {
  55086. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  55087. + return -DWC_E_NO_MEMORY;
  55088. + }
  55089. +
  55090. + /* Copy the new values into the wTxBytes filed */
  55091. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  55092. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55093. +
  55094. + return 0;
  55095. +}
  55096. +
  55097. +/**
  55098. + * This function calculates the total of all FIFO sizes
  55099. + *
  55100. + * @param core_if Programming view of DWC_otg controller
  55101. + *
  55102. + * @return The total of data FIFO sizes.
  55103. + *
  55104. + */
  55105. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  55106. +{
  55107. + dwc_otg_core_params_t *params = core_if->core_params;
  55108. + uint16_t dfifo_total = 0;
  55109. + int i;
  55110. +
  55111. + /* The shared RxFIFO size */
  55112. + dfifo_total =
  55113. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55114. +
  55115. + /* Add up each TxFIFO size to the total */
  55116. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55117. + dfifo_total += params->dev_tx_fifo_size[i];
  55118. + }
  55119. +
  55120. + return dfifo_total;
  55121. +}
  55122. +
  55123. +/**
  55124. + * This function returns Rx FIFO size
  55125. + *
  55126. + * @param core_if Programming view of DWC_otg controller
  55127. + *
  55128. + * @return The total of data FIFO sizes.
  55129. + *
  55130. + */
  55131. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  55132. +{
  55133. + switch (wValue >> 8) {
  55134. + case 0:
  55135. + return (core_if->pwron_rxfsiz <
  55136. + 32768) ? core_if->pwron_rxfsiz : 32768;
  55137. + break;
  55138. + case 1:
  55139. + return core_if->core_params->dev_rx_fifo_size;
  55140. + break;
  55141. + default:
  55142. + return -DWC_E_INVALID;
  55143. + break;
  55144. + }
  55145. +}
  55146. +
  55147. +/**
  55148. + * This function returns Tx FIFO size for IN EP
  55149. + *
  55150. + * @param core_if Programming view of DWC_otg controller
  55151. + *
  55152. + * @return The total of data FIFO sizes.
  55153. + *
  55154. + */
  55155. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  55156. +{
  55157. + dwc_otg_pcd_ep_t *ep;
  55158. +
  55159. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  55160. +
  55161. + if (NULL == ep) {
  55162. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55163. + __func__, wValue & 0xff);
  55164. + return -DWC_E_INVALID;
  55165. + }
  55166. +
  55167. + if (!ep->dwc_ep.is_in) {
  55168. + CFI_INFO
  55169. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  55170. + __func__, wValue & 0xff);
  55171. + return -DWC_E_INVALID;
  55172. + }
  55173. +
  55174. + switch (wValue >> 8) {
  55175. + case 0:
  55176. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  55177. + [ep->dwc_ep.tx_fifo_num - 1] <
  55178. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  55179. + dwc_ep.tx_fifo_num
  55180. + - 1] : 32768;
  55181. + break;
  55182. + case 1:
  55183. + return GET_CORE_IF(pcd)->core_params->
  55184. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  55185. + break;
  55186. + default:
  55187. + return -DWC_E_INVALID;
  55188. + break;
  55189. + }
  55190. +}
  55191. +
  55192. +/**
  55193. + * This function checks if the submitted combination of
  55194. + * device mode FIFO sizes is possible or not.
  55195. + *
  55196. + * @param core_if Programming view of DWC_otg controller
  55197. + *
  55198. + * @return 1 if possible, 0 otherwise.
  55199. + *
  55200. + */
  55201. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  55202. +{
  55203. + uint16_t dfifo_actual = 0;
  55204. + dwc_otg_core_params_t *params = core_if->core_params;
  55205. + uint16_t start_addr = 0;
  55206. + int i;
  55207. +
  55208. + dfifo_actual =
  55209. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55210. +
  55211. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55212. + dfifo_actual += params->dev_tx_fifo_size[i];
  55213. + }
  55214. +
  55215. + if (dfifo_actual > core_if->total_fifo_size) {
  55216. + return 0;
  55217. + }
  55218. +
  55219. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  55220. + return 0;
  55221. +
  55222. + if (params->dev_nperio_tx_fifo_size > 32768
  55223. + || params->dev_nperio_tx_fifo_size < 16)
  55224. + return 0;
  55225. +
  55226. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55227. +
  55228. + if (params->dev_tx_fifo_size[i] > 768
  55229. + || params->dev_tx_fifo_size[i] < 4)
  55230. + return 0;
  55231. + }
  55232. +
  55233. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  55234. + return 0;
  55235. + start_addr = params->dev_rx_fifo_size;
  55236. +
  55237. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  55238. + return 0;
  55239. + start_addr += params->dev_nperio_tx_fifo_size;
  55240. +
  55241. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55242. +
  55243. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  55244. + return 0;
  55245. + start_addr += params->dev_tx_fifo_size[i];
  55246. + }
  55247. +
  55248. + return 1;
  55249. +}
  55250. +
  55251. +/**
  55252. + * This function resizes Device mode FIFOs
  55253. + *
  55254. + * @param core_if Programming view of DWC_otg controller
  55255. + *
  55256. + * @return 1 if successful, 0 otherwise
  55257. + *
  55258. + */
  55259. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  55260. +{
  55261. + int i = 0;
  55262. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55263. + dwc_otg_core_params_t *params = core_if->core_params;
  55264. + uint32_t rx_fifo_size;
  55265. + fifosize_data_t nptxfifosize;
  55266. + fifosize_data_t txfifosize[15];
  55267. +
  55268. + uint32_t rx_fsz_bak;
  55269. + uint32_t nptxfsz_bak;
  55270. + uint32_t txfsz_bak[15];
  55271. +
  55272. + uint16_t start_address;
  55273. + uint8_t retval = 1;
  55274. +
  55275. + if (!check_fifo_sizes(core_if)) {
  55276. + return 0;
  55277. + }
  55278. +
  55279. + /* Configure data FIFO sizes */
  55280. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  55281. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  55282. + rx_fifo_size = params->dev_rx_fifo_size;
  55283. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  55284. +
  55285. + /*
  55286. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  55287. + * Indexes of the FIFO size module parameters in the
  55288. + * dev_tx_fifo_size array and the FIFO size registers in
  55289. + * the dtxfsiz array run from 0 to 14.
  55290. + */
  55291. +
  55292. + /* Non-periodic Tx FIFO */
  55293. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  55294. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  55295. + start_address = params->dev_rx_fifo_size;
  55296. + nptxfifosize.b.startaddr = start_address;
  55297. +
  55298. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  55299. +
  55300. + start_address += nptxfifosize.b.depth;
  55301. +
  55302. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55303. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  55304. +
  55305. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  55306. + txfifosize[i].b.startaddr = start_address;
  55307. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  55308. + txfifosize[i].d32);
  55309. +
  55310. + start_address += txfifosize[i].b.depth;
  55311. + }
  55312. +
  55313. + /** Check if register values are set correctly */
  55314. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  55315. + retval = 0;
  55316. + }
  55317. +
  55318. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  55319. + retval = 0;
  55320. + }
  55321. +
  55322. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55323. + if (txfifosize[i].d32 !=
  55324. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  55325. + retval = 0;
  55326. + }
  55327. + }
  55328. +
  55329. + /** If register values are not set correctly, reset old values */
  55330. + if (retval == 0) {
  55331. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  55332. +
  55333. + /* Non-periodic Tx FIFO */
  55334. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  55335. +
  55336. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55337. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  55338. + txfsz_bak[i]);
  55339. + }
  55340. + }
  55341. + } else {
  55342. + return 0;
  55343. + }
  55344. +
  55345. + /* Flush the FIFOs */
  55346. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  55347. + dwc_otg_flush_rx_fifo(core_if);
  55348. +
  55349. + return retval;
  55350. +}
  55351. +
  55352. +/**
  55353. + * This function sets a new value for the buffer Alignment setup.
  55354. + */
  55355. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  55356. +{
  55357. + int retval;
  55358. + uint32_t fsiz;
  55359. + uint16_t size;
  55360. + uint16_t ep_addr;
  55361. + dwc_otg_pcd_ep_t *ep;
  55362. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55363. + tx_fifo_size_setup_t *ptxfifoval;
  55364. +
  55365. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  55366. + ep_addr = ptxfifoval->bEndpointAddress;
  55367. + size = ptxfifoval->wDepth;
  55368. +
  55369. + ep = get_ep_by_addr(pcd, ep_addr);
  55370. +
  55371. + CFI_INFO
  55372. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  55373. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  55374. +
  55375. + if (NULL == ep) {
  55376. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55377. + __func__, ep_addr);
  55378. + return -DWC_E_INVALID;
  55379. + }
  55380. +
  55381. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  55382. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  55383. +
  55384. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55385. + retval = 0;
  55386. + } else {
  55387. + CFI_INFO
  55388. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  55389. + __func__, ep_addr);
  55390. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  55391. + retval = -DWC_E_INVALID;
  55392. + }
  55393. +
  55394. + return retval;
  55395. +}
  55396. +
  55397. +/**
  55398. + * This function sets a new value for the buffer Alignment setup.
  55399. + */
  55400. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  55401. +{
  55402. + int retval;
  55403. + uint32_t fsiz;
  55404. + uint16_t size;
  55405. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55406. + rx_fifo_size_setup_t *prxfifoval;
  55407. +
  55408. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  55409. + size = prxfifoval->wDepth;
  55410. +
  55411. + fsiz = params->dev_rx_fifo_size;
  55412. + params->dev_rx_fifo_size = size;
  55413. +
  55414. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55415. + retval = 0;
  55416. + } else {
  55417. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  55418. + __func__);
  55419. + params->dev_rx_fifo_size = fsiz;
  55420. + retval = -DWC_E_INVALID;
  55421. + }
  55422. +
  55423. + return retval;
  55424. +}
  55425. +
  55426. +/**
  55427. + * This function reads the SG of an EP's buffer setup into the buffer buf
  55428. + */
  55429. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55430. + struct cfi_usb_ctrlrequest *req)
  55431. +{
  55432. + int retval = -DWC_E_INVALID;
  55433. + uint8_t addr;
  55434. + cfi_ep_t *ep;
  55435. +
  55436. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55437. + addr = req->wValue & 0xFF;
  55438. + if (addr == 0) /* The address should be non-zero */
  55439. + return retval;
  55440. +
  55441. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55442. + if (NULL == ep) {
  55443. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55444. + __func__, addr);
  55445. + return retval;
  55446. + }
  55447. +
  55448. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  55449. + retval = BS_SG_VAL_DESC_LEN;
  55450. + return retval;
  55451. +}
  55452. +
  55453. +/**
  55454. + * This function reads the Concatenation value of an EP's buffer mode into
  55455. + * the buffer buf
  55456. + */
  55457. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55458. + struct cfi_usb_ctrlrequest *req)
  55459. +{
  55460. + int retval = -DWC_E_INVALID;
  55461. + uint8_t addr;
  55462. + cfi_ep_t *ep;
  55463. + uint8_t desc_count;
  55464. +
  55465. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55466. + addr = req->wValue & 0xFF;
  55467. + if (addr == 0) /* The address should be non-zero */
  55468. + return retval;
  55469. +
  55470. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55471. + if (NULL == ep) {
  55472. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55473. + __func__, addr);
  55474. + return retval;
  55475. + }
  55476. +
  55477. + /* Copy the header to the buffer */
  55478. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  55479. + /* Advance the buffer pointer by the header size */
  55480. + buf += BS_CONCAT_VAL_HDR_LEN;
  55481. +
  55482. + desc_count = ep->bm_concat->hdr.bDescCount;
  55483. + /* Copy alll the wTxBytes to the buffer */
  55484. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  55485. +
  55486. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  55487. + return retval;
  55488. +}
  55489. +
  55490. +/**
  55491. + * This function reads the buffer Alignment value of an EP's buffer mode into
  55492. + * the buffer buf
  55493. + *
  55494. + * @return The total number of bytes copied to the buffer or negative error code.
  55495. + */
  55496. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55497. + struct cfi_usb_ctrlrequest *req)
  55498. +{
  55499. + int retval = -DWC_E_INVALID;
  55500. + uint8_t addr;
  55501. + cfi_ep_t *ep;
  55502. +
  55503. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55504. + addr = req->wValue & 0xFF;
  55505. + if (addr == 0) /* The address should be non-zero */
  55506. + return retval;
  55507. +
  55508. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55509. + if (NULL == ep) {
  55510. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55511. + __func__, addr);
  55512. + return retval;
  55513. + }
  55514. +
  55515. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  55516. + retval = BS_ALIGN_VAL_HDR_LEN;
  55517. +
  55518. + return retval;
  55519. +}
  55520. +
  55521. +/**
  55522. + * This function sets a new value for the specified feature
  55523. + *
  55524. + * @param pcd A pointer to the PCD object
  55525. + *
  55526. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  55527. + */
  55528. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  55529. +{
  55530. + int retval = -DWC_E_NOT_SUPPORTED;
  55531. + uint16_t wIndex, wValue;
  55532. + uint8_t bRequest;
  55533. + struct dwc_otg_core_if *coreif;
  55534. + cfiobject_t *cfi = pcd->cfi;
  55535. + struct cfi_usb_ctrlrequest *ctrl_req;
  55536. + uint8_t *buf;
  55537. + ctrl_req = &cfi->ctrl_req;
  55538. +
  55539. + buf = pcd->cfi->ctrl_req.data;
  55540. +
  55541. + coreif = GET_CORE_IF(pcd);
  55542. + bRequest = ctrl_req->bRequest;
  55543. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  55544. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  55545. +
  55546. + /* See which feature is to be modified */
  55547. + switch (wIndex) {
  55548. + case FT_ID_DMA_BUFFER_SETUP:
  55549. + /* Modify the feature */
  55550. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  55551. + return retval;
  55552. +
  55553. + /* And send this request to the gadget */
  55554. + cfi->need_gadget_att = 1;
  55555. + break;
  55556. +
  55557. + case FT_ID_DMA_BUFF_ALIGN:
  55558. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  55559. + return retval;
  55560. + cfi->need_gadget_att = 1;
  55561. + break;
  55562. +
  55563. + case FT_ID_DMA_CONCAT_SETUP:
  55564. + /* Modify the feature */
  55565. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  55566. + return retval;
  55567. + cfi->need_gadget_att = 1;
  55568. + break;
  55569. +
  55570. + case FT_ID_DMA_CIRCULAR:
  55571. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  55572. + break;
  55573. +
  55574. + case FT_ID_THRESHOLD_SETUP:
  55575. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  55576. + break;
  55577. +
  55578. + case FT_ID_DFIFO_DEPTH:
  55579. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  55580. + break;
  55581. +
  55582. + case FT_ID_TX_FIFO_DEPTH:
  55583. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  55584. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  55585. + return retval;
  55586. + cfi->need_gadget_att = 0;
  55587. + break;
  55588. +
  55589. + case FT_ID_RX_FIFO_DEPTH:
  55590. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  55591. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  55592. + return retval;
  55593. + cfi->need_gadget_att = 0;
  55594. + break;
  55595. + }
  55596. +
  55597. + return retval;
  55598. +}
  55599. +
  55600. +#endif //DWC_UTE_CFI
  55601. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  55602. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  55603. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-03-13 12:46:39.512097981 +0100
  55604. @@ -0,0 +1,320 @@
  55605. +/* ==========================================================================
  55606. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55607. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55608. + * otherwise expressly agreed to in writing between Synopsys and you.
  55609. + *
  55610. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55611. + * any End User Software License Agreement or Agreement for Licensed Product
  55612. + * with Synopsys or any supplement thereto. You are permitted to use and
  55613. + * redistribute this Software in source and binary forms, with or without
  55614. + * modification, provided that redistributions of source code must retain this
  55615. + * notice. You may not view, use, disclose, copy or distribute this file or
  55616. + * any information contained herein except pursuant to this license grant from
  55617. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55618. + * below, then you are not authorized to use the Software.
  55619. + *
  55620. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55621. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55622. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55623. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55624. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55625. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55626. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55627. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55628. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55629. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55630. + * DAMAGE.
  55631. + * ========================================================================== */
  55632. +
  55633. +#if !defined(__DWC_OTG_CFI_H__)
  55634. +#define __DWC_OTG_CFI_H__
  55635. +
  55636. +#include "dwc_otg_pcd.h"
  55637. +#include "dwc_cfi_common.h"
  55638. +
  55639. +/**
  55640. + * @file
  55641. + * This file contains the CFI related OTG PCD specific common constants,
  55642. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  55643. + * optional interface for internal testing purposes that a DUT may implement to
  55644. + * support testing of configurable features.
  55645. + *
  55646. + */
  55647. +
  55648. +struct dwc_otg_pcd;
  55649. +struct dwc_otg_pcd_ep;
  55650. +
  55651. +/** OTG CFI Features (properties) ID constants */
  55652. +/** This is a request for all Core Features */
  55653. +#define FT_ID_DMA_MODE 0x0001
  55654. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  55655. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  55656. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  55657. +#define FT_ID_DMA_CIRCULAR 0x0005
  55658. +#define FT_ID_THRESHOLD_SETUP 0x0006
  55659. +#define FT_ID_DFIFO_DEPTH 0x0007
  55660. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  55661. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  55662. +
  55663. +/**********************************************************/
  55664. +#define CFI_INFO_DEF
  55665. +
  55666. +#ifdef CFI_INFO_DEF
  55667. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  55668. +#else
  55669. +#define CFI_INFO(fmt...)
  55670. +#endif
  55671. +
  55672. +#define min(x,y) ({ \
  55673. + x < y ? x : y; })
  55674. +
  55675. +#define max(x,y) ({ \
  55676. + x > y ? x : y; })
  55677. +
  55678. +/**
  55679. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  55680. + * also used for setting up a buffer for Circular DDMA.
  55681. + */
  55682. +struct _ddma_sg_buffer_setup {
  55683. +#define BS_SG_VAL_DESC_LEN 6
  55684. + /* The OUT EP address */
  55685. + uint8_t bOutEndpointAddress;
  55686. + /* The IN EP address */
  55687. + uint8_t bInEndpointAddress;
  55688. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  55689. + uint8_t bOffset;
  55690. + /* The number of transfer segments (a DMA descriptors per each segment) */
  55691. + uint8_t bCount;
  55692. + /* Size (in byte) of each transfer segment */
  55693. + uint16_t wSize;
  55694. +} __attribute__ ((packed));
  55695. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  55696. +
  55697. +/** Descriptor DMA Concatenation Buffer setup structure */
  55698. +struct _ddma_concat_buffer_setup_hdr {
  55699. +#define BS_CONCAT_VAL_HDR_LEN 4
  55700. + /* The endpoint for which the buffer is to be set up */
  55701. + uint8_t bEndpointAddress;
  55702. + /* The count of descriptors to be used */
  55703. + uint8_t bDescCount;
  55704. + /* The total size of the transfer */
  55705. + uint16_t wSize;
  55706. +} __attribute__ ((packed));
  55707. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  55708. +
  55709. +/** Descriptor DMA Concatenation Buffer setup structure */
  55710. +struct _ddma_concat_buffer_setup {
  55711. + /* The SG header */
  55712. + ddma_concat_buffer_setup_hdr_t hdr;
  55713. +
  55714. + /* The XFER sizes pointer (allocated dynamically) */
  55715. + uint16_t *wTxBytes;
  55716. +} __attribute__ ((packed));
  55717. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  55718. +
  55719. +/** Descriptor DMA Alignment Buffer setup structure */
  55720. +struct _ddma_align_buffer_setup {
  55721. +#define BS_ALIGN_VAL_HDR_LEN 2
  55722. + uint8_t bEndpointAddress;
  55723. + uint8_t bAlign;
  55724. +} __attribute__ ((packed));
  55725. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  55726. +
  55727. +/** Transmit FIFO Size setup structure */
  55728. +struct _tx_fifo_size_setup {
  55729. + uint8_t bEndpointAddress;
  55730. + uint16_t wDepth;
  55731. +} __attribute__ ((packed));
  55732. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  55733. +
  55734. +/** Transmit FIFO Size setup structure */
  55735. +struct _rx_fifo_size_setup {
  55736. + uint16_t wDepth;
  55737. +} __attribute__ ((packed));
  55738. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  55739. +
  55740. +/**
  55741. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  55742. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  55743. + * to the data returned in the data stage of a 3-stage Control Write requests.
  55744. + */
  55745. +struct cfi_usb_ctrlrequest {
  55746. + uint8_t bRequestType;
  55747. + uint8_t bRequest;
  55748. + uint16_t wValue;
  55749. + uint16_t wIndex;
  55750. + uint16_t wLength;
  55751. + uint8_t *data;
  55752. +} UPACKED;
  55753. +
  55754. +/*---------------------------------------------------------------------------*/
  55755. +
  55756. +/**
  55757. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  55758. + * This structure is used to store the buffer setup data for any
  55759. + * enabled endpoint in the PCD.
  55760. + */
  55761. +struct cfi_ep {
  55762. + /* Entry for the list container */
  55763. + dwc_list_link_t lh;
  55764. + /* Pointer to the active PCD endpoint structure */
  55765. + struct dwc_otg_pcd_ep *ep;
  55766. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  55767. + struct dwc_otg_dma_desc *dma_desc_last;
  55768. + /* The SG feature value */
  55769. + ddma_sg_buffer_setup_t *bm_sg;
  55770. + /* The Circular feature value */
  55771. + ddma_sg_buffer_setup_t *bm_circ;
  55772. + /* The Concatenation feature value */
  55773. + ddma_concat_buffer_setup_t *bm_concat;
  55774. + /* The Alignment feature value */
  55775. + ddma_align_buffer_setup_t *bm_align;
  55776. + /* XFER length */
  55777. + uint32_t xfer_len;
  55778. + /*
  55779. + * Count of DMA descriptors currently used.
  55780. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  55781. + * defined in the dwc_otg_cil.h
  55782. + */
  55783. + uint32_t desc_count;
  55784. +};
  55785. +typedef struct cfi_ep cfi_ep_t;
  55786. +
  55787. +typedef struct cfi_dma_buff {
  55788. +#define CFI_IN_BUF_LEN 1024
  55789. +#define CFI_OUT_BUF_LEN 1024
  55790. + dma_addr_t addr;
  55791. + uint8_t *buf;
  55792. +} cfi_dma_buff_t;
  55793. +
  55794. +struct cfiobject;
  55795. +
  55796. +/**
  55797. + * This is the interface for the CFI operations.
  55798. + *
  55799. + * @param ep_enable Called when any endpoint is enabled and activated.
  55800. + * @param release Called when the CFI object is released and it needs to correctly
  55801. + * deallocate the dynamic memory
  55802. + * @param ctrl_write_complete Called when the data stage of the request is complete
  55803. + */
  55804. +typedef struct cfi_ops {
  55805. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55806. + struct dwc_otg_pcd_ep * ep);
  55807. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55808. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  55809. + unsigned size, gfp_t flags);
  55810. + void (*release) (struct cfiobject * cfi);
  55811. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  55812. + struct dwc_otg_pcd * pcd);
  55813. + void (*build_descriptors) (struct cfiobject * cfi,
  55814. + struct dwc_otg_pcd * pcd,
  55815. + struct dwc_otg_pcd_ep * ep,
  55816. + dwc_otg_pcd_request_t * req);
  55817. +} cfi_ops_t;
  55818. +
  55819. +struct cfiobject {
  55820. + cfi_ops_t ops;
  55821. + struct dwc_otg_pcd *pcd;
  55822. + struct usb_gadget *gadget;
  55823. +
  55824. + /* Buffers used to send/receive CFI-related request data */
  55825. + cfi_dma_buff_t buf_in;
  55826. + cfi_dma_buff_t buf_out;
  55827. +
  55828. + /* CFI specific Control request wrapper */
  55829. + struct cfi_usb_ctrlrequest ctrl_req;
  55830. +
  55831. + /* The list of active EP's in the PCD of type cfi_ep_t */
  55832. + dwc_list_link_t active_eps;
  55833. +
  55834. + /* This flag shall control the propagation of a specific request
  55835. + * to the gadget's processing routines.
  55836. + * 0 - no gadget handling
  55837. + * 1 - the gadget needs to know about this request (w/o completing a status
  55838. + * phase - just return a 0 to the _setup callback)
  55839. + */
  55840. + uint8_t need_gadget_att;
  55841. +
  55842. + /* Flag indicating whether the status IN phase needs to be
  55843. + * completed by the PCD
  55844. + */
  55845. + uint8_t need_status_in_complete;
  55846. +};
  55847. +typedef struct cfiobject cfiobject_t;
  55848. +
  55849. +#define DUMP_MSG
  55850. +
  55851. +#if defined(DUMP_MSG)
  55852. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55853. +{
  55854. + unsigned int start, num, i;
  55855. + char line[52], *p;
  55856. +
  55857. + if (length >= 512)
  55858. + return;
  55859. +
  55860. + start = 0;
  55861. + while (length > 0) {
  55862. + num = min(length, 16u);
  55863. + p = line;
  55864. + for (i = 0; i < num; ++i) {
  55865. + if (i == 8)
  55866. + *p++ = ' ';
  55867. + DWC_SPRINTF(p, " %02x", buf[i]);
  55868. + p += 3;
  55869. + }
  55870. + *p = 0;
  55871. + DWC_DEBUG("%6x: %s\n", start, line);
  55872. + buf += num;
  55873. + start += num;
  55874. + length -= num;
  55875. + }
  55876. +}
  55877. +#else
  55878. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55879. +{
  55880. +}
  55881. +#endif
  55882. +
  55883. +/**
  55884. + * This function returns a pointer to cfi_ep_t object with the addr address.
  55885. + */
  55886. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  55887. + uint8_t addr)
  55888. +{
  55889. + struct cfi_ep *pcfiep;
  55890. + dwc_list_link_t *tmp;
  55891. +
  55892. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55893. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55894. +
  55895. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  55896. + return pcfiep;
  55897. + }
  55898. + }
  55899. +
  55900. + return NULL;
  55901. +}
  55902. +
  55903. +/**
  55904. + * This function returns a pointer to cfi_ep_t object that matches
  55905. + * the dwc_otg_pcd_ep object.
  55906. + */
  55907. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  55908. + struct dwc_otg_pcd_ep *ep)
  55909. +{
  55910. + struct cfi_ep *pcfiep = NULL;
  55911. + dwc_list_link_t *tmp;
  55912. +
  55913. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55914. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55915. + if (pcfiep->ep == ep) {
  55916. + return pcfiep;
  55917. + }
  55918. + }
  55919. + return NULL;
  55920. +}
  55921. +
  55922. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  55923. +
  55924. +#endif /* (__DWC_OTG_CFI_H__) */
  55925. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  55926. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  55927. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-03-13 12:46:39.512097981 +0100
  55928. @@ -0,0 +1,7151 @@
  55929. +/* ==========================================================================
  55930. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  55931. + * $Revision: #191 $
  55932. + * $Date: 2012/08/10 $
  55933. + * $Change: 2047372 $
  55934. + *
  55935. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55936. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55937. + * otherwise expressly agreed to in writing between Synopsys and you.
  55938. + *
  55939. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55940. + * any End User Software License Agreement or Agreement for Licensed Product
  55941. + * with Synopsys or any supplement thereto. You are permitted to use and
  55942. + * redistribute this Software in source and binary forms, with or without
  55943. + * modification, provided that redistributions of source code must retain this
  55944. + * notice. You may not view, use, disclose, copy or distribute this file or
  55945. + * any information contained herein except pursuant to this license grant from
  55946. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55947. + * below, then you are not authorized to use the Software.
  55948. + *
  55949. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55950. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55951. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55952. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55953. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55954. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55955. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55956. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55957. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55958. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55959. + * DAMAGE.
  55960. + * ========================================================================== */
  55961. +
  55962. +/** @file
  55963. + *
  55964. + * The Core Interface Layer provides basic services for accessing and
  55965. + * managing the DWC_otg hardware. These services are used by both the
  55966. + * Host Controller Driver and the Peripheral Controller Driver.
  55967. + *
  55968. + * The CIL manages the memory map for the core so that the HCD and PCD
  55969. + * don't have to do this separately. It also handles basic tasks like
  55970. + * reading/writing the registers and data FIFOs in the controller.
  55971. + * Some of the data access functions provide encapsulation of several
  55972. + * operations required to perform a task, such as writing multiple
  55973. + * registers to start a transfer. Finally, the CIL performs basic
  55974. + * services that are not specific to either the host or device modes
  55975. + * of operation. These services include management of the OTG Host
  55976. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  55977. + * Diagnostic API is also provided to allow testing of the controller
  55978. + * hardware.
  55979. + *
  55980. + * The Core Interface Layer has the following requirements:
  55981. + * - Provides basic controller operations.
  55982. + * - Minimal use of OS services.
  55983. + * - The OS services used will be abstracted by using inline functions
  55984. + * or macros.
  55985. + *
  55986. + */
  55987. +
  55988. +#include "dwc_os.h"
  55989. +#include "dwc_otg_regs.h"
  55990. +#include "dwc_otg_cil.h"
  55991. +
  55992. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  55993. +
  55994. +/**
  55995. + * This function is called to initialize the DWC_otg CSR data
  55996. + * structures. The register addresses in the device and host
  55997. + * structures are initialized from the base address supplied by the
  55998. + * caller. The calling function must make the OS calls to get the
  55999. + * base address of the DWC_otg controller registers. The core_params
  56000. + * argument holds the parameters that specify how the core should be
  56001. + * configured.
  56002. + *
  56003. + * @param reg_base_addr Base address of DWC_otg core registers
  56004. + *
  56005. + */
  56006. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  56007. +{
  56008. + dwc_otg_core_if_t *core_if = 0;
  56009. + dwc_otg_dev_if_t *dev_if = 0;
  56010. + dwc_otg_host_if_t *host_if = 0;
  56011. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  56012. + int i = 0;
  56013. +
  56014. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  56015. +
  56016. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  56017. +
  56018. + if (core_if == NULL) {
  56019. + DWC_DEBUGPL(DBG_CIL,
  56020. + "Allocation of dwc_otg_core_if_t failed\n");
  56021. + return 0;
  56022. + }
  56023. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  56024. +
  56025. + /*
  56026. + * Allocate the Device Mode structures.
  56027. + */
  56028. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  56029. +
  56030. + if (dev_if == NULL) {
  56031. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  56032. + DWC_FREE(core_if);
  56033. + return 0;
  56034. + }
  56035. +
  56036. + dev_if->dev_global_regs =
  56037. + (dwc_otg_device_global_regs_t *) (reg_base +
  56038. + DWC_DEV_GLOBAL_REG_OFFSET);
  56039. +
  56040. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56041. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  56042. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  56043. + (i * DWC_EP_REG_OFFSET));
  56044. +
  56045. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  56046. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  56047. + (i * DWC_EP_REG_OFFSET));
  56048. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  56049. + i, &dev_if->in_ep_regs[i]->diepctl);
  56050. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  56051. + i, &dev_if->out_ep_regs[i]->doepctl);
  56052. + }
  56053. +
  56054. + dev_if->speed = 0; // unknown
  56055. +
  56056. + core_if->dev_if = dev_if;
  56057. +
  56058. + /*
  56059. + * Allocate the Host Mode structures.
  56060. + */
  56061. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  56062. +
  56063. + if (host_if == NULL) {
  56064. + DWC_DEBUGPL(DBG_CIL,
  56065. + "Allocation of dwc_otg_host_if_t failed\n");
  56066. + DWC_FREE(dev_if);
  56067. + DWC_FREE(core_if);
  56068. + return 0;
  56069. + }
  56070. +
  56071. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  56072. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  56073. +
  56074. + host_if->hprt0 =
  56075. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  56076. +
  56077. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56078. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  56079. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  56080. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  56081. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  56082. + i, &host_if->hc_regs[i]->hcchar);
  56083. + }
  56084. +
  56085. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  56086. + core_if->host_if = host_if;
  56087. +
  56088. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56089. + core_if->data_fifo[i] =
  56090. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  56091. + (i * DWC_OTG_DATA_FIFO_SIZE));
  56092. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  56093. + i, (unsigned long)core_if->data_fifo[i]);
  56094. + }
  56095. +
  56096. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  56097. +
  56098. + /* Initiate lx_state to L3 disconnected state */
  56099. + core_if->lx_state = DWC_OTG_L3;
  56100. + /*
  56101. + * Store the contents of the hardware configuration registers here for
  56102. + * easy access later.
  56103. + */
  56104. + core_if->hwcfg1.d32 =
  56105. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  56106. + core_if->hwcfg2.d32 =
  56107. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  56108. + core_if->hwcfg3.d32 =
  56109. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  56110. + core_if->hwcfg4.d32 =
  56111. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  56112. +
  56113. + /* Force host mode to get HPTXFSIZ exact power on value */
  56114. + {
  56115. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56116. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56117. + gusbcfg.b.force_host_mode = 1;
  56118. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56119. + dwc_mdelay(100);
  56120. + core_if->hptxfsiz.d32 =
  56121. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56122. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56123. + gusbcfg.b.force_host_mode = 0;
  56124. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56125. + dwc_mdelay(100);
  56126. + }
  56127. +
  56128. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  56129. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  56130. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  56131. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  56132. +
  56133. + core_if->hcfg.d32 =
  56134. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56135. + core_if->dcfg.d32 =
  56136. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56137. +
  56138. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  56139. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  56140. +
  56141. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  56142. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  56143. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  56144. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  56145. + core_if->hwcfg2.b.num_host_chan);
  56146. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  56147. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  56148. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  56149. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  56150. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  56151. + core_if->hwcfg2.b.dev_token_q_depth);
  56152. +
  56153. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  56154. + core_if->hwcfg3.b.dfifo_depth);
  56155. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  56156. + core_if->hwcfg3.b.xfer_size_cntr_width);
  56157. +
  56158. + /*
  56159. + * Set the SRP sucess bit for FS-I2c
  56160. + */
  56161. + core_if->srp_success = 0;
  56162. + core_if->srp_timer_started = 0;
  56163. +
  56164. + /*
  56165. + * Create new workqueue and init works
  56166. + */
  56167. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  56168. + if (core_if->wq_otg == 0) {
  56169. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  56170. + DWC_FREE(host_if);
  56171. + DWC_FREE(dev_if);
  56172. + DWC_FREE(core_if);
  56173. + return 0;
  56174. + }
  56175. +
  56176. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  56177. +
  56178. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  56179. + (core_if->snpsid >> 12 & 0xF),
  56180. + (core_if->snpsid >> 8 & 0xF),
  56181. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  56182. +
  56183. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  56184. + w_wakeup_detected, core_if);
  56185. + if (core_if->wkp_timer == 0) {
  56186. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  56187. + DWC_FREE(host_if);
  56188. + DWC_FREE(dev_if);
  56189. + DWC_WORKQ_FREE(core_if->wq_otg);
  56190. + DWC_FREE(core_if);
  56191. + return 0;
  56192. + }
  56193. +
  56194. + if (dwc_otg_setup_params(core_if)) {
  56195. + DWC_WARN("Error while setting core params\n");
  56196. + }
  56197. +
  56198. + core_if->hibernation_suspend = 0;
  56199. +
  56200. + /** ADP initialization */
  56201. + dwc_otg_adp_init(core_if);
  56202. +
  56203. + return core_if;
  56204. +}
  56205. +
  56206. +/**
  56207. + * This function frees the structures allocated by dwc_otg_cil_init().
  56208. + *
  56209. + * @param core_if The core interface pointer returned from
  56210. + * dwc_otg_cil_init().
  56211. + *
  56212. + */
  56213. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  56214. +{
  56215. + dctl_data_t dctl = {.d32 = 0 };
  56216. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  56217. +
  56218. + /* Disable all interrupts */
  56219. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  56220. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  56221. +
  56222. + dctl.b.sftdiscon = 1;
  56223. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  56224. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  56225. + dctl.d32);
  56226. + }
  56227. +
  56228. + if (core_if->wq_otg) {
  56229. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  56230. + DWC_WORKQ_FREE(core_if->wq_otg);
  56231. + }
  56232. + if (core_if->dev_if) {
  56233. + DWC_FREE(core_if->dev_if);
  56234. + }
  56235. + if (core_if->host_if) {
  56236. + DWC_FREE(core_if->host_if);
  56237. + }
  56238. +
  56239. + /** Remove ADP Stuff */
  56240. + dwc_otg_adp_remove(core_if);
  56241. + if (core_if->core_params) {
  56242. + DWC_FREE(core_if->core_params);
  56243. + }
  56244. + if (core_if->wkp_timer) {
  56245. + DWC_TIMER_FREE(core_if->wkp_timer);
  56246. + }
  56247. + if (core_if->srp_timer) {
  56248. + DWC_TIMER_FREE(core_if->srp_timer);
  56249. + }
  56250. + DWC_FREE(core_if);
  56251. +}
  56252. +
  56253. +/**
  56254. + * This function enables the controller's Global Interrupt in the AHB Config
  56255. + * register.
  56256. + *
  56257. + * @param core_if Programming view of DWC_otg controller.
  56258. + */
  56259. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  56260. +{
  56261. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56262. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  56263. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  56264. +}
  56265. +
  56266. +/**
  56267. + * This function disables the controller's Global Interrupt in the AHB Config
  56268. + * register.
  56269. + *
  56270. + * @param core_if Programming view of DWC_otg controller.
  56271. + */
  56272. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  56273. +{
  56274. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56275. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  56276. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  56277. +}
  56278. +
  56279. +/**
  56280. + * This function initializes the commmon interrupts, used in both
  56281. + * device and host modes.
  56282. + *
  56283. + * @param core_if Programming view of the DWC_otg controller
  56284. + *
  56285. + */
  56286. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  56287. +{
  56288. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56289. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56290. +
  56291. + /* Clear any pending OTG Interrupts */
  56292. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  56293. +
  56294. + /* Clear any pending interrupts */
  56295. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56296. +
  56297. + /*
  56298. + * Enable the interrupts in the GINTMSK.
  56299. + */
  56300. + intr_mask.b.modemismatch = 1;
  56301. + intr_mask.b.otgintr = 1;
  56302. +
  56303. + if (!core_if->dma_enable) {
  56304. + intr_mask.b.rxstsqlvl = 1;
  56305. + }
  56306. +
  56307. + intr_mask.b.conidstschng = 1;
  56308. + intr_mask.b.wkupintr = 1;
  56309. + intr_mask.b.disconnect = 0;
  56310. + intr_mask.b.usbsuspend = 1;
  56311. + intr_mask.b.sessreqintr = 1;
  56312. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56313. + if (core_if->core_params->lpm_enable) {
  56314. + intr_mask.b.lpmtranrcvd = 1;
  56315. + }
  56316. +#endif
  56317. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  56318. +}
  56319. +
  56320. +/*
  56321. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  56322. + * Hibernation. This function is for exiting from Device mode hibernation by
  56323. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  56324. + * @param core_if Programming view of DWC_otg controller.
  56325. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  56326. + * @param reset - indicates whether resume is initiated by Reset.
  56327. + */
  56328. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  56329. + int rem_wakeup, int reset)
  56330. +{
  56331. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56332. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56333. + dctl_data_t dctl = {.d32 = 0 };
  56334. +
  56335. + int timeout = 2000;
  56336. +
  56337. + if (!core_if->hibernation_suspend) {
  56338. + DWC_PRINTF("Already exited from Hibernation\n");
  56339. + return 1;
  56340. + }
  56341. +
  56342. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  56343. + /* Switch-on voltage to the core */
  56344. + gpwrdn.b.pwrdnswtch = 1;
  56345. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56346. + dwc_udelay(10);
  56347. +
  56348. + /* Reset core */
  56349. + gpwrdn.d32 = 0;
  56350. + gpwrdn.b.pwrdnrstn = 1;
  56351. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56352. + dwc_udelay(10);
  56353. +
  56354. + /* Assert Restore signal */
  56355. + gpwrdn.d32 = 0;
  56356. + gpwrdn.b.restore = 1;
  56357. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56358. + dwc_udelay(10);
  56359. +
  56360. + /* Disable power clamps */
  56361. + gpwrdn.d32 = 0;
  56362. + gpwrdn.b.pwrdnclmp = 1;
  56363. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56364. +
  56365. + if (rem_wakeup) {
  56366. + dwc_udelay(70);
  56367. + }
  56368. +
  56369. + /* Deassert Reset core */
  56370. + gpwrdn.d32 = 0;
  56371. + gpwrdn.b.pwrdnrstn = 1;
  56372. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56373. + dwc_udelay(10);
  56374. +
  56375. + /* Disable PMU interrupt */
  56376. + gpwrdn.d32 = 0;
  56377. + gpwrdn.b.pmuintsel = 1;
  56378. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56379. +
  56380. + /* Mask interrupts from gpwrdn */
  56381. + gpwrdn.d32 = 0;
  56382. + gpwrdn.b.connect_det_msk = 1;
  56383. + gpwrdn.b.srp_det_msk = 1;
  56384. + gpwrdn.b.disconn_det_msk = 1;
  56385. + gpwrdn.b.rst_det_msk = 1;
  56386. + gpwrdn.b.lnstchng_msk = 1;
  56387. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56388. +
  56389. + /* Indicates that we are going out from hibernation */
  56390. + core_if->hibernation_suspend = 0;
  56391. +
  56392. + /*
  56393. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  56394. + * indicates restore from remote_wakeup
  56395. + */
  56396. + restore_essential_regs(core_if, rem_wakeup, 0);
  56397. +
  56398. + /*
  56399. + * Wait a little for seeing new value of variable hibernation_suspend if
  56400. + * Restore done interrupt received before polling
  56401. + */
  56402. + dwc_udelay(10);
  56403. +
  56404. + if (core_if->hibernation_suspend == 0) {
  56405. + /*
  56406. + * Wait For Restore_done Interrupt. This mechanism of polling the
  56407. + * interrupt is introduced to avoid any possible race conditions
  56408. + */
  56409. + do {
  56410. + gintsts_data_t gintsts;
  56411. + gintsts.d32 =
  56412. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56413. + if (gintsts.b.restoredone) {
  56414. + gintsts.d32 = 0;
  56415. + gintsts.b.restoredone = 1;
  56416. + DWC_WRITE_REG32(&core_if->core_global_regs->
  56417. + gintsts, gintsts.d32);
  56418. + DWC_PRINTF("Restore Done Interrupt seen\n");
  56419. + break;
  56420. + }
  56421. + dwc_udelay(10);
  56422. + } while (--timeout);
  56423. + if (!timeout) {
  56424. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  56425. + }
  56426. + }
  56427. + /* Clear all pending interupts */
  56428. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56429. +
  56430. + /* De-assert Restore */
  56431. + gpwrdn.d32 = 0;
  56432. + gpwrdn.b.restore = 1;
  56433. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56434. + dwc_udelay(10);
  56435. +
  56436. + if (!rem_wakeup) {
  56437. + pcgcctl.d32 = 0;
  56438. + pcgcctl.b.rstpdwnmodule = 1;
  56439. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  56440. + }
  56441. +
  56442. + /* Restore GUSBCFG and DCFG */
  56443. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56444. + core_if->gr_backup->gusbcfg_local);
  56445. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  56446. + core_if->dr_backup->dcfg);
  56447. +
  56448. + /* De-assert Wakeup Logic */
  56449. + gpwrdn.d32 = 0;
  56450. + gpwrdn.b.pmuactv = 1;
  56451. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56452. + dwc_udelay(10);
  56453. +
  56454. + if (!rem_wakeup) {
  56455. + /* Set Device programming done bit */
  56456. + dctl.b.pwronprgdone = 1;
  56457. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56458. + } else {
  56459. + /* Start Remote Wakeup Signaling */
  56460. + dctl.d32 = core_if->dr_backup->dctl;
  56461. + dctl.b.rmtwkupsig = 1;
  56462. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  56463. + }
  56464. +
  56465. + dwc_mdelay(2);
  56466. + /* Clear all pending interupts */
  56467. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56468. +
  56469. + /* Restore global registers */
  56470. + dwc_otg_restore_global_regs(core_if);
  56471. + /* Restore device global registers */
  56472. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  56473. +
  56474. + if (rem_wakeup) {
  56475. + dwc_mdelay(7);
  56476. + dctl.d32 = 0;
  56477. + dctl.b.rmtwkupsig = 1;
  56478. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  56479. + }
  56480. +
  56481. + core_if->hibernation_suspend = 0;
  56482. + /* The core will be in ON STATE */
  56483. + core_if->lx_state = DWC_OTG_L0;
  56484. + DWC_PRINTF("Hibernation recovery completes here\n");
  56485. +
  56486. + return 1;
  56487. +}
  56488. +
  56489. +/*
  56490. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  56491. + * Hibernation. This function is for exiting from Host mode hibernation by
  56492. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  56493. + * @param core_if Programming view of DWC_otg controller.
  56494. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  56495. + * @param reset - indicates whether resume is initiated by Reset.
  56496. + */
  56497. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  56498. + int rem_wakeup, int reset)
  56499. +{
  56500. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56501. + hprt0_data_t hprt0 = {.d32 = 0 };
  56502. +
  56503. + int timeout = 2000;
  56504. +
  56505. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  56506. + /* Switch-on voltage to the core */
  56507. + gpwrdn.b.pwrdnswtch = 1;
  56508. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56509. + dwc_udelay(10);
  56510. +
  56511. + /* Reset core */
  56512. + gpwrdn.d32 = 0;
  56513. + gpwrdn.b.pwrdnrstn = 1;
  56514. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56515. + dwc_udelay(10);
  56516. +
  56517. + /* Assert Restore signal */
  56518. + gpwrdn.d32 = 0;
  56519. + gpwrdn.b.restore = 1;
  56520. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56521. + dwc_udelay(10);
  56522. +
  56523. + /* Disable power clamps */
  56524. + gpwrdn.d32 = 0;
  56525. + gpwrdn.b.pwrdnclmp = 1;
  56526. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56527. +
  56528. + if (!rem_wakeup) {
  56529. + dwc_udelay(50);
  56530. + }
  56531. +
  56532. + /* Deassert Reset core */
  56533. + gpwrdn.d32 = 0;
  56534. + gpwrdn.b.pwrdnrstn = 1;
  56535. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56536. + dwc_udelay(10);
  56537. +
  56538. + /* Disable PMU interrupt */
  56539. + gpwrdn.d32 = 0;
  56540. + gpwrdn.b.pmuintsel = 1;
  56541. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56542. +
  56543. + gpwrdn.d32 = 0;
  56544. + gpwrdn.b.connect_det_msk = 1;
  56545. + gpwrdn.b.srp_det_msk = 1;
  56546. + gpwrdn.b.disconn_det_msk = 1;
  56547. + gpwrdn.b.rst_det_msk = 1;
  56548. + gpwrdn.b.lnstchng_msk = 1;
  56549. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56550. +
  56551. + /* Indicates that we are going out from hibernation */
  56552. + core_if->hibernation_suspend = 0;
  56553. +
  56554. + /* Set Restore Essential Regs bit in PCGCCTL register */
  56555. + restore_essential_regs(core_if, rem_wakeup, 1);
  56556. +
  56557. + /* Wait a little for seeing new value of variable hibernation_suspend if
  56558. + * Restore done interrupt received before polling */
  56559. + dwc_udelay(10);
  56560. +
  56561. + if (core_if->hibernation_suspend == 0) {
  56562. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  56563. + * interrupt is introduced to avoid any possible race conditions
  56564. + */
  56565. + do {
  56566. + gintsts_data_t gintsts;
  56567. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56568. + if (gintsts.b.restoredone) {
  56569. + gintsts.d32 = 0;
  56570. + gintsts.b.restoredone = 1;
  56571. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56572. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  56573. + break;
  56574. + }
  56575. + dwc_udelay(10);
  56576. + } while (--timeout);
  56577. + if (!timeout) {
  56578. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  56579. + }
  56580. + }
  56581. +
  56582. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  56583. + core_if->hibernation_suspend = 0;
  56584. +
  56585. + /* This step is not described in functional spec but if not wait for this
  56586. + * delay, mismatch interrupts occurred because just after restore core is
  56587. + * in Device mode(gintsts.curmode == 0) */
  56588. + dwc_mdelay(100);
  56589. +
  56590. + /* Clear all pending interrupts */
  56591. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56592. +
  56593. + /* De-assert Restore */
  56594. + gpwrdn.d32 = 0;
  56595. + gpwrdn.b.restore = 1;
  56596. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56597. + dwc_udelay(10);
  56598. +
  56599. + /* Restore GUSBCFG and HCFG */
  56600. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56601. + core_if->gr_backup->gusbcfg_local);
  56602. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56603. + core_if->hr_backup->hcfg_local);
  56604. +
  56605. + /* De-assert Wakeup Logic */
  56606. + gpwrdn.d32 = 0;
  56607. + gpwrdn.b.pmuactv = 1;
  56608. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56609. + dwc_udelay(10);
  56610. +
  56611. + /* Start the Resume operation by programming HPRT0 */
  56612. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56613. + hprt0.b.prtpwr = 1;
  56614. + hprt0.b.prtena = 0;
  56615. + hprt0.b.prtsusp = 0;
  56616. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56617. +
  56618. + DWC_PRINTF("Resume Starts Now\n");
  56619. + if (!reset) { // Indicates it is Resume Operation
  56620. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56621. + hprt0.b.prtres = 1;
  56622. + hprt0.b.prtpwr = 1;
  56623. + hprt0.b.prtena = 0;
  56624. + hprt0.b.prtsusp = 0;
  56625. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56626. +
  56627. + if (!rem_wakeup)
  56628. + hprt0.b.prtres = 0;
  56629. + /* Wait for Resume time and then program HPRT again */
  56630. + dwc_mdelay(100);
  56631. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56632. +
  56633. + } else { // Indicates it is Reset Operation
  56634. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56635. + hprt0.b.prtrst = 1;
  56636. + hprt0.b.prtpwr = 1;
  56637. + hprt0.b.prtena = 0;
  56638. + hprt0.b.prtsusp = 0;
  56639. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56640. + /* Wait for Reset time and then program HPRT again */
  56641. + dwc_mdelay(60);
  56642. + hprt0.b.prtrst = 0;
  56643. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56644. + }
  56645. + /* Clear all interrupt status */
  56646. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  56647. + hprt0.b.prtconndet = 1;
  56648. + hprt0.b.prtenchng = 1;
  56649. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56650. +
  56651. + /* Clear all pending interupts */
  56652. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56653. +
  56654. + /* Restore global registers */
  56655. + dwc_otg_restore_global_regs(core_if);
  56656. + /* Restore host global registers */
  56657. + dwc_otg_restore_host_regs(core_if, reset);
  56658. +
  56659. + /* The core will be in ON STATE */
  56660. + core_if->lx_state = DWC_OTG_L0;
  56661. + DWC_PRINTF("Hibernation recovery is complete here\n");
  56662. + return 0;
  56663. +}
  56664. +
  56665. +/** Saves some register values into system memory. */
  56666. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  56667. +{
  56668. + struct dwc_otg_global_regs_backup *gr;
  56669. + int i;
  56670. +
  56671. + gr = core_if->gr_backup;
  56672. + if (!gr) {
  56673. + gr = DWC_ALLOC(sizeof(*gr));
  56674. + if (!gr) {
  56675. + return -DWC_E_NO_MEMORY;
  56676. + }
  56677. + core_if->gr_backup = gr;
  56678. + }
  56679. +
  56680. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  56681. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56682. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  56683. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56684. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  56685. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  56686. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56687. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56688. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  56689. +#endif
  56690. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  56691. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  56692. + gr->gdfifocfg_local =
  56693. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  56694. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56695. + gr->dtxfsiz_local[i] =
  56696. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  56697. + }
  56698. +
  56699. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  56700. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  56701. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56702. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  56703. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  56704. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  56705. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  56706. + gr->gnptxfsiz_local);
  56707. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  56708. + gr->hptxfsiz_local);
  56709. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56710. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  56711. +#endif
  56712. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  56713. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  56714. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  56715. +
  56716. + return 0;
  56717. +}
  56718. +
  56719. +/** Saves GINTMSK register before setting the msk bits. */
  56720. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  56721. +{
  56722. + struct dwc_otg_global_regs_backup *gr;
  56723. +
  56724. + gr = core_if->gr_backup;
  56725. + if (!gr) {
  56726. + gr = DWC_ALLOC(sizeof(*gr));
  56727. + if (!gr) {
  56728. + return -DWC_E_NO_MEMORY;
  56729. + }
  56730. + core_if->gr_backup = gr;
  56731. + }
  56732. +
  56733. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56734. +
  56735. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  56736. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56737. +
  56738. + return 0;
  56739. +}
  56740. +
  56741. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  56742. +{
  56743. + struct dwc_otg_dev_regs_backup *dr;
  56744. + int i;
  56745. +
  56746. + dr = core_if->dr_backup;
  56747. + if (!dr) {
  56748. + dr = DWC_ALLOC(sizeof(*dr));
  56749. + if (!dr) {
  56750. + return -DWC_E_NO_MEMORY;
  56751. + }
  56752. + core_if->dr_backup = dr;
  56753. + }
  56754. +
  56755. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56756. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  56757. + dr->daintmsk =
  56758. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  56759. + dr->diepmsk =
  56760. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  56761. + dr->doepmsk =
  56762. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  56763. +
  56764. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56765. + dr->diepctl[i] =
  56766. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  56767. + dr->dieptsiz[i] =
  56768. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  56769. + dr->diepdma[i] =
  56770. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  56771. + }
  56772. +
  56773. + DWC_DEBUGPL(DBG_ANY,
  56774. + "=============Backing Host registers==============\n");
  56775. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  56776. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  56777. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  56778. + dr->daintmsk);
  56779. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  56780. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  56781. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56782. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  56783. + dr->diepctl[i]);
  56784. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  56785. + i, dr->dieptsiz[i]);
  56786. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  56787. + dr->diepdma[i]);
  56788. + }
  56789. +
  56790. + return 0;
  56791. +}
  56792. +
  56793. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  56794. +{
  56795. + struct dwc_otg_host_regs_backup *hr;
  56796. + int i;
  56797. +
  56798. + hr = core_if->hr_backup;
  56799. + if (!hr) {
  56800. + hr = DWC_ALLOC(sizeof(*hr));
  56801. + if (!hr) {
  56802. + return -DWC_E_NO_MEMORY;
  56803. + }
  56804. + core_if->hr_backup = hr;
  56805. + }
  56806. +
  56807. + hr->hcfg_local =
  56808. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56809. + hr->haintmsk_local =
  56810. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  56811. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56812. + hr->hcintmsk_local[i] =
  56813. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  56814. + }
  56815. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  56816. + hr->hfir_local =
  56817. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  56818. +
  56819. + DWC_DEBUGPL(DBG_ANY,
  56820. + "=============Backing Host registers===============\n");
  56821. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  56822. + hr->hcfg_local);
  56823. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  56824. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56825. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  56826. + hr->hcintmsk_local[i]);
  56827. + }
  56828. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  56829. + hr->hprt0_local);
  56830. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  56831. + hr->hfir_local);
  56832. +
  56833. + return 0;
  56834. +}
  56835. +
  56836. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  56837. +{
  56838. + struct dwc_otg_global_regs_backup *gr;
  56839. + int i;
  56840. +
  56841. + gr = core_if->gr_backup;
  56842. + if (!gr) {
  56843. + return -DWC_E_INVALID;
  56844. + }
  56845. +
  56846. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  56847. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  56848. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  56849. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  56850. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  56851. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  56852. + gr->gnptxfsiz_local);
  56853. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  56854. + gr->hptxfsiz_local);
  56855. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  56856. + gr->gdfifocfg_local);
  56857. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56858. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  56859. + gr->dtxfsiz_local[i]);
  56860. + }
  56861. +
  56862. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56863. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  56864. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  56865. + (gr->gahbcfg_local));
  56866. + return 0;
  56867. +}
  56868. +
  56869. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  56870. +{
  56871. + struct dwc_otg_dev_regs_backup *dr;
  56872. + int i;
  56873. +
  56874. + dr = core_if->dr_backup;
  56875. +
  56876. + if (!dr) {
  56877. + return -DWC_E_INVALID;
  56878. + }
  56879. +
  56880. + if (!rem_wakeup) {
  56881. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  56882. + dr->dctl);
  56883. + }
  56884. +
  56885. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  56886. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  56887. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  56888. +
  56889. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56890. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  56891. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  56892. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  56893. + }
  56894. +
  56895. + return 0;
  56896. +}
  56897. +
  56898. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  56899. +{
  56900. + struct dwc_otg_host_regs_backup *hr;
  56901. + int i;
  56902. + hr = core_if->hr_backup;
  56903. +
  56904. + if (!hr) {
  56905. + return -DWC_E_INVALID;
  56906. + }
  56907. +
  56908. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  56909. + //if (!reset)
  56910. + //{
  56911. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  56912. + //}
  56913. +
  56914. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  56915. + hr->haintmsk_local);
  56916. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56917. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  56918. + hr->hcintmsk_local[i]);
  56919. + }
  56920. +
  56921. + return 0;
  56922. +}
  56923. +
  56924. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  56925. +{
  56926. + struct dwc_otg_global_regs_backup *gr;
  56927. +
  56928. + gr = core_if->gr_backup;
  56929. +
  56930. + /* Restore values for LPM and I2C */
  56931. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56932. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  56933. +#endif
  56934. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  56935. +
  56936. + return 0;
  56937. +}
  56938. +
  56939. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  56940. +{
  56941. + struct dwc_otg_global_regs_backup *gr;
  56942. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56943. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  56944. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56945. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56946. +
  56947. + /* Restore LPM and I2C registers */
  56948. + restore_lpm_i2c_regs(core_if);
  56949. +
  56950. + /* Set PCGCCTL to 0 */
  56951. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  56952. +
  56953. + gr = core_if->gr_backup;
  56954. + /* Load restore values for [31:14] bits */
  56955. + DWC_WRITE_REG32(core_if->pcgcctl,
  56956. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  56957. +
  56958. + /* Umnask global Interrupt in GAHBCFG and restore it */
  56959. + gahbcfg.d32 = gr->gahbcfg_local;
  56960. + gahbcfg.b.glblintrmsk = 1;
  56961. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  56962. +
  56963. + /* Clear all pending interupts */
  56964. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56965. +
  56966. + /* Unmask restore done interrupt */
  56967. + gintmsk.b.restoredone = 1;
  56968. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  56969. +
  56970. + /* Restore GUSBCFG and HCFG/DCFG */
  56971. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  56972. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56973. +
  56974. + if (is_host) {
  56975. + hcfg_data_t hcfg = {.d32 = 0 };
  56976. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  56977. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56978. + hcfg.d32);
  56979. +
  56980. + /* Load restore values for [31:14] bits */
  56981. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56982. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56983. +
  56984. + if (rmode)
  56985. + pcgcctl.b.restoremode = 1;
  56986. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56987. + dwc_udelay(10);
  56988. +
  56989. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  56990. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  56991. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56992. + pcgcctl.b.ess_reg_restored = 1;
  56993. + if (rmode)
  56994. + pcgcctl.b.restoremode = 1;
  56995. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56996. + } else {
  56997. + dcfg_data_t dcfg = {.d32 = 0 };
  56998. + dcfg.d32 = core_if->dr_backup->dcfg;
  56999. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57000. +
  57001. + /* Load restore values for [31:14] bits */
  57002. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57003. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57004. + if (!rmode) {
  57005. + pcgcctl.d32 |= 0x208;
  57006. + }
  57007. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57008. + dwc_udelay(10);
  57009. +
  57010. + /* Load restore values for [31:14] bits */
  57011. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57012. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57013. + pcgcctl.b.ess_reg_restored = 1;
  57014. + if (!rmode)
  57015. + pcgcctl.d32 |= 0x208;
  57016. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57017. + }
  57018. +
  57019. + return 0;
  57020. +}
  57021. +
  57022. +/**
  57023. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  57024. + * type.
  57025. + */
  57026. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  57027. +{
  57028. + uint32_t val;
  57029. + hcfg_data_t hcfg;
  57030. +
  57031. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57032. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57033. + (core_if->core_params->ulpi_fs_ls)) ||
  57034. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57035. + /* Full speed PHY */
  57036. + val = DWC_HCFG_48_MHZ;
  57037. + } else {
  57038. + /* High speed PHY running at full speed or high speed */
  57039. + val = DWC_HCFG_30_60_MHZ;
  57040. + }
  57041. +
  57042. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  57043. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  57044. + hcfg.b.fslspclksel = val;
  57045. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  57046. +}
  57047. +
  57048. +/**
  57049. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  57050. + * and the enumeration speed of the device.
  57051. + */
  57052. +static void init_devspd(dwc_otg_core_if_t * core_if)
  57053. +{
  57054. + uint32_t val;
  57055. + dcfg_data_t dcfg;
  57056. +
  57057. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57058. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57059. + (core_if->core_params->ulpi_fs_ls)) ||
  57060. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57061. + /* Full speed PHY */
  57062. + val = 0x3;
  57063. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57064. + /* High speed PHY running at full speed */
  57065. + val = 0x1;
  57066. + } else {
  57067. + /* High speed PHY running at high speed */
  57068. + val = 0x0;
  57069. + }
  57070. +
  57071. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  57072. +
  57073. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  57074. + dcfg.b.devspd = val;
  57075. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57076. +}
  57077. +
  57078. +/**
  57079. + * This function calculates the number of IN EPS
  57080. + * using GHWCFG1 and GHWCFG2 registers values
  57081. + *
  57082. + * @param core_if Programming view of the DWC_otg controller
  57083. + */
  57084. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  57085. +{
  57086. + uint32_t num_in_eps = 0;
  57087. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57088. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  57089. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  57090. + int i;
  57091. +
  57092. + for (i = 0; i < num_eps; ++i) {
  57093. + if (!(hwcfg1 & 0x1))
  57094. + num_in_eps++;
  57095. +
  57096. + hwcfg1 >>= 2;
  57097. + }
  57098. +
  57099. + if (core_if->hwcfg4.b.ded_fifo_en) {
  57100. + num_in_eps =
  57101. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  57102. + }
  57103. +
  57104. + return num_in_eps;
  57105. +}
  57106. +
  57107. +/**
  57108. + * This function calculates the number of OUT EPS
  57109. + * using GHWCFG1 and GHWCFG2 registers values
  57110. + *
  57111. + * @param core_if Programming view of the DWC_otg controller
  57112. + */
  57113. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  57114. +{
  57115. + uint32_t num_out_eps = 0;
  57116. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57117. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  57118. + int i;
  57119. +
  57120. + for (i = 0; i < num_eps; ++i) {
  57121. + if (!(hwcfg1 & 0x1))
  57122. + num_out_eps++;
  57123. +
  57124. + hwcfg1 >>= 2;
  57125. + }
  57126. + return num_out_eps;
  57127. +}
  57128. +
  57129. +/**
  57130. + * This function initializes the DWC_otg controller registers and
  57131. + * prepares the core for device mode or host mode operation.
  57132. + *
  57133. + * @param core_if Programming view of the DWC_otg controller
  57134. + *
  57135. + */
  57136. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  57137. +{
  57138. + int i = 0;
  57139. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57140. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57141. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  57142. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  57143. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  57144. +
  57145. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  57146. + core_if, global_regs);
  57147. +
  57148. + /* Common Initialization */
  57149. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57150. +
  57151. + /* Program the ULPI External VBUS bit if needed */
  57152. + usbcfg.b.ulpi_ext_vbus_drv =
  57153. + (core_if->core_params->phy_ulpi_ext_vbus ==
  57154. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  57155. +
  57156. + /* Set external TS Dline pulsing */
  57157. + usbcfg.b.term_sel_dl_pulse =
  57158. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  57159. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57160. +
  57161. + /* Reset the Controller */
  57162. + dwc_otg_core_reset(core_if);
  57163. +
  57164. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  57165. + core_if->power_down = core_if->core_params->power_down;
  57166. + core_if->otg_sts = 0;
  57167. +
  57168. + /* Initialize parameters from Hardware configuration registers. */
  57169. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  57170. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  57171. +
  57172. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  57173. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  57174. +
  57175. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57176. + dev_if->perio_tx_fifo_size[i] =
  57177. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57178. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  57179. + i, dev_if->perio_tx_fifo_size[i]);
  57180. + }
  57181. +
  57182. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57183. + dev_if->tx_fifo_size[i] =
  57184. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57185. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  57186. + i, dev_if->tx_fifo_size[i]);
  57187. + }
  57188. +
  57189. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  57190. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  57191. + core_if->nperio_tx_fifo_size =
  57192. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  57193. +
  57194. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  57195. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  57196. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  57197. + core_if->nperio_tx_fifo_size);
  57198. +
  57199. + /* This programming sequence needs to happen in FS mode before any other
  57200. + * programming occurs */
  57201. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  57202. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57203. + /* If FS mode with FS PHY */
  57204. +
  57205. + /* core_init() is now called on every switch so only call the
  57206. + * following for the first time through. */
  57207. + if (!core_if->phy_init_done) {
  57208. + core_if->phy_init_done = 1;
  57209. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  57210. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57211. + usbcfg.b.physel = 1;
  57212. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57213. +
  57214. + /* Reset after a PHY select */
  57215. + dwc_otg_core_reset(core_if);
  57216. + }
  57217. +
  57218. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  57219. + * do this on HNP Dev/Host mode switches (done in dev_init and
  57220. + * host_init). */
  57221. + if (dwc_otg_is_host_mode(core_if)) {
  57222. + init_fslspclksel(core_if);
  57223. + } else {
  57224. + init_devspd(core_if);
  57225. + }
  57226. +
  57227. + if (core_if->core_params->i2c_enable) {
  57228. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  57229. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  57230. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57231. + usbcfg.b.otgutmifssel = 1;
  57232. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57233. +
  57234. + /* Program GI2CCTL.I2CEn */
  57235. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  57236. + i2cctl.b.i2cdevaddr = 1;
  57237. + i2cctl.b.i2cen = 0;
  57238. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  57239. + i2cctl.b.i2cen = 1;
  57240. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  57241. + }
  57242. +
  57243. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  57244. + else {
  57245. + /* High speed PHY. */
  57246. + if (!core_if->phy_init_done) {
  57247. + core_if->phy_init_done = 1;
  57248. + /* HS PHY parameters. These parameters are preserved
  57249. + * during soft reset so only program the first time. Do
  57250. + * a soft reset immediately after setting phyif. */
  57251. +
  57252. + if (core_if->core_params->phy_type == 2) {
  57253. + /* ULPI interface */
  57254. + usbcfg.b.ulpi_utmi_sel = 1;
  57255. + usbcfg.b.phyif = 0;
  57256. + usbcfg.b.ddrsel =
  57257. + core_if->core_params->phy_ulpi_ddr;
  57258. + } else if (core_if->core_params->phy_type == 1) {
  57259. + /* UTMI+ interface */
  57260. + usbcfg.b.ulpi_utmi_sel = 0;
  57261. + if (core_if->core_params->phy_utmi_width == 16) {
  57262. + usbcfg.b.phyif = 1;
  57263. +
  57264. + } else {
  57265. + usbcfg.b.phyif = 0;
  57266. + }
  57267. + } else {
  57268. + DWC_ERROR("FS PHY TYPE\n");
  57269. + }
  57270. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57271. + /* Reset after setting the PHY parameters */
  57272. + dwc_otg_core_reset(core_if);
  57273. + }
  57274. + }
  57275. +
  57276. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57277. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57278. + (core_if->core_params->ulpi_fs_ls)) {
  57279. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  57280. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57281. + usbcfg.b.ulpi_fsls = 1;
  57282. + usbcfg.b.ulpi_clk_sus_m = 1;
  57283. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57284. + } else {
  57285. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57286. + usbcfg.b.ulpi_fsls = 0;
  57287. + usbcfg.b.ulpi_clk_sus_m = 0;
  57288. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57289. + }
  57290. +
  57291. + /* Program the GAHBCFG Register. */
  57292. + switch (core_if->hwcfg2.b.architecture) {
  57293. +
  57294. + case DWC_SLAVE_ONLY_ARCH:
  57295. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  57296. + ahbcfg.b.nptxfemplvl_txfemplvl =
  57297. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  57298. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  57299. + core_if->dma_enable = 0;
  57300. + core_if->dma_desc_enable = 0;
  57301. + break;
  57302. +
  57303. + case DWC_EXT_DMA_ARCH:
  57304. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  57305. + {
  57306. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  57307. + ahbcfg.b.hburstlen = 0;
  57308. + while (brst_sz > 1) {
  57309. + ahbcfg.b.hburstlen++;
  57310. + brst_sz >>= 1;
  57311. + }
  57312. + }
  57313. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  57314. + core_if->dma_desc_enable =
  57315. + (core_if->core_params->dma_desc_enable != 0);
  57316. + break;
  57317. +
  57318. + case DWC_INT_DMA_ARCH:
  57319. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  57320. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  57321. + Host mode ISOC in issue fix - vahrama */
  57322. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  57323. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  57324. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  57325. + core_if->dma_desc_enable =
  57326. + (core_if->core_params->dma_desc_enable != 0);
  57327. + break;
  57328. +
  57329. + }
  57330. + if (core_if->dma_enable) {
  57331. + if (core_if->dma_desc_enable) {
  57332. + DWC_PRINTF("Using Descriptor DMA mode\n");
  57333. + } else {
  57334. + DWC_PRINTF("Using Buffer DMA mode\n");
  57335. +
  57336. + }
  57337. + } else {
  57338. + DWC_PRINTF("Using Slave mode\n");
  57339. + core_if->dma_desc_enable = 0;
  57340. + }
  57341. +
  57342. + if (core_if->core_params->ahb_single) {
  57343. + ahbcfg.b.ahbsingle = 1;
  57344. + }
  57345. +
  57346. + ahbcfg.b.dmaenable = core_if->dma_enable;
  57347. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  57348. +
  57349. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  57350. +
  57351. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  57352. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  57353. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  57354. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  57355. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  57356. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  57357. +
  57358. + /*
  57359. + * Program the GUSBCFG register.
  57360. + */
  57361. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57362. +
  57363. + switch (core_if->hwcfg2.b.op_mode) {
  57364. + case DWC_MODE_HNP_SRP_CAPABLE:
  57365. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  57366. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  57367. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57368. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57369. + break;
  57370. +
  57371. + case DWC_MODE_SRP_ONLY_CAPABLE:
  57372. + usbcfg.b.hnpcap = 0;
  57373. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57374. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57375. + break;
  57376. +
  57377. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  57378. + usbcfg.b.hnpcap = 0;
  57379. + usbcfg.b.srpcap = 0;
  57380. + break;
  57381. +
  57382. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  57383. + usbcfg.b.hnpcap = 0;
  57384. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57385. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57386. + break;
  57387. +
  57388. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  57389. + usbcfg.b.hnpcap = 0;
  57390. + usbcfg.b.srpcap = 0;
  57391. + break;
  57392. +
  57393. + case DWC_MODE_SRP_CAPABLE_HOST:
  57394. + usbcfg.b.hnpcap = 0;
  57395. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57396. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57397. + break;
  57398. +
  57399. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  57400. + usbcfg.b.hnpcap = 0;
  57401. + usbcfg.b.srpcap = 0;
  57402. + break;
  57403. + }
  57404. +
  57405. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57406. +
  57407. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57408. + if (core_if->core_params->lpm_enable) {
  57409. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  57410. +
  57411. + /* To enable LPM support set lpm_cap_en bit */
  57412. + lpmcfg.b.lpm_cap_en = 1;
  57413. +
  57414. + /* Make AppL1Res ACK */
  57415. + lpmcfg.b.appl_resp = 1;
  57416. +
  57417. + /* Retry 3 times */
  57418. + lpmcfg.b.retry_count = 3;
  57419. +
  57420. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  57421. + 0, lpmcfg.d32);
  57422. +
  57423. + }
  57424. +#endif
  57425. + if (core_if->core_params->ic_usb_cap) {
  57426. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  57427. + gusbcfg.b.ic_usb_cap = 1;
  57428. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  57429. + 0, gusbcfg.d32);
  57430. + }
  57431. + {
  57432. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57433. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  57434. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  57435. + gotgctl.d32);
  57436. + /* Set OTG version supported */
  57437. + core_if->otg_ver = core_if->core_params->otg_ver;
  57438. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  57439. + core_if->core_params->otg_ver, core_if->otg_ver);
  57440. + }
  57441. +
  57442. +
  57443. + /* Enable common interrupts */
  57444. + dwc_otg_enable_common_interrupts(core_if);
  57445. +
  57446. + /* Do device or host intialization based on mode during PCD
  57447. + * and HCD initialization */
  57448. + if (dwc_otg_is_host_mode(core_if)) {
  57449. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  57450. + core_if->op_state = A_HOST;
  57451. + } else {
  57452. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  57453. + core_if->op_state = B_PERIPHERAL;
  57454. +#ifdef DWC_DEVICE_ONLY
  57455. + dwc_otg_core_dev_init(core_if);
  57456. +#endif
  57457. + }
  57458. +}
  57459. +
  57460. +/**
  57461. + * This function enables the Device mode interrupts.
  57462. + *
  57463. + * @param core_if Programming view of DWC_otg controller
  57464. + */
  57465. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  57466. +{
  57467. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57468. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57469. +
  57470. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  57471. +
  57472. + /* Disable all interrupts. */
  57473. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57474. +
  57475. + /* Clear any pending interrupts */
  57476. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57477. +
  57478. + /* Enable the common interrupts */
  57479. + dwc_otg_enable_common_interrupts(core_if);
  57480. +
  57481. + /* Enable interrupts */
  57482. + intr_mask.b.usbreset = 1;
  57483. + intr_mask.b.enumdone = 1;
  57484. + /* Disable Disconnect interrupt in Device mode */
  57485. + intr_mask.b.disconnect = 0;
  57486. +
  57487. + if (!core_if->multiproc_int_enable) {
  57488. + intr_mask.b.inepintr = 1;
  57489. + intr_mask.b.outepintr = 1;
  57490. + }
  57491. +
  57492. + intr_mask.b.erlysuspend = 1;
  57493. +
  57494. + if (core_if->en_multiple_tx_fifo == 0) {
  57495. + intr_mask.b.epmismatch = 1;
  57496. + }
  57497. +
  57498. + //intr_mask.b.incomplisoout = 1;
  57499. + intr_mask.b.incomplisoin = 1;
  57500. +
  57501. +/* Enable the ignore frame number for ISOC xfers - MAS */
  57502. +/* Disable to support high bandwith ISOC transfers - manukz */
  57503. +#if 0
  57504. +#ifdef DWC_UTE_PER_IO
  57505. + if (core_if->dma_enable) {
  57506. + if (core_if->dma_desc_enable) {
  57507. + dctl_data_t dctl1 = {.d32 = 0 };
  57508. + dctl1.b.ifrmnum = 1;
  57509. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  57510. + dctl, 0, dctl1.d32);
  57511. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  57512. + DWC_READ_REG32(&core_if->dev_if->
  57513. + dev_global_regs->dctl));
  57514. + }
  57515. + }
  57516. +#endif
  57517. +#endif
  57518. +#ifdef DWC_EN_ISOC
  57519. + if (core_if->dma_enable) {
  57520. + if (core_if->dma_desc_enable == 0) {
  57521. + if (core_if->pti_enh_enable) {
  57522. + dctl_data_t dctl = {.d32 = 0 };
  57523. + dctl.b.ifrmnum = 1;
  57524. + DWC_MODIFY_REG32(&core_if->
  57525. + dev_if->dev_global_regs->dctl,
  57526. + 0, dctl.d32);
  57527. + } else {
  57528. + intr_mask.b.incomplisoin = 1;
  57529. + intr_mask.b.incomplisoout = 1;
  57530. + }
  57531. + }
  57532. + } else {
  57533. + intr_mask.b.incomplisoin = 1;
  57534. + intr_mask.b.incomplisoout = 1;
  57535. + }
  57536. +#endif /* DWC_EN_ISOC */
  57537. +
  57538. + /** @todo NGS: Should this be a module parameter? */
  57539. +#ifdef USE_PERIODIC_EP
  57540. + intr_mask.b.isooutdrop = 1;
  57541. + intr_mask.b.eopframe = 1;
  57542. + intr_mask.b.incomplisoin = 1;
  57543. + intr_mask.b.incomplisoout = 1;
  57544. +#endif
  57545. +
  57546. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57547. +
  57548. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  57549. + DWC_READ_REG32(&global_regs->gintmsk));
  57550. +}
  57551. +
  57552. +/**
  57553. + * This function initializes the DWC_otg controller registers for
  57554. + * device mode.
  57555. + *
  57556. + * @param core_if Programming view of DWC_otg controller
  57557. + *
  57558. + */
  57559. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  57560. +{
  57561. + int i;
  57562. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57563. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57564. + dwc_otg_core_params_t *params = core_if->core_params;
  57565. + dcfg_data_t dcfg = {.d32 = 0 };
  57566. + depctl_data_t diepctl = {.d32 = 0 };
  57567. + grstctl_t resetctl = {.d32 = 0 };
  57568. + uint32_t rx_fifo_size;
  57569. + fifosize_data_t nptxfifosize;
  57570. + fifosize_data_t txfifosize;
  57571. + dthrctl_data_t dthrctl;
  57572. + fifosize_data_t ptxfifosize;
  57573. + uint16_t rxfsiz, nptxfsiz;
  57574. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57575. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  57576. +
  57577. + /* Restart the Phy Clock */
  57578. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57579. +
  57580. + /* Device configuration register */
  57581. + init_devspd(core_if);
  57582. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57583. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  57584. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  57585. + /* Enable Device OUT NAK in case of DDMA mode*/
  57586. + if (core_if->core_params->dev_out_nak) {
  57587. + dcfg.b.endevoutnak = 1;
  57588. + }
  57589. +
  57590. + if (core_if->core_params->cont_on_bna) {
  57591. + dctl_data_t dctl = {.d32 = 0 };
  57592. + dctl.b.encontonbna = 1;
  57593. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57594. + }
  57595. +
  57596. +
  57597. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57598. +
  57599. + /* Configure data FIFO sizes */
  57600. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57601. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57602. + core_if->total_fifo_size);
  57603. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57604. + params->dev_rx_fifo_size);
  57605. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57606. + params->dev_nperio_tx_fifo_size);
  57607. +
  57608. + /* Rx FIFO */
  57609. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57610. + DWC_READ_REG32(&global_regs->grxfsiz));
  57611. +
  57612. +#ifdef DWC_UTE_CFI
  57613. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  57614. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  57615. +#endif
  57616. + rx_fifo_size = params->dev_rx_fifo_size;
  57617. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  57618. +
  57619. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57620. + DWC_READ_REG32(&global_regs->grxfsiz));
  57621. +
  57622. + /** Set Periodic Tx FIFO Mask all bits 0 */
  57623. + core_if->p_tx_msk = 0;
  57624. +
  57625. + /** Set Tx FIFO Mask all bits 0 */
  57626. + core_if->tx_msk = 0;
  57627. +
  57628. + if (core_if->en_multiple_tx_fifo == 0) {
  57629. + /* Non-periodic Tx FIFO */
  57630. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57631. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57632. +
  57633. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57634. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57635. +
  57636. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57637. + nptxfifosize.d32);
  57638. +
  57639. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57640. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57641. +
  57642. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  57643. + /*
  57644. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  57645. + * Indexes of the FIFO size module parameters in the
  57646. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  57647. + * the dptxfsiz array run from 0 to 14.
  57648. + */
  57649. + /** @todo Finish debug of this */
  57650. + ptxfifosize.b.startaddr =
  57651. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57652. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57653. + ptxfifosize.b.depth =
  57654. + params->dev_perio_tx_fifo_size[i];
  57655. + DWC_DEBUGPL(DBG_CIL,
  57656. + "initial dtxfsiz[%d]=%08x\n", i,
  57657. + DWC_READ_REG32(&global_regs->dtxfsiz
  57658. + [i]));
  57659. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57660. + ptxfifosize.d32);
  57661. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  57662. + i,
  57663. + DWC_READ_REG32(&global_regs->dtxfsiz
  57664. + [i]));
  57665. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  57666. + }
  57667. + } else {
  57668. + /*
  57669. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  57670. + * Indexes of the FIFO size module parameters in the
  57671. + * dev_tx_fifo_size array and the FIFO size registers in
  57672. + * the dtxfsiz array run from 0 to 14.
  57673. + */
  57674. +
  57675. + /* Non-periodic Tx FIFO */
  57676. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57677. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57678. +
  57679. +#ifdef DWC_UTE_CFI
  57680. + core_if->pwron_gnptxfsiz =
  57681. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57682. + core_if->init_gnptxfsiz =
  57683. + params->dev_nperio_tx_fifo_size;
  57684. +#endif
  57685. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57686. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57687. +
  57688. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57689. + nptxfifosize.d32);
  57690. +
  57691. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57692. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57693. +
  57694. + txfifosize.b.startaddr =
  57695. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57696. +
  57697. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57698. +
  57699. + txfifosize.b.depth =
  57700. + params->dev_tx_fifo_size[i];
  57701. +
  57702. + DWC_DEBUGPL(DBG_CIL,
  57703. + "initial dtxfsiz[%d]=%08x\n",
  57704. + i,
  57705. + DWC_READ_REG32(&global_regs->dtxfsiz
  57706. + [i]));
  57707. +
  57708. +#ifdef DWC_UTE_CFI
  57709. + core_if->pwron_txfsiz[i] =
  57710. + (DWC_READ_REG32
  57711. + (&global_regs->dtxfsiz[i]) >> 16);
  57712. + core_if->init_txfsiz[i] =
  57713. + params->dev_tx_fifo_size[i];
  57714. +#endif
  57715. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57716. + txfifosize.d32);
  57717. +
  57718. + DWC_DEBUGPL(DBG_CIL,
  57719. + "new dtxfsiz[%d]=%08x\n",
  57720. + i,
  57721. + DWC_READ_REG32(&global_regs->dtxfsiz
  57722. + [i]));
  57723. +
  57724. + txfifosize.b.startaddr += txfifosize.b.depth;
  57725. + }
  57726. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57727. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  57728. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57729. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  57730. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  57731. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57732. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57733. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57734. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  57735. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57736. + }
  57737. + }
  57738. +
  57739. + /* Flush the FIFOs */
  57740. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  57741. + dwc_otg_flush_rx_fifo(core_if);
  57742. +
  57743. + /* Flush the Learning Queue. */
  57744. + resetctl.b.intknqflsh = 1;
  57745. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  57746. +
  57747. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  57748. + core_if->start_predict = 0;
  57749. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  57750. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  57751. + }
  57752. + core_if->nextep_seq[0] = 0;
  57753. + core_if->first_in_nextep_seq = 0;
  57754. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  57755. + diepctl.b.nextep = 0;
  57756. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  57757. +
  57758. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  57759. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57760. + dcfg.b.epmscnt = 2;
  57761. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57762. +
  57763. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  57764. + __func__, core_if->first_in_nextep_seq);
  57765. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  57766. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  57767. + }
  57768. + DWC_DEBUGPL(DBG_CILV,"\n");
  57769. + }
  57770. +
  57771. + /* Clear all pending Device Interrupts */
  57772. + /** @todo - if the condition needed to be checked
  57773. + * or in any case all pending interrutps should be cleared?
  57774. + */
  57775. + if (core_if->multiproc_int_enable) {
  57776. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57777. + DWC_WRITE_REG32(&dev_if->
  57778. + dev_global_regs->diepeachintmsk[i], 0);
  57779. + }
  57780. + }
  57781. +
  57782. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  57783. + DWC_WRITE_REG32(&dev_if->
  57784. + dev_global_regs->doepeachintmsk[i], 0);
  57785. + }
  57786. +
  57787. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  57788. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  57789. + } else {
  57790. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  57791. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  57792. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  57793. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  57794. + }
  57795. +
  57796. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  57797. + depctl_data_t depctl;
  57798. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  57799. + if (depctl.b.epena) {
  57800. + depctl.d32 = 0;
  57801. + depctl.b.epdis = 1;
  57802. + depctl.b.snak = 1;
  57803. + } else {
  57804. + depctl.d32 = 0;
  57805. + }
  57806. +
  57807. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  57808. +
  57809. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  57810. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  57811. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  57812. + }
  57813. +
  57814. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  57815. + depctl_data_t depctl;
  57816. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  57817. + if (depctl.b.epena) {
  57818. + dctl_data_t dctl = {.d32 = 0 };
  57819. + gintmsk_data_t gintsts = {.d32 = 0 };
  57820. + doepint_data_t doepint = {.d32 = 0 };
  57821. + dctl.b.sgoutnak = 1;
  57822. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57823. + do {
  57824. + dwc_udelay(10);
  57825. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57826. + } while (!gintsts.b.goutnakeff);
  57827. + gintsts.d32 = 0;
  57828. + gintsts.b.goutnakeff = 1;
  57829. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  57830. +
  57831. + depctl.d32 = 0;
  57832. + depctl.b.epdis = 1;
  57833. + depctl.b.snak = 1;
  57834. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57835. + do {
  57836. + dwc_udelay(10);
  57837. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  57838. + out_ep_regs[i]->doepint);
  57839. + } while (!doepint.b.epdisabled);
  57840. +
  57841. + doepint.b.epdisabled = 1;
  57842. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  57843. +
  57844. + dctl.d32 = 0;
  57845. + dctl.b.cgoutnak = 1;
  57846. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57847. + } else {
  57848. + depctl.d32 = 0;
  57849. + }
  57850. +
  57851. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57852. +
  57853. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  57854. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  57855. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  57856. + }
  57857. +
  57858. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  57859. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  57860. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  57861. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  57862. +
  57863. + dev_if->rx_thr_length = params->rx_thr_length;
  57864. + dev_if->tx_thr_length = params->tx_thr_length;
  57865. +
  57866. + dev_if->setup_desc_index = 0;
  57867. +
  57868. + dthrctl.d32 = 0;
  57869. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  57870. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  57871. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  57872. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  57873. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  57874. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  57875. +
  57876. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  57877. + dthrctl.d32);
  57878. +
  57879. + DWC_DEBUGPL(DBG_CIL,
  57880. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  57881. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  57882. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  57883. + dthrctl.b.rx_thr_len);
  57884. +
  57885. + }
  57886. +
  57887. + dwc_otg_enable_device_interrupts(core_if);
  57888. +
  57889. + {
  57890. + diepmsk_data_t msk = {.d32 = 0 };
  57891. + msk.b.txfifoundrn = 1;
  57892. + if (core_if->multiproc_int_enable) {
  57893. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  57894. + diepeachintmsk[0], msk.d32, msk.d32);
  57895. + } else {
  57896. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  57897. + msk.d32, msk.d32);
  57898. + }
  57899. + }
  57900. +
  57901. + if (core_if->multiproc_int_enable) {
  57902. + /* Set NAK on Babble */
  57903. + dctl_data_t dctl = {.d32 = 0 };
  57904. + dctl.b.nakonbble = 1;
  57905. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57906. + }
  57907. +
  57908. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  57909. + dctl_data_t dctl = {.d32 = 0 };
  57910. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  57911. + dctl.b.sftdiscon = 0;
  57912. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  57913. + }
  57914. +}
  57915. +
  57916. +/**
  57917. + * This function enables the Host mode interrupts.
  57918. + *
  57919. + * @param core_if Programming view of DWC_otg controller
  57920. + */
  57921. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  57922. +{
  57923. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57924. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57925. +
  57926. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  57927. +
  57928. + /* Disable all interrupts. */
  57929. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57930. +
  57931. + /* Clear any pending interrupts. */
  57932. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57933. +
  57934. + /* Enable the common interrupts */
  57935. + dwc_otg_enable_common_interrupts(core_if);
  57936. +
  57937. + /*
  57938. + * Enable host mode interrupts without disturbing common
  57939. + * interrupts.
  57940. + */
  57941. +
  57942. + intr_mask.b.disconnect = 1;
  57943. + intr_mask.b.portintr = 1;
  57944. + intr_mask.b.hcintr = 1;
  57945. +
  57946. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57947. +}
  57948. +
  57949. +/**
  57950. + * This function disables the Host Mode interrupts.
  57951. + *
  57952. + * @param core_if Programming view of DWC_otg controller
  57953. + */
  57954. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  57955. +{
  57956. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57957. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57958. +
  57959. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  57960. +
  57961. + /*
  57962. + * Disable host mode interrupts without disturbing common
  57963. + * interrupts.
  57964. + */
  57965. + intr_mask.b.sofintr = 1;
  57966. + intr_mask.b.portintr = 1;
  57967. + intr_mask.b.hcintr = 1;
  57968. + intr_mask.b.ptxfempty = 1;
  57969. + intr_mask.b.nptxfempty = 1;
  57970. +
  57971. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  57972. +}
  57973. +
  57974. +/**
  57975. + * This function initializes the DWC_otg controller registers for
  57976. + * host mode.
  57977. + *
  57978. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  57979. + * request queues. Host channels are reset to ensure that they are ready for
  57980. + * performing transfers.
  57981. + *
  57982. + * @param core_if Programming view of DWC_otg controller
  57983. + *
  57984. + */
  57985. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  57986. +{
  57987. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57988. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57989. + dwc_otg_core_params_t *params = core_if->core_params;
  57990. + hprt0_data_t hprt0 = {.d32 = 0 };
  57991. + fifosize_data_t nptxfifosize;
  57992. + fifosize_data_t ptxfifosize;
  57993. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  57994. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57995. + int i;
  57996. + hcchar_data_t hcchar;
  57997. + hcfg_data_t hcfg;
  57998. + hfir_data_t hfir;
  57999. + dwc_otg_hc_regs_t *hc_regs;
  58000. + int num_channels;
  58001. + gotgctl_data_t gotgctl = {.d32 = 0 };
  58002. +
  58003. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  58004. +
  58005. + /* Restart the Phy Clock */
  58006. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  58007. +
  58008. + /* Initialize Host Configuration Register */
  58009. + init_fslspclksel(core_if);
  58010. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  58011. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58012. + hcfg.b.fslssupp = 1;
  58013. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58014. +
  58015. + }
  58016. +
  58017. + /* This bit allows dynamic reloading of the HFIR register
  58018. + * during runtime. This bit needs to be programmed during
  58019. + * initial configuration and its value must not be changed
  58020. + * during runtime.*/
  58021. + if (core_if->core_params->reload_ctl == 1) {
  58022. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  58023. + hfir.b.hfirrldctrl = 1;
  58024. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  58025. + }
  58026. +
  58027. + if (core_if->core_params->dma_desc_enable) {
  58028. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  58029. + if (!
  58030. + (core_if->hwcfg4.b.desc_dma
  58031. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  58032. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  58033. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  58034. + || (op_mode ==
  58035. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  58036. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  58037. + || (op_mode ==
  58038. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  58039. +
  58040. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  58041. + "Either core version is below 2.90a or "
  58042. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  58043. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  58044. + "module parameter to 0.\n");
  58045. + return;
  58046. + }
  58047. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58048. + hcfg.b.descdma = 1;
  58049. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58050. + }
  58051. +
  58052. + /* Configure data FIFO sizes */
  58053. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  58054. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  58055. + core_if->total_fifo_size);
  58056. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  58057. + params->host_rx_fifo_size);
  58058. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  58059. + params->host_nperio_tx_fifo_size);
  58060. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  58061. + params->host_perio_tx_fifo_size);
  58062. +
  58063. + /* Rx FIFO */
  58064. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  58065. + DWC_READ_REG32(&global_regs->grxfsiz));
  58066. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  58067. + params->host_rx_fifo_size);
  58068. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  58069. + DWC_READ_REG32(&global_regs->grxfsiz));
  58070. +
  58071. + /* Non-periodic Tx FIFO */
  58072. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  58073. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58074. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  58075. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  58076. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  58077. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  58078. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58079. +
  58080. + /* Periodic Tx FIFO */
  58081. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  58082. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58083. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  58084. + ptxfifosize.b.startaddr =
  58085. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  58086. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  58087. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  58088. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58089. +
  58090. + if (core_if->en_multiple_tx_fifo
  58091. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58092. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  58093. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  58094. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  58095. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  58096. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  58097. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  58098. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  58099. + }
  58100. + }
  58101. +
  58102. + /* TODO - check this */
  58103. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58104. + gotgctl.b.hstsethnpen = 1;
  58105. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58106. + /* Make sure the FIFOs are flushed. */
  58107. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  58108. + dwc_otg_flush_rx_fifo(core_if);
  58109. +
  58110. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58111. + gotgctl.b.hstsethnpen = 1;
  58112. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58113. +
  58114. + if (!core_if->core_params->dma_desc_enable) {
  58115. + /* Flush out any leftover queued requests. */
  58116. + num_channels = core_if->core_params->host_channels;
  58117. +
  58118. + for (i = 0; i < num_channels; i++) {
  58119. + hc_regs = core_if->host_if->hc_regs[i];
  58120. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58121. + hcchar.b.chen = 0;
  58122. + hcchar.b.chdis = 1;
  58123. + hcchar.b.epdir = 0;
  58124. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58125. + }
  58126. +
  58127. + /* Halt all channels to put them into a known state. */
  58128. + for (i = 0; i < num_channels; i++) {
  58129. + int count = 0;
  58130. + hc_regs = core_if->host_if->hc_regs[i];
  58131. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58132. + hcchar.b.chen = 1;
  58133. + hcchar.b.chdis = 1;
  58134. + hcchar.b.epdir = 0;
  58135. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58136. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  58137. + do {
  58138. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58139. + if (++count > 1000) {
  58140. + DWC_ERROR
  58141. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  58142. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  58143. + break;
  58144. + }
  58145. + dwc_udelay(1);
  58146. + } while (hcchar.b.chen);
  58147. + }
  58148. + }
  58149. +
  58150. + /* Turn on the vbus power. */
  58151. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  58152. + if (core_if->op_state == A_HOST) {
  58153. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  58154. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  58155. + if (hprt0.b.prtpwr == 0) {
  58156. + hprt0.b.prtpwr = 1;
  58157. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  58158. + }
  58159. + }
  58160. +
  58161. + dwc_otg_enable_host_interrupts(core_if);
  58162. +}
  58163. +
  58164. +/**
  58165. + * Prepares a host channel for transferring packets to/from a specific
  58166. + * endpoint. The HCCHARn register is set up with the characteristics specified
  58167. + * in _hc. Host channel interrupts that may need to be serviced while this
  58168. + * transfer is in progress are enabled.
  58169. + *
  58170. + * @param core_if Programming view of DWC_otg controller
  58171. + * @param hc Information needed to initialize the host channel
  58172. + */
  58173. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58174. +{
  58175. + uint32_t intr_enable;
  58176. + hcintmsk_data_t hc_intr_mask;
  58177. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58178. + hcchar_data_t hcchar;
  58179. + hcsplt_data_t hcsplt;
  58180. +
  58181. + uint8_t hc_num = hc->hc_num;
  58182. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58183. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  58184. +
  58185. + /* Clear old interrupt conditions for this host channel. */
  58186. + hc_intr_mask.d32 = 0xFFFFFFFF;
  58187. + hc_intr_mask.b.reserved14_31 = 0;
  58188. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  58189. +
  58190. + /* Enable channel interrupts required for this transfer. */
  58191. + hc_intr_mask.d32 = 0;
  58192. + hc_intr_mask.b.chhltd = 1;
  58193. + if (core_if->dma_enable) {
  58194. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  58195. + if (!core_if->dma_desc_enable)
  58196. + hc_intr_mask.b.ahberr = 1;
  58197. + else {
  58198. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58199. + hc_intr_mask.b.xfercompl = 1;
  58200. + }
  58201. +
  58202. + if (hc->error_state && !hc->do_split &&
  58203. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  58204. + hc_intr_mask.b.ack = 1;
  58205. + if (hc->ep_is_in) {
  58206. + hc_intr_mask.b.datatglerr = 1;
  58207. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58208. + hc_intr_mask.b.nak = 1;
  58209. + }
  58210. + }
  58211. + }
  58212. + } else {
  58213. + switch (hc->ep_type) {
  58214. + case DWC_OTG_EP_TYPE_CONTROL:
  58215. + case DWC_OTG_EP_TYPE_BULK:
  58216. + hc_intr_mask.b.xfercompl = 1;
  58217. + hc_intr_mask.b.stall = 1;
  58218. + hc_intr_mask.b.xacterr = 1;
  58219. + hc_intr_mask.b.datatglerr = 1;
  58220. + if (hc->ep_is_in) {
  58221. + hc_intr_mask.b.bblerr = 1;
  58222. + } else {
  58223. + hc_intr_mask.b.nak = 1;
  58224. + hc_intr_mask.b.nyet = 1;
  58225. + if (hc->do_ping) {
  58226. + hc_intr_mask.b.ack = 1;
  58227. + }
  58228. + }
  58229. +
  58230. + if (hc->do_split) {
  58231. + hc_intr_mask.b.nak = 1;
  58232. + if (hc->complete_split) {
  58233. + hc_intr_mask.b.nyet = 1;
  58234. + } else {
  58235. + hc_intr_mask.b.ack = 1;
  58236. + }
  58237. + }
  58238. +
  58239. + if (hc->error_state) {
  58240. + hc_intr_mask.b.ack = 1;
  58241. + }
  58242. + break;
  58243. + case DWC_OTG_EP_TYPE_INTR:
  58244. + hc_intr_mask.b.xfercompl = 1;
  58245. + hc_intr_mask.b.nak = 1;
  58246. + hc_intr_mask.b.stall = 1;
  58247. + hc_intr_mask.b.xacterr = 1;
  58248. + hc_intr_mask.b.datatglerr = 1;
  58249. + hc_intr_mask.b.frmovrun = 1;
  58250. +
  58251. + if (hc->ep_is_in) {
  58252. + hc_intr_mask.b.bblerr = 1;
  58253. + }
  58254. + if (hc->error_state) {
  58255. + hc_intr_mask.b.ack = 1;
  58256. + }
  58257. + if (hc->do_split) {
  58258. + if (hc->complete_split) {
  58259. + hc_intr_mask.b.nyet = 1;
  58260. + } else {
  58261. + hc_intr_mask.b.ack = 1;
  58262. + }
  58263. + }
  58264. + break;
  58265. + case DWC_OTG_EP_TYPE_ISOC:
  58266. + hc_intr_mask.b.xfercompl = 1;
  58267. + hc_intr_mask.b.frmovrun = 1;
  58268. + hc_intr_mask.b.ack = 1;
  58269. +
  58270. + if (hc->ep_is_in) {
  58271. + hc_intr_mask.b.xacterr = 1;
  58272. + hc_intr_mask.b.bblerr = 1;
  58273. + }
  58274. + break;
  58275. + }
  58276. + }
  58277. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  58278. +
  58279. + /* Enable the top level host channel interrupt. */
  58280. + intr_enable = (1 << hc_num);
  58281. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  58282. +
  58283. + /* Make sure host channel interrupts are enabled. */
  58284. + gintmsk.b.hcintr = 1;
  58285. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  58286. +
  58287. + /*
  58288. + * Program the HCCHARn register with the endpoint characteristics for
  58289. + * the current transfer.
  58290. + */
  58291. + hcchar.d32 = 0;
  58292. + hcchar.b.devaddr = hc->dev_addr;
  58293. + hcchar.b.epnum = hc->ep_num;
  58294. + hcchar.b.epdir = hc->ep_is_in;
  58295. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  58296. + hcchar.b.eptype = hc->ep_type;
  58297. + hcchar.b.mps = hc->max_packet;
  58298. +
  58299. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  58300. +
  58301. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  58302. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  58303. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  58304. + "Max Pkt %d, Multi Cnt %d\n",
  58305. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  58306. + hcchar.b.mps, hcchar.b.multicnt);
  58307. +
  58308. + /*
  58309. + * Program the HCSPLIT register for SPLITs
  58310. + */
  58311. + hcsplt.d32 = 0;
  58312. + if (hc->do_split) {
  58313. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  58314. + hc->hc_num,
  58315. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  58316. + hcsplt.b.compsplt = hc->complete_split;
  58317. + hcsplt.b.xactpos = hc->xact_pos;
  58318. + hcsplt.b.hubaddr = hc->hub_addr;
  58319. + hcsplt.b.prtaddr = hc->port_addr;
  58320. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  58321. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  58322. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  58323. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  58324. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  58325. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  58326. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  58327. + }
  58328. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  58329. +
  58330. +}
  58331. +
  58332. +/**
  58333. + * Attempts to halt a host channel. This function should only be called in
  58334. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  58335. + * normal circumstances in DMA mode, the controller halts the channel when the
  58336. + * transfer is complete or a condition occurs that requires application
  58337. + * intervention.
  58338. + *
  58339. + * In slave mode, checks for a free request queue entry, then sets the Channel
  58340. + * Enable and Channel Disable bits of the Host Channel Characteristics
  58341. + * register of the specified channel to intiate the halt. If there is no free
  58342. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  58343. + * register to flush requests for this channel. In the latter case, sets a
  58344. + * flag to indicate that the host channel needs to be halted when a request
  58345. + * queue slot is open.
  58346. + *
  58347. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  58348. + * HCCHARn register. The controller ensures there is space in the request
  58349. + * queue before submitting the halt request.
  58350. + *
  58351. + * Some time may elapse before the core flushes any posted requests for this
  58352. + * host channel and halts. The Channel Halted interrupt handler completes the
  58353. + * deactivation of the host channel.
  58354. + *
  58355. + * @param core_if Controller register interface.
  58356. + * @param hc Host channel to halt.
  58357. + * @param halt_status Reason for halting the channel.
  58358. + */
  58359. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  58360. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  58361. +{
  58362. + gnptxsts_data_t nptxsts;
  58363. + hptxsts_data_t hptxsts;
  58364. + hcchar_data_t hcchar;
  58365. + dwc_otg_hc_regs_t *hc_regs;
  58366. + dwc_otg_core_global_regs_t *global_regs;
  58367. + dwc_otg_host_global_regs_t *host_global_regs;
  58368. +
  58369. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58370. + global_regs = core_if->core_global_regs;
  58371. + host_global_regs = core_if->host_if->host_global_regs;
  58372. +
  58373. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  58374. + "halt_status = %d\n", halt_status);
  58375. +
  58376. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  58377. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  58378. + /*
  58379. + * Disable all channel interrupts except Ch Halted. The QTD
  58380. + * and QH state associated with this transfer has been cleared
  58381. + * (in the case of URB_DEQUEUE), so the channel needs to be
  58382. + * shut down carefully to prevent crashes.
  58383. + */
  58384. + hcintmsk_data_t hcintmsk;
  58385. + hcintmsk.d32 = 0;
  58386. + hcintmsk.b.chhltd = 1;
  58387. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  58388. +
  58389. + /*
  58390. + * Make sure no other interrupts besides halt are currently
  58391. + * pending. Handling another interrupt could cause a crash due
  58392. + * to the QTD and QH state.
  58393. + */
  58394. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  58395. +
  58396. + /*
  58397. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  58398. + * even if the channel was already halted for some other
  58399. + * reason.
  58400. + */
  58401. + hc->halt_status = halt_status;
  58402. +
  58403. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58404. + if (hcchar.b.chen == 0) {
  58405. + /*
  58406. + * The channel is either already halted or it hasn't
  58407. + * started yet. In DMA mode, the transfer may halt if
  58408. + * it finishes normally or a condition occurs that
  58409. + * requires driver intervention. Don't want to halt
  58410. + * the channel again. In either Slave or DMA mode,
  58411. + * it's possible that the transfer has been assigned
  58412. + * to a channel, but not started yet when an URB is
  58413. + * dequeued. Don't want to halt a channel that hasn't
  58414. + * started yet.
  58415. + */
  58416. + return;
  58417. + }
  58418. + }
  58419. + if (hc->halt_pending) {
  58420. + /*
  58421. + * A halt has already been issued for this channel. This might
  58422. + * happen when a transfer is aborted by a higher level in
  58423. + * the stack.
  58424. + */
  58425. +#ifdef DEBUG
  58426. + DWC_PRINTF
  58427. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  58428. + __func__, hc->hc_num);
  58429. +
  58430. +#endif
  58431. + return;
  58432. + }
  58433. +
  58434. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58435. +
  58436. + /* No need to set the bit in DDMA for disabling the channel */
  58437. + //TODO check it everywhere channel is disabled
  58438. + if (!core_if->core_params->dma_desc_enable)
  58439. + hcchar.b.chen = 1;
  58440. + hcchar.b.chdis = 1;
  58441. +
  58442. + if (!core_if->dma_enable) {
  58443. + /* Check for space in the request queue to issue the halt. */
  58444. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  58445. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  58446. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  58447. + if (nptxsts.b.nptxqspcavail == 0) {
  58448. + hcchar.b.chen = 0;
  58449. + }
  58450. + } else {
  58451. + hptxsts.d32 =
  58452. + DWC_READ_REG32(&host_global_regs->hptxsts);
  58453. + if ((hptxsts.b.ptxqspcavail == 0)
  58454. + || (core_if->queuing_high_bandwidth)) {
  58455. + hcchar.b.chen = 0;
  58456. + }
  58457. + }
  58458. + }
  58459. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58460. +
  58461. + hc->halt_status = halt_status;
  58462. +
  58463. + if (hcchar.b.chen) {
  58464. + hc->halt_pending = 1;
  58465. + hc->halt_on_queue = 0;
  58466. + } else {
  58467. + hc->halt_on_queue = 1;
  58468. + }
  58469. +
  58470. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58471. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  58472. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  58473. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  58474. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  58475. +
  58476. + return;
  58477. +}
  58478. +
  58479. +/**
  58480. + * Clears the transfer state for a host channel. This function is normally
  58481. + * called after a transfer is done and the host channel is being released.
  58482. + *
  58483. + * @param core_if Programming view of DWC_otg controller.
  58484. + * @param hc Identifies the host channel to clean up.
  58485. + */
  58486. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58487. +{
  58488. + dwc_otg_hc_regs_t *hc_regs;
  58489. +
  58490. + hc->xfer_started = 0;
  58491. +
  58492. + /*
  58493. + * Clear channel interrupt enables and any unhandled channel interrupt
  58494. + * conditions.
  58495. + */
  58496. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58497. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  58498. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  58499. +#ifdef DEBUG
  58500. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  58501. +#endif
  58502. +}
  58503. +
  58504. +/**
  58505. + * Sets the channel property that indicates in which frame a periodic transfer
  58506. + * should occur. This is always set to the _next_ frame. This function has no
  58507. + * effect on non-periodic transfers.
  58508. + *
  58509. + * @param core_if Programming view of DWC_otg controller.
  58510. + * @param hc Identifies the host channel to set up and its properties.
  58511. + * @param hcchar Current value of the HCCHAR register for the specified host
  58512. + * channel.
  58513. + */
  58514. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  58515. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  58516. +{
  58517. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58518. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58519. + hfnum_data_t hfnum;
  58520. + hfnum.d32 =
  58521. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  58522. +
  58523. + /* 1 if _next_ frame is odd, 0 if it's even */
  58524. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  58525. +#ifdef DEBUG
  58526. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  58527. + && !hc->complete_split) {
  58528. + switch (hfnum.b.frnum & 0x7) {
  58529. + case 7:
  58530. + core_if->hfnum_7_samples++;
  58531. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  58532. + break;
  58533. + case 0:
  58534. + core_if->hfnum_0_samples++;
  58535. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  58536. + break;
  58537. + default:
  58538. + core_if->hfnum_other_samples++;
  58539. + core_if->hfnum_other_frrem_accum +=
  58540. + hfnum.b.frrem;
  58541. + break;
  58542. + }
  58543. + }
  58544. +#endif
  58545. + }
  58546. +}
  58547. +
  58548. +#ifdef DEBUG
  58549. +void hc_xfer_timeout(void *ptr)
  58550. +{
  58551. + hc_xfer_info_t *xfer_info = NULL;
  58552. + int hc_num = 0;
  58553. +
  58554. + if (ptr)
  58555. + xfer_info = (hc_xfer_info_t *) ptr;
  58556. +
  58557. + if (!xfer_info->hc) {
  58558. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  58559. + return;
  58560. + }
  58561. +
  58562. + hc_num = xfer_info->hc->hc_num;
  58563. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  58564. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  58565. + xfer_info->core_if->start_hcchar_val[hc_num]);
  58566. +}
  58567. +#endif
  58568. +
  58569. +void ep_xfer_timeout(void *ptr)
  58570. +{
  58571. + ep_xfer_info_t *xfer_info = NULL;
  58572. + int ep_num = 0;
  58573. + dctl_data_t dctl = {.d32 = 0 };
  58574. + gintsts_data_t gintsts = {.d32 = 0 };
  58575. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58576. +
  58577. + if (ptr)
  58578. + xfer_info = (ep_xfer_info_t *) ptr;
  58579. +
  58580. + if (!xfer_info->ep) {
  58581. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  58582. + return;
  58583. + }
  58584. +
  58585. + ep_num = xfer_info->ep->num;
  58586. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  58587. + /* Put the sate to 2 as it was time outed */
  58588. + xfer_info->state = 2;
  58589. +
  58590. + dctl.d32 =
  58591. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  58592. + gintsts.d32 =
  58593. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  58594. + gintmsk.d32 =
  58595. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  58596. +
  58597. + if (!gintmsk.b.goutnakeff) {
  58598. + /* Unmask it */
  58599. + gintmsk.b.goutnakeff = 1;
  58600. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  58601. + gintmsk.d32);
  58602. +
  58603. + }
  58604. +
  58605. + if (!gintsts.b.goutnakeff) {
  58606. + dctl.b.sgoutnak = 1;
  58607. + }
  58608. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  58609. + dctl.d32);
  58610. +
  58611. +}
  58612. +
  58613. +void set_pid_isoc(dwc_hc_t * hc)
  58614. +{
  58615. + /* Set up the initial PID for the transfer. */
  58616. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  58617. + if (hc->ep_is_in) {
  58618. + if (hc->multi_count == 1) {
  58619. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58620. + } else if (hc->multi_count == 2) {
  58621. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  58622. + } else {
  58623. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  58624. + }
  58625. + } else {
  58626. + if (hc->multi_count == 1) {
  58627. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58628. + } else {
  58629. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  58630. + }
  58631. + }
  58632. + } else {
  58633. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58634. + }
  58635. +}
  58636. +
  58637. +/**
  58638. + * This function does the setup for a data transfer for a host channel and
  58639. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  58640. + * Slave mode, the caller must ensure that there is sufficient space in the
  58641. + * request queue and Tx Data FIFO.
  58642. + *
  58643. + * For an OUT transfer in Slave mode, it loads a data packet into the
  58644. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  58645. + * the Host ISR.
  58646. + *
  58647. + * For an IN transfer in Slave mode, a data packet is requested. The data
  58648. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  58649. + * additional data packets are requested in the Host ISR.
  58650. + *
  58651. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  58652. + * register along with a packet count of 1 and the channel is enabled. This
  58653. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  58654. + * simply set to 0 since no data transfer occurs in this case.
  58655. + *
  58656. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  58657. + * all the information required to perform the subsequent data transfer. In
  58658. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  58659. + * controller performs the entire PING protocol, then starts the data
  58660. + * transfer.
  58661. + *
  58662. + * @param core_if Programming view of DWC_otg controller.
  58663. + * @param hc Information needed to initialize the host channel. The xfer_len
  58664. + * value may be reduced to accommodate the max widths of the XferSize and
  58665. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  58666. + * to reflect the final xfer_len value.
  58667. + */
  58668. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58669. +{
  58670. + hcchar_data_t hcchar;
  58671. + hctsiz_data_t hctsiz;
  58672. + uint16_t num_packets;
  58673. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  58674. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  58675. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58676. +
  58677. + hctsiz.d32 = 0;
  58678. +
  58679. + if (hc->do_ping) {
  58680. + if (!core_if->dma_enable) {
  58681. + dwc_otg_hc_do_ping(core_if, hc);
  58682. + hc->xfer_started = 1;
  58683. + return;
  58684. + } else {
  58685. + hctsiz.b.dopng = 1;
  58686. + }
  58687. + }
  58688. +
  58689. + if (hc->do_split) {
  58690. + num_packets = 1;
  58691. +
  58692. + if (hc->complete_split && !hc->ep_is_in) {
  58693. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  58694. + * core doesn't expect any data written to the FIFO */
  58695. + hc->xfer_len = 0;
  58696. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  58697. + hc->xfer_len = hc->max_packet;
  58698. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  58699. + hc->xfer_len = 188;
  58700. + }
  58701. +
  58702. + hctsiz.b.xfersize = hc->xfer_len;
  58703. + } else {
  58704. + /*
  58705. + * Ensure that the transfer length and packet count will fit
  58706. + * in the widths allocated for them in the HCTSIZn register.
  58707. + */
  58708. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58709. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58710. + /*
  58711. + * Make sure the transfer size is no larger than one
  58712. + * (micro)frame's worth of data. (A check was done
  58713. + * when the periodic transfer was accepted to ensure
  58714. + * that a (micro)frame's worth of data can be
  58715. + * programmed into a channel.)
  58716. + */
  58717. + uint32_t max_periodic_len =
  58718. + hc->multi_count * hc->max_packet;
  58719. + if (hc->xfer_len > max_periodic_len) {
  58720. + hc->xfer_len = max_periodic_len;
  58721. + } else {
  58722. + }
  58723. + } else if (hc->xfer_len > max_hc_xfer_size) {
  58724. + /* Make sure that xfer_len is a multiple of max packet size. */
  58725. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  58726. + }
  58727. +
  58728. + if (hc->xfer_len > 0) {
  58729. + num_packets =
  58730. + (hc->xfer_len + hc->max_packet -
  58731. + 1) / hc->max_packet;
  58732. + if (num_packets > max_hc_pkt_count) {
  58733. + num_packets = max_hc_pkt_count;
  58734. + hc->xfer_len = num_packets * hc->max_packet;
  58735. + }
  58736. + } else {
  58737. + /* Need 1 packet for transfer length of 0. */
  58738. + num_packets = 1;
  58739. + }
  58740. +
  58741. + if (hc->ep_is_in) {
  58742. + /* Always program an integral # of max packets for IN transfers. */
  58743. + hc->xfer_len = num_packets * hc->max_packet;
  58744. + }
  58745. +
  58746. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58747. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58748. + /*
  58749. + * Make sure that the multi_count field matches the
  58750. + * actual transfer length.
  58751. + */
  58752. + hc->multi_count = num_packets;
  58753. + }
  58754. +
  58755. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58756. + set_pid_isoc(hc);
  58757. +
  58758. + hctsiz.b.xfersize = hc->xfer_len;
  58759. + }
  58760. +
  58761. + hc->start_pkt_count = num_packets;
  58762. + hctsiz.b.pktcnt = num_packets;
  58763. + hctsiz.b.pid = hc->data_pid_start;
  58764. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58765. +
  58766. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58767. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  58768. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  58769. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58770. +
  58771. + if (core_if->dma_enable) {
  58772. + dwc_dma_t dma_addr;
  58773. + if (hc->align_buff) {
  58774. + dma_addr = hc->align_buff;
  58775. + } else {
  58776. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  58777. + }
  58778. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  58779. + }
  58780. +
  58781. + /* Start the split */
  58782. + if (hc->do_split) {
  58783. + hcsplt_data_t hcsplt;
  58784. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  58785. + hcsplt.b.spltena = 1;
  58786. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  58787. + }
  58788. +
  58789. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58790. + hcchar.b.multicnt = hc->multi_count;
  58791. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58792. +#ifdef DEBUG
  58793. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58794. + if (hcchar.b.chdis) {
  58795. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58796. + __func__, hc->hc_num, hcchar.d32);
  58797. + }
  58798. +#endif
  58799. +
  58800. + /* Set host channel enable after all other setup is complete. */
  58801. + hcchar.b.chen = 1;
  58802. + hcchar.b.chdis = 0;
  58803. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58804. +
  58805. + hc->xfer_started = 1;
  58806. + hc->requests++;
  58807. +
  58808. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  58809. + /* Load OUT packet into the appropriate Tx FIFO. */
  58810. + dwc_otg_hc_write_packet(core_if, hc);
  58811. + }
  58812. +#ifdef DEBUG
  58813. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58814. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  58815. + hc->hc_num, core_if);//GRAYG
  58816. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58817. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58818. +
  58819. + /* Start a timer for this transfer. */
  58820. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58821. + }
  58822. +#endif
  58823. +}
  58824. +
  58825. +/**
  58826. + * This function does the setup for a data transfer for a host channel
  58827. + * and starts the transfer in Descriptor DMA mode.
  58828. + *
  58829. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  58830. + * Sets PID and NTD values. For periodic transfers
  58831. + * initializes SCHED_INFO field with micro-frame bitmap.
  58832. + *
  58833. + * Initializes HCDMA register with descriptor list address and CTD value
  58834. + * then starts the transfer via enabling the channel.
  58835. + *
  58836. + * @param core_if Programming view of DWC_otg controller.
  58837. + * @param hc Information needed to initialize the host channel.
  58838. + */
  58839. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58840. +{
  58841. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58842. + hcchar_data_t hcchar;
  58843. + hctsiz_data_t hctsiz;
  58844. + hcdma_data_t hcdma;
  58845. +
  58846. + hctsiz.d32 = 0;
  58847. +
  58848. + if (hc->do_ping)
  58849. + hctsiz.b_ddma.dopng = 1;
  58850. +
  58851. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58852. + set_pid_isoc(hc);
  58853. +
  58854. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  58855. + hctsiz.b_ddma.pid = hc->data_pid_start;
  58856. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  58857. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  58858. +
  58859. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58860. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58861. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  58862. +
  58863. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58864. +
  58865. + hcdma.d32 = 0;
  58866. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  58867. +
  58868. + /* Always start from first descriptor. */
  58869. + hcdma.b.ctd = 0;
  58870. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  58871. +
  58872. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58873. + hcchar.b.multicnt = hc->multi_count;
  58874. +
  58875. +#ifdef DEBUG
  58876. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58877. + if (hcchar.b.chdis) {
  58878. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58879. + __func__, hc->hc_num, hcchar.d32);
  58880. + }
  58881. +#endif
  58882. +
  58883. + /* Set host channel enable after all other setup is complete. */
  58884. + hcchar.b.chen = 1;
  58885. + hcchar.b.chdis = 0;
  58886. +
  58887. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58888. +
  58889. + hc->xfer_started = 1;
  58890. + hc->requests++;
  58891. +
  58892. +#ifdef DEBUG
  58893. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  58894. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  58895. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  58896. + hc->hc_num, core_if);//GRAYG
  58897. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58898. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58899. + /* Start a timer for this transfer. */
  58900. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58901. + }
  58902. +#endif
  58903. +
  58904. +}
  58905. +
  58906. +/**
  58907. + * This function continues a data transfer that was started by previous call
  58908. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  58909. + * sufficient space in the request queue and Tx Data FIFO. This function
  58910. + * should only be called in Slave mode. In DMA mode, the controller acts
  58911. + * autonomously to complete transfers programmed to a host channel.
  58912. + *
  58913. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  58914. + * if there is any data remaining to be queued. For an IN transfer, another
  58915. + * data packet is always requested. For the SETUP phase of a control transfer,
  58916. + * this function does nothing.
  58917. + *
  58918. + * @return 1 if a new request is queued, 0 if no more requests are required
  58919. + * for this transfer.
  58920. + */
  58921. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58922. +{
  58923. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58924. +
  58925. + if (hc->do_split) {
  58926. + /* SPLITs always queue just once per channel */
  58927. + return 0;
  58928. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  58929. + /* SETUPs are queued only once since they can't be NAKed. */
  58930. + return 0;
  58931. + } else if (hc->ep_is_in) {
  58932. + /*
  58933. + * Always queue another request for other IN transfers. If
  58934. + * back-to-back INs are issued and NAKs are received for both,
  58935. + * the driver may still be processing the first NAK when the
  58936. + * second NAK is received. When the interrupt handler clears
  58937. + * the NAK interrupt for the first NAK, the second NAK will
  58938. + * not be seen. So we can't depend on the NAK interrupt
  58939. + * handler to requeue a NAKed request. Instead, IN requests
  58940. + * are issued each time this function is called. When the
  58941. + * transfer completes, the extra requests for the channel will
  58942. + * be flushed.
  58943. + */
  58944. + hcchar_data_t hcchar;
  58945. + dwc_otg_hc_regs_t *hc_regs =
  58946. + core_if->host_if->hc_regs[hc->hc_num];
  58947. +
  58948. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58949. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58950. + hcchar.b.chen = 1;
  58951. + hcchar.b.chdis = 0;
  58952. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  58953. + hcchar.d32);
  58954. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58955. + hc->requests++;
  58956. + return 1;
  58957. + } else {
  58958. + /* OUT transfers. */
  58959. + if (hc->xfer_count < hc->xfer_len) {
  58960. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58961. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58962. + hcchar_data_t hcchar;
  58963. + dwc_otg_hc_regs_t *hc_regs;
  58964. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58965. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58966. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58967. + }
  58968. +
  58969. + /* Load OUT packet into the appropriate Tx FIFO. */
  58970. + dwc_otg_hc_write_packet(core_if, hc);
  58971. + hc->requests++;
  58972. + return 1;
  58973. + } else {
  58974. + return 0;
  58975. + }
  58976. + }
  58977. +}
  58978. +
  58979. +/**
  58980. + * Starts a PING transfer. This function should only be called in Slave mode.
  58981. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  58982. + */
  58983. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58984. +{
  58985. + hcchar_data_t hcchar;
  58986. + hctsiz_data_t hctsiz;
  58987. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58988. +
  58989. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58990. +
  58991. + hctsiz.d32 = 0;
  58992. + hctsiz.b.dopng = 1;
  58993. + hctsiz.b.pktcnt = 1;
  58994. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58995. +
  58996. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58997. + hcchar.b.chen = 1;
  58998. + hcchar.b.chdis = 0;
  58999. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59000. +}
  59001. +
  59002. +/*
  59003. + * This function writes a packet into the Tx FIFO associated with the Host
  59004. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  59005. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  59006. + * periodic Tx FIFO is written. This function should only be called in Slave
  59007. + * mode.
  59008. + *
  59009. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  59010. + * then number of bytes written to the Tx FIFO.
  59011. + */
  59012. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59013. +{
  59014. + uint32_t i;
  59015. + uint32_t remaining_count;
  59016. + uint32_t byte_count;
  59017. + uint32_t dword_count;
  59018. +
  59019. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  59020. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  59021. +
  59022. + remaining_count = hc->xfer_len - hc->xfer_count;
  59023. + if (remaining_count > hc->max_packet) {
  59024. + byte_count = hc->max_packet;
  59025. + } else {
  59026. + byte_count = remaining_count;
  59027. + }
  59028. +
  59029. + dword_count = (byte_count + 3) / 4;
  59030. +
  59031. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  59032. + /* xfer_buff is DWORD aligned. */
  59033. + for (i = 0; i < dword_count; i++, data_buff++) {
  59034. + DWC_WRITE_REG32(data_fifo, *data_buff);
  59035. + }
  59036. + } else {
  59037. + /* xfer_buff is not DWORD aligned. */
  59038. + for (i = 0; i < dword_count; i++, data_buff++) {
  59039. + uint32_t data;
  59040. + data =
  59041. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  59042. + 16 | data_buff[3] << 24);
  59043. + DWC_WRITE_REG32(data_fifo, data);
  59044. + }
  59045. + }
  59046. +
  59047. + hc->xfer_count += byte_count;
  59048. + hc->xfer_buff += byte_count;
  59049. +}
  59050. +
  59051. +/**
  59052. + * Gets the current USB frame number. This is the frame number from the last
  59053. + * SOF packet.
  59054. + */
  59055. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  59056. +{
  59057. + dsts_data_t dsts;
  59058. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  59059. +
  59060. + /* read current frame/microframe number from DSTS register */
  59061. + return dsts.b.soffn;
  59062. +}
  59063. +
  59064. +/**
  59065. + * Calculates and gets the frame Interval value of HFIR register according PHY
  59066. + * type and speed.The application can modify a value of HFIR register only after
  59067. + * the Port Enable bit of the Host Port Control and Status register
  59068. + * (HPRT.PrtEnaPort) has been set.
  59069. +*/
  59070. +
  59071. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  59072. +{
  59073. + gusbcfg_data_t usbcfg;
  59074. + hwcfg2_data_t hwcfg2;
  59075. + hprt0_data_t hprt0;
  59076. + int clock = 60; // default value
  59077. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  59078. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  59079. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  59080. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59081. + clock = 60;
  59082. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  59083. + clock = 48;
  59084. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59085. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59086. + clock = 30;
  59087. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59088. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59089. + clock = 60;
  59090. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59091. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59092. + clock = 48;
  59093. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  59094. + clock = 48;
  59095. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  59096. + clock = 48;
  59097. + if (hprt0.b.prtspd == 0)
  59098. + /* High speed case */
  59099. + return 125 * clock;
  59100. + else
  59101. + /* FS/LS case */
  59102. + return 1000 * clock;
  59103. +}
  59104. +
  59105. +/**
  59106. + * This function reads a setup packet from the Rx FIFO into the destination
  59107. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  59108. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  59109. + *
  59110. + * @param core_if Programming view of DWC_otg controller.
  59111. + * @param dest Destination buffer for packet data.
  59112. + */
  59113. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  59114. +{
  59115. + device_grxsts_data_t status;
  59116. + /* Get the 8 bytes of a setup transaction data */
  59117. +
  59118. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  59119. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  59120. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  59121. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59122. + status.d32 =
  59123. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  59124. + DWC_DEBUGPL(DBG_ANY,
  59125. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  59126. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  59127. + status.b.fn, status.b.fn);
  59128. + }
  59129. +}
  59130. +
  59131. +/**
  59132. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  59133. + * IN for transmitting packets. It is normally called when the
  59134. + * "Enumeration Done" interrupt occurs.
  59135. + *
  59136. + * @param core_if Programming view of DWC_otg controller.
  59137. + * @param ep The EP0 data.
  59138. + */
  59139. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59140. +{
  59141. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59142. + dsts_data_t dsts;
  59143. + depctl_data_t diepctl;
  59144. + depctl_data_t doepctl;
  59145. + dctl_data_t dctl = {.d32 = 0 };
  59146. +
  59147. + ep->stp_rollover = 0;
  59148. + /* Read the Device Status and Endpoint 0 Control registers */
  59149. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  59150. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  59151. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  59152. +
  59153. + /* Set the MPS of the IN EP based on the enumeration speed */
  59154. + switch (dsts.b.enumspd) {
  59155. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  59156. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  59157. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  59158. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  59159. + break;
  59160. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  59161. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  59162. + break;
  59163. + }
  59164. +
  59165. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  59166. +
  59167. + /* Enable OUT EP for receive */
  59168. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  59169. + doepctl.b.epena = 1;
  59170. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  59171. + }
  59172. +#ifdef VERBOSE
  59173. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  59174. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  59175. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  59176. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  59177. +#endif
  59178. + dctl.b.cgnpinnak = 1;
  59179. +
  59180. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  59181. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  59182. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  59183. +
  59184. +}
  59185. +
  59186. +/**
  59187. + * This function activates an EP. The Device EP control register for
  59188. + * the EP is configured as defined in the ep structure. Note: This
  59189. + * function is not used for EP0.
  59190. + *
  59191. + * @param core_if Programming view of DWC_otg controller.
  59192. + * @param ep The EP to activate.
  59193. + */
  59194. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59195. +{
  59196. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59197. + depctl_data_t depctl;
  59198. + volatile uint32_t *addr;
  59199. + daint_data_t daintmsk = {.d32 = 0 };
  59200. + dcfg_data_t dcfg;
  59201. + uint8_t i;
  59202. +
  59203. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  59204. + (ep->is_in ? "IN" : "OUT"));
  59205. +
  59206. +#ifdef DWC_UTE_PER_IO
  59207. + ep->xiso_frame_num = 0xFFFFFFFF;
  59208. + ep->xiso_active_xfers = 0;
  59209. + ep->xiso_queued_xfers = 0;
  59210. +#endif
  59211. + /* Read DEPCTLn register */
  59212. + if (ep->is_in == 1) {
  59213. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  59214. + daintmsk.ep.in = 1 << ep->num;
  59215. + } else {
  59216. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  59217. + daintmsk.ep.out = 1 << ep->num;
  59218. + }
  59219. +
  59220. + /* If the EP is already active don't change the EP Control
  59221. + * register. */
  59222. + depctl.d32 = DWC_READ_REG32(addr);
  59223. + if (!depctl.b.usbactep) {
  59224. + depctl.b.mps = ep->maxpacket;
  59225. + depctl.b.eptype = ep->type;
  59226. + depctl.b.txfnum = ep->tx_fifo_num;
  59227. +
  59228. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59229. + depctl.b.setd0pid = 1; // ???
  59230. + } else {
  59231. + depctl.b.setd0pid = 1;
  59232. + }
  59233. + depctl.b.usbactep = 1;
  59234. +
  59235. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  59236. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  59237. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59238. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  59239. + break;
  59240. + }
  59241. + core_if->nextep_seq[i] = ep->num;
  59242. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  59243. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59244. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  59245. + dcfg.b.epmscnt++;
  59246. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  59247. +
  59248. + DWC_DEBUGPL(DBG_PCDV,
  59249. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  59250. + __func__, core_if->first_in_nextep_seq);
  59251. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  59252. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  59253. + core_if->nextep_seq[i]);
  59254. + }
  59255. +
  59256. + }
  59257. +
  59258. +
  59259. + DWC_WRITE_REG32(addr, depctl.d32);
  59260. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  59261. + }
  59262. +
  59263. + /* Enable the Interrupt for this EP */
  59264. + if (core_if->multiproc_int_enable) {
  59265. + if (ep->is_in == 1) {
  59266. + diepmsk_data_t diepmsk = {.d32 = 0 };
  59267. + diepmsk.b.xfercompl = 1;
  59268. + diepmsk.b.timeout = 1;
  59269. + diepmsk.b.epdisabled = 1;
  59270. + diepmsk.b.ahberr = 1;
  59271. + diepmsk.b.intknepmis = 1;
  59272. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  59273. + diepmsk.b.intknepmis = 0;
  59274. + diepmsk.b.txfifoundrn = 1; //?????
  59275. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59276. + diepmsk.b.nak = 1;
  59277. + }
  59278. +
  59279. +
  59280. +
  59281. +/*
  59282. + if (core_if->dma_desc_enable) {
  59283. + diepmsk.b.bna = 1;
  59284. + }
  59285. +*/
  59286. +/*
  59287. + if (core_if->dma_enable) {
  59288. + doepmsk.b.nak = 1;
  59289. + }
  59290. +*/
  59291. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  59292. + diepeachintmsk[ep->num], diepmsk.d32);
  59293. +
  59294. + } else {
  59295. + doepmsk_data_t doepmsk = {.d32 = 0 };
  59296. + doepmsk.b.xfercompl = 1;
  59297. + doepmsk.b.ahberr = 1;
  59298. + doepmsk.b.epdisabled = 1;
  59299. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59300. + doepmsk.b.outtknepdis = 1;
  59301. +
  59302. +/*
  59303. +
  59304. + if (core_if->dma_desc_enable) {
  59305. + doepmsk.b.bna = 1;
  59306. + }
  59307. +*/
  59308. +/*
  59309. + doepmsk.b.babble = 1;
  59310. + doepmsk.b.nyet = 1;
  59311. + doepmsk.b.nak = 1;
  59312. +*/
  59313. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  59314. + doepeachintmsk[ep->num], doepmsk.d32);
  59315. + }
  59316. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  59317. + 0, daintmsk.d32);
  59318. + } else {
  59319. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59320. + if (ep->is_in) {
  59321. + diepmsk_data_t diepmsk = {.d32 = 0 };
  59322. + diepmsk.b.nak = 1;
  59323. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  59324. + } else {
  59325. + doepmsk_data_t doepmsk = {.d32 = 0 };
  59326. + doepmsk.b.outtknepdis = 1;
  59327. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  59328. + }
  59329. + }
  59330. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  59331. + 0, daintmsk.d32);
  59332. + }
  59333. +
  59334. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  59335. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  59336. +
  59337. + ep->stall_clear_flag = 0;
  59338. +
  59339. + return;
  59340. +}
  59341. +
  59342. +/**
  59343. + * This function deactivates an EP. This is done by clearing the USB Active
  59344. + * EP bit in the Device EP control register. Note: This function is not used
  59345. + * for EP0. EP0 cannot be deactivated.
  59346. + *
  59347. + * @param core_if Programming view of DWC_otg controller.
  59348. + * @param ep The EP to deactivate.
  59349. + */
  59350. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59351. +{
  59352. + depctl_data_t depctl = {.d32 = 0 };
  59353. + volatile uint32_t *addr;
  59354. + daint_data_t daintmsk = {.d32 = 0 };
  59355. + dcfg_data_t dcfg;
  59356. + uint8_t i = 0;
  59357. +
  59358. +#ifdef DWC_UTE_PER_IO
  59359. + ep->xiso_frame_num = 0xFFFFFFFF;
  59360. + ep->xiso_active_xfers = 0;
  59361. + ep->xiso_queued_xfers = 0;
  59362. +#endif
  59363. +
  59364. + /* Read DEPCTLn register */
  59365. + if (ep->is_in == 1) {
  59366. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  59367. + daintmsk.ep.in = 1 << ep->num;
  59368. + } else {
  59369. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  59370. + daintmsk.ep.out = 1 << ep->num;
  59371. + }
  59372. +
  59373. + depctl.d32 = DWC_READ_REG32(addr);
  59374. +
  59375. + depctl.b.usbactep = 0;
  59376. +
  59377. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  59378. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  59379. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59380. + if (core_if->nextep_seq[i] == ep->num)
  59381. + break;
  59382. + }
  59383. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  59384. + if (core_if->first_in_nextep_seq == ep->num)
  59385. + core_if->first_in_nextep_seq = i;
  59386. + core_if->nextep_seq[ep->num] = 0xff;
  59387. + depctl.b.nextep = 0;
  59388. + dcfg.d32 =
  59389. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  59390. + dcfg.b.epmscnt--;
  59391. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  59392. + dcfg.d32);
  59393. +
  59394. + DWC_DEBUGPL(DBG_PCDV,
  59395. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  59396. + __func__, core_if->first_in_nextep_seq);
  59397. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  59398. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  59399. + }
  59400. + }
  59401. +
  59402. + if (ep->is_in == 1)
  59403. + depctl.b.txfnum = 0;
  59404. +
  59405. + if (core_if->dma_desc_enable)
  59406. + depctl.b.epdis = 1;
  59407. +
  59408. + DWC_WRITE_REG32(addr, depctl.d32);
  59409. + depctl.d32 = DWC_READ_REG32(addr);
  59410. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  59411. + && depctl.b.epena) {
  59412. + depctl_data_t depctl = {.d32 = 0};
  59413. + if (ep->is_in) {
  59414. + diepint_data_t diepint = {.d32 = 0};
  59415. +
  59416. + depctl.b.snak = 1;
  59417. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59418. + diepctl, depctl.d32);
  59419. + do {
  59420. + dwc_udelay(10);
  59421. + diepint.d32 =
  59422. + DWC_READ_REG32(&core_if->
  59423. + dev_if->in_ep_regs[ep->num]->
  59424. + diepint);
  59425. + } while (!diepint.b.inepnakeff);
  59426. + diepint.b.inepnakeff = 1;
  59427. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59428. + diepint, diepint.d32);
  59429. + depctl.d32 = 0;
  59430. + depctl.b.epdis = 1;
  59431. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59432. + diepctl, depctl.d32);
  59433. + do {
  59434. + dwc_udelay(10);
  59435. + diepint.d32 =
  59436. + DWC_READ_REG32(&core_if->
  59437. + dev_if->in_ep_regs[ep->num]->
  59438. + diepint);
  59439. + } while (!diepint.b.epdisabled);
  59440. + diepint.b.epdisabled = 1;
  59441. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59442. + diepint, diepint.d32);
  59443. + } else {
  59444. + dctl_data_t dctl = {.d32 = 0};
  59445. + gintmsk_data_t gintsts = {.d32 = 0};
  59446. + doepint_data_t doepint = {.d32 = 0};
  59447. + dctl.b.sgoutnak = 1;
  59448. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  59449. + dctl, 0, dctl.d32);
  59450. + do {
  59451. + dwc_udelay(10);
  59452. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  59453. + } while (!gintsts.b.goutnakeff);
  59454. + gintsts.d32 = 0;
  59455. + gintsts.b.goutnakeff = 1;
  59456. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  59457. +
  59458. + depctl.d32 = 0;
  59459. + depctl.b.epdis = 1;
  59460. + depctl.b.snak = 1;
  59461. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  59462. + do
  59463. + {
  59464. + dwc_udelay(10);
  59465. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  59466. + out_ep_regs[ep->num]->doepint);
  59467. + } while (!doepint.b.epdisabled);
  59468. +
  59469. + doepint.b.epdisabled = 1;
  59470. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  59471. +
  59472. + dctl.d32 = 0;
  59473. + dctl.b.cgoutnak = 1;
  59474. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  59475. + }
  59476. + }
  59477. +
  59478. + /* Disable the Interrupt for this EP */
  59479. + if (core_if->multiproc_int_enable) {
  59480. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  59481. + daintmsk.d32, 0);
  59482. +
  59483. + if (ep->is_in == 1) {
  59484. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  59485. + diepeachintmsk[ep->num], 0);
  59486. + } else {
  59487. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  59488. + doepeachintmsk[ep->num], 0);
  59489. + }
  59490. + } else {
  59491. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  59492. + daintmsk.d32, 0);
  59493. + }
  59494. +
  59495. +}
  59496. +
  59497. +/**
  59498. + * This function initializes dma descriptor chain.
  59499. + *
  59500. + * @param core_if Programming view of DWC_otg controller.
  59501. + * @param ep The EP to start the transfer on.
  59502. + */
  59503. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59504. +{
  59505. + dwc_otg_dev_dma_desc_t *dma_desc;
  59506. + uint32_t offset;
  59507. + uint32_t xfer_est;
  59508. + int i;
  59509. + unsigned maxxfer_local, total_len;
  59510. +
  59511. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  59512. + (ep->maxpacket%4)) {
  59513. + maxxfer_local = ep->maxpacket;
  59514. + total_len = ep->xfer_len;
  59515. + } else {
  59516. + maxxfer_local = ep->maxxfer;
  59517. + total_len = ep->total_len;
  59518. + }
  59519. +
  59520. + ep->desc_cnt = (total_len / maxxfer_local) +
  59521. + ((total_len % maxxfer_local) ? 1 : 0);
  59522. +
  59523. + if (!ep->desc_cnt)
  59524. + ep->desc_cnt = 1;
  59525. +
  59526. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  59527. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  59528. +
  59529. + dma_desc = ep->desc_addr;
  59530. + if (maxxfer_local == ep->maxpacket) {
  59531. + if ((total_len % maxxfer_local) &&
  59532. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  59533. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  59534. + (total_len % maxxfer_local);
  59535. + } else
  59536. + xfer_est = ep->desc_cnt * maxxfer_local;
  59537. + } else
  59538. + xfer_est = total_len;
  59539. + offset = 0;
  59540. + for (i = 0; i < ep->desc_cnt; ++i) {
  59541. + /** DMA Descriptor Setup */
  59542. + if (xfer_est > maxxfer_local) {
  59543. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59544. + dma_desc->status.b.l = 0;
  59545. + dma_desc->status.b.ioc = 0;
  59546. + dma_desc->status.b.sp = 0;
  59547. + dma_desc->status.b.bytes = maxxfer_local;
  59548. + dma_desc->buf = ep->dma_addr + offset;
  59549. + dma_desc->status.b.sts = 0;
  59550. + dma_desc->status.b.bs = BS_HOST_READY;
  59551. +
  59552. + xfer_est -= maxxfer_local;
  59553. + offset += maxxfer_local;
  59554. + } else {
  59555. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59556. + dma_desc->status.b.l = 1;
  59557. + dma_desc->status.b.ioc = 1;
  59558. + if (ep->is_in) {
  59559. + dma_desc->status.b.sp =
  59560. + (xfer_est %
  59561. + ep->maxpacket) ? 1 : ((ep->
  59562. + sent_zlp) ? 1 : 0);
  59563. + dma_desc->status.b.bytes = xfer_est;
  59564. + } else {
  59565. + if (maxxfer_local == ep->maxpacket)
  59566. + dma_desc->status.b.bytes = xfer_est;
  59567. + else
  59568. + dma_desc->status.b.bytes =
  59569. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  59570. + }
  59571. +
  59572. + dma_desc->buf = ep->dma_addr + offset;
  59573. + dma_desc->status.b.sts = 0;
  59574. + dma_desc->status.b.bs = BS_HOST_READY;
  59575. + }
  59576. + dma_desc++;
  59577. + }
  59578. +}
  59579. +/**
  59580. + * This function is called when to write ISOC data into appropriate dedicated
  59581. + * periodic FIFO.
  59582. + */
  59583. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  59584. +{
  59585. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59586. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  59587. + dtxfsts_data_t txstatus = {.d32 = 0 };
  59588. + uint32_t len = 0;
  59589. + int epnum = dwc_ep->num;
  59590. + int dwords;
  59591. +
  59592. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  59593. +
  59594. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  59595. +
  59596. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59597. +
  59598. + if (len > dwc_ep->maxpacket) {
  59599. + len = dwc_ep->maxpacket;
  59600. + }
  59601. +
  59602. + dwords = (len + 3) / 4;
  59603. +
  59604. + /* While there is space in the queue and space in the FIFO and
  59605. + * More data to tranfer, Write packets to the Tx FIFO */
  59606. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59607. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  59608. +
  59609. + while (txstatus.b.txfspcavail > dwords &&
  59610. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  59611. + /* Write the FIFO */
  59612. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  59613. +
  59614. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59615. + if (len > dwc_ep->maxpacket) {
  59616. + len = dwc_ep->maxpacket;
  59617. + }
  59618. +
  59619. + dwords = (len + 3) / 4;
  59620. + txstatus.d32 =
  59621. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59622. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  59623. + txstatus.d32);
  59624. + }
  59625. +
  59626. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  59627. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  59628. +
  59629. + return 1;
  59630. +}
  59631. +/**
  59632. + * This function does the setup for a data transfer for an EP and
  59633. + * starts the transfer. For an IN transfer, the packets will be
  59634. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  59635. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  59636. + *
  59637. + * @param core_if Programming view of DWC_otg controller.
  59638. + * @param ep The EP to start the transfer on.
  59639. + */
  59640. +
  59641. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59642. +{
  59643. + depctl_data_t depctl;
  59644. + deptsiz_data_t deptsiz;
  59645. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59646. +
  59647. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59648. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59649. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  59650. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59651. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  59652. + ep->total_len);
  59653. + /* IN endpoint */
  59654. + if (ep->is_in == 1) {
  59655. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59656. + core_if->dev_if->in_ep_regs[ep->num];
  59657. +
  59658. + gnptxsts_data_t gtxstatus;
  59659. +
  59660. + gtxstatus.d32 =
  59661. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59662. +
  59663. + if (core_if->en_multiple_tx_fifo == 0
  59664. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  59665. +#ifdef DEBUG
  59666. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  59667. +#endif
  59668. + return;
  59669. + }
  59670. +
  59671. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59672. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59673. +
  59674. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59675. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59676. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59677. + else
  59678. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  59679. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59680. +
  59681. +
  59682. + /* Zero Length Packet? */
  59683. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59684. + deptsiz.b.xfersize = 0;
  59685. + deptsiz.b.pktcnt = 1;
  59686. + } else {
  59687. + /* Program the transfer size and packet count
  59688. + * as follows: xfersize = N * maxpacket +
  59689. + * short_packet pktcnt = N + (short_packet
  59690. + * exist ? 1 : 0)
  59691. + */
  59692. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59693. + deptsiz.b.pktcnt =
  59694. + (ep->xfer_len - ep->xfer_count - 1 +
  59695. + ep->maxpacket) / ep->maxpacket;
  59696. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59697. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59698. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  59699. + }
  59700. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59701. + deptsiz.b.mc = deptsiz.b.pktcnt;
  59702. + }
  59703. +
  59704. + /* Write the DMA register */
  59705. + if (core_if->dma_enable) {
  59706. + if (core_if->dma_desc_enable == 0) {
  59707. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  59708. + deptsiz.b.mc = 1;
  59709. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59710. + deptsiz.d32);
  59711. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59712. + (uint32_t) ep->dma_addr);
  59713. + } else {
  59714. +#ifdef DWC_UTE_CFI
  59715. + /* The descriptor chain should be already initialized by now */
  59716. + if (ep->buff_mode != BM_STANDARD) {
  59717. + DWC_WRITE_REG32(&in_regs->diepdma,
  59718. + ep->descs_dma_addr);
  59719. + } else {
  59720. +#endif
  59721. + init_dma_desc_chain(core_if, ep);
  59722. + /** DIEPDMAn Register write */
  59723. + DWC_WRITE_REG32(&in_regs->diepdma,
  59724. + ep->dma_desc_addr);
  59725. +#ifdef DWC_UTE_CFI
  59726. + }
  59727. +#endif
  59728. + }
  59729. + } else {
  59730. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59731. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  59732. + /**
  59733. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59734. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59735. + * the data will be written into the fifo by the ISR.
  59736. + */
  59737. + if (core_if->en_multiple_tx_fifo == 0) {
  59738. + intr_mask.b.nptxfempty = 1;
  59739. + DWC_MODIFY_REG32
  59740. + (&core_if->core_global_regs->gintmsk,
  59741. + intr_mask.d32, intr_mask.d32);
  59742. + } else {
  59743. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59744. + if (ep->xfer_len > 0) {
  59745. + uint32_t fifoemptymsk = 0;
  59746. + fifoemptymsk = 1 << ep->num;
  59747. + DWC_MODIFY_REG32
  59748. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59749. + 0, fifoemptymsk);
  59750. +
  59751. + }
  59752. + }
  59753. + } else {
  59754. + write_isoc_tx_fifo(core_if, ep);
  59755. + }
  59756. + }
  59757. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59758. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59759. +
  59760. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59761. + dsts_data_t dsts = {.d32 = 0};
  59762. + if (ep->bInterval == 1) {
  59763. + dsts.d32 =
  59764. + DWC_READ_REG32(&core_if->dev_if->
  59765. + dev_global_regs->dsts);
  59766. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59767. + if (ep->frame_num > 0x3FFF) {
  59768. + ep->frm_overrun = 1;
  59769. + ep->frame_num &= 0x3FFF;
  59770. + } else
  59771. + ep->frm_overrun = 0;
  59772. + if (ep->frame_num & 0x1) {
  59773. + depctl.b.setd1pid = 1;
  59774. + } else {
  59775. + depctl.b.setd0pid = 1;
  59776. + }
  59777. + }
  59778. + }
  59779. + /* EP enable, IN data in FIFO */
  59780. + depctl.b.cnak = 1;
  59781. + depctl.b.epena = 1;
  59782. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59783. +
  59784. + } else {
  59785. + /* OUT endpoint */
  59786. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59787. + core_if->dev_if->out_ep_regs[ep->num];
  59788. +
  59789. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59790. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59791. +
  59792. + if (!core_if->dma_desc_enable) {
  59793. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59794. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59795. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59796. + else
  59797. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  59798. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59799. + }
  59800. +
  59801. + /* Program the transfer size and packet count as follows:
  59802. + *
  59803. + * pktcnt = N
  59804. + * xfersize = N * maxpacket
  59805. + */
  59806. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59807. + /* Zero Length Packet */
  59808. + deptsiz.b.xfersize = ep->maxpacket;
  59809. + deptsiz.b.pktcnt = 1;
  59810. + } else {
  59811. + deptsiz.b.pktcnt =
  59812. + (ep->xfer_len - ep->xfer_count +
  59813. + (ep->maxpacket - 1)) / ep->maxpacket;
  59814. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59815. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59816. + }
  59817. + if (!core_if->dma_desc_enable) {
  59818. + ep->xfer_len =
  59819. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  59820. + }
  59821. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59822. + }
  59823. +
  59824. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  59825. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59826. +
  59827. + if (core_if->dma_enable) {
  59828. + if (!core_if->dma_desc_enable) {
  59829. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59830. + deptsiz.d32);
  59831. +
  59832. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59833. + (uint32_t) ep->dma_addr);
  59834. + } else {
  59835. +#ifdef DWC_UTE_CFI
  59836. + /* The descriptor chain should be already initialized by now */
  59837. + if (ep->buff_mode != BM_STANDARD) {
  59838. + DWC_WRITE_REG32(&out_regs->doepdma,
  59839. + ep->descs_dma_addr);
  59840. + } else {
  59841. +#endif
  59842. + /** This is used for interrupt out transfers*/
  59843. + if (!ep->xfer_len)
  59844. + ep->xfer_len = ep->total_len;
  59845. + init_dma_desc_chain(core_if, ep);
  59846. +
  59847. + if (core_if->core_params->dev_out_nak) {
  59848. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59849. + deptsiz.b.pktcnt = (ep->total_len +
  59850. + (ep->maxpacket - 1)) / ep->maxpacket;
  59851. + deptsiz.b.xfersize = ep->total_len;
  59852. + /* Remember initial value of doeptsiz */
  59853. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  59854. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59855. + deptsiz.d32);
  59856. + }
  59857. + }
  59858. + /** DOEPDMAn Register write */
  59859. + DWC_WRITE_REG32(&out_regs->doepdma,
  59860. + ep->dma_desc_addr);
  59861. +#ifdef DWC_UTE_CFI
  59862. + }
  59863. +#endif
  59864. + }
  59865. + } else {
  59866. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59867. + }
  59868. +
  59869. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59870. + dsts_data_t dsts = {.d32 = 0};
  59871. + if (ep->bInterval == 1) {
  59872. + dsts.d32 =
  59873. + DWC_READ_REG32(&core_if->dev_if->
  59874. + dev_global_regs->dsts);
  59875. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59876. + if (ep->frame_num > 0x3FFF) {
  59877. + ep->frm_overrun = 1;
  59878. + ep->frame_num &= 0x3FFF;
  59879. + } else
  59880. + ep->frm_overrun = 0;
  59881. +
  59882. + if (ep->frame_num & 0x1) {
  59883. + depctl.b.setd1pid = 1;
  59884. + } else {
  59885. + depctl.b.setd0pid = 1;
  59886. + }
  59887. + }
  59888. + }
  59889. +
  59890. + /* EP enable */
  59891. + depctl.b.cnak = 1;
  59892. + depctl.b.epena = 1;
  59893. +
  59894. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59895. +
  59896. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  59897. + DWC_READ_REG32(&out_regs->doepctl),
  59898. + DWC_READ_REG32(&out_regs->doeptsiz));
  59899. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  59900. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  59901. + daintmsk),
  59902. + DWC_READ_REG32(&core_if->core_global_regs->
  59903. + gintmsk));
  59904. +
  59905. + /* Timer is scheduling only for out bulk transfers for
  59906. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  59907. + * about received data payload in case of timeout
  59908. + */
  59909. + if (core_if->core_params->dev_out_nak) {
  59910. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59911. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  59912. + core_if->ep_xfer_info[ep->num].ep = ep;
  59913. + core_if->ep_xfer_info[ep->num].state = 1;
  59914. +
  59915. + /* Start a timer for this transfer. */
  59916. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  59917. + }
  59918. + }
  59919. + }
  59920. +}
  59921. +
  59922. +/**
  59923. + * This function setup a zero length transfer in Buffer DMA and
  59924. + * Slave modes for usb requests with zero field set
  59925. + *
  59926. + * @param core_if Programming view of DWC_otg controller.
  59927. + * @param ep The EP to start the transfer on.
  59928. + *
  59929. + */
  59930. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59931. +{
  59932. +
  59933. + depctl_data_t depctl;
  59934. + deptsiz_data_t deptsiz;
  59935. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59936. +
  59937. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59938. + DWC_PRINTF("zero length transfer is called\n");
  59939. +
  59940. + /* IN endpoint */
  59941. + if (ep->is_in == 1) {
  59942. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59943. + core_if->dev_if->in_ep_regs[ep->num];
  59944. +
  59945. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59946. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59947. +
  59948. + deptsiz.b.xfersize = 0;
  59949. + deptsiz.b.pktcnt = 1;
  59950. +
  59951. + /* Write the DMA register */
  59952. + if (core_if->dma_enable) {
  59953. + if (core_if->dma_desc_enable == 0) {
  59954. + deptsiz.b.mc = 1;
  59955. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59956. + deptsiz.d32);
  59957. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59958. + (uint32_t) ep->dma_addr);
  59959. + }
  59960. + } else {
  59961. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59962. + /**
  59963. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59964. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59965. + * the data will be written into the fifo by the ISR.
  59966. + */
  59967. + if (core_if->en_multiple_tx_fifo == 0) {
  59968. + intr_mask.b.nptxfempty = 1;
  59969. + DWC_MODIFY_REG32(&core_if->
  59970. + core_global_regs->gintmsk,
  59971. + intr_mask.d32, intr_mask.d32);
  59972. + } else {
  59973. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59974. + if (ep->xfer_len > 0) {
  59975. + uint32_t fifoemptymsk = 0;
  59976. + fifoemptymsk = 1 << ep->num;
  59977. + DWC_MODIFY_REG32(&core_if->
  59978. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59979. + 0, fifoemptymsk);
  59980. + }
  59981. + }
  59982. + }
  59983. +
  59984. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59985. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59986. + /* EP enable, IN data in FIFO */
  59987. + depctl.b.cnak = 1;
  59988. + depctl.b.epena = 1;
  59989. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59990. +
  59991. + } else {
  59992. + /* OUT endpoint */
  59993. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59994. + core_if->dev_if->out_ep_regs[ep->num];
  59995. +
  59996. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59997. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59998. +
  59999. + /* Zero Length Packet */
  60000. + deptsiz.b.xfersize = ep->maxpacket;
  60001. + deptsiz.b.pktcnt = 1;
  60002. +
  60003. + if (core_if->dma_enable) {
  60004. + if (!core_if->dma_desc_enable) {
  60005. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60006. + deptsiz.d32);
  60007. +
  60008. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60009. + (uint32_t) ep->dma_addr);
  60010. + }
  60011. + } else {
  60012. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60013. + }
  60014. +
  60015. + /* EP enable */
  60016. + depctl.b.cnak = 1;
  60017. + depctl.b.epena = 1;
  60018. +
  60019. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60020. +
  60021. + }
  60022. +}
  60023. +
  60024. +/**
  60025. + * This function does the setup for a data transfer for EP0 and starts
  60026. + * the transfer. For an IN transfer, the packets will be loaded into
  60027. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  60028. + * unloaded from the Rx FIFO in the ISR.
  60029. + *
  60030. + * @param core_if Programming view of DWC_otg controller.
  60031. + * @param ep The EP0 data.
  60032. + */
  60033. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60034. +{
  60035. + depctl_data_t depctl;
  60036. + deptsiz0_data_t deptsiz;
  60037. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60038. + dwc_otg_dev_dma_desc_t *dma_desc;
  60039. +
  60040. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  60041. + "xfer_buff=%p start_xfer_buff=%p \n",
  60042. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  60043. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  60044. +
  60045. + ep->total_len = ep->xfer_len;
  60046. +
  60047. + /* IN endpoint */
  60048. + if (ep->is_in == 1) {
  60049. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60050. + core_if->dev_if->in_ep_regs[0];
  60051. +
  60052. + gnptxsts_data_t gtxstatus;
  60053. +
  60054. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60055. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60056. + if (depctl.b.epena)
  60057. + return;
  60058. + }
  60059. +
  60060. + gtxstatus.d32 =
  60061. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60062. +
  60063. + /* If dedicated FIFO every time flush fifo before enable ep*/
  60064. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  60065. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  60066. +
  60067. + if (core_if->en_multiple_tx_fifo == 0
  60068. + && gtxstatus.b.nptxqspcavail == 0
  60069. + && !core_if->dma_enable) {
  60070. +#ifdef DEBUG
  60071. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60072. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  60073. + DWC_READ_REG32(&in_regs->diepctl));
  60074. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  60075. + deptsiz.d32,
  60076. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60077. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  60078. + gtxstatus.d32);
  60079. +#endif
  60080. + return;
  60081. + }
  60082. +
  60083. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60084. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60085. +
  60086. + /* Zero Length Packet? */
  60087. + if (ep->xfer_len == 0) {
  60088. + deptsiz.b.xfersize = 0;
  60089. + deptsiz.b.pktcnt = 1;
  60090. + } else {
  60091. + /* Program the transfer size and packet count
  60092. + * as follows: xfersize = N * maxpacket +
  60093. + * short_packet pktcnt = N + (short_packet
  60094. + * exist ? 1 : 0)
  60095. + */
  60096. + if (ep->xfer_len > ep->maxpacket) {
  60097. + ep->xfer_len = ep->maxpacket;
  60098. + deptsiz.b.xfersize = ep->maxpacket;
  60099. + } else {
  60100. + deptsiz.b.xfersize = ep->xfer_len;
  60101. + }
  60102. + deptsiz.b.pktcnt = 1;
  60103. +
  60104. + }
  60105. + DWC_DEBUGPL(DBG_PCDV,
  60106. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60107. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60108. + deptsiz.d32);
  60109. +
  60110. + /* Write the DMA register */
  60111. + if (core_if->dma_enable) {
  60112. + if (core_if->dma_desc_enable == 0) {
  60113. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60114. + deptsiz.d32);
  60115. +
  60116. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60117. + (uint32_t) ep->dma_addr);
  60118. + } else {
  60119. + dma_desc = core_if->dev_if->in_desc_addr;
  60120. +
  60121. + /** DMA Descriptor Setup */
  60122. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60123. + dma_desc->status.b.l = 1;
  60124. + dma_desc->status.b.ioc = 1;
  60125. + dma_desc->status.b.sp =
  60126. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60127. + dma_desc->status.b.bytes = ep->xfer_len;
  60128. + dma_desc->buf = ep->dma_addr;
  60129. + dma_desc->status.b.sts = 0;
  60130. + dma_desc->status.b.bs = BS_HOST_READY;
  60131. +
  60132. + /** DIEPDMA0 Register write */
  60133. + DWC_WRITE_REG32(&in_regs->diepdma,
  60134. + core_if->
  60135. + dev_if->dma_in_desc_addr);
  60136. + }
  60137. + } else {
  60138. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60139. + }
  60140. +
  60141. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60142. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60143. + /* EP enable, IN data in FIFO */
  60144. + depctl.b.cnak = 1;
  60145. + depctl.b.epena = 1;
  60146. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60147. +
  60148. + /**
  60149. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60150. + * data will be written into the fifo by the ISR.
  60151. + */
  60152. + if (!core_if->dma_enable) {
  60153. + if (core_if->en_multiple_tx_fifo == 0) {
  60154. + intr_mask.b.nptxfempty = 1;
  60155. + DWC_MODIFY_REG32(&core_if->
  60156. + core_global_regs->gintmsk,
  60157. + intr_mask.d32, intr_mask.d32);
  60158. + } else {
  60159. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60160. + if (ep->xfer_len > 0) {
  60161. + uint32_t fifoemptymsk = 0;
  60162. + fifoemptymsk |= 1 << ep->num;
  60163. + DWC_MODIFY_REG32(&core_if->
  60164. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60165. + 0, fifoemptymsk);
  60166. + }
  60167. + }
  60168. + }
  60169. + } else {
  60170. + /* OUT endpoint */
  60171. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60172. + core_if->dev_if->out_ep_regs[0];
  60173. +
  60174. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60175. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60176. +
  60177. + /* Program the transfer size and packet count as follows:
  60178. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  60179. + * pktcnt = N */
  60180. + /* Zero Length Packet */
  60181. + deptsiz.b.xfersize = ep->maxpacket;
  60182. + deptsiz.b.pktcnt = 1;
  60183. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  60184. + deptsiz.b.supcnt = 3;
  60185. +
  60186. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  60187. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60188. +
  60189. + if (core_if->dma_enable) {
  60190. + if (!core_if->dma_desc_enable) {
  60191. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60192. + deptsiz.d32);
  60193. +
  60194. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60195. + (uint32_t) ep->dma_addr);
  60196. + } else {
  60197. + dma_desc = core_if->dev_if->out_desc_addr;
  60198. +
  60199. + /** DMA Descriptor Setup */
  60200. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60201. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60202. + dma_desc->status.b.mtrf = 0;
  60203. + dma_desc->status.b.sr = 0;
  60204. + }
  60205. + dma_desc->status.b.l = 1;
  60206. + dma_desc->status.b.ioc = 1;
  60207. + dma_desc->status.b.bytes = ep->maxpacket;
  60208. + dma_desc->buf = ep->dma_addr;
  60209. + dma_desc->status.b.sts = 0;
  60210. + dma_desc->status.b.bs = BS_HOST_READY;
  60211. +
  60212. + /** DOEPDMA0 Register write */
  60213. + DWC_WRITE_REG32(&out_regs->doepdma,
  60214. + core_if->dev_if->
  60215. + dma_out_desc_addr);
  60216. + }
  60217. + } else {
  60218. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60219. + }
  60220. +
  60221. + /* EP enable */
  60222. + depctl.b.cnak = 1;
  60223. + depctl.b.epena = 1;
  60224. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  60225. + }
  60226. +}
  60227. +
  60228. +/**
  60229. + * This function continues control IN transfers started by
  60230. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  60231. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  60232. + * bit for the packet count.
  60233. + *
  60234. + * @param core_if Programming view of DWC_otg controller.
  60235. + * @param ep The EP0 data.
  60236. + */
  60237. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60238. +{
  60239. + depctl_data_t depctl;
  60240. + deptsiz0_data_t deptsiz;
  60241. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60242. + dwc_otg_dev_dma_desc_t *dma_desc;
  60243. +
  60244. + if (ep->is_in == 1) {
  60245. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60246. + core_if->dev_if->in_ep_regs[0];
  60247. + gnptxsts_data_t tx_status = {.d32 = 0 };
  60248. +
  60249. + tx_status.d32 =
  60250. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60251. + /** @todo Should there be check for room in the Tx
  60252. + * Status Queue. If not remove the code above this comment. */
  60253. +
  60254. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60255. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60256. +
  60257. + /* Program the transfer size and packet count
  60258. + * as follows: xfersize = N * maxpacket +
  60259. + * short_packet pktcnt = N + (short_packet
  60260. + * exist ? 1 : 0)
  60261. + */
  60262. +
  60263. + if (core_if->dma_desc_enable == 0) {
  60264. + deptsiz.b.xfersize =
  60265. + (ep->total_len - ep->xfer_count) >
  60266. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  60267. + ep->xfer_count);
  60268. + deptsiz.b.pktcnt = 1;
  60269. + if (core_if->dma_enable == 0) {
  60270. + ep->xfer_len += deptsiz.b.xfersize;
  60271. + } else {
  60272. + ep->xfer_len = deptsiz.b.xfersize;
  60273. + }
  60274. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60275. + } else {
  60276. + ep->xfer_len =
  60277. + (ep->total_len - ep->xfer_count) >
  60278. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  60279. + ep->xfer_count);
  60280. +
  60281. + dma_desc = core_if->dev_if->in_desc_addr;
  60282. +
  60283. + /** DMA Descriptor Setup */
  60284. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60285. + dma_desc->status.b.l = 1;
  60286. + dma_desc->status.b.ioc = 1;
  60287. + dma_desc->status.b.sp =
  60288. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60289. + dma_desc->status.b.bytes = ep->xfer_len;
  60290. + dma_desc->buf = ep->dma_addr;
  60291. + dma_desc->status.b.sts = 0;
  60292. + dma_desc->status.b.bs = BS_HOST_READY;
  60293. +
  60294. + /** DIEPDMA0 Register write */
  60295. + DWC_WRITE_REG32(&in_regs->diepdma,
  60296. + core_if->dev_if->dma_in_desc_addr);
  60297. + }
  60298. +
  60299. + DWC_DEBUGPL(DBG_PCDV,
  60300. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60301. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60302. + deptsiz.d32);
  60303. +
  60304. + /* Write the DMA register */
  60305. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  60306. + if (core_if->dma_desc_enable == 0)
  60307. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60308. + (uint32_t) ep->dma_addr);
  60309. + }
  60310. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60311. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60312. + /* EP enable, IN data in FIFO */
  60313. + depctl.b.cnak = 1;
  60314. + depctl.b.epena = 1;
  60315. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60316. +
  60317. + /**
  60318. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60319. + * data will be written into the fifo by the ISR.
  60320. + */
  60321. + if (!core_if->dma_enable) {
  60322. + if (core_if->en_multiple_tx_fifo == 0) {
  60323. + /* First clear it from GINTSTS */
  60324. + intr_mask.b.nptxfempty = 1;
  60325. + DWC_MODIFY_REG32(&core_if->
  60326. + core_global_regs->gintmsk,
  60327. + intr_mask.d32, intr_mask.d32);
  60328. +
  60329. + } else {
  60330. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60331. + if (ep->xfer_len > 0) {
  60332. + uint32_t fifoemptymsk = 0;
  60333. + fifoemptymsk |= 1 << ep->num;
  60334. + DWC_MODIFY_REG32(&core_if->
  60335. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60336. + 0, fifoemptymsk);
  60337. + }
  60338. + }
  60339. + }
  60340. + } else {
  60341. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60342. + core_if->dev_if->out_ep_regs[0];
  60343. +
  60344. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60345. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60346. +
  60347. + /* Program the transfer size and packet count
  60348. + * as follows: xfersize = N * maxpacket +
  60349. + * short_packet pktcnt = N + (short_packet
  60350. + * exist ? 1 : 0)
  60351. + */
  60352. + deptsiz.b.xfersize = ep->maxpacket;
  60353. + deptsiz.b.pktcnt = 1;
  60354. +
  60355. + if (core_if->dma_desc_enable == 0) {
  60356. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60357. + } else {
  60358. + dma_desc = core_if->dev_if->out_desc_addr;
  60359. +
  60360. + /** DMA Descriptor Setup */
  60361. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60362. + dma_desc->status.b.l = 1;
  60363. + dma_desc->status.b.ioc = 1;
  60364. + dma_desc->status.b.bytes = ep->maxpacket;
  60365. + dma_desc->buf = ep->dma_addr;
  60366. + dma_desc->status.b.sts = 0;
  60367. + dma_desc->status.b.bs = BS_HOST_READY;
  60368. +
  60369. + /** DOEPDMA0 Register write */
  60370. + DWC_WRITE_REG32(&out_regs->doepdma,
  60371. + core_if->dev_if->dma_out_desc_addr);
  60372. + }
  60373. +
  60374. + DWC_DEBUGPL(DBG_PCDV,
  60375. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60376. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60377. + deptsiz.d32);
  60378. +
  60379. + /* Write the DMA register */
  60380. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  60381. + if (core_if->dma_desc_enable == 0)
  60382. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60383. + (uint32_t) ep->dma_addr);
  60384. +
  60385. + }
  60386. +
  60387. + /* EP enable, IN data in FIFO */
  60388. + depctl.b.cnak = 1;
  60389. + depctl.b.epena = 1;
  60390. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60391. +
  60392. + }
  60393. +}
  60394. +
  60395. +#ifdef DEBUG
  60396. +void dump_msg(const u8 * buf, unsigned int length)
  60397. +{
  60398. + unsigned int start, num, i;
  60399. + char line[52], *p;
  60400. +
  60401. + if (length >= 512)
  60402. + return;
  60403. + start = 0;
  60404. + while (length > 0) {
  60405. + num = length < 16u ? length : 16u;
  60406. + p = line;
  60407. + for (i = 0; i < num; ++i) {
  60408. + if (i == 8)
  60409. + *p++ = ' ';
  60410. + DWC_SPRINTF(p, " %02x", buf[i]);
  60411. + p += 3;
  60412. + }
  60413. + *p = 0;
  60414. + DWC_PRINTF("%6x: %s\n", start, line);
  60415. + buf += num;
  60416. + start += num;
  60417. + length -= num;
  60418. + }
  60419. +}
  60420. +#else
  60421. +static inline void dump_msg(const u8 * buf, unsigned int length)
  60422. +{
  60423. +}
  60424. +#endif
  60425. +
  60426. +/**
  60427. + * This function writes a packet into the Tx FIFO associated with the
  60428. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  60429. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  60430. + * with all packets for the next micro-frame.
  60431. + *
  60432. + * @param core_if Programming view of DWC_otg controller.
  60433. + * @param ep The EP to write packet for.
  60434. + * @param dma Indicates if DMA is being used.
  60435. + */
  60436. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  60437. + int dma)
  60438. +{
  60439. + /**
  60440. + * The buffer is padded to DWORD on a per packet basis in
  60441. + * slave/dma mode if the MPS is not DWORD aligned. The last
  60442. + * packet, if short, is also padded to a multiple of DWORD.
  60443. + *
  60444. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  60445. + * multiple of DWORD in length
  60446. + *
  60447. + * ep->xfer_len can be any number of bytes
  60448. + *
  60449. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  60450. + * packet
  60451. + *
  60452. + * FIFO access is DWORD */
  60453. +
  60454. + uint32_t i;
  60455. + uint32_t byte_count;
  60456. + uint32_t dword_count;
  60457. + uint32_t *fifo;
  60458. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  60459. +
  60460. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  60461. + ep);
  60462. + if (ep->xfer_count >= ep->xfer_len) {
  60463. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  60464. + return;
  60465. + }
  60466. +
  60467. + /* Find the byte length of the packet either short packet or MPS */
  60468. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  60469. + byte_count = ep->xfer_len - ep->xfer_count;
  60470. + } else {
  60471. + byte_count = ep->maxpacket;
  60472. + }
  60473. +
  60474. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  60475. + * is not a multiple of DWORD */
  60476. + dword_count = (byte_count + 3) / 4;
  60477. +
  60478. +#ifdef VERBOSE
  60479. + dump_msg(ep->xfer_buff, byte_count);
  60480. +#endif
  60481. +
  60482. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  60483. + * intialized? What should this be? */
  60484. +
  60485. + fifo = core_if->data_fifo[ep->num];
  60486. +
  60487. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  60488. + fifo, data_buff, *data_buff, byte_count);
  60489. +
  60490. + if (!dma) {
  60491. + for (i = 0; i < dword_count; i++, data_buff++) {
  60492. + DWC_WRITE_REG32(fifo, *data_buff);
  60493. + }
  60494. + }
  60495. +
  60496. + ep->xfer_count += byte_count;
  60497. + ep->xfer_buff += byte_count;
  60498. + ep->dma_addr += byte_count;
  60499. +}
  60500. +
  60501. +/**
  60502. + * Set the EP STALL.
  60503. + *
  60504. + * @param core_if Programming view of DWC_otg controller.
  60505. + * @param ep The EP to set the stall on.
  60506. + */
  60507. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60508. +{
  60509. + depctl_data_t depctl;
  60510. + volatile uint32_t *depctl_addr;
  60511. +
  60512. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60513. + (ep->is_in ? "IN" : "OUT"));
  60514. +
  60515. + if (ep->is_in == 1) {
  60516. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60517. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60518. +
  60519. + /* set the disable and stall bits */
  60520. + if (depctl.b.epena) {
  60521. + depctl.b.epdis = 1;
  60522. + }
  60523. + depctl.b.stall = 1;
  60524. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60525. + } else {
  60526. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60527. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60528. +
  60529. + /* set the stall bit */
  60530. + depctl.b.stall = 1;
  60531. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60532. + }
  60533. +
  60534. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60535. +
  60536. + return;
  60537. +}
  60538. +
  60539. +/**
  60540. + * Clear the EP STALL.
  60541. + *
  60542. + * @param core_if Programming view of DWC_otg controller.
  60543. + * @param ep The EP to clear stall from.
  60544. + */
  60545. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60546. +{
  60547. + depctl_data_t depctl;
  60548. + volatile uint32_t *depctl_addr;
  60549. +
  60550. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60551. + (ep->is_in ? "IN" : "OUT"));
  60552. +
  60553. + if (ep->is_in == 1) {
  60554. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60555. + } else {
  60556. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60557. + }
  60558. +
  60559. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60560. +
  60561. + /* clear the stall bits */
  60562. + depctl.b.stall = 0;
  60563. +
  60564. + /*
  60565. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  60566. + * of whether an endpoint has the Halt feature set, a
  60567. + * ClearFeature(ENDPOINT_HALT) request always results in the
  60568. + * data toggle being reinitialized to DATA0.
  60569. + */
  60570. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  60571. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  60572. + depctl.b.setd0pid = 1; /* DATA0 */
  60573. + }
  60574. +
  60575. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60576. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60577. + return;
  60578. +}
  60579. +
  60580. +/**
  60581. + * This function reads a packet from the Rx FIFO into the destination
  60582. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  60583. + *
  60584. + * @param core_if Programming view of DWC_otg controller.
  60585. + * @param dest Destination buffer for the packet.
  60586. + * @param bytes Number of bytes to copy to the destination.
  60587. + */
  60588. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  60589. + uint8_t * dest, uint16_t bytes)
  60590. +{
  60591. + int i;
  60592. + int word_count = (bytes + 3) / 4;
  60593. +
  60594. + volatile uint32_t *fifo = core_if->data_fifo[0];
  60595. + uint32_t *data_buff = (uint32_t *) dest;
  60596. +
  60597. + /**
  60598. + * @todo Account for the case where _dest is not dword aligned. This
  60599. + * requires reading data from the FIFO into a uint32_t temp buffer,
  60600. + * then moving it into the data buffer.
  60601. + */
  60602. +
  60603. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  60604. + core_if, dest, bytes);
  60605. +
  60606. + for (i = 0; i < word_count; i++, data_buff++) {
  60607. + *data_buff = DWC_READ_REG32(fifo);
  60608. + }
  60609. +
  60610. + return;
  60611. +}
  60612. +
  60613. +/**
  60614. + * This functions reads the device registers and prints them
  60615. + *
  60616. + * @param core_if Programming view of DWC_otg controller.
  60617. + */
  60618. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  60619. +{
  60620. + int i;
  60621. + volatile uint32_t *addr;
  60622. +
  60623. + DWC_PRINTF("Device Global Registers\n");
  60624. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  60625. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  60626. + (unsigned long)addr, DWC_READ_REG32(addr));
  60627. + addr = &core_if->dev_if->dev_global_regs->dctl;
  60628. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  60629. + (unsigned long)addr, DWC_READ_REG32(addr));
  60630. + addr = &core_if->dev_if->dev_global_regs->dsts;
  60631. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  60632. + (unsigned long)addr, DWC_READ_REG32(addr));
  60633. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  60634. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60635. + DWC_READ_REG32(addr));
  60636. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  60637. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60638. + DWC_READ_REG32(addr));
  60639. + addr = &core_if->dev_if->dev_global_regs->daint;
  60640. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60641. + DWC_READ_REG32(addr));
  60642. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  60643. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60644. + DWC_READ_REG32(addr));
  60645. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  60646. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60647. + DWC_READ_REG32(addr));
  60648. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  60649. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  60650. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  60651. + (unsigned long)addr, DWC_READ_REG32(addr));
  60652. + }
  60653. +
  60654. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  60655. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60656. + DWC_READ_REG32(addr));
  60657. +
  60658. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  60659. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  60660. + (unsigned long)addr, DWC_READ_REG32(addr));
  60661. +
  60662. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  60663. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  60664. + (unsigned long)addr, DWC_READ_REG32(addr));
  60665. +
  60666. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  60667. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60668. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  60669. + (unsigned long)addr, DWC_READ_REG32(addr));
  60670. + }
  60671. +
  60672. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60673. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60674. + DWC_READ_REG32(addr));
  60675. +
  60676. + if (core_if->hwcfg2.b.multi_proc_int) {
  60677. +
  60678. + addr = &core_if->dev_if->dev_global_regs->deachint;
  60679. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  60680. + (unsigned long)addr, DWC_READ_REG32(addr));
  60681. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  60682. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  60683. + (unsigned long)addr, DWC_READ_REG32(addr));
  60684. +
  60685. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60686. + addr =
  60687. + &core_if->dev_if->
  60688. + dev_global_regs->diepeachintmsk[i];
  60689. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60690. + i, (unsigned long)addr,
  60691. + DWC_READ_REG32(addr));
  60692. + }
  60693. +
  60694. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60695. + addr =
  60696. + &core_if->dev_if->
  60697. + dev_global_regs->doepeachintmsk[i];
  60698. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60699. + i, (unsigned long)addr,
  60700. + DWC_READ_REG32(addr));
  60701. + }
  60702. + }
  60703. +
  60704. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60705. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  60706. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  60707. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  60708. + (unsigned long)addr, DWC_READ_REG32(addr));
  60709. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  60710. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  60711. + (unsigned long)addr, DWC_READ_REG32(addr));
  60712. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  60713. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  60714. + (unsigned long)addr, DWC_READ_REG32(addr));
  60715. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  60716. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  60717. + (unsigned long)addr, DWC_READ_REG32(addr));
  60718. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  60719. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  60720. + (unsigned long)addr, DWC_READ_REG32(addr));
  60721. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  60722. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  60723. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  60724. + }
  60725. +
  60726. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60727. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  60728. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  60729. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  60730. + (unsigned long)addr, DWC_READ_REG32(addr));
  60731. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  60732. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  60733. + (unsigned long)addr, DWC_READ_REG32(addr));
  60734. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  60735. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  60736. + (unsigned long)addr, DWC_READ_REG32(addr));
  60737. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  60738. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  60739. + (unsigned long)addr, DWC_READ_REG32(addr));
  60740. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  60741. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  60742. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  60743. + (unsigned long)addr, DWC_READ_REG32(addr));
  60744. + }
  60745. +
  60746. + }
  60747. +}
  60748. +
  60749. +/**
  60750. + * This functions reads the SPRAM and prints its content
  60751. + *
  60752. + * @param core_if Programming view of DWC_otg controller.
  60753. + */
  60754. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  60755. +{
  60756. + volatile uint8_t *addr, *start_addr, *end_addr;
  60757. +
  60758. + DWC_PRINTF("SPRAM Data:\n");
  60759. + start_addr = (void *)core_if->core_global_regs;
  60760. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  60761. + start_addr += 0x00028000;
  60762. + end_addr = (void *)core_if->core_global_regs;
  60763. + end_addr += 0x000280e0;
  60764. +
  60765. + for (addr = start_addr; addr < end_addr; addr += 16) {
  60766. + DWC_PRINTF
  60767. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  60768. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  60769. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  60770. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  60771. + );
  60772. + }
  60773. +
  60774. + return;
  60775. +}
  60776. +
  60777. +/**
  60778. + * This function reads the host registers and prints them
  60779. + *
  60780. + * @param core_if Programming view of DWC_otg controller.
  60781. + */
  60782. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  60783. +{
  60784. + int i;
  60785. + volatile uint32_t *addr;
  60786. +
  60787. + DWC_PRINTF("Host Global Registers\n");
  60788. + addr = &core_if->host_if->host_global_regs->hcfg;
  60789. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  60790. + (unsigned long)addr, DWC_READ_REG32(addr));
  60791. + addr = &core_if->host_if->host_global_regs->hfir;
  60792. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  60793. + (unsigned long)addr, DWC_READ_REG32(addr));
  60794. + addr = &core_if->host_if->host_global_regs->hfnum;
  60795. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60796. + DWC_READ_REG32(addr));
  60797. + addr = &core_if->host_if->host_global_regs->hptxsts;
  60798. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60799. + DWC_READ_REG32(addr));
  60800. + addr = &core_if->host_if->host_global_regs->haint;
  60801. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60802. + DWC_READ_REG32(addr));
  60803. + addr = &core_if->host_if->host_global_regs->haintmsk;
  60804. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60805. + DWC_READ_REG32(addr));
  60806. + if (core_if->dma_desc_enable) {
  60807. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  60808. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  60809. + (unsigned long)addr, DWC_READ_REG32(addr));
  60810. + }
  60811. +
  60812. + addr = core_if->host_if->hprt0;
  60813. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60814. + DWC_READ_REG32(addr));
  60815. +
  60816. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  60817. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  60818. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  60819. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  60820. + (unsigned long)addr, DWC_READ_REG32(addr));
  60821. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  60822. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  60823. + (unsigned long)addr, DWC_READ_REG32(addr));
  60824. + addr = &core_if->host_if->hc_regs[i]->hcint;
  60825. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  60826. + (unsigned long)addr, DWC_READ_REG32(addr));
  60827. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  60828. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  60829. + (unsigned long)addr, DWC_READ_REG32(addr));
  60830. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  60831. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  60832. + (unsigned long)addr, DWC_READ_REG32(addr));
  60833. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  60834. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  60835. + (unsigned long)addr, DWC_READ_REG32(addr));
  60836. + if (core_if->dma_desc_enable) {
  60837. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  60838. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  60839. + (unsigned long)addr, DWC_READ_REG32(addr));
  60840. + }
  60841. +
  60842. + }
  60843. + return;
  60844. +}
  60845. +
  60846. +/**
  60847. + * This function reads the core global registers and prints them
  60848. + *
  60849. + * @param core_if Programming view of DWC_otg controller.
  60850. + */
  60851. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  60852. +{
  60853. + int i, ep_num;
  60854. + volatile uint32_t *addr;
  60855. + char *txfsiz;
  60856. +
  60857. + DWC_PRINTF("Core Global Registers\n");
  60858. + addr = &core_if->core_global_regs->gotgctl;
  60859. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60860. + DWC_READ_REG32(addr));
  60861. + addr = &core_if->core_global_regs->gotgint;
  60862. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60863. + DWC_READ_REG32(addr));
  60864. + addr = &core_if->core_global_regs->gahbcfg;
  60865. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60866. + DWC_READ_REG32(addr));
  60867. + addr = &core_if->core_global_regs->gusbcfg;
  60868. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60869. + DWC_READ_REG32(addr));
  60870. + addr = &core_if->core_global_regs->grstctl;
  60871. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60872. + DWC_READ_REG32(addr));
  60873. + addr = &core_if->core_global_regs->gintsts;
  60874. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60875. + DWC_READ_REG32(addr));
  60876. + addr = &core_if->core_global_regs->gintmsk;
  60877. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60878. + DWC_READ_REG32(addr));
  60879. + addr = &core_if->core_global_regs->grxstsr;
  60880. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60881. + DWC_READ_REG32(addr));
  60882. + addr = &core_if->core_global_regs->grxfsiz;
  60883. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60884. + DWC_READ_REG32(addr));
  60885. + addr = &core_if->core_global_regs->gnptxfsiz;
  60886. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60887. + DWC_READ_REG32(addr));
  60888. + addr = &core_if->core_global_regs->gnptxsts;
  60889. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60890. + DWC_READ_REG32(addr));
  60891. + addr = &core_if->core_global_regs->gi2cctl;
  60892. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60893. + DWC_READ_REG32(addr));
  60894. + addr = &core_if->core_global_regs->gpvndctl;
  60895. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60896. + DWC_READ_REG32(addr));
  60897. + addr = &core_if->core_global_regs->ggpio;
  60898. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60899. + DWC_READ_REG32(addr));
  60900. + addr = &core_if->core_global_regs->guid;
  60901. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  60902. + (unsigned long)addr, DWC_READ_REG32(addr));
  60903. + addr = &core_if->core_global_regs->gsnpsid;
  60904. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60905. + DWC_READ_REG32(addr));
  60906. + addr = &core_if->core_global_regs->ghwcfg1;
  60907. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60908. + DWC_READ_REG32(addr));
  60909. + addr = &core_if->core_global_regs->ghwcfg2;
  60910. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60911. + DWC_READ_REG32(addr));
  60912. + addr = &core_if->core_global_regs->ghwcfg3;
  60913. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60914. + DWC_READ_REG32(addr));
  60915. + addr = &core_if->core_global_regs->ghwcfg4;
  60916. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60917. + DWC_READ_REG32(addr));
  60918. + addr = &core_if->core_global_regs->glpmcfg;
  60919. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60920. + DWC_READ_REG32(addr));
  60921. + addr = &core_if->core_global_regs->gpwrdn;
  60922. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60923. + DWC_READ_REG32(addr));
  60924. + addr = &core_if->core_global_regs->gdfifocfg;
  60925. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60926. + DWC_READ_REG32(addr));
  60927. + addr = &core_if->core_global_regs->adpctl;
  60928. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60929. + dwc_otg_adp_read_reg(core_if));
  60930. + addr = &core_if->core_global_regs->hptxfsiz;
  60931. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60932. + DWC_READ_REG32(addr));
  60933. +
  60934. + if (core_if->en_multiple_tx_fifo == 0) {
  60935. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  60936. + txfsiz = "DPTXFSIZ";
  60937. + } else {
  60938. + ep_num = core_if->hwcfg4.b.num_in_eps;
  60939. + txfsiz = "DIENPTXF";
  60940. + }
  60941. + for (i = 0; i < ep_num; i++) {
  60942. + addr = &core_if->core_global_regs->dtxfsiz[i];
  60943. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  60944. + (unsigned long)addr, DWC_READ_REG32(addr));
  60945. + }
  60946. + addr = core_if->pcgcctl;
  60947. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60948. + DWC_READ_REG32(addr));
  60949. +}
  60950. +
  60951. +/**
  60952. + * Flush a Tx FIFO.
  60953. + *
  60954. + * @param core_if Programming view of DWC_otg controller.
  60955. + * @param num Tx FIFO to flush.
  60956. + */
  60957. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  60958. +{
  60959. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60960. + volatile grstctl_t greset = {.d32 = 0 };
  60961. + int count = 0;
  60962. +
  60963. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  60964. +
  60965. + greset.b.txfflsh = 1;
  60966. + greset.b.txfnum = num;
  60967. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60968. +
  60969. + do {
  60970. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60971. + if (++count > 10000) {
  60972. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  60973. + __func__, greset.d32,
  60974. + DWC_READ_REG32(&global_regs->gnptxsts));
  60975. + break;
  60976. + }
  60977. + dwc_udelay(1);
  60978. + } while (greset.b.txfflsh == 1);
  60979. +
  60980. + /* Wait for 3 PHY Clocks */
  60981. + dwc_udelay(1);
  60982. +}
  60983. +
  60984. +/**
  60985. + * Flush Rx FIFO.
  60986. + *
  60987. + * @param core_if Programming view of DWC_otg controller.
  60988. + */
  60989. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  60990. +{
  60991. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60992. + volatile grstctl_t greset = {.d32 = 0 };
  60993. + int count = 0;
  60994. +
  60995. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  60996. + /*
  60997. + *
  60998. + */
  60999. + greset.b.rxfflsh = 1;
  61000. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61001. +
  61002. + do {
  61003. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61004. + if (++count > 10000) {
  61005. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  61006. + greset.d32);
  61007. + break;
  61008. + }
  61009. + dwc_udelay(1);
  61010. + } while (greset.b.rxfflsh == 1);
  61011. +
  61012. + /* Wait for 3 PHY Clocks */
  61013. + dwc_udelay(1);
  61014. +}
  61015. +
  61016. +/**
  61017. + * Do core a soft reset of the core. Be careful with this because it
  61018. + * resets all the internal state machines of the core.
  61019. + */
  61020. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  61021. +{
  61022. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61023. + volatile grstctl_t greset = {.d32 = 0 };
  61024. + int count = 0;
  61025. +
  61026. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  61027. + /* Wait for AHB master IDLE state. */
  61028. + do {
  61029. + dwc_udelay(10);
  61030. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61031. + if (++count > 100000) {
  61032. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  61033. + greset.d32);
  61034. + return;
  61035. + }
  61036. + }
  61037. + while (greset.b.ahbidle == 0);
  61038. +
  61039. + /* Core Soft Reset */
  61040. + count = 0;
  61041. + greset.b.csftrst = 1;
  61042. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61043. + do {
  61044. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61045. + if (++count > 10000) {
  61046. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  61047. + __func__, greset.d32);
  61048. + break;
  61049. + }
  61050. + dwc_udelay(1);
  61051. + }
  61052. + while (greset.b.csftrst == 1);
  61053. +
  61054. + /* Wait for 3 PHY Clocks */
  61055. + dwc_mdelay(100);
  61056. +}
  61057. +
  61058. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  61059. +{
  61060. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  61061. +}
  61062. +
  61063. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  61064. +{
  61065. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  61066. +}
  61067. +
  61068. +/**
  61069. + * Register HCD callbacks. The callbacks are used to start and stop
  61070. + * the HCD for interrupt processing.
  61071. + *
  61072. + * @param core_if Programming view of DWC_otg controller.
  61073. + * @param cb the HCD callback structure.
  61074. + * @param p pointer to be passed to callback function (usb_hcd*).
  61075. + */
  61076. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  61077. + dwc_otg_cil_callbacks_t * cb, void *p)
  61078. +{
  61079. + core_if->hcd_cb = cb;
  61080. + cb->p = p;
  61081. +}
  61082. +
  61083. +/**
  61084. + * Register PCD callbacks. The callbacks are used to start and stop
  61085. + * the PCD for interrupt processing.
  61086. + *
  61087. + * @param core_if Programming view of DWC_otg controller.
  61088. + * @param cb the PCD callback structure.
  61089. + * @param p pointer to be passed to callback function (pcd*).
  61090. + */
  61091. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  61092. + dwc_otg_cil_callbacks_t * cb, void *p)
  61093. +{
  61094. + core_if->pcd_cb = cb;
  61095. + cb->p = p;
  61096. +}
  61097. +
  61098. +#ifdef DWC_EN_ISOC
  61099. +
  61100. +/**
  61101. + * This function writes isoc data per 1 (micro)frame into tx fifo
  61102. + *
  61103. + * @param core_if Programming view of DWC_otg controller.
  61104. + * @param ep The EP to start the transfer on.
  61105. + *
  61106. + */
  61107. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61108. +{
  61109. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  61110. + dtxfsts_data_t txstatus = {.d32 = 0 };
  61111. + uint32_t len = 0;
  61112. + uint32_t dwords;
  61113. +
  61114. + ep->xfer_len = ep->data_per_frame;
  61115. + ep->xfer_count = 0;
  61116. +
  61117. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  61118. +
  61119. + len = ep->xfer_len - ep->xfer_count;
  61120. +
  61121. + if (len > ep->maxpacket) {
  61122. + len = ep->maxpacket;
  61123. + }
  61124. +
  61125. + dwords = (len + 3) / 4;
  61126. +
  61127. + /* While there is space in the queue and space in the FIFO and
  61128. + * More data to tranfer, Write packets to the Tx FIFO */
  61129. + txstatus.d32 =
  61130. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  61131. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  61132. +
  61133. + while (txstatus.b.txfspcavail > dwords &&
  61134. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  61135. + /* Write the FIFO */
  61136. + dwc_otg_ep_write_packet(core_if, ep, 0);
  61137. +
  61138. + len = ep->xfer_len - ep->xfer_count;
  61139. + if (len > ep->maxpacket) {
  61140. + len = ep->maxpacket;
  61141. + }
  61142. +
  61143. + dwords = (len + 3) / 4;
  61144. + txstatus.d32 =
  61145. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  61146. + dtxfsts);
  61147. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  61148. + txstatus.d32);
  61149. + }
  61150. +}
  61151. +
  61152. +/**
  61153. + * This function initializes a descriptor chain for Isochronous transfer
  61154. + *
  61155. + * @param core_if Programming view of DWC_otg controller.
  61156. + * @param ep The EP to start the transfer on.
  61157. + *
  61158. + */
  61159. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  61160. + dwc_ep_t * ep)
  61161. +{
  61162. + deptsiz_data_t deptsiz = {.d32 = 0 };
  61163. + depctl_data_t depctl = {.d32 = 0 };
  61164. + dsts_data_t dsts = {.d32 = 0 };
  61165. + volatile uint32_t *addr;
  61166. +
  61167. + if (ep->is_in) {
  61168. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  61169. + } else {
  61170. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  61171. + }
  61172. +
  61173. + ep->xfer_len = ep->data_per_frame;
  61174. + ep->xfer_count = 0;
  61175. + ep->xfer_buff = ep->cur_pkt_addr;
  61176. + ep->dma_addr = ep->cur_pkt_dma_addr;
  61177. +
  61178. + if (ep->is_in) {
  61179. + /* Program the transfer size and packet count
  61180. + * as follows: xfersize = N * maxpacket +
  61181. + * short_packet pktcnt = N + (short_packet
  61182. + * exist ? 1 : 0)
  61183. + */
  61184. + deptsiz.b.xfersize = ep->xfer_len;
  61185. + deptsiz.b.pktcnt =
  61186. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  61187. + deptsiz.b.mc = deptsiz.b.pktcnt;
  61188. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  61189. + deptsiz.d32);
  61190. +
  61191. + /* Write the DMA register */
  61192. + if (core_if->dma_enable) {
  61193. + DWC_WRITE_REG32(&
  61194. + (core_if->dev_if->in_ep_regs[ep->num]->
  61195. + diepdma), (uint32_t) ep->dma_addr);
  61196. + }
  61197. + } else {
  61198. + deptsiz.b.pktcnt =
  61199. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  61200. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  61201. +
  61202. + DWC_WRITE_REG32(&core_if->dev_if->
  61203. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  61204. +
  61205. + if (core_if->dma_enable) {
  61206. + DWC_WRITE_REG32(&
  61207. + (core_if->dev_if->
  61208. + out_ep_regs[ep->num]->doepdma),
  61209. + (uint32_t) ep->dma_addr);
  61210. + }
  61211. + }
  61212. +
  61213. + /** Enable endpoint, clear nak */
  61214. +
  61215. + depctl.d32 = 0;
  61216. + if (ep->bInterval == 1) {
  61217. + dsts.d32 =
  61218. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61219. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  61220. +
  61221. + if (ep->next_frame & 0x1) {
  61222. + depctl.b.setd1pid = 1;
  61223. + } else {
  61224. + depctl.b.setd0pid = 1;
  61225. + }
  61226. + } else {
  61227. + ep->next_frame += ep->bInterval;
  61228. +
  61229. + if (ep->next_frame & 0x1) {
  61230. + depctl.b.setd1pid = 1;
  61231. + } else {
  61232. + depctl.b.setd0pid = 1;
  61233. + }
  61234. + }
  61235. + depctl.b.epena = 1;
  61236. + depctl.b.cnak = 1;
  61237. +
  61238. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  61239. + depctl.d32 = DWC_READ_REG32(addr);
  61240. +
  61241. + if (ep->is_in && core_if->dma_enable == 0) {
  61242. + write_isoc_frame_data(core_if, ep);
  61243. + }
  61244. +
  61245. +}
  61246. +#endif /* DWC_EN_ISOC */
  61247. +
  61248. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  61249. +{
  61250. + int i;
  61251. + for (i = 0; i < size; i++) {
  61252. + p[i] = -1;
  61253. + }
  61254. +}
  61255. +
  61256. +static int dwc_otg_param_initialized(int32_t val)
  61257. +{
  61258. + return val != -1;
  61259. +}
  61260. +
  61261. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  61262. +{
  61263. + int i;
  61264. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  61265. + if (!core_if->core_params) {
  61266. + return -DWC_E_NO_MEMORY;
  61267. + }
  61268. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  61269. + sizeof(*core_if->core_params) /
  61270. + sizeof(int32_t));
  61271. + DWC_PRINTF("Setting default values for core params\n");
  61272. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  61273. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  61274. + dwc_otg_set_param_dma_desc_enable(core_if,
  61275. + dwc_param_dma_desc_enable_default);
  61276. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  61277. + dwc_otg_set_param_dma_burst_size(core_if,
  61278. + dwc_param_dma_burst_size_default);
  61279. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  61280. + dwc_param_host_support_fs_ls_low_power_default);
  61281. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  61282. + dwc_param_enable_dynamic_fifo_default);
  61283. + dwc_otg_set_param_data_fifo_size(core_if,
  61284. + dwc_param_data_fifo_size_default);
  61285. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  61286. + dwc_param_dev_rx_fifo_size_default);
  61287. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  61288. + dwc_param_dev_nperio_tx_fifo_size_default);
  61289. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  61290. + dwc_param_host_rx_fifo_size_default);
  61291. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  61292. + dwc_param_host_nperio_tx_fifo_size_default);
  61293. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  61294. + dwc_param_host_perio_tx_fifo_size_default);
  61295. + dwc_otg_set_param_max_transfer_size(core_if,
  61296. + dwc_param_max_transfer_size_default);
  61297. + dwc_otg_set_param_max_packet_count(core_if,
  61298. + dwc_param_max_packet_count_default);
  61299. + dwc_otg_set_param_host_channels(core_if,
  61300. + dwc_param_host_channels_default);
  61301. + dwc_otg_set_param_dev_endpoints(core_if,
  61302. + dwc_param_dev_endpoints_default);
  61303. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  61304. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  61305. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  61306. + dwc_param_host_ls_low_power_phy_clk_default);
  61307. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  61308. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  61309. + dwc_param_phy_ulpi_ext_vbus_default);
  61310. + dwc_otg_set_param_phy_utmi_width(core_if,
  61311. + dwc_param_phy_utmi_width_default);
  61312. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  61313. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  61314. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  61315. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  61316. + dwc_param_en_multiple_tx_fifo_default);
  61317. + for (i = 0; i < 15; i++) {
  61318. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  61319. + dwc_param_dev_perio_tx_fifo_size_default,
  61320. + i);
  61321. + }
  61322. +
  61323. + for (i = 0; i < 15; i++) {
  61324. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  61325. + dwc_param_dev_tx_fifo_size_default,
  61326. + i);
  61327. + }
  61328. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  61329. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  61330. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  61331. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  61332. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  61333. + dwc_otg_set_param_tx_thr_length(core_if,
  61334. + dwc_param_tx_thr_length_default);
  61335. + dwc_otg_set_param_rx_thr_length(core_if,
  61336. + dwc_param_rx_thr_length_default);
  61337. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  61338. + dwc_param_ahb_thr_ratio_default);
  61339. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  61340. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  61341. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  61342. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  61343. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  61344. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  61345. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  61346. + DWC_PRINTF("Finished setting default values for core params\n");
  61347. +
  61348. + return 0;
  61349. +}
  61350. +
  61351. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  61352. +{
  61353. + return core_if->dma_enable;
  61354. +}
  61355. +
  61356. +/* Checks if the parameter is outside of its valid range of values */
  61357. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  61358. + (((_param_) < (_low_)) || \
  61359. + ((_param_) > (_high_)))
  61360. +
  61361. +/* Parameter access functions */
  61362. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61363. +{
  61364. + int valid;
  61365. + int retval = 0;
  61366. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61367. + DWC_WARN("Wrong value for otg_cap parameter\n");
  61368. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  61369. + retval = -DWC_E_INVALID;
  61370. + goto out;
  61371. + }
  61372. +
  61373. + valid = 1;
  61374. + switch (val) {
  61375. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  61376. + if (core_if->hwcfg2.b.op_mode !=
  61377. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61378. + valid = 0;
  61379. + break;
  61380. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  61381. + if ((core_if->hwcfg2.b.op_mode !=
  61382. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61383. + && (core_if->hwcfg2.b.op_mode !=
  61384. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  61385. + && (core_if->hwcfg2.b.op_mode !=
  61386. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  61387. + && (core_if->hwcfg2.b.op_mode !=
  61388. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  61389. + valid = 0;
  61390. + }
  61391. + break;
  61392. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  61393. + /* always valid */
  61394. + break;
  61395. + }
  61396. + if (!valid) {
  61397. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  61398. + DWC_ERROR
  61399. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  61400. + val);
  61401. + }
  61402. + val =
  61403. + (((core_if->hwcfg2.b.op_mode ==
  61404. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61405. + || (core_if->hwcfg2.b.op_mode ==
  61406. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  61407. + || (core_if->hwcfg2.b.op_mode ==
  61408. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  61409. + || (core_if->hwcfg2.b.op_mode ==
  61410. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  61411. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  61412. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  61413. + retval = -DWC_E_INVALID;
  61414. + }
  61415. +
  61416. + core_if->core_params->otg_cap = val;
  61417. +out:
  61418. + return retval;
  61419. +}
  61420. +
  61421. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  61422. +{
  61423. + return core_if->core_params->otg_cap;
  61424. +}
  61425. +
  61426. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  61427. +{
  61428. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61429. + DWC_WARN("Wrong value for opt parameter\n");
  61430. + return -DWC_E_INVALID;
  61431. + }
  61432. + core_if->core_params->opt = val;
  61433. + return 0;
  61434. +}
  61435. +
  61436. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  61437. +{
  61438. + return core_if->core_params->opt;
  61439. +}
  61440. +
  61441. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61442. +{
  61443. + int retval = 0;
  61444. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61445. + DWC_WARN("Wrong value for dma enable\n");
  61446. + return -DWC_E_INVALID;
  61447. + }
  61448. +
  61449. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  61450. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  61451. + DWC_ERROR
  61452. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  61453. + val);
  61454. + }
  61455. + val = 0;
  61456. + retval = -DWC_E_INVALID;
  61457. + }
  61458. +
  61459. + core_if->core_params->dma_enable = val;
  61460. + if (val == 0) {
  61461. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  61462. + }
  61463. + return retval;
  61464. +}
  61465. +
  61466. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  61467. +{
  61468. + return core_if->core_params->dma_enable;
  61469. +}
  61470. +
  61471. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61472. +{
  61473. + int retval = 0;
  61474. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61475. + DWC_WARN("Wrong value for dma_enable\n");
  61476. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  61477. + return -DWC_E_INVALID;
  61478. + }
  61479. +
  61480. + if ((val == 1)
  61481. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  61482. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  61483. + if (dwc_otg_param_initialized
  61484. + (core_if->core_params->dma_desc_enable)) {
  61485. + DWC_ERROR
  61486. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  61487. + val);
  61488. + }
  61489. + val = 0;
  61490. + retval = -DWC_E_INVALID;
  61491. + }
  61492. + core_if->core_params->dma_desc_enable = val;
  61493. + return retval;
  61494. +}
  61495. +
  61496. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  61497. +{
  61498. + return core_if->core_params->dma_desc_enable;
  61499. +}
  61500. +
  61501. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  61502. + int32_t val)
  61503. +{
  61504. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61505. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  61506. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  61507. + return -DWC_E_INVALID;
  61508. + }
  61509. + core_if->core_params->host_support_fs_ls_low_power = val;
  61510. + return 0;
  61511. +}
  61512. +
  61513. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  61514. + core_if)
  61515. +{
  61516. + return core_if->core_params->host_support_fs_ls_low_power;
  61517. +}
  61518. +
  61519. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  61520. + int32_t val)
  61521. +{
  61522. + int retval = 0;
  61523. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61524. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  61525. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  61526. + return -DWC_E_INVALID;
  61527. + }
  61528. +
  61529. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  61530. + if (dwc_otg_param_initialized
  61531. + (core_if->core_params->enable_dynamic_fifo)) {
  61532. + DWC_ERROR
  61533. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  61534. + val);
  61535. + }
  61536. + val = 0;
  61537. + retval = -DWC_E_INVALID;
  61538. + }
  61539. + core_if->core_params->enable_dynamic_fifo = val;
  61540. + return retval;
  61541. +}
  61542. +
  61543. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  61544. +{
  61545. + return core_if->core_params->enable_dynamic_fifo;
  61546. +}
  61547. +
  61548. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61549. +{
  61550. + int retval = 0;
  61551. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  61552. + DWC_WARN("Wrong value for data_fifo_size\n");
  61553. + DWC_WARN("data_fifo_size must be 32-32768\n");
  61554. + return -DWC_E_INVALID;
  61555. + }
  61556. +
  61557. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  61558. + if (dwc_otg_param_initialized
  61559. + (core_if->core_params->data_fifo_size)) {
  61560. + DWC_ERROR
  61561. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  61562. + val);
  61563. + }
  61564. + val = core_if->hwcfg3.b.dfifo_depth;
  61565. + retval = -DWC_E_INVALID;
  61566. + }
  61567. +
  61568. + core_if->core_params->data_fifo_size = val;
  61569. + return retval;
  61570. +}
  61571. +
  61572. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  61573. +{
  61574. + return core_if->core_params->data_fifo_size;
  61575. +}
  61576. +
  61577. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61578. +{
  61579. + int retval = 0;
  61580. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61581. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  61582. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  61583. + return -DWC_E_INVALID;
  61584. + }
  61585. +
  61586. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61587. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  61588. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  61589. + }
  61590. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61591. + retval = -DWC_E_INVALID;
  61592. + }
  61593. +
  61594. + core_if->core_params->dev_rx_fifo_size = val;
  61595. + return retval;
  61596. +}
  61597. +
  61598. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61599. +{
  61600. + return core_if->core_params->dev_rx_fifo_size;
  61601. +}
  61602. +
  61603. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61604. + int32_t val)
  61605. +{
  61606. + int retval = 0;
  61607. +
  61608. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61609. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  61610. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  61611. + return -DWC_E_INVALID;
  61612. + }
  61613. +
  61614. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61615. + if (dwc_otg_param_initialized
  61616. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  61617. + DWC_ERROR
  61618. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  61619. + val);
  61620. + }
  61621. + val =
  61622. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61623. + 16);
  61624. + retval = -DWC_E_INVALID;
  61625. + }
  61626. +
  61627. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  61628. + return retval;
  61629. +}
  61630. +
  61631. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61632. +{
  61633. + return core_if->core_params->dev_nperio_tx_fifo_size;
  61634. +}
  61635. +
  61636. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  61637. + int32_t val)
  61638. +{
  61639. + int retval = 0;
  61640. +
  61641. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61642. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  61643. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  61644. + return -DWC_E_INVALID;
  61645. + }
  61646. +
  61647. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61648. + if (dwc_otg_param_initialized
  61649. + (core_if->core_params->host_rx_fifo_size)) {
  61650. + DWC_ERROR
  61651. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  61652. + val);
  61653. + }
  61654. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61655. + retval = -DWC_E_INVALID;
  61656. + }
  61657. +
  61658. + core_if->core_params->host_rx_fifo_size = val;
  61659. + return retval;
  61660. +
  61661. +}
  61662. +
  61663. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61664. +{
  61665. + return core_if->core_params->host_rx_fifo_size;
  61666. +}
  61667. +
  61668. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61669. + int32_t val)
  61670. +{
  61671. + int retval = 0;
  61672. +
  61673. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61674. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  61675. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  61676. + return -DWC_E_INVALID;
  61677. + }
  61678. +
  61679. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61680. + if (dwc_otg_param_initialized
  61681. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  61682. + DWC_ERROR
  61683. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  61684. + val);
  61685. + }
  61686. + val =
  61687. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61688. + 16);
  61689. + retval = -DWC_E_INVALID;
  61690. + }
  61691. +
  61692. + core_if->core_params->host_nperio_tx_fifo_size = val;
  61693. + return retval;
  61694. +}
  61695. +
  61696. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61697. +{
  61698. + return core_if->core_params->host_nperio_tx_fifo_size;
  61699. +}
  61700. +
  61701. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61702. + int32_t val)
  61703. +{
  61704. + int retval = 0;
  61705. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61706. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  61707. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  61708. + return -DWC_E_INVALID;
  61709. + }
  61710. +
  61711. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  61712. + if (dwc_otg_param_initialized
  61713. + (core_if->core_params->host_perio_tx_fifo_size)) {
  61714. + DWC_ERROR
  61715. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  61716. + val);
  61717. + }
  61718. + val = (core_if->hptxfsiz.d32) >> 16;
  61719. + retval = -DWC_E_INVALID;
  61720. + }
  61721. +
  61722. + core_if->core_params->host_perio_tx_fifo_size = val;
  61723. + return retval;
  61724. +}
  61725. +
  61726. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61727. +{
  61728. + return core_if->core_params->host_perio_tx_fifo_size;
  61729. +}
  61730. +
  61731. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  61732. + int32_t val)
  61733. +{
  61734. + int retval = 0;
  61735. +
  61736. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  61737. + DWC_WARN("Wrong value for max_transfer_size\n");
  61738. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  61739. + return -DWC_E_INVALID;
  61740. + }
  61741. +
  61742. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  61743. + if (dwc_otg_param_initialized
  61744. + (core_if->core_params->max_transfer_size)) {
  61745. + DWC_ERROR
  61746. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  61747. + val);
  61748. + }
  61749. + val =
  61750. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  61751. + 1);
  61752. + retval = -DWC_E_INVALID;
  61753. + }
  61754. +
  61755. + core_if->core_params->max_transfer_size = val;
  61756. + return retval;
  61757. +}
  61758. +
  61759. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  61760. +{
  61761. + return core_if->core_params->max_transfer_size;
  61762. +}
  61763. +
  61764. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  61765. +{
  61766. + int retval = 0;
  61767. +
  61768. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  61769. + DWC_WARN("Wrong value for max_packet_count\n");
  61770. + DWC_WARN("max_packet_count must be 15-511\n");
  61771. + return -DWC_E_INVALID;
  61772. + }
  61773. +
  61774. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  61775. + if (dwc_otg_param_initialized
  61776. + (core_if->core_params->max_packet_count)) {
  61777. + DWC_ERROR
  61778. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  61779. + val);
  61780. + }
  61781. + val =
  61782. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  61783. + retval = -DWC_E_INVALID;
  61784. + }
  61785. +
  61786. + core_if->core_params->max_packet_count = val;
  61787. + return retval;
  61788. +}
  61789. +
  61790. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  61791. +{
  61792. + return core_if->core_params->max_packet_count;
  61793. +}
  61794. +
  61795. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  61796. +{
  61797. + int retval = 0;
  61798. +
  61799. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  61800. + DWC_WARN("Wrong value for host_channels\n");
  61801. + DWC_WARN("host_channels must be 1-16\n");
  61802. + return -DWC_E_INVALID;
  61803. + }
  61804. +
  61805. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  61806. + if (dwc_otg_param_initialized
  61807. + (core_if->core_params->host_channels)) {
  61808. + DWC_ERROR
  61809. + ("%d invalid for host_channels. Check HW configurations.\n",
  61810. + val);
  61811. + }
  61812. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  61813. + retval = -DWC_E_INVALID;
  61814. + }
  61815. +
  61816. + core_if->core_params->host_channels = val;
  61817. + return retval;
  61818. +}
  61819. +
  61820. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  61821. +{
  61822. + return core_if->core_params->host_channels;
  61823. +}
  61824. +
  61825. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  61826. +{
  61827. + int retval = 0;
  61828. +
  61829. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  61830. + DWC_WARN("Wrong value for dev_endpoints\n");
  61831. + DWC_WARN("dev_endpoints must be 1-15\n");
  61832. + return -DWC_E_INVALID;
  61833. + }
  61834. +
  61835. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  61836. + if (dwc_otg_param_initialized
  61837. + (core_if->core_params->dev_endpoints)) {
  61838. + DWC_ERROR
  61839. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  61840. + val);
  61841. + }
  61842. + val = core_if->hwcfg2.b.num_dev_ep;
  61843. + retval = -DWC_E_INVALID;
  61844. + }
  61845. +
  61846. + core_if->core_params->dev_endpoints = val;
  61847. + return retval;
  61848. +}
  61849. +
  61850. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  61851. +{
  61852. + return core_if->core_params->dev_endpoints;
  61853. +}
  61854. +
  61855. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  61856. +{
  61857. + int retval = 0;
  61858. + int valid = 0;
  61859. +
  61860. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61861. + DWC_WARN("Wrong value for phy_type\n");
  61862. + DWC_WARN("phy_type must be 0,1 or 2\n");
  61863. + return -DWC_E_INVALID;
  61864. + }
  61865. +#ifndef NO_FS_PHY_HW_CHECKS
  61866. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  61867. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  61868. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61869. + valid = 1;
  61870. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  61871. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  61872. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61873. + valid = 1;
  61874. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  61875. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  61876. + valid = 1;
  61877. + }
  61878. + if (!valid) {
  61879. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  61880. + DWC_ERROR
  61881. + ("%d invalid for phy_type. Check HW configurations.\n",
  61882. + val);
  61883. + }
  61884. + if (core_if->hwcfg2.b.hs_phy_type) {
  61885. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  61886. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  61887. + val = DWC_PHY_TYPE_PARAM_UTMI;
  61888. + } else {
  61889. + val = DWC_PHY_TYPE_PARAM_ULPI;
  61890. + }
  61891. + }
  61892. + retval = -DWC_E_INVALID;
  61893. + }
  61894. +#endif
  61895. + core_if->core_params->phy_type = val;
  61896. + return retval;
  61897. +}
  61898. +
  61899. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  61900. +{
  61901. + return core_if->core_params->phy_type;
  61902. +}
  61903. +
  61904. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  61905. +{
  61906. + int retval = 0;
  61907. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61908. + DWC_WARN("Wrong value for speed parameter\n");
  61909. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  61910. + return -DWC_E_INVALID;
  61911. + }
  61912. + if ((val == 0)
  61913. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  61914. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  61915. + DWC_ERROR
  61916. + ("%d invalid for speed paremter. Check HW configuration.\n",
  61917. + val);
  61918. + }
  61919. + val =
  61920. + (dwc_otg_get_param_phy_type(core_if) ==
  61921. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  61922. + retval = -DWC_E_INVALID;
  61923. + }
  61924. + core_if->core_params->speed = val;
  61925. + return retval;
  61926. +}
  61927. +
  61928. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  61929. +{
  61930. + return core_if->core_params->speed;
  61931. +}
  61932. +
  61933. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  61934. + int32_t val)
  61935. +{
  61936. + int retval = 0;
  61937. +
  61938. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61939. + DWC_WARN
  61940. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  61941. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  61942. + return -DWC_E_INVALID;
  61943. + }
  61944. +
  61945. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  61946. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  61947. + if (dwc_otg_param_initialized
  61948. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  61949. + DWC_ERROR
  61950. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  61951. + val);
  61952. + }
  61953. + val =
  61954. + (dwc_otg_get_param_phy_type(core_if) ==
  61955. + DWC_PHY_TYPE_PARAM_FS) ?
  61956. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  61957. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  61958. + retval = -DWC_E_INVALID;
  61959. + }
  61960. +
  61961. + core_if->core_params->host_ls_low_power_phy_clk = val;
  61962. + return retval;
  61963. +}
  61964. +
  61965. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  61966. +{
  61967. + return core_if->core_params->host_ls_low_power_phy_clk;
  61968. +}
  61969. +
  61970. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  61971. +{
  61972. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61973. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  61974. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  61975. + return -DWC_E_INVALID;
  61976. + }
  61977. +
  61978. + core_if->core_params->phy_ulpi_ddr = val;
  61979. + return 0;
  61980. +}
  61981. +
  61982. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  61983. +{
  61984. + return core_if->core_params->phy_ulpi_ddr;
  61985. +}
  61986. +
  61987. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  61988. + int32_t val)
  61989. +{
  61990. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61991. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  61992. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  61993. + return -DWC_E_INVALID;
  61994. + }
  61995. +
  61996. + core_if->core_params->phy_ulpi_ext_vbus = val;
  61997. + return 0;
  61998. +}
  61999. +
  62000. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  62001. +{
  62002. + return core_if->core_params->phy_ulpi_ext_vbus;
  62003. +}
  62004. +
  62005. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  62006. +{
  62007. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  62008. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  62009. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  62010. + return -DWC_E_INVALID;
  62011. + }
  62012. +
  62013. + core_if->core_params->phy_utmi_width = val;
  62014. + return 0;
  62015. +}
  62016. +
  62017. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  62018. +{
  62019. + return core_if->core_params->phy_utmi_width;
  62020. +}
  62021. +
  62022. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  62023. +{
  62024. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62025. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  62026. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  62027. + return -DWC_E_INVALID;
  62028. + }
  62029. +
  62030. + core_if->core_params->ulpi_fs_ls = val;
  62031. + return 0;
  62032. +}
  62033. +
  62034. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  62035. +{
  62036. + return core_if->core_params->ulpi_fs_ls;
  62037. +}
  62038. +
  62039. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  62040. +{
  62041. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62042. + DWC_WARN("Wrong valaue for ts_dline\n");
  62043. + DWC_WARN("ts_dline must be 0 or 1\n");
  62044. + return -DWC_E_INVALID;
  62045. + }
  62046. +
  62047. + core_if->core_params->ts_dline = val;
  62048. + return 0;
  62049. +}
  62050. +
  62051. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  62052. +{
  62053. + return core_if->core_params->ts_dline;
  62054. +}
  62055. +
  62056. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62057. +{
  62058. + int retval = 0;
  62059. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62060. + DWC_WARN("Wrong valaue for i2c_enable\n");
  62061. + DWC_WARN("i2c_enable must be 0 or 1\n");
  62062. + return -DWC_E_INVALID;
  62063. + }
  62064. +#ifndef NO_FS_PHY_HW_CHECK
  62065. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  62066. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  62067. + DWC_ERROR
  62068. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  62069. + val);
  62070. + }
  62071. + val = 0;
  62072. + retval = -DWC_E_INVALID;
  62073. + }
  62074. +#endif
  62075. +
  62076. + core_if->core_params->i2c_enable = val;
  62077. + return retval;
  62078. +}
  62079. +
  62080. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  62081. +{
  62082. + return core_if->core_params->i2c_enable;
  62083. +}
  62084. +
  62085. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62086. + int32_t val, int fifo_num)
  62087. +{
  62088. + int retval = 0;
  62089. +
  62090. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62091. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  62092. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  62093. + return -DWC_E_INVALID;
  62094. + }
  62095. +
  62096. + if (val >
  62097. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62098. + if (dwc_otg_param_initialized
  62099. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  62100. + DWC_ERROR
  62101. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  62102. + val, fifo_num);
  62103. + }
  62104. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62105. + retval = -DWC_E_INVALID;
  62106. + }
  62107. +
  62108. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  62109. + return retval;
  62110. +}
  62111. +
  62112. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62113. + int fifo_num)
  62114. +{
  62115. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  62116. +}
  62117. +
  62118. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  62119. + int32_t val)
  62120. +{
  62121. + int retval = 0;
  62122. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62123. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  62124. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  62125. + return -DWC_E_INVALID;
  62126. + }
  62127. +
  62128. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  62129. + if (dwc_otg_param_initialized
  62130. + (core_if->core_params->en_multiple_tx_fifo)) {
  62131. + DWC_ERROR
  62132. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  62133. + val);
  62134. + }
  62135. + val = 0;
  62136. + retval = -DWC_E_INVALID;
  62137. + }
  62138. +
  62139. + core_if->core_params->en_multiple_tx_fifo = val;
  62140. + return retval;
  62141. +}
  62142. +
  62143. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  62144. +{
  62145. + return core_if->core_params->en_multiple_tx_fifo;
  62146. +}
  62147. +
  62148. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  62149. + int fifo_num)
  62150. +{
  62151. + int retval = 0;
  62152. +
  62153. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62154. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  62155. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  62156. + return -DWC_E_INVALID;
  62157. + }
  62158. +
  62159. + if (val >
  62160. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62161. + if (dwc_otg_param_initialized
  62162. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  62163. + DWC_ERROR
  62164. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  62165. + val, fifo_num);
  62166. + }
  62167. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62168. + retval = -DWC_E_INVALID;
  62169. + }
  62170. +
  62171. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  62172. + return retval;
  62173. +}
  62174. +
  62175. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62176. + int fifo_num)
  62177. +{
  62178. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  62179. +}
  62180. +
  62181. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62182. +{
  62183. + int retval = 0;
  62184. +
  62185. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  62186. + DWC_WARN("Wrong value for thr_ctl\n");
  62187. + DWC_WARN("thr_ctl must be 0-7\n");
  62188. + return -DWC_E_INVALID;
  62189. + }
  62190. +
  62191. + if ((val != 0) &&
  62192. + (!dwc_otg_get_param_dma_enable(core_if) ||
  62193. + !core_if->hwcfg4.b.ded_fifo_en)) {
  62194. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  62195. + DWC_ERROR
  62196. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  62197. + val);
  62198. + }
  62199. + val = 0;
  62200. + retval = -DWC_E_INVALID;
  62201. + }
  62202. +
  62203. + core_if->core_params->thr_ctl = val;
  62204. + return retval;
  62205. +}
  62206. +
  62207. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  62208. +{
  62209. + return core_if->core_params->thr_ctl;
  62210. +}
  62211. +
  62212. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62213. +{
  62214. + int retval = 0;
  62215. +
  62216. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62217. + DWC_WARN("Wrong value for lpm_enable\n");
  62218. + DWC_WARN("lpm_enable must be 0 or 1\n");
  62219. + return -DWC_E_INVALID;
  62220. + }
  62221. +
  62222. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  62223. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  62224. + DWC_ERROR
  62225. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  62226. + val);
  62227. + }
  62228. + val = 0;
  62229. + retval = -DWC_E_INVALID;
  62230. + }
  62231. +
  62232. + core_if->core_params->lpm_enable = val;
  62233. + return retval;
  62234. +}
  62235. +
  62236. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  62237. +{
  62238. + return core_if->core_params->lpm_enable;
  62239. +}
  62240. +
  62241. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  62242. +{
  62243. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  62244. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  62245. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  62246. + return -DWC_E_INVALID;
  62247. + }
  62248. +
  62249. + core_if->core_params->tx_thr_length = val;
  62250. + return 0;
  62251. +}
  62252. +
  62253. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  62254. +{
  62255. + return core_if->core_params->tx_thr_length;
  62256. +}
  62257. +
  62258. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  62259. +{
  62260. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  62261. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  62262. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  62263. + return -DWC_E_INVALID;
  62264. + }
  62265. +
  62266. + core_if->core_params->rx_thr_length = val;
  62267. + return 0;
  62268. +}
  62269. +
  62270. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  62271. +{
  62272. + return core_if->core_params->rx_thr_length;
  62273. +}
  62274. +
  62275. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  62276. +{
  62277. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  62278. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  62279. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  62280. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  62281. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  62282. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  62283. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  62284. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  62285. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  62286. + return -DWC_E_INVALID;
  62287. + }
  62288. + core_if->core_params->dma_burst_size = val;
  62289. + return 0;
  62290. +}
  62291. +
  62292. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  62293. +{
  62294. + return core_if->core_params->dma_burst_size;
  62295. +}
  62296. +
  62297. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62298. +{
  62299. + int retval = 0;
  62300. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62301. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  62302. + return -DWC_E_INVALID;
  62303. + }
  62304. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  62305. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  62306. + DWC_ERROR
  62307. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  62308. + val);
  62309. + }
  62310. + retval = -DWC_E_INVALID;
  62311. + val = 0;
  62312. + }
  62313. + core_if->core_params->pti_enable = val;
  62314. + return retval;
  62315. +}
  62316. +
  62317. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  62318. +{
  62319. + return core_if->core_params->pti_enable;
  62320. +}
  62321. +
  62322. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62323. +{
  62324. + int retval = 0;
  62325. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62326. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  62327. + return -DWC_E_INVALID;
  62328. + }
  62329. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  62330. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  62331. + DWC_ERROR
  62332. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  62333. + val);
  62334. + }
  62335. + retval = -DWC_E_INVALID;
  62336. + val = 0;
  62337. + }
  62338. + core_if->core_params->mpi_enable = val;
  62339. + return retval;
  62340. +}
  62341. +
  62342. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  62343. +{
  62344. + return core_if->core_params->mpi_enable;
  62345. +}
  62346. +
  62347. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62348. +{
  62349. + int retval = 0;
  62350. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62351. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  62352. + return -DWC_E_INVALID;
  62353. + }
  62354. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  62355. + if (dwc_otg_param_initialized
  62356. + (core_if->core_params->adp_supp_enable)) {
  62357. + DWC_ERROR
  62358. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  62359. + val);
  62360. + }
  62361. + retval = -DWC_E_INVALID;
  62362. + val = 0;
  62363. + }
  62364. + core_if->core_params->adp_supp_enable = val;
  62365. + /*Set OTG version 2.0 in case of enabling ADP*/
  62366. + if (val)
  62367. + dwc_otg_set_param_otg_ver(core_if, 1);
  62368. +
  62369. + return retval;
  62370. +}
  62371. +
  62372. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  62373. +{
  62374. + return core_if->core_params->adp_supp_enable;
  62375. +}
  62376. +
  62377. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  62378. +{
  62379. + int retval = 0;
  62380. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62381. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  62382. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  62383. + return -DWC_E_INVALID;
  62384. + }
  62385. +
  62386. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  62387. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  62388. + DWC_ERROR
  62389. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  62390. + val);
  62391. + }
  62392. + retval = -DWC_E_INVALID;
  62393. + val = 0;
  62394. + }
  62395. + core_if->core_params->ic_usb_cap = val;
  62396. + return retval;
  62397. +}
  62398. +
  62399. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  62400. +{
  62401. + return core_if->core_params->ic_usb_cap;
  62402. +}
  62403. +
  62404. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  62405. +{
  62406. + int retval = 0;
  62407. + int valid = 1;
  62408. +
  62409. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  62410. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  62411. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  62412. + return -DWC_E_INVALID;
  62413. + }
  62414. +
  62415. + if (val
  62416. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  62417. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  62418. + valid = 0;
  62419. + } else if (val
  62420. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  62421. + 4)) {
  62422. + valid = 0;
  62423. + }
  62424. + if (valid == 0) {
  62425. + if (dwc_otg_param_initialized
  62426. + (core_if->core_params->ahb_thr_ratio)) {
  62427. + DWC_ERROR
  62428. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  62429. + val);
  62430. + }
  62431. + retval = -DWC_E_INVALID;
  62432. + val = 0;
  62433. + }
  62434. +
  62435. + core_if->core_params->ahb_thr_ratio = val;
  62436. + return retval;
  62437. +}
  62438. +
  62439. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  62440. +{
  62441. + return core_if->core_params->ahb_thr_ratio;
  62442. +}
  62443. +
  62444. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  62445. +{
  62446. + int retval = 0;
  62447. + int valid = 1;
  62448. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  62449. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  62450. +
  62451. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  62452. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  62453. + DWC_WARN("power_down must be 0 - 2\n");
  62454. + return -DWC_E_INVALID;
  62455. + }
  62456. +
  62457. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  62458. + valid = 0;
  62459. + }
  62460. + if ((val == 3)
  62461. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  62462. + || (hwcfg4.b.xhiber == 0))) {
  62463. + valid = 0;
  62464. + }
  62465. + if (valid == 0) {
  62466. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  62467. + DWC_ERROR
  62468. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  62469. + val);
  62470. + }
  62471. + retval = -DWC_E_INVALID;
  62472. + val = 0;
  62473. + }
  62474. + core_if->core_params->power_down = val;
  62475. + return retval;
  62476. +}
  62477. +
  62478. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  62479. +{
  62480. + return core_if->core_params->power_down;
  62481. +}
  62482. +
  62483. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62484. +{
  62485. + int retval = 0;
  62486. + int valid = 1;
  62487. +
  62488. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62489. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  62490. + DWC_WARN("reload_ctl must be 0 or 1\n");
  62491. + return -DWC_E_INVALID;
  62492. + }
  62493. +
  62494. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  62495. + valid = 0;
  62496. + }
  62497. + if (valid == 0) {
  62498. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  62499. + DWC_ERROR("%d invalid for parameter reload_ctl."
  62500. + "Check HW configuration.\n", val);
  62501. + }
  62502. + retval = -DWC_E_INVALID;
  62503. + val = 0;
  62504. + }
  62505. + core_if->core_params->reload_ctl = val;
  62506. + return retval;
  62507. +}
  62508. +
  62509. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  62510. +{
  62511. + return core_if->core_params->reload_ctl;
  62512. +}
  62513. +
  62514. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  62515. +{
  62516. + int retval = 0;
  62517. + int valid = 1;
  62518. +
  62519. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62520. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  62521. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  62522. + return -DWC_E_INVALID;
  62523. + }
  62524. +
  62525. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  62526. + !(core_if->core_params->dma_desc_enable))) {
  62527. + valid = 0;
  62528. + }
  62529. + if (valid == 0) {
  62530. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  62531. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  62532. + "Check HW configuration.\n", val);
  62533. + }
  62534. + retval = -DWC_E_INVALID;
  62535. + val = 0;
  62536. + }
  62537. + core_if->core_params->dev_out_nak = val;
  62538. + return retval;
  62539. +}
  62540. +
  62541. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  62542. +{
  62543. + return core_if->core_params->dev_out_nak;
  62544. +}
  62545. +
  62546. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  62547. +{
  62548. + int retval = 0;
  62549. + int valid = 1;
  62550. +
  62551. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62552. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  62553. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  62554. + return -DWC_E_INVALID;
  62555. + }
  62556. +
  62557. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  62558. + !(core_if->core_params->dma_desc_enable))) {
  62559. + valid = 0;
  62560. + }
  62561. + if (valid == 0) {
  62562. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  62563. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  62564. + "Check HW configuration.\n", val);
  62565. + }
  62566. + retval = -DWC_E_INVALID;
  62567. + val = 0;
  62568. + }
  62569. + core_if->core_params->cont_on_bna = val;
  62570. + return retval;
  62571. +}
  62572. +
  62573. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  62574. +{
  62575. + return core_if->core_params->cont_on_bna;
  62576. +}
  62577. +
  62578. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  62579. +{
  62580. + int retval = 0;
  62581. + int valid = 1;
  62582. +
  62583. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62584. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  62585. + DWC_WARN("ahb_single must be 0 or 1\n");
  62586. + return -DWC_E_INVALID;
  62587. + }
  62588. +
  62589. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  62590. + valid = 0;
  62591. + }
  62592. + if (valid == 0) {
  62593. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  62594. + DWC_ERROR("%d invalid for parameter ahb_single."
  62595. + "Check HW configuration.\n", val);
  62596. + }
  62597. + retval = -DWC_E_INVALID;
  62598. + val = 0;
  62599. + }
  62600. + core_if->core_params->ahb_single = val;
  62601. + return retval;
  62602. +}
  62603. +
  62604. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  62605. +{
  62606. + return core_if->core_params->ahb_single;
  62607. +}
  62608. +
  62609. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  62610. +{
  62611. + int retval = 0;
  62612. +
  62613. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62614. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  62615. + DWC_WARN
  62616. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  62617. + return -DWC_E_INVALID;
  62618. + }
  62619. +
  62620. + core_if->core_params->otg_ver = val;
  62621. + return retval;
  62622. +}
  62623. +
  62624. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  62625. +{
  62626. + return core_if->core_params->otg_ver;
  62627. +}
  62628. +
  62629. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  62630. +{
  62631. + gotgctl_data_t otgctl;
  62632. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62633. + return otgctl.b.hstnegscs;
  62634. +}
  62635. +
  62636. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  62637. +{
  62638. + gotgctl_data_t otgctl;
  62639. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62640. + return otgctl.b.sesreqscs;
  62641. +}
  62642. +
  62643. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  62644. +{
  62645. + if(core_if->otg_ver == 0) {
  62646. + gotgctl_data_t otgctl;
  62647. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62648. + otgctl.b.hnpreq = val;
  62649. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  62650. + } else {
  62651. + core_if->otg_sts = val;
  62652. + }
  62653. +}
  62654. +
  62655. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  62656. +{
  62657. + return core_if->snpsid;
  62658. +}
  62659. +
  62660. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  62661. +{
  62662. + gintsts_data_t gintsts;
  62663. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  62664. + return gintsts.b.curmode;
  62665. +}
  62666. +
  62667. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  62668. +{
  62669. + gusbcfg_data_t usbcfg;
  62670. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62671. + return usbcfg.b.hnpcap;
  62672. +}
  62673. +
  62674. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62675. +{
  62676. + gusbcfg_data_t usbcfg;
  62677. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62678. + usbcfg.b.hnpcap = val;
  62679. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62680. +}
  62681. +
  62682. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  62683. +{
  62684. + gusbcfg_data_t usbcfg;
  62685. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62686. + return usbcfg.b.srpcap;
  62687. +}
  62688. +
  62689. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62690. +{
  62691. + gusbcfg_data_t usbcfg;
  62692. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62693. + usbcfg.b.srpcap = val;
  62694. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62695. +}
  62696. +
  62697. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  62698. +{
  62699. + dcfg_data_t dcfg;
  62700. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  62701. +
  62702. + dcfg.d32 = -1; //GRAYG
  62703. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  62704. + if (NULL == core_if)
  62705. + DWC_ERROR("reg request with NULL core_if\n");
  62706. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  62707. + core_if, core_if->dev_if);
  62708. + if (NULL == core_if->dev_if)
  62709. + DWC_ERROR("reg request with NULL dev_if\n");
  62710. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  62711. + "dev_global_regs(%p)\n", __func__,
  62712. + core_if, core_if->dev_if,
  62713. + core_if->dev_if->dev_global_regs);
  62714. + if (NULL == core_if->dev_if->dev_global_regs)
  62715. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  62716. + else {
  62717. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  62718. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  62719. + core_if, core_if->dev_if,
  62720. + core_if->dev_if->dev_global_regs,
  62721. + &core_if->dev_if->dev_global_regs->dcfg);
  62722. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62723. + }
  62724. + return dcfg.b.devspd;
  62725. +}
  62726. +
  62727. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  62728. +{
  62729. + dcfg_data_t dcfg;
  62730. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62731. + dcfg.b.devspd = val;
  62732. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  62733. +}
  62734. +
  62735. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  62736. +{
  62737. + hprt0_data_t hprt0;
  62738. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62739. + return hprt0.b.prtconnsts;
  62740. +}
  62741. +
  62742. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  62743. +{
  62744. + dsts_data_t dsts;
  62745. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  62746. + return dsts.b.enumspd;
  62747. +}
  62748. +
  62749. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  62750. +{
  62751. + hprt0_data_t hprt0;
  62752. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62753. + return hprt0.b.prtpwr;
  62754. +
  62755. +}
  62756. +
  62757. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  62758. +{
  62759. + return core_if->hibernation_suspend;
  62760. +}
  62761. +
  62762. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  62763. +{
  62764. + hprt0_data_t hprt0;
  62765. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62766. + hprt0.b.prtpwr = val;
  62767. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62768. +}
  62769. +
  62770. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  62771. +{
  62772. + hprt0_data_t hprt0;
  62773. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62774. + return hprt0.b.prtsusp;
  62775. +
  62776. +}
  62777. +
  62778. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  62779. +{
  62780. + hprt0_data_t hprt0;
  62781. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62782. + hprt0.b.prtsusp = val;
  62783. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62784. +}
  62785. +
  62786. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  62787. +{
  62788. + hfir_data_t hfir;
  62789. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62790. + return hfir.b.frint;
  62791. +
  62792. +}
  62793. +
  62794. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  62795. +{
  62796. + hfir_data_t hfir;
  62797. + uint32_t fram_int;
  62798. + fram_int = calc_frame_interval(core_if);
  62799. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62800. + if (!core_if->core_params->reload_ctl) {
  62801. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  62802. + "not set to 1.\nShould load driver with reload_ctl=1"
  62803. + " module parameter\n");
  62804. + return;
  62805. + }
  62806. + switch (fram_int) {
  62807. + case 3750:
  62808. + if ((val < 3350) || (val > 4150)) {
  62809. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  62810. + "clock freq should be from 3350 to 4150\n");
  62811. + return;
  62812. + }
  62813. + break;
  62814. + case 30000:
  62815. + if ((val < 26820) || (val > 33180)) {
  62816. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  62817. + "clock freq should be from 26820 to 33180\n");
  62818. + return;
  62819. + }
  62820. + break;
  62821. + case 6000:
  62822. + if ((val < 5360) || (val > 6640)) {
  62823. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  62824. + "clock freq should be from 5360 to 6640\n");
  62825. + return;
  62826. + }
  62827. + break;
  62828. + case 48000:
  62829. + if ((val < 42912) || (val > 53088)) {
  62830. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  62831. + "clock freq should be from 42912 to 53088\n");
  62832. + return;
  62833. + }
  62834. + break;
  62835. + case 7500:
  62836. + if ((val < 6700) || (val > 8300)) {
  62837. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  62838. + "clock freq should be from 6700 to 8300\n");
  62839. + return;
  62840. + }
  62841. + break;
  62842. + case 60000:
  62843. + if ((val < 53640) || (val > 65536)) {
  62844. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  62845. + "clock freq should be from 53640 to 65536\n");
  62846. + return;
  62847. + }
  62848. + break;
  62849. + default:
  62850. + DWC_WARN("Unknown frame interval\n");
  62851. + return;
  62852. + break;
  62853. +
  62854. + }
  62855. + hfir.b.frint = val;
  62856. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  62857. +}
  62858. +
  62859. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  62860. +{
  62861. + hcfg_data_t hcfg;
  62862. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62863. + return hcfg.b.modechtimen;
  62864. +
  62865. +}
  62866. +
  62867. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  62868. +{
  62869. + hcfg_data_t hcfg;
  62870. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62871. + hcfg.b.modechtimen = val;
  62872. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  62873. +}
  62874. +
  62875. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  62876. +{
  62877. + hprt0_data_t hprt0;
  62878. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62879. + hprt0.b.prtres = val;
  62880. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62881. +}
  62882. +
  62883. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  62884. +{
  62885. + dctl_data_t dctl;
  62886. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  62887. + return dctl.b.rmtwkupsig;
  62888. +}
  62889. +
  62890. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  62891. +{
  62892. + glpmcfg_data_t lpmcfg;
  62893. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62894. +
  62895. + DWC_ASSERT(!
  62896. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  62897. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  62898. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  62899. +
  62900. + return lpmcfg.b.prt_sleep_sts;
  62901. +}
  62902. +
  62903. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  62904. +{
  62905. + glpmcfg_data_t lpmcfg;
  62906. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62907. + return lpmcfg.b.rem_wkup_en;
  62908. +}
  62909. +
  62910. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  62911. +{
  62912. + glpmcfg_data_t lpmcfg;
  62913. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62914. + return lpmcfg.b.appl_resp;
  62915. +}
  62916. +
  62917. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  62918. +{
  62919. + glpmcfg_data_t lpmcfg;
  62920. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62921. + lpmcfg.b.appl_resp = val;
  62922. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62923. +}
  62924. +
  62925. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  62926. +{
  62927. + glpmcfg_data_t lpmcfg;
  62928. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62929. + return lpmcfg.b.hsic_connect;
  62930. +}
  62931. +
  62932. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  62933. +{
  62934. + glpmcfg_data_t lpmcfg;
  62935. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62936. + lpmcfg.b.hsic_connect = val;
  62937. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62938. +}
  62939. +
  62940. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  62941. +{
  62942. + glpmcfg_data_t lpmcfg;
  62943. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62944. + return lpmcfg.b.inv_sel_hsic;
  62945. +
  62946. +}
  62947. +
  62948. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  62949. +{
  62950. + glpmcfg_data_t lpmcfg;
  62951. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62952. + lpmcfg.b.inv_sel_hsic = val;
  62953. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62954. +}
  62955. +
  62956. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  62957. +{
  62958. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62959. +}
  62960. +
  62961. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62962. +{
  62963. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  62964. +}
  62965. +
  62966. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  62967. +{
  62968. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62969. +}
  62970. +
  62971. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  62972. +{
  62973. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  62974. +}
  62975. +
  62976. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  62977. +{
  62978. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62979. +}
  62980. +
  62981. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62982. +{
  62983. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  62984. +}
  62985. +
  62986. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  62987. +{
  62988. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  62989. +}
  62990. +
  62991. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62992. +{
  62993. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  62994. +}
  62995. +
  62996. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  62997. +{
  62998. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  62999. +}
  63000. +
  63001. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63002. +{
  63003. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  63004. +}
  63005. +
  63006. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  63007. +{
  63008. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  63009. +}
  63010. +
  63011. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  63012. +{
  63013. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  63014. +}
  63015. +
  63016. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  63017. +{
  63018. + return DWC_READ_REG32(core_if->host_if->hprt0);
  63019. +
  63020. +}
  63021. +
  63022. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  63023. +{
  63024. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  63025. +}
  63026. +
  63027. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  63028. +{
  63029. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  63030. +}
  63031. +
  63032. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  63033. +{
  63034. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  63035. +}
  63036. +
  63037. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  63038. +{
  63039. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  63040. +}
  63041. +
  63042. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  63043. +{
  63044. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  63045. +}
  63046. +
  63047. +/**
  63048. + * Start the SRP timer to detect when the SRP does not complete within
  63049. + * 6 seconds.
  63050. + *
  63051. + * @param core_if the pointer to core_if strucure.
  63052. + */
  63053. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  63054. +{
  63055. + core_if->srp_timer_started = 1;
  63056. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  63057. +}
  63058. +
  63059. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  63060. +{
  63061. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  63062. + gotgctl_data_t mem;
  63063. + gotgctl_data_t val;
  63064. +
  63065. + val.d32 = DWC_READ_REG32(addr);
  63066. + if (val.b.sesreq) {
  63067. + DWC_ERROR("Session Request Already active!\n");
  63068. + return;
  63069. + }
  63070. +
  63071. + DWC_INFO("Session Request Initated\n"); //NOTICE
  63072. + mem.d32 = DWC_READ_REG32(addr);
  63073. + mem.b.sesreq = 1;
  63074. + DWC_WRITE_REG32(addr, mem.d32);
  63075. +
  63076. + /* Start the SRP timer */
  63077. + dwc_otg_pcd_start_srp_timer(core_if);
  63078. + return;
  63079. +}
  63080. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  63081. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  63082. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-03-13 12:46:39.516097989 +0100
  63083. @@ -0,0 +1,1464 @@
  63084. +/* ==========================================================================
  63085. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  63086. + * $Revision: #123 $
  63087. + * $Date: 2012/08/10 $
  63088. + * $Change: 2047372 $
  63089. + *
  63090. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63091. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63092. + * otherwise expressly agreed to in writing between Synopsys and you.
  63093. + *
  63094. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63095. + * any End User Software License Agreement or Agreement for Licensed Product
  63096. + * with Synopsys or any supplement thereto. You are permitted to use and
  63097. + * redistribute this Software in source and binary forms, with or without
  63098. + * modification, provided that redistributions of source code must retain this
  63099. + * notice. You may not view, use, disclose, copy or distribute this file or
  63100. + * any information contained herein except pursuant to this license grant from
  63101. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63102. + * below, then you are not authorized to use the Software.
  63103. + *
  63104. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63105. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63106. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63107. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63108. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63109. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63110. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63111. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63112. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63113. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63114. + * DAMAGE.
  63115. + * ========================================================================== */
  63116. +
  63117. +#if !defined(__DWC_CIL_H__)
  63118. +#define __DWC_CIL_H__
  63119. +
  63120. +#include "dwc_list.h"
  63121. +#include "dwc_otg_dbg.h"
  63122. +#include "dwc_otg_regs.h"
  63123. +
  63124. +#include "dwc_otg_core_if.h"
  63125. +#include "dwc_otg_adp.h"
  63126. +
  63127. +/**
  63128. + * @file
  63129. + * This file contains the interface to the Core Interface Layer.
  63130. + */
  63131. +
  63132. +#ifdef DWC_UTE_CFI
  63133. +
  63134. +#define MAX_DMA_DESCS_PER_EP 256
  63135. +
  63136. +/**
  63137. + * Enumeration for the data buffer mode
  63138. + */
  63139. +typedef enum _data_buffer_mode {
  63140. + BM_STANDARD = 0, /* data buffer is in normal mode */
  63141. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  63142. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  63143. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  63144. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  63145. +} data_buffer_mode_e;
  63146. +#endif //DWC_UTE_CFI
  63147. +
  63148. +/** Macros defined for DWC OTG HW Release version */
  63149. +
  63150. +#define OTG_CORE_REV_2_60a 0x4F54260A
  63151. +#define OTG_CORE_REV_2_71a 0x4F54271A
  63152. +#define OTG_CORE_REV_2_72a 0x4F54272A
  63153. +#define OTG_CORE_REV_2_80a 0x4F54280A
  63154. +#define OTG_CORE_REV_2_81a 0x4F54281A
  63155. +#define OTG_CORE_REV_2_90a 0x4F54290A
  63156. +#define OTG_CORE_REV_2_91a 0x4F54291A
  63157. +#define OTG_CORE_REV_2_92a 0x4F54292A
  63158. +#define OTG_CORE_REV_2_93a 0x4F54293A
  63159. +#define OTG_CORE_REV_2_94a 0x4F54294A
  63160. +#define OTG_CORE_REV_3_00a 0x4F54300A
  63161. +
  63162. +/**
  63163. + * Information for each ISOC packet.
  63164. + */
  63165. +typedef struct iso_pkt_info {
  63166. + uint32_t offset;
  63167. + uint32_t length;
  63168. + int32_t status;
  63169. +} iso_pkt_info_t;
  63170. +
  63171. +/**
  63172. + * The <code>dwc_ep</code> structure represents the state of a single
  63173. + * endpoint when acting in device mode. It contains the data items
  63174. + * needed for an endpoint to be activated and transfer packets.
  63175. + */
  63176. +typedef struct dwc_ep {
  63177. + /** EP number used for register address lookup */
  63178. + uint8_t num;
  63179. + /** EP direction 0 = OUT */
  63180. + unsigned is_in:1;
  63181. + /** EP active. */
  63182. + unsigned active:1;
  63183. +
  63184. + /**
  63185. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  63186. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  63187. + unsigned tx_fifo_num:4;
  63188. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  63189. + unsigned type:2;
  63190. +#define DWC_OTG_EP_TYPE_CONTROL 0
  63191. +#define DWC_OTG_EP_TYPE_ISOC 1
  63192. +#define DWC_OTG_EP_TYPE_BULK 2
  63193. +#define DWC_OTG_EP_TYPE_INTR 3
  63194. +
  63195. + /** DATA start PID for INTR and BULK EP */
  63196. + unsigned data_pid_start:1;
  63197. + /** Frame (even/odd) for ISOC EP */
  63198. + unsigned even_odd_frame:1;
  63199. + /** Max Packet bytes */
  63200. + unsigned maxpacket:11;
  63201. +
  63202. + /** Max Transfer size */
  63203. + uint32_t maxxfer;
  63204. +
  63205. + /** @name Transfer state */
  63206. + /** @{ */
  63207. +
  63208. + /**
  63209. + * Pointer to the beginning of the transfer buffer -- do not modify
  63210. + * during transfer.
  63211. + */
  63212. +
  63213. + dwc_dma_t dma_addr;
  63214. +
  63215. + dwc_dma_t dma_desc_addr;
  63216. + dwc_otg_dev_dma_desc_t *desc_addr;
  63217. +
  63218. + uint8_t *start_xfer_buff;
  63219. + /** pointer to the transfer buffer */
  63220. + uint8_t *xfer_buff;
  63221. + /** Number of bytes to transfer */
  63222. + unsigned xfer_len:19;
  63223. + /** Number of bytes transferred. */
  63224. + unsigned xfer_count:19;
  63225. + /** Sent ZLP */
  63226. + unsigned sent_zlp:1;
  63227. + /** Total len for control transfer */
  63228. + unsigned total_len:19;
  63229. +
  63230. + /** stall clear flag */
  63231. + unsigned stall_clear_flag:1;
  63232. +
  63233. + /** SETUP pkt cnt rollover flag for EP0 out*/
  63234. + unsigned stp_rollover;
  63235. +
  63236. +#ifdef DWC_UTE_CFI
  63237. + /* The buffer mode */
  63238. + data_buffer_mode_e buff_mode;
  63239. +
  63240. + /* The chain of DMA descriptors.
  63241. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  63242. + */
  63243. + dwc_otg_dma_desc_t *descs;
  63244. +
  63245. + /* The DMA address of the descriptors chain start */
  63246. + dma_addr_t descs_dma_addr;
  63247. + /** This variable stores the length of the last enqueued request */
  63248. + uint32_t cfi_req_len;
  63249. +#endif //DWC_UTE_CFI
  63250. +
  63251. +/** Max DMA Descriptor count for any EP */
  63252. +#define MAX_DMA_DESC_CNT 256
  63253. + /** Allocated DMA Desc count */
  63254. + uint32_t desc_cnt;
  63255. +
  63256. + /** bInterval */
  63257. + uint32_t bInterval;
  63258. + /** Next frame num to setup next ISOC transfer */
  63259. + uint32_t frame_num;
  63260. + /** Indicates SOF number overrun in DSTS */
  63261. + uint8_t frm_overrun;
  63262. +
  63263. +#ifdef DWC_UTE_PER_IO
  63264. + /** Next frame num for which will be setup DMA Desc */
  63265. + uint32_t xiso_frame_num;
  63266. + /** bInterval */
  63267. + uint32_t xiso_bInterval;
  63268. + /** Count of currently active transfers - shall be either 0 or 1 */
  63269. + int xiso_active_xfers;
  63270. + int xiso_queued_xfers;
  63271. +#endif
  63272. +#ifdef DWC_EN_ISOC
  63273. + /**
  63274. + * Variables specific for ISOC EPs
  63275. + *
  63276. + */
  63277. + /** DMA addresses of ISOC buffers */
  63278. + dwc_dma_t dma_addr0;
  63279. + dwc_dma_t dma_addr1;
  63280. +
  63281. + dwc_dma_t iso_dma_desc_addr;
  63282. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  63283. +
  63284. + /** pointer to the transfer buffers */
  63285. + uint8_t *xfer_buff0;
  63286. + uint8_t *xfer_buff1;
  63287. +
  63288. + /** number of ISOC Buffer is processing */
  63289. + uint32_t proc_buf_num;
  63290. + /** Interval of ISOC Buffer processing */
  63291. + uint32_t buf_proc_intrvl;
  63292. + /** Data size for regular frame */
  63293. + uint32_t data_per_frame;
  63294. +
  63295. + /* todo - pattern data support is to be implemented in the future */
  63296. + /** Data size for pattern frame */
  63297. + uint32_t data_pattern_frame;
  63298. + /** Frame number of pattern data */
  63299. + uint32_t sync_frame;
  63300. +
  63301. + /** bInterval */
  63302. + uint32_t bInterval;
  63303. + /** ISO Packet number per frame */
  63304. + uint32_t pkt_per_frm;
  63305. + /** Next frame num for which will be setup DMA Desc */
  63306. + uint32_t next_frame;
  63307. + /** Number of packets per buffer processing */
  63308. + uint32_t pkt_cnt;
  63309. + /** Info for all isoc packets */
  63310. + iso_pkt_info_t *pkt_info;
  63311. + /** current pkt number */
  63312. + uint32_t cur_pkt;
  63313. + /** current pkt number */
  63314. + uint8_t *cur_pkt_addr;
  63315. + /** current pkt number */
  63316. + uint32_t cur_pkt_dma_addr;
  63317. +#endif /* DWC_EN_ISOC */
  63318. +
  63319. +/** @} */
  63320. +} dwc_ep_t;
  63321. +
  63322. +/*
  63323. + * Reasons for halting a host channel.
  63324. + */
  63325. +typedef enum dwc_otg_halt_status {
  63326. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  63327. + DWC_OTG_HC_XFER_COMPLETE,
  63328. + DWC_OTG_HC_XFER_URB_COMPLETE,
  63329. + DWC_OTG_HC_XFER_ACK,
  63330. + DWC_OTG_HC_XFER_NAK,
  63331. + DWC_OTG_HC_XFER_NYET,
  63332. + DWC_OTG_HC_XFER_STALL,
  63333. + DWC_OTG_HC_XFER_XACT_ERR,
  63334. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  63335. + DWC_OTG_HC_XFER_BABBLE_ERR,
  63336. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  63337. + DWC_OTG_HC_XFER_AHB_ERR,
  63338. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  63339. + DWC_OTG_HC_XFER_URB_DEQUEUE
  63340. +} dwc_otg_halt_status_e;
  63341. +
  63342. +/**
  63343. + * Host channel descriptor. This structure represents the state of a single
  63344. + * host channel when acting in host mode. It contains the data items needed to
  63345. + * transfer packets to an endpoint via a host channel.
  63346. + */
  63347. +typedef struct dwc_hc {
  63348. + /** Host channel number used for register address lookup */
  63349. + uint8_t hc_num;
  63350. +
  63351. + /** Device to access */
  63352. + unsigned dev_addr:7;
  63353. +
  63354. + /** EP to access */
  63355. + unsigned ep_num:4;
  63356. +
  63357. + /** EP direction. 0: OUT, 1: IN */
  63358. + unsigned ep_is_in:1;
  63359. +
  63360. + /**
  63361. + * EP speed.
  63362. + * One of the following values:
  63363. + * - DWC_OTG_EP_SPEED_LOW
  63364. + * - DWC_OTG_EP_SPEED_FULL
  63365. + * - DWC_OTG_EP_SPEED_HIGH
  63366. + */
  63367. + unsigned speed:2;
  63368. +#define DWC_OTG_EP_SPEED_LOW 0
  63369. +#define DWC_OTG_EP_SPEED_FULL 1
  63370. +#define DWC_OTG_EP_SPEED_HIGH 2
  63371. +
  63372. + /**
  63373. + * Endpoint type.
  63374. + * One of the following values:
  63375. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  63376. + * - DWC_OTG_EP_TYPE_ISOC: 1
  63377. + * - DWC_OTG_EP_TYPE_BULK: 2
  63378. + * - DWC_OTG_EP_TYPE_INTR: 3
  63379. + */
  63380. + unsigned ep_type:2;
  63381. +
  63382. + /** Max packet size in bytes */
  63383. + unsigned max_packet:11;
  63384. +
  63385. + /**
  63386. + * PID for initial transaction.
  63387. + * 0: DATA0,<br>
  63388. + * 1: DATA2,<br>
  63389. + * 2: DATA1,<br>
  63390. + * 3: MDATA (non-Control EP),
  63391. + * SETUP (Control EP)
  63392. + */
  63393. + unsigned data_pid_start:2;
  63394. +#define DWC_OTG_HC_PID_DATA0 0
  63395. +#define DWC_OTG_HC_PID_DATA2 1
  63396. +#define DWC_OTG_HC_PID_DATA1 2
  63397. +#define DWC_OTG_HC_PID_MDATA 3
  63398. +#define DWC_OTG_HC_PID_SETUP 3
  63399. +
  63400. + /** Number of periodic transactions per (micro)frame */
  63401. + unsigned multi_count:2;
  63402. +
  63403. + /** @name Transfer State */
  63404. + /** @{ */
  63405. +
  63406. + /** Pointer to the current transfer buffer position. */
  63407. + uint8_t *xfer_buff;
  63408. + /**
  63409. + * In Buffer DMA mode this buffer will be used
  63410. + * if xfer_buff is not DWORD aligned.
  63411. + */
  63412. + dwc_dma_t align_buff;
  63413. + /** Total number of bytes to transfer. */
  63414. + uint32_t xfer_len;
  63415. + /** Number of bytes transferred so far. */
  63416. + uint32_t xfer_count;
  63417. + /** Packet count at start of transfer.*/
  63418. + uint16_t start_pkt_count;
  63419. +
  63420. + /**
  63421. + * Flag to indicate whether the transfer has been started. Set to 1 if
  63422. + * it has been started, 0 otherwise.
  63423. + */
  63424. + uint8_t xfer_started;
  63425. +
  63426. + /**
  63427. + * Set to 1 to indicate that a PING request should be issued on this
  63428. + * channel. If 0, process normally.
  63429. + */
  63430. + uint8_t do_ping;
  63431. +
  63432. + /**
  63433. + * Set to 1 to indicate that the error count for this transaction is
  63434. + * non-zero. Set to 0 if the error count is 0.
  63435. + */
  63436. + uint8_t error_state;
  63437. +
  63438. + /**
  63439. + * Set to 1 to indicate that this channel should be halted the next
  63440. + * time a request is queued for the channel. This is necessary in
  63441. + * slave mode if no request queue space is available when an attempt
  63442. + * is made to halt the channel.
  63443. + */
  63444. + uint8_t halt_on_queue;
  63445. +
  63446. + /**
  63447. + * Set to 1 if the host channel has been halted, but the core is not
  63448. + * finished flushing queued requests. Otherwise 0.
  63449. + */
  63450. + uint8_t halt_pending;
  63451. +
  63452. + /**
  63453. + * Reason for halting the host channel.
  63454. + */
  63455. + dwc_otg_halt_status_e halt_status;
  63456. +
  63457. + /*
  63458. + * Split settings for the host channel
  63459. + */
  63460. + uint8_t do_split; /**< Enable split for the channel */
  63461. + uint8_t complete_split; /**< Enable complete split */
  63462. + uint8_t hub_addr; /**< Address of high speed hub */
  63463. +
  63464. + uint8_t port_addr; /**< Port of the low/full speed device */
  63465. + /** Split transaction position
  63466. + * One of the following values:
  63467. + * - DWC_HCSPLIT_XACTPOS_MID
  63468. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  63469. + * - DWC_HCSPLIT_XACTPOS_END
  63470. + * - DWC_HCSPLIT_XACTPOS_ALL */
  63471. + uint8_t xact_pos;
  63472. +
  63473. + /** Set when the host channel does a short read. */
  63474. + uint8_t short_read;
  63475. +
  63476. + /**
  63477. + * Number of requests issued for this channel since it was assigned to
  63478. + * the current transfer (not counting PINGs).
  63479. + */
  63480. + uint8_t requests;
  63481. +
  63482. + /**
  63483. + * Queue Head for the transfer being processed by this channel.
  63484. + */
  63485. + struct dwc_otg_qh *qh;
  63486. +
  63487. + /** @} */
  63488. +
  63489. + /** Entry in list of host channels. */
  63490. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  63491. +
  63492. + /** @name Descriptor DMA support */
  63493. + /** @{ */
  63494. +
  63495. + /** Number of Transfer Descriptors */
  63496. + uint16_t ntd;
  63497. +
  63498. + /** Descriptor List DMA address */
  63499. + dwc_dma_t desc_list_addr;
  63500. +
  63501. + /** Scheduling micro-frame bitmap. */
  63502. + uint8_t schinfo;
  63503. +
  63504. + /** @} */
  63505. +} dwc_hc_t;
  63506. +
  63507. +/**
  63508. + * The following parameters may be specified when starting the module. These
  63509. + * parameters define how the DWC_otg controller should be configured.
  63510. + */
  63511. +typedef struct dwc_otg_core_params {
  63512. + int32_t opt;
  63513. +
  63514. + /**
  63515. + * Specifies the OTG capabilities. The driver will automatically
  63516. + * detect the value for this parameter if none is specified.
  63517. + * 0 - HNP and SRP capable (default)
  63518. + * 1 - SRP Only capable
  63519. + * 2 - No HNP/SRP capable
  63520. + */
  63521. + int32_t otg_cap;
  63522. +
  63523. + /**
  63524. + * Specifies whether to use slave or DMA mode for accessing the data
  63525. + * FIFOs. The driver will automatically detect the value for this
  63526. + * parameter if none is specified.
  63527. + * 0 - Slave
  63528. + * 1 - DMA (default, if available)
  63529. + */
  63530. + int32_t dma_enable;
  63531. +
  63532. + /**
  63533. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  63534. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  63535. + * will automatically detect the value for this if none is specified.
  63536. + * 0 - address DMA
  63537. + * 1 - DMA Descriptor(default, if available)
  63538. + */
  63539. + int32_t dma_desc_enable;
  63540. + /** The DMA Burst size (applicable only for External DMA
  63541. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  63542. + */
  63543. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  63544. +
  63545. + /**
  63546. + * Specifies the maximum speed of operation in host and device mode.
  63547. + * The actual speed depends on the speed of the attached device and
  63548. + * the value of phy_type. The actual speed depends on the speed of the
  63549. + * attached device.
  63550. + * 0 - High Speed (default)
  63551. + * 1 - Full Speed
  63552. + */
  63553. + int32_t speed;
  63554. + /** Specifies whether low power mode is supported when attached
  63555. + * to a Full Speed or Low Speed device in host mode.
  63556. + * 0 - Don't support low power mode (default)
  63557. + * 1 - Support low power mode
  63558. + */
  63559. + int32_t host_support_fs_ls_low_power;
  63560. +
  63561. + /** Specifies the PHY clock rate in low power mode when connected to a
  63562. + * Low Speed device in host mode. This parameter is applicable only if
  63563. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  63564. + * then defaults to 6 MHZ otherwise 48 MHZ.
  63565. + *
  63566. + * 0 - 48 MHz
  63567. + * 1 - 6 MHz
  63568. + */
  63569. + int32_t host_ls_low_power_phy_clk;
  63570. +
  63571. + /**
  63572. + * 0 - Use cC FIFO size parameters
  63573. + * 1 - Allow dynamic FIFO sizing (default)
  63574. + */
  63575. + int32_t enable_dynamic_fifo;
  63576. +
  63577. + /** Total number of 4-byte words in the data FIFO memory. This
  63578. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  63579. + * Tx FIFOs.
  63580. + * 32 to 32768 (default 8192)
  63581. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  63582. + */
  63583. + int32_t data_fifo_size;
  63584. +
  63585. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  63586. + * FIFO sizing is enabled.
  63587. + * 16 to 32768 (default 1064)
  63588. + */
  63589. + int32_t dev_rx_fifo_size;
  63590. +
  63591. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  63592. + * when dynamic FIFO sizing is enabled.
  63593. + * 16 to 32768 (default 1024)
  63594. + */
  63595. + int32_t dev_nperio_tx_fifo_size;
  63596. +
  63597. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  63598. + * mode when dynamic FIFO sizing is enabled.
  63599. + * 4 to 768 (default 256)
  63600. + */
  63601. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  63602. +
  63603. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  63604. + * FIFO sizing is enabled.
  63605. + * 16 to 32768 (default 1024)
  63606. + */
  63607. + int32_t host_rx_fifo_size;
  63608. +
  63609. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  63610. + * when Dynamic FIFO sizing is enabled in the core.
  63611. + * 16 to 32768 (default 1024)
  63612. + */
  63613. + int32_t host_nperio_tx_fifo_size;
  63614. +
  63615. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  63616. + * FIFO sizing is enabled.
  63617. + * 16 to 32768 (default 1024)
  63618. + */
  63619. + int32_t host_perio_tx_fifo_size;
  63620. +
  63621. + /** The maximum transfer size supported in bytes.
  63622. + * 2047 to 65,535 (default 65,535)
  63623. + */
  63624. + int32_t max_transfer_size;
  63625. +
  63626. + /** The maximum number of packets in a transfer.
  63627. + * 15 to 511 (default 511)
  63628. + */
  63629. + int32_t max_packet_count;
  63630. +
  63631. + /** The number of host channel registers to use.
  63632. + * 1 to 16 (default 12)
  63633. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  63634. + */
  63635. + int32_t host_channels;
  63636. +
  63637. + /** The number of endpoints in addition to EP0 available for device
  63638. + * mode operations.
  63639. + * 1 to 15 (default 6 IN and OUT)
  63640. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  63641. + * endpoints in addition to EP0.
  63642. + */
  63643. + int32_t dev_endpoints;
  63644. +
  63645. + /**
  63646. + * Specifies the type of PHY interface to use. By default, the driver
  63647. + * will automatically detect the phy_type.
  63648. + *
  63649. + * 0 - Full Speed PHY
  63650. + * 1 - UTMI+ (default)
  63651. + * 2 - ULPI
  63652. + */
  63653. + int32_t phy_type;
  63654. +
  63655. + /**
  63656. + * Specifies the UTMI+ Data Width. This parameter is
  63657. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  63658. + * PHY_TYPE, this parameter indicates the data width between
  63659. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  63660. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  63661. + * to "8 and 16 bits", meaning that the core has been
  63662. + * configured to work at either data path width.
  63663. + *
  63664. + * 8 or 16 bits (default 16)
  63665. + */
  63666. + int32_t phy_utmi_width;
  63667. +
  63668. + /**
  63669. + * Specifies whether the ULPI operates at double or single
  63670. + * data rate. This parameter is only applicable if PHY_TYPE is
  63671. + * ULPI.
  63672. + *
  63673. + * 0 - single data rate ULPI interface with 8 bit wide data
  63674. + * bus (default)
  63675. + * 1 - double data rate ULPI interface with 4 bit wide data
  63676. + * bus
  63677. + */
  63678. + int32_t phy_ulpi_ddr;
  63679. +
  63680. + /**
  63681. + * Specifies whether to use the internal or external supply to
  63682. + * drive the vbus with a ULPI phy.
  63683. + */
  63684. + int32_t phy_ulpi_ext_vbus;
  63685. +
  63686. + /**
  63687. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  63688. + * parameter is only applicable if PHY_TYPE is FS.
  63689. + * 0 - No (default)
  63690. + * 1 - Yes
  63691. + */
  63692. + int32_t i2c_enable;
  63693. +
  63694. + int32_t ulpi_fs_ls;
  63695. +
  63696. + int32_t ts_dline;
  63697. +
  63698. + /**
  63699. + * Specifies whether dedicated transmit FIFOs are
  63700. + * enabled for non periodic IN endpoints in device mode
  63701. + * 0 - No
  63702. + * 1 - Yes
  63703. + */
  63704. + int32_t en_multiple_tx_fifo;
  63705. +
  63706. + /** Number of 4-byte words in each of the Tx FIFOs in device
  63707. + * mode when dynamic FIFO sizing is enabled.
  63708. + * 4 to 768 (default 256)
  63709. + */
  63710. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  63711. +
  63712. + /** Thresholding enable flag-
  63713. + * bit 0 - enable non-ISO Tx thresholding
  63714. + * bit 1 - enable ISO Tx thresholding
  63715. + * bit 2 - enable Rx thresholding
  63716. + */
  63717. + uint32_t thr_ctl;
  63718. +
  63719. + /** Thresholding length for Tx
  63720. + * FIFOs in 32 bit DWORDs
  63721. + */
  63722. + uint32_t tx_thr_length;
  63723. +
  63724. + /** Thresholding length for Rx
  63725. + * FIFOs in 32 bit DWORDs
  63726. + */
  63727. + uint32_t rx_thr_length;
  63728. +
  63729. + /**
  63730. + * Specifies whether LPM (Link Power Management) support is enabled
  63731. + */
  63732. + int32_t lpm_enable;
  63733. +
  63734. + /** Per Transfer Interrupt
  63735. + * mode enable flag
  63736. + * 1 - Enabled
  63737. + * 0 - Disabled
  63738. + */
  63739. + int32_t pti_enable;
  63740. +
  63741. + /** Multi Processor Interrupt
  63742. + * mode enable flag
  63743. + * 1 - Enabled
  63744. + * 0 - Disabled
  63745. + */
  63746. + int32_t mpi_enable;
  63747. +
  63748. + /** IS_USB Capability
  63749. + * 1 - Enabled
  63750. + * 0 - Disabled
  63751. + */
  63752. + int32_t ic_usb_cap;
  63753. +
  63754. + /** AHB Threshold Ratio
  63755. + * 2'b00 AHB Threshold = MAC Threshold
  63756. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  63757. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  63758. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  63759. + */
  63760. + int32_t ahb_thr_ratio;
  63761. +
  63762. + /** ADP Support
  63763. + * 1 - Enabled
  63764. + * 0 - Disabled
  63765. + */
  63766. + int32_t adp_supp_enable;
  63767. +
  63768. + /** HFIR Reload Control
  63769. + * 0 - The HFIR cannot be reloaded dynamically.
  63770. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  63771. + */
  63772. + int32_t reload_ctl;
  63773. +
  63774. + /** DCFG: Enable device Out NAK
  63775. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  63776. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  63777. + */
  63778. + int32_t dev_out_nak;
  63779. +
  63780. + /** DCFG: Enable Continue on BNA
  63781. + * After receiving BNA interrupt the core disables the endpoint,when the
  63782. + * endpoint is re-enabled by the application the core starts processing
  63783. + * 0 - from the DOEPDMA descriptor
  63784. + * 1 - from the descriptor which received the BNA.
  63785. + */
  63786. + int32_t cont_on_bna;
  63787. +
  63788. + /** GAHBCFG: AHB Single Support
  63789. + * This bit when programmed supports SINGLE transfers for remainder
  63790. + * data in a transfer for DMA mode of operation.
  63791. + * 0 - in this case the remainder data will be sent using INCR burst size.
  63792. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  63793. + */
  63794. + int32_t ahb_single;
  63795. +
  63796. + /** Core Power down mode
  63797. + * 0 - No Power Down is enabled
  63798. + * 1 - Reserved
  63799. + * 2 - Complete Power Down (Hibernation)
  63800. + */
  63801. + int32_t power_down;
  63802. +
  63803. + /** OTG revision supported
  63804. + * 0 - OTG 1.3 revision
  63805. + * 1 - OTG 2.0 revision
  63806. + */
  63807. + int32_t otg_ver;
  63808. +
  63809. +} dwc_otg_core_params_t;
  63810. +
  63811. +#ifdef DEBUG
  63812. +struct dwc_otg_core_if;
  63813. +typedef struct hc_xfer_info {
  63814. + struct dwc_otg_core_if *core_if;
  63815. + dwc_hc_t *hc;
  63816. +} hc_xfer_info_t;
  63817. +#endif
  63818. +
  63819. +typedef struct ep_xfer_info {
  63820. + struct dwc_otg_core_if *core_if;
  63821. + dwc_ep_t *ep;
  63822. + uint8_t state;
  63823. +} ep_xfer_info_t;
  63824. +/*
  63825. + * Device States
  63826. + */
  63827. +typedef enum dwc_otg_lx_state {
  63828. + /** On state */
  63829. + DWC_OTG_L0,
  63830. + /** LPM sleep state*/
  63831. + DWC_OTG_L1,
  63832. + /** USB suspend state*/
  63833. + DWC_OTG_L2,
  63834. + /** Off state*/
  63835. + DWC_OTG_L3
  63836. +} dwc_otg_lx_state_e;
  63837. +
  63838. +struct dwc_otg_global_regs_backup {
  63839. + uint32_t gotgctl_local;
  63840. + uint32_t gintmsk_local;
  63841. + uint32_t gahbcfg_local;
  63842. + uint32_t gusbcfg_local;
  63843. + uint32_t grxfsiz_local;
  63844. + uint32_t gnptxfsiz_local;
  63845. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63846. + uint32_t glpmcfg_local;
  63847. +#endif
  63848. + uint32_t gi2cctl_local;
  63849. + uint32_t hptxfsiz_local;
  63850. + uint32_t pcgcctl_local;
  63851. + uint32_t gdfifocfg_local;
  63852. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  63853. + uint32_t gpwrdn_local;
  63854. + uint32_t xhib_pcgcctl;
  63855. + uint32_t xhib_gpwrdn;
  63856. +};
  63857. +
  63858. +struct dwc_otg_host_regs_backup {
  63859. + uint32_t hcfg_local;
  63860. + uint32_t haintmsk_local;
  63861. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  63862. + uint32_t hprt0_local;
  63863. + uint32_t hfir_local;
  63864. +};
  63865. +
  63866. +struct dwc_otg_dev_regs_backup {
  63867. + uint32_t dcfg;
  63868. + uint32_t dctl;
  63869. + uint32_t daintmsk;
  63870. + uint32_t diepmsk;
  63871. + uint32_t doepmsk;
  63872. + uint32_t diepctl[MAX_EPS_CHANNELS];
  63873. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  63874. + uint32_t diepdma[MAX_EPS_CHANNELS];
  63875. +};
  63876. +/**
  63877. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  63878. + * the DWC_otg controller acting in either host or device mode. It
  63879. + * represents the programming view of the controller as a whole.
  63880. + */
  63881. +struct dwc_otg_core_if {
  63882. + /** Parameters that define how the core should be configured.*/
  63883. + dwc_otg_core_params_t *core_params;
  63884. +
  63885. + /** Core Global registers starting at offset 000h. */
  63886. + dwc_otg_core_global_regs_t *core_global_regs;
  63887. +
  63888. + /** Device-specific information */
  63889. + dwc_otg_dev_if_t *dev_if;
  63890. + /** Host-specific information */
  63891. + dwc_otg_host_if_t *host_if;
  63892. +
  63893. + /** Value from SNPSID register */
  63894. + uint32_t snpsid;
  63895. +
  63896. + /*
  63897. + * Set to 1 if the core PHY interface bits in USBCFG have been
  63898. + * initialized.
  63899. + */
  63900. + uint8_t phy_init_done;
  63901. +
  63902. + /*
  63903. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  63904. + */
  63905. + uint8_t srp_success;
  63906. + uint8_t srp_timer_started;
  63907. + /** Timer for SRP. If it expires before SRP is successful
  63908. + * clear the SRP. */
  63909. + dwc_timer_t *srp_timer;
  63910. +
  63911. +#ifdef DWC_DEV_SRPCAP
  63912. + /* This timer is needed to power on the hibernated host core if SRP is not
  63913. + * initiated on connected SRP capable device for limited period of time
  63914. + */
  63915. + uint8_t pwron_timer_started;
  63916. + dwc_timer_t *pwron_timer;
  63917. +#endif
  63918. + /* Common configuration information */
  63919. + /** Power and Clock Gating Control Register */
  63920. + volatile uint32_t *pcgcctl;
  63921. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  63922. +
  63923. + /** Push/pop addresses for endpoints or host channels.*/
  63924. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  63925. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  63926. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  63927. +
  63928. + /** Total RAM for FIFOs (Bytes) */
  63929. + uint16_t total_fifo_size;
  63930. + /** Size of Rx FIFO (Bytes) */
  63931. + uint16_t rx_fifo_size;
  63932. + /** Size of Non-periodic Tx FIFO (Bytes) */
  63933. + uint16_t nperio_tx_fifo_size;
  63934. +
  63935. + /** 1 if DMA is enabled, 0 otherwise. */
  63936. + uint8_t dma_enable;
  63937. +
  63938. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  63939. + uint8_t dma_desc_enable;
  63940. +
  63941. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  63942. + uint8_t pti_enh_enable;
  63943. +
  63944. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  63945. + uint8_t multiproc_int_enable;
  63946. +
  63947. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  63948. + uint8_t en_multiple_tx_fifo;
  63949. +
  63950. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  63951. + * process of being queued */
  63952. + uint8_t queuing_high_bandwidth;
  63953. +
  63954. + /** Hardware Configuration -- stored here for convenience.*/
  63955. + hwcfg1_data_t hwcfg1;
  63956. + hwcfg2_data_t hwcfg2;
  63957. + hwcfg3_data_t hwcfg3;
  63958. + hwcfg4_data_t hwcfg4;
  63959. + fifosize_data_t hptxfsiz;
  63960. +
  63961. + /** Host and Device Configuration -- stored here for convenience.*/
  63962. + hcfg_data_t hcfg;
  63963. + dcfg_data_t dcfg;
  63964. +
  63965. + /** The operational State, during transations
  63966. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  63967. + * match the core but allows the software to determine
  63968. + * transitions.
  63969. + */
  63970. + uint8_t op_state;
  63971. +
  63972. + /**
  63973. + * Set to 1 if the HCD needs to be restarted on a session request
  63974. + * interrupt. This is required if no connector ID status change has
  63975. + * occurred since the HCD was last disconnected.
  63976. + */
  63977. + uint8_t restart_hcd_on_session_req;
  63978. +
  63979. + /** HCD callbacks */
  63980. + /** A-Device is a_host */
  63981. +#define A_HOST (1)
  63982. + /** A-Device is a_suspend */
  63983. +#define A_SUSPEND (2)
  63984. + /** A-Device is a_peripherial */
  63985. +#define A_PERIPHERAL (3)
  63986. + /** B-Device is operating as a Peripheral. */
  63987. +#define B_PERIPHERAL (4)
  63988. + /** B-Device is operating as a Host. */
  63989. +#define B_HOST (5)
  63990. +
  63991. + /** HCD callbacks */
  63992. + struct dwc_otg_cil_callbacks *hcd_cb;
  63993. + /** PCD callbacks */
  63994. + struct dwc_otg_cil_callbacks *pcd_cb;
  63995. +
  63996. + /** Device mode Periodic Tx FIFO Mask */
  63997. + uint32_t p_tx_msk;
  63998. + /** Device mode Periodic Tx FIFO Mask */
  63999. + uint32_t tx_msk;
  64000. +
  64001. + /** Workqueue object used for handling several interrupts */
  64002. + dwc_workq_t *wq_otg;
  64003. +
  64004. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  64005. + dwc_timer_t *wkp_timer;
  64006. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  64007. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  64008. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  64009. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  64010. +#ifdef DEBUG
  64011. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  64012. +
  64013. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  64014. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  64015. +
  64016. + uint32_t hfnum_7_samples;
  64017. + uint64_t hfnum_7_frrem_accum;
  64018. + uint32_t hfnum_0_samples;
  64019. + uint64_t hfnum_0_frrem_accum;
  64020. + uint32_t hfnum_other_samples;
  64021. + uint64_t hfnum_other_frrem_accum;
  64022. +#endif
  64023. +
  64024. +#ifdef DWC_UTE_CFI
  64025. + uint16_t pwron_rxfsiz;
  64026. + uint16_t pwron_gnptxfsiz;
  64027. + uint16_t pwron_txfsiz[15];
  64028. +
  64029. + uint16_t init_rxfsiz;
  64030. + uint16_t init_gnptxfsiz;
  64031. + uint16_t init_txfsiz[15];
  64032. +#endif
  64033. +
  64034. + /** Lx state of device */
  64035. + dwc_otg_lx_state_e lx_state;
  64036. +
  64037. + /** Saved Core Global registers */
  64038. + struct dwc_otg_global_regs_backup *gr_backup;
  64039. + /** Saved Host registers */
  64040. + struct dwc_otg_host_regs_backup *hr_backup;
  64041. + /** Saved Device registers */
  64042. + struct dwc_otg_dev_regs_backup *dr_backup;
  64043. +
  64044. + /** Power Down Enable */
  64045. + uint32_t power_down;
  64046. +
  64047. + /** ADP support Enable */
  64048. + uint32_t adp_enable;
  64049. +
  64050. + /** ADP structure object */
  64051. + dwc_otg_adp_t adp;
  64052. +
  64053. + /** hibernation/suspend flag */
  64054. + int hibernation_suspend;
  64055. +
  64056. + /** Device mode extended hibernation flag */
  64057. + int xhib;
  64058. +
  64059. + /** OTG revision supported */
  64060. + uint32_t otg_ver;
  64061. +
  64062. + /** OTG status flag used for HNP polling */
  64063. + uint8_t otg_sts;
  64064. +
  64065. + /** Pointer to either hcd->lock or pcd->lock */
  64066. + dwc_spinlock_t *lock;
  64067. +
  64068. + /** Start predict NextEP based on Learning Queue if equal 1,
  64069. + * also used as counter of disabled NP IN EP's */
  64070. + uint8_t start_predict;
  64071. +
  64072. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  64073. + * active, 0xff otherwise */
  64074. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  64075. +
  64076. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  64077. + uint8_t first_in_nextep_seq;
  64078. +
  64079. + /** Frame number while entering to ISR - needed for ISOCs **/
  64080. + uint32_t frame_num;
  64081. +
  64082. +};
  64083. +
  64084. +#ifdef DEBUG
  64085. +/*
  64086. + * This function is called when transfer is timed out.
  64087. + */
  64088. +extern void hc_xfer_timeout(void *ptr);
  64089. +#endif
  64090. +
  64091. +/*
  64092. + * This function is called when transfer is timed out on endpoint.
  64093. + */
  64094. +extern void ep_xfer_timeout(void *ptr);
  64095. +
  64096. +/*
  64097. + * The following functions are functions for works
  64098. + * using during handling some interrupts
  64099. + */
  64100. +extern void w_conn_id_status_change(void *p);
  64101. +
  64102. +extern void w_wakeup_detected(void *p);
  64103. +
  64104. +/** Saves global register values into system memory. */
  64105. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  64106. +/** Saves device register values into system memory. */
  64107. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  64108. +/** Saves host register values into system memory. */
  64109. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  64110. +/** Restore global register values. */
  64111. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  64112. +/** Restore host register values. */
  64113. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  64114. +/** Restore device register values. */
  64115. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  64116. + int rem_wakeup);
  64117. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  64118. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  64119. + int is_host);
  64120. +
  64121. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  64122. + int restore_mode, int reset);
  64123. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  64124. + int rem_wakeup, int reset);
  64125. +
  64126. +/*
  64127. + * The following functions support initialization of the CIL driver component
  64128. + * and the DWC_otg controller.
  64129. + */
  64130. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  64131. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  64132. +
  64133. +/** @name Device CIL Functions
  64134. + * The following functions support managing the DWC_otg controller in device
  64135. + * mode.
  64136. + */
  64137. +/**@{*/
  64138. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  64139. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  64140. + uint32_t * _dest);
  64141. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  64142. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64143. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64144. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64145. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  64146. + dwc_ep_t * _ep);
  64147. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  64148. + dwc_ep_t * _ep);
  64149. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  64150. + dwc_ep_t * _ep);
  64151. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  64152. + dwc_ep_t * _ep);
  64153. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  64154. + dwc_ep_t * _ep, int _dma);
  64155. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64156. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  64157. + dwc_ep_t * _ep);
  64158. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  64159. +
  64160. +#ifdef DWC_EN_ISOC
  64161. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  64162. + dwc_ep_t * ep);
  64163. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  64164. + dwc_ep_t * ep);
  64165. +#endif /* DWC_EN_ISOC */
  64166. +/**@}*/
  64167. +
  64168. +/** @name Host CIL Functions
  64169. + * The following functions support managing the DWC_otg controller in host
  64170. + * mode.
  64171. + */
  64172. +/**@{*/
  64173. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64174. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  64175. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  64176. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64177. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  64178. + dwc_hc_t * _hc);
  64179. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  64180. + dwc_hc_t * _hc);
  64181. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64182. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  64183. + dwc_hc_t * _hc);
  64184. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  64185. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  64186. +
  64187. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  64188. + dwc_hc_t * hc);
  64189. +
  64190. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  64191. +
  64192. +/* Macro used to clear one channel interrupt */
  64193. +#define clear_hc_int(_hc_regs_, _intr_) \
  64194. +do { \
  64195. + hcint_data_t hcint_clear = {.d32 = 0}; \
  64196. + hcint_clear.b._intr_ = 1; \
  64197. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  64198. +} while (0)
  64199. +
  64200. +/*
  64201. + * Macro used to disable one channel interrupt. Channel interrupts are
  64202. + * disabled when the channel is halted or released by the interrupt handler.
  64203. + * There is no need to handle further interrupts of that type until the
  64204. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  64205. + * because the channel structures are cleaned up when the channel is released.
  64206. + */
  64207. +#define disable_hc_int(_hc_regs_, _intr_) \
  64208. +do { \
  64209. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  64210. + hcintmsk.b._intr_ = 1; \
  64211. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  64212. +} while (0)
  64213. +
  64214. +/**
  64215. + * This function Reads HPRT0 in preparation to modify. It keeps the
  64216. + * WC bits 0 so that if they are read as 1, they won't clear when you
  64217. + * write it back
  64218. + */
  64219. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  64220. +{
  64221. + hprt0_data_t hprt0;
  64222. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  64223. + hprt0.b.prtena = 0;
  64224. + hprt0.b.prtconndet = 0;
  64225. + hprt0.b.prtenchng = 0;
  64226. + hprt0.b.prtovrcurrchng = 0;
  64227. + return hprt0.d32;
  64228. +}
  64229. +
  64230. +/**@}*/
  64231. +
  64232. +/** @name Common CIL Functions
  64233. + * The following functions support managing the DWC_otg controller in either
  64234. + * device or host mode.
  64235. + */
  64236. +/**@{*/
  64237. +
  64238. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  64239. + uint8_t * dest, uint16_t bytes);
  64240. +
  64241. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  64242. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  64243. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  64244. +
  64245. +/**
  64246. + * This function returns the Core Interrupt register.
  64247. + */
  64248. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  64249. +{
  64250. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  64251. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  64252. +}
  64253. +
  64254. +/**
  64255. + * This function returns the OTG Interrupt register.
  64256. + */
  64257. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  64258. +{
  64259. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  64260. +}
  64261. +
  64262. +/**
  64263. + * This function reads the Device All Endpoints Interrupt register and
  64264. + * returns the IN endpoint interrupt bits.
  64265. + */
  64266. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  64267. + core_if)
  64268. +{
  64269. +
  64270. + uint32_t v;
  64271. +
  64272. + if (core_if->multiproc_int_enable) {
  64273. + v = DWC_READ_REG32(&core_if->dev_if->
  64274. + dev_global_regs->deachint) &
  64275. + DWC_READ_REG32(&core_if->
  64276. + dev_if->dev_global_regs->deachintmsk);
  64277. + } else {
  64278. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  64279. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  64280. + }
  64281. + return (v & 0xffff);
  64282. +}
  64283. +
  64284. +/**
  64285. + * This function reads the Device All Endpoints Interrupt register and
  64286. + * returns the OUT endpoint interrupt bits.
  64287. + */
  64288. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  64289. + core_if)
  64290. +{
  64291. + uint32_t v;
  64292. +
  64293. + if (core_if->multiproc_int_enable) {
  64294. + v = DWC_READ_REG32(&core_if->dev_if->
  64295. + dev_global_regs->deachint) &
  64296. + DWC_READ_REG32(&core_if->
  64297. + dev_if->dev_global_regs->deachintmsk);
  64298. + } else {
  64299. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  64300. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  64301. + }
  64302. +
  64303. + return ((v & 0xffff0000) >> 16);
  64304. +}
  64305. +
  64306. +/**
  64307. + * This function returns the Device IN EP Interrupt register
  64308. + */
  64309. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  64310. + dwc_ep_t * ep)
  64311. +{
  64312. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  64313. + uint32_t v, msk, emp;
  64314. +
  64315. + if (core_if->multiproc_int_enable) {
  64316. + msk =
  64317. + DWC_READ_REG32(&dev_if->
  64318. + dev_global_regs->diepeachintmsk[ep->num]);
  64319. + emp =
  64320. + DWC_READ_REG32(&dev_if->
  64321. + dev_global_regs->dtknqr4_fifoemptymsk);
  64322. + msk |= ((emp >> ep->num) & 0x1) << 7;
  64323. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  64324. + } else {
  64325. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  64326. + emp =
  64327. + DWC_READ_REG32(&dev_if->
  64328. + dev_global_regs->dtknqr4_fifoemptymsk);
  64329. + msk |= ((emp >> ep->num) & 0x1) << 7;
  64330. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  64331. + }
  64332. +
  64333. + return v;
  64334. +}
  64335. +
  64336. +/**
  64337. + * This function returns the Device OUT EP Interrupt register
  64338. + */
  64339. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  64340. + _core_if, dwc_ep_t * _ep)
  64341. +{
  64342. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  64343. + uint32_t v;
  64344. + doepmsk_data_t msk = {.d32 = 0 };
  64345. +
  64346. + if (_core_if->multiproc_int_enable) {
  64347. + msk.d32 =
  64348. + DWC_READ_REG32(&dev_if->
  64349. + dev_global_regs->doepeachintmsk[_ep->num]);
  64350. + if (_core_if->pti_enh_enable) {
  64351. + msk.b.pktdrpsts = 1;
  64352. + }
  64353. + v = DWC_READ_REG32(&dev_if->
  64354. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  64355. + } else {
  64356. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  64357. + if (_core_if->pti_enh_enable) {
  64358. + msk.b.pktdrpsts = 1;
  64359. + }
  64360. + v = DWC_READ_REG32(&dev_if->
  64361. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  64362. + }
  64363. + return v;
  64364. +}
  64365. +
  64366. +/**
  64367. + * This function returns the Host All Channel Interrupt register
  64368. + */
  64369. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  64370. + _core_if)
  64371. +{
  64372. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  64373. +}
  64374. +
  64375. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  64376. + _core_if, dwc_hc_t * _hc)
  64377. +{
  64378. + return (DWC_READ_REG32
  64379. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  64380. +}
  64381. +
  64382. +/**
  64383. + * This function returns the mode of the operation, host or device.
  64384. + *
  64385. + * @return 0 - Device Mode, 1 - Host Mode
  64386. + */
  64387. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  64388. +{
  64389. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  64390. +}
  64391. +
  64392. +/**@}*/
  64393. +
  64394. +/**
  64395. + * DWC_otg CIL callback structure. This structure allows the HCD and
  64396. + * PCD to register functions used for starting and stopping the PCD
  64397. + * and HCD for role change on for a DRD.
  64398. + */
  64399. +typedef struct dwc_otg_cil_callbacks {
  64400. + /** Start function for role change */
  64401. + int (*start) (void *_p);
  64402. + /** Stop Function for role change */
  64403. + int (*stop) (void *_p);
  64404. + /** Disconnect Function for role change */
  64405. + int (*disconnect) (void *_p);
  64406. + /** Resume/Remote wakeup Function */
  64407. + int (*resume_wakeup) (void *_p);
  64408. + /** Suspend function */
  64409. + int (*suspend) (void *_p);
  64410. + /** Session Start (SRP) */
  64411. + int (*session_start) (void *_p);
  64412. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64413. + /** Sleep (switch to L0 state) */
  64414. + int (*sleep) (void *_p);
  64415. +#endif
  64416. + /** Pointer passed to start() and stop() */
  64417. + void *p;
  64418. +} dwc_otg_cil_callbacks_t;
  64419. +
  64420. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  64421. + dwc_otg_cil_callbacks_t * _cb,
  64422. + void *_p);
  64423. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  64424. + dwc_otg_cil_callbacks_t * _cb,
  64425. + void *_p);
  64426. +
  64427. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  64428. +
  64429. +//////////////////////////////////////////////////////////////////////
  64430. +/** Start the HCD. Helper function for using the HCD callbacks.
  64431. + *
  64432. + * @param core_if Programming view of DWC_otg controller.
  64433. + */
  64434. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  64435. +{
  64436. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  64437. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  64438. + }
  64439. +}
  64440. +
  64441. +/** Stop the HCD. Helper function for using the HCD callbacks.
  64442. + *
  64443. + * @param core_if Programming view of DWC_otg controller.
  64444. + */
  64445. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  64446. +{
  64447. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  64448. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  64449. + }
  64450. +}
  64451. +
  64452. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  64453. + *
  64454. + * @param core_if Programming view of DWC_otg controller.
  64455. + */
  64456. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  64457. +{
  64458. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  64459. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  64460. + }
  64461. +}
  64462. +
  64463. +/** Inform the HCD the a New Session has begun. Helper function for
  64464. + * using the HCD callbacks.
  64465. + *
  64466. + * @param core_if Programming view of DWC_otg controller.
  64467. + */
  64468. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  64469. +{
  64470. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  64471. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  64472. + }
  64473. +}
  64474. +
  64475. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64476. +/**
  64477. + * Inform the HCD about LPM sleep.
  64478. + * Helper function for using the HCD callbacks.
  64479. + *
  64480. + * @param core_if Programming view of DWC_otg controller.
  64481. + */
  64482. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  64483. +{
  64484. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  64485. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  64486. + }
  64487. +}
  64488. +#endif
  64489. +
  64490. +/** Resume the HCD. Helper function for using the HCD callbacks.
  64491. + *
  64492. + * @param core_if Programming view of DWC_otg controller.
  64493. + */
  64494. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  64495. +{
  64496. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  64497. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  64498. + }
  64499. +}
  64500. +
  64501. +/** Start the PCD. Helper function for using the PCD callbacks.
  64502. + *
  64503. + * @param core_if Programming view of DWC_otg controller.
  64504. + */
  64505. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  64506. +{
  64507. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  64508. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  64509. + }
  64510. +}
  64511. +
  64512. +/** Stop the PCD. Helper function for using the PCD callbacks.
  64513. + *
  64514. + * @param core_if Programming view of DWC_otg controller.
  64515. + */
  64516. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  64517. +{
  64518. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  64519. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  64520. + }
  64521. +}
  64522. +
  64523. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  64524. + *
  64525. + * @param core_if Programming view of DWC_otg controller.
  64526. + */
  64527. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  64528. +{
  64529. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  64530. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  64531. + }
  64532. +}
  64533. +
  64534. +/** Resume the PCD. Helper function for using the PCD callbacks.
  64535. + *
  64536. + * @param core_if Programming view of DWC_otg controller.
  64537. + */
  64538. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  64539. +{
  64540. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64541. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64542. + }
  64543. +}
  64544. +
  64545. +//////////////////////////////////////////////////////////////////////
  64546. +
  64547. +#endif
  64548. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  64549. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  64550. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-03-13 12:46:39.516097989 +0100
  64551. @@ -0,0 +1,1588 @@
  64552. +/* ==========================================================================
  64553. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  64554. + * $Revision: #32 $
  64555. + * $Date: 2012/08/10 $
  64556. + * $Change: 2047372 $
  64557. + *
  64558. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  64559. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  64560. + * otherwise expressly agreed to in writing between Synopsys and you.
  64561. + *
  64562. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  64563. + * any End User Software License Agreement or Agreement for Licensed Product
  64564. + * with Synopsys or any supplement thereto. You are permitted to use and
  64565. + * redistribute this Software in source and binary forms, with or without
  64566. + * modification, provided that redistributions of source code must retain this
  64567. + * notice. You may not view, use, disclose, copy or distribute this file or
  64568. + * any information contained herein except pursuant to this license grant from
  64569. + * Synopsys. If you do not agree with this notice, including the disclaimer
  64570. + * below, then you are not authorized to use the Software.
  64571. + *
  64572. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  64573. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  64574. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  64575. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  64576. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  64577. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  64578. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64579. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64580. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64581. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  64582. + * DAMAGE.
  64583. + * ========================================================================== */
  64584. +
  64585. +/** @file
  64586. + *
  64587. + * The Core Interface Layer provides basic services for accessing and
  64588. + * managing the DWC_otg hardware. These services are used by both the
  64589. + * Host Controller Driver and the Peripheral Controller Driver.
  64590. + *
  64591. + * This file contains the Common Interrupt handlers.
  64592. + */
  64593. +#include "dwc_os.h"
  64594. +#include "dwc_otg_regs.h"
  64595. +#include "dwc_otg_cil.h"
  64596. +#include "dwc_otg_driver.h"
  64597. +#include "dwc_otg_pcd.h"
  64598. +#include "dwc_otg_hcd.h"
  64599. +#include "dwc_otg_mphi_fix.h"
  64600. +
  64601. +#ifdef DEBUG
  64602. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  64603. +{
  64604. + return (core_if->op_state == A_HOST ? "a_host" :
  64605. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  64606. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  64607. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  64608. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  64609. +}
  64610. +#endif
  64611. +
  64612. +/** This function will log a debug message
  64613. + *
  64614. + * @param core_if Programming view of DWC_otg controller.
  64615. + */
  64616. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  64617. +{
  64618. + gintsts_data_t gintsts;
  64619. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  64620. + dwc_otg_mode(core_if) ? "Host" : "Device");
  64621. +
  64622. + /* Clear interrupt */
  64623. + gintsts.d32 = 0;
  64624. + gintsts.b.modemismatch = 1;
  64625. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64626. + return 1;
  64627. +}
  64628. +
  64629. +/**
  64630. + * This function handles the OTG Interrupts. It reads the OTG
  64631. + * Interrupt Register (GOTGINT) to determine what interrupt has
  64632. + * occurred.
  64633. + *
  64634. + * @param core_if Programming view of DWC_otg controller.
  64635. + */
  64636. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  64637. +{
  64638. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  64639. + gotgint_data_t gotgint;
  64640. + gotgctl_data_t gotgctl;
  64641. + gintmsk_data_t gintmsk;
  64642. + gpwrdn_data_t gpwrdn;
  64643. +
  64644. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  64645. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64646. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  64647. + op_state_str(core_if));
  64648. +
  64649. + if (gotgint.b.sesenddet) {
  64650. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64651. + "Session End Detected++ (%s)\n",
  64652. + op_state_str(core_if));
  64653. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64654. +
  64655. + if (core_if->op_state == B_HOST) {
  64656. + cil_pcd_start(core_if);
  64657. + core_if->op_state = B_PERIPHERAL;
  64658. + } else {
  64659. + /* If not B_HOST and Device HNP still set. HNP
  64660. + * Did not succeed!*/
  64661. + if (gotgctl.b.devhnpen) {
  64662. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  64663. + __DWC_ERROR("Device Not Connected/Responding!\n");
  64664. + }
  64665. +
  64666. + /* If Session End Detected the B-Cable has
  64667. + * been disconnected. */
  64668. + /* Reset PCD and Gadget driver to a
  64669. + * clean state. */
  64670. + core_if->lx_state = DWC_OTG_L0;
  64671. + DWC_SPINUNLOCK(core_if->lock);
  64672. + cil_pcd_stop(core_if);
  64673. + DWC_SPINLOCK(core_if->lock);
  64674. +
  64675. + if (core_if->adp_enable) {
  64676. + if (core_if->power_down == 2) {
  64677. + gpwrdn.d32 = 0;
  64678. + gpwrdn.b.pwrdnswtch = 1;
  64679. + DWC_MODIFY_REG32(&core_if->
  64680. + core_global_regs->
  64681. + gpwrdn, gpwrdn.d32, 0);
  64682. + }
  64683. +
  64684. + gpwrdn.d32 = 0;
  64685. + gpwrdn.b.pmuintsel = 1;
  64686. + gpwrdn.b.pmuactv = 1;
  64687. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64688. + gpwrdn, 0, gpwrdn.d32);
  64689. +
  64690. + dwc_otg_adp_sense_start(core_if);
  64691. + }
  64692. + }
  64693. +
  64694. + gotgctl.d32 = 0;
  64695. + gotgctl.b.devhnpen = 1;
  64696. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64697. + }
  64698. + if (gotgint.b.sesreqsucstschng) {
  64699. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64700. + "Session Reqeust Success Status Change++\n");
  64701. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64702. + if (gotgctl.b.sesreqscs) {
  64703. +
  64704. + if ((core_if->core_params->phy_type ==
  64705. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  64706. + core_if->srp_success = 1;
  64707. + } else {
  64708. + DWC_SPINUNLOCK(core_if->lock);
  64709. + cil_pcd_resume(core_if);
  64710. + DWC_SPINLOCK(core_if->lock);
  64711. + /* Clear Session Request */
  64712. + gotgctl.d32 = 0;
  64713. + gotgctl.b.sesreq = 1;
  64714. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  64715. + gotgctl.d32, 0);
  64716. + }
  64717. + }
  64718. + }
  64719. + if (gotgint.b.hstnegsucstschng) {
  64720. + /* Print statements during the HNP interrupt handling
  64721. + * can cause it to fail.*/
  64722. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64723. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  64724. + * this does not help*/
  64725. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  64726. + dwc_udelay(100);
  64727. + if (gotgctl.b.hstnegscs) {
  64728. + if (dwc_otg_is_host_mode(core_if)) {
  64729. + core_if->op_state = B_HOST;
  64730. + /*
  64731. + * Need to disable SOF interrupt immediately.
  64732. + * When switching from device to host, the PCD
  64733. + * interrupt handler won't handle the
  64734. + * interrupt if host mode is already set. The
  64735. + * HCD interrupt handler won't get called if
  64736. + * the HCD state is HALT. This means that the
  64737. + * interrupt does not get handled and Linux
  64738. + * complains loudly.
  64739. + */
  64740. + gintmsk.d32 = 0;
  64741. + gintmsk.b.sofintr = 1;
  64742. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  64743. + gintmsk.d32, 0);
  64744. + /* Call callback function with spin lock released */
  64745. + DWC_SPINUNLOCK(core_if->lock);
  64746. + cil_pcd_stop(core_if);
  64747. + /*
  64748. + * Initialize the Core for Host mode.
  64749. + */
  64750. + cil_hcd_start(core_if);
  64751. + DWC_SPINLOCK(core_if->lock);
  64752. + core_if->op_state = B_HOST;
  64753. + }
  64754. + } else {
  64755. + gotgctl.d32 = 0;
  64756. + gotgctl.b.hnpreq = 1;
  64757. + gotgctl.b.devhnpen = 1;
  64758. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64759. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  64760. + __DWC_ERROR("Device Not Connected/Responding\n");
  64761. + }
  64762. + }
  64763. + if (gotgint.b.hstnegdet) {
  64764. + /* The disconnect interrupt is set at the same time as
  64765. + * Host Negotiation Detected. During the mode
  64766. + * switch all interrupts are cleared so the disconnect
  64767. + * interrupt handler will not get executed.
  64768. + */
  64769. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64770. + "Host Negotiation Detected++ (%s)\n",
  64771. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64772. + "Device"));
  64773. + if (dwc_otg_is_device_mode(core_if)) {
  64774. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  64775. + core_if->op_state);
  64776. + DWC_SPINUNLOCK(core_if->lock);
  64777. + cil_hcd_disconnect(core_if);
  64778. + cil_pcd_start(core_if);
  64779. + DWC_SPINLOCK(core_if->lock);
  64780. + core_if->op_state = A_PERIPHERAL;
  64781. + } else {
  64782. + /*
  64783. + * Need to disable SOF interrupt immediately. When
  64784. + * switching from device to host, the PCD interrupt
  64785. + * handler won't handle the interrupt if host mode is
  64786. + * already set. The HCD interrupt handler won't get
  64787. + * called if the HCD state is HALT. This means that
  64788. + * the interrupt does not get handled and Linux
  64789. + * complains loudly.
  64790. + */
  64791. + gintmsk.d32 = 0;
  64792. + gintmsk.b.sofintr = 1;
  64793. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  64794. + DWC_SPINUNLOCK(core_if->lock);
  64795. + cil_pcd_stop(core_if);
  64796. + cil_hcd_start(core_if);
  64797. + DWC_SPINLOCK(core_if->lock);
  64798. + core_if->op_state = A_HOST;
  64799. + }
  64800. + }
  64801. + if (gotgint.b.adevtoutchng) {
  64802. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64803. + "A-Device Timeout Change++\n");
  64804. + }
  64805. + if (gotgint.b.debdone) {
  64806. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  64807. + }
  64808. +
  64809. + /* Clear GOTGINT */
  64810. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  64811. +
  64812. + return 1;
  64813. +}
  64814. +
  64815. +void w_conn_id_status_change(void *p)
  64816. +{
  64817. + dwc_otg_core_if_t *core_if = p;
  64818. + uint32_t count = 0;
  64819. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64820. +
  64821. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64822. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  64823. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  64824. +
  64825. + /* B-Device connector (Device Mode) */
  64826. + if (gotgctl.b.conidsts) {
  64827. + /* Wait for switch to device mode. */
  64828. + while (!dwc_otg_is_device_mode(core_if)) {
  64829. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  64830. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64831. + "Peripheral"));
  64832. + dwc_mdelay(100);
  64833. + if (++count > 10000)
  64834. + break;
  64835. + }
  64836. + DWC_ASSERT(++count < 10000,
  64837. + "Connection id status change timed out");
  64838. + core_if->op_state = B_PERIPHERAL;
  64839. + dwc_otg_core_init(core_if);
  64840. + dwc_otg_enable_global_interrupts(core_if);
  64841. + cil_pcd_start(core_if);
  64842. + } else {
  64843. + /* A-Device connector (Host Mode) */
  64844. + while (!dwc_otg_is_host_mode(core_if)) {
  64845. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  64846. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64847. + "Peripheral"));
  64848. + dwc_mdelay(100);
  64849. + if (++count > 10000)
  64850. + break;
  64851. + }
  64852. + DWC_ASSERT(++count < 10000,
  64853. + "Connection id status change timed out");
  64854. + core_if->op_state = A_HOST;
  64855. + /*
  64856. + * Initialize the Core for Host mode.
  64857. + */
  64858. + dwc_otg_core_init(core_if);
  64859. + dwc_otg_enable_global_interrupts(core_if);
  64860. + cil_hcd_start(core_if);
  64861. + }
  64862. +}
  64863. +
  64864. +/**
  64865. + * This function handles the Connector ID Status Change Interrupt. It
  64866. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  64867. + * is a Device to Host Mode transition or a Host Mode to Device
  64868. + * Transition.
  64869. + *
  64870. + * This only occurs when the cable is connected/removed from the PHY
  64871. + * connector.
  64872. + *
  64873. + * @param core_if Programming view of DWC_otg controller.
  64874. + */
  64875. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  64876. +{
  64877. +
  64878. + /*
  64879. + * Need to disable SOF interrupt immediately. If switching from device
  64880. + * to host, the PCD interrupt handler won't handle the interrupt if
  64881. + * host mode is already set. The HCD interrupt handler won't get
  64882. + * called if the HCD state is HALT. This means that the interrupt does
  64883. + * not get handled and Linux complains loudly.
  64884. + */
  64885. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64886. + gintsts_data_t gintsts = {.d32 = 0 };
  64887. +
  64888. + gintmsk.b.sofintr = 1;
  64889. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  64890. +
  64891. + DWC_DEBUGPL(DBG_CIL,
  64892. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  64893. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  64894. +
  64895. + DWC_SPINUNLOCK(core_if->lock);
  64896. +
  64897. + /*
  64898. + * Need to schedule a work, as there are possible DELAY function calls
  64899. + * Release lock before scheduling workq as it holds spinlock during scheduling
  64900. + */
  64901. +
  64902. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  64903. + core_if, "connection id status change");
  64904. + DWC_SPINLOCK(core_if->lock);
  64905. +
  64906. + /* Set flag and clear interrupt */
  64907. + gintsts.b.conidstschng = 1;
  64908. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64909. +
  64910. + return 1;
  64911. +}
  64912. +
  64913. +/**
  64914. + * This interrupt indicates that a device is initiating the Session
  64915. + * Request Protocol to request the host to turn on bus power so a new
  64916. + * session can begin. The handler responds by turning on bus power. If
  64917. + * the DWC_otg controller is in low power mode, the handler brings the
  64918. + * controller out of low power mode before turning on bus power.
  64919. + *
  64920. + * @param core_if Programming view of DWC_otg controller.
  64921. + */
  64922. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  64923. +{
  64924. + gintsts_data_t gintsts;
  64925. +
  64926. +#ifndef DWC_HOST_ONLY
  64927. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  64928. +
  64929. + if (dwc_otg_is_device_mode(core_if)) {
  64930. + DWC_PRINTF("SRP: Device mode\n");
  64931. + } else {
  64932. + hprt0_data_t hprt0;
  64933. + DWC_PRINTF("SRP: Host mode\n");
  64934. +
  64935. + /* Turn on the port power bit. */
  64936. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64937. + hprt0.b.prtpwr = 1;
  64938. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64939. +
  64940. + /* Start the Connection timer. So a message can be displayed
  64941. + * if connect does not occur within 10 seconds. */
  64942. + cil_hcd_session_start(core_if);
  64943. + }
  64944. +#endif
  64945. +
  64946. + /* Clear interrupt */
  64947. + gintsts.d32 = 0;
  64948. + gintsts.b.sessreqintr = 1;
  64949. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64950. +
  64951. + return 1;
  64952. +}
  64953. +
  64954. +void w_wakeup_detected(void *p)
  64955. +{
  64956. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  64957. + /*
  64958. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  64959. + * so that OPT tests pass with all PHYs).
  64960. + */
  64961. + hprt0_data_t hprt0 = {.d32 = 0 };
  64962. +#if 0
  64963. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64964. + /* Restart the Phy Clock */
  64965. + pcgcctl.b.stoppclk = 1;
  64966. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64967. + dwc_udelay(10);
  64968. +#endif //0
  64969. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64970. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  64971. +// dwc_mdelay(70);
  64972. + hprt0.b.prtres = 0; /* Resume */
  64973. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64974. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  64975. + DWC_READ_REG32(core_if->host_if->hprt0));
  64976. +
  64977. + cil_hcd_resume(core_if);
  64978. +
  64979. + /** Change to L0 state*/
  64980. + core_if->lx_state = DWC_OTG_L0;
  64981. +}
  64982. +
  64983. +/**
  64984. + * This interrupt indicates that the DWC_otg controller has detected a
  64985. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  64986. + * low power mode, the handler must brings the controller out of low
  64987. + * power mode. The controller automatically begins resume
  64988. + * signaling. The handler schedules a time to stop resume signaling.
  64989. + */
  64990. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64991. +{
  64992. + gintsts_data_t gintsts;
  64993. +
  64994. + DWC_DEBUGPL(DBG_ANY,
  64995. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  64996. +
  64997. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  64998. +
  64999. + if (dwc_otg_is_device_mode(core_if)) {
  65000. + dctl_data_t dctl = {.d32 = 0 };
  65001. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  65002. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  65003. + dsts));
  65004. + if (core_if->lx_state == DWC_OTG_L2) {
  65005. +#ifdef PARTIAL_POWER_DOWN
  65006. + if (core_if->hwcfg4.b.power_optimiz) {
  65007. + pcgcctl_data_t power = {.d32 = 0 };
  65008. +
  65009. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65010. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  65011. + power.d32);
  65012. +
  65013. + power.b.stoppclk = 0;
  65014. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65015. +
  65016. + power.b.pwrclmp = 0;
  65017. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65018. +
  65019. + power.b.rstpdwnmodule = 0;
  65020. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65021. + }
  65022. +#endif
  65023. + /* Clear the Remote Wakeup Signaling */
  65024. + dctl.b.rmtwkupsig = 1;
  65025. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  65026. + dctl, dctl.d32, 0);
  65027. +
  65028. + DWC_SPINUNLOCK(core_if->lock);
  65029. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65030. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65031. + }
  65032. + DWC_SPINLOCK(core_if->lock);
  65033. + } else {
  65034. + glpmcfg_data_t lpmcfg;
  65035. + lpmcfg.d32 =
  65036. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65037. + lpmcfg.b.hird_thres &= (~(1 << 4));
  65038. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65039. + lpmcfg.d32);
  65040. + }
  65041. + /** Change to L0 state*/
  65042. + core_if->lx_state = DWC_OTG_L0;
  65043. + } else {
  65044. + if (core_if->lx_state != DWC_OTG_L1) {
  65045. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65046. +
  65047. + /* Restart the Phy Clock */
  65048. + pcgcctl.b.stoppclk = 1;
  65049. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65050. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  65051. + } else {
  65052. + /** Change to L0 state*/
  65053. + core_if->lx_state = DWC_OTG_L0;
  65054. + }
  65055. + }
  65056. +
  65057. + /* Clear interrupt */
  65058. + gintsts.d32 = 0;
  65059. + gintsts.b.wkupintr = 1;
  65060. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65061. +
  65062. + return 1;
  65063. +}
  65064. +
  65065. +/**
  65066. + * This interrupt indicates that the Wakeup Logic has detected a
  65067. + * Device disconnect.
  65068. + */
  65069. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  65070. +{
  65071. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65072. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  65073. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65074. +
  65075. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65076. +
  65077. + if (!core_if->hibernation_suspend) {
  65078. + DWC_PRINTF("Already exited from Hibernation\n");
  65079. + return 1;
  65080. + }
  65081. +
  65082. + /* Switch on the voltage to the core */
  65083. + gpwrdn.b.pwrdnswtch = 1;
  65084. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65085. + dwc_udelay(10);
  65086. +
  65087. + /* Reset the core */
  65088. + gpwrdn.d32 = 0;
  65089. + gpwrdn.b.pwrdnrstn = 1;
  65090. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65091. + dwc_udelay(10);
  65092. +
  65093. + /* Disable power clamps*/
  65094. + gpwrdn.d32 = 0;
  65095. + gpwrdn.b.pwrdnclmp = 1;
  65096. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65097. +
  65098. + /* Remove reset the core signal */
  65099. + gpwrdn.d32 = 0;
  65100. + gpwrdn.b.pwrdnrstn = 1;
  65101. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65102. + dwc_udelay(10);
  65103. +
  65104. + /* Disable PMU interrupt */
  65105. + gpwrdn.d32 = 0;
  65106. + gpwrdn.b.pmuintsel = 1;
  65107. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65108. +
  65109. + core_if->hibernation_suspend = 0;
  65110. +
  65111. + /* Disable PMU */
  65112. + gpwrdn.d32 = 0;
  65113. + gpwrdn.b.pmuactv = 1;
  65114. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65115. + dwc_udelay(10);
  65116. +
  65117. + if (gpwrdn_temp.b.idsts) {
  65118. + core_if->op_state = B_PERIPHERAL;
  65119. + dwc_otg_core_init(core_if);
  65120. + dwc_otg_enable_global_interrupts(core_if);
  65121. + cil_pcd_start(core_if);
  65122. + } else {
  65123. + core_if->op_state = A_HOST;
  65124. + dwc_otg_core_init(core_if);
  65125. + dwc_otg_enable_global_interrupts(core_if);
  65126. + cil_hcd_start(core_if);
  65127. + }
  65128. +
  65129. + return 1;
  65130. +}
  65131. +
  65132. +/**
  65133. + * This interrupt indicates that the Wakeup Logic has detected a
  65134. + * remote wakeup sequence.
  65135. + */
  65136. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65137. +{
  65138. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65139. + DWC_DEBUGPL(DBG_ANY,
  65140. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  65141. +
  65142. + if (!core_if->hibernation_suspend) {
  65143. + DWC_PRINTF("Already exited from Hibernation\n");
  65144. + return 1;
  65145. + }
  65146. +
  65147. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65148. + if (gpwrdn.b.idsts) { // Device Mode
  65149. + if ((core_if->power_down == 2)
  65150. + && (core_if->hibernation_suspend == 1)) {
  65151. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  65152. + }
  65153. + } else {
  65154. + if ((core_if->power_down == 2)
  65155. + && (core_if->hibernation_suspend == 1)) {
  65156. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  65157. + }
  65158. + }
  65159. + return 1;
  65160. +}
  65161. +
  65162. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  65163. +{
  65164. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65165. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65166. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65167. +
  65168. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65169. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65170. + if (core_if->power_down == 2) {
  65171. + if (!core_if->hibernation_suspend) {
  65172. + DWC_PRINTF("Already exited from Hibernation\n");
  65173. + return 1;
  65174. + }
  65175. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  65176. + /* Switch on the voltage to the core */
  65177. + gpwrdn.b.pwrdnswtch = 1;
  65178. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65179. + dwc_udelay(10);
  65180. +
  65181. + /* Reset the core */
  65182. + gpwrdn.d32 = 0;
  65183. + gpwrdn.b.pwrdnrstn = 1;
  65184. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65185. + dwc_udelay(10);
  65186. +
  65187. + /* Disable power clamps */
  65188. + gpwrdn.d32 = 0;
  65189. + gpwrdn.b.pwrdnclmp = 1;
  65190. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65191. +
  65192. + /* Remove reset the core signal */
  65193. + gpwrdn.d32 = 0;
  65194. + gpwrdn.b.pwrdnrstn = 1;
  65195. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65196. + dwc_udelay(10);
  65197. +
  65198. + /* Disable PMU interrupt */
  65199. + gpwrdn.d32 = 0;
  65200. + gpwrdn.b.pmuintsel = 1;
  65201. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65202. +
  65203. + /*Indicates that we are exiting from hibernation */
  65204. + core_if->hibernation_suspend = 0;
  65205. +
  65206. + /* Disable PMU */
  65207. + gpwrdn.d32 = 0;
  65208. + gpwrdn.b.pmuactv = 1;
  65209. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65210. + dwc_udelay(10);
  65211. +
  65212. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  65213. + if (gpwrdn.b.dis_vbus == 1) {
  65214. + gpwrdn.d32 = 0;
  65215. + gpwrdn.b.dis_vbus = 1;
  65216. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65217. + }
  65218. +
  65219. + if (gpwrdn_temp.b.idsts) {
  65220. + core_if->op_state = B_PERIPHERAL;
  65221. + dwc_otg_core_init(core_if);
  65222. + dwc_otg_enable_global_interrupts(core_if);
  65223. + cil_pcd_start(core_if);
  65224. + } else {
  65225. + core_if->op_state = A_HOST;
  65226. + dwc_otg_core_init(core_if);
  65227. + dwc_otg_enable_global_interrupts(core_if);
  65228. + cil_hcd_start(core_if);
  65229. + }
  65230. + }
  65231. +
  65232. + if (core_if->adp_enable) {
  65233. + uint8_t is_host = 0;
  65234. + DWC_SPINUNLOCK(core_if->lock);
  65235. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  65236. +#ifndef DWC_HOST_ONLY
  65237. + if (gpwrdn_temp.b.idsts)
  65238. + core_if->lock = otg_dev->pcd->lock;
  65239. +#endif
  65240. +#ifndef DWC_DEVICE_ONLY
  65241. + if (!gpwrdn_temp.b.idsts) {
  65242. + core_if->lock = otg_dev->hcd->lock;
  65243. + is_host = 1;
  65244. + }
  65245. +#endif
  65246. + DWC_PRINTF("RESTART ADP\n");
  65247. + if (core_if->adp.probe_enabled)
  65248. + dwc_otg_adp_probe_stop(core_if);
  65249. + if (core_if->adp.sense_enabled)
  65250. + dwc_otg_adp_sense_stop(core_if);
  65251. + if (core_if->adp.sense_timer_started)
  65252. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  65253. + if (core_if->adp.vbuson_timer_started)
  65254. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  65255. + core_if->adp.probe_timer_values[0] = -1;
  65256. + core_if->adp.probe_timer_values[1] = -1;
  65257. + core_if->adp.sense_timer_started = 0;
  65258. + core_if->adp.vbuson_timer_started = 0;
  65259. + core_if->adp.probe_counter = 0;
  65260. + core_if->adp.gpwrdn = 0;
  65261. +
  65262. + /* Disable PMU and restart ADP */
  65263. + gpwrdn_temp.d32 = 0;
  65264. + gpwrdn_temp.b.pmuactv = 1;
  65265. + gpwrdn_temp.b.pmuintsel = 1;
  65266. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65267. + DWC_PRINTF("Check point 1\n");
  65268. + dwc_mdelay(110);
  65269. + dwc_otg_adp_start(core_if, is_host);
  65270. + DWC_SPINLOCK(core_if->lock);
  65271. + }
  65272. +
  65273. +
  65274. + return 1;
  65275. +}
  65276. +
  65277. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  65278. +{
  65279. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65280. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  65281. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65282. +
  65283. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65284. + if (core_if->power_down == 2) {
  65285. + if (!core_if->hibernation_suspend) {
  65286. + DWC_PRINTF("Already exited from Hibernation\n");
  65287. + return 1;
  65288. + }
  65289. +
  65290. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  65291. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  65292. + gpwrdn.b.bsessvld == 0) {
  65293. + /* Save gpwrdn register for further usage if stschng interrupt */
  65294. + core_if->gr_backup->gpwrdn_local =
  65295. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65296. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  65297. + return 1;
  65298. + }
  65299. +
  65300. + /* Switch on the voltage to the core */
  65301. + gpwrdn.d32 = 0;
  65302. + gpwrdn.b.pwrdnswtch = 1;
  65303. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65304. + dwc_udelay(10);
  65305. +
  65306. + /* Reset the core */
  65307. + gpwrdn.d32 = 0;
  65308. + gpwrdn.b.pwrdnrstn = 1;
  65309. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65310. + dwc_udelay(10);
  65311. +
  65312. + /* Disable power clamps */
  65313. + gpwrdn.d32 = 0;
  65314. + gpwrdn.b.pwrdnclmp = 1;
  65315. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65316. +
  65317. + /* Remove reset the core signal */
  65318. + gpwrdn.d32 = 0;
  65319. + gpwrdn.b.pwrdnrstn = 1;
  65320. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65321. + dwc_udelay(10);
  65322. +
  65323. + /* Disable PMU interrupt */
  65324. + gpwrdn.d32 = 0;
  65325. + gpwrdn.b.pmuintsel = 1;
  65326. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65327. + dwc_udelay(10);
  65328. +
  65329. + /*Indicates that we are exiting from hibernation */
  65330. + core_if->hibernation_suspend = 0;
  65331. +
  65332. + /* Disable PMU */
  65333. + gpwrdn.d32 = 0;
  65334. + gpwrdn.b.pmuactv = 1;
  65335. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65336. + dwc_udelay(10);
  65337. +
  65338. + core_if->op_state = B_PERIPHERAL;
  65339. + dwc_otg_core_init(core_if);
  65340. + dwc_otg_enable_global_interrupts(core_if);
  65341. + cil_pcd_start(core_if);
  65342. +
  65343. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  65344. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  65345. + /*
  65346. + * Initiate SRP after initial ADP probe.
  65347. + */
  65348. + dwc_otg_initiate_srp(core_if);
  65349. + }
  65350. + }
  65351. +
  65352. + return 1;
  65353. +}
  65354. +/**
  65355. + * This interrupt indicates that the Wakeup Logic has detected a
  65356. + * status change either on IDDIG or BSessVld.
  65357. + */
  65358. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  65359. +{
  65360. + int retval;
  65361. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65362. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65363. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65364. +
  65365. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65366. +
  65367. + if (core_if->power_down == 2) {
  65368. + if (core_if->hibernation_suspend <= 0) {
  65369. + DWC_PRINTF("Already exited from Hibernation\n");
  65370. + return 1;
  65371. + } else
  65372. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  65373. +
  65374. + } else {
  65375. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  65376. + }
  65377. +
  65378. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65379. +
  65380. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  65381. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  65382. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  65383. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  65384. + }
  65385. +
  65386. + return retval;
  65387. +}
  65388. +
  65389. +/**
  65390. + * This interrupt indicates that the Wakeup Logic has detected a
  65391. + * SRP.
  65392. + */
  65393. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  65394. +{
  65395. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65396. +
  65397. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65398. +
  65399. + if (!core_if->hibernation_suspend) {
  65400. + DWC_PRINTF("Already exited from Hibernation\n");
  65401. + return 1;
  65402. + }
  65403. +#ifdef DWC_DEV_SRPCAP
  65404. + if (core_if->pwron_timer_started) {
  65405. + core_if->pwron_timer_started = 0;
  65406. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  65407. + }
  65408. +#endif
  65409. +
  65410. + /* Switch on the voltage to the core */
  65411. + gpwrdn.b.pwrdnswtch = 1;
  65412. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65413. + dwc_udelay(10);
  65414. +
  65415. + /* Reset the core */
  65416. + gpwrdn.d32 = 0;
  65417. + gpwrdn.b.pwrdnrstn = 1;
  65418. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65419. + dwc_udelay(10);
  65420. +
  65421. + /* Disable power clamps */
  65422. + gpwrdn.d32 = 0;
  65423. + gpwrdn.b.pwrdnclmp = 1;
  65424. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65425. +
  65426. + /* Remove reset the core signal */
  65427. + gpwrdn.d32 = 0;
  65428. + gpwrdn.b.pwrdnrstn = 1;
  65429. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65430. + dwc_udelay(10);
  65431. +
  65432. + /* Disable PMU interrupt */
  65433. + gpwrdn.d32 = 0;
  65434. + gpwrdn.b.pmuintsel = 1;
  65435. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65436. +
  65437. + /* Indicates that we are exiting from hibernation */
  65438. + core_if->hibernation_suspend = 0;
  65439. +
  65440. + /* Disable PMU */
  65441. + gpwrdn.d32 = 0;
  65442. + gpwrdn.b.pmuactv = 1;
  65443. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65444. + dwc_udelay(10);
  65445. +
  65446. + /* Programm Disable VBUS to 0 */
  65447. + gpwrdn.d32 = 0;
  65448. + gpwrdn.b.dis_vbus = 1;
  65449. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65450. +
  65451. + /*Initialize the core as Host */
  65452. + core_if->op_state = A_HOST;
  65453. + dwc_otg_core_init(core_if);
  65454. + dwc_otg_enable_global_interrupts(core_if);
  65455. + cil_hcd_start(core_if);
  65456. +
  65457. + return 1;
  65458. +}
  65459. +
  65460. +/** This interrupt indicates that restore command after Hibernation
  65461. + * was completed by the core. */
  65462. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  65463. +{
  65464. + pcgcctl_data_t pcgcctl;
  65465. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  65466. +
  65467. + //TODO De-assert restore signal. 8.a
  65468. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65469. + if (pcgcctl.b.restoremode == 1) {
  65470. + gintmsk_data_t gintmsk = {.d32 = 0 };
  65471. + /*
  65472. + * If restore mode is Remote Wakeup,
  65473. + * unmask Remote Wakeup interrupt.
  65474. + */
  65475. + gintmsk.b.wkupintr = 1;
  65476. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  65477. + 0, gintmsk.d32);
  65478. + }
  65479. +
  65480. + return 1;
  65481. +}
  65482. +
  65483. +/**
  65484. + * This interrupt indicates that a device has been disconnected from
  65485. + * the root port.
  65486. + */
  65487. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  65488. +{
  65489. + gintsts_data_t gintsts;
  65490. +
  65491. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  65492. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  65493. + op_state_str(core_if));
  65494. +
  65495. +/** @todo Consolidate this if statement. */
  65496. +#ifndef DWC_HOST_ONLY
  65497. + if (core_if->op_state == B_HOST) {
  65498. + /* If in device mode Disconnect and stop the HCD, then
  65499. + * start the PCD. */
  65500. + DWC_SPINUNLOCK(core_if->lock);
  65501. + cil_hcd_disconnect(core_if);
  65502. + cil_pcd_start(core_if);
  65503. + DWC_SPINLOCK(core_if->lock);
  65504. + core_if->op_state = B_PERIPHERAL;
  65505. + } else if (dwc_otg_is_device_mode(core_if)) {
  65506. + gotgctl_data_t gotgctl = {.d32 = 0 };
  65507. + gotgctl.d32 =
  65508. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  65509. + if (gotgctl.b.hstsethnpen == 1) {
  65510. + /* Do nothing, if HNP in process the OTG
  65511. + * interrupt "Host Negotiation Detected"
  65512. + * interrupt will do the mode switch.
  65513. + */
  65514. + } else if (gotgctl.b.devhnpen == 0) {
  65515. + /* If in device mode Disconnect and stop the HCD, then
  65516. + * start the PCD. */
  65517. + DWC_SPINUNLOCK(core_if->lock);
  65518. + cil_hcd_disconnect(core_if);
  65519. + cil_pcd_start(core_if);
  65520. + DWC_SPINLOCK(core_if->lock);
  65521. + core_if->op_state = B_PERIPHERAL;
  65522. + } else {
  65523. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  65524. + }
  65525. + } else {
  65526. + if (core_if->op_state == A_HOST) {
  65527. + /* A-Cable still connected but device disconnected. */
  65528. + cil_hcd_disconnect(core_if);
  65529. + if (core_if->adp_enable) {
  65530. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65531. + cil_hcd_stop(core_if);
  65532. + /* Enable Power Down Logic */
  65533. + gpwrdn.b.pmuintsel = 1;
  65534. + gpwrdn.b.pmuactv = 1;
  65535. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65536. + gpwrdn, 0, gpwrdn.d32);
  65537. + dwc_otg_adp_probe_start(core_if);
  65538. +
  65539. + /* Power off the core */
  65540. + if (core_if->power_down == 2) {
  65541. + gpwrdn.d32 = 0;
  65542. + gpwrdn.b.pwrdnswtch = 1;
  65543. + DWC_MODIFY_REG32
  65544. + (&core_if->core_global_regs->gpwrdn,
  65545. + gpwrdn.d32, 0);
  65546. + }
  65547. + }
  65548. + }
  65549. + }
  65550. +#endif
  65551. + /* Change to L3(OFF) state */
  65552. + core_if->lx_state = DWC_OTG_L3;
  65553. +
  65554. + gintsts.d32 = 0;
  65555. + gintsts.b.disconnect = 1;
  65556. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65557. + return 1;
  65558. +}
  65559. +
  65560. +/**
  65561. + * This interrupt indicates that SUSPEND state has been detected on
  65562. + * the USB.
  65563. + *
  65564. + * For HNP the USB Suspend interrupt signals the change from
  65565. + * "a_peripheral" to "a_host".
  65566. + *
  65567. + * When power management is enabled the core will be put in low power
  65568. + * mode.
  65569. + */
  65570. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  65571. +{
  65572. + dsts_data_t dsts;
  65573. + gintsts_data_t gintsts;
  65574. + dcfg_data_t dcfg;
  65575. +
  65576. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  65577. +
  65578. + if (dwc_otg_is_device_mode(core_if)) {
  65579. + /* Check the Device status register to determine if the Suspend
  65580. + * state is active. */
  65581. + dsts.d32 =
  65582. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  65583. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  65584. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  65585. + "HWCFG4.power Optimize=%d\n",
  65586. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  65587. +
  65588. +#ifdef PARTIAL_POWER_DOWN
  65589. +/** @todo Add a module parameter for power management. */
  65590. +
  65591. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  65592. + pcgcctl_data_t power = {.d32 = 0 };
  65593. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  65594. +
  65595. + power.b.pwrclmp = 1;
  65596. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65597. +
  65598. + power.b.rstpdwnmodule = 1;
  65599. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65600. +
  65601. + power.b.stoppclk = 1;
  65602. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65603. +
  65604. + } else {
  65605. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  65606. + }
  65607. +#endif
  65608. + /* PCD callback for suspend. Release the lock inside of callback function */
  65609. + cil_pcd_suspend(core_if);
  65610. + if (core_if->power_down == 2)
  65611. + {
  65612. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65613. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  65614. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  65615. +
  65616. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65617. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65618. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65619. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  65620. +
  65621. + /* Change to L2(suspend) state */
  65622. + core_if->lx_state = DWC_OTG_L2;
  65623. +
  65624. + /* Clear interrupt in gintsts */
  65625. + gintsts.d32 = 0;
  65626. + gintsts.b.usbsuspend = 1;
  65627. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65628. + gintsts, gintsts.d32);
  65629. + DWC_PRINTF("Start of hibernation completed\n");
  65630. + dwc_otg_save_global_regs(core_if);
  65631. + dwc_otg_save_dev_regs(core_if);
  65632. +
  65633. + gusbcfg.d32 =
  65634. + DWC_READ_REG32(&core_if->core_global_regs->
  65635. + gusbcfg);
  65636. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  65637. + /* ULPI interface */
  65638. + /* Suspend the Phy Clock */
  65639. + pcgcctl.d32 = 0;
  65640. + pcgcctl.b.stoppclk = 1;
  65641. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65642. + pcgcctl.d32);
  65643. + dwc_udelay(10);
  65644. + gpwrdn.b.pmuactv = 1;
  65645. + DWC_MODIFY_REG32(&core_if->
  65646. + core_global_regs->
  65647. + gpwrdn, 0, gpwrdn.d32);
  65648. + } else {
  65649. + /* UTMI+ Interface */
  65650. + gpwrdn.b.pmuactv = 1;
  65651. + DWC_MODIFY_REG32(&core_if->
  65652. + core_global_regs->
  65653. + gpwrdn, 0, gpwrdn.d32);
  65654. + dwc_udelay(10);
  65655. + pcgcctl.b.stoppclk = 1;
  65656. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65657. + pcgcctl.d32);
  65658. + dwc_udelay(10);
  65659. + }
  65660. +
  65661. + /* Set flag to indicate that we are in hibernation */
  65662. + core_if->hibernation_suspend = 1;
  65663. + /* Enable interrupts from wake up logic */
  65664. + gpwrdn.d32 = 0;
  65665. + gpwrdn.b.pmuintsel = 1;
  65666. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65667. + gpwrdn, 0, gpwrdn.d32);
  65668. + dwc_udelay(10);
  65669. +
  65670. + /* Unmask device mode interrupts in GPWRDN */
  65671. + gpwrdn.d32 = 0;
  65672. + gpwrdn.b.rst_det_msk = 1;
  65673. + gpwrdn.b.lnstchng_msk = 1;
  65674. + gpwrdn.b.sts_chngint_msk = 1;
  65675. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65676. + gpwrdn, 0, gpwrdn.d32);
  65677. + dwc_udelay(10);
  65678. +
  65679. + /* Enable Power Down Clamp */
  65680. + gpwrdn.d32 = 0;
  65681. + gpwrdn.b.pwrdnclmp = 1;
  65682. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65683. + gpwrdn, 0, gpwrdn.d32);
  65684. + dwc_udelay(10);
  65685. +
  65686. + /* Switch off VDD */
  65687. + gpwrdn.d32 = 0;
  65688. + gpwrdn.b.pwrdnswtch = 1;
  65689. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65690. + gpwrdn, 0, gpwrdn.d32);
  65691. +
  65692. + /* Save gpwrdn register for further usage if stschng interrupt */
  65693. + core_if->gr_backup->gpwrdn_local =
  65694. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65695. + DWC_PRINTF("Hibernation completed\n");
  65696. +
  65697. + return 1;
  65698. + }
  65699. + } else if (core_if->power_down == 3) {
  65700. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65701. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65702. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  65703. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  65704. +
  65705. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65706. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  65707. + core_if->xhib = 1;
  65708. +
  65709. + /* Clear interrupt in gintsts */
  65710. + gintsts.d32 = 0;
  65711. + gintsts.b.usbsuspend = 1;
  65712. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65713. + gintsts, gintsts.d32);
  65714. +
  65715. + dwc_otg_save_global_regs(core_if);
  65716. + dwc_otg_save_dev_regs(core_if);
  65717. +
  65718. + /* Wait for 10 PHY clocks */
  65719. + dwc_udelay(10);
  65720. +
  65721. + /* Program GPIO register while entering to xHib */
  65722. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  65723. +
  65724. + pcgcctl.b.enbl_extnd_hiber = 1;
  65725. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65726. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65727. +
  65728. + pcgcctl.d32 = 0;
  65729. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  65730. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65731. +
  65732. + pcgcctl.d32 = 0;
  65733. + pcgcctl.b.extnd_hiber_switch = 1;
  65734. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65735. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  65736. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65737. +
  65738. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  65739. +
  65740. + return 1;
  65741. + }
  65742. + }
  65743. + } else {
  65744. + if (core_if->op_state == A_PERIPHERAL) {
  65745. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  65746. + /* Clear the a_peripheral flag, back to a_host. */
  65747. + DWC_SPINUNLOCK(core_if->lock);
  65748. + cil_pcd_stop(core_if);
  65749. + cil_hcd_start(core_if);
  65750. + DWC_SPINLOCK(core_if->lock);
  65751. + core_if->op_state = A_HOST;
  65752. + }
  65753. + }
  65754. +
  65755. + /* Change to L2(suspend) state */
  65756. + core_if->lx_state = DWC_OTG_L2;
  65757. +
  65758. + /* Clear interrupt */
  65759. + gintsts.d32 = 0;
  65760. + gintsts.b.usbsuspend = 1;
  65761. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65762. +
  65763. + return 1;
  65764. +}
  65765. +
  65766. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  65767. +{
  65768. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65769. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65770. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65771. +
  65772. + dwc_udelay(10);
  65773. +
  65774. + /* Program GPIO register while entering to xHib */
  65775. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  65776. +
  65777. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  65778. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65779. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65780. + dwc_udelay(10);
  65781. +
  65782. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  65783. + gpwrdn.b.restore = 1;
  65784. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  65785. + dwc_udelay(10);
  65786. +
  65787. + restore_lpm_i2c_regs(core_if);
  65788. +
  65789. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65790. + pcgcctl.b.max_xcvrselect = 1;
  65791. + pcgcctl.b.ess_reg_restored = 0;
  65792. + pcgcctl.b.extnd_hiber_switch = 0;
  65793. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65794. + pcgcctl.b.enbl_extnd_hiber = 1;
  65795. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65796. +
  65797. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  65798. + gahbcfg.b.glblintrmsk = 1;
  65799. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  65800. +
  65801. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  65802. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  65803. +
  65804. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  65805. + core_if->gr_backup->gusbcfg_local);
  65806. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  65807. + core_if->dr_backup->dcfg);
  65808. +
  65809. + pcgcctl.d32 = 0;
  65810. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65811. + pcgcctl.b.max_xcvrselect = 1;
  65812. + pcgcctl.d32 |= 0x608;
  65813. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65814. + dwc_udelay(10);
  65815. +
  65816. + pcgcctl.d32 = 0;
  65817. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65818. + pcgcctl.b.max_xcvrselect = 1;
  65819. + pcgcctl.b.ess_reg_restored = 1;
  65820. + pcgcctl.b.enbl_extnd_hiber = 1;
  65821. + pcgcctl.b.rstpdwnmodule = 1;
  65822. + pcgcctl.b.restoremode = 1;
  65823. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65824. +
  65825. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65826. +
  65827. + return 1;
  65828. +}
  65829. +
  65830. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65831. +/**
  65832. + * This function hadles LPM transaction received interrupt.
  65833. + */
  65834. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  65835. +{
  65836. + glpmcfg_data_t lpmcfg;
  65837. + gintsts_data_t gintsts;
  65838. +
  65839. + if (!core_if->core_params->lpm_enable) {
  65840. + DWC_PRINTF("Unexpected LPM interrupt\n");
  65841. + }
  65842. +
  65843. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65844. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  65845. +
  65846. + if (dwc_otg_is_host_mode(core_if)) {
  65847. + cil_hcd_sleep(core_if);
  65848. + } else {
  65849. + lpmcfg.b.hird_thres |= (1 << 4);
  65850. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65851. + lpmcfg.d32);
  65852. + }
  65853. +
  65854. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  65855. + dwc_udelay(10);
  65856. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65857. + if (lpmcfg.b.prt_sleep_sts) {
  65858. + /* Save the current state */
  65859. + core_if->lx_state = DWC_OTG_L1;
  65860. + }
  65861. +
  65862. + /* Clear interrupt */
  65863. + gintsts.d32 = 0;
  65864. + gintsts.b.lpmtranrcvd = 1;
  65865. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65866. + return 1;
  65867. +}
  65868. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  65869. +
  65870. +/**
  65871. + * This function returns the Core Interrupt register.
  65872. + */
  65873. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
  65874. +{
  65875. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65876. + gintsts_data_t gintsts;
  65877. + gintmsk_data_t gintmsk;
  65878. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  65879. + gintmsk_common.b.wkupintr = 1;
  65880. + gintmsk_common.b.sessreqintr = 1;
  65881. + gintmsk_common.b.conidstschng = 1;
  65882. + gintmsk_common.b.otgintr = 1;
  65883. + gintmsk_common.b.modemismatch = 1;
  65884. + gintmsk_common.b.disconnect = 1;
  65885. + gintmsk_common.b.usbsuspend = 1;
  65886. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65887. + gintmsk_common.b.lpmtranrcvd = 1;
  65888. +#endif
  65889. + gintmsk_common.b.restoredone = 1;
  65890. + if(dwc_otg_is_device_mode(core_if))
  65891. + {
  65892. + /** @todo: The port interrupt occurs while in device
  65893. + * mode. Added code to CIL to clear the interrupt for now!
  65894. + */
  65895. + gintmsk_common.b.portintr = 1;
  65896. + }
  65897. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  65898. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  65899. + {
  65900. + unsigned long flags;
  65901. +
  65902. + // Re-enable the saved interrupts
  65903. + local_irq_save(flags);
  65904. + local_fiq_disable();
  65905. + gintmsk.d32 |= gintmsk_common.d32;
  65906. + gintsts_saved.d32 &= ~gintmsk_common.d32;
  65907. + reenable_gintmsk->d32 = gintmsk.d32;
  65908. + local_irq_restore(flags);
  65909. + }
  65910. +
  65911. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  65912. +
  65913. +#ifdef DEBUG
  65914. + /* if any common interrupts set */
  65915. + if (gintsts.d32 & gintmsk_common.d32) {
  65916. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  65917. + gintsts.d32, gintmsk.d32);
  65918. + }
  65919. +#endif
  65920. + if (!fiq_fix_enable){
  65921. + if (gahbcfg.b.glblintrmsk)
  65922. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65923. + else
  65924. + return 0;
  65925. + }
  65926. + else {
  65927. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65928. + }
  65929. +
  65930. +}
  65931. +
  65932. +/* MACRO for clearing interupt bits in GPWRDN register */
  65933. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  65934. +do { \
  65935. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  65936. + gpwrdn.b.__intr = 1; \
  65937. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  65938. + 0, gpwrdn.d32); \
  65939. +} while (0)
  65940. +
  65941. +/**
  65942. + * Common interrupt handler.
  65943. + *
  65944. + * The common interrupts are those that occur in both Host and Device mode.
  65945. + * This handler handles the following interrupts:
  65946. + * - Mode Mismatch Interrupt
  65947. + * - Disconnect Interrupt
  65948. + * - OTG Interrupt
  65949. + * - Connector ID Status Change Interrupt
  65950. + * - Session Request Interrupt.
  65951. + * - Resume / Remote Wakeup Detected Interrupt.
  65952. + * - LPM Transaction Received Interrupt
  65953. + * - ADP Transaction Received Interrupt
  65954. + *
  65955. + */
  65956. +int32_t dwc_otg_handle_common_intr(void *dev)
  65957. +{
  65958. + int retval = 0;
  65959. + gintsts_data_t gintsts;
  65960. + gintmsk_data_t reenable_gintmsk;
  65961. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65962. + dwc_otg_device_t *otg_dev = dev;
  65963. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65964. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65965. + if (dwc_otg_is_device_mode(core_if))
  65966. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  65967. +
  65968. + if (core_if->lock)
  65969. + DWC_SPINLOCK(core_if->lock);
  65970. +
  65971. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  65972. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  65973. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  65974. + core_if->xhib = 2;
  65975. + if (core_if->lock)
  65976. + DWC_SPINUNLOCK(core_if->lock);
  65977. +
  65978. + return retval;
  65979. + }
  65980. +
  65981. + if (core_if->hibernation_suspend <= 0) {
  65982. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
  65983. +
  65984. + if (gintsts.b.modemismatch) {
  65985. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  65986. + }
  65987. + if (gintsts.b.otgintr) {
  65988. + retval |= dwc_otg_handle_otg_intr(core_if);
  65989. + }
  65990. + if (gintsts.b.conidstschng) {
  65991. + retval |=
  65992. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  65993. + }
  65994. + if (gintsts.b.disconnect) {
  65995. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  65996. + }
  65997. + if (gintsts.b.sessreqintr) {
  65998. + retval |= dwc_otg_handle_session_req_intr(core_if);
  65999. + }
  66000. + if (gintsts.b.wkupintr) {
  66001. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  66002. + }
  66003. + if (gintsts.b.usbsuspend) {
  66004. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  66005. + }
  66006. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66007. + if (gintsts.b.lpmtranrcvd) {
  66008. + retval |= dwc_otg_handle_lpm_intr(core_if);
  66009. + }
  66010. +#endif
  66011. + if (gintsts.b.restoredone) {
  66012. + gintsts.d32 = 0;
  66013. + if (core_if->power_down == 2)
  66014. + core_if->hibernation_suspend = -1;
  66015. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  66016. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66017. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66018. + dctl_data_t dctl = {.d32 = 0 };
  66019. +
  66020. + DWC_WRITE_REG32(&core_if->core_global_regs->
  66021. + gintsts, 0xFFFFFFFF);
  66022. +
  66023. + DWC_DEBUGPL(DBG_ANY,
  66024. + "RESTORE DONE generated\n");
  66025. +
  66026. + gpwrdn.b.restore = 1;
  66027. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66028. + dwc_udelay(10);
  66029. +
  66030. + pcgcctl.b.rstpdwnmodule = 1;
  66031. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66032. +
  66033. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  66034. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  66035. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  66036. + dwc_udelay(50);
  66037. +
  66038. + dctl.b.pwronprgdone = 1;
  66039. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  66040. + dwc_udelay(10);
  66041. +
  66042. + dwc_otg_restore_global_regs(core_if);
  66043. + dwc_otg_restore_dev_regs(core_if, 0);
  66044. +
  66045. + dctl.d32 = 0;
  66046. + dctl.b.pwronprgdone = 1;
  66047. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  66048. + dwc_udelay(10);
  66049. +
  66050. + pcgcctl.d32 = 0;
  66051. + pcgcctl.b.enbl_extnd_hiber = 1;
  66052. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66053. +
  66054. + /* The core will be in ON STATE */
  66055. + core_if->lx_state = DWC_OTG_L0;
  66056. + core_if->xhib = 0;
  66057. +
  66058. + DWC_SPINUNLOCK(core_if->lock);
  66059. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  66060. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  66061. + }
  66062. + DWC_SPINLOCK(core_if->lock);
  66063. +
  66064. + }
  66065. +
  66066. + gintsts.b.restoredone = 1;
  66067. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66068. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  66069. + retval |= 1;
  66070. + }
  66071. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  66072. + /* The port interrupt occurs while in device mode with HPRT0
  66073. + * Port Enable/Disable.
  66074. + */
  66075. + gintsts.d32 = 0;
  66076. + gintsts.b.portintr = 1;
  66077. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66078. + retval |= 1;
  66079. + reenable_gintmsk.b.portintr = 1;
  66080. +
  66081. + }
  66082. +
  66083. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
  66084. +
  66085. + } else {
  66086. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  66087. +
  66088. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  66089. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  66090. + if (gpwrdn.b.linestate == 0) {
  66091. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  66092. + } else {
  66093. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  66094. + }
  66095. +
  66096. + retval |= 1;
  66097. + }
  66098. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  66099. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  66100. + /* remote wakeup from hibernation */
  66101. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  66102. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  66103. + } else {
  66104. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  66105. + }
  66106. + retval |= 1;
  66107. + }
  66108. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  66109. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  66110. + if (gpwrdn.b.linestate == 0) {
  66111. + DWC_PRINTF("Reset detected\n");
  66112. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  66113. + }
  66114. + }
  66115. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  66116. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  66117. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  66118. + retval |= 1;
  66119. + }
  66120. + }
  66121. + /* Handle ADP interrupt here */
  66122. + if (gpwrdn.b.adp_int) {
  66123. + DWC_PRINTF("ADP interrupt\n");
  66124. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  66125. + dwc_otg_adp_handle_intr(core_if);
  66126. + retval |= 1;
  66127. + }
  66128. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  66129. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  66130. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  66131. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  66132. +
  66133. + retval |= 1;
  66134. + }
  66135. + if (core_if->lock)
  66136. + DWC_SPINUNLOCK(core_if->lock);
  66137. +
  66138. + return retval;
  66139. +}
  66140. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  66141. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  66142. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-03-13 12:46:39.516097989 +0100
  66143. @@ -0,0 +1,705 @@
  66144. +/* ==========================================================================
  66145. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  66146. + * $Revision: #13 $
  66147. + * $Date: 2012/08/10 $
  66148. + * $Change: 2047372 $
  66149. + *
  66150. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66151. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66152. + * otherwise expressly agreed to in writing between Synopsys and you.
  66153. + *
  66154. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66155. + * any End User Software License Agreement or Agreement for Licensed Product
  66156. + * with Synopsys or any supplement thereto. You are permitted to use and
  66157. + * redistribute this Software in source and binary forms, with or without
  66158. + * modification, provided that redistributions of source code must retain this
  66159. + * notice. You may not view, use, disclose, copy or distribute this file or
  66160. + * any information contained herein except pursuant to this license grant from
  66161. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66162. + * below, then you are not authorized to use the Software.
  66163. + *
  66164. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66165. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66166. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66167. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66168. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66169. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66170. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66171. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66172. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66173. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66174. + * DAMAGE.
  66175. + * ========================================================================== */
  66176. +#if !defined(__DWC_CORE_IF_H__)
  66177. +#define __DWC_CORE_IF_H__
  66178. +
  66179. +#include "dwc_os.h"
  66180. +
  66181. +/** @file
  66182. + * This file defines DWC_OTG Core API
  66183. + */
  66184. +
  66185. +struct dwc_otg_core_if;
  66186. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  66187. +
  66188. +/** Maximum number of Periodic FIFOs */
  66189. +#define MAX_PERIO_FIFOS 15
  66190. +/** Maximum number of Periodic FIFOs */
  66191. +#define MAX_TX_FIFOS 15
  66192. +
  66193. +/** Maximum number of Endpoints/HostChannels */
  66194. +#define MAX_EPS_CHANNELS 16
  66195. +
  66196. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  66197. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  66198. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  66199. +
  66200. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  66201. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  66202. +
  66203. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  66204. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  66205. +
  66206. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  66207. +
  66208. +/** This function should be called on every hardware interrupt. */
  66209. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  66210. +
  66211. +/** @name OTG Core Parameters */
  66212. +/** @{ */
  66213. +
  66214. +/**
  66215. + * Specifies the OTG capabilities. The driver will automatically
  66216. + * detect the value for this parameter if none is specified.
  66217. + * 0 - HNP and SRP capable (default)
  66218. + * 1 - SRP Only capable
  66219. + * 2 - No HNP/SRP capable
  66220. + */
  66221. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  66222. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  66223. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  66224. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  66225. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  66226. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  66227. +
  66228. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  66229. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  66230. +#define dwc_param_opt_default 1
  66231. +
  66232. +/**
  66233. + * Specifies whether to use slave or DMA mode for accessing the data
  66234. + * FIFOs. The driver will automatically detect the value for this
  66235. + * parameter if none is specified.
  66236. + * 0 - Slave
  66237. + * 1 - DMA (default, if available)
  66238. + */
  66239. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  66240. + int32_t val);
  66241. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  66242. +#define dwc_param_dma_enable_default 1
  66243. +
  66244. +/**
  66245. + * When DMA mode is enabled specifies whether to use
  66246. + * address DMA or DMA Descritor mode for accessing the data
  66247. + * FIFOs in device mode. The driver will automatically detect
  66248. + * the value for this parameter if none is specified.
  66249. + * 0 - address DMA
  66250. + * 1 - DMA Descriptor(default, if available)
  66251. + */
  66252. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  66253. + int32_t val);
  66254. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  66255. +//#define dwc_param_dma_desc_enable_default 1
  66256. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  66257. +
  66258. +/** The DMA Burst size (applicable only for External DMA
  66259. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  66260. + */
  66261. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  66262. + int32_t val);
  66263. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  66264. +#define dwc_param_dma_burst_size_default 32
  66265. +
  66266. +/**
  66267. + * Specifies the maximum speed of operation in host and device mode.
  66268. + * The actual speed depends on the speed of the attached device and
  66269. + * the value of phy_type. The actual speed depends on the speed of the
  66270. + * attached device.
  66271. + * 0 - High Speed (default)
  66272. + * 1 - Full Speed
  66273. + */
  66274. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  66275. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  66276. +#define dwc_param_speed_default 0
  66277. +#define DWC_SPEED_PARAM_HIGH 0
  66278. +#define DWC_SPEED_PARAM_FULL 1
  66279. +
  66280. +/** Specifies whether low power mode is supported when attached
  66281. + * to a Full Speed or Low Speed device in host mode.
  66282. + * 0 - Don't support low power mode (default)
  66283. + * 1 - Support low power mode
  66284. + */
  66285. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  66286. + core_if, int32_t val);
  66287. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  66288. + * core_if);
  66289. +#define dwc_param_host_support_fs_ls_low_power_default 0
  66290. +
  66291. +/** Specifies the PHY clock rate in low power mode when connected to a
  66292. + * Low Speed device in host mode. This parameter is applicable only if
  66293. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  66294. + * then defaults to 6 MHZ otherwise 48 MHZ.
  66295. + *
  66296. + * 0 - 48 MHz
  66297. + * 1 - 6 MHz
  66298. + */
  66299. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  66300. + core_if, int32_t val);
  66301. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  66302. + core_if);
  66303. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  66304. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  66305. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  66306. +
  66307. +/**
  66308. + * 0 - Use cC FIFO size parameters
  66309. + * 1 - Allow dynamic FIFO sizing (default)
  66310. + */
  66311. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  66312. + int32_t val);
  66313. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  66314. + core_if);
  66315. +#define dwc_param_enable_dynamic_fifo_default 1
  66316. +
  66317. +/** Total number of 4-byte words in the data FIFO memory. This
  66318. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  66319. + * Tx FIFOs.
  66320. + * 32 to 32768 (default 8192)
  66321. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  66322. + */
  66323. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  66324. + int32_t val);
  66325. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  66326. +//#define dwc_param_data_fifo_size_default 8192
  66327. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  66328. +
  66329. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  66330. + * FIFO sizing is enabled.
  66331. + * 16 to 32768 (default 1064)
  66332. + */
  66333. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  66334. + int32_t val);
  66335. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  66336. +#define dwc_param_dev_rx_fifo_size_default 1064
  66337. +
  66338. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  66339. + * when dynamic FIFO sizing is enabled.
  66340. + * 16 to 32768 (default 1024)
  66341. + */
  66342. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66343. + core_if, int32_t val);
  66344. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66345. + core_if);
  66346. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  66347. +
  66348. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  66349. + * mode when dynamic FIFO sizing is enabled.
  66350. + * 4 to 768 (default 256)
  66351. + */
  66352. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66353. + int32_t val, int fifo_num);
  66354. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  66355. + core_if, int fifo_num);
  66356. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  66357. +
  66358. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  66359. + * FIFO sizing is enabled.
  66360. + * 16 to 32768 (default 1024)
  66361. + */
  66362. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  66363. + int32_t val);
  66364. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  66365. +//#define dwc_param_host_rx_fifo_size_default 1024
  66366. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  66367. +
  66368. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  66369. + * when Dynamic FIFO sizing is enabled in the core.
  66370. + * 16 to 32768 (default 1024)
  66371. + */
  66372. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66373. + core_if, int32_t val);
  66374. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66375. + core_if);
  66376. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  66377. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  66378. +
  66379. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  66380. + * FIFO sizing is enabled.
  66381. + * 16 to 32768 (default 1024)
  66382. + */
  66383. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  66384. + core_if, int32_t val);
  66385. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  66386. + core_if);
  66387. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  66388. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  66389. +
  66390. +/** The maximum transfer size supported in bytes.
  66391. + * 2047 to 65,535 (default 65,535)
  66392. + */
  66393. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  66394. + int32_t val);
  66395. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  66396. +#define dwc_param_max_transfer_size_default 65535
  66397. +
  66398. +/** The maximum number of packets in a transfer.
  66399. + * 15 to 511 (default 511)
  66400. + */
  66401. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  66402. + int32_t val);
  66403. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  66404. +#define dwc_param_max_packet_count_default 511
  66405. +
  66406. +/** The number of host channel registers to use.
  66407. + * 1 to 16 (default 12)
  66408. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  66409. + */
  66410. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  66411. + int32_t val);
  66412. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  66413. +//#define dwc_param_host_channels_default 12
  66414. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  66415. +
  66416. +/** The number of endpoints in addition to EP0 available for device
  66417. + * mode operations.
  66418. + * 1 to 15 (default 6 IN and OUT)
  66419. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  66420. + * endpoints in addition to EP0.
  66421. + */
  66422. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  66423. + int32_t val);
  66424. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  66425. +#define dwc_param_dev_endpoints_default 6
  66426. +
  66427. +/**
  66428. + * Specifies the type of PHY interface to use. By default, the driver
  66429. + * will automatically detect the phy_type.
  66430. + *
  66431. + * 0 - Full Speed PHY
  66432. + * 1 - UTMI+ (default)
  66433. + * 2 - ULPI
  66434. + */
  66435. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  66436. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  66437. +#define DWC_PHY_TYPE_PARAM_FS 0
  66438. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  66439. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  66440. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  66441. +
  66442. +/**
  66443. + * Specifies the UTMI+ Data Width. This parameter is
  66444. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  66445. + * PHY_TYPE, this parameter indicates the data width between
  66446. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  66447. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  66448. + * to "8 and 16 bits", meaning that the core has been
  66449. + * configured to work at either data path width.
  66450. + *
  66451. + * 8 or 16 bits (default 16)
  66452. + */
  66453. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  66454. + int32_t val);
  66455. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  66456. +//#define dwc_param_phy_utmi_width_default 16
  66457. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  66458. +
  66459. +/**
  66460. + * Specifies whether the ULPI operates at double or single
  66461. + * data rate. This parameter is only applicable if PHY_TYPE is
  66462. + * ULPI.
  66463. + *
  66464. + * 0 - single data rate ULPI interface with 8 bit wide data
  66465. + * bus (default)
  66466. + * 1 - double data rate ULPI interface with 4 bit wide data
  66467. + * bus
  66468. + */
  66469. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  66470. + int32_t val);
  66471. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  66472. +#define dwc_param_phy_ulpi_ddr_default 0
  66473. +
  66474. +/**
  66475. + * Specifies whether to use the internal or external supply to
  66476. + * drive the vbus with a ULPI phy.
  66477. + */
  66478. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  66479. + int32_t val);
  66480. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  66481. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  66482. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  66483. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  66484. +
  66485. +/**
  66486. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  66487. + * parameter is only applicable if PHY_TYPE is FS.
  66488. + * 0 - No (default)
  66489. + * 1 - Yes
  66490. + */
  66491. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  66492. + int32_t val);
  66493. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  66494. +#define dwc_param_i2c_enable_default 0
  66495. +
  66496. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  66497. + int32_t val);
  66498. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  66499. +#define dwc_param_ulpi_fs_ls_default 0
  66500. +
  66501. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  66502. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  66503. +#define dwc_param_ts_dline_default 0
  66504. +
  66505. +/**
  66506. + * Specifies whether dedicated transmit FIFOs are
  66507. + * enabled for non periodic IN endpoints in device mode
  66508. + * 0 - No
  66509. + * 1 - Yes
  66510. + */
  66511. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  66512. + int32_t val);
  66513. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  66514. + core_if);
  66515. +#define dwc_param_en_multiple_tx_fifo_default 1
  66516. +
  66517. +/** Number of 4-byte words in each of the Tx FIFOs in device
  66518. + * mode when dynamic FIFO sizing is enabled.
  66519. + * 4 to 768 (default 256)
  66520. + */
  66521. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66522. + int fifo_num, int32_t val);
  66523. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66524. + int fifo_num);
  66525. +#define dwc_param_dev_tx_fifo_size_default 768
  66526. +
  66527. +/** Thresholding enable flag-
  66528. + * bit 0 - enable non-ISO Tx thresholding
  66529. + * bit 1 - enable ISO Tx thresholding
  66530. + * bit 2 - enable Rx thresholding
  66531. + */
  66532. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  66533. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  66534. +#define dwc_param_thr_ctl_default 0
  66535. +
  66536. +/** Thresholding length for Tx
  66537. + * FIFOs in 32 bit DWORDs
  66538. + */
  66539. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  66540. + int32_t val);
  66541. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  66542. +#define dwc_param_tx_thr_length_default 64
  66543. +
  66544. +/** Thresholding length for Rx
  66545. + * FIFOs in 32 bit DWORDs
  66546. + */
  66547. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  66548. + int32_t val);
  66549. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  66550. +#define dwc_param_rx_thr_length_default 64
  66551. +
  66552. +/**
  66553. + * Specifies whether LPM (Link Power Management) support is enabled
  66554. + */
  66555. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  66556. + int32_t val);
  66557. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  66558. +#define dwc_param_lpm_enable_default 1
  66559. +
  66560. +/**
  66561. + * Specifies whether PTI enhancement is enabled
  66562. + */
  66563. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  66564. + int32_t val);
  66565. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  66566. +#define dwc_param_pti_enable_default 0
  66567. +
  66568. +/**
  66569. + * Specifies whether MPI enhancement is enabled
  66570. + */
  66571. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  66572. + int32_t val);
  66573. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  66574. +#define dwc_param_mpi_enable_default 0
  66575. +
  66576. +/**
  66577. + * Specifies whether ADP capability is enabled
  66578. + */
  66579. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  66580. + int32_t val);
  66581. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  66582. +#define dwc_param_adp_enable_default 0
  66583. +
  66584. +/**
  66585. + * Specifies whether IC_USB capability is enabled
  66586. + */
  66587. +
  66588. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  66589. + int32_t val);
  66590. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  66591. +#define dwc_param_ic_usb_cap_default 0
  66592. +
  66593. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  66594. + int32_t val);
  66595. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  66596. +#define dwc_param_ahb_thr_ratio_default 0
  66597. +
  66598. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  66599. + int32_t val);
  66600. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  66601. +#define dwc_param_power_down_default 0
  66602. +
  66603. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  66604. + int32_t val);
  66605. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  66606. +#define dwc_param_reload_ctl_default 0
  66607. +
  66608. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  66609. + int32_t val);
  66610. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  66611. +#define dwc_param_dev_out_nak_default 0
  66612. +
  66613. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  66614. + int32_t val);
  66615. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  66616. +#define dwc_param_cont_on_bna_default 0
  66617. +
  66618. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  66619. + int32_t val);
  66620. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  66621. +#define dwc_param_ahb_single_default 0
  66622. +
  66623. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  66624. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  66625. +#define dwc_param_otg_ver_default 0
  66626. +
  66627. +/** @} */
  66628. +
  66629. +/** @name Access to registers and bit-fields */
  66630. +
  66631. +/**
  66632. + * Dump core registers and SPRAM
  66633. + */
  66634. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  66635. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  66636. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  66637. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  66638. +
  66639. +/**
  66640. + * Get host negotiation status.
  66641. + */
  66642. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  66643. +
  66644. +/**
  66645. + * Get srp status
  66646. + */
  66647. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  66648. +
  66649. +/**
  66650. + * Set hnpreq bit in the GOTGCTL register.
  66651. + */
  66652. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  66653. +
  66654. +/**
  66655. + * Get Content of SNPSID register.
  66656. + */
  66657. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  66658. +
  66659. +/**
  66660. + * Get current mode.
  66661. + * Returns 0 if in device mode, and 1 if in host mode.
  66662. + */
  66663. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  66664. +
  66665. +/**
  66666. + * Get value of hnpcapable field in the GUSBCFG register
  66667. + */
  66668. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  66669. +/**
  66670. + * Set value of hnpcapable field in the GUSBCFG register
  66671. + */
  66672. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66673. +
  66674. +/**
  66675. + * Get value of srpcapable field in the GUSBCFG register
  66676. + */
  66677. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  66678. +/**
  66679. + * Set value of srpcapable field in the GUSBCFG register
  66680. + */
  66681. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66682. +
  66683. +/**
  66684. + * Get value of devspeed field in the DCFG register
  66685. + */
  66686. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  66687. +/**
  66688. + * Set value of devspeed field in the DCFG register
  66689. + */
  66690. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  66691. +
  66692. +/**
  66693. + * Get the value of busconnected field from the HPRT0 register
  66694. + */
  66695. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  66696. +
  66697. +/**
  66698. + * Gets the device enumeration Speed.
  66699. + */
  66700. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  66701. +
  66702. +/**
  66703. + * Get value of prtpwr field from the HPRT0 register
  66704. + */
  66705. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  66706. +
  66707. +/**
  66708. + * Get value of flag indicating core state - hibernated or not
  66709. + */
  66710. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  66711. +
  66712. +/**
  66713. + * Set value of prtpwr field from the HPRT0 register
  66714. + */
  66715. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  66716. +
  66717. +/**
  66718. + * Get value of prtsusp field from the HPRT0 regsiter
  66719. + */
  66720. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  66721. +/**
  66722. + * Set value of prtpwr field from the HPRT0 register
  66723. + */
  66724. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  66725. +
  66726. +/**
  66727. + * Get value of ModeChTimEn field from the HCFG regsiter
  66728. + */
  66729. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  66730. +/**
  66731. + * Set value of ModeChTimEn field from the HCFG regsiter
  66732. + */
  66733. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  66734. +
  66735. +/**
  66736. + * Get value of Fram Interval field from the HFIR regsiter
  66737. + */
  66738. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  66739. +/**
  66740. + * Set value of Frame Interval field from the HFIR regsiter
  66741. + */
  66742. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  66743. +
  66744. +/**
  66745. + * Set value of prtres field from the HPRT0 register
  66746. + *FIXME Remove?
  66747. + */
  66748. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  66749. +
  66750. +/**
  66751. + * Get value of rmtwkupsig bit in DCTL register
  66752. + */
  66753. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  66754. +
  66755. +/**
  66756. + * Get value of prt_sleep_sts field from the GLPMCFG register
  66757. + */
  66758. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  66759. +
  66760. +/**
  66761. + * Get value of rem_wkup_en field from the GLPMCFG register
  66762. + */
  66763. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  66764. +
  66765. +/**
  66766. + * Get value of appl_resp field from the GLPMCFG register
  66767. + */
  66768. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  66769. +/**
  66770. + * Set value of appl_resp field from the GLPMCFG register
  66771. + */
  66772. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  66773. +
  66774. +/**
  66775. + * Get value of hsic_connect field from the GLPMCFG register
  66776. + */
  66777. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  66778. +/**
  66779. + * Set value of hsic_connect field from the GLPMCFG register
  66780. + */
  66781. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  66782. +
  66783. +/**
  66784. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  66785. + */
  66786. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  66787. +/**
  66788. + * Set value of inv_sel_hsic field from the GLPMFG register.
  66789. + */
  66790. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  66791. +
  66792. +/*
  66793. + * Some functions for accessing registers
  66794. + */
  66795. +
  66796. +/**
  66797. + * GOTGCTL register
  66798. + */
  66799. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  66800. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66801. +
  66802. +/**
  66803. + * GUSBCFG register
  66804. + */
  66805. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  66806. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  66807. +
  66808. +/**
  66809. + * GRXFSIZ register
  66810. + */
  66811. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  66812. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66813. +
  66814. +/**
  66815. + * GNPTXFSIZ register
  66816. + */
  66817. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  66818. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66819. +
  66820. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  66821. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66822. +
  66823. +/**
  66824. + * GGPIO register
  66825. + */
  66826. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  66827. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  66828. +
  66829. +/**
  66830. + * GUID register
  66831. + */
  66832. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  66833. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  66834. +
  66835. +/**
  66836. + * HPRT0 register
  66837. + */
  66838. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  66839. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  66840. +
  66841. +/**
  66842. + * GHPTXFSIZE
  66843. + */
  66844. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  66845. +
  66846. +/** @} */
  66847. +
  66848. +#endif /* __DWC_CORE_IF_H__ */
  66849. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  66850. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  66851. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-03-13 12:46:39.516097989 +0100
  66852. @@ -0,0 +1,117 @@
  66853. +/* ==========================================================================
  66854. + *
  66855. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66856. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66857. + * otherwise expressly agreed to in writing between Synopsys and you.
  66858. + *
  66859. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66860. + * any End User Software License Agreement or Agreement for Licensed Product
  66861. + * with Synopsys or any supplement thereto. You are permitted to use and
  66862. + * redistribute this Software in source and binary forms, with or without
  66863. + * modification, provided that redistributions of source code must retain this
  66864. + * notice. You may not view, use, disclose, copy or distribute this file or
  66865. + * any information contained herein except pursuant to this license grant from
  66866. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66867. + * below, then you are not authorized to use the Software.
  66868. + *
  66869. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66870. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66871. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66872. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66873. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66874. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66875. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66876. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66877. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66878. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66879. + * DAMAGE.
  66880. + * ========================================================================== */
  66881. +
  66882. +#ifndef __DWC_OTG_DBG_H__
  66883. +#define __DWC_OTG_DBG_H__
  66884. +
  66885. +/** @file
  66886. + * This file defines debug levels.
  66887. + * Debugging support vanishes in non-debug builds.
  66888. + */
  66889. +
  66890. +/**
  66891. + * The Debug Level bit-mask variable.
  66892. + */
  66893. +extern uint32_t g_dbg_lvl;
  66894. +/**
  66895. + * Set the Debug Level variable.
  66896. + */
  66897. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  66898. +{
  66899. + uint32_t old = g_dbg_lvl;
  66900. + g_dbg_lvl = new;
  66901. + return old;
  66902. +}
  66903. +
  66904. +#define DBG_USER (0x1)
  66905. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  66906. +#define DBG_CIL (0x2)
  66907. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  66908. + * messages */
  66909. +#define DBG_CILV (0x20)
  66910. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  66911. + * messages */
  66912. +#define DBG_PCD (0x4)
  66913. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  66914. + * messages */
  66915. +#define DBG_PCDV (0x40)
  66916. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  66917. +#define DBG_HCD (0x8)
  66918. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  66919. + * messages */
  66920. +#define DBG_HCDV (0x80)
  66921. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  66922. + * mode. */
  66923. +#define DBG_HCD_URB (0x800)
  66924. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  66925. + * messages. */
  66926. +#define DBG_HCDI (0x1000)
  66927. +
  66928. +/** When debug level has any bit set, display debug messages */
  66929. +#define DBG_ANY (0xFF)
  66930. +
  66931. +/** All debug messages off */
  66932. +#define DBG_OFF 0
  66933. +
  66934. +/** Prefix string for DWC_DEBUG print macros. */
  66935. +#define USB_DWC "DWC_otg: "
  66936. +
  66937. +/**
  66938. + * Print a debug message when the Global debug level variable contains
  66939. + * the bit defined in <code>lvl</code>.
  66940. + *
  66941. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  66942. + * @param[in] x - like printf
  66943. + *
  66944. + * Example:<p>
  66945. + * <code>
  66946. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  66947. + * </code>
  66948. + * <br>
  66949. + * results in:<br>
  66950. + * <code>
  66951. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  66952. + * </code>
  66953. + */
  66954. +#ifdef DEBUG
  66955. +
  66956. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  66957. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  66958. +
  66959. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  66960. +
  66961. +#else
  66962. +
  66963. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  66964. +# define DWC_DEBUGP(x...)
  66965. +
  66966. +# define CHK_DEBUG_LEVEL(level) (0)
  66967. +
  66968. +#endif /*DEBUG*/
  66969. +#endif
  66970. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  66971. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  66972. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-03-13 12:46:39.516097989 +0100
  66973. @@ -0,0 +1,1742 @@
  66974. +/* ==========================================================================
  66975. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  66976. + * $Revision: #92 $
  66977. + * $Date: 2012/08/10 $
  66978. + * $Change: 2047372 $
  66979. + *
  66980. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66981. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66982. + * otherwise expressly agreed to in writing between Synopsys and you.
  66983. + *
  66984. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66985. + * any End User Software License Agreement or Agreement for Licensed Product
  66986. + * with Synopsys or any supplement thereto. You are permitted to use and
  66987. + * redistribute this Software in source and binary forms, with or without
  66988. + * modification, provided that redistributions of source code must retain this
  66989. + * notice. You may not view, use, disclose, copy or distribute this file or
  66990. + * any information contained herein except pursuant to this license grant from
  66991. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66992. + * below, then you are not authorized to use the Software.
  66993. + *
  66994. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66995. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66996. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66997. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66998. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66999. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67000. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67001. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67002. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67003. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67004. + * DAMAGE.
  67005. + * ========================================================================== */
  67006. +
  67007. +/** @file
  67008. + * The dwc_otg_driver module provides the initialization and cleanup entry
  67009. + * points for the DWC_otg driver. This module will be dynamically installed
  67010. + * after Linux is booted using the insmod command. When the module is
  67011. + * installed, the dwc_otg_driver_init function is called. When the module is
  67012. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  67013. + *
  67014. + * This module also defines a data structure for the dwc_otg_driver, which is
  67015. + * used in conjunction with the standard ARM lm_device structure. These
  67016. + * structures allow the OTG driver to comply with the standard Linux driver
  67017. + * model in which devices and drivers are registered with a bus driver. This
  67018. + * has the benefit that Linux can expose attributes of the driver and device
  67019. + * in its special sysfs file system. Users can then read or write files in
  67020. + * this file system to perform diagnostics on the driver components or the
  67021. + * device.
  67022. + */
  67023. +
  67024. +#include "dwc_otg_os_dep.h"
  67025. +#include "dwc_os.h"
  67026. +#include "dwc_otg_dbg.h"
  67027. +#include "dwc_otg_driver.h"
  67028. +#include "dwc_otg_attr.h"
  67029. +#include "dwc_otg_core_if.h"
  67030. +#include "dwc_otg_pcd_if.h"
  67031. +#include "dwc_otg_hcd_if.h"
  67032. +
  67033. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  67034. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  67035. +
  67036. +bool microframe_schedule=true;
  67037. +
  67038. +static const char dwc_driver_name[] = "dwc_otg";
  67039. +
  67040. +extern void* dummy_send;
  67041. +
  67042. +extern int pcd_init(
  67043. +#ifdef LM_INTERFACE
  67044. + struct lm_device *_dev
  67045. +#elif defined(PCI_INTERFACE)
  67046. + struct pci_dev *_dev
  67047. +#elif defined(PLATFORM_INTERFACE)
  67048. + struct platform_device *dev
  67049. +#endif
  67050. + );
  67051. +extern int hcd_init(
  67052. +#ifdef LM_INTERFACE
  67053. + struct lm_device *_dev
  67054. +#elif defined(PCI_INTERFACE)
  67055. + struct pci_dev *_dev
  67056. +#elif defined(PLATFORM_INTERFACE)
  67057. + struct platform_device *dev
  67058. +#endif
  67059. + );
  67060. +
  67061. +extern int pcd_remove(
  67062. +#ifdef LM_INTERFACE
  67063. + struct lm_device *_dev
  67064. +#elif defined(PCI_INTERFACE)
  67065. + struct pci_dev *_dev
  67066. +#elif defined(PLATFORM_INTERFACE)
  67067. + struct platform_device *_dev
  67068. +#endif
  67069. + );
  67070. +
  67071. +extern void hcd_remove(
  67072. +#ifdef LM_INTERFACE
  67073. + struct lm_device *_dev
  67074. +#elif defined(PCI_INTERFACE)
  67075. + struct pci_dev *_dev
  67076. +#elif defined(PLATFORM_INTERFACE)
  67077. + struct platform_device *_dev
  67078. +#endif
  67079. + );
  67080. +
  67081. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  67082. +
  67083. +/*-------------------------------------------------------------------------*/
  67084. +/* Encapsulate the module parameter settings */
  67085. +
  67086. +struct dwc_otg_driver_module_params {
  67087. + int32_t opt;
  67088. + int32_t otg_cap;
  67089. + int32_t dma_enable;
  67090. + int32_t dma_desc_enable;
  67091. + int32_t dma_burst_size;
  67092. + int32_t speed;
  67093. + int32_t host_support_fs_ls_low_power;
  67094. + int32_t host_ls_low_power_phy_clk;
  67095. + int32_t enable_dynamic_fifo;
  67096. + int32_t data_fifo_size;
  67097. + int32_t dev_rx_fifo_size;
  67098. + int32_t dev_nperio_tx_fifo_size;
  67099. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  67100. + int32_t host_rx_fifo_size;
  67101. + int32_t host_nperio_tx_fifo_size;
  67102. + int32_t host_perio_tx_fifo_size;
  67103. + int32_t max_transfer_size;
  67104. + int32_t max_packet_count;
  67105. + int32_t host_channels;
  67106. + int32_t dev_endpoints;
  67107. + int32_t phy_type;
  67108. + int32_t phy_utmi_width;
  67109. + int32_t phy_ulpi_ddr;
  67110. + int32_t phy_ulpi_ext_vbus;
  67111. + int32_t i2c_enable;
  67112. + int32_t ulpi_fs_ls;
  67113. + int32_t ts_dline;
  67114. + int32_t en_multiple_tx_fifo;
  67115. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  67116. + uint32_t thr_ctl;
  67117. + uint32_t tx_thr_length;
  67118. + uint32_t rx_thr_length;
  67119. + int32_t pti_enable;
  67120. + int32_t mpi_enable;
  67121. + int32_t lpm_enable;
  67122. + int32_t ic_usb_cap;
  67123. + int32_t ahb_thr_ratio;
  67124. + int32_t power_down;
  67125. + int32_t reload_ctl;
  67126. + int32_t dev_out_nak;
  67127. + int32_t cont_on_bna;
  67128. + int32_t ahb_single;
  67129. + int32_t otg_ver;
  67130. + int32_t adp_enable;
  67131. +};
  67132. +
  67133. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  67134. + .opt = -1,
  67135. + .otg_cap = -1,
  67136. + .dma_enable = -1,
  67137. + .dma_desc_enable = -1,
  67138. + .dma_burst_size = -1,
  67139. + .speed = -1,
  67140. + .host_support_fs_ls_low_power = -1,
  67141. + .host_ls_low_power_phy_clk = -1,
  67142. + .enable_dynamic_fifo = -1,
  67143. + .data_fifo_size = -1,
  67144. + .dev_rx_fifo_size = -1,
  67145. + .dev_nperio_tx_fifo_size = -1,
  67146. + .dev_perio_tx_fifo_size = {
  67147. + /* dev_perio_tx_fifo_size_1 */
  67148. + -1,
  67149. + -1,
  67150. + -1,
  67151. + -1,
  67152. + -1,
  67153. + -1,
  67154. + -1,
  67155. + -1,
  67156. + -1,
  67157. + -1,
  67158. + -1,
  67159. + -1,
  67160. + -1,
  67161. + -1,
  67162. + -1
  67163. + /* 15 */
  67164. + },
  67165. + .host_rx_fifo_size = -1,
  67166. + .host_nperio_tx_fifo_size = -1,
  67167. + .host_perio_tx_fifo_size = -1,
  67168. + .max_transfer_size = -1,
  67169. + .max_packet_count = -1,
  67170. + .host_channels = -1,
  67171. + .dev_endpoints = -1,
  67172. + .phy_type = -1,
  67173. + .phy_utmi_width = -1,
  67174. + .phy_ulpi_ddr = -1,
  67175. + .phy_ulpi_ext_vbus = -1,
  67176. + .i2c_enable = -1,
  67177. + .ulpi_fs_ls = -1,
  67178. + .ts_dline = -1,
  67179. + .en_multiple_tx_fifo = -1,
  67180. + .dev_tx_fifo_size = {
  67181. + /* dev_tx_fifo_size */
  67182. + -1,
  67183. + -1,
  67184. + -1,
  67185. + -1,
  67186. + -1,
  67187. + -1,
  67188. + -1,
  67189. + -1,
  67190. + -1,
  67191. + -1,
  67192. + -1,
  67193. + -1,
  67194. + -1,
  67195. + -1,
  67196. + -1
  67197. + /* 15 */
  67198. + },
  67199. + .thr_ctl = -1,
  67200. + .tx_thr_length = -1,
  67201. + .rx_thr_length = -1,
  67202. + .pti_enable = -1,
  67203. + .mpi_enable = -1,
  67204. + .lpm_enable = 0,
  67205. + .ic_usb_cap = -1,
  67206. + .ahb_thr_ratio = -1,
  67207. + .power_down = -1,
  67208. + .reload_ctl = -1,
  67209. + .dev_out_nak = -1,
  67210. + .cont_on_bna = -1,
  67211. + .ahb_single = -1,
  67212. + .otg_ver = -1,
  67213. + .adp_enable = -1,
  67214. +};
  67215. +
  67216. +//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
  67217. +extern bool fiq_fix_enable;
  67218. +// Global variable to enable the split transaction fix
  67219. +bool fiq_split_enable = true;
  67220. +//Global variable to switch the nak holdoff on or off
  67221. +bool nak_holdoff_enable = true;
  67222. +
  67223. +
  67224. +/**
  67225. + * This function shows the Driver Version.
  67226. + */
  67227. +static ssize_t version_show(struct device_driver *dev, char *buf)
  67228. +{
  67229. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  67230. + DWC_DRIVER_VERSION);
  67231. +}
  67232. +
  67233. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  67234. +
  67235. +/**
  67236. + * Global Debug Level Mask.
  67237. + */
  67238. +uint32_t g_dbg_lvl = 0; /* OFF */
  67239. +
  67240. +/**
  67241. + * This function shows the driver Debug Level.
  67242. + */
  67243. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  67244. +{
  67245. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  67246. +}
  67247. +
  67248. +/**
  67249. + * This function stores the driver Debug Level.
  67250. + */
  67251. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  67252. + size_t count)
  67253. +{
  67254. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  67255. + return count;
  67256. +}
  67257. +
  67258. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  67259. + dbg_level_store);
  67260. +
  67261. +/**
  67262. + * This function is called during module intialization
  67263. + * to pass module parameters to the DWC_OTG CORE.
  67264. + */
  67265. +static int set_parameters(dwc_otg_core_if_t * core_if)
  67266. +{
  67267. + int retval = 0;
  67268. + int i;
  67269. +
  67270. + if (dwc_otg_module_params.otg_cap != -1) {
  67271. + retval +=
  67272. + dwc_otg_set_param_otg_cap(core_if,
  67273. + dwc_otg_module_params.otg_cap);
  67274. + }
  67275. + if (dwc_otg_module_params.dma_enable != -1) {
  67276. + retval +=
  67277. + dwc_otg_set_param_dma_enable(core_if,
  67278. + dwc_otg_module_params.
  67279. + dma_enable);
  67280. + }
  67281. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  67282. + retval +=
  67283. + dwc_otg_set_param_dma_desc_enable(core_if,
  67284. + dwc_otg_module_params.
  67285. + dma_desc_enable);
  67286. + }
  67287. + if (dwc_otg_module_params.opt != -1) {
  67288. + retval +=
  67289. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  67290. + }
  67291. + if (dwc_otg_module_params.dma_burst_size != -1) {
  67292. + retval +=
  67293. + dwc_otg_set_param_dma_burst_size(core_if,
  67294. + dwc_otg_module_params.
  67295. + dma_burst_size);
  67296. + }
  67297. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  67298. + retval +=
  67299. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  67300. + dwc_otg_module_params.
  67301. + host_support_fs_ls_low_power);
  67302. + }
  67303. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  67304. + retval +=
  67305. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  67306. + dwc_otg_module_params.
  67307. + enable_dynamic_fifo);
  67308. + }
  67309. + if (dwc_otg_module_params.data_fifo_size != -1) {
  67310. + retval +=
  67311. + dwc_otg_set_param_data_fifo_size(core_if,
  67312. + dwc_otg_module_params.
  67313. + data_fifo_size);
  67314. + }
  67315. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  67316. + retval +=
  67317. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  67318. + dwc_otg_module_params.
  67319. + dev_rx_fifo_size);
  67320. + }
  67321. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  67322. + retval +=
  67323. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  67324. + dwc_otg_module_params.
  67325. + dev_nperio_tx_fifo_size);
  67326. + }
  67327. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  67328. + retval +=
  67329. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  67330. + dwc_otg_module_params.host_rx_fifo_size);
  67331. + }
  67332. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  67333. + retval +=
  67334. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  67335. + dwc_otg_module_params.
  67336. + host_nperio_tx_fifo_size);
  67337. + }
  67338. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  67339. + retval +=
  67340. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  67341. + dwc_otg_module_params.
  67342. + host_perio_tx_fifo_size);
  67343. + }
  67344. + if (dwc_otg_module_params.max_transfer_size != -1) {
  67345. + retval +=
  67346. + dwc_otg_set_param_max_transfer_size(core_if,
  67347. + dwc_otg_module_params.
  67348. + max_transfer_size);
  67349. + }
  67350. + if (dwc_otg_module_params.max_packet_count != -1) {
  67351. + retval +=
  67352. + dwc_otg_set_param_max_packet_count(core_if,
  67353. + dwc_otg_module_params.
  67354. + max_packet_count);
  67355. + }
  67356. + if (dwc_otg_module_params.host_channels != -1) {
  67357. + retval +=
  67358. + dwc_otg_set_param_host_channels(core_if,
  67359. + dwc_otg_module_params.
  67360. + host_channels);
  67361. + }
  67362. + if (dwc_otg_module_params.dev_endpoints != -1) {
  67363. + retval +=
  67364. + dwc_otg_set_param_dev_endpoints(core_if,
  67365. + dwc_otg_module_params.
  67366. + dev_endpoints);
  67367. + }
  67368. + if (dwc_otg_module_params.phy_type != -1) {
  67369. + retval +=
  67370. + dwc_otg_set_param_phy_type(core_if,
  67371. + dwc_otg_module_params.phy_type);
  67372. + }
  67373. + if (dwc_otg_module_params.speed != -1) {
  67374. + retval +=
  67375. + dwc_otg_set_param_speed(core_if,
  67376. + dwc_otg_module_params.speed);
  67377. + }
  67378. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  67379. + retval +=
  67380. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  67381. + dwc_otg_module_params.
  67382. + host_ls_low_power_phy_clk);
  67383. + }
  67384. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  67385. + retval +=
  67386. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  67387. + dwc_otg_module_params.
  67388. + phy_ulpi_ddr);
  67389. + }
  67390. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  67391. + retval +=
  67392. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  67393. + dwc_otg_module_params.
  67394. + phy_ulpi_ext_vbus);
  67395. + }
  67396. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  67397. + retval +=
  67398. + dwc_otg_set_param_phy_utmi_width(core_if,
  67399. + dwc_otg_module_params.
  67400. + phy_utmi_width);
  67401. + }
  67402. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  67403. + retval +=
  67404. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  67405. + dwc_otg_module_params.ulpi_fs_ls);
  67406. + }
  67407. + if (dwc_otg_module_params.ts_dline != -1) {
  67408. + retval +=
  67409. + dwc_otg_set_param_ts_dline(core_if,
  67410. + dwc_otg_module_params.ts_dline);
  67411. + }
  67412. + if (dwc_otg_module_params.i2c_enable != -1) {
  67413. + retval +=
  67414. + dwc_otg_set_param_i2c_enable(core_if,
  67415. + dwc_otg_module_params.
  67416. + i2c_enable);
  67417. + }
  67418. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  67419. + retval +=
  67420. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  67421. + dwc_otg_module_params.
  67422. + en_multiple_tx_fifo);
  67423. + }
  67424. + for (i = 0; i < 15; i++) {
  67425. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  67426. + retval +=
  67427. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  67428. + dwc_otg_module_params.
  67429. + dev_perio_tx_fifo_size
  67430. + [i], i);
  67431. + }
  67432. + }
  67433. +
  67434. + for (i = 0; i < 15; i++) {
  67435. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  67436. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  67437. + dwc_otg_module_params.
  67438. + dev_tx_fifo_size
  67439. + [i], i);
  67440. + }
  67441. + }
  67442. + if (dwc_otg_module_params.thr_ctl != -1) {
  67443. + retval +=
  67444. + dwc_otg_set_param_thr_ctl(core_if,
  67445. + dwc_otg_module_params.thr_ctl);
  67446. + }
  67447. + if (dwc_otg_module_params.mpi_enable != -1) {
  67448. + retval +=
  67449. + dwc_otg_set_param_mpi_enable(core_if,
  67450. + dwc_otg_module_params.
  67451. + mpi_enable);
  67452. + }
  67453. + if (dwc_otg_module_params.pti_enable != -1) {
  67454. + retval +=
  67455. + dwc_otg_set_param_pti_enable(core_if,
  67456. + dwc_otg_module_params.
  67457. + pti_enable);
  67458. + }
  67459. + if (dwc_otg_module_params.lpm_enable != -1) {
  67460. + retval +=
  67461. + dwc_otg_set_param_lpm_enable(core_if,
  67462. + dwc_otg_module_params.
  67463. + lpm_enable);
  67464. + }
  67465. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  67466. + retval +=
  67467. + dwc_otg_set_param_ic_usb_cap(core_if,
  67468. + dwc_otg_module_params.
  67469. + ic_usb_cap);
  67470. + }
  67471. + if (dwc_otg_module_params.tx_thr_length != -1) {
  67472. + retval +=
  67473. + dwc_otg_set_param_tx_thr_length(core_if,
  67474. + dwc_otg_module_params.tx_thr_length);
  67475. + }
  67476. + if (dwc_otg_module_params.rx_thr_length != -1) {
  67477. + retval +=
  67478. + dwc_otg_set_param_rx_thr_length(core_if,
  67479. + dwc_otg_module_params.
  67480. + rx_thr_length);
  67481. + }
  67482. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  67483. + retval +=
  67484. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  67485. + dwc_otg_module_params.ahb_thr_ratio);
  67486. + }
  67487. + if (dwc_otg_module_params.power_down != -1) {
  67488. + retval +=
  67489. + dwc_otg_set_param_power_down(core_if,
  67490. + dwc_otg_module_params.power_down);
  67491. + }
  67492. + if (dwc_otg_module_params.reload_ctl != -1) {
  67493. + retval +=
  67494. + dwc_otg_set_param_reload_ctl(core_if,
  67495. + dwc_otg_module_params.reload_ctl);
  67496. + }
  67497. +
  67498. + if (dwc_otg_module_params.dev_out_nak != -1) {
  67499. + retval +=
  67500. + dwc_otg_set_param_dev_out_nak(core_if,
  67501. + dwc_otg_module_params.dev_out_nak);
  67502. + }
  67503. +
  67504. + if (dwc_otg_module_params.cont_on_bna != -1) {
  67505. + retval +=
  67506. + dwc_otg_set_param_cont_on_bna(core_if,
  67507. + dwc_otg_module_params.cont_on_bna);
  67508. + }
  67509. +
  67510. + if (dwc_otg_module_params.ahb_single != -1) {
  67511. + retval +=
  67512. + dwc_otg_set_param_ahb_single(core_if,
  67513. + dwc_otg_module_params.ahb_single);
  67514. + }
  67515. +
  67516. + if (dwc_otg_module_params.otg_ver != -1) {
  67517. + retval +=
  67518. + dwc_otg_set_param_otg_ver(core_if,
  67519. + dwc_otg_module_params.otg_ver);
  67520. + }
  67521. + if (dwc_otg_module_params.adp_enable != -1) {
  67522. + retval +=
  67523. + dwc_otg_set_param_adp_enable(core_if,
  67524. + dwc_otg_module_params.
  67525. + adp_enable);
  67526. + }
  67527. + return retval;
  67528. +}
  67529. +
  67530. +/**
  67531. + * This function is the top level interrupt handler for the Common
  67532. + * (Device and host modes) interrupts.
  67533. + */
  67534. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  67535. +{
  67536. + int32_t retval = IRQ_NONE;
  67537. +
  67538. + retval = dwc_otg_handle_common_intr(dev);
  67539. + if (retval != 0) {
  67540. + S3C2410X_CLEAR_EINTPEND();
  67541. + }
  67542. + return IRQ_RETVAL(retval);
  67543. +}
  67544. +
  67545. +/**
  67546. + * This function is called when a lm_device is unregistered with the
  67547. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  67548. + * executed. The device may or may not be electrically present. If it is
  67549. + * present, the driver stops device processing. Any resources used on behalf
  67550. + * of this device are freed.
  67551. + *
  67552. + * @param _dev
  67553. + */
  67554. +#ifdef LM_INTERFACE
  67555. +#define REM_RETVAL(n)
  67556. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  67557. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  67558. +#elif defined(PCI_INTERFACE)
  67559. +#define REM_RETVAL(n)
  67560. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  67561. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  67562. +#elif defined(PLATFORM_INTERFACE)
  67563. +#define REM_RETVAL(n) n
  67564. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  67565. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  67566. +#endif
  67567. +
  67568. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  67569. +
  67570. + if (!otg_dev) {
  67571. + /* Memory allocation for the dwc_otg_device failed. */
  67572. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  67573. + return REM_RETVAL(-ENOMEM);
  67574. + }
  67575. +#ifndef DWC_DEVICE_ONLY
  67576. + if (otg_dev->hcd) {
  67577. + hcd_remove(_dev);
  67578. + } else {
  67579. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  67580. + return REM_RETVAL(-EINVAL);
  67581. + }
  67582. +#endif
  67583. +
  67584. +#ifndef DWC_HOST_ONLY
  67585. + if (otg_dev->pcd) {
  67586. + pcd_remove(_dev);
  67587. + } else {
  67588. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  67589. + return REM_RETVAL(-EINVAL);
  67590. + }
  67591. +#endif
  67592. + /*
  67593. + * Free the IRQ
  67594. + */
  67595. + if (otg_dev->common_irq_installed) {
  67596. +#ifdef PLATFORM_INTERFACE
  67597. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  67598. +#else
  67599. + free_irq(_dev->irq, otg_dev);
  67600. +#endif
  67601. + } else {
  67602. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  67603. + return REM_RETVAL(-ENXIO);
  67604. + }
  67605. +
  67606. + if (otg_dev->core_if) {
  67607. + dwc_otg_cil_remove(otg_dev->core_if);
  67608. + } else {
  67609. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  67610. + return REM_RETVAL(-ENXIO);
  67611. + }
  67612. +
  67613. + /*
  67614. + * Remove the device attributes
  67615. + */
  67616. + dwc_otg_attr_remove(_dev);
  67617. +
  67618. + /*
  67619. + * Return the memory.
  67620. + */
  67621. + if (otg_dev->os_dep.base) {
  67622. + iounmap(otg_dev->os_dep.base);
  67623. + }
  67624. + DWC_FREE(otg_dev);
  67625. +
  67626. + /*
  67627. + * Clear the drvdata pointer.
  67628. + */
  67629. +#ifdef LM_INTERFACE
  67630. + lm_set_drvdata(_dev, 0);
  67631. +#elif defined(PCI_INTERFACE)
  67632. + release_mem_region(otg_dev->os_dep.rsrc_start,
  67633. + otg_dev->os_dep.rsrc_len);
  67634. + pci_set_drvdata(_dev, 0);
  67635. +#elif defined(PLATFORM_INTERFACE)
  67636. + platform_set_drvdata(_dev, 0);
  67637. +#endif
  67638. + return REM_RETVAL(0);
  67639. +}
  67640. +
  67641. +/**
  67642. + * This function is called when an lm_device is bound to a
  67643. + * dwc_otg_driver. It creates the driver components required to
  67644. + * control the device (CIL, HCD, and PCD) and it initializes the
  67645. + * device. The driver components are stored in a dwc_otg_device
  67646. + * structure. A reference to the dwc_otg_device is saved in the
  67647. + * lm_device. This allows the driver to access the dwc_otg_device
  67648. + * structure on subsequent calls to driver methods for this device.
  67649. + *
  67650. + * @param _dev Bus device
  67651. + */
  67652. +static int dwc_otg_driver_probe(
  67653. +#ifdef LM_INTERFACE
  67654. + struct lm_device *_dev
  67655. +#elif defined(PCI_INTERFACE)
  67656. + struct pci_dev *_dev,
  67657. + const struct pci_device_id *id
  67658. +#elif defined(PLATFORM_INTERFACE)
  67659. + struct platform_device *_dev
  67660. +#endif
  67661. + )
  67662. +{
  67663. + int retval = 0;
  67664. + dwc_otg_device_t *dwc_otg_device;
  67665. + int devirq;
  67666. +
  67667. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  67668. +#ifdef LM_INTERFACE
  67669. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  67670. +#elif defined(PCI_INTERFACE)
  67671. + if (!id) {
  67672. + DWC_ERROR("Invalid pci_device_id %p", id);
  67673. + return -EINVAL;
  67674. + }
  67675. +
  67676. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  67677. + DWC_ERROR("Invalid pci_device %p", _dev);
  67678. + return -ENODEV;
  67679. + }
  67680. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  67681. + /* other stuff needed as well? */
  67682. +
  67683. +#elif defined(PLATFORM_INTERFACE)
  67684. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  67685. + (unsigned)_dev->resource->start,
  67686. + (unsigned)(_dev->resource->end - _dev->resource->start));
  67687. +#endif
  67688. +
  67689. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  67690. +
  67691. + if (!dwc_otg_device) {
  67692. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  67693. + return -ENOMEM;
  67694. + }
  67695. +
  67696. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  67697. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  67698. +
  67699. + /*
  67700. + * Map the DWC_otg Core memory into virtual address space.
  67701. + */
  67702. +#ifdef LM_INTERFACE
  67703. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  67704. +
  67705. + if (!dwc_otg_device->os_dep.base) {
  67706. + dev_err(&_dev->dev, "ioremap() failed\n");
  67707. + DWC_FREE(dwc_otg_device);
  67708. + return -ENOMEM;
  67709. + }
  67710. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67711. + (unsigned)dwc_otg_device->os_dep.base);
  67712. +#elif defined(PCI_INTERFACE)
  67713. + _dev->current_state = PCI_D0;
  67714. + _dev->dev.power.power_state = PMSG_ON;
  67715. +
  67716. + if (!_dev->irq) {
  67717. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  67718. + pci_name(_dev));
  67719. + iounmap(dwc_otg_device->os_dep.base);
  67720. + DWC_FREE(dwc_otg_device);
  67721. + return -ENODEV;
  67722. + }
  67723. +
  67724. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  67725. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  67726. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  67727. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67728. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  67729. + if (!request_mem_region
  67730. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  67731. + "dwc_otg")) {
  67732. + dev_dbg(&_dev->dev, "error requesting memory\n");
  67733. + iounmap(dwc_otg_device->os_dep.base);
  67734. + DWC_FREE(dwc_otg_device);
  67735. + return -EFAULT;
  67736. + }
  67737. +
  67738. + dwc_otg_device->os_dep.base =
  67739. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  67740. + dwc_otg_device->os_dep.rsrc_len);
  67741. + if (dwc_otg_device->os_dep.base == NULL) {
  67742. + dev_dbg(&_dev->dev, "error mapping memory\n");
  67743. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  67744. + dwc_otg_device->os_dep.rsrc_len);
  67745. + iounmap(dwc_otg_device->os_dep.base);
  67746. + DWC_FREE(dwc_otg_device);
  67747. + return -EFAULT;
  67748. + }
  67749. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  67750. + dwc_otg_device->os_dep.base);
  67751. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  67752. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  67753. + dwc_otg_device->os_dep.base);
  67754. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  67755. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67756. + dwc_otg_device->os_dep.base);
  67757. +
  67758. + pci_set_master(_dev);
  67759. + pci_set_drvdata(_dev, dwc_otg_device);
  67760. +#elif defined(PLATFORM_INTERFACE)
  67761. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  67762. + _dev->resource->start,
  67763. + _dev->resource->end - _dev->resource->start + 1);
  67764. +#if 1
  67765. + if (!request_mem_region(_dev->resource[0].start,
  67766. + _dev->resource[0].end - _dev->resource[0].start + 1,
  67767. + "dwc_otg")) {
  67768. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67769. + retval = -EFAULT;
  67770. + goto fail;
  67771. + }
  67772. +
  67773. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  67774. + _dev->resource[0].end -
  67775. + _dev->resource[0].start+1);
  67776. + if (fiq_fix_enable)
  67777. + {
  67778. + if (!request_mem_region(_dev->resource[1].start,
  67779. + _dev->resource[1].end - _dev->resource[1].start + 1,
  67780. + "dwc_otg")) {
  67781. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67782. + retval = -EFAULT;
  67783. + goto fail;
  67784. + }
  67785. +
  67786. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  67787. + _dev->resource[1].end -
  67788. + _dev->resource[1].start + 1);
  67789. + dummy_send = (void *) kmalloc(16, GFP_ATOMIC);
  67790. + }
  67791. +
  67792. +#else
  67793. + {
  67794. + struct map_desc desc = {
  67795. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  67796. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  67797. + .length = SZ_128K,
  67798. + .type = MT_DEVICE
  67799. + };
  67800. + iotable_init(&desc, 1);
  67801. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  67802. + }
  67803. +#endif
  67804. + if (!dwc_otg_device->os_dep.base) {
  67805. + dev_err(&_dev->dev, "ioremap() failed\n");
  67806. + retval = -ENOMEM;
  67807. + goto fail;
  67808. + }
  67809. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67810. + (unsigned)dwc_otg_device->os_dep.base);
  67811. +#endif
  67812. +
  67813. + /*
  67814. + * Initialize driver data to point to the global DWC_otg
  67815. + * Device structure.
  67816. + */
  67817. +#ifdef LM_INTERFACE
  67818. + lm_set_drvdata(_dev, dwc_otg_device);
  67819. +#elif defined(PLATFORM_INTERFACE)
  67820. + platform_set_drvdata(_dev, dwc_otg_device);
  67821. +#endif
  67822. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  67823. +
  67824. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  67825. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  67826. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  67827. +
  67828. + if (!dwc_otg_device->core_if) {
  67829. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  67830. + retval = -ENOMEM;
  67831. + goto fail;
  67832. + }
  67833. +
  67834. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  67835. + /*
  67836. + * Attempt to ensure this device is really a DWC_otg Controller.
  67837. + * Read and verify the SNPSID register contents. The value should be
  67838. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  67839. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  67840. + */
  67841. +
  67842. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  67843. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  67844. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  67845. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  67846. + retval = -EINVAL;
  67847. + goto fail;
  67848. + }
  67849. +
  67850. + /*
  67851. + * Validate parameter values.
  67852. + */
  67853. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  67854. + if (set_parameters(dwc_otg_device->core_if)) {
  67855. + retval = -EINVAL;
  67856. + goto fail;
  67857. + }
  67858. +
  67859. + /*
  67860. + * Create Device Attributes in sysfs
  67861. + */
  67862. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  67863. + dwc_otg_attr_create(_dev);
  67864. +
  67865. + /*
  67866. + * Disable the global interrupt until all the interrupt
  67867. + * handlers are installed.
  67868. + */
  67869. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  67870. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  67871. +
  67872. + /*
  67873. + * Install the interrupt handler for the common interrupts before
  67874. + * enabling common interrupts in core_init below.
  67875. + */
  67876. +
  67877. +#if defined(PLATFORM_INTERFACE)
  67878. + devirq = platform_get_irq(_dev, 0);
  67879. +#else
  67880. + devirq = _dev->irq;
  67881. +#endif
  67882. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  67883. + devirq);
  67884. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  67885. + retval = request_irq(devirq, dwc_otg_common_irq,
  67886. + IRQF_SHARED,
  67887. + "dwc_otg", dwc_otg_device);
  67888. + if (retval) {
  67889. + DWC_ERROR("request of irq%d failed\n", devirq);
  67890. + retval = -EBUSY;
  67891. + goto fail;
  67892. + } else {
  67893. + dwc_otg_device->common_irq_installed = 1;
  67894. + }
  67895. +
  67896. +#ifndef IRQF_TRIGGER_LOW
  67897. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  67898. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  67899. + set_irq_type(devirq,
  67900. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  67901. + IRQT_LOW
  67902. +#else
  67903. + IRQ_TYPE_LEVEL_LOW
  67904. +#endif
  67905. + );
  67906. +#endif
  67907. +#endif /*IRQF_TRIGGER_LOW*/
  67908. +
  67909. + /*
  67910. + * Initialize the DWC_otg core.
  67911. + */
  67912. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  67913. + dwc_otg_core_init(dwc_otg_device->core_if);
  67914. +
  67915. +#ifndef DWC_HOST_ONLY
  67916. + /*
  67917. + * Initialize the PCD
  67918. + */
  67919. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  67920. + retval = pcd_init(_dev);
  67921. + if (retval != 0) {
  67922. + DWC_ERROR("pcd_init failed\n");
  67923. + dwc_otg_device->pcd = NULL;
  67924. + goto fail;
  67925. + }
  67926. +#endif
  67927. +#ifndef DWC_DEVICE_ONLY
  67928. + /*
  67929. + * Initialize the HCD
  67930. + */
  67931. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  67932. + retval = hcd_init(_dev);
  67933. + if (retval != 0) {
  67934. + DWC_ERROR("hcd_init failed\n");
  67935. + dwc_otg_device->hcd = NULL;
  67936. + goto fail;
  67937. + }
  67938. +#endif
  67939. + /* Recover from drvdata having been overwritten by hcd_init() */
  67940. +#ifdef LM_INTERFACE
  67941. + lm_set_drvdata(_dev, dwc_otg_device);
  67942. +#elif defined(PLATFORM_INTERFACE)
  67943. + platform_set_drvdata(_dev, dwc_otg_device);
  67944. +#elif defined(PCI_INTERFACE)
  67945. + pci_set_drvdata(_dev, dwc_otg_device);
  67946. + dwc_otg_device->os_dep.pcidev = _dev;
  67947. +#endif
  67948. +
  67949. + /*
  67950. + * Enable the global interrupt after all the interrupt
  67951. + * handlers are installed if there is no ADP support else
  67952. + * perform initial actions required for Internal ADP logic.
  67953. + */
  67954. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  67955. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  67956. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  67957. + dev_dbg(&_dev->dev, "Done\n");
  67958. + } else
  67959. + dwc_otg_adp_start(dwc_otg_device->core_if,
  67960. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  67961. +
  67962. + return 0;
  67963. +
  67964. +fail:
  67965. + dwc_otg_driver_remove(_dev);
  67966. + return retval;
  67967. +}
  67968. +
  67969. +/**
  67970. + * This structure defines the methods to be called by a bus driver
  67971. + * during the lifecycle of a device on that bus. Both drivers and
  67972. + * devices are registered with a bus driver. The bus driver matches
  67973. + * devices to drivers based on information in the device and driver
  67974. + * structures.
  67975. + *
  67976. + * The probe function is called when the bus driver matches a device
  67977. + * to this driver. The remove function is called when a device is
  67978. + * unregistered with the bus driver.
  67979. + */
  67980. +#ifdef LM_INTERFACE
  67981. +static struct lm_driver dwc_otg_driver = {
  67982. + .drv = {.name = (char *)dwc_driver_name,},
  67983. + .probe = dwc_otg_driver_probe,
  67984. + .remove = dwc_otg_driver_remove,
  67985. + // 'suspend' and 'resume' absent
  67986. +};
  67987. +#elif defined(PCI_INTERFACE)
  67988. +static const struct pci_device_id pci_ids[] = { {
  67989. + PCI_DEVICE(0x16c3, 0xabcd),
  67990. + .driver_data =
  67991. + (unsigned long)0xdeadbeef,
  67992. + }, { /* end: all zeroes */ }
  67993. +};
  67994. +
  67995. +MODULE_DEVICE_TABLE(pci, pci_ids);
  67996. +
  67997. +/* pci driver glue; this is a "new style" PCI driver module */
  67998. +static struct pci_driver dwc_otg_driver = {
  67999. + .name = "dwc_otg",
  68000. + .id_table = pci_ids,
  68001. +
  68002. + .probe = dwc_otg_driver_probe,
  68003. + .remove = dwc_otg_driver_remove,
  68004. +
  68005. + .driver = {
  68006. + .name = (char *)dwc_driver_name,
  68007. + },
  68008. +};
  68009. +#elif defined(PLATFORM_INTERFACE)
  68010. +static struct platform_device_id platform_ids[] = {
  68011. + {
  68012. + .name = "bcm2708_usb",
  68013. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  68014. + },
  68015. + { /* end: all zeroes */ }
  68016. +};
  68017. +MODULE_DEVICE_TABLE(platform, platform_ids);
  68018. +
  68019. +static struct platform_driver dwc_otg_driver = {
  68020. + .driver = {
  68021. + .name = (char *)dwc_driver_name,
  68022. + },
  68023. + .id_table = platform_ids,
  68024. +
  68025. + .probe = dwc_otg_driver_probe,
  68026. + .remove = dwc_otg_driver_remove,
  68027. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  68028. +};
  68029. +#endif
  68030. +
  68031. +/**
  68032. + * This function is called when the dwc_otg_driver is installed with the
  68033. + * insmod command. It registers the dwc_otg_driver structure with the
  68034. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  68035. + * to be called. In addition, the bus driver will automatically expose
  68036. + * attributes defined for the device and driver in the special sysfs file
  68037. + * system.
  68038. + *
  68039. + * @return
  68040. + */
  68041. +static int __init dwc_otg_driver_init(void)
  68042. +{
  68043. + int retval = 0;
  68044. + int error;
  68045. + struct device_driver *drv;
  68046. +
  68047. + if(fiq_split_enable && !fiq_fix_enable) {
  68048. + printk(KERN_WARNING "dwc_otg: fiq_split_enable was set without fiq_fix_enable! Correcting.\n");
  68049. + fiq_fix_enable = 1;
  68050. + }
  68051. +
  68052. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  68053. + DWC_DRIVER_VERSION,
  68054. +#ifdef LM_INTERFACE
  68055. + "logicmodule");
  68056. + retval = lm_driver_register(&dwc_otg_driver);
  68057. + drv = &dwc_otg_driver.drv;
  68058. +#elif defined(PCI_INTERFACE)
  68059. + "pci");
  68060. + retval = pci_register_driver(&dwc_otg_driver);
  68061. + drv = &dwc_otg_driver.driver;
  68062. +#elif defined(PLATFORM_INTERFACE)
  68063. + "platform");
  68064. + retval = platform_driver_register(&dwc_otg_driver);
  68065. + drv = &dwc_otg_driver.driver;
  68066. +#endif
  68067. + if (retval < 0) {
  68068. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  68069. + return retval;
  68070. + }
  68071. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
  68072. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
  68073. + printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
  68074. +
  68075. + error = driver_create_file(drv, &driver_attr_version);
  68076. +#ifdef DEBUG
  68077. + error = driver_create_file(drv, &driver_attr_debuglevel);
  68078. +#endif
  68079. + return retval;
  68080. +}
  68081. +
  68082. +module_init(dwc_otg_driver_init);
  68083. +
  68084. +/**
  68085. + * This function is called when the driver is removed from the kernel
  68086. + * with the rmmod command. The driver unregisters itself with its bus
  68087. + * driver.
  68088. + *
  68089. + */
  68090. +static void __exit dwc_otg_driver_cleanup(void)
  68091. +{
  68092. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  68093. +
  68094. +#ifdef LM_INTERFACE
  68095. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  68096. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  68097. + lm_driver_unregister(&dwc_otg_driver);
  68098. +#elif defined(PCI_INTERFACE)
  68099. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68100. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68101. + pci_unregister_driver(&dwc_otg_driver);
  68102. +#elif defined(PLATFORM_INTERFACE)
  68103. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68104. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68105. + platform_driver_unregister(&dwc_otg_driver);
  68106. +#endif
  68107. +
  68108. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  68109. +}
  68110. +
  68111. +module_exit(dwc_otg_driver_cleanup);
  68112. +
  68113. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  68114. +MODULE_AUTHOR("Synopsys Inc.");
  68115. +MODULE_LICENSE("GPL");
  68116. +
  68117. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  68118. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  68119. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  68120. +MODULE_PARM_DESC(opt, "OPT Mode");
  68121. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  68122. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  68123. +
  68124. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  68125. + 0444);
  68126. +MODULE_PARM_DESC(dma_desc_enable,
  68127. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  68128. +
  68129. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  68130. + 0444);
  68131. +MODULE_PARM_DESC(dma_burst_size,
  68132. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  68133. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  68134. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  68135. +module_param_named(host_support_fs_ls_low_power,
  68136. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  68137. + 0444);
  68138. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  68139. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  68140. +module_param_named(host_ls_low_power_phy_clk,
  68141. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  68142. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  68143. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  68144. +module_param_named(enable_dynamic_fifo,
  68145. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  68146. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  68147. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  68148. + 0444);
  68149. +MODULE_PARM_DESC(data_fifo_size,
  68150. + "Total number of words in the data FIFO memory 32-32768");
  68151. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  68152. + int, 0444);
  68153. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68154. +module_param_named(dev_nperio_tx_fifo_size,
  68155. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  68156. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  68157. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68158. +module_param_named(dev_perio_tx_fifo_size_1,
  68159. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  68160. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  68161. + "Number of words in the periodic Tx FIFO 4-768");
  68162. +module_param_named(dev_perio_tx_fifo_size_2,
  68163. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  68164. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  68165. + "Number of words in the periodic Tx FIFO 4-768");
  68166. +module_param_named(dev_perio_tx_fifo_size_3,
  68167. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  68168. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  68169. + "Number of words in the periodic Tx FIFO 4-768");
  68170. +module_param_named(dev_perio_tx_fifo_size_4,
  68171. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  68172. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  68173. + "Number of words in the periodic Tx FIFO 4-768");
  68174. +module_param_named(dev_perio_tx_fifo_size_5,
  68175. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  68176. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  68177. + "Number of words in the periodic Tx FIFO 4-768");
  68178. +module_param_named(dev_perio_tx_fifo_size_6,
  68179. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  68180. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  68181. + "Number of words in the periodic Tx FIFO 4-768");
  68182. +module_param_named(dev_perio_tx_fifo_size_7,
  68183. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  68184. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  68185. + "Number of words in the periodic Tx FIFO 4-768");
  68186. +module_param_named(dev_perio_tx_fifo_size_8,
  68187. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  68188. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  68189. + "Number of words in the periodic Tx FIFO 4-768");
  68190. +module_param_named(dev_perio_tx_fifo_size_9,
  68191. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  68192. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  68193. + "Number of words in the periodic Tx FIFO 4-768");
  68194. +module_param_named(dev_perio_tx_fifo_size_10,
  68195. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  68196. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  68197. + "Number of words in the periodic Tx FIFO 4-768");
  68198. +module_param_named(dev_perio_tx_fifo_size_11,
  68199. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  68200. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  68201. + "Number of words in the periodic Tx FIFO 4-768");
  68202. +module_param_named(dev_perio_tx_fifo_size_12,
  68203. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  68204. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  68205. + "Number of words in the periodic Tx FIFO 4-768");
  68206. +module_param_named(dev_perio_tx_fifo_size_13,
  68207. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  68208. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  68209. + "Number of words in the periodic Tx FIFO 4-768");
  68210. +module_param_named(dev_perio_tx_fifo_size_14,
  68211. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  68212. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  68213. + "Number of words in the periodic Tx FIFO 4-768");
  68214. +module_param_named(dev_perio_tx_fifo_size_15,
  68215. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  68216. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  68217. + "Number of words in the periodic Tx FIFO 4-768");
  68218. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  68219. + int, 0444);
  68220. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68221. +module_param_named(host_nperio_tx_fifo_size,
  68222. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  68223. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  68224. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68225. +module_param_named(host_perio_tx_fifo_size,
  68226. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  68227. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  68228. + "Number of words in the host periodic Tx FIFO 16-32768");
  68229. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  68230. + int, 0444);
  68231. +/** @todo Set the max to 512K, modify checks */
  68232. +MODULE_PARM_DESC(max_transfer_size,
  68233. + "The maximum transfer size supported in bytes 2047-65535");
  68234. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  68235. + int, 0444);
  68236. +MODULE_PARM_DESC(max_packet_count,
  68237. + "The maximum number of packets in a transfer 15-511");
  68238. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  68239. + 0444);
  68240. +MODULE_PARM_DESC(host_channels,
  68241. + "The number of host channel registers to use 1-16");
  68242. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  68243. + 0444);
  68244. +MODULE_PARM_DESC(dev_endpoints,
  68245. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  68246. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  68247. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  68248. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  68249. + 0444);
  68250. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  68251. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  68252. +MODULE_PARM_DESC(phy_ulpi_ddr,
  68253. + "ULPI at double or single data rate 0=Single 1=Double");
  68254. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  68255. + int, 0444);
  68256. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  68257. + "ULPI PHY using internal or external vbus 0=Internal");
  68258. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  68259. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  68260. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  68261. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  68262. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  68263. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  68264. +module_param_named(debug, g_dbg_lvl, int, 0444);
  68265. +MODULE_PARM_DESC(debug, "");
  68266. +
  68267. +module_param_named(en_multiple_tx_fifo,
  68268. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  68269. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  68270. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  68271. +module_param_named(dev_tx_fifo_size_1,
  68272. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  68273. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  68274. +module_param_named(dev_tx_fifo_size_2,
  68275. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  68276. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  68277. +module_param_named(dev_tx_fifo_size_3,
  68278. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  68279. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  68280. +module_param_named(dev_tx_fifo_size_4,
  68281. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  68282. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  68283. +module_param_named(dev_tx_fifo_size_5,
  68284. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  68285. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  68286. +module_param_named(dev_tx_fifo_size_6,
  68287. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  68288. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  68289. +module_param_named(dev_tx_fifo_size_7,
  68290. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  68291. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  68292. +module_param_named(dev_tx_fifo_size_8,
  68293. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  68294. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  68295. +module_param_named(dev_tx_fifo_size_9,
  68296. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  68297. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  68298. +module_param_named(dev_tx_fifo_size_10,
  68299. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  68300. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  68301. +module_param_named(dev_tx_fifo_size_11,
  68302. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  68303. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  68304. +module_param_named(dev_tx_fifo_size_12,
  68305. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  68306. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  68307. +module_param_named(dev_tx_fifo_size_13,
  68308. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  68309. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  68310. +module_param_named(dev_tx_fifo_size_14,
  68311. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  68312. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  68313. +module_param_named(dev_tx_fifo_size_15,
  68314. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  68315. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  68316. +
  68317. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  68318. +MODULE_PARM_DESC(thr_ctl,
  68319. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  68320. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  68321. + 0444);
  68322. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  68323. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  68324. + 0444);
  68325. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  68326. +
  68327. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  68328. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  68329. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  68330. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  68331. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  68332. +MODULE_PARM_DESC(ic_usb_cap,
  68333. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  68334. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  68335. + 0444);
  68336. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  68337. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  68338. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  68339. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  68340. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  68341. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  68342. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  68343. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  68344. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  68345. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  68346. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  68347. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  68348. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  68349. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  68350. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  68351. +module_param(microframe_schedule, bool, 0444);
  68352. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  68353. +
  68354. +module_param(fiq_fix_enable, bool, 0444);
  68355. +MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
  68356. +module_param(nak_holdoff_enable, bool, 0444);
  68357. +MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
  68358. +module_param(fiq_split_enable, bool, 0444);
  68359. +MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
  68360. +
  68361. +/** @page "Module Parameters"
  68362. + *
  68363. + * The following parameters may be specified when starting the module.
  68364. + * These parameters define how the DWC_otg controller should be
  68365. + * configured. Parameter values are passed to the CIL initialization
  68366. + * function dwc_otg_cil_init
  68367. + *
  68368. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  68369. + *
  68370. +
  68371. + <table>
  68372. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  68373. +
  68374. + <tr>
  68375. + <td>otg_cap</td>
  68376. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  68377. + value for this parameter if none is specified.
  68378. + - 0: HNP and SRP capable (default, if available)
  68379. + - 1: SRP Only capable
  68380. + - 2: No HNP/SRP capable
  68381. + </td></tr>
  68382. +
  68383. + <tr>
  68384. + <td>dma_enable</td>
  68385. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  68386. + The driver will automatically detect the value for this parameter if none is
  68387. + specified.
  68388. + - 0: Slave
  68389. + - 1: DMA (default, if available)
  68390. + </td></tr>
  68391. +
  68392. + <tr>
  68393. + <td>dma_burst_size</td>
  68394. + <td>The DMA Burst size (applicable only for External DMA Mode).
  68395. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  68396. + </td></tr>
  68397. +
  68398. + <tr>
  68399. + <td>speed</td>
  68400. + <td>Specifies the maximum speed of operation in host and device mode. The
  68401. + actual speed depends on the speed of the attached device and the value of
  68402. + phy_type.
  68403. + - 0: High Speed (default)
  68404. + - 1: Full Speed
  68405. + </td></tr>
  68406. +
  68407. + <tr>
  68408. + <td>host_support_fs_ls_low_power</td>
  68409. + <td>Specifies whether low power mode is supported when attached to a Full
  68410. + Speed or Low Speed device in host mode.
  68411. + - 0: Don't support low power mode (default)
  68412. + - 1: Support low power mode
  68413. + </td></tr>
  68414. +
  68415. + <tr>
  68416. + <td>host_ls_low_power_phy_clk</td>
  68417. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  68418. + Speed device in host mode. This parameter is applicable only if
  68419. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  68420. + - 0: 48 MHz (default)
  68421. + - 1: 6 MHz
  68422. + </td></tr>
  68423. +
  68424. + <tr>
  68425. + <td>enable_dynamic_fifo</td>
  68426. + <td> Specifies whether FIFOs may be resized by the driver software.
  68427. + - 0: Use cC FIFO size parameters
  68428. + - 1: Allow dynamic FIFO sizing (default)
  68429. + </td></tr>
  68430. +
  68431. + <tr>
  68432. + <td>data_fifo_size</td>
  68433. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  68434. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  68435. + - Values: 32 to 32768 (default 8192)
  68436. +
  68437. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  68438. + </td></tr>
  68439. +
  68440. + <tr>
  68441. + <td>dev_rx_fifo_size</td>
  68442. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  68443. + FIFO sizing is enabled.
  68444. + - Values: 16 to 32768 (default 1064)
  68445. + </td></tr>
  68446. +
  68447. + <tr>
  68448. + <td>dev_nperio_tx_fifo_size</td>
  68449. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  68450. + dynamic FIFO sizing is enabled.
  68451. + - Values: 16 to 32768 (default 1024)
  68452. + </td></tr>
  68453. +
  68454. + <tr>
  68455. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  68456. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  68457. + when dynamic FIFO sizing is enabled.
  68458. + - Values: 4 to 768 (default 256)
  68459. + </td></tr>
  68460. +
  68461. + <tr>
  68462. + <td>host_rx_fifo_size</td>
  68463. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  68464. + sizing is enabled.
  68465. + - Values: 16 to 32768 (default 1024)
  68466. + </td></tr>
  68467. +
  68468. + <tr>
  68469. + <td>host_nperio_tx_fifo_size</td>
  68470. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  68471. + dynamic FIFO sizing is enabled in the core.
  68472. + - Values: 16 to 32768 (default 1024)
  68473. + </td></tr>
  68474. +
  68475. + <tr>
  68476. + <td>host_perio_tx_fifo_size</td>
  68477. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  68478. + sizing is enabled.
  68479. + - Values: 16 to 32768 (default 1024)
  68480. + </td></tr>
  68481. +
  68482. + <tr>
  68483. + <td>max_transfer_size</td>
  68484. + <td>The maximum transfer size supported in bytes.
  68485. + - Values: 2047 to 65,535 (default 65,535)
  68486. + </td></tr>
  68487. +
  68488. + <tr>
  68489. + <td>max_packet_count</td>
  68490. + <td>The maximum number of packets in a transfer.
  68491. + - Values: 15 to 511 (default 511)
  68492. + </td></tr>
  68493. +
  68494. + <tr>
  68495. + <td>host_channels</td>
  68496. + <td>The number of host channel registers to use.
  68497. + - Values: 1 to 16 (default 12)
  68498. +
  68499. + Note: The FPGA configuration supports a maximum of 12 host channels.
  68500. + </td></tr>
  68501. +
  68502. + <tr>
  68503. + <td>dev_endpoints</td>
  68504. + <td>The number of endpoints in addition to EP0 available for device mode
  68505. + operations.
  68506. + - Values: 1 to 15 (default 6 IN and OUT)
  68507. +
  68508. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  68509. + addition to EP0.
  68510. + </td></tr>
  68511. +
  68512. + <tr>
  68513. + <td>phy_type</td>
  68514. + <td>Specifies the type of PHY interface to use. By default, the driver will
  68515. + automatically detect the phy_type.
  68516. + - 0: Full Speed
  68517. + - 1: UTMI+ (default, if available)
  68518. + - 2: ULPI
  68519. + </td></tr>
  68520. +
  68521. + <tr>
  68522. + <td>phy_utmi_width</td>
  68523. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  68524. + phy_type of UTMI+. Also, this parameter is applicable only if the
  68525. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  68526. + core has been configured to work at either data path width.
  68527. + - Values: 8 or 16 bits (default 16)
  68528. + </td></tr>
  68529. +
  68530. + <tr>
  68531. + <td>phy_ulpi_ddr</td>
  68532. + <td>Specifies whether the ULPI operates at double or single data rate. This
  68533. + parameter is only applicable if phy_type is ULPI.
  68534. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  68535. + - 1: double data rate ULPI interface with 4 bit wide data bus
  68536. + </td></tr>
  68537. +
  68538. + <tr>
  68539. + <td>i2c_enable</td>
  68540. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  68541. + parameter is only applicable if PHY_TYPE is FS.
  68542. + - 0: Disabled (default)
  68543. + - 1: Enabled
  68544. + </td></tr>
  68545. +
  68546. + <tr>
  68547. + <td>ulpi_fs_ls</td>
  68548. + <td>Specifies whether to use ULPI FS/LS mode only.
  68549. + - 0: Disabled (default)
  68550. + - 1: Enabled
  68551. + </td></tr>
  68552. +
  68553. + <tr>
  68554. + <td>ts_dline</td>
  68555. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  68556. + - 0: Disabled (default)
  68557. + - 1: Enabled
  68558. + </td></tr>
  68559. +
  68560. + <tr>
  68561. + <td>en_multiple_tx_fifo</td>
  68562. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  68563. + The driver will automatically detect the value for this parameter if none is
  68564. + specified.
  68565. + - 0: Disabled
  68566. + - 1: Enabled (default, if available)
  68567. + </td></tr>
  68568. +
  68569. + <tr>
  68570. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  68571. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  68572. + when dynamic FIFO sizing is enabled.
  68573. + - Values: 4 to 768 (default 256)
  68574. + </td></tr>
  68575. +
  68576. + <tr>
  68577. + <td>tx_thr_length</td>
  68578. + <td>Transmit Threshold length in 32 bit double words
  68579. + - Values: 8 to 128 (default 64)
  68580. + </td></tr>
  68581. +
  68582. + <tr>
  68583. + <td>rx_thr_length</td>
  68584. + <td>Receive Threshold length in 32 bit double words
  68585. + - Values: 8 to 128 (default 64)
  68586. + </td></tr>
  68587. +
  68588. +<tr>
  68589. + <td>thr_ctl</td>
  68590. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  68591. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  68592. + Rx transfers accordingly.
  68593. + The driver will automatically detect the value for this parameter if none is
  68594. + specified.
  68595. + - Values: 0 to 7 (default 0)
  68596. + Bit values indicate:
  68597. + - 0: Thresholding disabled
  68598. + - 1: Thresholding enabled
  68599. + </td></tr>
  68600. +
  68601. +<tr>
  68602. + <td>dma_desc_enable</td>
  68603. + <td>Specifies whether to enable Descriptor DMA mode.
  68604. + The driver will automatically detect the value for this parameter if none is
  68605. + specified.
  68606. + - 0: Descriptor DMA disabled
  68607. + - 1: Descriptor DMA (default, if available)
  68608. + </td></tr>
  68609. +
  68610. +<tr>
  68611. + <td>mpi_enable</td>
  68612. + <td>Specifies whether to enable MPI enhancement mode.
  68613. + The driver will automatically detect the value for this parameter if none is
  68614. + specified.
  68615. + - 0: MPI disabled (default)
  68616. + - 1: MPI enable
  68617. + </td></tr>
  68618. +
  68619. +<tr>
  68620. + <td>pti_enable</td>
  68621. + <td>Specifies whether to enable PTI enhancement support.
  68622. + The driver will automatically detect the value for this parameter if none is
  68623. + specified.
  68624. + - 0: PTI disabled (default)
  68625. + - 1: PTI enable
  68626. + </td></tr>
  68627. +
  68628. +<tr>
  68629. + <td>lpm_enable</td>
  68630. + <td>Specifies whether to enable LPM support.
  68631. + The driver will automatically detect the value for this parameter if none is
  68632. + specified.
  68633. + - 0: LPM disabled
  68634. + - 1: LPM enable (default, if available)
  68635. + </td></tr>
  68636. +
  68637. +<tr>
  68638. + <td>ic_usb_cap</td>
  68639. + <td>Specifies whether to enable IC_USB capability.
  68640. + The driver will automatically detect the value for this parameter if none is
  68641. + specified.
  68642. + - 0: IC_USB disabled (default, if available)
  68643. + - 1: IC_USB enable
  68644. + </td></tr>
  68645. +
  68646. +<tr>
  68647. + <td>ahb_thr_ratio</td>
  68648. + <td>Specifies AHB Threshold ratio.
  68649. + - Values: 0 to 3 (default 0)
  68650. + </td></tr>
  68651. +
  68652. +<tr>
  68653. + <td>power_down</td>
  68654. + <td>Specifies Power Down(Hibernation) Mode.
  68655. + The driver will automatically detect the value for this parameter if none is
  68656. + specified.
  68657. + - 0: Power Down disabled (default)
  68658. + - 2: Power Down enabled
  68659. + </td></tr>
  68660. +
  68661. + <tr>
  68662. + <td>reload_ctl</td>
  68663. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  68664. + run time. The driver will automatically detect the value for this parameter if
  68665. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  68666. + the core might misbehave.
  68667. + - 0: Reload Control disabled (default)
  68668. + - 1: Reload Control enabled
  68669. + </td></tr>
  68670. +
  68671. + <tr>
  68672. + <td>dev_out_nak</td>
  68673. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  68674. + The driver will automatically detect the value for this parameter if
  68675. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68676. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  68677. + - 1: The core sets NAK after Bulk OUT transfer complete
  68678. + </td></tr>
  68679. +
  68680. + <tr>
  68681. + <td>cont_on_bna</td>
  68682. + <td>Specifies whether Enable Continue on BNA enabled or no.
  68683. + After receiving BNA interrupt the core disables the endpoint,when the
  68684. + endpoint is re-enabled by the application the
  68685. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  68686. + - 1: Core starts processing from the descriptor which received the BNA.
  68687. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68688. + </td></tr>
  68689. +
  68690. + <tr>
  68691. + <td>ahb_single</td>
  68692. + <td>This bit when programmed supports SINGLE transfers for remainder data
  68693. + in a transfer for DMA mode of operation.
  68694. + - 0: The remainder data will be sent using INCR burst size (default)
  68695. + - 1: The remainder data will be sent using SINGLE burst size.
  68696. + </td></tr>
  68697. +
  68698. +<tr>
  68699. + <td>adp_enable</td>
  68700. + <td>Specifies whether ADP feature is enabled.
  68701. + The driver will automatically detect the value for this parameter if none is
  68702. + specified.
  68703. + - 0: ADP feature disabled (default)
  68704. + - 1: ADP feature enabled
  68705. + </td></tr>
  68706. +
  68707. + <tr>
  68708. + <td>otg_ver</td>
  68709. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  68710. + USB OTG device.
  68711. + - 0: OTG 2.0 support disabled (default)
  68712. + - 1: OTG 2.0 support enabled
  68713. + </td></tr>
  68714. +
  68715. +*/
  68716. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  68717. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  68718. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-03-13 12:46:39.516097989 +0100
  68719. @@ -0,0 +1,86 @@
  68720. +/* ==========================================================================
  68721. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  68722. + * $Revision: #19 $
  68723. + * $Date: 2010/11/15 $
  68724. + * $Change: 1627671 $
  68725. + *
  68726. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68727. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68728. + * otherwise expressly agreed to in writing between Synopsys and you.
  68729. + *
  68730. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68731. + * any End User Software License Agreement or Agreement for Licensed Product
  68732. + * with Synopsys or any supplement thereto. You are permitted to use and
  68733. + * redistribute this Software in source and binary forms, with or without
  68734. + * modification, provided that redistributions of source code must retain this
  68735. + * notice. You may not view, use, disclose, copy or distribute this file or
  68736. + * any information contained herein except pursuant to this license grant from
  68737. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68738. + * below, then you are not authorized to use the Software.
  68739. + *
  68740. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68741. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68742. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68743. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68744. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68745. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68746. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68747. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68748. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68749. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68750. + * DAMAGE.
  68751. + * ========================================================================== */
  68752. +
  68753. +#ifndef __DWC_OTG_DRIVER_H__
  68754. +#define __DWC_OTG_DRIVER_H__
  68755. +
  68756. +/** @file
  68757. + * This file contains the interface to the Linux driver.
  68758. + */
  68759. +#include "dwc_otg_os_dep.h"
  68760. +#include "dwc_otg_core_if.h"
  68761. +
  68762. +/* Type declarations */
  68763. +struct dwc_otg_pcd;
  68764. +struct dwc_otg_hcd;
  68765. +
  68766. +/**
  68767. + * This structure is a wrapper that encapsulates the driver components used to
  68768. + * manage a single DWC_otg controller.
  68769. + */
  68770. +typedef struct dwc_otg_device {
  68771. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  68772. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  68773. + * require this. */
  68774. + struct os_dependent os_dep;
  68775. +
  68776. + /** Pointer to the core interface structure. */
  68777. + dwc_otg_core_if_t *core_if;
  68778. +
  68779. + /** Pointer to the PCD structure. */
  68780. + struct dwc_otg_pcd *pcd;
  68781. +
  68782. + /** Pointer to the HCD structure. */
  68783. + struct dwc_otg_hcd *hcd;
  68784. +
  68785. + /** Flag to indicate whether the common IRQ handler is installed. */
  68786. + uint8_t common_irq_installed;
  68787. +
  68788. +} dwc_otg_device_t;
  68789. +
  68790. +/*We must clear S3C24XX_EINTPEND external interrupt register
  68791. + * because after clearing in this register trigerred IRQ from
  68792. + * H/W core in kernel interrupt can be occured again before OTG
  68793. + * handlers clear all IRQ sources of Core registers because of
  68794. + * timing latencies and Low Level IRQ Type.
  68795. + */
  68796. +#ifdef CONFIG_MACH_IPMATE
  68797. +#define S3C2410X_CLEAR_EINTPEND() \
  68798. +do { \
  68799. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  68800. +} while (0)
  68801. +#else
  68802. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  68803. +#endif
  68804. +
  68805. +#endif
  68806. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  68807. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  68808. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-03-13 12:46:39.516097989 +0100
  68809. @@ -0,0 +1,3685 @@
  68810. +
  68811. +/* ==========================================================================
  68812. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  68813. + * $Revision: #104 $
  68814. + * $Date: 2011/10/24 $
  68815. + * $Change: 1871159 $
  68816. + *
  68817. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68818. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68819. + * otherwise expressly agreed to in writing between Synopsys and you.
  68820. + *
  68821. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68822. + * any End User Software License Agreement or Agreement for Licensed Product
  68823. + * with Synopsys or any supplement thereto. You are permitted to use and
  68824. + * redistribute this Software in source and binary forms, with or without
  68825. + * modification, provided that redistributions of source code must retain this
  68826. + * notice. You may not view, use, disclose, copy or distribute this file or
  68827. + * any information contained herein except pursuant to this license grant from
  68828. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68829. + * below, then you are not authorized to use the Software.
  68830. + *
  68831. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68832. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68833. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68834. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68835. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68836. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68837. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68838. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68839. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68840. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68841. + * DAMAGE.
  68842. + * ========================================================================== */
  68843. +#ifndef DWC_DEVICE_ONLY
  68844. +
  68845. +/** @file
  68846. + * This file implements HCD Core. All code in this file is portable and doesn't
  68847. + * use any OS specific functions.
  68848. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  68849. + * header file.
  68850. + */
  68851. +
  68852. +#include <linux/usb.h>
  68853. +#include <linux/usb/hcd.h>
  68854. +
  68855. +#include "dwc_otg_hcd.h"
  68856. +#include "dwc_otg_regs.h"
  68857. +#include "dwc_otg_mphi_fix.h"
  68858. +
  68859. +extern bool microframe_schedule, nak_holdoff_enable;
  68860. +
  68861. +//#define DEBUG_HOST_CHANNELS
  68862. +#ifdef DEBUG_HOST_CHANNELS
  68863. +static int last_sel_trans_num_per_scheduled = 0;
  68864. +static int last_sel_trans_num_nonper_scheduled = 0;
  68865. +static int last_sel_trans_num_avail_hc_at_start = 0;
  68866. +static int last_sel_trans_num_avail_hc_at_end = 0;
  68867. +#endif /* DEBUG_HOST_CHANNELS */
  68868. +
  68869. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  68870. +
  68871. +extern haint_data_t haint_saved;
  68872. +extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  68873. +extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  68874. +extern gintsts_data_t ginsts_saved;
  68875. +
  68876. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  68877. +{
  68878. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  68879. +}
  68880. +
  68881. +/**
  68882. + * Connection timeout function. An OTG host is required to display a
  68883. + * message if the device does not connect within 10 seconds.
  68884. + */
  68885. +void dwc_otg_hcd_connect_timeout(void *ptr)
  68886. +{
  68887. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  68888. + DWC_PRINTF("Connect Timeout\n");
  68889. + __DWC_ERROR("Device Not Connected/Responding\n");
  68890. +}
  68891. +
  68892. +#if defined(DEBUG)
  68893. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  68894. +{
  68895. + if (qh->channel != NULL) {
  68896. + dwc_hc_t *hc = qh->channel;
  68897. + dwc_list_link_t *item;
  68898. + dwc_otg_qh_t *qh_item;
  68899. + int num_channels = hcd->core_if->core_params->host_channels;
  68900. + int i;
  68901. +
  68902. + dwc_otg_hc_regs_t *hc_regs;
  68903. + hcchar_data_t hcchar;
  68904. + hcsplt_data_t hcsplt;
  68905. + hctsiz_data_t hctsiz;
  68906. + uint32_t hcdma;
  68907. +
  68908. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  68909. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  68910. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  68911. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  68912. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  68913. +
  68914. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  68915. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  68916. + hcsplt.d32);
  68917. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  68918. + hcdma);
  68919. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  68920. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  68921. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  68922. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  68923. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  68924. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  68925. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  68926. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  68927. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  68928. + DWC_PRINTF(" qh: %p\n", hc->qh);
  68929. + DWC_PRINTF(" NP inactive sched:\n");
  68930. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  68931. + qh_item =
  68932. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68933. + DWC_PRINTF(" %p\n", qh_item);
  68934. + }
  68935. + DWC_PRINTF(" NP active sched:\n");
  68936. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  68937. + qh_item =
  68938. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68939. + DWC_PRINTF(" %p\n", qh_item);
  68940. + }
  68941. + DWC_PRINTF(" Channels: \n");
  68942. + for (i = 0; i < num_channels; i++) {
  68943. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  68944. + DWC_PRINTF(" %2d: %p\n", i, hc);
  68945. + }
  68946. + }
  68947. +}
  68948. +#else
  68949. +#define dump_channel_info(hcd, qh)
  68950. +#endif /* DEBUG */
  68951. +
  68952. +/**
  68953. + * Work queue function for starting the HCD when A-Cable is connected.
  68954. + * The hcd_start() must be called in a process context.
  68955. + */
  68956. +static void hcd_start_func(void *_vp)
  68957. +{
  68958. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  68959. +
  68960. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  68961. + if (hcd) {
  68962. + hcd->fops->start(hcd);
  68963. + }
  68964. +}
  68965. +
  68966. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  68967. +{
  68968. +#ifdef DEBUG
  68969. + int i;
  68970. + int num_channels = hcd->core_if->core_params->host_channels;
  68971. + for (i = 0; i < num_channels; i++) {
  68972. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  68973. + }
  68974. +#endif
  68975. +}
  68976. +
  68977. +static void del_timers(dwc_otg_hcd_t * hcd)
  68978. +{
  68979. + del_xfer_timers(hcd);
  68980. + DWC_TIMER_CANCEL(hcd->conn_timer);
  68981. +}
  68982. +
  68983. +/**
  68984. + * Processes all the URBs in a single list of QHs. Completes them with
  68985. + * -ESHUTDOWN and frees the QTD.
  68986. + */
  68987. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  68988. +{
  68989. + dwc_list_link_t *qh_item, *qh_tmp;
  68990. + dwc_otg_qh_t *qh;
  68991. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  68992. +
  68993. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  68994. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  68995. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  68996. + &qh->qtd_list, qtd_list_entry) {
  68997. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  68998. + if (qtd->urb != NULL) {
  68999. + hcd->fops->complete(hcd, qtd->urb->priv,
  69000. + qtd->urb, -DWC_E_SHUTDOWN);
  69001. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  69002. + }
  69003. +
  69004. + }
  69005. + if(qh->channel) {
  69006. + /* Using hcchar.chen == 1 is not a reliable test.
  69007. + * It is possible that the channel has already halted
  69008. + * but not yet been through the IRQ handler.
  69009. + */
  69010. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  69011. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  69012. + if(microframe_schedule)
  69013. + hcd->available_host_channels++;
  69014. + qh->channel = NULL;
  69015. + }
  69016. + dwc_otg_hcd_qh_remove(hcd, qh);
  69017. + }
  69018. +}
  69019. +
  69020. +/**
  69021. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  69022. + * and periodic schedules. The QTD associated with each URB is removed from
  69023. + * the schedule and freed. This function may be called when a disconnect is
  69024. + * detected or when the HCD is being stopped.
  69025. + */
  69026. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  69027. +{
  69028. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  69029. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  69030. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  69031. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  69032. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  69033. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  69034. +}
  69035. +
  69036. +/**
  69037. + * Start the connection timer. An OTG host is required to display a
  69038. + * message if the device does not connect within 10 seconds. The
  69039. + * timer is deleted if a port connect interrupt occurs before the
  69040. + * timer expires.
  69041. + */
  69042. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  69043. +{
  69044. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  69045. +}
  69046. +
  69047. +/**
  69048. + * HCD Callback function for disconnect of the HCD.
  69049. + *
  69050. + * @param p void pointer to the <code>struct usb_hcd</code>
  69051. + */
  69052. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  69053. +{
  69054. + dwc_otg_hcd_t *dwc_otg_hcd;
  69055. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  69056. + dwc_otg_hcd = p;
  69057. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  69058. + return 1;
  69059. +}
  69060. +
  69061. +/**
  69062. + * HCD Callback function for starting the HCD when A-Cable is
  69063. + * connected.
  69064. + *
  69065. + * @param p void pointer to the <code>struct usb_hcd</code>
  69066. + */
  69067. +static int32_t dwc_otg_hcd_start_cb(void *p)
  69068. +{
  69069. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69070. + dwc_otg_core_if_t *core_if;
  69071. + hprt0_data_t hprt0;
  69072. +
  69073. + core_if = dwc_otg_hcd->core_if;
  69074. +
  69075. + if (core_if->op_state == B_HOST) {
  69076. + /*
  69077. + * Reset the port. During a HNP mode switch the reset
  69078. + * needs to occur within 1ms and have a duration of at
  69079. + * least 50ms.
  69080. + */
  69081. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69082. + hprt0.b.prtrst = 1;
  69083. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69084. + }
  69085. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  69086. + hcd_start_func, dwc_otg_hcd, 50,
  69087. + "start hcd");
  69088. +
  69089. + return 1;
  69090. +}
  69091. +
  69092. +/**
  69093. + * HCD Callback function for disconnect of the HCD.
  69094. + *
  69095. + * @param p void pointer to the <code>struct usb_hcd</code>
  69096. + */
  69097. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  69098. +{
  69099. + gintsts_data_t intr;
  69100. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69101. +
  69102. + /*
  69103. + * Set status flags for the hub driver.
  69104. + */
  69105. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  69106. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  69107. + if(fiq_fix_enable)
  69108. + local_fiq_disable();
  69109. + /*
  69110. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  69111. + * interrupt mask and status bits and disabling subsequent host
  69112. + * channel interrupts.
  69113. + */
  69114. + intr.d32 = 0;
  69115. + intr.b.nptxfempty = 1;
  69116. + intr.b.ptxfempty = 1;
  69117. + intr.b.hcintr = 1;
  69118. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  69119. + intr.d32, 0);
  69120. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  69121. + intr.d32, 0);
  69122. +
  69123. + del_timers(dwc_otg_hcd);
  69124. +
  69125. + /*
  69126. + * Turn off the vbus power only if the core has transitioned to device
  69127. + * mode. If still in host mode, need to keep power on to detect a
  69128. + * reconnection.
  69129. + */
  69130. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  69131. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  69132. + hprt0_data_t hprt0 = {.d32 = 0 };
  69133. + DWC_PRINTF("Disconnect: PortPower off\n");
  69134. + hprt0.b.prtpwr = 0;
  69135. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  69136. + hprt0.d32);
  69137. + }
  69138. +
  69139. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  69140. + }
  69141. +
  69142. + /* Respond with an error status to all URBs in the schedule. */
  69143. + kill_all_urbs(dwc_otg_hcd);
  69144. +
  69145. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  69146. + /* Clean up any host channels that were in use. */
  69147. + int num_channels;
  69148. + int i;
  69149. + dwc_hc_t *channel;
  69150. + dwc_otg_hc_regs_t *hc_regs;
  69151. + hcchar_data_t hcchar;
  69152. +
  69153. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  69154. +
  69155. + if (!dwc_otg_hcd->core_if->dma_enable) {
  69156. + /* Flush out any channel requests in slave mode. */
  69157. + for (i = 0; i < num_channels; i++) {
  69158. + channel = dwc_otg_hcd->hc_ptr_array[i];
  69159. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  69160. + (channel, hc_list_entry)) {
  69161. + hc_regs =
  69162. + dwc_otg_hcd->core_if->
  69163. + host_if->hc_regs[i];
  69164. + hcchar.d32 =
  69165. + DWC_READ_REG32(&hc_regs->hcchar);
  69166. + if (hcchar.b.chen) {
  69167. + hcchar.b.chen = 0;
  69168. + hcchar.b.chdis = 1;
  69169. + hcchar.b.epdir = 0;
  69170. + DWC_WRITE_REG32
  69171. + (&hc_regs->hcchar,
  69172. + hcchar.d32);
  69173. + }
  69174. + }
  69175. + }
  69176. + }
  69177. +
  69178. + for (i = 0; i < num_channels; i++) {
  69179. + channel = dwc_otg_hcd->hc_ptr_array[i];
  69180. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  69181. + hc_regs =
  69182. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  69183. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69184. + if (hcchar.b.chen) {
  69185. + /* Halt the channel. */
  69186. + hcchar.b.chdis = 1;
  69187. + DWC_WRITE_REG32(&hc_regs->hcchar,
  69188. + hcchar.d32);
  69189. + }
  69190. +
  69191. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  69192. + channel);
  69193. + DWC_CIRCLEQ_INSERT_TAIL
  69194. + (&dwc_otg_hcd->free_hc_list, channel,
  69195. + hc_list_entry);
  69196. + /*
  69197. + * Added for Descriptor DMA to prevent channel double cleanup
  69198. + * in release_channel_ddma(). Which called from ep_disable
  69199. + * when device disconnect.
  69200. + */
  69201. + channel->qh = NULL;
  69202. + }
  69203. + }
  69204. + if(fiq_split_enable) {
  69205. + for(i=0; i < 128; i++) {
  69206. + dwc_otg_hcd->hub_port[i] = 0;
  69207. + }
  69208. + haint_saved.d32 = 0;
  69209. + for(i=0; i < MAX_EPS_CHANNELS; i++) {
  69210. + hcint_saved[i].d32 = 0;
  69211. + hcintmsk_saved[i].d32 = 0;
  69212. + }
  69213. + }
  69214. +
  69215. + }
  69216. +
  69217. + if(fiq_fix_enable)
  69218. + local_fiq_enable();
  69219. +
  69220. + if (dwc_otg_hcd->fops->disconnect) {
  69221. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  69222. + }
  69223. +
  69224. + return 1;
  69225. +}
  69226. +
  69227. +/**
  69228. + * HCD Callback function for stopping the HCD.
  69229. + *
  69230. + * @param p void pointer to the <code>struct usb_hcd</code>
  69231. + */
  69232. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  69233. +{
  69234. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69235. +
  69236. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  69237. + dwc_otg_hcd_stop(dwc_otg_hcd);
  69238. + return 1;
  69239. +}
  69240. +
  69241. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69242. +/**
  69243. + * HCD Callback function for sleep of HCD.
  69244. + *
  69245. + * @param p void pointer to the <code>struct usb_hcd</code>
  69246. + */
  69247. +static int dwc_otg_hcd_sleep_cb(void *p)
  69248. +{
  69249. + dwc_otg_hcd_t *hcd = p;
  69250. +
  69251. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  69252. +
  69253. + return 0;
  69254. +}
  69255. +#endif
  69256. +
  69257. +
  69258. +/**
  69259. + * HCD Callback function for Remote Wakeup.
  69260. + *
  69261. + * @param p void pointer to the <code>struct usb_hcd</code>
  69262. + */
  69263. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  69264. +{
  69265. + dwc_otg_hcd_t *hcd = p;
  69266. +
  69267. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  69268. + hcd->flags.b.port_suspend_change = 1;
  69269. + }
  69270. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69271. + else {
  69272. + hcd->flags.b.port_l1_change = 1;
  69273. + }
  69274. +#endif
  69275. + return 0;
  69276. +}
  69277. +
  69278. +/**
  69279. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  69280. + * stopped.
  69281. + */
  69282. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  69283. +{
  69284. + hprt0_data_t hprt0 = {.d32 = 0 };
  69285. +
  69286. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  69287. +
  69288. + /*
  69289. + * The root hub should be disconnected before this function is called.
  69290. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  69291. + * and the QH lists (via ..._hcd_endpoint_disable).
  69292. + */
  69293. +
  69294. + /* Turn off all host-specific interrupts. */
  69295. + dwc_otg_disable_host_interrupts(hcd->core_if);
  69296. +
  69297. + /* Turn off the vbus power */
  69298. + DWC_PRINTF("PortPower off\n");
  69299. + hprt0.b.prtpwr = 0;
  69300. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  69301. + dwc_mdelay(1);
  69302. +}
  69303. +
  69304. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  69305. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  69306. + int atomic_alloc)
  69307. +{
  69308. + int retval = 0;
  69309. + uint8_t needs_scheduling = 0;
  69310. + dwc_otg_transaction_type_e tr_type;
  69311. + dwc_otg_qtd_t *qtd;
  69312. + gintmsk_data_t intr_mask = {.d32 = 0 };
  69313. + hprt0_data_t hprt0 = { .d32 = 0 };
  69314. +
  69315. +#ifdef DEBUG /* integrity checks (Broadcom) */
  69316. + if (NULL == hcd->core_if) {
  69317. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  69318. + /* No longer connected. */
  69319. + return -DWC_E_INVALID;
  69320. + }
  69321. +#endif
  69322. + if (!hcd->flags.b.port_connect_status) {
  69323. + /* No longer connected. */
  69324. + DWC_ERROR("Not connected\n");
  69325. + return -DWC_E_NO_DEVICE;
  69326. + }
  69327. +
  69328. + /* Some core configurations cannot support LS traffic on a FS root port */
  69329. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  69330. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  69331. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  69332. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  69333. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  69334. + return -DWC_E_NO_DEVICE;
  69335. + }
  69336. + }
  69337. +
  69338. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  69339. + if (qtd == NULL) {
  69340. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  69341. + return -DWC_E_NO_MEMORY;
  69342. + }
  69343. +#ifdef DEBUG /* integrity checks (Broadcom) */
  69344. + if (qtd->urb == NULL) {
  69345. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  69346. + return -DWC_E_NO_MEMORY;
  69347. + }
  69348. + if (qtd->urb->priv == NULL) {
  69349. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  69350. + return -DWC_E_NO_MEMORY;
  69351. + }
  69352. +#endif
  69353. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  69354. + if(!intr_mask.b.sofintr) needs_scheduling = 1;
  69355. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  69356. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  69357. + needs_scheduling = 0;
  69358. +
  69359. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  69360. + // creates a new queue in ep_handle if it doesn't exist already
  69361. + if (retval < 0) {
  69362. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  69363. + "Error status %d\n", retval);
  69364. + dwc_otg_hcd_qtd_free(qtd);
  69365. + return retval;
  69366. + }
  69367. +
  69368. + if(needs_scheduling) {
  69369. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  69370. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  69371. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  69372. + }
  69373. + }
  69374. + return retval;
  69375. +}
  69376. +
  69377. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  69378. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  69379. +{
  69380. + dwc_otg_qh_t *qh;
  69381. + dwc_otg_qtd_t *urb_qtd;
  69382. + BUG_ON(!hcd);
  69383. + BUG_ON(!dwc_otg_urb);
  69384. +
  69385. +#ifdef DEBUG /* integrity checks (Broadcom) */
  69386. +
  69387. + if (hcd == NULL) {
  69388. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  69389. + return -DWC_E_INVALID;
  69390. + }
  69391. + if (dwc_otg_urb == NULL) {
  69392. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  69393. + return -DWC_E_INVALID;
  69394. + }
  69395. + if (dwc_otg_urb->qtd == NULL) {
  69396. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  69397. + return -DWC_E_INVALID;
  69398. + }
  69399. + urb_qtd = dwc_otg_urb->qtd;
  69400. + BUG_ON(!urb_qtd);
  69401. + if (urb_qtd->qh == NULL) {
  69402. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  69403. + return -DWC_E_INVALID;
  69404. + }
  69405. +#else
  69406. + urb_qtd = dwc_otg_urb->qtd;
  69407. + BUG_ON(!urb_qtd);
  69408. +#endif
  69409. + qh = urb_qtd->qh;
  69410. + BUG_ON(!qh);
  69411. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  69412. + if (urb_qtd->in_process) {
  69413. + dump_channel_info(hcd, qh);
  69414. + }
  69415. + }
  69416. +#ifdef DEBUG /* integrity checks (Broadcom) */
  69417. + if (hcd->core_if == NULL) {
  69418. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  69419. + return -DWC_E_INVALID;
  69420. + }
  69421. +#endif
  69422. + if (urb_qtd->in_process && qh->channel) {
  69423. + /* The QTD is in process (it has been assigned to a channel). */
  69424. + if (hcd->flags.b.port_connect_status) {
  69425. + /*
  69426. + * If still connected (i.e. in host mode), halt the
  69427. + * channel so it can be used for other transfers. If
  69428. + * no longer connected, the host registers can't be
  69429. + * written to halt the channel since the core is in
  69430. + * device mode.
  69431. + */
  69432. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  69433. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  69434. +
  69435. + dwc_otg_hcd_release_port(hcd, qh);
  69436. + }
  69437. + }
  69438. +
  69439. + /*
  69440. + * Free the QTD and clean up the associated QH. Leave the QH in the
  69441. + * schedule if it has any remaining QTDs.
  69442. + */
  69443. +
  69444. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  69445. + "delete %sQueue handler\n",
  69446. + hcd->core_if->dma_desc_enable?"DMA ":"");
  69447. + if (!hcd->core_if->dma_desc_enable) {
  69448. + uint8_t b = urb_qtd->in_process;
  69449. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  69450. + if (b) {
  69451. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  69452. + qh->channel = NULL;
  69453. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  69454. + dwc_otg_hcd_qh_remove(hcd, qh);
  69455. + }
  69456. + } else {
  69457. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  69458. + }
  69459. + return 0;
  69460. +}
  69461. +
  69462. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  69463. + int retry)
  69464. +{
  69465. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  69466. + int retval = 0;
  69467. + dwc_irqflags_t flags;
  69468. +
  69469. + if (retry < 0) {
  69470. + retval = -DWC_E_INVALID;
  69471. + goto done;
  69472. + }
  69473. +
  69474. + if (!qh) {
  69475. + retval = -DWC_E_INVALID;
  69476. + goto done;
  69477. + }
  69478. +
  69479. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69480. +
  69481. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  69482. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69483. + retry--;
  69484. + dwc_msleep(5);
  69485. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69486. + }
  69487. +
  69488. + dwc_otg_hcd_qh_remove(hcd, qh);
  69489. +
  69490. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69491. + /*
  69492. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  69493. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  69494. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  69495. + * and dwc_otg_hcd_frame_list_alloc().
  69496. + */
  69497. + dwc_otg_hcd_qh_free(hcd, qh);
  69498. +
  69499. +done:
  69500. + return retval;
  69501. +}
  69502. +
  69503. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  69504. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  69505. +{
  69506. + int retval = 0;
  69507. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  69508. + if (!qh)
  69509. + return -DWC_E_INVALID;
  69510. +
  69511. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  69512. + return retval;
  69513. +}
  69514. +#endif
  69515. +
  69516. +/**
  69517. + * HCD Callback structure for handling mode switching.
  69518. + */
  69519. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  69520. + .start = dwc_otg_hcd_start_cb,
  69521. + .stop = dwc_otg_hcd_stop_cb,
  69522. + .disconnect = dwc_otg_hcd_disconnect_cb,
  69523. + .session_start = dwc_otg_hcd_session_start_cb,
  69524. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  69525. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69526. + .sleep = dwc_otg_hcd_sleep_cb,
  69527. +#endif
  69528. + .p = 0,
  69529. +};
  69530. +
  69531. +/**
  69532. + * Reset tasklet function
  69533. + */
  69534. +static void reset_tasklet_func(void *data)
  69535. +{
  69536. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  69537. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  69538. + hprt0_data_t hprt0;
  69539. +
  69540. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  69541. +
  69542. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69543. + hprt0.b.prtrst = 1;
  69544. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69545. + dwc_mdelay(60);
  69546. +
  69547. + hprt0.b.prtrst = 0;
  69548. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69549. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  69550. +}
  69551. +
  69552. +static void completion_tasklet_func(void *ptr)
  69553. +{
  69554. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  69555. + struct urb *urb;
  69556. + urb_tq_entry_t *item;
  69557. + dwc_irqflags_t flags;
  69558. +
  69559. + /* This could just be spin_lock_irq */
  69560. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69561. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  69562. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  69563. + urb = item->urb;
  69564. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  69565. + urb_tq_entries);
  69566. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69567. + DWC_FREE(item);
  69568. +
  69569. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  69570. +
  69571. + fiq_print(FIQDBG_PORTHUB, "COMPLETE");
  69572. +
  69573. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69574. + }
  69575. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69576. + return;
  69577. +}
  69578. +
  69579. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  69580. +{
  69581. + dwc_list_link_t *item;
  69582. + dwc_otg_qh_t *qh;
  69583. + dwc_irqflags_t flags;
  69584. +
  69585. + if (!qh_list->next) {
  69586. + /* The list hasn't been initialized yet. */
  69587. + return;
  69588. + }
  69589. + /*
  69590. + * Hold spinlock here. Not needed in that case if bellow
  69591. + * function is being called from ISR
  69592. + */
  69593. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69594. + /* Ensure there are no QTDs or URBs left. */
  69595. + kill_urbs_in_qh_list(hcd, qh_list);
  69596. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69597. +
  69598. + DWC_LIST_FOREACH(item, qh_list) {
  69599. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  69600. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  69601. + }
  69602. +}
  69603. +
  69604. +/**
  69605. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  69606. + * Device during SRP time by host power up.
  69607. + */
  69608. +void dwc_otg_hcd_power_up(void *ptr)
  69609. +{
  69610. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  69611. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  69612. +
  69613. + DWC_PRINTF("%s called\n", __FUNCTION__);
  69614. +
  69615. + if (!core_if->hibernation_suspend) {
  69616. + DWC_PRINTF("Already exited from Hibernation\n");
  69617. + return;
  69618. + }
  69619. +
  69620. + /* Switch on the voltage to the core */
  69621. + gpwrdn.b.pwrdnswtch = 1;
  69622. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69623. + dwc_udelay(10);
  69624. +
  69625. + /* Reset the core */
  69626. + gpwrdn.d32 = 0;
  69627. + gpwrdn.b.pwrdnrstn = 1;
  69628. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69629. + dwc_udelay(10);
  69630. +
  69631. + /* Disable power clamps */
  69632. + gpwrdn.d32 = 0;
  69633. + gpwrdn.b.pwrdnclmp = 1;
  69634. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69635. +
  69636. + /* Remove reset the core signal */
  69637. + gpwrdn.d32 = 0;
  69638. + gpwrdn.b.pwrdnrstn = 1;
  69639. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  69640. + dwc_udelay(10);
  69641. +
  69642. + /* Disable PMU interrupt */
  69643. + gpwrdn.d32 = 0;
  69644. + gpwrdn.b.pmuintsel = 1;
  69645. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69646. +
  69647. + core_if->hibernation_suspend = 0;
  69648. +
  69649. + /* Disable PMU */
  69650. + gpwrdn.d32 = 0;
  69651. + gpwrdn.b.pmuactv = 1;
  69652. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69653. + dwc_udelay(10);
  69654. +
  69655. + /* Enable VBUS */
  69656. + gpwrdn.d32 = 0;
  69657. + gpwrdn.b.dis_vbus = 1;
  69658. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69659. +
  69660. + core_if->op_state = A_HOST;
  69661. + dwc_otg_core_init(core_if);
  69662. + dwc_otg_enable_global_interrupts(core_if);
  69663. + cil_hcd_start(core_if);
  69664. +}
  69665. +
  69666. +/**
  69667. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  69668. + * in the struct usb_hcd field.
  69669. + */
  69670. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  69671. +{
  69672. + int i;
  69673. +
  69674. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  69675. +
  69676. + del_timers(dwc_otg_hcd);
  69677. +
  69678. + /* Free memory for QH/QTD lists */
  69679. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  69680. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  69681. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  69682. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  69683. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  69684. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  69685. +
  69686. + /* Free memory for the host channels. */
  69687. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  69688. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  69689. +
  69690. +#ifdef DEBUG
  69691. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  69692. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  69693. + }
  69694. +#endif
  69695. + if (hc != NULL) {
  69696. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  69697. + i, hc);
  69698. + DWC_FREE(hc);
  69699. + }
  69700. + }
  69701. +
  69702. + if (dwc_otg_hcd->core_if->dma_enable) {
  69703. + if (dwc_otg_hcd->status_buf_dma) {
  69704. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  69705. + dwc_otg_hcd->status_buf,
  69706. + dwc_otg_hcd->status_buf_dma);
  69707. + }
  69708. + } else if (dwc_otg_hcd->status_buf != NULL) {
  69709. + DWC_FREE(dwc_otg_hcd->status_buf);
  69710. + }
  69711. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  69712. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  69713. + /* Set core_if's lock pointer to NULL */
  69714. + dwc_otg_hcd->core_if->lock = NULL;
  69715. +
  69716. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  69717. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  69718. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  69719. +
  69720. +#ifdef DWC_DEV_SRPCAP
  69721. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  69722. + dwc_otg_hcd->core_if->pwron_timer) {
  69723. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  69724. + }
  69725. +#endif
  69726. + DWC_FREE(dwc_otg_hcd);
  69727. +}
  69728. +
  69729. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  69730. +
  69731. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  69732. +{
  69733. + int retval = 0;
  69734. + int num_channels;
  69735. + int i;
  69736. + dwc_hc_t *channel;
  69737. +
  69738. + hcd->lock = DWC_SPINLOCK_ALLOC();
  69739. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  69740. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  69741. + hcd, core_if);
  69742. + if (!hcd->lock) {
  69743. + DWC_ERROR("Could not allocate lock for pcd");
  69744. + DWC_FREE(hcd);
  69745. + retval = -DWC_E_NO_MEMORY;
  69746. + goto out;
  69747. + }
  69748. + hcd->core_if = core_if;
  69749. +
  69750. + /* Register the HCD CIL Callbacks */
  69751. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  69752. + &hcd_cil_callbacks, hcd);
  69753. +
  69754. + /* Initialize the non-periodic schedule. */
  69755. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  69756. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  69757. +
  69758. + /* Initialize the periodic schedule. */
  69759. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  69760. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  69761. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  69762. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  69763. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  69764. + /*
  69765. + * Create a host channel descriptor for each host channel implemented
  69766. + * in the controller. Initialize the channel descriptor array.
  69767. + */
  69768. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  69769. + num_channels = hcd->core_if->core_params->host_channels;
  69770. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  69771. + for (i = 0; i < num_channels; i++) {
  69772. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  69773. + if (channel == NULL) {
  69774. + retval = -DWC_E_NO_MEMORY;
  69775. + DWC_ERROR("%s: host channel allocation failed\n",
  69776. + __func__);
  69777. + dwc_otg_hcd_free(hcd);
  69778. + goto out;
  69779. + }
  69780. + channel->hc_num = i;
  69781. + hcd->hc_ptr_array[i] = channel;
  69782. +#ifdef DEBUG
  69783. + hcd->core_if->hc_xfer_timer[i] =
  69784. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  69785. + &hcd->core_if->hc_xfer_info[i]);
  69786. +#endif
  69787. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  69788. + channel);
  69789. + }
  69790. +
  69791. + /* Initialize the Connection timeout timer. */
  69792. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  69793. + dwc_otg_hcd_connect_timeout, 0);
  69794. +
  69795. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  69796. + if (microframe_schedule)
  69797. + init_hcd_usecs(hcd);
  69798. +
  69799. + /* Initialize reset tasklet. */
  69800. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  69801. +
  69802. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  69803. + completion_tasklet_func, hcd);
  69804. +#ifdef DWC_DEV_SRPCAP
  69805. + if (hcd->core_if->power_down == 2) {
  69806. + /* Initialize Power on timer for Host power up in case hibernation */
  69807. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  69808. + dwc_otg_hcd_power_up, core_if);
  69809. + }
  69810. +#endif
  69811. +
  69812. + /*
  69813. + * Allocate space for storing data on status transactions. Normally no
  69814. + * data is sent, but this space acts as a bit bucket. This must be
  69815. + * done after usb_add_hcd since that function allocates the DMA buffer
  69816. + * pool.
  69817. + */
  69818. + if (hcd->core_if->dma_enable) {
  69819. + hcd->status_buf =
  69820. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  69821. + &hcd->status_buf_dma);
  69822. + } else {
  69823. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  69824. + }
  69825. + if (!hcd->status_buf) {
  69826. + retval = -DWC_E_NO_MEMORY;
  69827. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  69828. + dwc_otg_hcd_free(hcd);
  69829. + goto out;
  69830. + }
  69831. +
  69832. + hcd->otg_port = 1;
  69833. + hcd->frame_list = NULL;
  69834. + hcd->frame_list_dma = 0;
  69835. + hcd->periodic_qh_count = 0;
  69836. +
  69837. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  69838. +#ifdef FIQ_DEBUG
  69839. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  69840. +#endif
  69841. +
  69842. +out:
  69843. + return retval;
  69844. +}
  69845. +
  69846. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  69847. +{
  69848. + /* Turn off all host-specific interrupts. */
  69849. + dwc_otg_disable_host_interrupts(hcd->core_if);
  69850. +
  69851. + dwc_otg_hcd_free(hcd);
  69852. +}
  69853. +
  69854. +/**
  69855. + * Initializes dynamic portions of the DWC_otg HCD state.
  69856. + */
  69857. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  69858. +{
  69859. + int num_channels;
  69860. + int i;
  69861. + dwc_hc_t *channel;
  69862. + dwc_hc_t *channel_tmp;
  69863. +
  69864. + hcd->flags.d32 = 0;
  69865. +
  69866. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  69867. + if (!microframe_schedule) {
  69868. + hcd->non_periodic_channels = 0;
  69869. + hcd->periodic_channels = 0;
  69870. + } else {
  69871. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  69872. + }
  69873. + /*
  69874. + * Put all channels in the free channel list and clean up channel
  69875. + * states.
  69876. + */
  69877. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  69878. + &hcd->free_hc_list, hc_list_entry) {
  69879. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  69880. + }
  69881. +
  69882. + num_channels = hcd->core_if->core_params->host_channels;
  69883. + for (i = 0; i < num_channels; i++) {
  69884. + channel = hcd->hc_ptr_array[i];
  69885. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  69886. + hc_list_entry);
  69887. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  69888. + }
  69889. +
  69890. + /* Initialize the DWC core for host mode operation. */
  69891. + dwc_otg_core_host_init(hcd->core_if);
  69892. +
  69893. + /* Set core_if's lock pointer to the hcd->lock */
  69894. + hcd->core_if->lock = hcd->lock;
  69895. +}
  69896. +
  69897. +/**
  69898. + * Assigns transactions from a QTD to a free host channel and initializes the
  69899. + * host channel to perform the transactions. The host channel is removed from
  69900. + * the free list.
  69901. + *
  69902. + * @param hcd The HCD state structure.
  69903. + * @param qh Transactions from the first QTD for this QH are selected and
  69904. + * assigned to a free host channel.
  69905. + */
  69906. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  69907. +{
  69908. + dwc_hc_t *hc;
  69909. + dwc_otg_qtd_t *qtd;
  69910. + dwc_otg_hcd_urb_t *urb;
  69911. + void* ptr = NULL;
  69912. +
  69913. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  69914. +
  69915. + urb = qtd->urb;
  69916. +
  69917. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  69918. +
  69919. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  69920. + urb->actual_length = urb->length;
  69921. +
  69922. +
  69923. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  69924. +
  69925. + /* Remove the host channel from the free list. */
  69926. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  69927. +
  69928. + qh->channel = hc;
  69929. +
  69930. + qtd->in_process = 1;
  69931. +
  69932. + /*
  69933. + * Use usb_pipedevice to determine device address. This address is
  69934. + * 0 before the SET_ADDRESS command and the correct address afterward.
  69935. + */
  69936. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  69937. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  69938. + hc->speed = qh->dev_speed;
  69939. + hc->max_packet = dwc_max_packet(qh->maxp);
  69940. +
  69941. + hc->xfer_started = 0;
  69942. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  69943. + hc->error_state = (qtd->error_count > 0);
  69944. + hc->halt_on_queue = 0;
  69945. + hc->halt_pending = 0;
  69946. + hc->requests = 0;
  69947. +
  69948. + /*
  69949. + * The following values may be modified in the transfer type section
  69950. + * below. The xfer_len value may be reduced when the transfer is
  69951. + * started to accommodate the max widths of the XferSize and PktCnt
  69952. + * fields in the HCTSIZn register.
  69953. + */
  69954. +
  69955. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  69956. + if (hc->ep_is_in) {
  69957. + hc->do_ping = 0;
  69958. + } else {
  69959. + hc->do_ping = qh->ping_state;
  69960. + }
  69961. +
  69962. + hc->data_pid_start = qh->data_toggle;
  69963. + hc->multi_count = 1;
  69964. +
  69965. + if (hcd->core_if->dma_enable) {
  69966. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  69967. +
  69968. + /* For non-dword aligned case */
  69969. + if (((unsigned long)hc->xfer_buff & 0x3)
  69970. + && !hcd->core_if->dma_desc_enable) {
  69971. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  69972. + }
  69973. + } else {
  69974. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  69975. + }
  69976. + hc->xfer_len = urb->length - urb->actual_length;
  69977. + hc->xfer_count = 0;
  69978. +
  69979. + /*
  69980. + * Set the split attributes
  69981. + */
  69982. + hc->do_split = 0;
  69983. + if (qh->do_split) {
  69984. + uint32_t hub_addr, port_addr;
  69985. + hc->do_split = 1;
  69986. + hc->xact_pos = qtd->isoc_split_pos;
  69987. + /* We don't need to do complete splits anymore */
  69988. + if(fiq_split_enable)
  69989. + hc->complete_split = qtd->complete_split = 0;
  69990. + else
  69991. + hc->complete_split = qtd->complete_split;
  69992. +
  69993. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  69994. + hc->hub_addr = (uint8_t) hub_addr;
  69995. + hc->port_addr = (uint8_t) port_addr;
  69996. + }
  69997. +
  69998. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  69999. + case UE_CONTROL:
  70000. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  70001. + switch (qtd->control_phase) {
  70002. + case DWC_OTG_CONTROL_SETUP:
  70003. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  70004. + hc->do_ping = 0;
  70005. + hc->ep_is_in = 0;
  70006. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  70007. + if (hcd->core_if->dma_enable) {
  70008. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  70009. + } else {
  70010. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  70011. + }
  70012. + hc->xfer_len = 8;
  70013. + ptr = NULL;
  70014. + break;
  70015. + case DWC_OTG_CONTROL_DATA:
  70016. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  70017. + hc->data_pid_start = qtd->data_toggle;
  70018. + break;
  70019. + case DWC_OTG_CONTROL_STATUS:
  70020. + /*
  70021. + * Direction is opposite of data direction or IN if no
  70022. + * data.
  70023. + */
  70024. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  70025. + if (urb->length == 0) {
  70026. + hc->ep_is_in = 1;
  70027. + } else {
  70028. + hc->ep_is_in =
  70029. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  70030. + }
  70031. + if (hc->ep_is_in) {
  70032. + hc->do_ping = 0;
  70033. + }
  70034. +
  70035. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  70036. +
  70037. + hc->xfer_len = 0;
  70038. + if (hcd->core_if->dma_enable) {
  70039. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  70040. + } else {
  70041. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  70042. + }
  70043. + ptr = NULL;
  70044. + break;
  70045. + }
  70046. + break;
  70047. + case UE_BULK:
  70048. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  70049. + break;
  70050. + case UE_INTERRUPT:
  70051. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  70052. + break;
  70053. + case UE_ISOCHRONOUS:
  70054. + {
  70055. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  70056. +
  70057. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  70058. +
  70059. + if (hcd->core_if->dma_desc_enable)
  70060. + break;
  70061. +
  70062. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  70063. +
  70064. + frame_desc->status = 0;
  70065. +
  70066. + if (hcd->core_if->dma_enable) {
  70067. + hc->xfer_buff = (uint8_t *) urb->dma;
  70068. + } else {
  70069. + hc->xfer_buff = (uint8_t *) urb->buf;
  70070. + }
  70071. + hc->xfer_buff +=
  70072. + frame_desc->offset + qtd->isoc_split_offset;
  70073. + hc->xfer_len =
  70074. + frame_desc->length - qtd->isoc_split_offset;
  70075. +
  70076. + /* For non-dword aligned buffers */
  70077. + if (((unsigned long)hc->xfer_buff & 0x3)
  70078. + && hcd->core_if->dma_enable) {
  70079. + ptr =
  70080. + (uint8_t *) urb->buf + frame_desc->offset +
  70081. + qtd->isoc_split_offset;
  70082. + } else
  70083. + ptr = NULL;
  70084. +
  70085. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  70086. + if (hc->xfer_len <= 188) {
  70087. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  70088. + } else {
  70089. + hc->xact_pos =
  70090. + DWC_HCSPLIT_XACTPOS_BEGIN;
  70091. + }
  70092. + }
  70093. + }
  70094. + break;
  70095. + }
  70096. + /* non DWORD-aligned buffer case */
  70097. + if (ptr) {
  70098. + uint32_t buf_size;
  70099. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  70100. + buf_size = hcd->core_if->core_params->max_transfer_size;
  70101. + } else {
  70102. + buf_size = 4096;
  70103. + }
  70104. + if (!qh->dw_align_buf) {
  70105. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  70106. + &qh->dw_align_buf_dma);
  70107. + if (!qh->dw_align_buf) {
  70108. + DWC_ERROR
  70109. + ("%s: Failed to allocate memory to handle "
  70110. + "non-dword aligned buffer case\n",
  70111. + __func__);
  70112. + return;
  70113. + }
  70114. + }
  70115. + if (!hc->ep_is_in) {
  70116. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  70117. + }
  70118. + hc->align_buff = qh->dw_align_buf_dma;
  70119. + } else {
  70120. + hc->align_buff = 0;
  70121. + }
  70122. +
  70123. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  70124. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  70125. + /*
  70126. + * This value may be modified when the transfer is started to
  70127. + * reflect the actual transfer length.
  70128. + */
  70129. + hc->multi_count = dwc_hb_mult(qh->maxp);
  70130. + }
  70131. +
  70132. + if (hcd->core_if->dma_desc_enable)
  70133. + hc->desc_list_addr = qh->desc_list_dma;
  70134. +
  70135. + dwc_otg_hc_init(hcd->core_if, hc);
  70136. + hc->qh = qh;
  70137. +}
  70138. +
  70139. +/*
  70140. +** Check the transaction to see if the port / hub has already been assigned for
  70141. +** a split transaction
  70142. +**
  70143. +** Return 0 - Port is already in use
  70144. +*/
  70145. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  70146. +{
  70147. + uint32_t hub_addr, port_addr;
  70148. +
  70149. + if(!fiq_split_enable)
  70150. + return 0;
  70151. +
  70152. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  70153. +
  70154. + if(hcd->hub_port[hub_addr] & (1 << port_addr))
  70155. + {
  70156. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
  70157. +
  70158. + qh->skip_count++;
  70159. +
  70160. + if(qh->skip_count > 40000)
  70161. + {
  70162. + printk_once(KERN_ERR "Error: Having to skip port allocation");
  70163. + local_fiq_disable();
  70164. + BUG();
  70165. + return 0;
  70166. + }
  70167. + return 1;
  70168. + }
  70169. + else
  70170. + {
  70171. + qh->skip_count = 0;
  70172. + hcd->hub_port[hub_addr] |= 1 << port_addr;
  70173. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  70174. +#ifdef FIQ_DEBUG
  70175. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
  70176. +#endif
  70177. + return 0;
  70178. + }
  70179. +}
  70180. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  70181. +{
  70182. + uint32_t hub_addr, port_addr;
  70183. +
  70184. + if(!fiq_split_enable)
  70185. + return;
  70186. +
  70187. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  70188. +
  70189. + hcd->hub_port[hub_addr] &= ~(1 << port_addr);
  70190. +#ifdef FIQ_DEBUG
  70191. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
  70192. +#endif
  70193. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  70194. +
  70195. +}
  70196. +
  70197. +
  70198. +/**
  70199. + * This function selects transactions from the HCD transfer schedule and
  70200. + * assigns them to available host channels. It is called from HCD interrupt
  70201. + * handler functions.
  70202. + *
  70203. + * @param hcd The HCD state structure.
  70204. + *
  70205. + * @return The types of new transactions that were assigned to host channels.
  70206. + */
  70207. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  70208. +{
  70209. + dwc_list_link_t *qh_ptr;
  70210. + dwc_otg_qh_t *qh;
  70211. + dwc_otg_qtd_t *qtd;
  70212. + int num_channels;
  70213. + dwc_irqflags_t flags;
  70214. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  70215. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  70216. +
  70217. +#ifdef DEBUG_SOF
  70218. + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
  70219. +#endif
  70220. +
  70221. +#ifdef DEBUG_HOST_CHANNELS
  70222. + last_sel_trans_num_per_scheduled = 0;
  70223. + last_sel_trans_num_nonper_scheduled = 0;
  70224. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  70225. +#endif /* DEBUG_HOST_CHANNELS */
  70226. +
  70227. + /* Process entries in the periodic ready list. */
  70228. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  70229. +
  70230. + while (qh_ptr != &hcd->periodic_sched_ready &&
  70231. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  70232. +
  70233. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  70234. +
  70235. + if(qh->do_split) {
  70236. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  70237. + if(!(qh->ep_type == UE_ISOCHRONOUS &&
  70238. + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  70239. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
  70240. + if(dwc_otg_hcd_allocate_port(hcd, qh))
  70241. + {
  70242. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  70243. + g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
  70244. + continue;
  70245. + }
  70246. + }
  70247. + }
  70248. +
  70249. + if (microframe_schedule) {
  70250. + // Make sure we leave one channel for non periodic transactions.
  70251. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  70252. + if (hcd->available_host_channels <= 1) {
  70253. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  70254. + if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
  70255. + break;
  70256. + }
  70257. + hcd->available_host_channels--;
  70258. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  70259. +#ifdef DEBUG_HOST_CHANNELS
  70260. + last_sel_trans_num_per_scheduled++;
  70261. +#endif /* DEBUG_HOST_CHANNELS */
  70262. + }
  70263. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  70264. + assign_and_init_hc(hcd, qh);
  70265. +
  70266. + /*
  70267. + * Move the QH from the periodic ready schedule to the
  70268. + * periodic assigned schedule.
  70269. + */
  70270. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  70271. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  70272. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  70273. + &qh->qh_list_entry);
  70274. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  70275. + }
  70276. +
  70277. + /*
  70278. + * Process entries in the inactive portion of the non-periodic
  70279. + * schedule. Some free host channels may not be used if they are
  70280. + * reserved for periodic transfers.
  70281. + */
  70282. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  70283. + num_channels = hcd->core_if->core_params->host_channels;
  70284. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  70285. + (microframe_schedule || hcd->non_periodic_channels <
  70286. + num_channels - hcd->periodic_channels) &&
  70287. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  70288. +
  70289. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  70290. +
  70291. + /*
  70292. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  70293. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  70294. + * cheeky devices that just hold off using NAKs
  70295. + */
  70296. + if (nak_holdoff_enable && qh->do_split) {
  70297. + if (qh->nak_frame != 0xffff &&
  70298. + dwc_full_frame_num(qh->nak_frame) ==
  70299. + dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
  70300. + /*
  70301. + * Revisit: Need to avoid trampling on periodic scheduling.
  70302. + * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
  70303. + * but if this behaviour is changed then periodic endpoints will get a slower
  70304. + * polling rate.
  70305. + */
  70306. + g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
  70307. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  70308. + continue;
  70309. + } else {
  70310. + qh->nak_frame = 0xffff;
  70311. + }
  70312. + }
  70313. +
  70314. + if (microframe_schedule) {
  70315. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  70316. + if (hcd->available_host_channels < 1) {
  70317. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  70318. + break;
  70319. + }
  70320. + hcd->available_host_channels--;
  70321. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  70322. +#ifdef DEBUG_HOST_CHANNELS
  70323. + last_sel_trans_num_nonper_scheduled++;
  70324. +#endif /* DEBUG_HOST_CHANNELS */
  70325. + }
  70326. +
  70327. + assign_and_init_hc(hcd, qh);
  70328. +
  70329. + /*
  70330. + * Move the QH from the non-periodic inactive schedule to the
  70331. + * non-periodic active schedule.
  70332. + */
  70333. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  70334. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  70335. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  70336. + &qh->qh_list_entry);
  70337. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  70338. +
  70339. + g_np_sent++;
  70340. +
  70341. + if (!microframe_schedule)
  70342. + hcd->non_periodic_channels++;
  70343. + }
  70344. +
  70345. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  70346. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  70347. +
  70348. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  70349. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  70350. +
  70351. +
  70352. +#ifdef DEBUG_HOST_CHANNELS
  70353. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  70354. +#endif /* DEBUG_HOST_CHANNELS */
  70355. + return ret_val;
  70356. +}
  70357. +
  70358. +/**
  70359. + * Attempts to queue a single transaction request for a host channel
  70360. + * associated with either a periodic or non-periodic transfer. This function
  70361. + * assumes that there is space available in the appropriate request queue. For
  70362. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  70363. + * is available in the appropriate Tx FIFO.
  70364. + *
  70365. + * @param hcd The HCD state structure.
  70366. + * @param hc Host channel descriptor associated with either a periodic or
  70367. + * non-periodic transfer.
  70368. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  70369. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  70370. + * transfers.
  70371. + *
  70372. + * @return 1 if a request is queued and more requests may be needed to
  70373. + * complete the transfer, 0 if no more requests are required for this
  70374. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  70375. + */
  70376. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  70377. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  70378. +{
  70379. + int retval;
  70380. +
  70381. + if (hcd->core_if->dma_enable) {
  70382. + if (hcd->core_if->dma_desc_enable) {
  70383. + if (!hc->xfer_started
  70384. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  70385. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  70386. + hc->qh->ping_state = 0;
  70387. + }
  70388. + } else if (!hc->xfer_started) {
  70389. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  70390. + hc->qh->ping_state = 0;
  70391. + }
  70392. + retval = 0;
  70393. + } else if (hc->halt_pending) {
  70394. + /* Don't queue a request if the channel has been halted. */
  70395. + retval = 0;
  70396. + } else if (hc->halt_on_queue) {
  70397. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  70398. + retval = 0;
  70399. + } else if (hc->do_ping) {
  70400. + if (!hc->xfer_started) {
  70401. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  70402. + }
  70403. + retval = 0;
  70404. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  70405. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  70406. + if (!hc->xfer_started) {
  70407. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  70408. + retval = 1;
  70409. + } else {
  70410. + retval =
  70411. + dwc_otg_hc_continue_transfer(hcd->core_if,
  70412. + hc);
  70413. + }
  70414. + } else {
  70415. + retval = -1;
  70416. + }
  70417. + } else {
  70418. + if (!hc->xfer_started) {
  70419. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  70420. + retval = 1;
  70421. + } else {
  70422. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  70423. + }
  70424. + }
  70425. +
  70426. + return retval;
  70427. +}
  70428. +
  70429. +/**
  70430. + * Processes periodic channels for the next frame and queues transactions for
  70431. + * these channels to the DWC_otg controller. After queueing transactions, the
  70432. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  70433. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  70434. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  70435. + */
  70436. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  70437. +{
  70438. + hptxsts_data_t tx_status;
  70439. + dwc_list_link_t *qh_ptr;
  70440. + dwc_otg_qh_t *qh;
  70441. + int status;
  70442. + int no_queue_space = 0;
  70443. + int no_fifo_space = 0;
  70444. +
  70445. + dwc_otg_host_global_regs_t *host_regs;
  70446. + host_regs = hcd->core_if->host_if->host_global_regs;
  70447. +
  70448. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  70449. +#ifdef DEBUG
  70450. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  70451. + DWC_DEBUGPL(DBG_HCDV,
  70452. + " P Tx Req Queue Space Avail (before queue): %d\n",
  70453. + tx_status.b.ptxqspcavail);
  70454. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  70455. + tx_status.b.ptxfspcavail);
  70456. +#endif
  70457. +
  70458. + qh_ptr = hcd->periodic_sched_assigned.next;
  70459. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  70460. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  70461. + if (tx_status.b.ptxqspcavail == 0) {
  70462. + no_queue_space = 1;
  70463. + break;
  70464. + }
  70465. +
  70466. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  70467. +
  70468. + // Do not send a split start transaction any later than frame .6
  70469. + // Note, we have to schedule a periodic in .5 to make it go in .6
  70470. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  70471. + {
  70472. + qh_ptr = qh_ptr->next;
  70473. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  70474. + continue;
  70475. + }
  70476. +
  70477. + /*
  70478. + * Set a flag if we're queuing high-bandwidth in slave mode.
  70479. + * The flag prevents any halts to get into the request queue in
  70480. + * the middle of multiple high-bandwidth packets getting queued.
  70481. + */
  70482. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  70483. + hcd->core_if->queuing_high_bandwidth = 1;
  70484. + }
  70485. + status =
  70486. + queue_transaction(hcd, qh->channel,
  70487. + tx_status.b.ptxfspcavail);
  70488. + if (status < 0) {
  70489. + no_fifo_space = 1;
  70490. + break;
  70491. + }
  70492. +
  70493. + /*
  70494. + * In Slave mode, stay on the current transfer until there is
  70495. + * nothing more to do or the high-bandwidth request count is
  70496. + * reached. In DMA mode, only need to queue one request. The
  70497. + * controller automatically handles multiple packets for
  70498. + * high-bandwidth transfers.
  70499. + */
  70500. + if (hcd->core_if->dma_enable || status == 0 ||
  70501. + qh->channel->requests == qh->channel->multi_count) {
  70502. + qh_ptr = qh_ptr->next;
  70503. + /*
  70504. + * Move the QH from the periodic assigned schedule to
  70505. + * the periodic queued schedule.
  70506. + */
  70507. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  70508. + &qh->qh_list_entry);
  70509. +
  70510. + /* done queuing high bandwidth */
  70511. + hcd->core_if->queuing_high_bandwidth = 0;
  70512. + }
  70513. + }
  70514. +
  70515. + if (!hcd->core_if->dma_enable) {
  70516. + dwc_otg_core_global_regs_t *global_regs;
  70517. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70518. +
  70519. + global_regs = hcd->core_if->core_global_regs;
  70520. + intr_mask.b.ptxfempty = 1;
  70521. +#ifdef DEBUG
  70522. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  70523. + DWC_DEBUGPL(DBG_HCDV,
  70524. + " P Tx Req Queue Space Avail (after queue): %d\n",
  70525. + tx_status.b.ptxqspcavail);
  70526. + DWC_DEBUGPL(DBG_HCDV,
  70527. + " P Tx FIFO Space Avail (after queue): %d\n",
  70528. + tx_status.b.ptxfspcavail);
  70529. +#endif
  70530. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  70531. + no_queue_space || no_fifo_space) {
  70532. + /*
  70533. + * May need to queue more transactions as the request
  70534. + * queue or Tx FIFO empties. Enable the periodic Tx
  70535. + * FIFO empty interrupt. (Always use the half-empty
  70536. + * level to ensure that new requests are loaded as
  70537. + * soon as possible.)
  70538. + */
  70539. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  70540. + intr_mask.d32);
  70541. + } else {
  70542. + /*
  70543. + * Disable the Tx FIFO empty interrupt since there are
  70544. + * no more transactions that need to be queued right
  70545. + * now. This function is called from interrupt
  70546. + * handlers to queue more transactions as transfer
  70547. + * states change.
  70548. + */
  70549. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  70550. + 0);
  70551. + }
  70552. + }
  70553. +}
  70554. +
  70555. +/**
  70556. + * Processes active non-periodic channels and queues transactions for these
  70557. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  70558. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  70559. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  70560. + * FIFO Empty interrupt is disabled.
  70561. + */
  70562. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  70563. +{
  70564. + gnptxsts_data_t tx_status;
  70565. + dwc_list_link_t *orig_qh_ptr;
  70566. + dwc_otg_qh_t *qh;
  70567. + int status;
  70568. + int no_queue_space = 0;
  70569. + int no_fifo_space = 0;
  70570. + int more_to_do = 0;
  70571. +
  70572. + dwc_otg_core_global_regs_t *global_regs =
  70573. + hcd->core_if->core_global_regs;
  70574. +
  70575. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  70576. +#ifdef DEBUG
  70577. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  70578. + DWC_DEBUGPL(DBG_HCDV,
  70579. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  70580. + tx_status.b.nptxqspcavail);
  70581. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  70582. + tx_status.b.nptxfspcavail);
  70583. +#endif
  70584. + /*
  70585. + * Keep track of the starting point. Skip over the start-of-list
  70586. + * entry.
  70587. + */
  70588. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  70589. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  70590. + }
  70591. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  70592. +
  70593. + /*
  70594. + * Process once through the active list or until no more space is
  70595. + * available in the request queue or the Tx FIFO.
  70596. + */
  70597. + do {
  70598. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  70599. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  70600. + no_queue_space = 1;
  70601. + break;
  70602. + }
  70603. +
  70604. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  70605. + qh_list_entry);
  70606. +
  70607. + // Do not send a split start transaction any later than frame .5
  70608. + // non periodic transactions will start immediately in this uframe
  70609. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  70610. + {
  70611. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  70612. + break;
  70613. + }
  70614. +
  70615. + status =
  70616. + queue_transaction(hcd, qh->channel,
  70617. + tx_status.b.nptxfspcavail);
  70618. +
  70619. + if (status > 0) {
  70620. + more_to_do = 1;
  70621. + } else if (status < 0) {
  70622. + no_fifo_space = 1;
  70623. + break;
  70624. + }
  70625. +
  70626. + /* Advance to next QH, skipping start-of-list entry. */
  70627. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  70628. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  70629. + hcd->non_periodic_qh_ptr =
  70630. + hcd->non_periodic_qh_ptr->next;
  70631. + }
  70632. +
  70633. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  70634. +
  70635. + if (!hcd->core_if->dma_enable) {
  70636. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70637. + intr_mask.b.nptxfempty = 1;
  70638. +
  70639. +#ifdef DEBUG
  70640. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  70641. + DWC_DEBUGPL(DBG_HCDV,
  70642. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  70643. + tx_status.b.nptxqspcavail);
  70644. + DWC_DEBUGPL(DBG_HCDV,
  70645. + " NP Tx FIFO Space Avail (after queue): %d\n",
  70646. + tx_status.b.nptxfspcavail);
  70647. +#endif
  70648. + if (more_to_do || no_queue_space || no_fifo_space) {
  70649. + /*
  70650. + * May need to queue more transactions as the request
  70651. + * queue or Tx FIFO empties. Enable the non-periodic
  70652. + * Tx FIFO empty interrupt. (Always use the half-empty
  70653. + * level to ensure that new requests are loaded as
  70654. + * soon as possible.)
  70655. + */
  70656. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  70657. + intr_mask.d32);
  70658. + } else {
  70659. + /*
  70660. + * Disable the Tx FIFO empty interrupt since there are
  70661. + * no more transactions that need to be queued right
  70662. + * now. This function is called from interrupt
  70663. + * handlers to queue more transactions as transfer
  70664. + * states change.
  70665. + */
  70666. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  70667. + 0);
  70668. + }
  70669. + }
  70670. +}
  70671. +
  70672. +/**
  70673. + * This function processes the currently active host channels and queues
  70674. + * transactions for these channels to the DWC_otg controller. It is called
  70675. + * from HCD interrupt handler functions.
  70676. + *
  70677. + * @param hcd The HCD state structure.
  70678. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  70679. + * periodic, or both).
  70680. + */
  70681. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  70682. + dwc_otg_transaction_type_e tr_type)
  70683. +{
  70684. +#ifdef DEBUG_SOF
  70685. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  70686. +#endif
  70687. + /* Process host channels associated with periodic transfers. */
  70688. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  70689. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  70690. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  70691. +
  70692. + process_periodic_channels(hcd);
  70693. + }
  70694. +
  70695. + /* Process host channels associated with non-periodic transfers. */
  70696. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  70697. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  70698. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  70699. + process_non_periodic_channels(hcd);
  70700. + } else {
  70701. + /*
  70702. + * Ensure NP Tx FIFO empty interrupt is disabled when
  70703. + * there are no non-periodic transfers to process.
  70704. + */
  70705. + gintmsk_data_t gintmsk = {.d32 = 0 };
  70706. + gintmsk.b.nptxfempty = 1;
  70707. + DWC_MODIFY_REG32(&hcd->core_if->
  70708. + core_global_regs->gintmsk, gintmsk.d32,
  70709. + 0);
  70710. + }
  70711. + }
  70712. +}
  70713. +
  70714. +#ifdef DWC_HS_ELECT_TST
  70715. +/*
  70716. + * Quick and dirty hack to implement the HS Electrical Test
  70717. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  70718. + *
  70719. + * This code was copied from our userspace app "hset". It sends a
  70720. + * Get Device Descriptor control sequence in two parts, first the
  70721. + * Setup packet by itself, followed some time later by the In and
  70722. + * Ack packets. Rather than trying to figure out how to add this
  70723. + * functionality to the normal driver code, we just hijack the
  70724. + * hardware, using these two function to drive the hardware
  70725. + * directly.
  70726. + */
  70727. +
  70728. +static dwc_otg_core_global_regs_t *global_regs;
  70729. +static dwc_otg_host_global_regs_t *hc_global_regs;
  70730. +static dwc_otg_hc_regs_t *hc_regs;
  70731. +static uint32_t *data_fifo;
  70732. +
  70733. +static void do_setup(void)
  70734. +{
  70735. + gintsts_data_t gintsts;
  70736. + hctsiz_data_t hctsiz;
  70737. + hcchar_data_t hcchar;
  70738. + haint_data_t haint;
  70739. + hcint_data_t hcint;
  70740. +
  70741. + /* Enable HAINTs */
  70742. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  70743. +
  70744. + /* Enable HCINTs */
  70745. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  70746. +
  70747. + /* Read GINTSTS */
  70748. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70749. +
  70750. + /* Read HAINT */
  70751. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70752. +
  70753. + /* Read HCINT */
  70754. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70755. +
  70756. + /* Read HCCHAR */
  70757. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70758. +
  70759. + /* Clear HCINT */
  70760. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70761. +
  70762. + /* Clear HAINT */
  70763. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70764. +
  70765. + /* Clear GINTSTS */
  70766. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70767. +
  70768. + /* Read GINTSTS */
  70769. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70770. +
  70771. + /*
  70772. + * Send Setup packet (Get Device Descriptor)
  70773. + */
  70774. +
  70775. + /* Make sure channel is disabled */
  70776. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70777. + if (hcchar.b.chen) {
  70778. + hcchar.b.chdis = 1;
  70779. +// hcchar.b.chen = 1;
  70780. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70781. + //sleep(1);
  70782. + dwc_mdelay(1000);
  70783. +
  70784. + /* Read GINTSTS */
  70785. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70786. +
  70787. + /* Read HAINT */
  70788. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70789. +
  70790. + /* Read HCINT */
  70791. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70792. +
  70793. + /* Read HCCHAR */
  70794. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70795. +
  70796. + /* Clear HCINT */
  70797. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70798. +
  70799. + /* Clear HAINT */
  70800. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70801. +
  70802. + /* Clear GINTSTS */
  70803. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70804. +
  70805. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70806. + }
  70807. +
  70808. + /* Set HCTSIZ */
  70809. + hctsiz.d32 = 0;
  70810. + hctsiz.b.xfersize = 8;
  70811. + hctsiz.b.pktcnt = 1;
  70812. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  70813. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70814. +
  70815. + /* Set HCCHAR */
  70816. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70817. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70818. + hcchar.b.epdir = 0;
  70819. + hcchar.b.epnum = 0;
  70820. + hcchar.b.mps = 8;
  70821. + hcchar.b.chen = 1;
  70822. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70823. +
  70824. + /* Fill FIFO with Setup data for Get Device Descriptor */
  70825. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  70826. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  70827. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  70828. +
  70829. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70830. +
  70831. + /* Wait for host channel interrupt */
  70832. + do {
  70833. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70834. + } while (gintsts.b.hcintr == 0);
  70835. +
  70836. + /* Disable HCINTs */
  70837. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  70838. +
  70839. + /* Disable HAINTs */
  70840. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  70841. +
  70842. + /* Read HAINT */
  70843. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70844. +
  70845. + /* Read HCINT */
  70846. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70847. +
  70848. + /* Read HCCHAR */
  70849. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70850. +
  70851. + /* Clear HCINT */
  70852. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70853. +
  70854. + /* Clear HAINT */
  70855. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70856. +
  70857. + /* Clear GINTSTS */
  70858. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70859. +
  70860. + /* Read GINTSTS */
  70861. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70862. +}
  70863. +
  70864. +static void do_in_ack(void)
  70865. +{
  70866. + gintsts_data_t gintsts;
  70867. + hctsiz_data_t hctsiz;
  70868. + hcchar_data_t hcchar;
  70869. + haint_data_t haint;
  70870. + hcint_data_t hcint;
  70871. + host_grxsts_data_t grxsts;
  70872. +
  70873. + /* Enable HAINTs */
  70874. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  70875. +
  70876. + /* Enable HCINTs */
  70877. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  70878. +
  70879. + /* Read GINTSTS */
  70880. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70881. +
  70882. + /* Read HAINT */
  70883. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70884. +
  70885. + /* Read HCINT */
  70886. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70887. +
  70888. + /* Read HCCHAR */
  70889. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70890. +
  70891. + /* Clear HCINT */
  70892. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70893. +
  70894. + /* Clear HAINT */
  70895. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70896. +
  70897. + /* Clear GINTSTS */
  70898. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70899. +
  70900. + /* Read GINTSTS */
  70901. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70902. +
  70903. + /*
  70904. + * Receive Control In packet
  70905. + */
  70906. +
  70907. + /* Make sure channel is disabled */
  70908. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70909. + if (hcchar.b.chen) {
  70910. + hcchar.b.chdis = 1;
  70911. + hcchar.b.chen = 1;
  70912. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70913. + //sleep(1);
  70914. + dwc_mdelay(1000);
  70915. +
  70916. + /* Read GINTSTS */
  70917. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70918. +
  70919. + /* Read HAINT */
  70920. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70921. +
  70922. + /* Read HCINT */
  70923. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70924. +
  70925. + /* Read HCCHAR */
  70926. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70927. +
  70928. + /* Clear HCINT */
  70929. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70930. +
  70931. + /* Clear HAINT */
  70932. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70933. +
  70934. + /* Clear GINTSTS */
  70935. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70936. +
  70937. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70938. + }
  70939. +
  70940. + /* Set HCTSIZ */
  70941. + hctsiz.d32 = 0;
  70942. + hctsiz.b.xfersize = 8;
  70943. + hctsiz.b.pktcnt = 1;
  70944. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  70945. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70946. +
  70947. + /* Set HCCHAR */
  70948. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70949. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70950. + hcchar.b.epdir = 1;
  70951. + hcchar.b.epnum = 0;
  70952. + hcchar.b.mps = 8;
  70953. + hcchar.b.chen = 1;
  70954. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70955. +
  70956. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70957. +
  70958. + /* Wait for receive status queue interrupt */
  70959. + do {
  70960. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70961. + } while (gintsts.b.rxstsqlvl == 0);
  70962. +
  70963. + /* Read RXSTS */
  70964. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  70965. +
  70966. + /* Clear RXSTSQLVL in GINTSTS */
  70967. + gintsts.d32 = 0;
  70968. + gintsts.b.rxstsqlvl = 1;
  70969. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70970. +
  70971. + switch (grxsts.b.pktsts) {
  70972. + case DWC_GRXSTS_PKTSTS_IN:
  70973. + /* Read the data into the host buffer */
  70974. + if (grxsts.b.bcnt > 0) {
  70975. + int i;
  70976. + int word_count = (grxsts.b.bcnt + 3) / 4;
  70977. +
  70978. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  70979. +
  70980. + for (i = 0; i < word_count; i++) {
  70981. + (void)DWC_READ_REG32(data_fifo++);
  70982. + }
  70983. + }
  70984. + break;
  70985. +
  70986. + default:
  70987. + break;
  70988. + }
  70989. +
  70990. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70991. +
  70992. + /* Wait for receive status queue interrupt */
  70993. + do {
  70994. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70995. + } while (gintsts.b.rxstsqlvl == 0);
  70996. +
  70997. + /* Read RXSTS */
  70998. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  70999. +
  71000. + /* Clear RXSTSQLVL in GINTSTS */
  71001. + gintsts.d32 = 0;
  71002. + gintsts.b.rxstsqlvl = 1;
  71003. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  71004. +
  71005. + switch (grxsts.b.pktsts) {
  71006. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  71007. + break;
  71008. +
  71009. + default:
  71010. + break;
  71011. + }
  71012. +
  71013. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71014. +
  71015. + /* Wait for host channel interrupt */
  71016. + do {
  71017. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71018. + } while (gintsts.b.hcintr == 0);
  71019. +
  71020. + /* Read HAINT */
  71021. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  71022. +
  71023. + /* Read HCINT */
  71024. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  71025. +
  71026. + /* Read HCCHAR */
  71027. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71028. +
  71029. + /* Clear HCINT */
  71030. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  71031. +
  71032. + /* Clear HAINT */
  71033. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  71034. +
  71035. + /* Clear GINTSTS */
  71036. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  71037. +
  71038. + /* Read GINTSTS */
  71039. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71040. +
  71041. +// usleep(100000);
  71042. +// mdelay(100);
  71043. + dwc_mdelay(1);
  71044. +
  71045. + /*
  71046. + * Send handshake packet
  71047. + */
  71048. +
  71049. + /* Read HAINT */
  71050. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  71051. +
  71052. + /* Read HCINT */
  71053. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  71054. +
  71055. + /* Read HCCHAR */
  71056. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71057. +
  71058. + /* Clear HCINT */
  71059. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  71060. +
  71061. + /* Clear HAINT */
  71062. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  71063. +
  71064. + /* Clear GINTSTS */
  71065. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  71066. +
  71067. + /* Read GINTSTS */
  71068. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71069. +
  71070. + /* Make sure channel is disabled */
  71071. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71072. + if (hcchar.b.chen) {
  71073. + hcchar.b.chdis = 1;
  71074. + hcchar.b.chen = 1;
  71075. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  71076. + //sleep(1);
  71077. + dwc_mdelay(1000);
  71078. +
  71079. + /* Read GINTSTS */
  71080. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71081. +
  71082. + /* Read HAINT */
  71083. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  71084. +
  71085. + /* Read HCINT */
  71086. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  71087. +
  71088. + /* Read HCCHAR */
  71089. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71090. +
  71091. + /* Clear HCINT */
  71092. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  71093. +
  71094. + /* Clear HAINT */
  71095. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  71096. +
  71097. + /* Clear GINTSTS */
  71098. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  71099. +
  71100. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71101. + }
  71102. +
  71103. + /* Set HCTSIZ */
  71104. + hctsiz.d32 = 0;
  71105. + hctsiz.b.xfersize = 0;
  71106. + hctsiz.b.pktcnt = 1;
  71107. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  71108. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  71109. +
  71110. + /* Set HCCHAR */
  71111. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71112. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  71113. + hcchar.b.epdir = 0;
  71114. + hcchar.b.epnum = 0;
  71115. + hcchar.b.mps = 8;
  71116. + hcchar.b.chen = 1;
  71117. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  71118. +
  71119. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71120. +
  71121. + /* Wait for host channel interrupt */
  71122. + do {
  71123. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71124. + } while (gintsts.b.hcintr == 0);
  71125. +
  71126. + /* Disable HCINTs */
  71127. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  71128. +
  71129. + /* Disable HAINTs */
  71130. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  71131. +
  71132. + /* Read HAINT */
  71133. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  71134. +
  71135. + /* Read HCINT */
  71136. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  71137. +
  71138. + /* Read HCCHAR */
  71139. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71140. +
  71141. + /* Clear HCINT */
  71142. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  71143. +
  71144. + /* Clear HAINT */
  71145. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  71146. +
  71147. + /* Clear GINTSTS */
  71148. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  71149. +
  71150. + /* Read GINTSTS */
  71151. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  71152. +}
  71153. +#endif
  71154. +
  71155. +/** Handles hub class-specific requests. */
  71156. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  71157. + uint16_t typeReq,
  71158. + uint16_t wValue,
  71159. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  71160. +{
  71161. + int retval = 0;
  71162. +
  71163. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  71164. + usb_hub_descriptor_t *hub_desc;
  71165. + hprt0_data_t hprt0 = {.d32 = 0 };
  71166. +
  71167. + uint32_t port_status;
  71168. +
  71169. + switch (typeReq) {
  71170. + case UCR_CLEAR_HUB_FEATURE:
  71171. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71172. + "ClearHubFeature 0x%x\n", wValue);
  71173. + switch (wValue) {
  71174. + case UHF_C_HUB_LOCAL_POWER:
  71175. + case UHF_C_HUB_OVER_CURRENT:
  71176. + /* Nothing required here */
  71177. + break;
  71178. + default:
  71179. + retval = -DWC_E_INVALID;
  71180. + DWC_ERROR("DWC OTG HCD - "
  71181. + "ClearHubFeature request %xh unknown\n",
  71182. + wValue);
  71183. + }
  71184. + break;
  71185. + case UCR_CLEAR_PORT_FEATURE:
  71186. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71187. + if (wValue != UHF_PORT_L1)
  71188. +#endif
  71189. + if (!wIndex || wIndex > 1)
  71190. + goto error;
  71191. +
  71192. + switch (wValue) {
  71193. + case UHF_PORT_ENABLE:
  71194. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  71195. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  71196. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71197. + hprt0.b.prtena = 1;
  71198. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71199. + break;
  71200. + case UHF_PORT_SUSPEND:
  71201. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71202. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  71203. +
  71204. + if (core_if->power_down == 2) {
  71205. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  71206. + } else {
  71207. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  71208. + dwc_mdelay(5);
  71209. +
  71210. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71211. + hprt0.b.prtres = 1;
  71212. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71213. + hprt0.b.prtsusp = 0;
  71214. + /* Clear Resume bit */
  71215. + dwc_mdelay(100);
  71216. + hprt0.b.prtres = 0;
  71217. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71218. + }
  71219. + break;
  71220. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71221. + case UHF_PORT_L1:
  71222. + {
  71223. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71224. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  71225. +
  71226. + lpmcfg.d32 =
  71227. + DWC_READ_REG32(&core_if->
  71228. + core_global_regs->glpmcfg);
  71229. + lpmcfg.b.en_utmi_sleep = 0;
  71230. + lpmcfg.b.hird_thres &= (~(1 << 4));
  71231. + lpmcfg.b.prt_sleep_sts = 1;
  71232. + DWC_WRITE_REG32(&core_if->
  71233. + core_global_regs->glpmcfg,
  71234. + lpmcfg.d32);
  71235. +
  71236. + /* Clear Enbl_L1Gating bit. */
  71237. + pcgcctl.b.enbl_sleep_gating = 1;
  71238. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  71239. + 0);
  71240. +
  71241. + dwc_mdelay(5);
  71242. +
  71243. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71244. + hprt0.b.prtres = 1;
  71245. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  71246. + hprt0.d32);
  71247. + /* This bit will be cleared in wakeup interrupt handle */
  71248. + break;
  71249. + }
  71250. +#endif
  71251. + case UHF_PORT_POWER:
  71252. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71253. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  71254. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71255. + hprt0.b.prtpwr = 0;
  71256. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71257. + break;
  71258. + case UHF_PORT_INDICATOR:
  71259. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71260. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  71261. + /* Port inidicator not supported */
  71262. + break;
  71263. + case UHF_C_PORT_CONNECTION:
  71264. + /* Clears drivers internal connect status change
  71265. + * flag */
  71266. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71267. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  71268. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  71269. + break;
  71270. + case UHF_C_PORT_RESET:
  71271. + /* Clears the driver's internal Port Reset Change
  71272. + * flag */
  71273. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71274. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  71275. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  71276. + break;
  71277. + case UHF_C_PORT_ENABLE:
  71278. + /* Clears the driver's internal Port
  71279. + * Enable/Disable Change flag */
  71280. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71281. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  71282. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  71283. + break;
  71284. + case UHF_C_PORT_SUSPEND:
  71285. + /* Clears the driver's internal Port Suspend
  71286. + * Change flag, which is set when resume signaling on
  71287. + * the host port is complete */
  71288. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71289. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  71290. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  71291. + break;
  71292. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71293. + case UHF_C_PORT_L1:
  71294. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  71295. + break;
  71296. +#endif
  71297. + case UHF_C_PORT_OVER_CURRENT:
  71298. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71299. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  71300. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  71301. + break;
  71302. + default:
  71303. + retval = -DWC_E_INVALID;
  71304. + DWC_ERROR("DWC OTG HCD - "
  71305. + "ClearPortFeature request %xh "
  71306. + "unknown or unsupported\n", wValue);
  71307. + }
  71308. + break;
  71309. + case UCR_GET_HUB_DESCRIPTOR:
  71310. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71311. + "GetHubDescriptor\n");
  71312. + hub_desc = (usb_hub_descriptor_t *) buf;
  71313. + hub_desc->bDescLength = 9;
  71314. + hub_desc->bDescriptorType = 0x29;
  71315. + hub_desc->bNbrPorts = 1;
  71316. + USETW(hub_desc->wHubCharacteristics, 0x08);
  71317. + hub_desc->bPwrOn2PwrGood = 1;
  71318. + hub_desc->bHubContrCurrent = 0;
  71319. + hub_desc->DeviceRemovable[0] = 0;
  71320. + hub_desc->DeviceRemovable[1] = 0xff;
  71321. + break;
  71322. + case UCR_GET_HUB_STATUS:
  71323. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71324. + "GetHubStatus\n");
  71325. + DWC_MEMSET(buf, 0, 4);
  71326. + break;
  71327. + case UCR_GET_PORT_STATUS:
  71328. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71329. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  71330. + wIndex, dwc_otg_hcd->flags.d32);
  71331. + if (!wIndex || wIndex > 1)
  71332. + goto error;
  71333. +
  71334. + port_status = 0;
  71335. +
  71336. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  71337. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  71338. +
  71339. + if (dwc_otg_hcd->flags.b.port_enable_change)
  71340. + port_status |= (1 << UHF_C_PORT_ENABLE);
  71341. +
  71342. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  71343. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  71344. +
  71345. + if (dwc_otg_hcd->flags.b.port_l1_change)
  71346. + port_status |= (1 << UHF_C_PORT_L1);
  71347. +
  71348. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  71349. + port_status |= (1 << UHF_C_PORT_RESET);
  71350. + }
  71351. +
  71352. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  71353. + DWC_WARN("Overcurrent change detected\n");
  71354. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  71355. + }
  71356. +
  71357. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  71358. + /*
  71359. + * The port is disconnected, which means the core is
  71360. + * either in device mode or it soon will be. Just
  71361. + * return 0's for the remainder of the port status
  71362. + * since the port register can't be read if the core
  71363. + * is in device mode.
  71364. + */
  71365. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  71366. + break;
  71367. + }
  71368. +
  71369. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  71370. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  71371. +
  71372. + if (hprt0.b.prtconnsts)
  71373. + port_status |= (1 << UHF_PORT_CONNECTION);
  71374. +
  71375. + if (hprt0.b.prtena)
  71376. + port_status |= (1 << UHF_PORT_ENABLE);
  71377. +
  71378. + if (hprt0.b.prtsusp)
  71379. + port_status |= (1 << UHF_PORT_SUSPEND);
  71380. +
  71381. + if (hprt0.b.prtovrcurract)
  71382. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  71383. +
  71384. + if (hprt0.b.prtrst)
  71385. + port_status |= (1 << UHF_PORT_RESET);
  71386. +
  71387. + if (hprt0.b.prtpwr)
  71388. + port_status |= (1 << UHF_PORT_POWER);
  71389. +
  71390. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  71391. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  71392. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  71393. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  71394. +
  71395. + if (hprt0.b.prttstctl)
  71396. + port_status |= (1 << UHF_PORT_TEST);
  71397. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  71398. + port_status |= (1 << UHF_PORT_L1);
  71399. + }
  71400. + /*
  71401. + For Synopsys HW emulation of Power down wkup_control asserts the
  71402. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  71403. + We intentionally tell the software that port is in L2Suspend state.
  71404. + Only for STE.
  71405. + */
  71406. + if ((core_if->power_down == 2)
  71407. + && (core_if->hibernation_suspend == 1)) {
  71408. + port_status |= (1 << UHF_PORT_SUSPEND);
  71409. + }
  71410. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  71411. +
  71412. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  71413. +
  71414. + break;
  71415. + case UCR_SET_HUB_FEATURE:
  71416. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71417. + "SetHubFeature\n");
  71418. + /* No HUB features supported */
  71419. + break;
  71420. + case UCR_SET_PORT_FEATURE:
  71421. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  71422. + goto error;
  71423. +
  71424. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  71425. + /*
  71426. + * The port is disconnected, which means the core is
  71427. + * either in device mode or it soon will be. Just
  71428. + * return without doing anything since the port
  71429. + * register can't be written if the core is in device
  71430. + * mode.
  71431. + */
  71432. + break;
  71433. + }
  71434. +
  71435. + switch (wValue) {
  71436. + case UHF_PORT_SUSPEND:
  71437. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71438. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  71439. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  71440. + goto error;
  71441. + }
  71442. + if (core_if->power_down == 2) {
  71443. + int timeout = 300;
  71444. + dwc_irqflags_t flags;
  71445. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71446. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  71447. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  71448. +#ifdef DWC_DEV_SRPCAP
  71449. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  71450. +#endif
  71451. + DWC_PRINTF("Preparing for complete power-off\n");
  71452. +
  71453. + /* Save registers before hibernation */
  71454. + dwc_otg_save_global_regs(core_if);
  71455. + dwc_otg_save_host_regs(core_if);
  71456. +
  71457. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71458. + hprt0.b.prtsusp = 1;
  71459. + hprt0.b.prtena = 0;
  71460. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71461. + /* Spin hprt0.b.prtsusp to became 1 */
  71462. + do {
  71463. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71464. + if (hprt0.b.prtsusp) {
  71465. + break;
  71466. + }
  71467. + dwc_mdelay(1);
  71468. + } while (--timeout);
  71469. + if (!timeout) {
  71470. + DWC_WARN("Suspend wasn't genereted\n");
  71471. + }
  71472. + dwc_udelay(10);
  71473. +
  71474. + /*
  71475. + * We need to disable interrupts to prevent servicing of any IRQ
  71476. + * during going to hibernation
  71477. + */
  71478. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  71479. + core_if->lx_state = DWC_OTG_L2;
  71480. +#ifdef DWC_DEV_SRPCAP
  71481. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71482. + hprt0.b.prtpwr = 0;
  71483. + hprt0.b.prtena = 0;
  71484. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  71485. + hprt0.d32);
  71486. +#endif
  71487. + gusbcfg.d32 =
  71488. + DWC_READ_REG32(&core_if->core_global_regs->
  71489. + gusbcfg);
  71490. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  71491. + /* ULPI interface */
  71492. + /* Suspend the Phy Clock */
  71493. + pcgcctl.d32 = 0;
  71494. + pcgcctl.b.stoppclk = 1;
  71495. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  71496. + pcgcctl.d32);
  71497. + dwc_udelay(10);
  71498. + gpwrdn.b.pmuactv = 1;
  71499. + DWC_MODIFY_REG32(&core_if->
  71500. + core_global_regs->
  71501. + gpwrdn, 0, gpwrdn.d32);
  71502. + } else {
  71503. + /* UTMI+ Interface */
  71504. + gpwrdn.b.pmuactv = 1;
  71505. + DWC_MODIFY_REG32(&core_if->
  71506. + core_global_regs->
  71507. + gpwrdn, 0, gpwrdn.d32);
  71508. + dwc_udelay(10);
  71509. + pcgcctl.b.stoppclk = 1;
  71510. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  71511. + dwc_udelay(10);
  71512. + }
  71513. +#ifdef DWC_DEV_SRPCAP
  71514. + gpwrdn.d32 = 0;
  71515. + gpwrdn.b.dis_vbus = 1;
  71516. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71517. + gpwrdn, 0, gpwrdn.d32);
  71518. +#endif
  71519. + gpwrdn.d32 = 0;
  71520. + gpwrdn.b.pmuintsel = 1;
  71521. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71522. + gpwrdn, 0, gpwrdn.d32);
  71523. + dwc_udelay(10);
  71524. +
  71525. + gpwrdn.d32 = 0;
  71526. +#ifdef DWC_DEV_SRPCAP
  71527. + gpwrdn.b.srp_det_msk = 1;
  71528. +#endif
  71529. + gpwrdn.b.disconn_det_msk = 1;
  71530. + gpwrdn.b.lnstchng_msk = 1;
  71531. + gpwrdn.b.sts_chngint_msk = 1;
  71532. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71533. + gpwrdn, 0, gpwrdn.d32);
  71534. + dwc_udelay(10);
  71535. +
  71536. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  71537. + gpwrdn.d32 = 0;
  71538. + gpwrdn.b.pwrdnclmp = 1;
  71539. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71540. + gpwrdn, 0, gpwrdn.d32);
  71541. + dwc_udelay(10);
  71542. +
  71543. + /* Switch off VDD */
  71544. + gpwrdn.d32 = 0;
  71545. + gpwrdn.b.pwrdnswtch = 1;
  71546. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71547. + gpwrdn, 0, gpwrdn.d32);
  71548. +
  71549. +#ifdef DWC_DEV_SRPCAP
  71550. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  71551. + {
  71552. + core_if->pwron_timer_started = 1;
  71553. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  71554. + }
  71555. +#endif
  71556. + /* Save gpwrdn register for further usage if stschng interrupt */
  71557. + core_if->gr_backup->gpwrdn_local =
  71558. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  71559. +
  71560. + /* Set flag to indicate that we are in hibernation */
  71561. + core_if->hibernation_suspend = 1;
  71562. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  71563. +
  71564. + DWC_PRINTF("Host hibernation completed\n");
  71565. + // Exit from case statement
  71566. + break;
  71567. +
  71568. + }
  71569. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  71570. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  71571. + gotgctl_data_t gotgctl = {.d32 = 0 };
  71572. + gotgctl.b.hstsethnpen = 1;
  71573. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71574. + gotgctl, 0, gotgctl.d32);
  71575. + core_if->op_state = A_SUSPEND;
  71576. + }
  71577. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71578. + hprt0.b.prtsusp = 1;
  71579. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71580. + {
  71581. + dwc_irqflags_t flags;
  71582. + /* Update lx_state */
  71583. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  71584. + core_if->lx_state = DWC_OTG_L2;
  71585. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  71586. + }
  71587. + /* Suspend the Phy Clock */
  71588. + {
  71589. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71590. + pcgcctl.b.stoppclk = 1;
  71591. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  71592. + pcgcctl.d32);
  71593. + dwc_udelay(10);
  71594. + }
  71595. +
  71596. + /* For HNP the bus must be suspended for at least 200ms. */
  71597. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  71598. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71599. + pcgcctl.b.stoppclk = 1;
  71600. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  71601. + dwc_mdelay(200);
  71602. + }
  71603. +
  71604. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  71605. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  71606. + if (core_if->adp_enable) {
  71607. + gotgctl_data_t gotgctl = {.d32 = 0 };
  71608. + gpwrdn_data_t gpwrdn;
  71609. +
  71610. + while (gotgctl.b.asesvld == 1) {
  71611. + gotgctl.d32 =
  71612. + DWC_READ_REG32(&core_if->
  71613. + core_global_regs->
  71614. + gotgctl);
  71615. + dwc_mdelay(100);
  71616. + }
  71617. +
  71618. + /* Enable Power Down Logic */
  71619. + gpwrdn.d32 = 0;
  71620. + gpwrdn.b.pmuactv = 1;
  71621. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71622. + gpwrdn, 0, gpwrdn.d32);
  71623. +
  71624. + /* Unmask SRP detected interrupt from Power Down Logic */
  71625. + gpwrdn.d32 = 0;
  71626. + gpwrdn.b.srp_det_msk = 1;
  71627. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71628. + gpwrdn, 0, gpwrdn.d32);
  71629. +
  71630. + dwc_otg_adp_probe_start(core_if);
  71631. + }
  71632. +#endif
  71633. + break;
  71634. + case UHF_PORT_POWER:
  71635. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71636. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  71637. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71638. + hprt0.b.prtpwr = 1;
  71639. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71640. + break;
  71641. + case UHF_PORT_RESET:
  71642. + if ((core_if->power_down == 2)
  71643. + && (core_if->hibernation_suspend == 1)) {
  71644. + /* If we are going to exit from Hibernated
  71645. + * state via USB RESET.
  71646. + */
  71647. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  71648. + } else {
  71649. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71650. +
  71651. + DWC_DEBUGPL(DBG_HCD,
  71652. + "DWC OTG HCD HUB CONTROL - "
  71653. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  71654. + {
  71655. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71656. + pcgcctl.b.enbl_sleep_gating = 1;
  71657. + pcgcctl.b.stoppclk = 1;
  71658. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  71659. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  71660. + }
  71661. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71662. + {
  71663. + glpmcfg_data_t lpmcfg;
  71664. + lpmcfg.d32 =
  71665. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71666. + if (lpmcfg.b.prt_sleep_sts) {
  71667. + lpmcfg.b.en_utmi_sleep = 0;
  71668. + lpmcfg.b.hird_thres &= (~(1 << 4));
  71669. + DWC_WRITE_REG32
  71670. + (&core_if->core_global_regs->glpmcfg,
  71671. + lpmcfg.d32);
  71672. + dwc_mdelay(1);
  71673. + }
  71674. + }
  71675. +#endif
  71676. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71677. + /* Clear suspend bit if resetting from suspended state. */
  71678. + hprt0.b.prtsusp = 0;
  71679. + /* When B-Host the Port reset bit is set in
  71680. + * the Start HCD Callback function, so that
  71681. + * the reset is started within 1ms of the HNP
  71682. + * success interrupt. */
  71683. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  71684. + hprt0.b.prtpwr = 1;
  71685. + hprt0.b.prtrst = 1;
  71686. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  71687. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  71688. + hprt0.d32);
  71689. + }
  71690. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  71691. + dwc_mdelay(60);
  71692. + hprt0.b.prtrst = 0;
  71693. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71694. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  71695. + }
  71696. + break;
  71697. +#ifdef DWC_HS_ELECT_TST
  71698. + case UHF_PORT_TEST:
  71699. + {
  71700. + uint32_t t;
  71701. + gintmsk_data_t gintmsk;
  71702. +
  71703. + t = (wIndex >> 8); /* MSB wIndex USB */
  71704. + DWC_DEBUGPL(DBG_HCD,
  71705. + "DWC OTG HCD HUB CONTROL - "
  71706. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  71707. + t);
  71708. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  71709. + if (t < 6) {
  71710. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71711. + hprt0.b.prttstctl = t;
  71712. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  71713. + hprt0.d32);
  71714. + } else {
  71715. + /* Setup global vars with reg addresses (quick and
  71716. + * dirty hack, should be cleaned up)
  71717. + */
  71718. + global_regs = core_if->core_global_regs;
  71719. + hc_global_regs =
  71720. + core_if->host_if->host_global_regs;
  71721. + hc_regs =
  71722. + (dwc_otg_hc_regs_t *) ((char *)
  71723. + global_regs +
  71724. + 0x500);
  71725. + data_fifo =
  71726. + (uint32_t *) ((char *)global_regs +
  71727. + 0x1000);
  71728. +
  71729. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  71730. + /* Save current interrupt mask */
  71731. + gintmsk.d32 =
  71732. + DWC_READ_REG32
  71733. + (&global_regs->gintmsk);
  71734. +
  71735. + /* Disable all interrupts while we muck with
  71736. + * the hardware directly
  71737. + */
  71738. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  71739. +
  71740. + /* 15 second delay per the test spec */
  71741. + dwc_mdelay(15000);
  71742. +
  71743. + /* Drive suspend on the root port */
  71744. + hprt0.d32 =
  71745. + dwc_otg_read_hprt0(core_if);
  71746. + hprt0.b.prtsusp = 1;
  71747. + hprt0.b.prtres = 0;
  71748. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71749. +
  71750. + /* 15 second delay per the test spec */
  71751. + dwc_mdelay(15000);
  71752. +
  71753. + /* Drive resume on the root port */
  71754. + hprt0.d32 =
  71755. + dwc_otg_read_hprt0(core_if);
  71756. + hprt0.b.prtsusp = 0;
  71757. + hprt0.b.prtres = 1;
  71758. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71759. + dwc_mdelay(100);
  71760. +
  71761. + /* Clear the resume bit */
  71762. + hprt0.b.prtres = 0;
  71763. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71764. +
  71765. + /* Restore interrupts */
  71766. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  71767. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  71768. + /* Save current interrupt mask */
  71769. + gintmsk.d32 =
  71770. + DWC_READ_REG32
  71771. + (&global_regs->gintmsk);
  71772. +
  71773. + /* Disable all interrupts while we muck with
  71774. + * the hardware directly
  71775. + */
  71776. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  71777. +
  71778. + /* 15 second delay per the test spec */
  71779. + dwc_mdelay(15000);
  71780. +
  71781. + /* Send the Setup packet */
  71782. + do_setup();
  71783. +
  71784. + /* 15 second delay so nothing else happens for awhile */
  71785. + dwc_mdelay(15000);
  71786. +
  71787. + /* Restore interrupts */
  71788. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  71789. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  71790. + /* Save current interrupt mask */
  71791. + gintmsk.d32 =
  71792. + DWC_READ_REG32
  71793. + (&global_regs->gintmsk);
  71794. +
  71795. + /* Disable all interrupts while we muck with
  71796. + * the hardware directly
  71797. + */
  71798. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  71799. +
  71800. + /* Send the Setup packet */
  71801. + do_setup();
  71802. +
  71803. + /* 15 second delay so nothing else happens for awhile */
  71804. + dwc_mdelay(15000);
  71805. +
  71806. + /* Send the In and Ack packets */
  71807. + do_in_ack();
  71808. +
  71809. + /* 15 second delay so nothing else happens for awhile */
  71810. + dwc_mdelay(15000);
  71811. +
  71812. + /* Restore interrupts */
  71813. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  71814. + }
  71815. + }
  71816. + break;
  71817. + }
  71818. +#endif /* DWC_HS_ELECT_TST */
  71819. +
  71820. + case UHF_PORT_INDICATOR:
  71821. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71822. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  71823. + /* Not supported */
  71824. + break;
  71825. + default:
  71826. + retval = -DWC_E_INVALID;
  71827. + DWC_ERROR("DWC OTG HCD - "
  71828. + "SetPortFeature request %xh "
  71829. + "unknown or unsupported\n", wValue);
  71830. + break;
  71831. + }
  71832. + break;
  71833. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71834. + case UCR_SET_AND_TEST_PORT_FEATURE:
  71835. + if (wValue != UHF_PORT_L1) {
  71836. + goto error;
  71837. + }
  71838. + {
  71839. + int portnum, hird, devaddr, remwake;
  71840. + glpmcfg_data_t lpmcfg;
  71841. + uint32_t time_usecs;
  71842. + gintsts_data_t gintsts;
  71843. + gintmsk_data_t gintmsk;
  71844. +
  71845. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  71846. + goto error;
  71847. + }
  71848. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  71849. + goto error;
  71850. + }
  71851. + /* Check if the port currently is in SLEEP state */
  71852. + lpmcfg.d32 =
  71853. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71854. + if (lpmcfg.b.prt_sleep_sts) {
  71855. + DWC_INFO("Port is already in sleep mode\n");
  71856. + buf[0] = 0; /* Return success */
  71857. + break;
  71858. + }
  71859. +
  71860. + portnum = wIndex & 0xf;
  71861. + hird = (wIndex >> 4) & 0xf;
  71862. + devaddr = (wIndex >> 8) & 0x7f;
  71863. + remwake = (wIndex >> 15);
  71864. +
  71865. + if (portnum != 1) {
  71866. + retval = -DWC_E_INVALID;
  71867. + DWC_WARN
  71868. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  71869. + portnum);
  71870. + break;
  71871. + }
  71872. +
  71873. + DWC_PRINTF
  71874. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  71875. + portnum, hird, devaddr, remwake);
  71876. + /* Disable LPM interrupt */
  71877. + gintmsk.d32 = 0;
  71878. + gintmsk.b.lpmtranrcvd = 1;
  71879. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  71880. + gintmsk.d32, 0);
  71881. +
  71882. + if (dwc_otg_hcd_send_lpm
  71883. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  71884. + retval = -DWC_E_INVALID;
  71885. + break;
  71886. + }
  71887. +
  71888. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  71889. + /* We will consider timeout if time_usecs microseconds pass,
  71890. + * and we don't receive LPM transaction status.
  71891. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  71892. + * core will set lpmtranrcvd bit.
  71893. + */
  71894. + do {
  71895. + gintsts.d32 =
  71896. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  71897. + if (gintsts.b.lpmtranrcvd) {
  71898. + break;
  71899. + }
  71900. + dwc_udelay(1);
  71901. + } while (--time_usecs);
  71902. + /* lpm_int bit will be cleared in LPM interrupt handler */
  71903. +
  71904. + /* Now fill status
  71905. + * 0x00 - Success
  71906. + * 0x10 - NYET
  71907. + * 0x11 - Timeout
  71908. + */
  71909. + if (!gintsts.b.lpmtranrcvd) {
  71910. + buf[0] = 0x3; /* Completion code is Timeout */
  71911. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  71912. + } else {
  71913. + lpmcfg.d32 =
  71914. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71915. + if (lpmcfg.b.lpm_resp == 0x3) {
  71916. + /* ACK responce from the device */
  71917. + buf[0] = 0x00; /* Success */
  71918. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  71919. + /* NYET responce from the device */
  71920. + buf[0] = 0x2;
  71921. + } else {
  71922. + /* Otherwise responce with Timeout */
  71923. + buf[0] = 0x3;
  71924. + }
  71925. + }
  71926. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  71927. + lpmcfg.b.lpm_resp);
  71928. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  71929. + gintmsk.d32);
  71930. +
  71931. + break;
  71932. + }
  71933. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  71934. + default:
  71935. +error:
  71936. + retval = -DWC_E_INVALID;
  71937. + DWC_WARN("DWC OTG HCD - "
  71938. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  71939. + typeReq, wIndex, wValue);
  71940. + break;
  71941. + }
  71942. +
  71943. + return retval;
  71944. +}
  71945. +
  71946. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71947. +/** Returns index of host channel to perform LPM transaction. */
  71948. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  71949. +{
  71950. + dwc_otg_core_if_t *core_if = hcd->core_if;
  71951. + dwc_hc_t *hc;
  71952. + hcchar_data_t hcchar;
  71953. + gintmsk_data_t gintmsk = {.d32 = 0 };
  71954. +
  71955. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71956. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  71957. + return -1;
  71958. + }
  71959. +
  71960. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  71961. +
  71962. + /* Mask host channel interrupts. */
  71963. + gintmsk.b.hcintr = 1;
  71964. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  71965. +
  71966. + /* Fill fields that core needs for LPM transaction */
  71967. + hcchar.b.devaddr = devaddr;
  71968. + hcchar.b.epnum = 0;
  71969. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  71970. + hcchar.b.mps = 64;
  71971. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  71972. + hcchar.b.epdir = 0; /* OUT */
  71973. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  71974. + hcchar.d32);
  71975. +
  71976. + /* Remove the host channel from the free list. */
  71977. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  71978. +
  71979. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  71980. +
  71981. + return hc->hc_num;
  71982. +}
  71983. +
  71984. +/** Release hc after performing LPM transaction */
  71985. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  71986. +{
  71987. + dwc_hc_t *hc;
  71988. + glpmcfg_data_t lpmcfg;
  71989. + uint8_t hc_num;
  71990. +
  71991. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  71992. + hc_num = lpmcfg.b.lpm_chan_index;
  71993. +
  71994. + hc = hcd->hc_ptr_array[hc_num];
  71995. +
  71996. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  71997. + /* Return host channel to free list */
  71998. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  71999. +}
  72000. +
  72001. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  72002. + uint8_t bRemoteWake)
  72003. +{
  72004. + glpmcfg_data_t lpmcfg;
  72005. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72006. + int channel;
  72007. +
  72008. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  72009. + if (channel < 0) {
  72010. + return channel;
  72011. + }
  72012. +
  72013. + pcgcctl.b.enbl_sleep_gating = 1;
  72014. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  72015. +
  72016. + /* Read LPM config register */
  72017. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  72018. +
  72019. + /* Program LPM transaction fields */
  72020. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  72021. + lpmcfg.b.hird = hird;
  72022. + lpmcfg.b.hird_thres = 0x1c;
  72023. + lpmcfg.b.lpm_chan_index = channel;
  72024. + lpmcfg.b.en_utmi_sleep = 1;
  72025. + /* Program LPM config register */
  72026. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  72027. +
  72028. + /* Send LPM transaction */
  72029. + lpmcfg.b.send_lpm = 1;
  72030. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  72031. +
  72032. + return 0;
  72033. +}
  72034. +
  72035. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  72036. +
  72037. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  72038. +{
  72039. + int retval;
  72040. +
  72041. + if (port != 1) {
  72042. + return -DWC_E_INVALID;
  72043. + }
  72044. +
  72045. + retval = (hcd->flags.b.port_connect_status_change ||
  72046. + hcd->flags.b.port_reset_change ||
  72047. + hcd->flags.b.port_enable_change ||
  72048. + hcd->flags.b.port_suspend_change ||
  72049. + hcd->flags.b.port_over_current_change);
  72050. +#ifdef DEBUG
  72051. + if (retval) {
  72052. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  72053. + " Root port status changed\n");
  72054. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  72055. + hcd->flags.b.port_connect_status_change);
  72056. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  72057. + hcd->flags.b.port_reset_change);
  72058. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  72059. + hcd->flags.b.port_enable_change);
  72060. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  72061. + hcd->flags.b.port_suspend_change);
  72062. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  72063. + hcd->flags.b.port_over_current_change);
  72064. + }
  72065. +#endif
  72066. + return retval;
  72067. +}
  72068. +
  72069. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  72070. +{
  72071. + hfnum_data_t hfnum;
  72072. + hfnum.d32 =
  72073. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  72074. + hfnum);
  72075. +
  72076. +#ifdef DEBUG_SOF
  72077. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  72078. + hfnum.b.frnum);
  72079. +#endif
  72080. + return hfnum.b.frnum;
  72081. +}
  72082. +
  72083. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  72084. + struct dwc_otg_hcd_function_ops *fops)
  72085. +{
  72086. + int retval = 0;
  72087. +
  72088. + hcd->fops = fops;
  72089. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  72090. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  72091. + dwc_otg_hcd_reinit(hcd);
  72092. + } else {
  72093. + retval = -DWC_E_NO_DEVICE;
  72094. + }
  72095. +
  72096. + return retval;
  72097. +}
  72098. +
  72099. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  72100. +{
  72101. + return hcd->priv;
  72102. +}
  72103. +
  72104. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  72105. +{
  72106. + hcd->priv = priv_data;
  72107. +}
  72108. +
  72109. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  72110. +{
  72111. + return hcd->otg_port;
  72112. +}
  72113. +
  72114. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  72115. +{
  72116. + uint32_t is_b_host;
  72117. + if (hcd->core_if->op_state == B_HOST) {
  72118. + is_b_host = 1;
  72119. + } else {
  72120. + is_b_host = 0;
  72121. + }
  72122. +
  72123. + return is_b_host;
  72124. +}
  72125. +
  72126. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  72127. + int iso_desc_count, int atomic_alloc)
  72128. +{
  72129. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  72130. + uint32_t size;
  72131. +
  72132. + size =
  72133. + sizeof(*dwc_otg_urb) +
  72134. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  72135. + if (atomic_alloc)
  72136. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  72137. + else
  72138. + dwc_otg_urb = DWC_ALLOC(size);
  72139. +
  72140. + if (dwc_otg_urb)
  72141. + dwc_otg_urb->packet_count = iso_desc_count;
  72142. + else {
  72143. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  72144. + "%salloc of %db failed\n",
  72145. + atomic_alloc?"atomic ":"", size);
  72146. + }
  72147. + return dwc_otg_urb;
  72148. +}
  72149. +
  72150. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  72151. + uint8_t dev_addr, uint8_t ep_num,
  72152. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  72153. +{
  72154. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  72155. + ep_type, ep_dir, mps);
  72156. +#if 0
  72157. + DWC_PRINTF
  72158. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  72159. + dev_addr, ep_num, ep_dir, ep_type, mps);
  72160. +#endif
  72161. +}
  72162. +
  72163. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  72164. + void *urb_handle, void *buf, dwc_dma_t dma,
  72165. + uint32_t buflen, void *setup_packet,
  72166. + dwc_dma_t setup_dma, uint32_t flags,
  72167. + uint16_t interval)
  72168. +{
  72169. + dwc_otg_urb->priv = urb_handle;
  72170. + dwc_otg_urb->buf = buf;
  72171. + dwc_otg_urb->dma = dma;
  72172. + dwc_otg_urb->length = buflen;
  72173. + dwc_otg_urb->setup_packet = setup_packet;
  72174. + dwc_otg_urb->setup_dma = setup_dma;
  72175. + dwc_otg_urb->flags = flags;
  72176. + dwc_otg_urb->interval = interval;
  72177. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  72178. +}
  72179. +
  72180. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  72181. +{
  72182. + return dwc_otg_urb->status;
  72183. +}
  72184. +
  72185. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  72186. +{
  72187. + return dwc_otg_urb->actual_length;
  72188. +}
  72189. +
  72190. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  72191. +{
  72192. + return dwc_otg_urb->error_count;
  72193. +}
  72194. +
  72195. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  72196. + int desc_num, uint32_t offset,
  72197. + uint32_t length)
  72198. +{
  72199. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  72200. + dwc_otg_urb->iso_descs[desc_num].length = length;
  72201. +}
  72202. +
  72203. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  72204. + int desc_num)
  72205. +{
  72206. + return dwc_otg_urb->iso_descs[desc_num].status;
  72207. +}
  72208. +
  72209. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  72210. + dwc_otg_urb, int desc_num)
  72211. +{
  72212. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  72213. +}
  72214. +
  72215. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  72216. +{
  72217. + int allocated = 0;
  72218. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  72219. +
  72220. + if (qh) {
  72221. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  72222. + allocated = 1;
  72223. + }
  72224. + }
  72225. + return allocated;
  72226. +}
  72227. +
  72228. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  72229. +{
  72230. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  72231. + int freed = 0;
  72232. + DWC_ASSERT(qh, "qh is not allocated\n");
  72233. +
  72234. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  72235. + freed = 1;
  72236. + }
  72237. +
  72238. + return freed;
  72239. +}
  72240. +
  72241. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  72242. +{
  72243. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  72244. + DWC_ASSERT(qh, "qh is not allocated\n");
  72245. + return qh->usecs;
  72246. +}
  72247. +
  72248. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  72249. +{
  72250. +#ifdef DEBUG
  72251. + int num_channels;
  72252. + int i;
  72253. + gnptxsts_data_t np_tx_status;
  72254. + hptxsts_data_t p_tx_status;
  72255. +
  72256. + num_channels = hcd->core_if->core_params->host_channels;
  72257. + DWC_PRINTF("\n");
  72258. + DWC_PRINTF
  72259. + ("************************************************************\n");
  72260. + DWC_PRINTF("HCD State:\n");
  72261. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  72262. + for (i = 0; i < num_channels; i++) {
  72263. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  72264. + DWC_PRINTF(" Channel %d:\n", i);
  72265. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  72266. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  72267. + DWC_PRINTF(" speed: %d\n", hc->speed);
  72268. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  72269. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  72270. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  72271. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  72272. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  72273. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  72274. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  72275. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  72276. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  72277. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  72278. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  72279. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  72280. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  72281. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  72282. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  72283. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  72284. + DWC_PRINTF(" requests: %d\n", hc->requests);
  72285. + DWC_PRINTF(" qh: %p\n", hc->qh);
  72286. + if (hc->xfer_started) {
  72287. + hfnum_data_t hfnum;
  72288. + hcchar_data_t hcchar;
  72289. + hctsiz_data_t hctsiz;
  72290. + hcint_data_t hcint;
  72291. + hcintmsk_data_t hcintmsk;
  72292. + hfnum.d32 =
  72293. + DWC_READ_REG32(&hcd->core_if->
  72294. + host_if->host_global_regs->hfnum);
  72295. + hcchar.d32 =
  72296. + DWC_READ_REG32(&hcd->core_if->host_if->
  72297. + hc_regs[i]->hcchar);
  72298. + hctsiz.d32 =
  72299. + DWC_READ_REG32(&hcd->core_if->host_if->
  72300. + hc_regs[i]->hctsiz);
  72301. + hcint.d32 =
  72302. + DWC_READ_REG32(&hcd->core_if->host_if->
  72303. + hc_regs[i]->hcint);
  72304. + hcintmsk.d32 =
  72305. + DWC_READ_REG32(&hcd->core_if->host_if->
  72306. + hc_regs[i]->hcintmsk);
  72307. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  72308. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  72309. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  72310. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  72311. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  72312. + }
  72313. + if (hc->xfer_started && hc->qh) {
  72314. + dwc_otg_qtd_t *qtd;
  72315. + dwc_otg_hcd_urb_t *urb;
  72316. +
  72317. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  72318. + if (!qtd->in_process)
  72319. + break;
  72320. +
  72321. + urb = qtd->urb;
  72322. + DWC_PRINTF(" URB Info:\n");
  72323. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  72324. + if (urb) {
  72325. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  72326. + dwc_otg_hcd_get_dev_addr(&urb->
  72327. + pipe_info),
  72328. + dwc_otg_hcd_get_ep_num(&urb->
  72329. + pipe_info),
  72330. + dwc_otg_hcd_is_pipe_in(&urb->
  72331. + pipe_info) ?
  72332. + "IN" : "OUT");
  72333. + DWC_PRINTF(" Max packet size: %d\n",
  72334. + dwc_otg_hcd_get_mps(&urb->
  72335. + pipe_info));
  72336. + DWC_PRINTF(" transfer_buffer: %p\n",
  72337. + urb->buf);
  72338. + DWC_PRINTF(" transfer_dma: %p\n",
  72339. + (void *)urb->dma);
  72340. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  72341. + urb->length);
  72342. + DWC_PRINTF(" actual_length: %d\n",
  72343. + urb->actual_length);
  72344. + }
  72345. + }
  72346. + }
  72347. + }
  72348. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  72349. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  72350. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  72351. + np_tx_status.d32 =
  72352. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  72353. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  72354. + np_tx_status.b.nptxqspcavail);
  72355. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  72356. + np_tx_status.b.nptxfspcavail);
  72357. + p_tx_status.d32 =
  72358. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  72359. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  72360. + p_tx_status.b.ptxqspcavail);
  72361. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  72362. + dwc_otg_hcd_dump_frrem(hcd);
  72363. + dwc_otg_dump_global_registers(hcd->core_if);
  72364. + dwc_otg_dump_host_registers(hcd->core_if);
  72365. + DWC_PRINTF
  72366. + ("************************************************************\n");
  72367. + DWC_PRINTF("\n");
  72368. +#endif
  72369. +}
  72370. +
  72371. +#ifdef DEBUG
  72372. +void dwc_print_setup_data(uint8_t * setup)
  72373. +{
  72374. + int i;
  72375. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  72376. + DWC_PRINTF("Setup Data = MSB ");
  72377. + for (i = 7; i >= 0; i--)
  72378. + DWC_PRINTF("%02x ", setup[i]);
  72379. + DWC_PRINTF("\n");
  72380. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  72381. + (setup[0] & 0x80) ? "Device-to-Host" :
  72382. + "Host-to-Device");
  72383. + DWC_PRINTF(" bmRequestType Type = ");
  72384. + switch ((setup[0] & 0x60) >> 5) {
  72385. + case 0:
  72386. + DWC_PRINTF("Standard\n");
  72387. + break;
  72388. + case 1:
  72389. + DWC_PRINTF("Class\n");
  72390. + break;
  72391. + case 2:
  72392. + DWC_PRINTF("Vendor\n");
  72393. + break;
  72394. + case 3:
  72395. + DWC_PRINTF("Reserved\n");
  72396. + break;
  72397. + }
  72398. + DWC_PRINTF(" bmRequestType Recipient = ");
  72399. + switch (setup[0] & 0x1f) {
  72400. + case 0:
  72401. + DWC_PRINTF("Device\n");
  72402. + break;
  72403. + case 1:
  72404. + DWC_PRINTF("Interface\n");
  72405. + break;
  72406. + case 2:
  72407. + DWC_PRINTF("Endpoint\n");
  72408. + break;
  72409. + case 3:
  72410. + DWC_PRINTF("Other\n");
  72411. + break;
  72412. + default:
  72413. + DWC_PRINTF("Reserved\n");
  72414. + break;
  72415. + }
  72416. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  72417. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  72418. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  72419. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  72420. + }
  72421. +}
  72422. +#endif
  72423. +
  72424. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  72425. +{
  72426. +#if 0
  72427. + DWC_PRINTF("Frame remaining at SOF:\n");
  72428. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72429. + hcd->frrem_samples, hcd->frrem_accum,
  72430. + (hcd->frrem_samples > 0) ?
  72431. + hcd->frrem_accum / hcd->frrem_samples : 0);
  72432. +
  72433. + DWC_PRINTF("\n");
  72434. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  72435. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72436. + hcd->core_if->hfnum_7_samples,
  72437. + hcd->core_if->hfnum_7_frrem_accum,
  72438. + (hcd->core_if->hfnum_7_samples >
  72439. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  72440. + hcd->core_if->hfnum_7_samples : 0);
  72441. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  72442. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72443. + hcd->core_if->hfnum_0_samples,
  72444. + hcd->core_if->hfnum_0_frrem_accum,
  72445. + (hcd->core_if->hfnum_0_samples >
  72446. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  72447. + hcd->core_if->hfnum_0_samples : 0);
  72448. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  72449. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72450. + hcd->core_if->hfnum_other_samples,
  72451. + hcd->core_if->hfnum_other_frrem_accum,
  72452. + (hcd->core_if->hfnum_other_samples >
  72453. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  72454. + hcd->core_if->hfnum_other_samples : 0);
  72455. +
  72456. + DWC_PRINTF("\n");
  72457. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  72458. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72459. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  72460. + (hcd->hfnum_7_samples_a > 0) ?
  72461. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  72462. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  72463. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72464. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  72465. + (hcd->hfnum_0_samples_a > 0) ?
  72466. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  72467. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  72468. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72469. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  72470. + (hcd->hfnum_other_samples_a > 0) ?
  72471. + hcd->hfnum_other_frrem_accum_a /
  72472. + hcd->hfnum_other_samples_a : 0);
  72473. +
  72474. + DWC_PRINTF("\n");
  72475. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  72476. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72477. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  72478. + (hcd->hfnum_7_samples_b > 0) ?
  72479. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  72480. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  72481. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72482. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  72483. + (hcd->hfnum_0_samples_b > 0) ?
  72484. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  72485. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  72486. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  72487. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  72488. + (hcd->hfnum_other_samples_b > 0) ?
  72489. + hcd->hfnum_other_frrem_accum_b /
  72490. + hcd->hfnum_other_samples_b : 0);
  72491. +#endif
  72492. +}
  72493. +
  72494. +#endif /* DWC_DEVICE_ONLY */
  72495. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  72496. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  72497. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-03-13 12:46:39.516097989 +0100
  72498. @@ -0,0 +1,1132 @@
  72499. +/*==========================================================================
  72500. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  72501. + * $Revision: #10 $
  72502. + * $Date: 2011/10/20 $
  72503. + * $Change: 1869464 $
  72504. + *
  72505. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  72506. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  72507. + * otherwise expressly agreed to in writing between Synopsys and you.
  72508. + *
  72509. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  72510. + * any End User Software License Agreement or Agreement for Licensed Product
  72511. + * with Synopsys or any supplement thereto. You are permitted to use and
  72512. + * redistribute this Software in source and binary forms, with or without
  72513. + * modification, provided that redistributions of source code must retain this
  72514. + * notice. You may not view, use, disclose, copy or distribute this file or
  72515. + * any information contained herein except pursuant to this license grant from
  72516. + * Synopsys. If you do not agree with this notice, including the disclaimer
  72517. + * below, then you are not authorized to use the Software.
  72518. + *
  72519. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  72520. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  72521. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  72522. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  72523. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  72524. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  72525. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  72526. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72527. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  72528. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  72529. + * DAMAGE.
  72530. + * ========================================================================== */
  72531. +#ifndef DWC_DEVICE_ONLY
  72532. +
  72533. +/** @file
  72534. + * This file contains Descriptor DMA support implementation for host mode.
  72535. + */
  72536. +
  72537. +#include "dwc_otg_hcd.h"
  72538. +#include "dwc_otg_regs.h"
  72539. +
  72540. +extern bool microframe_schedule;
  72541. +
  72542. +static inline uint8_t frame_list_idx(uint16_t frame)
  72543. +{
  72544. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  72545. +}
  72546. +
  72547. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  72548. +{
  72549. + return (idx + inc) &
  72550. + (((speed ==
  72551. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  72552. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  72553. +}
  72554. +
  72555. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  72556. +{
  72557. + return (idx - inc) &
  72558. + (((speed ==
  72559. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  72560. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  72561. +}
  72562. +
  72563. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  72564. +{
  72565. + return (((qh->ep_type == UE_ISOCHRONOUS)
  72566. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  72567. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  72568. +}
  72569. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  72570. +{
  72571. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  72572. + ? ((qh->interval + 8 - 1) / 8)
  72573. + : qh->interval);
  72574. +}
  72575. +
  72576. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  72577. +{
  72578. + int retval = 0;
  72579. +
  72580. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  72581. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  72582. + &qh->desc_list_dma);
  72583. +
  72584. + if (!qh->desc_list) {
  72585. + retval = -DWC_E_NO_MEMORY;
  72586. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  72587. +
  72588. + }
  72589. +
  72590. + dwc_memset(qh->desc_list, 0x00,
  72591. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  72592. +
  72593. + qh->n_bytes =
  72594. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  72595. +
  72596. + if (!qh->n_bytes) {
  72597. + retval = -DWC_E_NO_MEMORY;
  72598. + DWC_ERROR
  72599. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  72600. + __func__);
  72601. +
  72602. + }
  72603. + return retval;
  72604. +
  72605. +}
  72606. +
  72607. +static void desc_list_free(dwc_otg_qh_t * qh)
  72608. +{
  72609. + if (qh->desc_list) {
  72610. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  72611. + qh->desc_list_dma);
  72612. + qh->desc_list = NULL;
  72613. + }
  72614. +
  72615. + if (qh->n_bytes) {
  72616. + DWC_FREE(qh->n_bytes);
  72617. + qh->n_bytes = NULL;
  72618. + }
  72619. +}
  72620. +
  72621. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  72622. +{
  72623. + int retval = 0;
  72624. + if (hcd->frame_list)
  72625. + return 0;
  72626. +
  72627. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  72628. + &hcd->frame_list_dma);
  72629. + if (!hcd->frame_list) {
  72630. + retval = -DWC_E_NO_MEMORY;
  72631. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  72632. + }
  72633. +
  72634. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  72635. +
  72636. + return retval;
  72637. +}
  72638. +
  72639. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  72640. +{
  72641. + if (!hcd->frame_list)
  72642. + return;
  72643. +
  72644. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  72645. + hcd->frame_list = NULL;
  72646. +}
  72647. +
  72648. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  72649. +{
  72650. +
  72651. + hcfg_data_t hcfg;
  72652. +
  72653. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  72654. +
  72655. + if (hcfg.b.perschedena) {
  72656. + /* already enabled */
  72657. + return;
  72658. + }
  72659. +
  72660. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  72661. + hcd->frame_list_dma);
  72662. +
  72663. + switch (fr_list_en) {
  72664. + case 64:
  72665. + hcfg.b.frlisten = 3;
  72666. + break;
  72667. + case 32:
  72668. + hcfg.b.frlisten = 2;
  72669. + break;
  72670. + case 16:
  72671. + hcfg.b.frlisten = 1;
  72672. + break;
  72673. + case 8:
  72674. + hcfg.b.frlisten = 0;
  72675. + break;
  72676. + default:
  72677. + break;
  72678. + }
  72679. +
  72680. + hcfg.b.perschedena = 1;
  72681. +
  72682. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  72683. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  72684. +
  72685. +}
  72686. +
  72687. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  72688. +{
  72689. + hcfg_data_t hcfg;
  72690. +
  72691. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  72692. +
  72693. + if (!hcfg.b.perschedena) {
  72694. + /* already disabled */
  72695. + return;
  72696. + }
  72697. + hcfg.b.perschedena = 0;
  72698. +
  72699. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  72700. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  72701. +}
  72702. +
  72703. +/*
  72704. + * Activates/Deactivates FrameList entries for the channel
  72705. + * based on endpoint servicing period.
  72706. + */
  72707. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  72708. +{
  72709. + uint16_t i, j, inc;
  72710. + dwc_hc_t *hc = NULL;
  72711. +
  72712. + if (!qh->channel) {
  72713. + DWC_ERROR("qh->channel = %p", qh->channel);
  72714. + return;
  72715. + }
  72716. +
  72717. + if (!hcd) {
  72718. + DWC_ERROR("------hcd = %p", hcd);
  72719. + return;
  72720. + }
  72721. +
  72722. + if (!hcd->frame_list) {
  72723. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  72724. + return;
  72725. + }
  72726. +
  72727. + hc = qh->channel;
  72728. + inc = frame_incr_val(qh);
  72729. + if (qh->ep_type == UE_ISOCHRONOUS)
  72730. + i = frame_list_idx(qh->sched_frame);
  72731. + else
  72732. + i = 0;
  72733. +
  72734. + j = i;
  72735. + do {
  72736. + if (enable)
  72737. + hcd->frame_list[j] |= (1 << hc->hc_num);
  72738. + else
  72739. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  72740. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  72741. + }
  72742. + while (j != i);
  72743. + if (!enable)
  72744. + return;
  72745. + hc->schinfo = 0;
  72746. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  72747. + j = 1;
  72748. + /* TODO - check this */
  72749. + inc = (8 + qh->interval - 1) / qh->interval;
  72750. + for (i = 0; i < inc; i++) {
  72751. + hc->schinfo |= j;
  72752. + j = j << qh->interval;
  72753. + }
  72754. + } else {
  72755. + hc->schinfo = 0xff;
  72756. + }
  72757. +}
  72758. +
  72759. +#if 1
  72760. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  72761. +{
  72762. + int i = 0;
  72763. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  72764. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  72765. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  72766. + if (!(i % 8) && i)
  72767. + DWC_PRINTF("\n");
  72768. + }
  72769. + DWC_PRINTF("\n----\n");
  72770. +
  72771. +}
  72772. +#endif
  72773. +
  72774. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72775. +{
  72776. + dwc_irqflags_t flags;
  72777. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  72778. +
  72779. + dwc_hc_t *hc = qh->channel;
  72780. + if (dwc_qh_is_non_per(qh)) {
  72781. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72782. + if (!microframe_schedule)
  72783. + hcd->non_periodic_channels--;
  72784. + else
  72785. + hcd->available_host_channels++;
  72786. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72787. + } else
  72788. + update_frame_list(hcd, qh, 0);
  72789. +
  72790. + /*
  72791. + * The condition is added to prevent double cleanup try in case of device
  72792. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  72793. + */
  72794. + if (hc->qh) {
  72795. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  72796. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  72797. + hc->qh = NULL;
  72798. + }
  72799. +
  72800. + qh->channel = NULL;
  72801. + qh->ntd = 0;
  72802. +
  72803. + if (qh->desc_list) {
  72804. + dwc_memset(qh->desc_list, 0x00,
  72805. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  72806. + }
  72807. +}
  72808. +
  72809. +/**
  72810. + * Initializes a QH structure's Descriptor DMA related members.
  72811. + * Allocates memory for descriptor list.
  72812. + * On first periodic QH, allocates memory for FrameList
  72813. + * and enables periodic scheduling.
  72814. + *
  72815. + * @param hcd The HCD state structure for the DWC OTG controller.
  72816. + * @param qh The QH to init.
  72817. + *
  72818. + * @return 0 if successful, negative error code otherwise.
  72819. + */
  72820. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72821. +{
  72822. + int retval = 0;
  72823. +
  72824. + if (qh->do_split) {
  72825. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  72826. + return -1;
  72827. + }
  72828. +
  72829. + retval = desc_list_alloc(qh);
  72830. +
  72831. + if ((retval == 0)
  72832. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  72833. + if (!hcd->frame_list) {
  72834. + retval = frame_list_alloc(hcd);
  72835. + /* Enable periodic schedule on first periodic QH */
  72836. + if (retval == 0)
  72837. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  72838. + }
  72839. + }
  72840. +
  72841. + qh->ntd = 0;
  72842. +
  72843. + return retval;
  72844. +}
  72845. +
  72846. +/**
  72847. + * Frees descriptor list memory associated with the QH.
  72848. + * If QH is periodic and the last, frees FrameList memory
  72849. + * and disables periodic scheduling.
  72850. + *
  72851. + * @param hcd The HCD state structure for the DWC OTG controller.
  72852. + * @param qh The QH to init.
  72853. + */
  72854. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72855. +{
  72856. + desc_list_free(qh);
  72857. +
  72858. + /*
  72859. + * Channel still assigned due to some reasons.
  72860. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  72861. + * ChHalted interrupt to release the channel. Afterwards
  72862. + * when it comes here from endpoint disable routine
  72863. + * channel remains assigned.
  72864. + */
  72865. + if (qh->channel)
  72866. + release_channel_ddma(hcd, qh);
  72867. +
  72868. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  72869. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  72870. +
  72871. + per_sched_disable(hcd);
  72872. + frame_list_free(hcd);
  72873. + }
  72874. +}
  72875. +
  72876. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  72877. +{
  72878. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  72879. + /*
  72880. + * Descriptor set(8 descriptors) index
  72881. + * which is 8-aligned.
  72882. + */
  72883. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  72884. + } else {
  72885. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  72886. + }
  72887. +}
  72888. +
  72889. +/*
  72890. + * Determine starting frame for Isochronous transfer.
  72891. + * Few frames skipped to prevent race condition with HC.
  72892. + */
  72893. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  72894. + uint8_t * skip_frames)
  72895. +{
  72896. + uint16_t frame = 0;
  72897. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  72898. +
  72899. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  72900. +
  72901. + /*
  72902. + * skip_frames is used to limit activated descriptors number
  72903. + * to avoid the situation when HC services the last activated
  72904. + * descriptor firstly.
  72905. + * Example for FS:
  72906. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  72907. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  72908. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  72909. + * list will be fully programmed with Active descriptors and it is possible
  72910. + * case(rare) that the latest descriptor(considering rollback) corresponding
  72911. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  72912. + * up to 11 uframes(16 in the code) may be skipped.
  72913. + */
  72914. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  72915. + /*
  72916. + * Consider uframe counter also, to start xfer asap.
  72917. + * If half of the frame elapsed skip 2 frames otherwise
  72918. + * just 1 frame.
  72919. + * Starting descriptor index must be 8-aligned, so
  72920. + * if the current frame is near to complete the next one
  72921. + * is skipped as well.
  72922. + */
  72923. +
  72924. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  72925. + *skip_frames = 2 * 8;
  72926. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  72927. + } else {
  72928. + *skip_frames = 1 * 8;
  72929. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  72930. + }
  72931. +
  72932. + frame = dwc_full_frame_num(frame);
  72933. + } else {
  72934. + /*
  72935. + * Two frames are skipped for FS - the current and the next.
  72936. + * But for descriptor programming, 1 frame(descriptor) is enough,
  72937. + * see example above.
  72938. + */
  72939. + *skip_frames = 1;
  72940. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  72941. + }
  72942. +
  72943. + return frame;
  72944. +}
  72945. +
  72946. +/*
  72947. + * Calculate initial descriptor index for isochronous transfer
  72948. + * based on scheduled frame.
  72949. + */
  72950. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72951. +{
  72952. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  72953. + uint8_t skip_frames = 0;
  72954. + /*
  72955. + * With current ISOC processing algorithm the channel is being
  72956. + * released when no more QTDs in the list(qh->ntd == 0).
  72957. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  72958. + *
  72959. + * So qh->channel != NULL branch is not used and just not removed from the
  72960. + * source file. It is required for another possible approach which is,
  72961. + * do not disable and release the channel when ISOC session completed,
  72962. + * just move QH to inactive schedule until new QTD arrives.
  72963. + * On new QTD, the QH moved back to 'ready' schedule,
  72964. + * starting frame and therefore starting desc_index are recalculated.
  72965. + * In this case channel is released only on ep_disable.
  72966. + */
  72967. +
  72968. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  72969. + if (qh->channel) {
  72970. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  72971. + /*
  72972. + * Calculate initial descriptor index based on FrameList current bitmap
  72973. + * and servicing period.
  72974. + */
  72975. + fr_idx_tmp = frame_list_idx(frame);
  72976. + fr_idx =
  72977. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  72978. + fr_idx_tmp)
  72979. + % frame_incr_val(qh);
  72980. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  72981. + } else {
  72982. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  72983. + fr_idx = frame_list_idx(qh->sched_frame);
  72984. + }
  72985. +
  72986. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  72987. +
  72988. + return skip_frames;
  72989. +}
  72990. +
  72991. +#define ISOC_URB_GIVEBACK_ASAP
  72992. +
  72993. +#define MAX_ISOC_XFER_SIZE_FS 1023
  72994. +#define MAX_ISOC_XFER_SIZE_HS 3072
  72995. +#define DESCNUM_THRESHOLD 4
  72996. +
  72997. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  72998. + uint8_t skip_frames)
  72999. +{
  73000. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  73001. + dwc_otg_qtd_t *qtd;
  73002. + dwc_otg_host_dma_desc_t *dma_desc;
  73003. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  73004. +
  73005. + idx = qh->td_last;
  73006. + inc = qh->interval;
  73007. + n_desc = 0;
  73008. +
  73009. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  73010. + if (skip_frames && !qh->channel)
  73011. + ntd_max = ntd_max - skip_frames / qh->interval;
  73012. +
  73013. + max_xfer_size =
  73014. + (qh->dev_speed ==
  73015. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  73016. + MAX_ISOC_XFER_SIZE_FS;
  73017. +
  73018. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  73019. + while ((qh->ntd < ntd_max)
  73020. + && (qtd->isoc_frame_index_last <
  73021. + qtd->urb->packet_count)) {
  73022. +
  73023. + dma_desc = &qh->desc_list[idx];
  73024. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  73025. +
  73026. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  73027. +
  73028. + if (frame_desc->length > max_xfer_size)
  73029. + qh->n_bytes[idx] = max_xfer_size;
  73030. + else
  73031. + qh->n_bytes[idx] = frame_desc->length;
  73032. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  73033. + dma_desc->status.b_isoc.a = 1;
  73034. + dma_desc->status.b_isoc.sts = 0;
  73035. +
  73036. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  73037. +
  73038. + qh->ntd++;
  73039. +
  73040. + qtd->isoc_frame_index_last++;
  73041. +
  73042. +#ifdef ISOC_URB_GIVEBACK_ASAP
  73043. + /*
  73044. + * Set IOC for each descriptor corresponding to the
  73045. + * last frame of the URB.
  73046. + */
  73047. + if (qtd->isoc_frame_index_last ==
  73048. + qtd->urb->packet_count)
  73049. + dma_desc->status.b_isoc.ioc = 1;
  73050. +
  73051. +#endif
  73052. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  73053. + n_desc++;
  73054. +
  73055. + }
  73056. + qtd->in_process = 1;
  73057. + }
  73058. +
  73059. + qh->td_last = idx;
  73060. +
  73061. +#ifdef ISOC_URB_GIVEBACK_ASAP
  73062. + /* Set IOC for the last descriptor if descriptor list is full */
  73063. + if (qh->ntd == ntd_max) {
  73064. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  73065. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  73066. + }
  73067. +#else
  73068. + /*
  73069. + * Set IOC bit only for one descriptor.
  73070. + * Always try to be ahead of HW processing,
  73071. + * i.e. on IOC generation driver activates next descriptors but
  73072. + * core continues to process descriptors followed the one with IOC set.
  73073. + */
  73074. +
  73075. + if (n_desc > DESCNUM_THRESHOLD) {
  73076. + /*
  73077. + * Move IOC "up". Required even if there is only one QTD
  73078. + * in the list, cause QTDs migth continue to be queued,
  73079. + * but during the activation it was only one queued.
  73080. + * Actually more than one QTD might be in the list if this function called
  73081. + * from XferCompletion - QTDs was queued during HW processing of the previous
  73082. + * descriptor chunk.
  73083. + */
  73084. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  73085. + } else {
  73086. + /*
  73087. + * Set the IOC for the latest descriptor
  73088. + * if either number of descriptor is not greather than threshold
  73089. + * or no more new descriptors activated.
  73090. + */
  73091. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  73092. + }
  73093. +
  73094. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  73095. +#endif
  73096. +}
  73097. +
  73098. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  73099. +{
  73100. +
  73101. + dwc_hc_t *hc;
  73102. + dwc_otg_host_dma_desc_t *dma_desc;
  73103. + dwc_otg_qtd_t *qtd;
  73104. + int num_packets, len, n_desc = 0;
  73105. +
  73106. + hc = qh->channel;
  73107. +
  73108. + /*
  73109. + * Start with hc->xfer_buff initialized in
  73110. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  73111. + * this pointer re-assigned to the buffer of the currently processed QTD.
  73112. + * For non-SG request there is always one QTD active.
  73113. + */
  73114. +
  73115. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  73116. +
  73117. + if (n_desc) {
  73118. + /* SG request - more than 1 QTDs */
  73119. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  73120. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  73121. + }
  73122. +
  73123. + qtd->n_desc = 0;
  73124. +
  73125. + do {
  73126. + dma_desc = &qh->desc_list[n_desc];
  73127. + len = hc->xfer_len;
  73128. +
  73129. + if (len > MAX_DMA_DESC_SIZE)
  73130. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  73131. +
  73132. + if (hc->ep_is_in) {
  73133. + if (len > 0) {
  73134. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  73135. + } else {
  73136. + /* Need 1 packet for transfer length of 0. */
  73137. + num_packets = 1;
  73138. + }
  73139. + /* Always program an integral # of max packets for IN transfers. */
  73140. + len = num_packets * hc->max_packet;
  73141. + }
  73142. +
  73143. + dma_desc->status.b.n_bytes = len;
  73144. +
  73145. + qh->n_bytes[n_desc] = len;
  73146. +
  73147. + if ((qh->ep_type == UE_CONTROL)
  73148. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  73149. + dma_desc->status.b.sup = 1; /* Setup Packet */
  73150. +
  73151. + dma_desc->status.b.a = 1; /* Active descriptor */
  73152. + dma_desc->status.b.sts = 0;
  73153. +
  73154. + dma_desc->buf =
  73155. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  73156. +
  73157. + /*
  73158. + * Last descriptor(or single) of IN transfer
  73159. + * with actual size less than MaxPacket.
  73160. + */
  73161. + if (len > hc->xfer_len) {
  73162. + hc->xfer_len = 0;
  73163. + } else {
  73164. + hc->xfer_buff += len;
  73165. + hc->xfer_len -= len;
  73166. + }
  73167. +
  73168. + qtd->n_desc++;
  73169. + n_desc++;
  73170. + }
  73171. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  73172. +
  73173. +
  73174. + qtd->in_process = 1;
  73175. +
  73176. + if (qh->ep_type == UE_CONTROL)
  73177. + break;
  73178. +
  73179. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  73180. + break;
  73181. + }
  73182. +
  73183. + if (n_desc) {
  73184. + /* Request Transfer Complete interrupt for the last descriptor */
  73185. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  73186. + /* End of List indicator */
  73187. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  73188. +
  73189. + hc->ntd = n_desc;
  73190. + }
  73191. +}
  73192. +
  73193. +/**
  73194. + * For Control and Bulk endpoints initializes descriptor list
  73195. + * and starts the transfer.
  73196. + *
  73197. + * For Interrupt and Isochronous endpoints initializes descriptor list
  73198. + * then updates FrameList, marking appropriate entries as active.
  73199. + * In case of Isochronous, the starting descriptor index is calculated based
  73200. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  73201. + * Then starts the transfer via enabling the channel.
  73202. + * For Isochronous endpoint the channel is not halted on XferComplete
  73203. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  73204. + *
  73205. + * @param hcd The HCD state structure for the DWC OTG controller.
  73206. + * @param qh The QH to init.
  73207. + *
  73208. + * @return 0 if successful, negative error code otherwise.
  73209. + */
  73210. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  73211. +{
  73212. + /* Channel is already assigned */
  73213. + dwc_hc_t *hc = qh->channel;
  73214. + uint8_t skip_frames = 0;
  73215. +
  73216. + switch (hc->ep_type) {
  73217. + case DWC_OTG_EP_TYPE_CONTROL:
  73218. + case DWC_OTG_EP_TYPE_BULK:
  73219. + init_non_isoc_dma_desc(hcd, qh);
  73220. +
  73221. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  73222. + break;
  73223. + case DWC_OTG_EP_TYPE_INTR:
  73224. + init_non_isoc_dma_desc(hcd, qh);
  73225. +
  73226. + update_frame_list(hcd, qh, 1);
  73227. +
  73228. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  73229. + break;
  73230. + case DWC_OTG_EP_TYPE_ISOC:
  73231. +
  73232. + if (!qh->ntd)
  73233. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  73234. +
  73235. + init_isoc_dma_desc(hcd, qh, skip_frames);
  73236. +
  73237. + if (!hc->xfer_started) {
  73238. +
  73239. + update_frame_list(hcd, qh, 1);
  73240. +
  73241. + /*
  73242. + * Always set to max, instead of actual size.
  73243. + * Otherwise ntd will be changed with
  73244. + * channel being enabled. Not recommended.
  73245. + *
  73246. + */
  73247. + hc->ntd = max_desc_num(qh);
  73248. + /* Enable channel only once for ISOC */
  73249. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  73250. + }
  73251. +
  73252. + break;
  73253. + default:
  73254. +
  73255. + break;
  73256. + }
  73257. +}
  73258. +
  73259. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  73260. + dwc_hc_t * hc,
  73261. + dwc_otg_hc_regs_t * hc_regs,
  73262. + dwc_otg_halt_status_e halt_status)
  73263. +{
  73264. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  73265. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  73266. + dwc_otg_qh_t *qh;
  73267. + dwc_otg_host_dma_desc_t *dma_desc;
  73268. + uint16_t idx, remain;
  73269. + uint8_t urb_compl;
  73270. +
  73271. + qh = hc->qh;
  73272. + idx = qh->td_first;
  73273. +
  73274. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  73275. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  73276. + qtd->in_process = 0;
  73277. + return;
  73278. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  73279. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  73280. + /*
  73281. + * Channel is halted in these error cases.
  73282. + * Considered as serious issues.
  73283. + * Complete all URBs marking all frames as failed,
  73284. + * irrespective whether some of the descriptors(frames) succeeded or no.
  73285. + * Pass error code to completion routine as well, to
  73286. + * update urb->status, some of class drivers might use it to stop
  73287. + * queing transfer requests.
  73288. + */
  73289. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  73290. + ? (-DWC_E_IO)
  73291. + : (-DWC_E_OVERFLOW);
  73292. +
  73293. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  73294. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  73295. + frame_desc = &qtd->urb->iso_descs[idx];
  73296. + frame_desc->status = err;
  73297. + }
  73298. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  73299. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  73300. + }
  73301. + return;
  73302. + }
  73303. +
  73304. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  73305. +
  73306. + if (!qtd->in_process)
  73307. + break;
  73308. +
  73309. + urb_compl = 0;
  73310. +
  73311. + do {
  73312. +
  73313. + dma_desc = &qh->desc_list[idx];
  73314. +
  73315. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  73316. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  73317. +
  73318. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  73319. + /*
  73320. + * XactError or, unable to complete all the transactions
  73321. + * in the scheduled micro-frame/frame,
  73322. + * both indicated by DMA_DESC_STS_PKTERR.
  73323. + */
  73324. + qtd->urb->error_count++;
  73325. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  73326. + frame_desc->status = -DWC_E_PROTOCOL;
  73327. + } else {
  73328. + /* Success */
  73329. +
  73330. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  73331. + frame_desc->status = 0;
  73332. + }
  73333. +
  73334. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  73335. + /*
  73336. + * urb->status is not used for isoc transfers here.
  73337. + * The individual frame_desc status are used instead.
  73338. + */
  73339. +
  73340. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  73341. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  73342. +
  73343. + /*
  73344. + * This check is necessary because urb_dequeue can be called
  73345. + * from urb complete callback(sound driver example).
  73346. + * All pending URBs are dequeued there, so no need for
  73347. + * further processing.
  73348. + */
  73349. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  73350. + return;
  73351. + }
  73352. +
  73353. + urb_compl = 1;
  73354. +
  73355. + }
  73356. +
  73357. + qh->ntd--;
  73358. +
  73359. + /* Stop if IOC requested descriptor reached */
  73360. + if (dma_desc->status.b_isoc.ioc) {
  73361. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  73362. + goto stop_scan;
  73363. + }
  73364. +
  73365. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  73366. +
  73367. + if (urb_compl)
  73368. + break;
  73369. + }
  73370. + while (idx != qh->td_first);
  73371. + }
  73372. +stop_scan:
  73373. + qh->td_first = idx;
  73374. +}
  73375. +
  73376. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  73377. + dwc_hc_t * hc,
  73378. + dwc_otg_qtd_t * qtd,
  73379. + dwc_otg_host_dma_desc_t * dma_desc,
  73380. + dwc_otg_halt_status_e halt_status,
  73381. + uint32_t n_bytes, uint8_t * xfer_done)
  73382. +{
  73383. +
  73384. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  73385. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  73386. +
  73387. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  73388. + urb->status = -DWC_E_IO;
  73389. + return 1;
  73390. + }
  73391. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  73392. + switch (halt_status) {
  73393. + case DWC_OTG_HC_XFER_STALL:
  73394. + urb->status = -DWC_E_PIPE;
  73395. + break;
  73396. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  73397. + urb->status = -DWC_E_OVERFLOW;
  73398. + break;
  73399. + case DWC_OTG_HC_XFER_XACT_ERR:
  73400. + urb->status = -DWC_E_PROTOCOL;
  73401. + break;
  73402. + default:
  73403. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  73404. + halt_status);
  73405. + break;
  73406. + }
  73407. + return 1;
  73408. + }
  73409. +
  73410. + if (dma_desc->status.b.a == 1) {
  73411. + DWC_DEBUGPL(DBG_HCDV,
  73412. + "Active descriptor encountered on channel %d\n",
  73413. + hc->hc_num);
  73414. + return 0;
  73415. + }
  73416. +
  73417. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  73418. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  73419. + urb->actual_length += n_bytes - remain;
  73420. + if (remain || urb->actual_length == urb->length) {
  73421. + /*
  73422. + * For Control Data stage do not set urb->status=0 to prevent
  73423. + * URB callback. Set it when Status phase done. See below.
  73424. + */
  73425. + *xfer_done = 1;
  73426. + }
  73427. +
  73428. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  73429. + urb->status = 0;
  73430. + *xfer_done = 1;
  73431. + }
  73432. + /* No handling for SETUP stage */
  73433. + } else {
  73434. + /* BULK and INTR */
  73435. + urb->actual_length += n_bytes - remain;
  73436. + if (remain || urb->actual_length == urb->length) {
  73437. + urb->status = 0;
  73438. + *xfer_done = 1;
  73439. + }
  73440. + }
  73441. +
  73442. + return 0;
  73443. +}
  73444. +
  73445. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  73446. + dwc_hc_t * hc,
  73447. + dwc_otg_hc_regs_t * hc_regs,
  73448. + dwc_otg_halt_status_e halt_status)
  73449. +{
  73450. + dwc_otg_hcd_urb_t *urb = NULL;
  73451. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  73452. + dwc_otg_qh_t *qh;
  73453. + dwc_otg_host_dma_desc_t *dma_desc;
  73454. + uint32_t n_bytes, n_desc, i;
  73455. + uint8_t failed = 0, xfer_done;
  73456. +
  73457. + n_desc = 0;
  73458. +
  73459. + qh = hc->qh;
  73460. +
  73461. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  73462. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  73463. + qtd->in_process = 0;
  73464. + }
  73465. + return;
  73466. + }
  73467. +
  73468. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  73469. +
  73470. + urb = qtd->urb;
  73471. +
  73472. + n_bytes = 0;
  73473. + xfer_done = 0;
  73474. +
  73475. + for (i = 0; i < qtd->n_desc; i++) {
  73476. + dma_desc = &qh->desc_list[n_desc];
  73477. +
  73478. + n_bytes = qh->n_bytes[n_desc];
  73479. +
  73480. + failed =
  73481. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  73482. + dma_desc,
  73483. + halt_status, n_bytes,
  73484. + &xfer_done);
  73485. +
  73486. + if (failed
  73487. + || (xfer_done
  73488. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  73489. +
  73490. + hcd->fops->complete(hcd, urb->priv, urb,
  73491. + urb->status);
  73492. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  73493. +
  73494. + if (failed)
  73495. + goto stop_scan;
  73496. + } else if (qh->ep_type == UE_CONTROL) {
  73497. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  73498. + if (urb->length > 0) {
  73499. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  73500. + } else {
  73501. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  73502. + }
  73503. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  73504. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  73505. + if (xfer_done) {
  73506. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  73507. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  73508. + } else if (i + 1 == qtd->n_desc) {
  73509. + /*
  73510. + * Last descriptor for Control data stage which is
  73511. + * not completed yet.
  73512. + */
  73513. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  73514. + }
  73515. + }
  73516. + }
  73517. +
  73518. + n_desc++;
  73519. + }
  73520. +
  73521. + }
  73522. +
  73523. +stop_scan:
  73524. +
  73525. + if (qh->ep_type != UE_CONTROL) {
  73526. + /*
  73527. + * Resetting the data toggle for bulk
  73528. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  73529. + */
  73530. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  73531. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  73532. + else
  73533. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  73534. + }
  73535. +
  73536. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  73537. + hcint_data_t hcint;
  73538. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73539. + if (hcint.b.nyet) {
  73540. + /*
  73541. + * Got a NYET on the last transaction of the transfer. It
  73542. + * means that the endpoint should be in the PING state at the
  73543. + * beginning of the next transfer.
  73544. + */
  73545. + qh->ping_state = 1;
  73546. + clear_hc_int(hc_regs, nyet);
  73547. + }
  73548. +
  73549. + }
  73550. +
  73551. +}
  73552. +
  73553. +/**
  73554. + * This function is called from interrupt handlers.
  73555. + * Scans the descriptor list, updates URB's status and
  73556. + * calls completion routine for the URB if it's done.
  73557. + * Releases the channel to be used by other transfers.
  73558. + * In case of Isochronous endpoint the channel is not halted until
  73559. + * the end of the session, i.e. QTD list is empty.
  73560. + * If periodic channel released the FrameList is updated accordingly.
  73561. + *
  73562. + * Calls transaction selection routines to activate pending transfers.
  73563. + *
  73564. + * @param hcd The HCD state structure for the DWC OTG controller.
  73565. + * @param hc Host channel, the transfer is completed on.
  73566. + * @param hc_regs Host channel registers.
  73567. + * @param halt_status Reason the channel is being halted,
  73568. + * or just XferComplete for isochronous transfer
  73569. + */
  73570. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  73571. + dwc_hc_t * hc,
  73572. + dwc_otg_hc_regs_t * hc_regs,
  73573. + dwc_otg_halt_status_e halt_status)
  73574. +{
  73575. + uint8_t continue_isoc_xfer = 0;
  73576. + dwc_otg_transaction_type_e tr_type;
  73577. + dwc_otg_qh_t *qh = hc->qh;
  73578. +
  73579. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73580. +
  73581. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  73582. +
  73583. + /* Release the channel if halted or session completed */
  73584. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  73585. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  73586. +
  73587. + /* Halt the channel if session completed */
  73588. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  73589. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  73590. + }
  73591. +
  73592. + release_channel_ddma(hcd, qh);
  73593. + dwc_otg_hcd_qh_remove(hcd, qh);
  73594. + } else {
  73595. + /* Keep in assigned schedule to continue transfer */
  73596. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  73597. + &qh->qh_list_entry);
  73598. + continue_isoc_xfer = 1;
  73599. +
  73600. + }
  73601. + /** @todo Consider the case when period exceeds FrameList size.
  73602. + * Frame Rollover interrupt should be used.
  73603. + */
  73604. + } else {
  73605. + /* Scan descriptor list to complete the URB(s), then release the channel */
  73606. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  73607. +
  73608. + release_channel_ddma(hcd, qh);
  73609. + dwc_otg_hcd_qh_remove(hcd, qh);
  73610. +
  73611. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  73612. + /* Add back to inactive non-periodic schedule on normal completion */
  73613. + dwc_otg_hcd_qh_add(hcd, qh);
  73614. + }
  73615. +
  73616. + }
  73617. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  73618. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  73619. + if (continue_isoc_xfer) {
  73620. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  73621. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  73622. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  73623. + tr_type = DWC_OTG_TRANSACTION_ALL;
  73624. + }
  73625. + }
  73626. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  73627. + }
  73628. +}
  73629. +
  73630. +#endif /* DWC_DEVICE_ONLY */
  73631. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  73632. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  73633. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-03-13 12:46:39.516097989 +0100
  73634. @@ -0,0 +1,851 @@
  73635. +/* ==========================================================================
  73636. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  73637. + * $Revision: #58 $
  73638. + * $Date: 2011/09/15 $
  73639. + * $Change: 1846647 $
  73640. + *
  73641. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73642. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73643. + * otherwise expressly agreed to in writing between Synopsys and you.
  73644. + *
  73645. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73646. + * any End User Software License Agreement or Agreement for Licensed Product
  73647. + * with Synopsys or any supplement thereto. You are permitted to use and
  73648. + * redistribute this Software in source and binary forms, with or without
  73649. + * modification, provided that redistributions of source code must retain this
  73650. + * notice. You may not view, use, disclose, copy or distribute this file or
  73651. + * any information contained herein except pursuant to this license grant from
  73652. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73653. + * below, then you are not authorized to use the Software.
  73654. + *
  73655. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73656. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73657. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73658. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73659. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73660. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73661. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  73662. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73663. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73664. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  73665. + * DAMAGE.
  73666. + * ========================================================================== */
  73667. +#ifndef DWC_DEVICE_ONLY
  73668. +#ifndef __DWC_HCD_H__
  73669. +#define __DWC_HCD_H__
  73670. +
  73671. +#include "dwc_otg_os_dep.h"
  73672. +#include "usb.h"
  73673. +#include "dwc_otg_hcd_if.h"
  73674. +#include "dwc_otg_core_if.h"
  73675. +#include "dwc_list.h"
  73676. +#include "dwc_otg_cil.h"
  73677. +
  73678. +/**
  73679. + * @file
  73680. + *
  73681. + * This file contains the structures, constants, and interfaces for
  73682. + * the Host Contoller Driver (HCD).
  73683. + *
  73684. + * The Host Controller Driver (HCD) is responsible for translating requests
  73685. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  73686. + * It isolates the USBD from the specifics of the controller by providing an
  73687. + * API to the USBD.
  73688. + */
  73689. +
  73690. +struct dwc_otg_hcd_pipe_info {
  73691. + uint8_t dev_addr;
  73692. + uint8_t ep_num;
  73693. + uint8_t pipe_type;
  73694. + uint8_t pipe_dir;
  73695. + uint16_t mps;
  73696. +};
  73697. +
  73698. +struct dwc_otg_hcd_iso_packet_desc {
  73699. + uint32_t offset;
  73700. + uint32_t length;
  73701. + uint32_t actual_length;
  73702. + uint32_t status;
  73703. +};
  73704. +
  73705. +struct dwc_otg_qtd;
  73706. +
  73707. +struct dwc_otg_hcd_urb {
  73708. + void *priv;
  73709. + struct dwc_otg_qtd *qtd;
  73710. + void *buf;
  73711. + dwc_dma_t dma;
  73712. + void *setup_packet;
  73713. + dwc_dma_t setup_dma;
  73714. + uint32_t length;
  73715. + uint32_t actual_length;
  73716. + uint32_t status;
  73717. + uint32_t error_count;
  73718. + uint32_t packet_count;
  73719. + uint32_t flags;
  73720. + uint16_t interval;
  73721. + struct dwc_otg_hcd_pipe_info pipe_info;
  73722. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  73723. +};
  73724. +
  73725. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  73726. +{
  73727. + return pipe->ep_num;
  73728. +}
  73729. +
  73730. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  73731. + *pipe)
  73732. +{
  73733. + return pipe->pipe_type;
  73734. +}
  73735. +
  73736. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  73737. +{
  73738. + return pipe->mps;
  73739. +}
  73740. +
  73741. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  73742. + *pipe)
  73743. +{
  73744. + return pipe->dev_addr;
  73745. +}
  73746. +
  73747. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  73748. + *pipe)
  73749. +{
  73750. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  73751. +}
  73752. +
  73753. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  73754. + *pipe)
  73755. +{
  73756. + return (pipe->pipe_type == UE_INTERRUPT);
  73757. +}
  73758. +
  73759. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  73760. + *pipe)
  73761. +{
  73762. + return (pipe->pipe_type == UE_BULK);
  73763. +}
  73764. +
  73765. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  73766. + *pipe)
  73767. +{
  73768. + return (pipe->pipe_type == UE_CONTROL);
  73769. +}
  73770. +
  73771. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  73772. +{
  73773. + return (pipe->pipe_dir == UE_DIR_IN);
  73774. +}
  73775. +
  73776. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  73777. + *pipe)
  73778. +{
  73779. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  73780. +}
  73781. +
  73782. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  73783. + uint8_t devaddr, uint8_t ep_num,
  73784. + uint8_t pipe_type, uint8_t pipe_dir,
  73785. + uint16_t mps)
  73786. +{
  73787. + pipe->dev_addr = devaddr;
  73788. + pipe->ep_num = ep_num;
  73789. + pipe->pipe_type = pipe_type;
  73790. + pipe->pipe_dir = pipe_dir;
  73791. + pipe->mps = mps;
  73792. +}
  73793. +
  73794. +/**
  73795. + * Phases for control transfers.
  73796. + */
  73797. +typedef enum dwc_otg_control_phase {
  73798. + DWC_OTG_CONTROL_SETUP,
  73799. + DWC_OTG_CONTROL_DATA,
  73800. + DWC_OTG_CONTROL_STATUS
  73801. +} dwc_otg_control_phase_e;
  73802. +
  73803. +/** Transaction types. */
  73804. +typedef enum dwc_otg_transaction_type {
  73805. + DWC_OTG_TRANSACTION_NONE = 0,
  73806. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  73807. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  73808. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  73809. +} dwc_otg_transaction_type_e;
  73810. +
  73811. +struct dwc_otg_qh;
  73812. +
  73813. +/**
  73814. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  73815. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  73816. + * (of one of these types) submitted to the HCD. The transfer associated with
  73817. + * a QTD may require one or multiple transactions.
  73818. + *
  73819. + * A QTD is linked to a Queue Head, which is entered in either the
  73820. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  73821. + * execution, some or all of its transactions may be executed. After
  73822. + * execution, the state of the QTD is updated. The QTD may be retired if all
  73823. + * its transactions are complete or if an error occurred. Otherwise, it
  73824. + * remains in the schedule so more transactions can be executed later.
  73825. + */
  73826. +typedef struct dwc_otg_qtd {
  73827. + /**
  73828. + * Determines the PID of the next data packet for the data phase of
  73829. + * control transfers. Ignored for other transfer types.<br>
  73830. + * One of the following values:
  73831. + * - DWC_OTG_HC_PID_DATA0
  73832. + * - DWC_OTG_HC_PID_DATA1
  73833. + */
  73834. + uint8_t data_toggle;
  73835. +
  73836. + /** Current phase for control transfers (Setup, Data, or Status). */
  73837. + dwc_otg_control_phase_e control_phase;
  73838. +
  73839. + /** Keep track of the current split type
  73840. + * for FS/LS endpoints on a HS Hub */
  73841. + uint8_t complete_split;
  73842. +
  73843. + /** How many bytes transferred during SSPLIT OUT */
  73844. + uint32_t ssplit_out_xfer_count;
  73845. +
  73846. + /**
  73847. + * Holds the number of bus errors that have occurred for a transaction
  73848. + * within this transfer.
  73849. + */
  73850. + uint8_t error_count;
  73851. +
  73852. + /**
  73853. + * Index of the next frame descriptor for an isochronous transfer. A
  73854. + * frame descriptor describes the buffer position and length of the
  73855. + * data to be transferred in the next scheduled (micro)frame of an
  73856. + * isochronous transfer. It also holds status for that transaction.
  73857. + * The frame index starts at 0.
  73858. + */
  73859. + uint16_t isoc_frame_index;
  73860. +
  73861. + /** Position of the ISOC split on full/low speed */
  73862. + uint8_t isoc_split_pos;
  73863. +
  73864. + /** Position of the ISOC split in the buffer for the current frame */
  73865. + uint16_t isoc_split_offset;
  73866. +
  73867. + /** URB for this transfer */
  73868. + struct dwc_otg_hcd_urb *urb;
  73869. +
  73870. + struct dwc_otg_qh *qh;
  73871. +
  73872. + /** This list of QTDs */
  73873. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  73874. +
  73875. + /** Indicates if this QTD is currently processed by HW. */
  73876. + uint8_t in_process;
  73877. +
  73878. + /** Number of DMA descriptors for this QTD */
  73879. + uint8_t n_desc;
  73880. +
  73881. + /**
  73882. + * Last activated frame(packet) index.
  73883. + * Used in Descriptor DMA mode only.
  73884. + */
  73885. + uint16_t isoc_frame_index_last;
  73886. +
  73887. +} dwc_otg_qtd_t;
  73888. +
  73889. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  73890. +
  73891. +/**
  73892. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  73893. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  73894. + * be entered in either the non-periodic or periodic schedule.
  73895. + */
  73896. +typedef struct dwc_otg_qh {
  73897. + /**
  73898. + * Endpoint type.
  73899. + * One of the following values:
  73900. + * - UE_CONTROL
  73901. + * - UE_BULK
  73902. + * - UE_INTERRUPT
  73903. + * - UE_ISOCHRONOUS
  73904. + */
  73905. + uint8_t ep_type;
  73906. + uint8_t ep_is_in;
  73907. +
  73908. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  73909. + uint16_t maxp;
  73910. +
  73911. + /**
  73912. + * Device speed.
  73913. + * One of the following values:
  73914. + * - DWC_OTG_EP_SPEED_LOW
  73915. + * - DWC_OTG_EP_SPEED_FULL
  73916. + * - DWC_OTG_EP_SPEED_HIGH
  73917. + */
  73918. + uint8_t dev_speed;
  73919. +
  73920. + /**
  73921. + * Determines the PID of the next data packet for non-control
  73922. + * transfers. Ignored for control transfers.<br>
  73923. + * One of the following values:
  73924. + * - DWC_OTG_HC_PID_DATA0
  73925. + * - DWC_OTG_HC_PID_DATA1
  73926. + */
  73927. + uint8_t data_toggle;
  73928. +
  73929. + /** Ping state if 1. */
  73930. + uint8_t ping_state;
  73931. +
  73932. + /**
  73933. + * List of QTDs for this QH.
  73934. + */
  73935. + struct dwc_otg_qtd_list qtd_list;
  73936. +
  73937. + /** Host channel currently processing transfers for this QH. */
  73938. + struct dwc_hc *channel;
  73939. +
  73940. + /** Full/low speed endpoint on high-speed hub requires split. */
  73941. + uint8_t do_split;
  73942. +
  73943. + /** @name Periodic schedule information */
  73944. + /** @{ */
  73945. +
  73946. + /** Bandwidth in microseconds per (micro)frame. */
  73947. + uint16_t usecs;
  73948. +
  73949. + /** Interval between transfers in (micro)frames. */
  73950. + uint16_t interval;
  73951. +
  73952. + /**
  73953. + * (micro)frame to initialize a periodic transfer. The transfer
  73954. + * executes in the following (micro)frame.
  73955. + */
  73956. + uint16_t sched_frame;
  73957. +
  73958. + /*
  73959. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  73960. + */
  73961. + uint16_t nak_frame;
  73962. +
  73963. + /** (micro)frame at which last start split was initialized. */
  73964. + uint16_t start_split_frame;
  73965. +
  73966. + /** @} */
  73967. +
  73968. + /**
  73969. + * Used instead of original buffer if
  73970. + * it(physical address) is not dword-aligned.
  73971. + */
  73972. + uint8_t *dw_align_buf;
  73973. + dwc_dma_t dw_align_buf_dma;
  73974. +
  73975. + /** Entry for QH in either the periodic or non-periodic schedule. */
  73976. + dwc_list_link_t qh_list_entry;
  73977. +
  73978. + /** @name Descriptor DMA support */
  73979. + /** @{ */
  73980. +
  73981. + /** Descriptor List. */
  73982. + dwc_otg_host_dma_desc_t *desc_list;
  73983. +
  73984. + /** Descriptor List physical address. */
  73985. + dwc_dma_t desc_list_dma;
  73986. +
  73987. + /**
  73988. + * Xfer Bytes array.
  73989. + * Each element corresponds to a descriptor and indicates
  73990. + * original XferSize size value for the descriptor.
  73991. + */
  73992. + uint32_t *n_bytes;
  73993. +
  73994. + /** Actual number of transfer descriptors in a list. */
  73995. + uint16_t ntd;
  73996. +
  73997. + /** First activated isochronous transfer descriptor index. */
  73998. + uint8_t td_first;
  73999. + /** Last activated isochronous transfer descriptor index. */
  74000. + uint8_t td_last;
  74001. +
  74002. + /** @} */
  74003. +
  74004. +
  74005. + uint16_t speed;
  74006. + uint16_t frame_usecs[8];
  74007. +
  74008. + uint32_t skip_count;
  74009. +} dwc_otg_qh_t;
  74010. +
  74011. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  74012. +
  74013. +typedef struct urb_tq_entry {
  74014. + struct urb *urb;
  74015. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  74016. +} urb_tq_entry_t;
  74017. +
  74018. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  74019. +
  74020. +/**
  74021. + * This structure holds the state of the HCD, including the non-periodic and
  74022. + * periodic schedules.
  74023. + */
  74024. +struct dwc_otg_hcd {
  74025. + /** The DWC otg device pointer */
  74026. + struct dwc_otg_device *otg_dev;
  74027. + /** DWC OTG Core Interface Layer */
  74028. + dwc_otg_core_if_t *core_if;
  74029. +
  74030. + /** Function HCD driver callbacks */
  74031. + struct dwc_otg_hcd_function_ops *fops;
  74032. +
  74033. + /** Internal DWC HCD Flags */
  74034. + volatile union dwc_otg_hcd_internal_flags {
  74035. + uint32_t d32;
  74036. + struct {
  74037. + unsigned port_connect_status_change:1;
  74038. + unsigned port_connect_status:1;
  74039. + unsigned port_reset_change:1;
  74040. + unsigned port_enable_change:1;
  74041. + unsigned port_suspend_change:1;
  74042. + unsigned port_over_current_change:1;
  74043. + unsigned port_l1_change:1;
  74044. + unsigned reserved:26;
  74045. + } b;
  74046. + } flags;
  74047. +
  74048. + /**
  74049. + * Inactive items in the non-periodic schedule. This is a list of
  74050. + * Queue Heads. Transfers associated with these Queue Heads are not
  74051. + * currently assigned to a host channel.
  74052. + */
  74053. + dwc_list_link_t non_periodic_sched_inactive;
  74054. +
  74055. + /**
  74056. + * Active items in the non-periodic schedule. This is a list of
  74057. + * Queue Heads. Transfers associated with these Queue Heads are
  74058. + * currently assigned to a host channel.
  74059. + */
  74060. + dwc_list_link_t non_periodic_sched_active;
  74061. +
  74062. + /**
  74063. + * Pointer to the next Queue Head to process in the active
  74064. + * non-periodic schedule.
  74065. + */
  74066. + dwc_list_link_t *non_periodic_qh_ptr;
  74067. +
  74068. + /**
  74069. + * Inactive items in the periodic schedule. This is a list of QHs for
  74070. + * periodic transfers that are _not_ scheduled for the next frame.
  74071. + * Each QH in the list has an interval counter that determines when it
  74072. + * needs to be scheduled for execution. This scheduling mechanism
  74073. + * allows only a simple calculation for periodic bandwidth used (i.e.
  74074. + * must assume that all periodic transfers may need to execute in the
  74075. + * same frame). However, it greatly simplifies scheduling and should
  74076. + * be sufficient for the vast majority of OTG hosts, which need to
  74077. + * connect to a small number of peripherals at one time.
  74078. + *
  74079. + * Items move from this list to periodic_sched_ready when the QH
  74080. + * interval counter is 0 at SOF.
  74081. + */
  74082. + dwc_list_link_t periodic_sched_inactive;
  74083. +
  74084. + /**
  74085. + * List of periodic QHs that are ready for execution in the next
  74086. + * frame, but have not yet been assigned to host channels.
  74087. + *
  74088. + * Items move from this list to periodic_sched_assigned as host
  74089. + * channels become available during the current frame.
  74090. + */
  74091. + dwc_list_link_t periodic_sched_ready;
  74092. +
  74093. + /**
  74094. + * List of periodic QHs to be executed in the next frame that are
  74095. + * assigned to host channels.
  74096. + *
  74097. + * Items move from this list to periodic_sched_queued as the
  74098. + * transactions for the QH are queued to the DWC_otg controller.
  74099. + */
  74100. + dwc_list_link_t periodic_sched_assigned;
  74101. +
  74102. + /**
  74103. + * List of periodic QHs that have been queued for execution.
  74104. + *
  74105. + * Items move from this list to either periodic_sched_inactive or
  74106. + * periodic_sched_ready when the channel associated with the transfer
  74107. + * is released. If the interval for the QH is 1, the item moves to
  74108. + * periodic_sched_ready because it must be rescheduled for the next
  74109. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  74110. + */
  74111. + dwc_list_link_t periodic_sched_queued;
  74112. +
  74113. + /**
  74114. + * Total bandwidth claimed so far for periodic transfers. This value
  74115. + * is in microseconds per (micro)frame. The assumption is that all
  74116. + * periodic transfers may occur in the same (micro)frame.
  74117. + */
  74118. + uint16_t periodic_usecs;
  74119. +
  74120. + /**
  74121. + * Total bandwidth claimed so far for all periodic transfers
  74122. + * in a frame.
  74123. + * This will include a mixture of HS and FS transfers.
  74124. + * Units are microseconds per (micro)frame.
  74125. + * We have a budget per frame and have to schedule
  74126. + * transactions accordingly.
  74127. + * Watch out for the fact that things are actually scheduled for the
  74128. + * "next frame".
  74129. + */
  74130. + uint16_t frame_usecs[8];
  74131. +
  74132. +
  74133. + /**
  74134. + * Frame number read from the core at SOF. The value ranges from 0 to
  74135. + * DWC_HFNUM_MAX_FRNUM.
  74136. + */
  74137. + uint16_t frame_number;
  74138. +
  74139. + /**
  74140. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  74141. + */
  74142. + uint16_t periodic_qh_count;
  74143. +
  74144. + /**
  74145. + * Free host channels in the controller. This is a list of
  74146. + * dwc_hc_t items.
  74147. + */
  74148. + struct hc_list free_hc_list;
  74149. + /**
  74150. + * Number of host channels assigned to periodic transfers. Currently
  74151. + * assuming that there is a dedicated host channel for each periodic
  74152. + * transaction and at least one host channel available for
  74153. + * non-periodic transactions.
  74154. + */
  74155. + int periodic_channels; /* microframe_schedule==0 */
  74156. +
  74157. + /**
  74158. + * Number of host channels assigned to non-periodic transfers.
  74159. + */
  74160. + int non_periodic_channels; /* microframe_schedule==0 */
  74161. +
  74162. + /**
  74163. + * Number of host channels assigned to non-periodic transfers.
  74164. + */
  74165. + int available_host_channels;
  74166. +
  74167. + /**
  74168. + * Array of pointers to the host channel descriptors. Allows accessing
  74169. + * a host channel descriptor given the host channel number. This is
  74170. + * useful in interrupt handlers.
  74171. + */
  74172. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  74173. +
  74174. + /**
  74175. + * Buffer to use for any data received during the status phase of a
  74176. + * control transfer. Normally no data is transferred during the status
  74177. + * phase. This buffer is used as a bit bucket.
  74178. + */
  74179. + uint8_t *status_buf;
  74180. +
  74181. + /**
  74182. + * DMA address for status_buf.
  74183. + */
  74184. + dma_addr_t status_buf_dma;
  74185. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  74186. +
  74187. + /**
  74188. + * Connection timer. An OTG host must display a message if the device
  74189. + * does not connect. Started when the VBus power is turned on via
  74190. + * sysfs attribute "buspower".
  74191. + */
  74192. + dwc_timer_t *conn_timer;
  74193. +
  74194. + /* Tasket to do a reset */
  74195. + dwc_tasklet_t *reset_tasklet;
  74196. +
  74197. + dwc_tasklet_t *completion_tasklet;
  74198. + struct urb_list completed_urb_list;
  74199. +
  74200. + /* */
  74201. + dwc_spinlock_t *lock;
  74202. + dwc_spinlock_t *channel_lock;
  74203. + /**
  74204. + * Private data that could be used by OS wrapper.
  74205. + */
  74206. + void *priv;
  74207. +
  74208. + uint8_t otg_port;
  74209. +
  74210. + /** Frame List */
  74211. + uint32_t *frame_list;
  74212. +
  74213. + /** Hub - Port assignment */
  74214. + int hub_port[128];
  74215. +#ifdef FIQ_DEBUG
  74216. + int hub_port_alloc[2048];
  74217. +#endif
  74218. +
  74219. + /** Frame List DMA address */
  74220. + dma_addr_t frame_list_dma;
  74221. +
  74222. +#ifdef DEBUG
  74223. + uint32_t frrem_samples;
  74224. + uint64_t frrem_accum;
  74225. +
  74226. + uint32_t hfnum_7_samples_a;
  74227. + uint64_t hfnum_7_frrem_accum_a;
  74228. + uint32_t hfnum_0_samples_a;
  74229. + uint64_t hfnum_0_frrem_accum_a;
  74230. + uint32_t hfnum_other_samples_a;
  74231. + uint64_t hfnum_other_frrem_accum_a;
  74232. +
  74233. + uint32_t hfnum_7_samples_b;
  74234. + uint64_t hfnum_7_frrem_accum_b;
  74235. + uint32_t hfnum_0_samples_b;
  74236. + uint64_t hfnum_0_frrem_accum_b;
  74237. + uint32_t hfnum_other_samples_b;
  74238. + uint64_t hfnum_other_frrem_accum_b;
  74239. +#endif
  74240. +};
  74241. +
  74242. +/** @name Transaction Execution Functions */
  74243. +/** @{ */
  74244. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  74245. + * hcd);
  74246. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  74247. + dwc_otg_transaction_type_e tr_type);
  74248. +
  74249. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  74250. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  74251. +
  74252. +
  74253. +/** @} */
  74254. +
  74255. +/** @name Interrupt Handler Functions */
  74256. +/** @{ */
  74257. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74258. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74259. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  74260. + dwc_otg_hcd);
  74261. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  74262. + dwc_otg_hcd);
  74263. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  74264. + dwc_otg_hcd);
  74265. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  74266. + dwc_otg_hcd);
  74267. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74268. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  74269. + dwc_otg_hcd);
  74270. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74271. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74272. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  74273. + uint32_t num);
  74274. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74275. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  74276. + dwc_otg_hcd);
  74277. +/** @} */
  74278. +
  74279. +/** @name Schedule Queue Functions */
  74280. +/** @{ */
  74281. +
  74282. +/* Implemented in dwc_otg_hcd_queue.c */
  74283. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  74284. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  74285. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  74286. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  74287. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  74288. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  74289. + int sched_csplit);
  74290. +
  74291. +/** Remove and free a QH */
  74292. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  74293. + dwc_otg_qh_t * qh)
  74294. +{
  74295. + dwc_irqflags_t flags;
  74296. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  74297. + dwc_otg_hcd_qh_remove(hcd, qh);
  74298. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  74299. + dwc_otg_hcd_qh_free(hcd, qh);
  74300. +}
  74301. +
  74302. +/** Allocates memory for a QH structure.
  74303. + * @return Returns the memory allocate or NULL on error. */
  74304. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  74305. +{
  74306. + if (atomic_alloc)
  74307. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  74308. + else
  74309. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  74310. +}
  74311. +
  74312. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  74313. + int atomic_alloc);
  74314. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  74315. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  74316. + dwc_otg_qh_t ** qh, int atomic_alloc);
  74317. +
  74318. +/** Allocates memory for a QTD structure.
  74319. + * @return Returns the memory allocate or NULL on error. */
  74320. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  74321. +{
  74322. + if (atomic_alloc)
  74323. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  74324. + else
  74325. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  74326. +}
  74327. +
  74328. +/** Frees the memory for a QTD structure. QTD should already be removed from
  74329. + * list.
  74330. + * @param qtd QTD to free.*/
  74331. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  74332. +{
  74333. + DWC_FREE(qtd);
  74334. +}
  74335. +
  74336. +/** Removes a QTD from list.
  74337. + * @param hcd HCD instance.
  74338. + * @param qtd QTD to remove from list.
  74339. + * @param qh QTD belongs to.
  74340. + */
  74341. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  74342. + dwc_otg_qtd_t * qtd,
  74343. + dwc_otg_qh_t * qh)
  74344. +{
  74345. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  74346. +}
  74347. +
  74348. +/** Remove and free a QTD
  74349. + * Need to disable IRQ and hold hcd lock while calling this function out of
  74350. + * interrupt servicing chain */
  74351. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  74352. + dwc_otg_qtd_t * qtd,
  74353. + dwc_otg_qh_t * qh)
  74354. +{
  74355. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  74356. + dwc_otg_hcd_qtd_free(qtd);
  74357. +}
  74358. +
  74359. +/** @} */
  74360. +
  74361. +/** @name Descriptor DMA Supporting Functions */
  74362. +/** @{ */
  74363. +
  74364. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  74365. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  74366. + dwc_hc_t * hc,
  74367. + dwc_otg_hc_regs_t * hc_regs,
  74368. + dwc_otg_halt_status_e halt_status);
  74369. +
  74370. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  74371. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  74372. +
  74373. +/** @} */
  74374. +
  74375. +/** @name Internal Functions */
  74376. +/** @{ */
  74377. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  74378. +/** @} */
  74379. +
  74380. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74381. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  74382. + uint8_t devaddr);
  74383. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  74384. +#endif
  74385. +
  74386. +/** Gets the QH that contains the list_head */
  74387. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  74388. +
  74389. +/** Gets the QTD that contains the list_head */
  74390. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  74391. +
  74392. +/** Check if QH is non-periodic */
  74393. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  74394. + (_qh_ptr_->ep_type == UE_CONTROL))
  74395. +
  74396. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  74397. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  74398. +
  74399. +/** Packet size for any kind of endpoint descriptor */
  74400. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  74401. +
  74402. +/**
  74403. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  74404. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  74405. + * frame number when the max frame number is reached.
  74406. + */
  74407. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  74408. +{
  74409. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  74410. + (DWC_HFNUM_MAX_FRNUM >> 1);
  74411. +}
  74412. +
  74413. +/**
  74414. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  74415. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  74416. + * number when the max frame number is reached.
  74417. + */
  74418. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  74419. +{
  74420. + return (frame1 != frame2) &&
  74421. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  74422. + (DWC_HFNUM_MAX_FRNUM >> 1));
  74423. +}
  74424. +
  74425. +/**
  74426. + * Increments _frame by the amount specified by _inc. The addition is done
  74427. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  74428. + */
  74429. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  74430. +{
  74431. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  74432. +}
  74433. +
  74434. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  74435. +{
  74436. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  74437. +}
  74438. +
  74439. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  74440. +{
  74441. + return frame & 0x7;
  74442. +}
  74443. +
  74444. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  74445. + dwc_otg_hc_regs_t * hc_regs,
  74446. + dwc_otg_qtd_t * qtd);
  74447. +
  74448. +#ifdef DEBUG
  74449. +/**
  74450. + * Macro to sample the remaining PHY clocks left in the current frame. This
  74451. + * may be used during debugging to determine the average time it takes to
  74452. + * execute sections of code. There are two possible sample points, "a" and
  74453. + * "b", so the _letter argument must be one of these values.
  74454. + *
  74455. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  74456. + * example, "cat /sys/devices/lm0/hcd_frrem".
  74457. + */
  74458. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  74459. +{ \
  74460. + hfnum_data_t hfnum; \
  74461. + dwc_otg_qtd_t *qtd; \
  74462. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  74463. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  74464. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  74465. + switch (hfnum.b.frnum & 0x7) { \
  74466. + case 7: \
  74467. + _hcd->hfnum_7_samples_##_letter++; \
  74468. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  74469. + break; \
  74470. + case 0: \
  74471. + _hcd->hfnum_0_samples_##_letter++; \
  74472. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  74473. + break; \
  74474. + default: \
  74475. + _hcd->hfnum_other_samples_##_letter++; \
  74476. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  74477. + break; \
  74478. + } \
  74479. + } \
  74480. +}
  74481. +#else
  74482. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  74483. +#endif
  74484. +#endif
  74485. +#endif /* DWC_DEVICE_ONLY */
  74486. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  74487. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  74488. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-03-13 12:46:39.516097989 +0100
  74489. @@ -0,0 +1,417 @@
  74490. +/* ==========================================================================
  74491. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  74492. + * $Revision: #12 $
  74493. + * $Date: 2011/10/26 $
  74494. + * $Change: 1873028 $
  74495. + *
  74496. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74497. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74498. + * otherwise expressly agreed to in writing between Synopsys and you.
  74499. + *
  74500. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74501. + * any End User Software License Agreement or Agreement for Licensed Product
  74502. + * with Synopsys or any supplement thereto. You are permitted to use and
  74503. + * redistribute this Software in source and binary forms, with or without
  74504. + * modification, provided that redistributions of source code must retain this
  74505. + * notice. You may not view, use, disclose, copy or distribute this file or
  74506. + * any information contained herein except pursuant to this license grant from
  74507. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74508. + * below, then you are not authorized to use the Software.
  74509. + *
  74510. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74511. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74512. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74513. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74514. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74515. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74516. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74517. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74518. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74519. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74520. + * DAMAGE.
  74521. + * ========================================================================== */
  74522. +#ifndef DWC_DEVICE_ONLY
  74523. +#ifndef __DWC_HCD_IF_H__
  74524. +#define __DWC_HCD_IF_H__
  74525. +
  74526. +#include "dwc_otg_core_if.h"
  74527. +
  74528. +/** @file
  74529. + * This file defines DWC_OTG HCD Core API.
  74530. + */
  74531. +
  74532. +struct dwc_otg_hcd;
  74533. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  74534. +
  74535. +struct dwc_otg_hcd_urb;
  74536. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  74537. +
  74538. +/** @name HCD Function Driver Callbacks */
  74539. +/** @{ */
  74540. +
  74541. +/** This function is called whenever core switches to host mode. */
  74542. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  74543. +
  74544. +/** This function is called when device has been disconnected */
  74545. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  74546. +
  74547. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  74548. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  74549. + void *urb_handle,
  74550. + uint32_t * hub_addr,
  74551. + uint32_t * port_addr);
  74552. +/** Via this function HCD core gets device speed */
  74553. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  74554. + void *urb_handle);
  74555. +
  74556. +/** This function is called when urb is completed */
  74557. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  74558. + void *urb_handle,
  74559. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  74560. + int32_t status);
  74561. +
  74562. +/** Via this function HCD core gets b_hnp_enable parameter */
  74563. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  74564. +
  74565. +struct dwc_otg_hcd_function_ops {
  74566. + dwc_otg_hcd_start_cb_t start;
  74567. + dwc_otg_hcd_disconnect_cb_t disconnect;
  74568. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  74569. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  74570. + dwc_otg_hcd_complete_urb_cb_t complete;
  74571. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  74572. +};
  74573. +/** @} */
  74574. +
  74575. +/** @name HCD Core API */
  74576. +/** @{ */
  74577. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  74578. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  74579. +
  74580. +/** This function should be called to initiate HCD Core.
  74581. + *
  74582. + * @param hcd The HCD
  74583. + * @param core_if The DWC_OTG Core
  74584. + *
  74585. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  74586. + * Returns 0 on success
  74587. + */
  74588. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  74589. +
  74590. +/** Frees HCD
  74591. + *
  74592. + * @param hcd The HCD
  74593. + */
  74594. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  74595. +
  74596. +/** This function should be called on every hardware interrupt.
  74597. + *
  74598. + * @param dwc_otg_hcd The HCD
  74599. + *
  74600. + * Returns non zero if interrupt is handled
  74601. + * Return 0 if interrupt is not handled
  74602. + */
  74603. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74604. +
  74605. +/** This function is used to handle the fast interrupt
  74606. + *
  74607. + */
  74608. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  74609. +
  74610. +/**
  74611. + * Returns private data set by
  74612. + * dwc_otg_hcd_set_priv_data function.
  74613. + *
  74614. + * @param hcd The HCD
  74615. + */
  74616. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  74617. +
  74618. +/**
  74619. + * Set private data.
  74620. + *
  74621. + * @param hcd The HCD
  74622. + * @param priv_data pointer to be stored in private data
  74623. + */
  74624. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  74625. +
  74626. +/**
  74627. + * This function initializes the HCD Core.
  74628. + *
  74629. + * @param hcd The HCD
  74630. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  74631. + *
  74632. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  74633. + * Returns 0 on success
  74634. + */
  74635. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  74636. + struct dwc_otg_hcd_function_ops *fops);
  74637. +
  74638. +/**
  74639. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  74640. + * stopped.
  74641. + *
  74642. + * @param hcd The HCD
  74643. + */
  74644. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  74645. +
  74646. +/**
  74647. + * Handles hub class-specific requests.
  74648. + *
  74649. + * @param dwc_otg_hcd The HCD
  74650. + * @param typeReq Request Type
  74651. + * @param wValue wValue from control request
  74652. + * @param wIndex wIndex from control request
  74653. + * @param buf data buffer
  74654. + * @param wLength data buffer length
  74655. + *
  74656. + * Returns -DWC_E_INVALID if invalid argument is passed
  74657. + * Returns 0 on success
  74658. + */
  74659. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  74660. + uint16_t typeReq, uint16_t wValue,
  74661. + uint16_t wIndex, uint8_t * buf,
  74662. + uint16_t wLength);
  74663. +
  74664. +/**
  74665. + * Returns otg port number.
  74666. + *
  74667. + * @param hcd The HCD
  74668. + */
  74669. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  74670. +
  74671. +/**
  74672. + * Returns OTG version - either 1.3 or 2.0.
  74673. + *
  74674. + * @param core_if The core_if structure pointer
  74675. + */
  74676. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  74677. +
  74678. +/**
  74679. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  74680. + *
  74681. + * @param hcd The HCD
  74682. + */
  74683. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  74684. +
  74685. +/**
  74686. + * Returns current frame number.
  74687. + *
  74688. + * @param hcd The HCD
  74689. + */
  74690. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  74691. +
  74692. +/**
  74693. + * Dumps hcd state.
  74694. + *
  74695. + * @param hcd The HCD
  74696. + */
  74697. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  74698. +
  74699. +/**
  74700. + * Dump the average frame remaining at SOF. This can be used to
  74701. + * determine average interrupt latency. Frame remaining is also shown for
  74702. + * start transfer and two additional sample points.
  74703. + * Currently this function is not implemented.
  74704. + *
  74705. + * @param hcd The HCD
  74706. + */
  74707. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  74708. +
  74709. +/**
  74710. + * Sends LPM transaction to the local device.
  74711. + *
  74712. + * @param hcd The HCD
  74713. + * @param devaddr Device Address
  74714. + * @param hird Host initiated resume duration
  74715. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  74716. + *
  74717. + * Returns negative value if sending LPM transaction was not succeeded.
  74718. + * Returns 0 on success.
  74719. + */
  74720. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  74721. + uint8_t hird, uint8_t bRemoteWake);
  74722. +
  74723. +/* URB interface */
  74724. +
  74725. +/**
  74726. + * Allocates memory for dwc_otg_hcd_urb structure.
  74727. + * Allocated memory should be freed by call of DWC_FREE.
  74728. + *
  74729. + * @param hcd The HCD
  74730. + * @param iso_desc_count Count of ISOC descriptors
  74731. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  74732. + */
  74733. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  74734. + int iso_desc_count,
  74735. + int atomic_alloc);
  74736. +
  74737. +/**
  74738. + * Set pipe information in URB.
  74739. + *
  74740. + * @param hcd_urb DWC_OTG URB
  74741. + * @param devaddr Device Address
  74742. + * @param ep_num Endpoint Number
  74743. + * @param ep_type Endpoint Type
  74744. + * @param ep_dir Endpoint Direction
  74745. + * @param mps Max Packet Size
  74746. + */
  74747. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  74748. + uint8_t devaddr, uint8_t ep_num,
  74749. + uint8_t ep_type, uint8_t ep_dir,
  74750. + uint16_t mps);
  74751. +
  74752. +/* Transfer flags */
  74753. +#define URB_GIVEBACK_ASAP 0x1
  74754. +#define URB_SEND_ZERO_PACKET 0x2
  74755. +
  74756. +/**
  74757. + * Sets dwc_otg_hcd_urb parameters.
  74758. + *
  74759. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  74760. + * @param urb_handle Unique handle for request, this will be passed back
  74761. + * to function driver in completion callback.
  74762. + * @param buf The buffer for the data
  74763. + * @param dma The DMA buffer for the data
  74764. + * @param buflen Transfer length
  74765. + * @param sp Buffer for setup data
  74766. + * @param sp_dma DMA address of setup data buffer
  74767. + * @param flags Transfer flags
  74768. + * @param interval Polling interval for interrupt or isochronous transfers.
  74769. + */
  74770. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  74771. + void *urb_handle, void *buf,
  74772. + dwc_dma_t dma, uint32_t buflen, void *sp,
  74773. + dwc_dma_t sp_dma, uint32_t flags,
  74774. + uint16_t interval);
  74775. +
  74776. +/** Gets status from dwc_otg_hcd_urb
  74777. + *
  74778. + * @param dwc_otg_urb DWC_OTG URB
  74779. + */
  74780. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  74781. +
  74782. +/** Gets actual length from dwc_otg_hcd_urb
  74783. + *
  74784. + * @param dwc_otg_urb DWC_OTG URB
  74785. + */
  74786. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  74787. + dwc_otg_urb);
  74788. +
  74789. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  74790. + *
  74791. + * @param dwc_otg_urb DWC_OTG URB
  74792. + */
  74793. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  74794. + dwc_otg_urb);
  74795. +
  74796. +/** Set ISOC descriptor offset and length
  74797. + *
  74798. + * @param dwc_otg_urb DWC_OTG URB
  74799. + * @param desc_num ISOC descriptor number
  74800. + * @param offset Offset from beginig of buffer.
  74801. + * @param length Transaction length
  74802. + */
  74803. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74804. + int desc_num, uint32_t offset,
  74805. + uint32_t length);
  74806. +
  74807. +/** Get status of ISOC descriptor, specified by desc_num
  74808. + *
  74809. + * @param dwc_otg_urb DWC_OTG URB
  74810. + * @param desc_num ISOC descriptor number
  74811. + */
  74812. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  74813. + dwc_otg_urb, int desc_num);
  74814. +
  74815. +/** Get actual length of ISOC descriptor, specified by desc_num
  74816. + *
  74817. + * @param dwc_otg_urb DWC_OTG URB
  74818. + * @param desc_num ISOC descriptor number
  74819. + */
  74820. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  74821. + dwc_otg_urb,
  74822. + int desc_num);
  74823. +
  74824. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  74825. + *
  74826. + * @param dwc_otg_hcd The HCD
  74827. + * @param dwc_otg_urb DWC_OTG URB
  74828. + * @param ep_handle Out parameter for returning endpoint handle
  74829. + * @param atomic_alloc Flag to do atomic allocation if needed
  74830. + *
  74831. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  74832. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  74833. + * Returns 0 on success.
  74834. + */
  74835. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  74836. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  74837. + void **ep_handle, int atomic_alloc);
  74838. +
  74839. +/** De-queue the specified URB
  74840. + *
  74841. + * @param dwc_otg_hcd The HCD
  74842. + * @param dwc_otg_urb DWC_OTG URB
  74843. + */
  74844. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  74845. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  74846. +
  74847. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  74848. + * Any URBs for the endpoint must already be dequeued.
  74849. + *
  74850. + * @param hcd The HCD
  74851. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  74852. + * @param retry Number of retries if there are queued transfers.
  74853. + *
  74854. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  74855. + * Returns 0 on success
  74856. + */
  74857. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  74858. + int retry);
  74859. +
  74860. +/* Resets the data toggle in qh structure. This function can be called from
  74861. + * usb_clear_halt routine.
  74862. + *
  74863. + * @param hcd The HCD
  74864. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  74865. + *
  74866. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  74867. + * Returns 0 on success
  74868. + */
  74869. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  74870. +
  74871. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  74872. + *
  74873. + * @param hcd The HCD
  74874. + * @param port Port number
  74875. + */
  74876. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  74877. +
  74878. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  74879. + * Only for ISOC and INTERRUPT endpoints.
  74880. + *
  74881. + * @param hcd The HCD
  74882. + * @param ep_handle Endpoint handle
  74883. + */
  74884. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  74885. + void *ep_handle);
  74886. +
  74887. +/** Call this function to check if bandwidth was freed for specified endpoint.
  74888. + *
  74889. + * @param hcd The HCD
  74890. + * @param ep_handle Endpoint handle
  74891. + */
  74892. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  74893. +
  74894. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  74895. + * Only for ISOC and INTERRUPT endpoints.
  74896. + *
  74897. + * @param hcd The HCD
  74898. + * @param ep_handle Endpoint handle
  74899. + */
  74900. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  74901. + void *ep_handle);
  74902. +
  74903. +/** @} */
  74904. +
  74905. +#endif /* __DWC_HCD_IF_H__ */
  74906. +#endif /* DWC_DEVICE_ONLY */
  74907. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  74908. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  74909. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-03-13 12:46:39.516097989 +0100
  74910. @@ -0,0 +1,2741 @@
  74911. +/* ==========================================================================
  74912. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  74913. + * $Revision: #89 $
  74914. + * $Date: 2011/10/20 $
  74915. + * $Change: 1869487 $
  74916. + *
  74917. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74918. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74919. + * otherwise expressly agreed to in writing between Synopsys and you.
  74920. + *
  74921. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74922. + * any End User Software License Agreement or Agreement for Licensed Product
  74923. + * with Synopsys or any supplement thereto. You are permitted to use and
  74924. + * redistribute this Software in source and binary forms, with or without
  74925. + * modification, provided that redistributions of source code must retain this
  74926. + * notice. You may not view, use, disclose, copy or distribute this file or
  74927. + * any information contained herein except pursuant to this license grant from
  74928. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74929. + * below, then you are not authorized to use the Software.
  74930. + *
  74931. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74932. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74933. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74934. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74935. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74936. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74937. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74938. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74939. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74940. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74941. + * DAMAGE.
  74942. + * ========================================================================== */
  74943. +#ifndef DWC_DEVICE_ONLY
  74944. +
  74945. +#include "dwc_otg_hcd.h"
  74946. +#include "dwc_otg_regs.h"
  74947. +#include "dwc_otg_mphi_fix.h"
  74948. +
  74949. +#include <linux/jiffies.h>
  74950. +#include <mach/hardware.h>
  74951. +#include <asm/fiq.h>
  74952. +
  74953. +
  74954. +extern bool microframe_schedule;
  74955. +
  74956. +/** @file
  74957. + * This file contains the implementation of the HCD Interrupt handlers.
  74958. + */
  74959. +
  74960. +/*
  74961. + * Some globals to communicate between the FIQ and INTERRUPT
  74962. + */
  74963. +
  74964. +void * dummy_send;
  74965. +mphi_regs_t c_mphi_regs;
  74966. +volatile void *dwc_regs_base;
  74967. +int fiq_done, int_done;
  74968. +
  74969. +gintsts_data_t gintsts_saved = {.d32 = 0};
  74970. +hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  74971. +hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  74972. +int split_out_xfersize[MAX_EPS_CHANNELS];
  74973. +haint_data_t haint_saved;
  74974. +
  74975. +int g_next_sched_frame, g_np_count, g_np_sent;
  74976. +static int mphi_int_count = 0 ;
  74977. +
  74978. +hcchar_data_t nak_hcchar;
  74979. +hctsiz_data_t nak_hctsiz;
  74980. +hcsplt_data_t nak_hcsplt;
  74981. +int nak_count;
  74982. +
  74983. +int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  74984. +int split_start_frame[MAX_EPS_CHANNELS];
  74985. +int queued_port[MAX_EPS_CHANNELS];
  74986. +
  74987. +#ifdef FIQ_DEBUG
  74988. +char buffer[1000*16];
  74989. +int wptr;
  74990. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  74991. +{
  74992. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  74993. + va_list args;
  74994. + char text[17];
  74995. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  74996. + unsigned long flags;
  74997. +
  74998. + local_irq_save(flags);
  74999. + local_fiq_disable();
  75000. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  75001. + {
  75002. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  75003. + va_start(args, fmt);
  75004. + vsnprintf(text+8, 9, fmt, args);
  75005. + va_end(args);
  75006. +
  75007. + memcpy(buffer + wptr, text, 16);
  75008. + wptr = (wptr + 16) % sizeof(buffer);
  75009. + }
  75010. + local_irq_restore(flags);
  75011. +}
  75012. +#endif
  75013. +
  75014. +void notrace fiq_queue_request(int channel, int odd_frame)
  75015. +{
  75016. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  75017. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  75018. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
  75019. +
  75020. + if(hcsplt.b.spltena == 0)
  75021. + {
  75022. + fiq_print(FIQDBG_ERR, "SPLTENA ");
  75023. + BUG();
  75024. + }
  75025. +
  75026. + if(hcchar.b.epdir == 1)
  75027. + {
  75028. + fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
  75029. + }
  75030. + else
  75031. + {
  75032. + hctsiz.b.xfersize = 0;
  75033. + fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
  75034. + }
  75035. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
  75036. +
  75037. + hcsplt.b.compsplt = 1;
  75038. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
  75039. +
  75040. + // Send the Split complete
  75041. + hcchar.b.chen = 1;
  75042. + hcchar.b.oddfrm = odd_frame ? 1 : 0;
  75043. +
  75044. + // Post this for transmit on the next frame for periodic or this frame for non-periodic
  75045. + fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
  75046. +
  75047. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
  75048. +}
  75049. +
  75050. +static int last_sof = -1;
  75051. +
  75052. +/*
  75053. +** Function to handle the start of frame interrupt, choose whether we need to do anything and
  75054. +** therefore trigger the main interrupt
  75055. +**
  75056. +** returns int != 0 - interrupt has been handled
  75057. +*/
  75058. +int diff;
  75059. +
  75060. +int notrace fiq_sof_handle(hfnum_data_t hfnum)
  75061. +{
  75062. + int handled = 0;
  75063. + int i;
  75064. +
  75065. + // Just check that once we're running we don't miss a SOF
  75066. + /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
  75067. + {
  75068. + fiq_print(FIQDBG_ERR, "LASTSOF ");
  75069. + fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
  75070. + fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
  75071. + BUG();
  75072. + }*/
  75073. +
  75074. + // Only start remembering the last sof when the interrupt has been
  75075. + // enabled (we don't check the mask to come in here...)
  75076. + if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
  75077. + last_sof = hfnum.b.frnum;
  75078. +
  75079. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  75080. + {
  75081. + if(complete_sched[i] != -1)
  75082. + {
  75083. + if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
  75084. + {
  75085. + fiq_queue_request(i, hfnum.b.frnum & 1);
  75086. + complete_sched[i] = -1;
  75087. + }
  75088. + }
  75089. +
  75090. + if(complete_sched[i] != -1)
  75091. + {
  75092. + // This is because we've seen a split complete occur with no start...
  75093. + // most likely because missed the complete 0x3fff frames ago!
  75094. +
  75095. + diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
  75096. + if(diff > 32 && diff < 0x3f00)
  75097. + {
  75098. + fiq_print(FIQDBG_ERR, "SPLTMISS");
  75099. + BUG();
  75100. + }
  75101. + }
  75102. + }
  75103. +
  75104. + if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  75105. + {
  75106. + /*
  75107. + * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
  75108. + * g_next_sched_frame is the next frame we have periodic packets for
  75109. + *
  75110. + * if neither of these are required for this frame then just clear the interrupt
  75111. + */
  75112. + handled = 1;
  75113. +
  75114. + }
  75115. +
  75116. + return handled;
  75117. +}
  75118. +
  75119. +int notrace port_id(hcsplt_data_t hcsplt)
  75120. +{
  75121. + return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
  75122. +}
  75123. +
  75124. +int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
  75125. +{
  75126. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  75127. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  75128. + hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
  75129. + hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
  75130. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
  75131. +
  75132. + hcint_saved[channel].d32 |= hcint.d32;
  75133. + hcintmsk_saved[channel].d32 = hcintmsk.d32;
  75134. +
  75135. + if(hcsplt.b.spltena)
  75136. + {
  75137. + fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
  75138. + if(hcint.b.chhltd)
  75139. + {
  75140. + fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
  75141. + fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
  75142. + }
  75143. + if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
  75144. + {
  75145. + queued_port[channel] = 0;
  75146. + fiq_print(FIQDBG_ERR, "CHAN ERR");
  75147. + }
  75148. + if(hcint.b.xfercomp)
  75149. + {
  75150. + // Clear the port allocation and transmit anything also on this port
  75151. + queued_port[channel] = 0;
  75152. + fiq_print(FIQDBG_SCHED, "XFERCOMP");
  75153. + }
  75154. + if(hcint.b.nak)
  75155. + {
  75156. + queued_port[channel] = 0;
  75157. + fiq_print(FIQDBG_SCHED, "NAK");
  75158. + }
  75159. + if(hcint.b.ack && !hcsplt.b.compsplt)
  75160. + {
  75161. + int i;
  75162. +
  75163. + // Do not complete isochronous out transactions
  75164. + if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
  75165. + {
  75166. + queued_port[channel] = 0;
  75167. + fiq_print(FIQDBG_SCHED, "ISOC_OUT");
  75168. + }
  75169. + else
  75170. + {
  75171. + // Make sure we check the port / hub combination that we sent this split on.
  75172. + // Do not queue a second request to the same port
  75173. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  75174. + {
  75175. + if(port_id(hcsplt) == queued_port[i])
  75176. + {
  75177. + fiq_print(FIQDBG_ERR, "PORTERR ");
  75178. + //BUG();
  75179. + }
  75180. + }
  75181. +
  75182. + split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
  75183. +
  75184. + // Note, the size of an OUT is in the start split phase, not
  75185. + // the complete split
  75186. + split_out_xfersize[channel] = hctsiz.b.xfersize;
  75187. +
  75188. + hcint_saved[channel].b.chhltd = 0;
  75189. + hcint_saved[channel].b.ack = 0;
  75190. +
  75191. + queued_port[channel] = port_id(hcsplt);
  75192. +
  75193. + if(hcchar.b.eptype & 1)
  75194. + {
  75195. + // Send the periodic complete in the same oddness frame as the ACK went...
  75196. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  75197. + // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  75198. + }
  75199. + else
  75200. + {
  75201. + // Schedule the split complete to occur later
  75202. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
  75203. + fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  75204. + }
  75205. + }
  75206. + }
  75207. + if(hcint.b.nyet)
  75208. + {
  75209. + fiq_print(FIQDBG_ERR, "NYETERR1");
  75210. + //BUG();
  75211. + // Can transmit a split complete up to uframe .0 of the next frame
  75212. + if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
  75213. + {
  75214. + // Send it next frame
  75215. + if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
  75216. + {
  75217. + fiq_print(FIQDBG_SCHED, "NYT:SEND");
  75218. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  75219. + }
  75220. + else
  75221. + {
  75222. + // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
  75223. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  75224. + fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  75225. + }
  75226. + hcint_saved[channel].b.chhltd = 0;
  75227. + hcint_saved[channel].b.nyet = 0;
  75228. + }
  75229. + else
  75230. + {
  75231. + queued_port[channel] = 0;
  75232. + fiq_print(FIQDBG_ERR, "NYETERR2");
  75233. + //BUG();
  75234. + }
  75235. + }
  75236. + }
  75237. + else
  75238. + {
  75239. + /*
  75240. + * If we have any of NAK, ACK, Datatlgerr active on a
  75241. + * non-split channel, the sole reason is to reset error
  75242. + * counts for a previously broken transaction. The FIQ
  75243. + * will thrash on NAK IN and ACK OUT in particular so
  75244. + * handle it "once" and allow the IRQ to do the rest.
  75245. + */
  75246. + hcint.d32 &= hcintmsk.d32;
  75247. + if(hcint.b.nak)
  75248. + {
  75249. + hcintmsk.b.nak = 0;
  75250. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  75251. + }
  75252. + if (hcint.b.ack)
  75253. + {
  75254. + hcintmsk.b.ack = 0;
  75255. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  75256. + }
  75257. + }
  75258. +
  75259. + // Clear the interrupt, this will also clear the HAINT bit
  75260. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
  75261. + return hcint_saved[channel].d32 == 0;
  75262. +}
  75263. +
  75264. +gintsts_data_t gintsts;
  75265. +gintmsk_data_t gintmsk;
  75266. +// triggered: The set of interrupts that were triggered
  75267. +// handled: The set of interrupts that have been handled (no IRQ is
  75268. +// required)
  75269. +// keep: The set of interrupts we want to keep unmasked even though we
  75270. +// want to trigger an IRQ to handle it (SOF and HCINTR)
  75271. +gintsts_data_t triggered, handled, keep;
  75272. +hfnum_data_t hfnum;
  75273. +
  75274. +void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
  75275. +{
  75276. +
  75277. + /* entry takes care to store registers we will be treading on here */
  75278. + asm __volatile__ (
  75279. + "mov ip, sp ;"
  75280. + /* stash FIQ and normal regs */
  75281. + "stmdb sp!, {r0-r12, lr};"
  75282. + /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
  75283. + "sub fp, ip, #512 ;"
  75284. + );
  75285. +
  75286. + // Cannot put local variables at the beginning of the function
  75287. + // because otherwise 'C' will play with the stack pointer. any locals
  75288. + // need to be inside the following block
  75289. + do
  75290. + {
  75291. + fiq_done++;
  75292. + gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
  75293. + gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
  75294. + hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
  75295. + triggered.d32 = gintsts.d32 & gintmsk.d32;
  75296. + handled.d32 = 0;
  75297. + keep.d32 = 0;
  75298. + fiq_print(FIQDBG_INT, "FIQ ");
  75299. + fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
  75300. + fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
  75301. + if(gintsts.d32)
  75302. + {
  75303. + // If port enabled
  75304. + if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
  75305. + {
  75306. + if(gintsts.b.sofintr)
  75307. + {
  75308. + if(fiq_sof_handle(hfnum))
  75309. + {
  75310. + handled.b.sofintr = 1; /* Handled in FIQ */
  75311. + }
  75312. + else
  75313. + {
  75314. + /* Keer interrupt unmasked */
  75315. + keep.b.sofintr = 1;
  75316. + }
  75317. + {
  75318. + // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
  75319. + // a start of frame interrupt
  75320. + gintsts_data_t gintsts = { .b.sofintr = 1 };
  75321. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  75322. + }
  75323. + }
  75324. +
  75325. + if(fiq_split_enable && gintsts.b.hcintr)
  75326. + {
  75327. + int i;
  75328. + haint_data_t haint;
  75329. + haintmsk_data_t haintmsk;
  75330. +
  75331. + haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
  75332. + haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
  75333. + haint.d32 &= haintmsk.d32;
  75334. + haint_saved.d32 |= haint.d32;
  75335. +
  75336. + fiq_print(FIQDBG_INT, "hcintr");
  75337. + fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
  75338. +
  75339. + // Go through each channel that has an enabled interrupt
  75340. + for(i = 0; i < 16; i++)
  75341. + if((haint.d32 >> i) & 1)
  75342. + if(fiq_hcintr_handle(i, hfnum))
  75343. + haint_saved.d32 &= ~(1 << i); /* this was handled */
  75344. +
  75345. + /* If we've handled all host channel interrupts then don't trigger the interrupt */
  75346. + if(haint_saved.d32 == 0)
  75347. + {
  75348. + handled.b.hcintr = 1;
  75349. + }
  75350. + else
  75351. + {
  75352. + /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
  75353. + keep.b.hcintr = 1;
  75354. + }
  75355. +
  75356. + {
  75357. + gintsts_data_t gintsts = { .b.hcintr = 1 };
  75358. +
  75359. + // Always clear the channel interrupt
  75360. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  75361. + }
  75362. + }
  75363. + }
  75364. + else
  75365. + {
  75366. + last_sof = -1;
  75367. + }
  75368. + }
  75369. +
  75370. + // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
  75371. + gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
  75372. + // Save those that were triggered but not handled
  75373. + gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
  75374. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  75375. +
  75376. + // Clear and save any unhandled interrupts and trigger the interrupt
  75377. + if(gintsts_saved.d32)
  75378. + {
  75379. + /* To enable the MPHI interrupt (INT 32)
  75380. + */
  75381. + FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
  75382. + FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
  75383. +
  75384. + mphi_int_count++;
  75385. + }
  75386. + }
  75387. + while(0);
  75388. +
  75389. + mb();
  75390. +
  75391. + /* exit back to normal mode restoring everything */
  75392. + asm __volatile__ (
  75393. + /* return FIQ regs back to pristine state
  75394. + * and get normal regs back
  75395. + */
  75396. + "ldmia sp!, {r0-r12, lr};"
  75397. +
  75398. + /* return */
  75399. + "subs pc, lr, #4;"
  75400. + );
  75401. +}
  75402. +
  75403. +/** This function handles interrupts for the HCD. */
  75404. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75405. +{
  75406. + int retval = 0;
  75407. + static int last_time;
  75408. +
  75409. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  75410. + gintsts_data_t gintsts;
  75411. + gintmsk_data_t gintmsk;
  75412. + hfnum_data_t hfnum;
  75413. +
  75414. +#ifdef DEBUG
  75415. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  75416. +
  75417. +#endif
  75418. +
  75419. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  75420. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  75421. +
  75422. + /* Exit from ISR if core is hibernated */
  75423. + if (core_if->hibernation_suspend == 1) {
  75424. + goto exit_handler_routine;
  75425. + }
  75426. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  75427. + /* Check if HOST Mode */
  75428. + if (dwc_otg_is_host_mode(core_if)) {
  75429. + local_fiq_disable();
  75430. + gintmsk.d32 |= gintsts_saved.d32;
  75431. + gintsts.d32 |= gintsts_saved.d32;
  75432. + gintsts_saved.d32 = 0;
  75433. + local_fiq_enable();
  75434. + if (!gintsts.d32) {
  75435. + goto exit_handler_routine;
  75436. + }
  75437. + gintsts.d32 &= gintmsk.d32;
  75438. +
  75439. +#ifdef DEBUG
  75440. + // We should be OK doing this because the common interrupts should already have been serviced
  75441. + /* Don't print debug message in the interrupt handler on SOF */
  75442. +#ifndef DEBUG_SOF
  75443. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  75444. +#endif
  75445. + DWC_DEBUGPL(DBG_HCDI, "\n");
  75446. +#endif
  75447. +
  75448. +#ifdef DEBUG
  75449. +#ifndef DEBUG_SOF
  75450. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  75451. +#endif
  75452. + DWC_DEBUGPL(DBG_HCDI,
  75453. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  75454. + gintsts.d32, core_if);
  75455. +#endif
  75456. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  75457. + if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  75458. + {
  75459. + /* Note, we should never get here if the FIQ is doing it's job properly*/
  75460. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  75461. + }
  75462. + else if (gintsts.b.sofintr) {
  75463. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  75464. + }
  75465. +
  75466. + if (gintsts.b.rxstsqlvl) {
  75467. + retval |=
  75468. + dwc_otg_hcd_handle_rx_status_q_level_intr
  75469. + (dwc_otg_hcd);
  75470. + }
  75471. + if (gintsts.b.nptxfempty) {
  75472. + retval |=
  75473. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  75474. + (dwc_otg_hcd);
  75475. + }
  75476. + if (gintsts.b.i2cintr) {
  75477. + /** @todo Implement i2cintr handler. */
  75478. + }
  75479. + if (gintsts.b.portintr) {
  75480. +
  75481. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  75482. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  75483. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  75484. + }
  75485. + if (gintsts.b.hcintr) {
  75486. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  75487. + }
  75488. + if (gintsts.b.ptxfempty) {
  75489. + retval |=
  75490. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  75491. + (dwc_otg_hcd);
  75492. + }
  75493. +#ifdef DEBUG
  75494. +#ifndef DEBUG_SOF
  75495. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  75496. +#endif
  75497. + {
  75498. + DWC_DEBUGPL(DBG_HCDI,
  75499. + "DWC OTG HCD Finished Servicing Interrupts\n");
  75500. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  75501. + DWC_READ_REG32(&global_regs->gintsts));
  75502. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  75503. + DWC_READ_REG32(&global_regs->gintmsk));
  75504. + }
  75505. +#endif
  75506. +
  75507. +#ifdef DEBUG
  75508. +#ifndef DEBUG_SOF
  75509. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  75510. +#endif
  75511. + DWC_DEBUGPL(DBG_HCDI, "\n");
  75512. +#endif
  75513. +
  75514. + }
  75515. +
  75516. +exit_handler_routine:
  75517. +
  75518. + if (fiq_fix_enable)
  75519. + {
  75520. + local_fiq_disable();
  75521. + // Make sure that we don't clear the interrupt if we've still got pending work to do
  75522. + if(gintsts_saved.d32 == 0)
  75523. + {
  75524. + /* Clear the MPHI interrupt */
  75525. + DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
  75526. + if (mphi_int_count >= 60)
  75527. + {
  75528. + DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
  75529. + while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
  75530. + ;
  75531. + DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
  75532. + mphi_int_count = 0;
  75533. + }
  75534. + int_done++;
  75535. + }
  75536. +
  75537. + // Unmask handled interrupts
  75538. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  75539. + //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
  75540. +
  75541. + local_fiq_enable();
  75542. +
  75543. + if((jiffies / HZ) > last_time)
  75544. + {
  75545. + /* Once a second output the fiq and irq numbers, useful for debug */
  75546. + last_time = jiffies / HZ;
  75547. + DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
  75548. + }
  75549. + }
  75550. +
  75551. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  75552. + return retval;
  75553. +}
  75554. +
  75555. +#ifdef DWC_TRACK_MISSED_SOFS
  75556. +
  75557. +#warning Compiling code to track missed SOFs
  75558. +#define FRAME_NUM_ARRAY_SIZE 1000
  75559. +/**
  75560. + * This function is for debug only.
  75561. + */
  75562. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  75563. +{
  75564. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  75565. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  75566. + static int frame_num_idx = 0;
  75567. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  75568. + static int dumped_frame_num_array = 0;
  75569. +
  75570. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  75571. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  75572. + curr_frame_number) {
  75573. + frame_num_array[frame_num_idx] = curr_frame_number;
  75574. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  75575. + }
  75576. + } else if (!dumped_frame_num_array) {
  75577. + int i;
  75578. + DWC_PRINTF("Frame Last Frame\n");
  75579. + DWC_PRINTF("----- ----------\n");
  75580. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  75581. + DWC_PRINTF("0x%04x 0x%04x\n",
  75582. + frame_num_array[i], last_frame_num_array[i]);
  75583. + }
  75584. + dumped_frame_num_array = 1;
  75585. + }
  75586. + last_frame_num = curr_frame_number;
  75587. +}
  75588. +#endif
  75589. +
  75590. +/**
  75591. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  75592. + * transactions may be queued to the DWC_otg controller for the current
  75593. + * (micro)frame. Periodic transactions may be queued to the controller for the
  75594. + * next (micro)frame.
  75595. + */
  75596. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  75597. +{
  75598. + hfnum_data_t hfnum;
  75599. + dwc_list_link_t *qh_entry;
  75600. + dwc_otg_qh_t *qh;
  75601. + dwc_otg_transaction_type_e tr_type;
  75602. + int did_something = 0;
  75603. + int32_t next_sched_frame = -1;
  75604. +
  75605. + hfnum.d32 =
  75606. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  75607. +
  75608. +#ifdef DEBUG_SOF
  75609. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  75610. +#endif
  75611. + hcd->frame_number = hfnum.b.frnum;
  75612. +
  75613. +#ifdef DEBUG
  75614. + hcd->frrem_accum += hfnum.b.frrem;
  75615. + hcd->frrem_samples++;
  75616. +#endif
  75617. +
  75618. +#ifdef DWC_TRACK_MISSED_SOFS
  75619. + track_missed_sofs(hcd->frame_number);
  75620. +#endif
  75621. + /* Determine whether any periodic QHs should be executed. */
  75622. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  75623. + while (qh_entry != &hcd->periodic_sched_inactive) {
  75624. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  75625. + qh_entry = qh_entry->next;
  75626. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  75627. +
  75628. + /*
  75629. + * Move QH to the ready list to be executed next
  75630. + * (micro)frame.
  75631. + */
  75632. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  75633. + &qh->qh_list_entry);
  75634. +
  75635. + did_something = 1;
  75636. + }
  75637. + else
  75638. + {
  75639. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  75640. + {
  75641. + next_sched_frame = qh->sched_frame;
  75642. + }
  75643. + }
  75644. + }
  75645. +
  75646. + g_next_sched_frame = next_sched_frame;
  75647. +
  75648. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  75649. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  75650. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  75651. + did_something = 1;
  75652. + }
  75653. +
  75654. + /* Clear interrupt */
  75655. + gintsts.b.sofintr = 1;
  75656. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  75657. +
  75658. + return 1;
  75659. +}
  75660. +
  75661. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  75662. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  75663. + * memory if the DWC_otg controller is operating in Slave mode. */
  75664. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75665. +{
  75666. + host_grxsts_data_t grxsts;
  75667. + dwc_hc_t *hc = NULL;
  75668. +
  75669. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  75670. +
  75671. + grxsts.d32 =
  75672. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  75673. +
  75674. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  75675. + if (!hc) {
  75676. + DWC_ERROR("Unable to get corresponding channel\n");
  75677. + return 0;
  75678. + }
  75679. +
  75680. + /* Packet Status */
  75681. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  75682. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  75683. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  75684. + hc->data_pid_start);
  75685. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  75686. +
  75687. + switch (grxsts.b.pktsts) {
  75688. + case DWC_GRXSTS_PKTSTS_IN:
  75689. + /* Read the data into the host buffer. */
  75690. + if (grxsts.b.bcnt > 0) {
  75691. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  75692. + hc->xfer_buff, grxsts.b.bcnt);
  75693. +
  75694. + /* Update the HC fields for the next packet received. */
  75695. + hc->xfer_count += grxsts.b.bcnt;
  75696. + hc->xfer_buff += grxsts.b.bcnt;
  75697. + }
  75698. +
  75699. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  75700. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  75701. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  75702. + /* Handled in interrupt, just ignore data */
  75703. + break;
  75704. + default:
  75705. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  75706. + grxsts.b.pktsts);
  75707. + break;
  75708. + }
  75709. +
  75710. + return 1;
  75711. +}
  75712. +
  75713. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  75714. + * data packets may be written to the FIFO for OUT transfers. More requests
  75715. + * may be written to the non-periodic request queue for IN transfers. This
  75716. + * interrupt is enabled only in Slave mode. */
  75717. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75718. +{
  75719. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  75720. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  75721. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  75722. + return 1;
  75723. +}
  75724. +
  75725. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  75726. + * packets may be written to the FIFO for OUT transfers. More requests may be
  75727. + * written to the periodic request queue for IN transfers. This interrupt is
  75728. + * enabled only in Slave mode. */
  75729. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75730. +{
  75731. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  75732. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  75733. + DWC_OTG_TRANSACTION_PERIODIC);
  75734. + return 1;
  75735. +}
  75736. +
  75737. +/** There are multiple conditions that can cause a port interrupt. This function
  75738. + * determines which interrupt conditions have occurred and handles them
  75739. + * appropriately. */
  75740. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75741. +{
  75742. + int retval = 0;
  75743. + hprt0_data_t hprt0;
  75744. + hprt0_data_t hprt0_modify;
  75745. +
  75746. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  75747. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  75748. +
  75749. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  75750. + * GINTSTS */
  75751. +
  75752. + hprt0_modify.b.prtena = 0;
  75753. + hprt0_modify.b.prtconndet = 0;
  75754. + hprt0_modify.b.prtenchng = 0;
  75755. + hprt0_modify.b.prtovrcurrchng = 0;
  75756. +
  75757. + /* Port Connect Detected
  75758. + * Set flag and clear if detected */
  75759. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  75760. + // Dont modify port status if we are in hibernation state
  75761. + hprt0_modify.b.prtconndet = 1;
  75762. + hprt0_modify.b.prtenchng = 1;
  75763. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  75764. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  75765. + return retval;
  75766. + }
  75767. +
  75768. + if (hprt0.b.prtconndet) {
  75769. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  75770. + if (dwc_otg_hcd->core_if->adp_enable &&
  75771. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  75772. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  75773. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  75774. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  75775. + /* TODO - check if this is required, as
  75776. + * host initialization was already performed
  75777. + * after initial ADP probing
  75778. + */
  75779. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  75780. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  75781. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  75782. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  75783. + } else {
  75784. +
  75785. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  75786. + "Port Connect Detected--\n", hprt0.d32);
  75787. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  75788. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  75789. + hprt0_modify.b.prtconndet = 1;
  75790. +
  75791. + /* B-Device has connected, Delete the connection timer. */
  75792. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  75793. + }
  75794. + /* The Hub driver asserts a reset when it sees port connect
  75795. + * status change flag */
  75796. + retval |= 1;
  75797. + }
  75798. +
  75799. + /* Port Enable Changed
  75800. + * Clear if detected - Set internal flag if disabled */
  75801. + if (hprt0.b.prtenchng) {
  75802. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  75803. + "Port Enable Changed--\n", hprt0.d32);
  75804. + hprt0_modify.b.prtenchng = 1;
  75805. + if (hprt0.b.prtena == 1) {
  75806. + hfir_data_t hfir;
  75807. + int do_reset = 0;
  75808. + dwc_otg_core_params_t *params =
  75809. + dwc_otg_hcd->core_if->core_params;
  75810. + dwc_otg_core_global_regs_t *global_regs =
  75811. + dwc_otg_hcd->core_if->core_global_regs;
  75812. + dwc_otg_host_if_t *host_if =
  75813. + dwc_otg_hcd->core_if->host_if;
  75814. +
  75815. + /* Every time when port enables calculate
  75816. + * HFIR.FrInterval
  75817. + */
  75818. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  75819. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  75820. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  75821. +
  75822. + /* Check if we need to adjust the PHY clock speed for
  75823. + * low power and adjust it */
  75824. + if (params->host_support_fs_ls_low_power) {
  75825. + gusbcfg_data_t usbcfg;
  75826. +
  75827. + usbcfg.d32 =
  75828. + DWC_READ_REG32(&global_regs->gusbcfg);
  75829. +
  75830. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  75831. + || hprt0.b.prtspd ==
  75832. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  75833. + /*
  75834. + * Low power
  75835. + */
  75836. + hcfg_data_t hcfg;
  75837. + if (usbcfg.b.phylpwrclksel == 0) {
  75838. + /* Set PHY low power clock select for FS/LS devices */
  75839. + usbcfg.b.phylpwrclksel = 1;
  75840. + DWC_WRITE_REG32
  75841. + (&global_regs->gusbcfg,
  75842. + usbcfg.d32);
  75843. + do_reset = 1;
  75844. + }
  75845. +
  75846. + hcfg.d32 =
  75847. + DWC_READ_REG32
  75848. + (&host_if->host_global_regs->hcfg);
  75849. +
  75850. + if (hprt0.b.prtspd ==
  75851. + DWC_HPRT0_PRTSPD_LOW_SPEED
  75852. + && params->host_ls_low_power_phy_clk
  75853. + ==
  75854. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  75855. + {
  75856. + /* 6 MHZ */
  75857. + DWC_DEBUGPL(DBG_CIL,
  75858. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  75859. + if (hcfg.b.fslspclksel !=
  75860. + DWC_HCFG_6_MHZ) {
  75861. + hcfg.b.fslspclksel =
  75862. + DWC_HCFG_6_MHZ;
  75863. + DWC_WRITE_REG32
  75864. + (&host_if->host_global_regs->hcfg,
  75865. + hcfg.d32);
  75866. + do_reset = 1;
  75867. + }
  75868. + } else {
  75869. + /* 48 MHZ */
  75870. + DWC_DEBUGPL(DBG_CIL,
  75871. + "FS_PHY programming HCFG to 48 MHz ()\n");
  75872. + if (hcfg.b.fslspclksel !=
  75873. + DWC_HCFG_48_MHZ) {
  75874. + hcfg.b.fslspclksel =
  75875. + DWC_HCFG_48_MHZ;
  75876. + DWC_WRITE_REG32
  75877. + (&host_if->host_global_regs->hcfg,
  75878. + hcfg.d32);
  75879. + do_reset = 1;
  75880. + }
  75881. + }
  75882. + } else {
  75883. + /*
  75884. + * Not low power
  75885. + */
  75886. + if (usbcfg.b.phylpwrclksel == 1) {
  75887. + usbcfg.b.phylpwrclksel = 0;
  75888. + DWC_WRITE_REG32
  75889. + (&global_regs->gusbcfg,
  75890. + usbcfg.d32);
  75891. + do_reset = 1;
  75892. + }
  75893. + }
  75894. +
  75895. + if (do_reset) {
  75896. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  75897. + }
  75898. + }
  75899. +
  75900. + if (!do_reset) {
  75901. + /* Port has been enabled set the reset change flag */
  75902. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  75903. + }
  75904. + } else {
  75905. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  75906. + }
  75907. + retval |= 1;
  75908. + }
  75909. +
  75910. + /** Overcurrent Change Interrupt */
  75911. + if (hprt0.b.prtovrcurrchng) {
  75912. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  75913. + "Port Overcurrent Changed--\n", hprt0.d32);
  75914. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  75915. + hprt0_modify.b.prtovrcurrchng = 1;
  75916. + retval |= 1;
  75917. + }
  75918. +
  75919. + /* Clear Port Interrupts */
  75920. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  75921. +
  75922. + return retval;
  75923. +}
  75924. +
  75925. +/** This interrupt indicates that one or more host channels has a pending
  75926. + * interrupt. There are multiple conditions that can cause each host channel
  75927. + * interrupt. This function determines which conditions have occurred for each
  75928. + * host channel interrupt and handles them appropriately. */
  75929. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75930. +{
  75931. + int i;
  75932. + int retval = 0;
  75933. + haint_data_t haint;
  75934. +
  75935. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  75936. + * GINTSTS */
  75937. +
  75938. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  75939. +
  75940. + // Overwrite with saved interrupts from fiq handler
  75941. + if(fiq_split_enable)
  75942. + {
  75943. + local_fiq_disable();
  75944. + haint.d32 = haint_saved.d32;
  75945. + haint_saved.d32 = 0;
  75946. + local_fiq_enable();
  75947. + }
  75948. +
  75949. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  75950. + if (haint.b2.chint & (1 << i)) {
  75951. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  75952. + }
  75953. + }
  75954. +
  75955. + return retval;
  75956. +}
  75957. +
  75958. +/**
  75959. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  75960. + * holds the reason for the halt.
  75961. + *
  75962. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  75963. + * *short_read is set to 1 upon return if less than the requested
  75964. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  75965. + * return. short_read may also be NULL on entry, in which case it remains
  75966. + * unchanged.
  75967. + */
  75968. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  75969. + dwc_otg_hc_regs_t * hc_regs,
  75970. + dwc_otg_qtd_t * qtd,
  75971. + dwc_otg_halt_status_e halt_status,
  75972. + int *short_read)
  75973. +{
  75974. + hctsiz_data_t hctsiz;
  75975. + uint32_t length;
  75976. +
  75977. + if (short_read != NULL) {
  75978. + *short_read = 0;
  75979. + }
  75980. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75981. +
  75982. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75983. + if (hc->ep_is_in) {
  75984. + length = hc->xfer_len - hctsiz.b.xfersize;
  75985. + if (short_read != NULL) {
  75986. + *short_read = (hctsiz.b.xfersize != 0);
  75987. + }
  75988. + } else if (hc->qh->do_split) {
  75989. + if(fiq_split_enable)
  75990. + length = split_out_xfersize[hc->hc_num];
  75991. + else
  75992. + length = qtd->ssplit_out_xfer_count;
  75993. + } else {
  75994. + length = hc->xfer_len;
  75995. + }
  75996. + } else {
  75997. + /*
  75998. + * Must use the hctsiz.pktcnt field to determine how much data
  75999. + * has been transferred. This field reflects the number of
  76000. + * packets that have been transferred via the USB. This is
  76001. + * always an integral number of packets if the transfer was
  76002. + * halted before its normal completion. (Can't use the
  76003. + * hctsiz.xfersize field because that reflects the number of
  76004. + * bytes transferred via the AHB, not the USB).
  76005. + */
  76006. + length =
  76007. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  76008. + }
  76009. +
  76010. + return length;
  76011. +}
  76012. +
  76013. +/**
  76014. + * Updates the state of the URB after a Transfer Complete interrupt on the
  76015. + * host channel. Updates the actual_length field of the URB based on the
  76016. + * number of bytes transferred via the host channel. Sets the URB status
  76017. + * if the data transfer is finished.
  76018. + *
  76019. + * @return 1 if the data transfer specified by the URB is completely finished,
  76020. + * 0 otherwise.
  76021. + */
  76022. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  76023. + dwc_otg_hc_regs_t * hc_regs,
  76024. + dwc_otg_hcd_urb_t * urb,
  76025. + dwc_otg_qtd_t * qtd)
  76026. +{
  76027. + int xfer_done = 0;
  76028. + int short_read = 0;
  76029. +
  76030. + int xfer_length;
  76031. +
  76032. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  76033. + DWC_OTG_HC_XFER_COMPLETE,
  76034. + &short_read);
  76035. +
  76036. + /* non DWORD-aligned buffer case handling. */
  76037. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  76038. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  76039. + xfer_length);
  76040. + }
  76041. +
  76042. + urb->actual_length += xfer_length;
  76043. +
  76044. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  76045. + (urb->flags & URB_SEND_ZERO_PACKET)
  76046. + && (urb->actual_length == urb->length)
  76047. + && !(urb->length % hc->max_packet)) {
  76048. + xfer_done = 0;
  76049. + } else if (short_read || urb->actual_length >= urb->length) {
  76050. + xfer_done = 1;
  76051. + urb->status = 0;
  76052. + }
  76053. +
  76054. +#ifdef DEBUG
  76055. + {
  76056. + hctsiz_data_t hctsiz;
  76057. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76058. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  76059. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  76060. + hc->hc_num);
  76061. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  76062. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  76063. + hctsiz.b.xfersize);
  76064. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  76065. + urb->length);
  76066. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  76067. + urb->actual_length);
  76068. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  76069. + short_read, xfer_done);
  76070. + }
  76071. +#endif
  76072. +
  76073. + return xfer_done;
  76074. +}
  76075. +
  76076. +/*
  76077. + * Save the starting data toggle for the next transfer. The data toggle is
  76078. + * saved in the QH for non-control transfers and it's saved in the QTD for
  76079. + * control transfers.
  76080. + */
  76081. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  76082. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  76083. +{
  76084. + hctsiz_data_t hctsiz;
  76085. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76086. +
  76087. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  76088. + dwc_otg_qh_t *qh = hc->qh;
  76089. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  76090. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  76091. + } else {
  76092. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  76093. + }
  76094. + } else {
  76095. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  76096. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  76097. + } else {
  76098. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  76099. + }
  76100. + }
  76101. +}
  76102. +
  76103. +/**
  76104. + * Updates the state of an Isochronous URB when the transfer is stopped for
  76105. + * any reason. The fields of the current entry in the frame descriptor array
  76106. + * are set based on the transfer state and the input _halt_status. Completes
  76107. + * the Isochronous URB if all the URB frames have been completed.
  76108. + *
  76109. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  76110. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  76111. + */
  76112. +static dwc_otg_halt_status_e
  76113. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  76114. + dwc_hc_t * hc,
  76115. + dwc_otg_hc_regs_t * hc_regs,
  76116. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  76117. +{
  76118. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76119. + dwc_otg_halt_status_e ret_val = halt_status;
  76120. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  76121. +
  76122. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  76123. + switch (halt_status) {
  76124. + case DWC_OTG_HC_XFER_COMPLETE:
  76125. + frame_desc->status = 0;
  76126. + frame_desc->actual_length =
  76127. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  76128. +
  76129. + /* non DWORD-aligned buffer case handling. */
  76130. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  76131. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  76132. + hc->qh->dw_align_buf, frame_desc->actual_length);
  76133. + }
  76134. +
  76135. + break;
  76136. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  76137. + urb->error_count++;
  76138. + if (hc->ep_is_in) {
  76139. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  76140. + } else {
  76141. + frame_desc->status = -DWC_E_COMMUNICATION;
  76142. + }
  76143. + frame_desc->actual_length = 0;
  76144. + break;
  76145. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  76146. + urb->error_count++;
  76147. + frame_desc->status = -DWC_E_OVERFLOW;
  76148. + /* Don't need to update actual_length in this case. */
  76149. + break;
  76150. + case DWC_OTG_HC_XFER_XACT_ERR:
  76151. + urb->error_count++;
  76152. + frame_desc->status = -DWC_E_PROTOCOL;
  76153. + frame_desc->actual_length =
  76154. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  76155. +
  76156. + /* non DWORD-aligned buffer case handling. */
  76157. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  76158. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  76159. + hc->qh->dw_align_buf, frame_desc->actual_length);
  76160. + }
  76161. + /* Skip whole frame */
  76162. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  76163. + hc->ep_is_in && hcd->core_if->dma_enable) {
  76164. + qtd->complete_split = 0;
  76165. + qtd->isoc_split_offset = 0;
  76166. + }
  76167. +
  76168. + break;
  76169. + default:
  76170. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  76171. + break;
  76172. + }
  76173. + if (++qtd->isoc_frame_index == urb->packet_count) {
  76174. + /*
  76175. + * urb->status is not used for isoc transfers.
  76176. + * The individual frame_desc statuses are used instead.
  76177. + */
  76178. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  76179. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  76180. + } else {
  76181. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  76182. + }
  76183. + return ret_val;
  76184. +}
  76185. +
  76186. +/**
  76187. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  76188. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  76189. + * still linked to the QH, the QH is added to the end of the inactive
  76190. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  76191. + * schedule if no more QTDs are linked to the QH.
  76192. + */
  76193. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  76194. +{
  76195. + int continue_split = 0;
  76196. + dwc_otg_qtd_t *qtd;
  76197. +
  76198. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  76199. +
  76200. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  76201. +
  76202. + if (qtd->complete_split) {
  76203. + continue_split = 1;
  76204. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  76205. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  76206. + continue_split = 1;
  76207. + }
  76208. +
  76209. + if (free_qtd) {
  76210. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  76211. + continue_split = 0;
  76212. + }
  76213. +
  76214. + qh->channel = NULL;
  76215. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  76216. +}
  76217. +
  76218. +/**
  76219. + * Releases a host channel for use by other transfers. Attempts to select and
  76220. + * queue more transactions since at least one host channel is available.
  76221. + *
  76222. + * @param hcd The HCD state structure.
  76223. + * @param hc The host channel to release.
  76224. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  76225. + * if the transfer is complete or an error has occurred.
  76226. + * @param halt_status Reason the channel is being released. This status
  76227. + * determines the actions taken by this function.
  76228. + */
  76229. +static void release_channel(dwc_otg_hcd_t * hcd,
  76230. + dwc_hc_t * hc,
  76231. + dwc_otg_qtd_t * qtd,
  76232. + dwc_otg_halt_status_e halt_status)
  76233. +{
  76234. + dwc_otg_transaction_type_e tr_type;
  76235. + int free_qtd;
  76236. + dwc_irqflags_t flags;
  76237. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  76238. +#ifdef FIQ_DEBUG
  76239. + int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
  76240. +#endif
  76241. + int hog_port = 0;
  76242. +
  76243. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  76244. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  76245. +
  76246. + if(fiq_split_enable && hc->do_split) {
  76247. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  76248. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  76249. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  76250. + hog_port = 1;
  76251. + }
  76252. + }
  76253. + }
  76254. +
  76255. + switch (halt_status) {
  76256. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  76257. + free_qtd = 1;
  76258. + break;
  76259. + case DWC_OTG_HC_XFER_AHB_ERR:
  76260. + case DWC_OTG_HC_XFER_STALL:
  76261. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  76262. + free_qtd = 1;
  76263. + break;
  76264. + case DWC_OTG_HC_XFER_XACT_ERR:
  76265. + if (qtd->error_count >= 3) {
  76266. + DWC_DEBUGPL(DBG_HCDV,
  76267. + " Complete URB with transaction error\n");
  76268. + free_qtd = 1;
  76269. + qtd->urb->status = -DWC_E_PROTOCOL;
  76270. + hcd->fops->complete(hcd, qtd->urb->priv,
  76271. + qtd->urb, -DWC_E_PROTOCOL);
  76272. + } else {
  76273. + free_qtd = 0;
  76274. + }
  76275. + break;
  76276. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  76277. + /*
  76278. + * The QTD has already been removed and the QH has been
  76279. + * deactivated. Don't want to do anything except release the
  76280. + * host channel and try to queue more transfers.
  76281. + */
  76282. + goto cleanup;
  76283. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  76284. + free_qtd = 0;
  76285. + break;
  76286. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  76287. + DWC_DEBUGPL(DBG_HCDV,
  76288. + " Complete URB with I/O error\n");
  76289. + free_qtd = 1;
  76290. + qtd->urb->status = -DWC_E_IO;
  76291. + hcd->fops->complete(hcd, qtd->urb->priv,
  76292. + qtd->urb, -DWC_E_IO);
  76293. + break;
  76294. + default:
  76295. + free_qtd = 0;
  76296. + break;
  76297. + }
  76298. +
  76299. + deactivate_qh(hcd, hc->qh, free_qtd);
  76300. +
  76301. +cleanup:
  76302. + /*
  76303. + * Release the host channel for use by other transfers. The cleanup
  76304. + * function clears the channel interrupt enables and conditions, so
  76305. + * there's no need to clear the Channel Halted interrupt separately.
  76306. + */
  76307. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  76308. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  76309. +
  76310. + if (!microframe_schedule) {
  76311. + switch (hc->ep_type) {
  76312. + case DWC_OTG_EP_TYPE_CONTROL:
  76313. + case DWC_OTG_EP_TYPE_BULK:
  76314. + hcd->non_periodic_channels--;
  76315. + break;
  76316. +
  76317. + default:
  76318. + /*
  76319. + * Don't release reservations for periodic channels here.
  76320. + * That's done when a periodic transfer is descheduled (i.e.
  76321. + * when the QH is removed from the periodic schedule).
  76322. + */
  76323. + break;
  76324. + }
  76325. + } else {
  76326. +
  76327. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  76328. + hcd->available_host_channels++;
  76329. + fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
  76330. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  76331. + }
  76332. +
  76333. + if(fiq_split_enable && hc->do_split)
  76334. + {
  76335. + if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
  76336. + {
  76337. + fiq_print(FIQDBG_ERR, "PRTNOTAL");
  76338. + //BUG();
  76339. + }
  76340. + if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
  76341. + hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
  76342. + hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
  76343. +#ifdef FIQ_DEBUG
  76344. + hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
  76345. +#endif
  76346. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
  76347. + }
  76348. + }
  76349. +
  76350. + /* Try to queue more transfers now that there's a free channel. */
  76351. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  76352. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  76353. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  76354. + }
  76355. +}
  76356. +
  76357. +/**
  76358. + * Halts a host channel. If the channel cannot be halted immediately because
  76359. + * the request queue is full, this function ensures that the FIFO empty
  76360. + * interrupt for the appropriate queue is enabled so that the halt request can
  76361. + * be queued when there is space in the request queue.
  76362. + *
  76363. + * This function may also be called in DMA mode. In that case, the channel is
  76364. + * simply released since the core always halts the channel automatically in
  76365. + * DMA mode.
  76366. + */
  76367. +static void halt_channel(dwc_otg_hcd_t * hcd,
  76368. + dwc_hc_t * hc,
  76369. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  76370. +{
  76371. + if (hcd->core_if->dma_enable) {
  76372. + release_channel(hcd, hc, qtd, halt_status);
  76373. + return;
  76374. + }
  76375. +
  76376. + /* Slave mode processing... */
  76377. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  76378. +
  76379. + if (hc->halt_on_queue) {
  76380. + gintmsk_data_t gintmsk = {.d32 = 0 };
  76381. + dwc_otg_core_global_regs_t *global_regs;
  76382. + global_regs = hcd->core_if->core_global_regs;
  76383. +
  76384. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  76385. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  76386. + /*
  76387. + * Make sure the Non-periodic Tx FIFO empty interrupt
  76388. + * is enabled so that the non-periodic schedule will
  76389. + * be processed.
  76390. + */
  76391. + gintmsk.b.nptxfempty = 1;
  76392. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  76393. + } else {
  76394. + /*
  76395. + * Move the QH from the periodic queued schedule to
  76396. + * the periodic assigned schedule. This allows the
  76397. + * halt to be queued when the periodic schedule is
  76398. + * processed.
  76399. + */
  76400. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  76401. + &hc->qh->qh_list_entry);
  76402. +
  76403. + /*
  76404. + * Make sure the Periodic Tx FIFO Empty interrupt is
  76405. + * enabled so that the periodic schedule will be
  76406. + * processed.
  76407. + */
  76408. + gintmsk.b.ptxfempty = 1;
  76409. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  76410. + }
  76411. + }
  76412. +}
  76413. +
  76414. +/**
  76415. + * Performs common cleanup for non-periodic transfers after a Transfer
  76416. + * Complete interrupt. This function should be called after any endpoint type
  76417. + * specific handling is finished to release the host channel.
  76418. + */
  76419. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  76420. + dwc_hc_t * hc,
  76421. + dwc_otg_hc_regs_t * hc_regs,
  76422. + dwc_otg_qtd_t * qtd,
  76423. + dwc_otg_halt_status_e halt_status)
  76424. +{
  76425. + hcint_data_t hcint;
  76426. +
  76427. + qtd->error_count = 0;
  76428. +
  76429. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76430. + if (hcint.b.nyet) {
  76431. + /*
  76432. + * Got a NYET on the last transaction of the transfer. This
  76433. + * means that the endpoint should be in the PING state at the
  76434. + * beginning of the next transfer.
  76435. + */
  76436. + hc->qh->ping_state = 1;
  76437. + clear_hc_int(hc_regs, nyet);
  76438. + }
  76439. +
  76440. + /*
  76441. + * Always halt and release the host channel to make it available for
  76442. + * more transfers. There may still be more phases for a control
  76443. + * transfer or more data packets for a bulk transfer at this point,
  76444. + * but the host channel is still halted. A channel will be reassigned
  76445. + * to the transfer when the non-periodic schedule is processed after
  76446. + * the channel is released. This allows transactions to be queued
  76447. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  76448. + * Tx FIFO Empty interrupt if necessary.
  76449. + */
  76450. + if (hc->ep_is_in) {
  76451. + /*
  76452. + * IN transfers in Slave mode require an explicit disable to
  76453. + * halt the channel. (In DMA mode, this call simply releases
  76454. + * the channel.)
  76455. + */
  76456. + halt_channel(hcd, hc, qtd, halt_status);
  76457. + } else {
  76458. + /*
  76459. + * The channel is automatically disabled by the core for OUT
  76460. + * transfers in Slave mode.
  76461. + */
  76462. + release_channel(hcd, hc, qtd, halt_status);
  76463. + }
  76464. +}
  76465. +
  76466. +/**
  76467. + * Performs common cleanup for periodic transfers after a Transfer Complete
  76468. + * interrupt. This function should be called after any endpoint type specific
  76469. + * handling is finished to release the host channel.
  76470. + */
  76471. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  76472. + dwc_hc_t * hc,
  76473. + dwc_otg_hc_regs_t * hc_regs,
  76474. + dwc_otg_qtd_t * qtd,
  76475. + dwc_otg_halt_status_e halt_status)
  76476. +{
  76477. + hctsiz_data_t hctsiz;
  76478. + qtd->error_count = 0;
  76479. +
  76480. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76481. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  76482. + /* Core halts channel in these cases. */
  76483. + release_channel(hcd, hc, qtd, halt_status);
  76484. + } else {
  76485. + /* Flush any outstanding requests from the Tx queue. */
  76486. + halt_channel(hcd, hc, qtd, halt_status);
  76487. + }
  76488. +}
  76489. +
  76490. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  76491. + dwc_hc_t * hc,
  76492. + dwc_otg_hc_regs_t * hc_regs,
  76493. + dwc_otg_qtd_t * qtd)
  76494. +{
  76495. + uint32_t len;
  76496. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  76497. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  76498. +
  76499. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  76500. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  76501. +
  76502. + if (!len) {
  76503. + qtd->complete_split = 0;
  76504. + qtd->isoc_split_offset = 0;
  76505. + return 0;
  76506. + }
  76507. + frame_desc->actual_length += len;
  76508. +
  76509. + if (hc->align_buff && len)
  76510. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  76511. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  76512. + qtd->isoc_split_offset += len;
  76513. +
  76514. + if (frame_desc->length == frame_desc->actual_length) {
  76515. + frame_desc->status = 0;
  76516. + qtd->isoc_frame_index++;
  76517. + qtd->complete_split = 0;
  76518. + qtd->isoc_split_offset = 0;
  76519. + }
  76520. +
  76521. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  76522. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  76523. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  76524. + } else {
  76525. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  76526. + }
  76527. +
  76528. + return 1; /* Indicates that channel released */
  76529. +}
  76530. +
  76531. +/**
  76532. + * Handles a host channel Transfer Complete interrupt. This handler may be
  76533. + * called in either DMA mode or Slave mode.
  76534. + */
  76535. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  76536. + dwc_hc_t * hc,
  76537. + dwc_otg_hc_regs_t * hc_regs,
  76538. + dwc_otg_qtd_t * qtd)
  76539. +{
  76540. + int urb_xfer_done;
  76541. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76542. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76543. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  76544. +
  76545. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76546. + "Transfer Complete--\n", hc->hc_num);
  76547. +
  76548. + if (hcd->core_if->dma_desc_enable) {
  76549. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  76550. + if (pipe_type == UE_ISOCHRONOUS) {
  76551. + /* Do not disable the interrupt, just clear it */
  76552. + clear_hc_int(hc_regs, xfercomp);
  76553. + return 1;
  76554. + }
  76555. + goto handle_xfercomp_done;
  76556. + }
  76557. +
  76558. + /*
  76559. + * Handle xfer complete on CSPLIT.
  76560. + */
  76561. +
  76562. + if (hc->qh->do_split) {
  76563. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  76564. + && hcd->core_if->dma_enable) {
  76565. + if (qtd->complete_split
  76566. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  76567. + qtd))
  76568. + goto handle_xfercomp_done;
  76569. + } else {
  76570. + qtd->complete_split = 0;
  76571. + }
  76572. + }
  76573. +
  76574. + /* Update the QTD and URB states. */
  76575. + switch (pipe_type) {
  76576. + case UE_CONTROL:
  76577. + switch (qtd->control_phase) {
  76578. + case DWC_OTG_CONTROL_SETUP:
  76579. + if (urb->length > 0) {
  76580. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  76581. + } else {
  76582. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  76583. + }
  76584. + DWC_DEBUGPL(DBG_HCDV,
  76585. + " Control setup transaction done\n");
  76586. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76587. + break;
  76588. + case DWC_OTG_CONTROL_DATA:{
  76589. + urb_xfer_done =
  76590. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  76591. + qtd);
  76592. + if (urb_xfer_done) {
  76593. + qtd->control_phase =
  76594. + DWC_OTG_CONTROL_STATUS;
  76595. + DWC_DEBUGPL(DBG_HCDV,
  76596. + " Control data transfer done\n");
  76597. + } else {
  76598. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76599. + }
  76600. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76601. + break;
  76602. + }
  76603. + case DWC_OTG_CONTROL_STATUS:
  76604. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  76605. + if (urb->status == -DWC_E_IN_PROGRESS) {
  76606. + urb->status = 0;
  76607. + }
  76608. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  76609. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  76610. + break;
  76611. + }
  76612. +
  76613. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76614. + break;
  76615. + case UE_BULK:
  76616. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  76617. + urb_xfer_done =
  76618. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  76619. + if (urb_xfer_done) {
  76620. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  76621. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  76622. + } else {
  76623. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76624. + }
  76625. +
  76626. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76627. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76628. + break;
  76629. + case UE_INTERRUPT:
  76630. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  76631. + urb_xfer_done =
  76632. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  76633. +
  76634. + /*
  76635. + * Interrupt URB is done on the first transfer complete
  76636. + * interrupt.
  76637. + */
  76638. + if (urb_xfer_done) {
  76639. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  76640. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  76641. + } else {
  76642. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76643. + }
  76644. +
  76645. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76646. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76647. + break;
  76648. + case UE_ISOCHRONOUS:
  76649. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  76650. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  76651. + halt_status =
  76652. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76653. + DWC_OTG_HC_XFER_COMPLETE);
  76654. + }
  76655. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76656. + break;
  76657. + }
  76658. +
  76659. +handle_xfercomp_done:
  76660. + disable_hc_int(hc_regs, xfercompl);
  76661. +
  76662. + return 1;
  76663. +}
  76664. +
  76665. +/**
  76666. + * Handles a host channel STALL interrupt. This handler may be called in
  76667. + * either DMA mode or Slave mode.
  76668. + */
  76669. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  76670. + dwc_hc_t * hc,
  76671. + dwc_otg_hc_regs_t * hc_regs,
  76672. + dwc_otg_qtd_t * qtd)
  76673. +{
  76674. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76675. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  76676. +
  76677. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  76678. + "STALL Received--\n", hc->hc_num);
  76679. +
  76680. + if (hcd->core_if->dma_desc_enable) {
  76681. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  76682. + goto handle_stall_done;
  76683. + }
  76684. +
  76685. + if (pipe_type == UE_CONTROL) {
  76686. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  76687. + }
  76688. +
  76689. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  76690. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  76691. + /*
  76692. + * USB protocol requires resetting the data toggle for bulk
  76693. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  76694. + * setup command is issued to the endpoint. Anticipate the
  76695. + * CLEAR_FEATURE command since a STALL has occurred and reset
  76696. + * the data toggle now.
  76697. + */
  76698. + hc->qh->data_toggle = 0;
  76699. + }
  76700. +
  76701. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  76702. +
  76703. +handle_stall_done:
  76704. + disable_hc_int(hc_regs, stall);
  76705. +
  76706. + return 1;
  76707. +}
  76708. +
  76709. +/*
  76710. + * Updates the state of the URB when a transfer has been stopped due to an
  76711. + * abnormal condition before the transfer completes. Modifies the
  76712. + * actual_length field of the URB to reflect the number of bytes that have
  76713. + * actually been transferred via the host channel.
  76714. + */
  76715. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  76716. + dwc_otg_hc_regs_t * hc_regs,
  76717. + dwc_otg_hcd_urb_t * urb,
  76718. + dwc_otg_qtd_t * qtd,
  76719. + dwc_otg_halt_status_e halt_status)
  76720. +{
  76721. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  76722. + halt_status, NULL);
  76723. + /* non DWORD-aligned buffer case handling. */
  76724. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  76725. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  76726. + bytes_transferred);
  76727. + }
  76728. +
  76729. + urb->actual_length += bytes_transferred;
  76730. +
  76731. +#ifdef DEBUG
  76732. + {
  76733. + hctsiz_data_t hctsiz;
  76734. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76735. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  76736. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  76737. + hc->hc_num);
  76738. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  76739. + hc->start_pkt_count);
  76740. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  76741. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  76742. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  76743. + bytes_transferred);
  76744. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  76745. + urb->actual_length);
  76746. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  76747. + urb->length);
  76748. + }
  76749. +#endif
  76750. +}
  76751. +
  76752. +/**
  76753. + * Handles a host channel NAK interrupt. This handler may be called in either
  76754. + * DMA mode or Slave mode.
  76755. + */
  76756. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  76757. + dwc_hc_t * hc,
  76758. + dwc_otg_hc_regs_t * hc_regs,
  76759. + dwc_otg_qtd_t * qtd)
  76760. +{
  76761. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76762. + "NAK Received--\n", hc->hc_num);
  76763. +
  76764. + /*
  76765. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  76766. + * the beginning of the next frame
  76767. + */
  76768. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76769. + case UE_BULK:
  76770. + case UE_CONTROL:
  76771. + if (nak_holdoff_enable)
  76772. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  76773. + }
  76774. +
  76775. + /*
  76776. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  76777. + * interrupt. Re-start the SSPLIT transfer.
  76778. + */
  76779. + if (hc->do_split) {
  76780. + if (hc->complete_split) {
  76781. + qtd->error_count = 0;
  76782. + }
  76783. + qtd->complete_split = 0;
  76784. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  76785. + goto handle_nak_done;
  76786. + }
  76787. +
  76788. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76789. + case UE_CONTROL:
  76790. + case UE_BULK:
  76791. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  76792. + /*
  76793. + * NAK interrupts are enabled on bulk/control IN
  76794. + * transfers in DMA mode for the sole purpose of
  76795. + * resetting the error count after a transaction error
  76796. + * occurs. The core will continue transferring data.
  76797. + * Disable other interrupts unmasked for the same
  76798. + * reason.
  76799. + */
  76800. + disable_hc_int(hc_regs, datatglerr);
  76801. + disable_hc_int(hc_regs, ack);
  76802. + qtd->error_count = 0;
  76803. + goto handle_nak_done;
  76804. + }
  76805. +
  76806. + /*
  76807. + * NAK interrupts normally occur during OUT transfers in DMA
  76808. + * or Slave mode. For IN transfers, more requests will be
  76809. + * queued as request queue space is available.
  76810. + */
  76811. + qtd->error_count = 0;
  76812. +
  76813. + if (!hc->qh->ping_state) {
  76814. + update_urb_state_xfer_intr(hc, hc_regs,
  76815. + qtd->urb, qtd,
  76816. + DWC_OTG_HC_XFER_NAK);
  76817. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76818. +
  76819. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  76820. + hc->qh->ping_state = 1;
  76821. + }
  76822. +
  76823. + /*
  76824. + * Halt the channel so the transfer can be re-started from
  76825. + * the appropriate point or the PING protocol will
  76826. + * start/continue.
  76827. + */
  76828. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  76829. + break;
  76830. + case UE_INTERRUPT:
  76831. + qtd->error_count = 0;
  76832. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  76833. + break;
  76834. + case UE_ISOCHRONOUS:
  76835. + /* Should never get called for isochronous transfers. */
  76836. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  76837. + break;
  76838. + }
  76839. +
  76840. +handle_nak_done:
  76841. + disable_hc_int(hc_regs, nak);
  76842. +
  76843. + return 1;
  76844. +}
  76845. +
  76846. +/**
  76847. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  76848. + * performing the PING protocol in Slave mode, when errors occur during
  76849. + * either Slave mode or DMA mode, and during Start Split transactions.
  76850. + */
  76851. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  76852. + dwc_hc_t * hc,
  76853. + dwc_otg_hc_regs_t * hc_regs,
  76854. + dwc_otg_qtd_t * qtd)
  76855. +{
  76856. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76857. + "ACK Received--\n", hc->hc_num);
  76858. +
  76859. + if (hc->do_split) {
  76860. + /*
  76861. + * Handle ACK on SSPLIT.
  76862. + * ACK should not occur in CSPLIT.
  76863. + */
  76864. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  76865. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  76866. + }
  76867. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  76868. + /* Don't need complete for isochronous out transfers. */
  76869. + qtd->complete_split = 1;
  76870. + }
  76871. +
  76872. + /* ISOC OUT */
  76873. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  76874. + switch (hc->xact_pos) {
  76875. + case DWC_HCSPLIT_XACTPOS_ALL:
  76876. + break;
  76877. + case DWC_HCSPLIT_XACTPOS_END:
  76878. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  76879. + qtd->isoc_split_offset = 0;
  76880. + break;
  76881. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  76882. + case DWC_HCSPLIT_XACTPOS_MID:
  76883. + /*
  76884. + * For BEGIN or MID, calculate the length for
  76885. + * the next microframe to determine the correct
  76886. + * SSPLIT token, either MID or END.
  76887. + */
  76888. + {
  76889. + struct dwc_otg_hcd_iso_packet_desc
  76890. + *frame_desc;
  76891. +
  76892. + frame_desc =
  76893. + &qtd->urb->
  76894. + iso_descs[qtd->isoc_frame_index];
  76895. + qtd->isoc_split_offset += 188;
  76896. +
  76897. + if ((frame_desc->length -
  76898. + qtd->isoc_split_offset) <= 188) {
  76899. + qtd->isoc_split_pos =
  76900. + DWC_HCSPLIT_XACTPOS_END;
  76901. + } else {
  76902. + qtd->isoc_split_pos =
  76903. + DWC_HCSPLIT_XACTPOS_MID;
  76904. + }
  76905. +
  76906. + }
  76907. + break;
  76908. + }
  76909. + } else {
  76910. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  76911. + }
  76912. + } else {
  76913. + /*
  76914. + * An unmasked ACK on a non-split DMA transaction is
  76915. + * for the sole purpose of resetting error counts. Disable other
  76916. + * interrupts unmasked for the same reason.
  76917. + */
  76918. + if(hcd->core_if->dma_enable) {
  76919. + disable_hc_int(hc_regs, datatglerr);
  76920. + disable_hc_int(hc_regs, nak);
  76921. + }
  76922. + qtd->error_count = 0;
  76923. +
  76924. + if (hc->qh->ping_state) {
  76925. + hc->qh->ping_state = 0;
  76926. + /*
  76927. + * Halt the channel so the transfer can be re-started
  76928. + * from the appropriate point. This only happens in
  76929. + * Slave mode. In DMA mode, the ping_state is cleared
  76930. + * when the transfer is started because the core
  76931. + * automatically executes the PING, then the transfer.
  76932. + */
  76933. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  76934. + }
  76935. + }
  76936. +
  76937. + /*
  76938. + * If the ACK occurred when _not_ in the PING state, let the channel
  76939. + * continue transferring data after clearing the error count.
  76940. + */
  76941. +
  76942. + disable_hc_int(hc_regs, ack);
  76943. +
  76944. + return 1;
  76945. +}
  76946. +
  76947. +/**
  76948. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  76949. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  76950. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  76951. + * handled in the xfercomp interrupt handler, not here. This handler may be
  76952. + * called in either DMA mode or Slave mode.
  76953. + */
  76954. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  76955. + dwc_hc_t * hc,
  76956. + dwc_otg_hc_regs_t * hc_regs,
  76957. + dwc_otg_qtd_t * qtd)
  76958. +{
  76959. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76960. + "NYET Received--\n", hc->hc_num);
  76961. +
  76962. + /*
  76963. + * NYET on CSPLIT
  76964. + * re-do the CSPLIT immediately on non-periodic
  76965. + */
  76966. + if (hc->do_split && hc->complete_split) {
  76967. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  76968. + && hcd->core_if->dma_enable) {
  76969. + qtd->complete_split = 0;
  76970. + qtd->isoc_split_offset = 0;
  76971. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  76972. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  76973. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  76974. + }
  76975. + else
  76976. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  76977. + goto handle_nyet_done;
  76978. + }
  76979. +
  76980. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  76981. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  76982. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  76983. +
  76984. + // With the FIQ running we only ever see the failed NYET
  76985. + if (dwc_full_frame_num(frnum) !=
  76986. + dwc_full_frame_num(hc->qh->sched_frame) ||
  76987. + fiq_split_enable) {
  76988. + /*
  76989. + * No longer in the same full speed frame.
  76990. + * Treat this as a transaction error.
  76991. + */
  76992. +#if 0
  76993. + /** @todo Fix system performance so this can
  76994. + * be treated as an error. Right now complete
  76995. + * splits cannot be scheduled precisely enough
  76996. + * due to other system activity, so this error
  76997. + * occurs regularly in Slave mode.
  76998. + */
  76999. + qtd->error_count++;
  77000. +#endif
  77001. + qtd->complete_split = 0;
  77002. + halt_channel(hcd, hc, qtd,
  77003. + DWC_OTG_HC_XFER_XACT_ERR);
  77004. + /** @todo add support for isoc release */
  77005. + goto handle_nyet_done;
  77006. + }
  77007. + }
  77008. +
  77009. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  77010. + goto handle_nyet_done;
  77011. + }
  77012. +
  77013. + hc->qh->ping_state = 1;
  77014. + qtd->error_count = 0;
  77015. +
  77016. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  77017. + DWC_OTG_HC_XFER_NYET);
  77018. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77019. +
  77020. + /*
  77021. + * Halt the channel and re-start the transfer so the PING
  77022. + * protocol will start.
  77023. + */
  77024. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  77025. +
  77026. +handle_nyet_done:
  77027. + disable_hc_int(hc_regs, nyet);
  77028. + return 1;
  77029. +}
  77030. +
  77031. +/**
  77032. + * Handles a host channel babble interrupt. This handler may be called in
  77033. + * either DMA mode or Slave mode.
  77034. + */
  77035. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  77036. + dwc_hc_t * hc,
  77037. + dwc_otg_hc_regs_t * hc_regs,
  77038. + dwc_otg_qtd_t * qtd)
  77039. +{
  77040. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77041. + "Babble Error--\n", hc->hc_num);
  77042. +
  77043. + if (hcd->core_if->dma_desc_enable) {
  77044. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  77045. + DWC_OTG_HC_XFER_BABBLE_ERR);
  77046. + goto handle_babble_done;
  77047. + }
  77048. +
  77049. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  77050. + hcd->fops->complete(hcd, qtd->urb->priv,
  77051. + qtd->urb, -DWC_E_OVERFLOW);
  77052. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  77053. + } else {
  77054. + dwc_otg_halt_status_e halt_status;
  77055. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77056. + DWC_OTG_HC_XFER_BABBLE_ERR);
  77057. + halt_channel(hcd, hc, qtd, halt_status);
  77058. + }
  77059. +
  77060. +handle_babble_done:
  77061. + disable_hc_int(hc_regs, bblerr);
  77062. + return 1;
  77063. +}
  77064. +
  77065. +/**
  77066. + * Handles a host channel AHB error interrupt. This handler is only called in
  77067. + * DMA mode.
  77068. + */
  77069. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  77070. + dwc_hc_t * hc,
  77071. + dwc_otg_hc_regs_t * hc_regs,
  77072. + dwc_otg_qtd_t * qtd)
  77073. +{
  77074. + hcchar_data_t hcchar;
  77075. + hcsplt_data_t hcsplt;
  77076. + hctsiz_data_t hctsiz;
  77077. + uint32_t hcdma;
  77078. + char *pipetype, *speed;
  77079. +
  77080. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77081. +
  77082. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77083. + "AHB Error--\n", hc->hc_num);
  77084. +
  77085. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  77086. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  77087. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77088. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  77089. +
  77090. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  77091. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  77092. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  77093. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  77094. + DWC_ERROR(" Device address: %d\n",
  77095. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  77096. + DWC_ERROR(" Endpoint: %d, %s\n",
  77097. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  77098. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  77099. +
  77100. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  77101. + case UE_CONTROL:
  77102. + pipetype = "CONTROL";
  77103. + break;
  77104. + case UE_BULK:
  77105. + pipetype = "BULK";
  77106. + break;
  77107. + case UE_INTERRUPT:
  77108. + pipetype = "INTERRUPT";
  77109. + break;
  77110. + case UE_ISOCHRONOUS:
  77111. + pipetype = "ISOCHRONOUS";
  77112. + break;
  77113. + default:
  77114. + pipetype = "UNKNOWN";
  77115. + break;
  77116. + }
  77117. +
  77118. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  77119. +
  77120. + switch (hc->speed) {
  77121. + case DWC_OTG_EP_SPEED_HIGH:
  77122. + speed = "HIGH";
  77123. + break;
  77124. + case DWC_OTG_EP_SPEED_FULL:
  77125. + speed = "FULL";
  77126. + break;
  77127. + case DWC_OTG_EP_SPEED_LOW:
  77128. + speed = "LOW";
  77129. + break;
  77130. + default:
  77131. + speed = "UNKNOWN";
  77132. + break;
  77133. + };
  77134. +
  77135. + DWC_ERROR(" Speed: %s\n", speed);
  77136. +
  77137. + DWC_ERROR(" Max packet size: %d\n",
  77138. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  77139. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  77140. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  77141. + urb->buf, (void *)urb->dma);
  77142. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  77143. + urb->setup_packet, (void *)urb->setup_dma);
  77144. + DWC_ERROR(" Interval: %d\n", urb->interval);
  77145. +
  77146. + /* Core haltes the channel for Descriptor DMA mode */
  77147. + if (hcd->core_if->dma_desc_enable) {
  77148. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  77149. + DWC_OTG_HC_XFER_AHB_ERR);
  77150. + goto handle_ahberr_done;
  77151. + }
  77152. +
  77153. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  77154. +
  77155. + /*
  77156. + * Force a channel halt. Don't call halt_channel because that won't
  77157. + * write to the HCCHARn register in DMA mode to force the halt.
  77158. + */
  77159. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  77160. +handle_ahberr_done:
  77161. + disable_hc_int(hc_regs, ahberr);
  77162. + return 1;
  77163. +}
  77164. +
  77165. +/**
  77166. + * Handles a host channel transaction error interrupt. This handler may be
  77167. + * called in either DMA mode or Slave mode.
  77168. + */
  77169. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  77170. + dwc_hc_t * hc,
  77171. + dwc_otg_hc_regs_t * hc_regs,
  77172. + dwc_otg_qtd_t * qtd)
  77173. +{
  77174. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77175. + "Transaction Error--\n", hc->hc_num);
  77176. +
  77177. + if (hcd->core_if->dma_desc_enable) {
  77178. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  77179. + DWC_OTG_HC_XFER_XACT_ERR);
  77180. + goto handle_xacterr_done;
  77181. + }
  77182. +
  77183. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  77184. + case UE_CONTROL:
  77185. + case UE_BULK:
  77186. + qtd->error_count++;
  77187. + if (!hc->qh->ping_state) {
  77188. +
  77189. + update_urb_state_xfer_intr(hc, hc_regs,
  77190. + qtd->urb, qtd,
  77191. + DWC_OTG_HC_XFER_XACT_ERR);
  77192. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77193. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  77194. + hc->qh->ping_state = 1;
  77195. + }
  77196. + }
  77197. +
  77198. + /*
  77199. + * Halt the channel so the transfer can be re-started from
  77200. + * the appropriate point or the PING protocol will start.
  77201. + */
  77202. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77203. + break;
  77204. + case UE_INTERRUPT:
  77205. + qtd->error_count++;
  77206. + if (hc->do_split && hc->complete_split) {
  77207. + qtd->complete_split = 0;
  77208. + }
  77209. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77210. + break;
  77211. + case UE_ISOCHRONOUS:
  77212. + {
  77213. + dwc_otg_halt_status_e halt_status;
  77214. + halt_status =
  77215. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77216. + DWC_OTG_HC_XFER_XACT_ERR);
  77217. +
  77218. + halt_channel(hcd, hc, qtd, halt_status);
  77219. + }
  77220. + break;
  77221. + }
  77222. +handle_xacterr_done:
  77223. + disable_hc_int(hc_regs, xacterr);
  77224. +
  77225. + return 1;
  77226. +}
  77227. +
  77228. +/**
  77229. + * Handles a host channel frame overrun interrupt. This handler may be called
  77230. + * in either DMA mode or Slave mode.
  77231. + */
  77232. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  77233. + dwc_hc_t * hc,
  77234. + dwc_otg_hc_regs_t * hc_regs,
  77235. + dwc_otg_qtd_t * qtd)
  77236. +{
  77237. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77238. + "Frame Overrun--\n", hc->hc_num);
  77239. +
  77240. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  77241. + case UE_CONTROL:
  77242. + case UE_BULK:
  77243. + break;
  77244. + case UE_INTERRUPT:
  77245. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  77246. + break;
  77247. + case UE_ISOCHRONOUS:
  77248. + {
  77249. + dwc_otg_halt_status_e halt_status;
  77250. + halt_status =
  77251. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77252. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  77253. +
  77254. + halt_channel(hcd, hc, qtd, halt_status);
  77255. + }
  77256. + break;
  77257. + }
  77258. +
  77259. + disable_hc_int(hc_regs, frmovrun);
  77260. +
  77261. + return 1;
  77262. +}
  77263. +
  77264. +/**
  77265. + * Handles a host channel data toggle error interrupt. This handler may be
  77266. + * called in either DMA mode or Slave mode.
  77267. + */
  77268. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  77269. + dwc_hc_t * hc,
  77270. + dwc_otg_hc_regs_t * hc_regs,
  77271. + dwc_otg_qtd_t * qtd)
  77272. +{
  77273. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77274. + "Data Toggle Error on %s transfer--\n",
  77275. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  77276. +
  77277. + /* Data toggles on split transactions cause the hc to halt.
  77278. + * restart transfer */
  77279. + if(hc->qh->do_split)
  77280. + {
  77281. + qtd->error_count++;
  77282. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77283. + update_urb_state_xfer_intr(hc, hc_regs,
  77284. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77285. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77286. + } else if (hc->ep_is_in) {
  77287. + /* An unmasked data toggle error on a non-split DMA transaction is
  77288. + * for the sole purpose of resetting error counts. Disable other
  77289. + * interrupts unmasked for the same reason.
  77290. + */
  77291. + if(hcd->core_if->dma_enable) {
  77292. + disable_hc_int(hc_regs, ack);
  77293. + disable_hc_int(hc_regs, nak);
  77294. + }
  77295. + qtd->error_count = 0;
  77296. + }
  77297. +
  77298. + disable_hc_int(hc_regs, datatglerr);
  77299. +
  77300. + return 1;
  77301. +}
  77302. +
  77303. +#ifdef DEBUG
  77304. +/**
  77305. + * This function is for debug only. It checks that a valid halt status is set
  77306. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  77307. + * taken and a warning is issued.
  77308. + * @return 1 if halt status is ok, 0 otherwise.
  77309. + */
  77310. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  77311. + dwc_hc_t * hc,
  77312. + dwc_otg_hc_regs_t * hc_regs,
  77313. + dwc_otg_qtd_t * qtd)
  77314. +{
  77315. + hcchar_data_t hcchar;
  77316. + hctsiz_data_t hctsiz;
  77317. + hcint_data_t hcint;
  77318. + hcintmsk_data_t hcintmsk;
  77319. + hcsplt_data_t hcsplt;
  77320. +
  77321. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  77322. + /*
  77323. + * This code is here only as a check. This condition should
  77324. + * never happen. Ignore the halt if it does occur.
  77325. + */
  77326. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  77327. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77328. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  77329. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  77330. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  77331. + DWC_WARN
  77332. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  77333. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  77334. + "hcint 0x%08x, hcintmsk 0x%08x, "
  77335. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  77336. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  77337. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  77338. +
  77339. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  77340. + __func__, hc->hc_num);
  77341. + DWC_WARN("\n");
  77342. + clear_hc_int(hc_regs, chhltd);
  77343. + return 0;
  77344. + }
  77345. +
  77346. + /*
  77347. + * This code is here only as a check. hcchar.chdis should
  77348. + * never be set when the halt interrupt occurs. Halt the
  77349. + * channel again if it does occur.
  77350. + */
  77351. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  77352. + if (hcchar.b.chdis) {
  77353. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  77354. + "hcchar 0x%08x, trying to halt again\n",
  77355. + __func__, hcchar.d32);
  77356. + clear_hc_int(hc_regs, chhltd);
  77357. + hc->halt_pending = 0;
  77358. + halt_channel(hcd, hc, qtd, hc->halt_status);
  77359. + return 0;
  77360. + }
  77361. +
  77362. + return 1;
  77363. +}
  77364. +#endif
  77365. +
  77366. +/**
  77367. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  77368. + * determines the reason the channel halted and proceeds accordingly.
  77369. + */
  77370. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  77371. + dwc_hc_t * hc,
  77372. + dwc_otg_hc_regs_t * hc_regs,
  77373. + dwc_otg_qtd_t * qtd,
  77374. + hcint_data_t hcint,
  77375. + hcintmsk_data_t hcintmsk)
  77376. +{
  77377. + int out_nak_enh = 0;
  77378. +
  77379. + /* For core with OUT NAK enhancement, the flow for high-
  77380. + * speed CONTROL/BULK OUT is handled a little differently.
  77381. + */
  77382. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  77383. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  77384. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  77385. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  77386. + out_nak_enh = 1;
  77387. + }
  77388. + }
  77389. +
  77390. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  77391. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  77392. + && !hcd->core_if->dma_desc_enable)) {
  77393. + /*
  77394. + * Just release the channel. A dequeue can happen on a
  77395. + * transfer timeout. In the case of an AHB Error, the channel
  77396. + * was forced to halt because there's no way to gracefully
  77397. + * recover.
  77398. + */
  77399. + if (hcd->core_if->dma_desc_enable)
  77400. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  77401. + hc->halt_status);
  77402. + else
  77403. + release_channel(hcd, hc, qtd, hc->halt_status);
  77404. + return;
  77405. + }
  77406. +
  77407. + /* Read the HCINTn register to determine the cause for the halt. */
  77408. + if(!fiq_split_enable)
  77409. + {
  77410. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  77411. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  77412. + }
  77413. +
  77414. + if (hcint.b.xfercomp) {
  77415. + /** @todo This is here because of a possible hardware bug. Spec
  77416. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  77417. + * interrupt w/ACK bit set should occur, but I only see the
  77418. + * XFERCOMP bit, even with it masked out. This is a workaround
  77419. + * for that behavior. Should fix this when hardware is fixed.
  77420. + */
  77421. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  77422. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  77423. + }
  77424. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  77425. + } else if (hcint.b.stall) {
  77426. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  77427. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  77428. + if (out_nak_enh) {
  77429. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  77430. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  77431. + qtd->error_count = 0;
  77432. + } else {
  77433. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  77434. + }
  77435. + }
  77436. +
  77437. + /*
  77438. + * Must handle xacterr before nak or ack. Could get a xacterr
  77439. + * at the same time as either of these on a BULK/CONTROL OUT
  77440. + * that started with a PING. The xacterr takes precedence.
  77441. + */
  77442. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  77443. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  77444. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  77445. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  77446. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  77447. + } else if (hcint.b.bblerr) {
  77448. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  77449. + } else if (hcint.b.frmovrun) {
  77450. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  77451. + } else if (hcint.b.datatglerr) {
  77452. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  77453. + } else if (!out_nak_enh) {
  77454. + if (hcint.b.nyet) {
  77455. + /*
  77456. + * Must handle nyet before nak or ack. Could get a nyet at the
  77457. + * same time as either of those on a BULK/CONTROL OUT that
  77458. + * started with a PING. The nyet takes precedence.
  77459. + */
  77460. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  77461. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  77462. + /*
  77463. + * If nak is not masked, it's because a non-split IN transfer
  77464. + * is in an error state. In that case, the nak is handled by
  77465. + * the nak interrupt handler, not here. Handle nak here for
  77466. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  77467. + * rewinding the buffer pointer.
  77468. + */
  77469. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  77470. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  77471. + /*
  77472. + * If ack is not masked, it's because a non-split IN transfer
  77473. + * is in an error state. In that case, the ack is handled by
  77474. + * the ack interrupt handler, not here. Handle ack here for
  77475. + * split transfers. Start splits halt on ACK.
  77476. + */
  77477. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  77478. + } else {
  77479. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  77480. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  77481. + /*
  77482. + * A periodic transfer halted with no other channel
  77483. + * interrupts set. Assume it was halted by the core
  77484. + * because it could not be completed in its scheduled
  77485. + * (micro)frame.
  77486. + */
  77487. +#ifdef DEBUG
  77488. + DWC_PRINTF
  77489. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  77490. + __func__, hc->hc_num);
  77491. +#endif
  77492. + halt_channel(hcd, hc, qtd,
  77493. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  77494. + } else {
  77495. + DWC_ERROR
  77496. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  77497. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  77498. + __func__, hc->hc_num, hcint.d32,
  77499. + DWC_READ_REG32(&hcd->
  77500. + core_if->core_global_regs->
  77501. + gintsts));
  77502. + /* Failthrough: use 3-strikes rule */
  77503. + qtd->error_count++;
  77504. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77505. + update_urb_state_xfer_intr(hc, hc_regs,
  77506. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77507. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77508. + }
  77509. +
  77510. + }
  77511. + } else {
  77512. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  77513. + hcint.d32);
  77514. + /* Failthrough: use 3-strikes rule */
  77515. + qtd->error_count++;
  77516. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77517. + update_urb_state_xfer_intr(hc, hc_regs,
  77518. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77519. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77520. + }
  77521. +}
  77522. +
  77523. +/**
  77524. + * Handles a host channel Channel Halted interrupt.
  77525. + *
  77526. + * In slave mode, this handler is called only when the driver specifically
  77527. + * requests a halt. This occurs during handling other host channel interrupts
  77528. + * (e.g. nak, xacterr, stall, nyet, etc.).
  77529. + *
  77530. + * In DMA mode, this is the interrupt that occurs when the core has finished
  77531. + * processing a transfer on a channel. Other host channel interrupts (except
  77532. + * ahberr) are disabled in DMA mode.
  77533. + */
  77534. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  77535. + dwc_hc_t * hc,
  77536. + dwc_otg_hc_regs_t * hc_regs,
  77537. + dwc_otg_qtd_t * qtd,
  77538. + hcint_data_t hcint,
  77539. + hcintmsk_data_t hcintmsk)
  77540. +{
  77541. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77542. + "Channel Halted--\n", hc->hc_num);
  77543. +
  77544. + if (hcd->core_if->dma_enable) {
  77545. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
  77546. + } else {
  77547. +#ifdef DEBUG
  77548. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  77549. + return 1;
  77550. + }
  77551. +#endif
  77552. + release_channel(hcd, hc, qtd, hc->halt_status);
  77553. + }
  77554. +
  77555. + return 1;
  77556. +}
  77557. +
  77558. +/** Handles interrupt for a specific Host Channel */
  77559. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  77560. +{
  77561. + int retval = 0;
  77562. + hcint_data_t hcint, hcint_orig;
  77563. + hcintmsk_data_t hcintmsk;
  77564. + dwc_hc_t *hc;
  77565. + dwc_otg_hc_regs_t *hc_regs;
  77566. + dwc_otg_qtd_t *qtd;
  77567. +
  77568. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  77569. +
  77570. + hc = dwc_otg_hcd->hc_ptr_array[num];
  77571. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  77572. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  77573. + /* We are responding to a channel disable. Driver
  77574. + * state is cleared - our qtd has gone away.
  77575. + */
  77576. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  77577. + return 1;
  77578. + }
  77579. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  77580. +
  77581. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  77582. + hcint_orig = hcint;
  77583. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  77584. + DWC_DEBUGPL(DBG_HCDV,
  77585. + " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  77586. + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
  77587. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  77588. +
  77589. + if(fiq_split_enable)
  77590. + {
  77591. + // replace with the saved interrupts from the fiq handler
  77592. + local_fiq_disable();
  77593. + hcint_orig.d32 = hcint_saved[num].d32;
  77594. + hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
  77595. + hcint_saved[num].d32 = 0;
  77596. + local_fiq_enable();
  77597. + }
  77598. +
  77599. + if (!dwc_otg_hcd->core_if->dma_enable) {
  77600. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  77601. + hcint.b.chhltd = 0;
  77602. + }
  77603. + }
  77604. +
  77605. + if (hcint.b.xfercomp) {
  77606. + retval |=
  77607. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77608. + /*
  77609. + * If NYET occurred at same time as Xfer Complete, the NYET is
  77610. + * handled by the Xfer Complete interrupt handler. Don't want
  77611. + * to call the NYET interrupt handler in this case.
  77612. + */
  77613. + hcint.b.nyet = 0;
  77614. + }
  77615. + if (hcint.b.chhltd) {
  77616. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
  77617. + }
  77618. + if (hcint.b.ahberr) {
  77619. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77620. + }
  77621. + if (hcint.b.stall) {
  77622. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77623. + }
  77624. + if (hcint.b.nak) {
  77625. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77626. + }
  77627. + if (hcint.b.ack) {
  77628. + if(!hcint.b.chhltd)
  77629. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77630. + }
  77631. + if (hcint.b.nyet) {
  77632. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77633. + }
  77634. + if (hcint.b.xacterr) {
  77635. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77636. + }
  77637. + if (hcint.b.bblerr) {
  77638. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77639. + }
  77640. + if (hcint.b.frmovrun) {
  77641. + retval |=
  77642. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77643. + }
  77644. + if (hcint.b.datatglerr) {
  77645. + retval |=
  77646. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77647. + }
  77648. +
  77649. + return retval;
  77650. +}
  77651. +#endif /* DWC_DEVICE_ONLY */
  77652. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  77653. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  77654. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-03-13 12:46:39.520097997 +0100
  77655. @@ -0,0 +1,972 @@
  77656. +
  77657. +/* ==========================================================================
  77658. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  77659. + * $Revision: #20 $
  77660. + * $Date: 2011/10/26 $
  77661. + * $Change: 1872981 $
  77662. + *
  77663. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77664. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77665. + * otherwise expressly agreed to in writing between Synopsys and you.
  77666. + *
  77667. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77668. + * any End User Software License Agreement or Agreement for Licensed Product
  77669. + * with Synopsys or any supplement thereto. You are permitted to use and
  77670. + * redistribute this Software in source and binary forms, with or without
  77671. + * modification, provided that redistributions of source code must retain this
  77672. + * notice. You may not view, use, disclose, copy or distribute this file or
  77673. + * any information contained herein except pursuant to this license grant from
  77674. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77675. + * below, then you are not authorized to use the Software.
  77676. + *
  77677. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77678. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77679. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77680. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77681. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77682. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77683. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77684. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77685. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77686. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77687. + * DAMAGE.
  77688. + * ========================================================================== */
  77689. +#ifndef DWC_DEVICE_ONLY
  77690. +
  77691. +/**
  77692. + * @file
  77693. + *
  77694. + * This file contains the implementation of the HCD. In Linux, the HCD
  77695. + * implements the hc_driver API.
  77696. + */
  77697. +#include <linux/kernel.h>
  77698. +#include <linux/module.h>
  77699. +#include <linux/moduleparam.h>
  77700. +#include <linux/init.h>
  77701. +#include <linux/device.h>
  77702. +#include <linux/errno.h>
  77703. +#include <linux/list.h>
  77704. +#include <linux/interrupt.h>
  77705. +#include <linux/string.h>
  77706. +#include <linux/dma-mapping.h>
  77707. +#include <linux/version.h>
  77708. +#include <asm/io.h>
  77709. +#include <asm/fiq.h>
  77710. +#include <linux/usb.h>
  77711. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  77712. +#include <../drivers/usb/core/hcd.h>
  77713. +#else
  77714. +#include <linux/usb/hcd.h>
  77715. +#endif
  77716. +
  77717. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  77718. +#define USB_URB_EP_LINKING 1
  77719. +#else
  77720. +#define USB_URB_EP_LINKING 0
  77721. +#endif
  77722. +
  77723. +#include "dwc_otg_hcd_if.h"
  77724. +#include "dwc_otg_dbg.h"
  77725. +#include "dwc_otg_driver.h"
  77726. +#include "dwc_otg_hcd.h"
  77727. +#include "dwc_otg_mphi_fix.h"
  77728. +
  77729. +/**
  77730. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  77731. + * qualified with its direction (possible 32 endpoints per device).
  77732. + */
  77733. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  77734. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  77735. +
  77736. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  77737. +
  77738. +extern bool fiq_fix_enable;
  77739. +
  77740. +/** @name Linux HC Driver API Functions */
  77741. +/** @{ */
  77742. +/* manage i/o requests, device state */
  77743. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  77744. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77745. + struct usb_host_endpoint *ep,
  77746. +#endif
  77747. + struct urb *urb, gfp_t mem_flags);
  77748. +
  77749. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  77750. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77751. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  77752. +#endif
  77753. +#else /* kernels at or post 2.6.30 */
  77754. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  77755. + struct urb *urb, int status);
  77756. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  77757. +
  77758. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  77759. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  77760. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  77761. +#endif
  77762. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  77763. +extern int hcd_start(struct usb_hcd *hcd);
  77764. +extern void hcd_stop(struct usb_hcd *hcd);
  77765. +static int get_frame_number(struct usb_hcd *hcd);
  77766. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  77767. +extern int hub_control(struct usb_hcd *hcd,
  77768. + u16 typeReq,
  77769. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  77770. +
  77771. +struct wrapper_priv_data {
  77772. + dwc_otg_hcd_t *dwc_otg_hcd;
  77773. +};
  77774. +
  77775. +/** @} */
  77776. +
  77777. +static struct hc_driver dwc_otg_hc_driver = {
  77778. +
  77779. + .description = dwc_otg_hcd_name,
  77780. + .product_desc = "DWC OTG Controller",
  77781. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  77782. +
  77783. + .irq = dwc_otg_hcd_irq,
  77784. +
  77785. + .flags = HCD_MEMORY | HCD_USB2,
  77786. +
  77787. + //.reset =
  77788. + .start = hcd_start,
  77789. + //.suspend =
  77790. + //.resume =
  77791. + .stop = hcd_stop,
  77792. +
  77793. + .urb_enqueue = dwc_otg_urb_enqueue,
  77794. + .urb_dequeue = dwc_otg_urb_dequeue,
  77795. + .endpoint_disable = endpoint_disable,
  77796. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  77797. + .endpoint_reset = endpoint_reset,
  77798. +#endif
  77799. + .get_frame_number = get_frame_number,
  77800. +
  77801. + .hub_status_data = hub_status_data,
  77802. + .hub_control = hub_control,
  77803. + //.bus_suspend =
  77804. + //.bus_resume =
  77805. +};
  77806. +
  77807. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  77808. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  77809. +{
  77810. + struct wrapper_priv_data *p;
  77811. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  77812. + return p->dwc_otg_hcd;
  77813. +}
  77814. +
  77815. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  77816. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  77817. +{
  77818. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  77819. +}
  77820. +
  77821. +/** Gets the usb_host_endpoint associated with an URB. */
  77822. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  77823. +{
  77824. + struct usb_device *dev = urb->dev;
  77825. + int ep_num = usb_pipeendpoint(urb->pipe);
  77826. +
  77827. + if (usb_pipein(urb->pipe))
  77828. + return dev->ep_in[ep_num];
  77829. + else
  77830. + return dev->ep_out[ep_num];
  77831. +}
  77832. +
  77833. +static int _disconnect(dwc_otg_hcd_t * hcd)
  77834. +{
  77835. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  77836. +
  77837. + usb_hcd->self.is_b_host = 0;
  77838. + return 0;
  77839. +}
  77840. +
  77841. +static int _start(dwc_otg_hcd_t * hcd)
  77842. +{
  77843. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  77844. +
  77845. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  77846. + hcd_start(usb_hcd);
  77847. +
  77848. + return 0;
  77849. +}
  77850. +
  77851. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  77852. + uint32_t * port_addr)
  77853. +{
  77854. + struct urb *urb = (struct urb *)urb_handle;
  77855. + struct usb_bus *bus;
  77856. +#if 1 //GRAYG - temporary
  77857. + if (NULL == urb_handle)
  77858. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  77859. + if (NULL == urb->dev)
  77860. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  77861. + if (NULL == port_addr)
  77862. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  77863. +#endif
  77864. + if (urb->dev->tt) {
  77865. + if (NULL == urb->dev->tt->hub) {
  77866. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  77867. + __func__); //GRAYG
  77868. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  77869. + *hub_addr = 0; //GRAYG
  77870. + // we probably shouldn't have a transaction translator if
  77871. + // there's no associated hub?
  77872. + } else {
  77873. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  77874. + if (urb->dev->tt->hub == bus->root_hub)
  77875. + *hub_addr = 0;
  77876. + else
  77877. + *hub_addr = urb->dev->tt->hub->devnum;
  77878. + }
  77879. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  77880. + } else {
  77881. + *hub_addr = 0;
  77882. + *port_addr = urb->dev->ttport;
  77883. + }
  77884. + return 0;
  77885. +}
  77886. +
  77887. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  77888. +{
  77889. + struct urb *urb = (struct urb *)urb_handle;
  77890. + return urb->dev->speed;
  77891. +}
  77892. +
  77893. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  77894. +{
  77895. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  77896. + return usb_hcd->self.b_hnp_enable;
  77897. +}
  77898. +
  77899. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  77900. + struct urb *urb)
  77901. +{
  77902. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  77903. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77904. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  77905. + } else {
  77906. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  77907. + }
  77908. +}
  77909. +
  77910. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  77911. + struct urb *urb)
  77912. +{
  77913. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  77914. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77915. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  77916. + } else {
  77917. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  77918. + }
  77919. +}
  77920. +
  77921. +/**
  77922. + * Sets the final status of an URB and returns it to the device driver. Any
  77923. + * required cleanup of the URB is performed. The HCD lock should be held on
  77924. + * entry.
  77925. + */
  77926. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  77927. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  77928. +{
  77929. + struct urb *urb = (struct urb *)urb_handle;
  77930. + urb_tq_entry_t *new_entry;
  77931. + int rc = 0;
  77932. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77933. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  77934. + __func__, urb, usb_pipedevice(urb->pipe),
  77935. + usb_pipeendpoint(urb->pipe),
  77936. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  77937. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77938. + int i;
  77939. + for (i = 0; i < urb->number_of_packets; i++) {
  77940. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  77941. + i, urb->iso_frame_desc[i].status);
  77942. + }
  77943. + }
  77944. + }
  77945. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  77946. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  77947. + /* Convert status value. */
  77948. + switch (status) {
  77949. + case -DWC_E_PROTOCOL:
  77950. + status = -EPROTO;
  77951. + break;
  77952. + case -DWC_E_IN_PROGRESS:
  77953. + status = -EINPROGRESS;
  77954. + break;
  77955. + case -DWC_E_PIPE:
  77956. + status = -EPIPE;
  77957. + break;
  77958. + case -DWC_E_IO:
  77959. + status = -EIO;
  77960. + break;
  77961. + case -DWC_E_TIMEOUT:
  77962. + status = -ETIMEDOUT;
  77963. + break;
  77964. + case -DWC_E_OVERFLOW:
  77965. + status = -EOVERFLOW;
  77966. + break;
  77967. + case -DWC_E_SHUTDOWN:
  77968. + status = -ESHUTDOWN;
  77969. + break;
  77970. + default:
  77971. + if (status) {
  77972. + DWC_PRINTF("Uknown urb status %d\n", status);
  77973. +
  77974. + }
  77975. + }
  77976. +
  77977. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77978. + int i;
  77979. +
  77980. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  77981. + for (i = 0; i < urb->number_of_packets; ++i) {
  77982. + urb->iso_frame_desc[i].actual_length =
  77983. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  77984. + (dwc_otg_urb, i);
  77985. + urb->iso_frame_desc[i].status =
  77986. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  77987. + }
  77988. + }
  77989. +
  77990. + urb->status = status;
  77991. + urb->hcpriv = NULL;
  77992. + if (!status) {
  77993. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  77994. + (urb->actual_length < urb->transfer_buffer_length)) {
  77995. + urb->status = -EREMOTEIO;
  77996. + }
  77997. + }
  77998. +
  77999. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  78000. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  78001. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  78002. + if (ep) {
  78003. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  78004. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  78005. + ep->hcpriv),
  78006. + urb);
  78007. + }
  78008. + }
  78009. +
  78010. + DWC_FREE(dwc_otg_urb);
  78011. + if (!new_entry) {
  78012. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  78013. + urb->status = -EPROTO;
  78014. + /* don't schedule the tasklet -
  78015. + * directly return the packet here with error. */
  78016. +#if USB_URB_EP_LINKING
  78017. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  78018. +#endif
  78019. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  78020. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  78021. +#else
  78022. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  78023. +#endif
  78024. + } else {
  78025. + new_entry->urb = urb;
  78026. +#if USB_URB_EP_LINKING
  78027. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  78028. + if(0 == rc) {
  78029. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  78030. + }
  78031. +#endif
  78032. + if(0 == rc) {
  78033. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  78034. + urb_tq_entries);
  78035. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  78036. + }
  78037. + }
  78038. + return 0;
  78039. +}
  78040. +
  78041. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  78042. + .start = _start,
  78043. + .disconnect = _disconnect,
  78044. + .hub_info = _hub_info,
  78045. + .speed = _speed,
  78046. + .complete = _complete,
  78047. + .get_b_hnp_enable = _get_b_hnp_enable,
  78048. +};
  78049. +
  78050. +static struct fiq_handler fh = {
  78051. + .name = "usb_fiq",
  78052. +};
  78053. +struct fiq_stack_s {
  78054. + int magic1;
  78055. + uint8_t stack[2048];
  78056. + int magic2;
  78057. +} fiq_stack;
  78058. +
  78059. +extern mphi_regs_t c_mphi_regs;
  78060. +/**
  78061. + * Initializes the HCD. This function allocates memory for and initializes the
  78062. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  78063. + * USB bus with the core and calls the hc_driver->start() function. It returns
  78064. + * a negative error on failure.
  78065. + */
  78066. +int hcd_init(dwc_bus_dev_t *_dev)
  78067. +{
  78068. + struct usb_hcd *hcd = NULL;
  78069. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  78070. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  78071. + int retval = 0;
  78072. + u64 dmamask;
  78073. + struct pt_regs regs;
  78074. +
  78075. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  78076. +
  78077. + /* Set device flags indicating whether the HCD supports DMA. */
  78078. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  78079. + dmamask = DMA_BIT_MASK(32);
  78080. + else
  78081. + dmamask = 0;
  78082. +
  78083. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  78084. + dma_set_mask(&_dev->dev, dmamask);
  78085. + dma_set_coherent_mask(&_dev->dev, dmamask);
  78086. +#elif defined(PCI_INTERFACE)
  78087. + pci_set_dma_mask(_dev, dmamask);
  78088. + pci_set_consistent_dma_mask(_dev, dmamask);
  78089. +#endif
  78090. +
  78091. + if (fiq_fix_enable)
  78092. + {
  78093. + // Set up fiq
  78094. + claim_fiq(&fh);
  78095. + set_fiq_handler(__FIQ_Branch, 4);
  78096. + memset(&regs,0,sizeof(regs));
  78097. + regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
  78098. + regs.ARM_r9 = (long)0;
  78099. + regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
  78100. + set_fiq_regs(&regs);
  78101. + fiq_stack.magic1 = 0xdeadbeef;
  78102. + fiq_stack.magic2 = 0xaa995566;
  78103. + }
  78104. +
  78105. + /*
  78106. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  78107. + * Initialize the base HCD.
  78108. + */
  78109. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  78110. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  78111. +#else
  78112. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  78113. + hcd->has_tt = 1;
  78114. +// hcd->uses_new_polling = 1;
  78115. +// hcd->poll_rh = 0;
  78116. +#endif
  78117. + if (!hcd) {
  78118. + retval = -ENOMEM;
  78119. + goto error1;
  78120. + }
  78121. +
  78122. + hcd->regs = otg_dev->os_dep.base;
  78123. +
  78124. + if (fiq_fix_enable)
  78125. + {
  78126. + volatile extern void *dwc_regs_base;
  78127. +
  78128. + //Set the mphi periph to the required registers
  78129. + c_mphi_regs.base = otg_dev->os_dep.mphi_base;
  78130. + c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  78131. + c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  78132. + c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  78133. + c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  78134. +
  78135. + dwc_regs_base = otg_dev->os_dep.base;
  78136. +
  78137. + //Enable mphi peripheral
  78138. + writel((1<<31),c_mphi_regs.ctrl);
  78139. +#ifdef DEBUG
  78140. + if (readl(c_mphi_regs.ctrl) & 0x80000000)
  78141. + DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
  78142. + else
  78143. + DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
  78144. +#endif
  78145. + // Enable FIQ interrupt from USB peripheral
  78146. + enable_fiq(INTERRUPT_VC_USB);
  78147. + }
  78148. + /* Initialize the DWC OTG HCD. */
  78149. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  78150. + if (!dwc_otg_hcd) {
  78151. + goto error2;
  78152. + }
  78153. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  78154. + dwc_otg_hcd;
  78155. + otg_dev->hcd = dwc_otg_hcd;
  78156. +
  78157. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  78158. + goto error2;
  78159. + }
  78160. +
  78161. + otg_dev->hcd->otg_dev = otg_dev;
  78162. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  78163. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  78164. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  78165. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  78166. +#endif
  78167. + /* Don't support SG list at this point */
  78168. + hcd->self.sg_tablesize = 0;
  78169. +#endif
  78170. + /*
  78171. + * Finish generic HCD initialization and start the HCD. This function
  78172. + * allocates the DMA buffer pool, registers the USB bus, requests the
  78173. + * IRQ line, and calls hcd_start method.
  78174. + */
  78175. +#ifdef PLATFORM_INTERFACE
  78176. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  78177. +#else
  78178. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  78179. +#endif
  78180. + if (retval < 0) {
  78181. + goto error2;
  78182. + }
  78183. +
  78184. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  78185. + return 0;
  78186. +
  78187. +error2:
  78188. + usb_put_hcd(hcd);
  78189. +error1:
  78190. + return retval;
  78191. +}
  78192. +
  78193. +/**
  78194. + * Removes the HCD.
  78195. + * Frees memory and resources associated with the HCD and deregisters the bus.
  78196. + */
  78197. +void hcd_remove(dwc_bus_dev_t *_dev)
  78198. +{
  78199. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  78200. + dwc_otg_hcd_t *dwc_otg_hcd;
  78201. + struct usb_hcd *hcd;
  78202. +
  78203. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  78204. +
  78205. + if (!otg_dev) {
  78206. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  78207. + return;
  78208. + }
  78209. +
  78210. + dwc_otg_hcd = otg_dev->hcd;
  78211. +
  78212. + if (!dwc_otg_hcd) {
  78213. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  78214. + return;
  78215. + }
  78216. +
  78217. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  78218. +
  78219. + if (!hcd) {
  78220. + DWC_DEBUGPL(DBG_ANY,
  78221. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  78222. + __func__);
  78223. + return;
  78224. + }
  78225. + usb_remove_hcd(hcd);
  78226. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  78227. + dwc_otg_hcd_remove(dwc_otg_hcd);
  78228. + usb_put_hcd(hcd);
  78229. +}
  78230. +
  78231. +/* =========================================================================
  78232. + * Linux HC Driver Functions
  78233. + * ========================================================================= */
  78234. +
  78235. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  78236. + * mode operation. Activates the root port. Returns 0 on success and a negative
  78237. + * error code on failure. */
  78238. +int hcd_start(struct usb_hcd *hcd)
  78239. +{
  78240. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78241. + struct usb_bus *bus;
  78242. +
  78243. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  78244. + bus = hcd_to_bus(hcd);
  78245. +
  78246. + hcd->state = HC_STATE_RUNNING;
  78247. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  78248. + return 0;
  78249. + }
  78250. +
  78251. + /* Initialize and connect root hub if one is not already attached */
  78252. + if (bus->root_hub) {
  78253. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  78254. + /* Inform the HUB driver to resume. */
  78255. + usb_hcd_resume_root_hub(hcd);
  78256. + }
  78257. +
  78258. + return 0;
  78259. +}
  78260. +
  78261. +/**
  78262. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  78263. + * stopped.
  78264. + */
  78265. +void hcd_stop(struct usb_hcd *hcd)
  78266. +{
  78267. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78268. +
  78269. + dwc_otg_hcd_stop(dwc_otg_hcd);
  78270. +}
  78271. +
  78272. +/** Returns the current frame number. */
  78273. +static int get_frame_number(struct usb_hcd *hcd)
  78274. +{
  78275. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78276. +
  78277. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  78278. +}
  78279. +
  78280. +#ifdef DEBUG
  78281. +static void dump_urb_info(struct urb *urb, char *fn_name)
  78282. +{
  78283. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  78284. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  78285. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  78286. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  78287. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  78288. + char *pipetype;
  78289. + switch (usb_pipetype(urb->pipe)) {
  78290. +case PIPE_CONTROL:
  78291. +pipetype = "CONTROL"; break; case PIPE_BULK:
  78292. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  78293. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  78294. +pipetype = "ISOCHRONOUS"; break; default:
  78295. + pipetype = "UNKNOWN"; break;};
  78296. + pipetype;}
  78297. + )) ;
  78298. + DWC_PRINTF(" Speed: %s\n", ( {
  78299. + char *speed; switch (urb->dev->speed) {
  78300. +case USB_SPEED_HIGH:
  78301. +speed = "HIGH"; break; case USB_SPEED_FULL:
  78302. +speed = "FULL"; break; case USB_SPEED_LOW:
  78303. +speed = "LOW"; break; default:
  78304. + speed = "UNKNOWN"; break;};
  78305. + speed;}
  78306. + )) ;
  78307. + DWC_PRINTF(" Max packet size: %d\n",
  78308. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  78309. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  78310. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  78311. + urb->transfer_buffer, (void *)urb->transfer_dma);
  78312. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  78313. + urb->setup_packet, (void *)urb->setup_dma);
  78314. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  78315. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  78316. + int i;
  78317. + for (i = 0; i < urb->number_of_packets; i++) {
  78318. + DWC_PRINTF(" ISO Desc %d:\n", i);
  78319. + DWC_PRINTF(" offset: %d, length %d\n",
  78320. + urb->iso_frame_desc[i].offset,
  78321. + urb->iso_frame_desc[i].length);
  78322. + }
  78323. + }
  78324. +}
  78325. +#endif
  78326. +
  78327. +/** Starts processing a USB transfer request specified by a USB Request Block
  78328. + * (URB). mem_flags indicates the type of memory allocation to use while
  78329. + * processing this URB. */
  78330. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  78331. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  78332. + struct usb_host_endpoint *ep,
  78333. +#endif
  78334. + struct urb *urb, gfp_t mem_flags)
  78335. +{
  78336. + int retval = 0;
  78337. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  78338. + struct usb_host_endpoint *ep = urb->ep;
  78339. +#endif
  78340. + dwc_irqflags_t irqflags;
  78341. + void **ref_ep_hcpriv = &ep->hcpriv;
  78342. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78343. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  78344. + int i;
  78345. + int alloc_bandwidth = 0;
  78346. + uint8_t ep_type = 0;
  78347. + uint32_t flags = 0;
  78348. + void *buf;
  78349. +
  78350. +#ifdef DEBUG
  78351. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  78352. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  78353. + }
  78354. +#endif
  78355. +
  78356. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  78357. + return -EINVAL;
  78358. +
  78359. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  78360. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  78361. + if (!dwc_otg_hcd_is_bandwidth_allocated
  78362. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  78363. + alloc_bandwidth = 1;
  78364. + }
  78365. + }
  78366. +
  78367. + switch (usb_pipetype(urb->pipe)) {
  78368. + case PIPE_CONTROL:
  78369. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  78370. + break;
  78371. + case PIPE_ISOCHRONOUS:
  78372. + ep_type = USB_ENDPOINT_XFER_ISOC;
  78373. + break;
  78374. + case PIPE_BULK:
  78375. + ep_type = USB_ENDPOINT_XFER_BULK;
  78376. + break;
  78377. + case PIPE_INTERRUPT:
  78378. + ep_type = USB_ENDPOINT_XFER_INT;
  78379. + break;
  78380. + default:
  78381. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  78382. + }
  78383. +
  78384. + /* # of packets is often 0 - do we really need to call this then? */
  78385. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  78386. + urb->number_of_packets,
  78387. + mem_flags == GFP_ATOMIC ? 1 : 0);
  78388. +
  78389. + if(dwc_otg_urb == NULL)
  78390. + return -ENOMEM;
  78391. +
  78392. + if (!dwc_otg_urb && urb->number_of_packets)
  78393. + return -ENOMEM;
  78394. +
  78395. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  78396. + usb_pipeendpoint(urb->pipe), ep_type,
  78397. + usb_pipein(urb->pipe),
  78398. + usb_maxpacket(urb->dev, urb->pipe,
  78399. + !(usb_pipein(urb->pipe))));
  78400. +
  78401. + buf = urb->transfer_buffer;
  78402. + if (hcd->self.uses_dma) {
  78403. + /*
  78404. + * Calculate virtual address from physical address,
  78405. + * because some class driver may not fill transfer_buffer.
  78406. + * In Buffer DMA mode virual address is used,
  78407. + * when handling non DWORD aligned buffers.
  78408. + */
  78409. + //buf = phys_to_virt(urb->transfer_dma);
  78410. + // DMA addresses are bus addresses not physical addresses!
  78411. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  78412. + }
  78413. +
  78414. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  78415. + flags |= URB_GIVEBACK_ASAP;
  78416. + if (urb->transfer_flags & URB_ZERO_PACKET)
  78417. + flags |= URB_SEND_ZERO_PACKET;
  78418. +
  78419. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  78420. + urb->transfer_dma,
  78421. + urb->transfer_buffer_length,
  78422. + urb->setup_packet,
  78423. + urb->setup_dma, flags, urb->interval);
  78424. +
  78425. + for (i = 0; i < urb->number_of_packets; ++i) {
  78426. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  78427. + urb->
  78428. + iso_frame_desc[i].offset,
  78429. + urb->
  78430. + iso_frame_desc[i].length);
  78431. + }
  78432. +
  78433. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  78434. + urb->hcpriv = dwc_otg_urb;
  78435. +#if USB_URB_EP_LINKING
  78436. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  78437. + if (0 == retval)
  78438. +#endif
  78439. + {
  78440. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  78441. + /*(dwc_otg_qh_t **)*/
  78442. + ref_ep_hcpriv, 1);
  78443. + if (0 == retval) {
  78444. + if (alloc_bandwidth) {
  78445. + allocate_bus_bandwidth(hcd,
  78446. + dwc_otg_hcd_get_ep_bandwidth(
  78447. + dwc_otg_hcd, *ref_ep_hcpriv),
  78448. + urb);
  78449. + }
  78450. + } else {
  78451. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  78452. +#if USB_URB_EP_LINKING
  78453. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  78454. +#endif
  78455. + DWC_FREE(dwc_otg_urb);
  78456. + urb->hcpriv = NULL;
  78457. + if (retval == -DWC_E_NO_DEVICE)
  78458. + retval = -ENODEV;
  78459. + }
  78460. + }
  78461. +#if USB_URB_EP_LINKING
  78462. + else
  78463. + {
  78464. + DWC_FREE(dwc_otg_urb);
  78465. + urb->hcpriv = NULL;
  78466. + }
  78467. +#endif
  78468. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  78469. + return retval;
  78470. +}
  78471. +
  78472. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  78473. + * success. */
  78474. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  78475. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  78476. +#else
  78477. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  78478. +#endif
  78479. +{
  78480. + dwc_irqflags_t flags;
  78481. + dwc_otg_hcd_t *dwc_otg_hcd;
  78482. + int rc;
  78483. +
  78484. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  78485. +
  78486. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78487. +
  78488. +#ifdef DEBUG
  78489. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  78490. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  78491. + }
  78492. +#endif
  78493. +
  78494. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  78495. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  78496. + if (0 == rc) {
  78497. + if(urb->hcpriv != NULL) {
  78498. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  78499. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  78500. +
  78501. + DWC_FREE(urb->hcpriv);
  78502. + urb->hcpriv = NULL;
  78503. + }
  78504. + }
  78505. +
  78506. + if (0 == rc) {
  78507. + /* Higher layer software sets URB status. */
  78508. +#if USB_URB_EP_LINKING
  78509. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  78510. +#endif
  78511. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  78512. +
  78513. +
  78514. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  78515. + usb_hcd_giveback_urb(hcd, urb);
  78516. +#else
  78517. + usb_hcd_giveback_urb(hcd, urb, status);
  78518. +#endif
  78519. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  78520. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  78521. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  78522. + }
  78523. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  78524. + } else {
  78525. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  78526. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  78527. + rc);
  78528. + }
  78529. +
  78530. + return rc;
  78531. +}
  78532. +
  78533. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  78534. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  78535. + * must already be dequeued. */
  78536. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  78537. +{
  78538. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78539. +
  78540. + DWC_DEBUGPL(DBG_HCD,
  78541. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  78542. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  78543. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  78544. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  78545. + ep->hcpriv = NULL;
  78546. +}
  78547. +
  78548. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  78549. +/* Resets endpoint specific parameter values, in current version used to reset
  78550. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  78551. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  78552. +{
  78553. + dwc_irqflags_t flags;
  78554. + struct usb_device *udev = NULL;
  78555. + int epnum = usb_endpoint_num(&ep->desc);
  78556. + int is_out = usb_endpoint_dir_out(&ep->desc);
  78557. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  78558. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78559. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  78560. +
  78561. + if (dev)
  78562. + udev = to_usb_device(dev);
  78563. + else
  78564. + return;
  78565. +
  78566. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  78567. +
  78568. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  78569. + usb_settoggle(udev, epnum, is_out, 0);
  78570. + if (is_control)
  78571. + usb_settoggle(udev, epnum, !is_out, 0);
  78572. +
  78573. + if (ep->hcpriv) {
  78574. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  78575. + }
  78576. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  78577. +}
  78578. +#endif
  78579. +
  78580. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  78581. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  78582. + * interrupt.
  78583. + *
  78584. + * This function is called by the USB core when an interrupt occurs */
  78585. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  78586. +{
  78587. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78588. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  78589. + if (retval != 0) {
  78590. + S3C2410X_CLEAR_EINTPEND();
  78591. + }
  78592. + return IRQ_RETVAL(retval);
  78593. +}
  78594. +
  78595. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  78596. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  78597. + * is the status change indicator for the single root port. Returns 1 if either
  78598. + * change indicator is 1, otherwise returns 0. */
  78599. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  78600. +{
  78601. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78602. +
  78603. + buf[0] = 0;
  78604. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  78605. +
  78606. + return (buf[0] != 0);
  78607. +}
  78608. +
  78609. +/** Handles hub class-specific requests. */
  78610. +int hub_control(struct usb_hcd *hcd,
  78611. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  78612. +{
  78613. + int retval;
  78614. +
  78615. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  78616. + typeReq, wValue, wIndex, buf, wLength);
  78617. +
  78618. + switch (retval) {
  78619. + case -DWC_E_INVALID:
  78620. + retval = -EINVAL;
  78621. + break;
  78622. + }
  78623. +
  78624. + return retval;
  78625. +}
  78626. +
  78627. +#endif /* DWC_DEVICE_ONLY */
  78628. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  78629. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  78630. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-03-13 12:46:39.520097997 +0100
  78631. @@ -0,0 +1,959 @@
  78632. +/* ==========================================================================
  78633. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  78634. + * $Revision: #44 $
  78635. + * $Date: 2011/10/26 $
  78636. + * $Change: 1873028 $
  78637. + *
  78638. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78639. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78640. + * otherwise expressly agreed to in writing between Synopsys and you.
  78641. + *
  78642. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78643. + * any End User Software License Agreement or Agreement for Licensed Product
  78644. + * with Synopsys or any supplement thereto. You are permitted to use and
  78645. + * redistribute this Software in source and binary forms, with or without
  78646. + * modification, provided that redistributions of source code must retain this
  78647. + * notice. You may not view, use, disclose, copy or distribute this file or
  78648. + * any information contained herein except pursuant to this license grant from
  78649. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78650. + * below, then you are not authorized to use the Software.
  78651. + *
  78652. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78653. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78654. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78655. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78656. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78657. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78658. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78659. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78660. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78661. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78662. + * DAMAGE.
  78663. + * ========================================================================== */
  78664. +#ifndef DWC_DEVICE_ONLY
  78665. +
  78666. +/**
  78667. + * @file
  78668. + *
  78669. + * This file contains the functions to manage Queue Heads and Queue
  78670. + * Transfer Descriptors.
  78671. + */
  78672. +
  78673. +#include "dwc_otg_hcd.h"
  78674. +#include "dwc_otg_regs.h"
  78675. +#include "dwc_otg_mphi_fix.h"
  78676. +
  78677. +extern bool microframe_schedule;
  78678. +
  78679. +/**
  78680. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  78681. + * removed from a list. QTD list should already be empty if called from URB
  78682. + * Dequeue.
  78683. + *
  78684. + * @param hcd HCD instance.
  78685. + * @param qh The QH to free.
  78686. + */
  78687. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78688. +{
  78689. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  78690. +
  78691. + /* Free each QTD in the QTD list */
  78692. + DWC_SPINLOCK(hcd->lock);
  78693. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  78694. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  78695. + dwc_otg_hcd_qtd_free(qtd);
  78696. + }
  78697. +
  78698. + if (hcd->core_if->dma_desc_enable) {
  78699. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  78700. + } else if (qh->dw_align_buf) {
  78701. + uint32_t buf_size;
  78702. + if (qh->ep_type == UE_ISOCHRONOUS) {
  78703. + buf_size = 4096;
  78704. + } else {
  78705. + buf_size = hcd->core_if->core_params->max_transfer_size;
  78706. + }
  78707. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  78708. + }
  78709. +
  78710. + DWC_FREE(qh);
  78711. + DWC_SPINUNLOCK(hcd->lock);
  78712. + return;
  78713. +}
  78714. +
  78715. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  78716. +#define HS_HOST_DELAY 5 /* nanoseconds */
  78717. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  78718. +#define HUB_LS_SETUP 333 /* nanoseconds */
  78719. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  78720. + /* convert & round nanoseconds to microseconds */
  78721. +
  78722. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  78723. +{
  78724. + unsigned long retval;
  78725. +
  78726. + switch (speed) {
  78727. + case USB_SPEED_HIGH:
  78728. + if (is_isoc) {
  78729. + retval =
  78730. + ((38 * 8 * 2083) +
  78731. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  78732. + HS_HOST_DELAY;
  78733. + } else {
  78734. + retval =
  78735. + ((55 * 8 * 2083) +
  78736. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  78737. + HS_HOST_DELAY;
  78738. + }
  78739. + break;
  78740. + case USB_SPEED_FULL:
  78741. + if (is_isoc) {
  78742. + retval =
  78743. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  78744. + if (is_in) {
  78745. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  78746. + } else {
  78747. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  78748. + }
  78749. + } else {
  78750. + retval =
  78751. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  78752. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  78753. + }
  78754. + break;
  78755. + case USB_SPEED_LOW:
  78756. + if (is_in) {
  78757. + retval =
  78758. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  78759. + 1000;
  78760. + retval =
  78761. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  78762. + retval;
  78763. + } else {
  78764. + retval =
  78765. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  78766. + 1000;
  78767. + retval =
  78768. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  78769. + retval;
  78770. + }
  78771. + break;
  78772. + default:
  78773. + DWC_WARN("Unknown device speed\n");
  78774. + retval = -1;
  78775. + }
  78776. +
  78777. + return NS_TO_US(retval);
  78778. +}
  78779. +
  78780. +/**
  78781. + * Initializes a QH structure.
  78782. + *
  78783. + * @param hcd The HCD state structure for the DWC OTG controller.
  78784. + * @param qh The QH to init.
  78785. + * @param urb Holds the information about the device/endpoint that we need
  78786. + * to initialize the QH.
  78787. + */
  78788. +#define SCHEDULE_SLOP 10
  78789. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  78790. +{
  78791. + char *speed, *type;
  78792. + int dev_speed;
  78793. + uint32_t hub_addr, hub_port;
  78794. +
  78795. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  78796. +
  78797. + /* Initialize QH */
  78798. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  78799. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  78800. +
  78801. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  78802. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  78803. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  78804. + DWC_LIST_INIT(&qh->qh_list_entry);
  78805. + qh->channel = NULL;
  78806. +
  78807. + /* FS/LS Enpoint on HS Hub
  78808. + * NOT virtual root hub */
  78809. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  78810. +
  78811. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  78812. + qh->do_split = 0;
  78813. + if (microframe_schedule)
  78814. + qh->speed = dev_speed;
  78815. +
  78816. + qh->nak_frame = 0xffff;
  78817. +
  78818. + if (((dev_speed == USB_SPEED_LOW) ||
  78819. + (dev_speed == USB_SPEED_FULL)) &&
  78820. + (hub_addr != 0 && hub_addr != 1)) {
  78821. + DWC_DEBUGPL(DBG_HCD,
  78822. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  78823. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  78824. + hub_port);
  78825. + qh->do_split = 1;
  78826. + qh->skip_count = 0;
  78827. + }
  78828. +
  78829. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  78830. + /* Compute scheduling parameters once and save them. */
  78831. + hprt0_data_t hprt;
  78832. +
  78833. + /** @todo Account for split transfers in the bus time. */
  78834. + int bytecount =
  78835. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  78836. +
  78837. + qh->usecs =
  78838. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  78839. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  78840. + bytecount);
  78841. + /* Start in a slightly future (micro)frame. */
  78842. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  78843. + SCHEDULE_SLOP);
  78844. + qh->interval = urb->interval;
  78845. +
  78846. +#if 0
  78847. + /* Increase interrupt polling rate for debugging. */
  78848. + if (qh->ep_type == UE_INTERRUPT) {
  78849. + qh->interval = 8;
  78850. + }
  78851. +#endif
  78852. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  78853. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  78854. + ((dev_speed == USB_SPEED_LOW) ||
  78855. + (dev_speed == USB_SPEED_FULL))) {
  78856. + qh->interval *= 8;
  78857. + qh->sched_frame |= 0x7;
  78858. + qh->start_split_frame = qh->sched_frame;
  78859. + }
  78860. +
  78861. + }
  78862. +
  78863. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  78864. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  78865. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  78866. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  78867. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  78868. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  78869. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  78870. + switch (dev_speed) {
  78871. + case USB_SPEED_LOW:
  78872. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  78873. + speed = "low";
  78874. + break;
  78875. + case USB_SPEED_FULL:
  78876. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  78877. + speed = "full";
  78878. + break;
  78879. + case USB_SPEED_HIGH:
  78880. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  78881. + speed = "high";
  78882. + break;
  78883. + default:
  78884. + speed = "?";
  78885. + break;
  78886. + }
  78887. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  78888. +
  78889. + switch (qh->ep_type) {
  78890. + case UE_ISOCHRONOUS:
  78891. + type = "isochronous";
  78892. + break;
  78893. + case UE_INTERRUPT:
  78894. + type = "interrupt";
  78895. + break;
  78896. + case UE_CONTROL:
  78897. + type = "control";
  78898. + break;
  78899. + case UE_BULK:
  78900. + type = "bulk";
  78901. + break;
  78902. + default:
  78903. + type = "?";
  78904. + break;
  78905. + }
  78906. +
  78907. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  78908. +
  78909. +#ifdef DEBUG
  78910. + if (qh->ep_type == UE_INTERRUPT) {
  78911. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  78912. + qh->usecs);
  78913. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  78914. + qh->interval);
  78915. + }
  78916. +#endif
  78917. +
  78918. +}
  78919. +
  78920. +/**
  78921. + * This function allocates and initializes a QH.
  78922. + *
  78923. + * @param hcd The HCD state structure for the DWC OTG controller.
  78924. + * @param urb Holds the information about the device/endpoint that we need
  78925. + * to initialize the QH.
  78926. + * @param atomic_alloc Flag to do atomic allocation if needed
  78927. + *
  78928. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  78929. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  78930. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  78931. +{
  78932. + dwc_otg_qh_t *qh;
  78933. +
  78934. + /* Allocate memory */
  78935. + /** @todo add memflags argument */
  78936. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  78937. + if (qh == NULL) {
  78938. + DWC_ERROR("qh allocation failed");
  78939. + return NULL;
  78940. + }
  78941. +
  78942. + qh_init(hcd, qh, urb);
  78943. +
  78944. + if (hcd->core_if->dma_desc_enable
  78945. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  78946. + dwc_otg_hcd_qh_free(hcd, qh);
  78947. + return NULL;
  78948. + }
  78949. +
  78950. + return qh;
  78951. +}
  78952. +
  78953. +/* microframe_schedule=0 start */
  78954. +
  78955. +/**
  78956. + * Checks that a channel is available for a periodic transfer.
  78957. + *
  78958. + * @return 0 if successful, negative error code otherise.
  78959. + */
  78960. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  78961. +{
  78962. + /*
  78963. + * Currently assuming that there is a dedicated host channnel for each
  78964. + * periodic transaction plus at least one host channel for
  78965. + * non-periodic transactions.
  78966. + */
  78967. + int status;
  78968. + int num_channels;
  78969. +
  78970. + num_channels = hcd->core_if->core_params->host_channels;
  78971. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  78972. + && (hcd->periodic_channels < num_channels - 1)) {
  78973. + status = 0;
  78974. + } else {
  78975. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  78976. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  78977. + status = -DWC_E_NO_SPACE;
  78978. + }
  78979. +
  78980. + return status;
  78981. +}
  78982. +
  78983. +/**
  78984. + * Checks that there is sufficient bandwidth for the specified QH in the
  78985. + * periodic schedule. For simplicity, this calculation assumes that all the
  78986. + * transfers in the periodic schedule may occur in the same (micro)frame.
  78987. + *
  78988. + * @param hcd The HCD state structure for the DWC OTG controller.
  78989. + * @param qh QH containing periodic bandwidth required.
  78990. + *
  78991. + * @return 0 if successful, negative error code otherwise.
  78992. + */
  78993. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78994. +{
  78995. + int status;
  78996. + int16_t max_claimed_usecs;
  78997. +
  78998. + status = 0;
  78999. +
  79000. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  79001. + /*
  79002. + * High speed mode.
  79003. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  79004. + */
  79005. +
  79006. + max_claimed_usecs = 100 - qh->usecs;
  79007. + } else {
  79008. + /*
  79009. + * Full speed mode.
  79010. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  79011. + */
  79012. + max_claimed_usecs = 900 - qh->usecs;
  79013. + }
  79014. +
  79015. + if (hcd->periodic_usecs > max_claimed_usecs) {
  79016. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  79017. + status = -DWC_E_NO_SPACE;
  79018. + }
  79019. +
  79020. + return status;
  79021. +}
  79022. +
  79023. +/* microframe_schedule=0 end */
  79024. +
  79025. +/**
  79026. + * Microframe scheduler
  79027. + * track the total use in hcd->frame_usecs
  79028. + * keep each qh use in qh->frame_usecs
  79029. + * when surrendering the qh then donate the time back
  79030. + */
  79031. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  79032. +
  79033. +/*
  79034. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  79035. + */
  79036. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  79037. +{
  79038. + int i;
  79039. + for (i=0; i<8; i++) {
  79040. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  79041. + }
  79042. + return 0;
  79043. +}
  79044. +
  79045. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  79046. +{
  79047. + int i;
  79048. + unsigned short utime;
  79049. + int t_left;
  79050. + int ret;
  79051. + int done;
  79052. +
  79053. + ret = -1;
  79054. + utime = _qh->usecs;
  79055. + t_left = utime;
  79056. + i = 0;
  79057. + done = 0;
  79058. + while (done == 0) {
  79059. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  79060. + if (utime <= _hcd->frame_usecs[i]) {
  79061. + _hcd->frame_usecs[i] -= utime;
  79062. + _qh->frame_usecs[i] += utime;
  79063. + t_left -= utime;
  79064. + ret = i;
  79065. + done = 1;
  79066. + return ret;
  79067. + } else {
  79068. + i++;
  79069. + if (i == 8) {
  79070. + done = 1;
  79071. + ret = -1;
  79072. + }
  79073. + }
  79074. + }
  79075. + return ret;
  79076. + }
  79077. +
  79078. +/*
  79079. + * use this for FS apps that can span multiple uframes
  79080. + */
  79081. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  79082. +{
  79083. + int i;
  79084. + int j;
  79085. + unsigned short utime;
  79086. + int t_left;
  79087. + int ret;
  79088. + int done;
  79089. + unsigned short xtime;
  79090. +
  79091. + ret = -1;
  79092. + utime = _qh->usecs;
  79093. + t_left = utime;
  79094. + i = 0;
  79095. + done = 0;
  79096. +loop:
  79097. + while (done == 0) {
  79098. + if(_hcd->frame_usecs[i] <= 0) {
  79099. + i++;
  79100. + if (i == 8) {
  79101. + done = 1;
  79102. + ret = -1;
  79103. + }
  79104. + goto loop;
  79105. + }
  79106. +
  79107. + /*
  79108. + * we need n consecutive slots
  79109. + * so use j as a start slot j plus j+1 must be enough time (for now)
  79110. + */
  79111. + xtime= _hcd->frame_usecs[i];
  79112. + for (j = i+1 ; j < 8 ; j++ ) {
  79113. + /*
  79114. + * if we add this frame remaining time to xtime we may
  79115. + * be OK, if not we need to test j for a complete frame
  79116. + */
  79117. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  79118. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  79119. + j = 8;
  79120. + ret = -1;
  79121. + continue;
  79122. + }
  79123. + }
  79124. + if (xtime >= utime) {
  79125. + ret = i;
  79126. + j = 8; /* stop loop with a good value ret */
  79127. + continue;
  79128. + }
  79129. + /* add the frame time to x time */
  79130. + xtime += _hcd->frame_usecs[j];
  79131. + /* we must have a fully available next frame or break */
  79132. + if ((xtime < utime)
  79133. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  79134. + ret = -1;
  79135. + j = 8; /* stop loop with a bad value ret */
  79136. + continue;
  79137. + }
  79138. + }
  79139. + if (ret >= 0) {
  79140. + t_left = utime;
  79141. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  79142. + t_left -= _hcd->frame_usecs[j];
  79143. + if ( t_left <= 0 ) {
  79144. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  79145. + _hcd->frame_usecs[j]= -t_left;
  79146. + ret = i;
  79147. + done = 1;
  79148. + } else {
  79149. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  79150. + _hcd->frame_usecs[j] = 0;
  79151. + }
  79152. + }
  79153. + } else {
  79154. + i++;
  79155. + if (i == 8) {
  79156. + done = 1;
  79157. + ret = -1;
  79158. + }
  79159. + }
  79160. + }
  79161. + return ret;
  79162. +}
  79163. +
  79164. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  79165. +{
  79166. + int ret;
  79167. + ret = -1;
  79168. +
  79169. + if (_qh->speed == USB_SPEED_HIGH) {
  79170. + /* if this is a hs transaction we need a full frame */
  79171. + ret = find_single_uframe(_hcd, _qh);
  79172. + } else {
  79173. + /* if this is a fs transaction we may need a sequence of frames */
  79174. + ret = find_multi_uframe(_hcd, _qh);
  79175. + }
  79176. + return ret;
  79177. +}
  79178. +
  79179. +/**
  79180. + * Checks that the max transfer size allowed in a host channel is large enough
  79181. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  79182. + * transfer.
  79183. + *
  79184. + * @param hcd The HCD state structure for the DWC OTG controller.
  79185. + * @param qh QH for a periodic endpoint.
  79186. + *
  79187. + * @return 0 if successful, negative error code otherwise.
  79188. + */
  79189. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79190. +{
  79191. + int status;
  79192. + uint32_t max_xfer_size;
  79193. + uint32_t max_channel_xfer_size;
  79194. +
  79195. + status = 0;
  79196. +
  79197. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  79198. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  79199. +
  79200. + if (max_xfer_size > max_channel_xfer_size) {
  79201. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  79202. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  79203. + status = -DWC_E_NO_SPACE;
  79204. + }
  79205. +
  79206. + return status;
  79207. +}
  79208. +
  79209. +
  79210. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  79211. +
  79212. +/**
  79213. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  79214. + *
  79215. + * @param hcd The HCD state structure for the DWC OTG controller.
  79216. + * @param qh QH for the periodic transfer. The QH should already contain the
  79217. + * scheduling information.
  79218. + *
  79219. + * @return 0 if successful, negative error code otherwise.
  79220. + */
  79221. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79222. +{
  79223. + int status = 0;
  79224. +
  79225. + if (microframe_schedule) {
  79226. + int frame;
  79227. + status = find_uframe(hcd, qh);
  79228. + frame = -1;
  79229. + if (status == 0) {
  79230. + frame = 7;
  79231. + } else {
  79232. + if (status > 0 )
  79233. + frame = status-1;
  79234. + }
  79235. +
  79236. + /* Set the new frame up */
  79237. + if (frame > -1) {
  79238. + qh->sched_frame &= ~0x7;
  79239. + qh->sched_frame |= (frame & 7);
  79240. + }
  79241. +
  79242. + if (status != -1)
  79243. + status = 0;
  79244. + } else {
  79245. + status = periodic_channel_available(hcd);
  79246. + if (status) {
  79247. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  79248. + return status;
  79249. + }
  79250. +
  79251. + status = check_periodic_bandwidth(hcd, qh);
  79252. + }
  79253. + if (status) {
  79254. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  79255. + "periodic transfer.\n", __func__);
  79256. + return status;
  79257. + }
  79258. + status = check_max_xfer_size(hcd, qh);
  79259. + if (status) {
  79260. + DWC_INFO("%s: Channel max transfer size too small "
  79261. + "for periodic transfer.\n", __func__);
  79262. + return status;
  79263. + }
  79264. +
  79265. + if (hcd->core_if->dma_desc_enable) {
  79266. + /* Don't rely on SOF and start in ready schedule */
  79267. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  79268. + }
  79269. + else {
  79270. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
  79271. + {
  79272. + g_next_sched_frame = qh->sched_frame;
  79273. +
  79274. + }
  79275. + /* Always start in the inactive schedule. */
  79276. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  79277. + }
  79278. +
  79279. + if (!microframe_schedule) {
  79280. + /* Reserve the periodic channel. */
  79281. + hcd->periodic_channels++;
  79282. + }
  79283. +
  79284. + /* Update claimed usecs per (micro)frame. */
  79285. + hcd->periodic_usecs += qh->usecs;
  79286. +
  79287. + return status;
  79288. +}
  79289. +
  79290. +
  79291. +/**
  79292. + * This function adds a QH to either the non periodic or periodic schedule if
  79293. + * it is not already in the schedule. If the QH is already in the schedule, no
  79294. + * action is taken.
  79295. + *
  79296. + * @return 0 if successful, negative error code otherwise.
  79297. + */
  79298. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79299. +{
  79300. + int status = 0;
  79301. + gintmsk_data_t intr_mask = {.d32 = 0 };
  79302. +
  79303. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  79304. + /* QH already in a schedule. */
  79305. + return status;
  79306. + }
  79307. +
  79308. + /* Add the new QH to the appropriate schedule */
  79309. + if (dwc_qh_is_non_per(qh)) {
  79310. + /* Always start in the inactive schedule. */
  79311. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  79312. + &qh->qh_list_entry);
  79313. + g_np_count++;
  79314. + } else {
  79315. + status = schedule_periodic(hcd, qh);
  79316. + if ( !hcd->periodic_qh_count ) {
  79317. + intr_mask.b.sofintr = 1;
  79318. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  79319. + intr_mask.d32, intr_mask.d32);
  79320. + }
  79321. + hcd->periodic_qh_count++;
  79322. + }
  79323. +
  79324. + return status;
  79325. +}
  79326. +
  79327. +/**
  79328. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  79329. + *
  79330. + * @param hcd The HCD state structure for the DWC OTG controller.
  79331. + * @param qh QH for the periodic transfer.
  79332. + */
  79333. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79334. +{
  79335. + int i;
  79336. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  79337. +
  79338. + /* Update claimed usecs per (micro)frame. */
  79339. + hcd->periodic_usecs -= qh->usecs;
  79340. +
  79341. + if (!microframe_schedule) {
  79342. + /* Release the periodic channel reservation. */
  79343. + hcd->periodic_channels--;
  79344. + } else {
  79345. + for (i = 0; i < 8; i++) {
  79346. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  79347. + qh->frame_usecs[i] = 0;
  79348. + }
  79349. + }
  79350. +}
  79351. +
  79352. +/**
  79353. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  79354. + * not freed.
  79355. + *
  79356. + * @param hcd The HCD state structure.
  79357. + * @param qh QH to remove from schedule. */
  79358. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79359. +{
  79360. + gintmsk_data_t intr_mask = {.d32 = 0 };
  79361. +
  79362. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  79363. + /* QH is not in a schedule. */
  79364. + return;
  79365. + }
  79366. +
  79367. + if (dwc_qh_is_non_per(qh)) {
  79368. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  79369. + hcd->non_periodic_qh_ptr =
  79370. + hcd->non_periodic_qh_ptr->next;
  79371. + }
  79372. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  79373. +
  79374. + // If we've removed the last non-periodic entry then there are none left!
  79375. + g_np_count = g_np_sent;
  79376. + } else {
  79377. + deschedule_periodic(hcd, qh);
  79378. + hcd->periodic_qh_count--;
  79379. + if( !hcd->periodic_qh_count ) {
  79380. + intr_mask.b.sofintr = 1;
  79381. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  79382. + intr_mask.d32, 0);
  79383. + }
  79384. + }
  79385. +}
  79386. +
  79387. +/**
  79388. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  79389. + * non-periodic schedule. The QH is added to the inactive non-periodic
  79390. + * schedule if any QTDs are still attached to the QH.
  79391. + *
  79392. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  79393. + * there are any QTDs still attached to the QH, the QH is added to either the
  79394. + * periodic inactive schedule or the periodic ready schedule and its next
  79395. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  79396. + * the scheduled frame has been reached already. Otherwise it's placed in the
  79397. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  79398. + * completely removed from the periodic schedule.
  79399. + */
  79400. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  79401. + int sched_next_periodic_split)
  79402. +{
  79403. + if (dwc_qh_is_non_per(qh)) {
  79404. +
  79405. + dwc_otg_qh_t *qh_tmp;
  79406. + dwc_list_link_t *qh_list;
  79407. + DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
  79408. + {
  79409. + qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
  79410. + if(qh_tmp == qh)
  79411. + {
  79412. + /*
  79413. + * FIQ is being disabled because this one nevers gets a np_count increment
  79414. + * This is still not absolutely correct, but it should fix itself with
  79415. + * just an unnecessary extra interrupt
  79416. + */
  79417. + g_np_sent = g_np_count;
  79418. + }
  79419. + }
  79420. +
  79421. +
  79422. + dwc_otg_hcd_qh_remove(hcd, qh);
  79423. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  79424. + /* Add back to inactive non-periodic schedule. */
  79425. + dwc_otg_hcd_qh_add(hcd, qh);
  79426. + }
  79427. + } else {
  79428. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  79429. +
  79430. + if (qh->do_split) {
  79431. + /* Schedule the next continuing periodic split transfer */
  79432. + if (sched_next_periodic_split) {
  79433. +
  79434. + qh->sched_frame = frame_number;
  79435. +
  79436. + if (dwc_frame_num_le(frame_number,
  79437. + dwc_frame_num_inc
  79438. + (qh->start_split_frame,
  79439. + 1))) {
  79440. + /*
  79441. + * Allow one frame to elapse after start
  79442. + * split microframe before scheduling
  79443. + * complete split, but DONT if we are
  79444. + * doing the next start split in the
  79445. + * same frame for an ISOC out.
  79446. + */
  79447. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  79448. + (qh->ep_is_in != 0)) {
  79449. + qh->sched_frame =
  79450. + dwc_frame_num_inc(qh->sched_frame, 1);
  79451. + }
  79452. + }
  79453. + } else {
  79454. + qh->sched_frame =
  79455. + dwc_frame_num_inc(qh->start_split_frame,
  79456. + qh->interval);
  79457. + if (dwc_frame_num_le
  79458. + (qh->sched_frame, frame_number)) {
  79459. + qh->sched_frame = frame_number;
  79460. + }
  79461. + qh->sched_frame |= 0x7;
  79462. + qh->start_split_frame = qh->sched_frame;
  79463. + }
  79464. + } else {
  79465. + qh->sched_frame =
  79466. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  79467. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  79468. + qh->sched_frame = frame_number;
  79469. + }
  79470. + }
  79471. +
  79472. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  79473. + dwc_otg_hcd_qh_remove(hcd, qh);
  79474. + } else {
  79475. + /*
  79476. + * Remove from periodic_sched_queued and move to
  79477. + * appropriate queue.
  79478. + */
  79479. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  79480. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  79481. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  79482. + &qh->qh_list_entry);
  79483. + } else {
  79484. + if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
  79485. + {
  79486. + g_next_sched_frame = qh->sched_frame;
  79487. + }
  79488. +
  79489. + DWC_LIST_MOVE_HEAD
  79490. + (&hcd->periodic_sched_inactive,
  79491. + &qh->qh_list_entry);
  79492. + }
  79493. + }
  79494. + }
  79495. +}
  79496. +
  79497. +/**
  79498. + * This function allocates and initializes a QTD.
  79499. + *
  79500. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  79501. + * pointing to each other so each pair should have a unique correlation.
  79502. + * @param atomic_alloc Flag to do atomic alloc if needed
  79503. + *
  79504. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  79505. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  79506. +{
  79507. + dwc_otg_qtd_t *qtd;
  79508. +
  79509. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  79510. + if (qtd == NULL) {
  79511. + return NULL;
  79512. + }
  79513. +
  79514. + dwc_otg_hcd_qtd_init(qtd, urb);
  79515. + return qtd;
  79516. +}
  79517. +
  79518. +/**
  79519. + * Initializes a QTD structure.
  79520. + *
  79521. + * @param qtd The QTD to initialize.
  79522. + * @param urb The URB to use for initialization. */
  79523. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  79524. +{
  79525. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  79526. + qtd->urb = urb;
  79527. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  79528. + /*
  79529. + * The only time the QTD data toggle is used is on the data
  79530. + * phase of control transfers. This phase always starts with
  79531. + * DATA1.
  79532. + */
  79533. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  79534. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  79535. + }
  79536. +
  79537. + /* start split */
  79538. + qtd->complete_split = 0;
  79539. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  79540. + qtd->isoc_split_offset = 0;
  79541. + qtd->in_process = 0;
  79542. +
  79543. + /* Store the qtd ptr in the urb to reference what QTD. */
  79544. + urb->qtd = qtd;
  79545. + return;
  79546. +}
  79547. +
  79548. +/**
  79549. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  79550. + * QH to place the QTD into. If it does not find a QH, then it will create a
  79551. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  79552. + * is placed into the proper schedule based on its EP type.
  79553. + * HCD lock must be held and interrupts must be disabled on entry
  79554. + *
  79555. + * @param[in] qtd The QTD to add
  79556. + * @param[in] hcd The DWC HCD structure
  79557. + * @param[out] qh out parameter to return queue head
  79558. + * @param atomic_alloc Flag to do atomic alloc if needed
  79559. + *
  79560. + * @return 0 if successful, negative error code otherwise.
  79561. + */
  79562. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  79563. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  79564. +{
  79565. + int retval = 0;
  79566. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  79567. +
  79568. + /*
  79569. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  79570. + * doesn't exist.
  79571. + */
  79572. + if (*qh == NULL) {
  79573. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  79574. + if (*qh == NULL) {
  79575. + retval = -DWC_E_NO_MEMORY;
  79576. + goto done;
  79577. + }
  79578. + }
  79579. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  79580. + if (retval == 0) {
  79581. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  79582. + qtd_list_entry);
  79583. + qtd->qh = *qh;
  79584. + }
  79585. +done:
  79586. +
  79587. + return retval;
  79588. +}
  79589. +
  79590. +#endif /* DWC_DEVICE_ONLY */
  79591. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
  79592. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 1970-01-01 01:00:00.000000000 +0100
  79593. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 2014-03-13 12:46:39.520097997 +0100
  79594. @@ -0,0 +1,113 @@
  79595. +#include "dwc_otg_regs.h"
  79596. +#include "dwc_otg_dbg.h"
  79597. +
  79598. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
  79599. +{
  79600. + DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
  79601. + "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
  79602. + "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
  79603. + "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
  79604. + "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
  79605. + "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
  79606. + "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
  79607. + "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
  79608. + "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  79609. + function_name,
  79610. + gintsts.b.curmode,
  79611. + gintsts.b.modemismatch,
  79612. + gintsts.b.otgintr,
  79613. + gintsts.b.sofintr,
  79614. + gintsts.b.rxstsqlvl,
  79615. + gintsts.b.nptxfempty,
  79616. + gintsts.b.ginnakeff,
  79617. + gintsts.b.goutnakeff,
  79618. + gintsts.b.ulpickint,
  79619. + gintsts.b.i2cintr,
  79620. + gintsts.b.erlysuspend,
  79621. + gintsts.b.usbsuspend,
  79622. + gintsts.b.usbreset,
  79623. + gintsts.b.enumdone,
  79624. + gintsts.b.isooutdrop,
  79625. + gintsts.b.eopframe,
  79626. + gintsts.b.restoredone,
  79627. + gintsts.b.epmismatch,
  79628. + gintsts.b.inepint,
  79629. + gintsts.b.outepintr,
  79630. + gintsts.b.incomplisoin,
  79631. + gintsts.b.incomplisoout,
  79632. + gintsts.b.fetsusp,
  79633. + gintsts.b.resetdet,
  79634. + gintsts.b.portintr,
  79635. + gintsts.b.hcintr,
  79636. + gintsts.b.ptxfempty,
  79637. + gintsts.b.lpmtranrcvd,
  79638. + gintsts.b.conidstschng,
  79639. + gintsts.b.disconnect,
  79640. + gintsts.b.sessreqintr,
  79641. + gintsts.b.wkupintr);
  79642. + return;
  79643. +}
  79644. +
  79645. +void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
  79646. +{
  79647. + DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
  79648. + "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
  79649. + "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
  79650. + "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
  79651. + "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
  79652. + "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
  79653. + "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
  79654. + "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
  79655. + "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  79656. + function_name,
  79657. + gintmsk.b.modemismatch,
  79658. + gintmsk.b.otgintr,
  79659. + gintmsk.b.sofintr,
  79660. + gintmsk.b.rxstsqlvl,
  79661. + gintmsk.b.nptxfempty,
  79662. + gintmsk.b.ginnakeff,
  79663. + gintmsk.b.goutnakeff,
  79664. + gintmsk.b.ulpickint,
  79665. + gintmsk.b.i2cintr,
  79666. + gintmsk.b.erlysuspend,
  79667. + gintmsk.b.usbsuspend,
  79668. + gintmsk.b.usbreset,
  79669. + gintmsk.b.enumdone,
  79670. + gintmsk.b.isooutdrop,
  79671. + gintmsk.b.eopframe,
  79672. + gintmsk.b.restoredone,
  79673. + gintmsk.b.epmismatch,
  79674. + gintmsk.b.inepintr,
  79675. + gintmsk.b.outepintr,
  79676. + gintmsk.b.incomplisoin,
  79677. + gintmsk.b.incomplisoout,
  79678. + gintmsk.b.fetsusp,
  79679. + gintmsk.b.resetdet,
  79680. + gintmsk.b.portintr,
  79681. + gintmsk.b.hcintr,
  79682. + gintmsk.b.ptxfempty,
  79683. + gintmsk.b.lpmtranrcvd,
  79684. + gintmsk.b.conidstschng,
  79685. + gintmsk.b.disconnect,
  79686. + gintmsk.b.sessreqintr,
  79687. + gintmsk.b.wkupintr);
  79688. + return;
  79689. +}
  79690. +
  79691. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
  79692. +{
  79693. + DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
  79694. + "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
  79695. + "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
  79696. + "mvic: %1i\n",
  79697. + function_name,
  79698. + gotgint.b.sesenddet,
  79699. + gotgint.b.sesreqsucstschng,
  79700. + gotgint.b.hstnegsucstschng,
  79701. + gotgint.b.hstnegdet,
  79702. + gotgint.b.adevtoutchng,
  79703. + gotgint.b.debdone,
  79704. + gotgint.b.mvic);
  79705. +
  79706. + return;
  79707. +}
  79708. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
  79709. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 1970-01-01 01:00:00.000000000 +0100
  79710. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 2014-03-13 12:46:39.520097997 +0100
  79711. @@ -0,0 +1,48 @@
  79712. +#ifndef __DWC_OTG_MPHI_FIX_H__
  79713. +#define __DWC_OTG_MPHI_FIX_H__
  79714. +#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
  79715. +#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
  79716. +
  79717. +typedef struct {
  79718. + volatile void* base;
  79719. + volatile void* ctrl;
  79720. + volatile void* outdda;
  79721. + volatile void* outddb;
  79722. + volatile void* intstat;
  79723. +} mphi_regs_t;
  79724. +
  79725. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
  79726. +void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
  79727. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
  79728. +
  79729. +extern gintsts_data_t gintsts_saved;
  79730. +
  79731. +#ifdef DEBUG
  79732. +#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
  79733. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
  79734. +#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
  79735. +
  79736. +#else
  79737. +#define DWC_DBG_PRINT_CORE_INT(_arg_)
  79738. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
  79739. +#define DWC_DBG_PRINT_OTG_INT(_arg_)
  79740. +
  79741. +#endif
  79742. +
  79743. +typedef enum {
  79744. + FIQDBG_SCHED = (1 << 0),
  79745. + FIQDBG_INT = (1 << 1),
  79746. + FIQDBG_ERR = (1 << 2),
  79747. + FIQDBG_PORTHUB = (1 << 3),
  79748. +} FIQDBG_T;
  79749. +
  79750. +void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
  79751. +#ifdef FIQ_DEBUG
  79752. +#define fiq_print _fiq_print
  79753. +#else
  79754. +#define fiq_print(x, y, ...)
  79755. +#endif
  79756. +
  79757. +extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
  79758. +
  79759. +#endif
  79760. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  79761. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  79762. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-03-13 12:46:39.520097997 +0100
  79763. @@ -0,0 +1,188 @@
  79764. +#ifndef _DWC_OS_DEP_H_
  79765. +#define _DWC_OS_DEP_H_
  79766. +
  79767. +/**
  79768. + * @file
  79769. + *
  79770. + * This file contains OS dependent structures.
  79771. + *
  79772. + */
  79773. +
  79774. +#include <linux/kernel.h>
  79775. +#include <linux/module.h>
  79776. +#include <linux/moduleparam.h>
  79777. +#include <linux/init.h>
  79778. +#include <linux/device.h>
  79779. +#include <linux/errno.h>
  79780. +#include <linux/types.h>
  79781. +#include <linux/slab.h>
  79782. +#include <linux/list.h>
  79783. +#include <linux/interrupt.h>
  79784. +#include <linux/ctype.h>
  79785. +#include <linux/string.h>
  79786. +#include <linux/dma-mapping.h>
  79787. +#include <linux/jiffies.h>
  79788. +#include <linux/delay.h>
  79789. +#include <linux/timer.h>
  79790. +#include <linux/workqueue.h>
  79791. +#include <linux/stat.h>
  79792. +#include <linux/pci.h>
  79793. +
  79794. +#include <linux/version.h>
  79795. +
  79796. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  79797. +# include <linux/irq.h>
  79798. +#endif
  79799. +
  79800. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  79801. +# include <linux/usb/ch9.h>
  79802. +#else
  79803. +# include <linux/usb_ch9.h>
  79804. +#endif
  79805. +
  79806. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  79807. +# include <linux/usb/gadget.h>
  79808. +#else
  79809. +# include <linux/usb_gadget.h>
  79810. +#endif
  79811. +
  79812. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  79813. +# include <asm/irq.h>
  79814. +#endif
  79815. +
  79816. +#ifdef PCI_INTERFACE
  79817. +# include <asm/io.h>
  79818. +#endif
  79819. +
  79820. +#ifdef LM_INTERFACE
  79821. +# include <asm/unaligned.h>
  79822. +# include <asm/sizes.h>
  79823. +# include <asm/param.h>
  79824. +# include <asm/io.h>
  79825. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  79826. +# include <asm/arch/hardware.h>
  79827. +# include <asm/arch/lm.h>
  79828. +# include <asm/arch/irqs.h>
  79829. +# include <asm/arch/regs-irq.h>
  79830. +# else
  79831. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  79832. + here we assume that the machine architecture provides definitions
  79833. + in its own header
  79834. +*/
  79835. +# include <mach/lm.h>
  79836. +# include <mach/hardware.h>
  79837. +# endif
  79838. +#endif
  79839. +
  79840. +#ifdef PLATFORM_INTERFACE
  79841. +#include <linux/platform_device.h>
  79842. +#include <asm/mach/map.h>
  79843. +#endif
  79844. +
  79845. +/** The OS page size */
  79846. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  79847. +
  79848. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  79849. +typedef int gfp_t;
  79850. +#endif
  79851. +
  79852. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  79853. +# define IRQF_SHARED SA_SHIRQ
  79854. +#endif
  79855. +
  79856. +typedef struct os_dependent {
  79857. + /** Base address returned from ioremap() */
  79858. + void *base;
  79859. +
  79860. + /** Register offset for Diagnostic API */
  79861. + uint32_t reg_offset;
  79862. +
  79863. + /** Base address for MPHI peripheral */
  79864. + void *mphi_base;
  79865. +
  79866. +#ifdef LM_INTERFACE
  79867. + struct lm_device *lmdev;
  79868. +#elif defined(PCI_INTERFACE)
  79869. + struct pci_dev *pcidev;
  79870. +
  79871. + /** Start address of a PCI region */
  79872. + resource_size_t rsrc_start;
  79873. +
  79874. + /** Length address of a PCI region */
  79875. + resource_size_t rsrc_len;
  79876. +#elif defined(PLATFORM_INTERFACE)
  79877. + struct platform_device *platformdev;
  79878. +#endif
  79879. +
  79880. +} os_dependent_t;
  79881. +
  79882. +#ifdef __cplusplus
  79883. +}
  79884. +#endif
  79885. +
  79886. +
  79887. +
  79888. +/* Type for the our device on the chosen bus */
  79889. +#if defined(LM_INTERFACE)
  79890. +typedef struct lm_device dwc_bus_dev_t;
  79891. +#elif defined(PCI_INTERFACE)
  79892. +typedef struct pci_dev dwc_bus_dev_t;
  79893. +#elif defined(PLATFORM_INTERFACE)
  79894. +typedef struct platform_device dwc_bus_dev_t;
  79895. +#endif
  79896. +
  79897. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  79898. +#if defined(LM_INTERFACE)
  79899. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  79900. +#elif defined(PCI_INTERFACE)
  79901. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  79902. +#elif defined(PLATFORM_INTERFACE)
  79903. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  79904. +#endif
  79905. +
  79906. +/**
  79907. + * Helper macro returning the otg_device structure of a given struct device
  79908. + *
  79909. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  79910. + */
  79911. +#ifdef LM_INTERFACE
  79912. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  79913. + struct lm_device *lm_dev = \
  79914. + container_of(_dev, struct lm_device, dev); \
  79915. + _var = lm_get_drvdata(lm_dev); \
  79916. + } while (0)
  79917. +
  79918. +#elif defined(PCI_INTERFACE)
  79919. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  79920. + _var = dev_get_drvdata(_dev); \
  79921. + } while (0)
  79922. +
  79923. +#elif defined(PLATFORM_INTERFACE)
  79924. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  79925. + struct platform_device *platform_dev = \
  79926. + container_of(_dev, struct platform_device, dev); \
  79927. + _var = platform_get_drvdata(platform_dev); \
  79928. + } while (0)
  79929. +#endif
  79930. +
  79931. +
  79932. +/**
  79933. + * Helper macro returning the struct dev of the given struct os_dependent
  79934. + *
  79935. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  79936. + */
  79937. +#ifdef LM_INTERFACE
  79938. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79939. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  79940. +#elif defined(PCI_INTERFACE)
  79941. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79942. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  79943. +#elif defined(PLATFORM_INTERFACE)
  79944. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79945. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  79946. +#endif
  79947. +
  79948. +
  79949. +
  79950. +
  79951. +#endif /* _DWC_OS_DEP_H_ */
  79952. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  79953. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  79954. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-03-13 12:46:39.520097997 +0100
  79955. @@ -0,0 +1,2708 @@
  79956. +/* ==========================================================================
  79957. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  79958. + * $Revision: #101 $
  79959. + * $Date: 2012/08/10 $
  79960. + * $Change: 2047372 $
  79961. + *
  79962. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79963. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79964. + * otherwise expressly agreed to in writing between Synopsys and you.
  79965. + *
  79966. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79967. + * any End User Software License Agreement or Agreement for Licensed Product
  79968. + * with Synopsys or any supplement thereto. You are permitted to use and
  79969. + * redistribute this Software in source and binary forms, with or without
  79970. + * modification, provided that redistributions of source code must retain this
  79971. + * notice. You may not view, use, disclose, copy or distribute this file or
  79972. + * any information contained herein except pursuant to this license grant from
  79973. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79974. + * below, then you are not authorized to use the Software.
  79975. + *
  79976. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79977. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79978. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79979. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79980. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79981. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79982. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79983. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79984. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79985. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79986. + * DAMAGE.
  79987. + * ========================================================================== */
  79988. +#ifndef DWC_HOST_ONLY
  79989. +
  79990. +/** @file
  79991. + * This file implements PCD Core. All code in this file is portable and doesn't
  79992. + * use any OS specific functions.
  79993. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  79994. + * header file, which can be used to implement OS specific PCD interface.
  79995. + *
  79996. + * An important function of the PCD is managing interrupts generated
  79997. + * by the DWC_otg controller. The implementation of the DWC_otg device
  79998. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  79999. + *
  80000. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  80001. + * @todo Does it work when the request size is greater than DEPTSIZ
  80002. + * transfer size
  80003. + *
  80004. + */
  80005. +
  80006. +#include "dwc_otg_pcd.h"
  80007. +
  80008. +#ifdef DWC_UTE_CFI
  80009. +#include "dwc_otg_cfi.h"
  80010. +
  80011. +extern int init_cfi(cfiobject_t * cfiobj);
  80012. +#endif
  80013. +
  80014. +/**
  80015. + * Choose endpoint from ep arrays using usb_ep structure.
  80016. + */
  80017. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  80018. +{
  80019. + int i;
  80020. + if (pcd->ep0.priv == handle) {
  80021. + return &pcd->ep0;
  80022. + }
  80023. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  80024. + if (pcd->in_ep[i].priv == handle)
  80025. + return &pcd->in_ep[i];
  80026. + if (pcd->out_ep[i].priv == handle)
  80027. + return &pcd->out_ep[i];
  80028. + }
  80029. +
  80030. + return NULL;
  80031. +}
  80032. +
  80033. +/**
  80034. + * This function completes a request. It call's the request call back.
  80035. + */
  80036. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  80037. + int32_t status)
  80038. +{
  80039. + unsigned stopped = ep->stopped;
  80040. +
  80041. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  80042. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  80043. +
  80044. + /* don't modify queue heads during completion callback */
  80045. + ep->stopped = 1;
  80046. + /* spin_unlock/spin_lock now done in fops->complete() */
  80047. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  80048. + req->actual);
  80049. +
  80050. + if (ep->pcd->request_pending > 0) {
  80051. + --ep->pcd->request_pending;
  80052. + }
  80053. +
  80054. + ep->stopped = stopped;
  80055. + DWC_FREE(req);
  80056. +}
  80057. +
  80058. +/**
  80059. + * This function terminates all the requsts in the EP request queue.
  80060. + */
  80061. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  80062. +{
  80063. + dwc_otg_pcd_request_t *req;
  80064. +
  80065. + ep->stopped = 1;
  80066. +
  80067. + /* called with irqs blocked?? */
  80068. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80069. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  80070. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  80071. + }
  80072. +}
  80073. +
  80074. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  80075. + const struct dwc_otg_pcd_function_ops *fops)
  80076. +{
  80077. + pcd->fops = fops;
  80078. +}
  80079. +
  80080. +/**
  80081. + * PCD Callback function for initializing the PCD when switching to
  80082. + * device mode.
  80083. + *
  80084. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  80085. + */
  80086. +static int32_t dwc_otg_pcd_start_cb(void *p)
  80087. +{
  80088. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  80089. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80090. +
  80091. + /*
  80092. + * Initialized the Core for Device mode.
  80093. + */
  80094. + if (dwc_otg_is_device_mode(core_if)) {
  80095. + dwc_otg_core_dev_init(core_if);
  80096. + /* Set core_if's lock pointer to the pcd->lock */
  80097. + core_if->lock = pcd->lock;
  80098. + }
  80099. + return 1;
  80100. +}
  80101. +
  80102. +/** CFI-specific buffer allocation function for EP */
  80103. +#ifdef DWC_UTE_CFI
  80104. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  80105. + size_t buflen, int flags)
  80106. +{
  80107. + dwc_otg_pcd_ep_t *ep;
  80108. + ep = get_ep_from_handle(pcd, pep);
  80109. + if (!ep) {
  80110. + DWC_WARN("bad ep\n");
  80111. + return -DWC_E_INVALID;
  80112. + }
  80113. +
  80114. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  80115. + flags);
  80116. +}
  80117. +#else
  80118. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  80119. + size_t buflen, int flags);
  80120. +#endif
  80121. +
  80122. +/**
  80123. + * PCD Callback function for notifying the PCD when resuming from
  80124. + * suspend.
  80125. + *
  80126. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  80127. + */
  80128. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  80129. +{
  80130. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  80131. +
  80132. + if (pcd->fops->resume) {
  80133. + pcd->fops->resume(pcd);
  80134. + }
  80135. +
  80136. + /* Stop the SRP timeout timer. */
  80137. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  80138. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  80139. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  80140. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  80141. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  80142. + }
  80143. + }
  80144. + return 1;
  80145. +}
  80146. +
  80147. +/**
  80148. + * PCD Callback function for notifying the PCD device is suspended.
  80149. + *
  80150. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  80151. + */
  80152. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  80153. +{
  80154. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  80155. +
  80156. + if (pcd->fops->suspend) {
  80157. + DWC_SPINUNLOCK(pcd->lock);
  80158. + pcd->fops->suspend(pcd);
  80159. + DWC_SPINLOCK(pcd->lock);
  80160. + }
  80161. +
  80162. + return 1;
  80163. +}
  80164. +
  80165. +/**
  80166. + * PCD Callback function for stopping the PCD when switching to Host
  80167. + * mode.
  80168. + *
  80169. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  80170. + */
  80171. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  80172. +{
  80173. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  80174. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  80175. +
  80176. + dwc_otg_pcd_stop(pcd);
  80177. + return 1;
  80178. +}
  80179. +
  80180. +/**
  80181. + * PCD Callback structure for handling mode switching.
  80182. + */
  80183. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  80184. + .start = dwc_otg_pcd_start_cb,
  80185. + .stop = dwc_otg_pcd_stop_cb,
  80186. + .suspend = dwc_otg_pcd_suspend_cb,
  80187. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  80188. + .p = 0, /* Set at registration */
  80189. +};
  80190. +
  80191. +/**
  80192. + * This function allocates a DMA Descriptor chain for the Endpoint
  80193. + * buffer to be used for a transfer to/from the specified endpoint.
  80194. + */
  80195. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  80196. + uint32_t count)
  80197. +{
  80198. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  80199. + dma_desc_addr);
  80200. +}
  80201. +
  80202. +/**
  80203. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  80204. + */
  80205. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  80206. + uint32_t dma_desc_addr, uint32_t count)
  80207. +{
  80208. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  80209. + dma_desc_addr);
  80210. +}
  80211. +
  80212. +#ifdef DWC_EN_ISOC
  80213. +
  80214. +/**
  80215. + * This function initializes a descriptor chain for Isochronous transfer
  80216. + *
  80217. + * @param core_if Programming view of DWC_otg controller.
  80218. + * @param dwc_ep The EP to start the transfer on.
  80219. + *
  80220. + */
  80221. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  80222. + dwc_ep_t * dwc_ep)
  80223. +{
  80224. +
  80225. + dsts_data_t dsts = {.d32 = 0 };
  80226. + depctl_data_t depctl = {.d32 = 0 };
  80227. + volatile uint32_t *addr;
  80228. + int i, j;
  80229. + uint32_t len;
  80230. +
  80231. + if (dwc_ep->is_in)
  80232. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  80233. + else
  80234. + dwc_ep->desc_cnt =
  80235. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  80236. + dwc_ep->bInterval;
  80237. +
  80238. + /** Allocate descriptors for double buffering */
  80239. + dwc_ep->iso_desc_addr =
  80240. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  80241. + dwc_ep->desc_cnt * 2);
  80242. + if (dwc_ep->desc_addr) {
  80243. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  80244. + return;
  80245. + }
  80246. +
  80247. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80248. +
  80249. + /** ISO OUT EP */
  80250. + if (dwc_ep->is_in == 0) {
  80251. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  80252. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  80253. + dma_addr_t dma_ad;
  80254. + uint32_t data_per_desc;
  80255. + dwc_otg_dev_out_ep_regs_t *out_regs =
  80256. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  80257. + int offset;
  80258. +
  80259. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  80260. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  80261. +
  80262. + /** Buffer 0 descriptors setup */
  80263. + dma_ad = dwc_ep->dma_addr0;
  80264. +
  80265. + sts.b_iso_out.bs = BS_HOST_READY;
  80266. + sts.b_iso_out.rxsts = 0;
  80267. + sts.b_iso_out.l = 0;
  80268. + sts.b_iso_out.sp = 0;
  80269. + sts.b_iso_out.ioc = 0;
  80270. + sts.b_iso_out.pid = 0;
  80271. + sts.b_iso_out.framenum = 0;
  80272. +
  80273. + offset = 0;
  80274. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  80275. + i += dwc_ep->pkt_per_frm) {
  80276. +
  80277. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  80278. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  80279. + if (len > dwc_ep->data_per_frame)
  80280. + data_per_desc =
  80281. + dwc_ep->data_per_frame -
  80282. + j * dwc_ep->maxpacket;
  80283. + else
  80284. + data_per_desc = dwc_ep->maxpacket;
  80285. + len = data_per_desc % 4;
  80286. + if (len)
  80287. + data_per_desc += 4 - len;
  80288. +
  80289. + sts.b_iso_out.rxbytes = data_per_desc;
  80290. + dma_desc->buf = dma_ad;
  80291. + dma_desc->status.d32 = sts.d32;
  80292. +
  80293. + offset += data_per_desc;
  80294. + dma_desc++;
  80295. + dma_ad += data_per_desc;
  80296. + }
  80297. + }
  80298. +
  80299. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  80300. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  80301. + if (len > dwc_ep->data_per_frame)
  80302. + data_per_desc =
  80303. + dwc_ep->data_per_frame -
  80304. + j * dwc_ep->maxpacket;
  80305. + else
  80306. + data_per_desc = dwc_ep->maxpacket;
  80307. + len = data_per_desc % 4;
  80308. + if (len)
  80309. + data_per_desc += 4 - len;
  80310. + sts.b_iso_out.rxbytes = data_per_desc;
  80311. + dma_desc->buf = dma_ad;
  80312. + dma_desc->status.d32 = sts.d32;
  80313. +
  80314. + offset += data_per_desc;
  80315. + dma_desc++;
  80316. + dma_ad += data_per_desc;
  80317. + }
  80318. +
  80319. + sts.b_iso_out.ioc = 1;
  80320. + len = (j + 1) * dwc_ep->maxpacket;
  80321. + if (len > dwc_ep->data_per_frame)
  80322. + data_per_desc =
  80323. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  80324. + else
  80325. + data_per_desc = dwc_ep->maxpacket;
  80326. + len = data_per_desc % 4;
  80327. + if (len)
  80328. + data_per_desc += 4 - len;
  80329. + sts.b_iso_out.rxbytes = data_per_desc;
  80330. +
  80331. + dma_desc->buf = dma_ad;
  80332. + dma_desc->status.d32 = sts.d32;
  80333. + dma_desc++;
  80334. +
  80335. + /** Buffer 1 descriptors setup */
  80336. + sts.b_iso_out.ioc = 0;
  80337. + dma_ad = dwc_ep->dma_addr1;
  80338. +
  80339. + offset = 0;
  80340. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  80341. + i += dwc_ep->pkt_per_frm) {
  80342. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  80343. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  80344. + if (len > dwc_ep->data_per_frame)
  80345. + data_per_desc =
  80346. + dwc_ep->data_per_frame -
  80347. + j * dwc_ep->maxpacket;
  80348. + else
  80349. + data_per_desc = dwc_ep->maxpacket;
  80350. + len = data_per_desc % 4;
  80351. + if (len)
  80352. + data_per_desc += 4 - len;
  80353. +
  80354. + data_per_desc =
  80355. + sts.b_iso_out.rxbytes = data_per_desc;
  80356. + dma_desc->buf = dma_ad;
  80357. + dma_desc->status.d32 = sts.d32;
  80358. +
  80359. + offset += data_per_desc;
  80360. + dma_desc++;
  80361. + dma_ad += data_per_desc;
  80362. + }
  80363. + }
  80364. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  80365. + data_per_desc =
  80366. + ((j + 1) * dwc_ep->maxpacket >
  80367. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  80368. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  80369. + data_per_desc +=
  80370. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  80371. + sts.b_iso_out.rxbytes = data_per_desc;
  80372. + dma_desc->buf = dma_ad;
  80373. + dma_desc->status.d32 = sts.d32;
  80374. +
  80375. + offset += data_per_desc;
  80376. + dma_desc++;
  80377. + dma_ad += data_per_desc;
  80378. + }
  80379. +
  80380. + sts.b_iso_out.ioc = 1;
  80381. + sts.b_iso_out.l = 1;
  80382. + data_per_desc =
  80383. + ((j + 1) * dwc_ep->maxpacket >
  80384. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  80385. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  80386. + data_per_desc +=
  80387. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  80388. + sts.b_iso_out.rxbytes = data_per_desc;
  80389. +
  80390. + dma_desc->buf = dma_ad;
  80391. + dma_desc->status.d32 = sts.d32;
  80392. +
  80393. + dwc_ep->next_frame = 0;
  80394. +
  80395. + /** Write dma_ad into DOEPDMA register */
  80396. + DWC_WRITE_REG32(&(out_regs->doepdma),
  80397. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  80398. +
  80399. + }
  80400. + /** ISO IN EP */
  80401. + else {
  80402. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  80403. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  80404. + dma_addr_t dma_ad;
  80405. + dwc_otg_dev_in_ep_regs_t *in_regs =
  80406. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  80407. + unsigned int frmnumber;
  80408. + fifosize_data_t txfifosize, rxfifosize;
  80409. +
  80410. + txfifosize.d32 =
  80411. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  80412. + dtxfsts);
  80413. + rxfifosize.d32 =
  80414. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  80415. +
  80416. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  80417. +
  80418. + dma_ad = dwc_ep->dma_addr0;
  80419. +
  80420. + dsts.d32 =
  80421. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80422. +
  80423. + sts.b_iso_in.bs = BS_HOST_READY;
  80424. + sts.b_iso_in.txsts = 0;
  80425. + sts.b_iso_in.sp =
  80426. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  80427. + sts.b_iso_in.ioc = 0;
  80428. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  80429. +
  80430. + frmnumber = dwc_ep->next_frame;
  80431. +
  80432. + sts.b_iso_in.framenum = frmnumber;
  80433. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  80434. + sts.b_iso_in.l = 0;
  80435. +
  80436. + /** Buffer 0 descriptors setup */
  80437. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  80438. + dma_desc->buf = dma_ad;
  80439. + dma_desc->status.d32 = sts.d32;
  80440. + dma_desc++;
  80441. +
  80442. + dma_ad += dwc_ep->data_per_frame;
  80443. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  80444. + }
  80445. +
  80446. + sts.b_iso_in.ioc = 1;
  80447. + dma_desc->buf = dma_ad;
  80448. + dma_desc->status.d32 = sts.d32;
  80449. + ++dma_desc;
  80450. +
  80451. + /** Buffer 1 descriptors setup */
  80452. + sts.b_iso_in.ioc = 0;
  80453. + dma_ad = dwc_ep->dma_addr1;
  80454. +
  80455. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  80456. + i += dwc_ep->pkt_per_frm) {
  80457. + dma_desc->buf = dma_ad;
  80458. + dma_desc->status.d32 = sts.d32;
  80459. + dma_desc++;
  80460. +
  80461. + dma_ad += dwc_ep->data_per_frame;
  80462. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  80463. +
  80464. + sts.b_iso_in.ioc = 0;
  80465. + }
  80466. + sts.b_iso_in.ioc = 1;
  80467. + sts.b_iso_in.l = 1;
  80468. +
  80469. + dma_desc->buf = dma_ad;
  80470. + dma_desc->status.d32 = sts.d32;
  80471. +
  80472. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  80473. +
  80474. + /** Write dma_ad into diepdma register */
  80475. + DWC_WRITE_REG32(&(in_regs->diepdma),
  80476. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  80477. + }
  80478. + /** Enable endpoint, clear nak */
  80479. + depctl.d32 = 0;
  80480. + depctl.b.epena = 1;
  80481. + depctl.b.usbactep = 1;
  80482. + depctl.b.cnak = 1;
  80483. +
  80484. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  80485. + depctl.d32 = DWC_READ_REG32(addr);
  80486. +}
  80487. +
  80488. +/**
  80489. + * This function initializes a descriptor chain for Isochronous transfer
  80490. + *
  80491. + * @param core_if Programming view of DWC_otg controller.
  80492. + * @param ep The EP to start the transfer on.
  80493. + *
  80494. + */
  80495. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  80496. + dwc_ep_t * ep)
  80497. +{
  80498. + depctl_data_t depctl = {.d32 = 0 };
  80499. + volatile uint32_t *addr;
  80500. +
  80501. + if (ep->is_in) {
  80502. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  80503. + } else {
  80504. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  80505. + }
  80506. +
  80507. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  80508. + return;
  80509. + } else {
  80510. + deptsiz_data_t deptsiz = {.d32 = 0 };
  80511. +
  80512. + ep->xfer_len =
  80513. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  80514. + ep->pkt_cnt =
  80515. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  80516. + ep->xfer_count = 0;
  80517. + ep->xfer_buff =
  80518. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  80519. + ep->dma_addr =
  80520. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  80521. +
  80522. + if (ep->is_in) {
  80523. + /* Program the transfer size and packet count
  80524. + * as follows: xfersize = N * maxpacket +
  80525. + * short_packet pktcnt = N + (short_packet
  80526. + * exist ? 1 : 0)
  80527. + */
  80528. + deptsiz.b.mc = ep->pkt_per_frm;
  80529. + deptsiz.b.xfersize = ep->xfer_len;
  80530. + deptsiz.b.pktcnt =
  80531. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  80532. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  80533. + dieptsiz, deptsiz.d32);
  80534. +
  80535. + /* Write the DMA register */
  80536. + DWC_WRITE_REG32(&
  80537. + (core_if->dev_if->in_ep_regs[ep->num]->
  80538. + diepdma), (uint32_t) ep->dma_addr);
  80539. +
  80540. + } else {
  80541. + deptsiz.b.pktcnt =
  80542. + (ep->xfer_len + (ep->maxpacket - 1)) /
  80543. + ep->maxpacket;
  80544. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  80545. +
  80546. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  80547. + doeptsiz, deptsiz.d32);
  80548. +
  80549. + /* Write the DMA register */
  80550. + DWC_WRITE_REG32(&
  80551. + (core_if->dev_if->out_ep_regs[ep->num]->
  80552. + doepdma), (uint32_t) ep->dma_addr);
  80553. +
  80554. + }
  80555. + /** Enable endpoint, clear nak */
  80556. + depctl.d32 = 0;
  80557. + depctl.b.epena = 1;
  80558. + depctl.b.cnak = 1;
  80559. +
  80560. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  80561. + }
  80562. +}
  80563. +
  80564. +/**
  80565. + * This function does the setup for a data transfer for an EP and
  80566. + * starts the transfer. For an IN transfer, the packets will be
  80567. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  80568. + * the packets are unloaded from the Rx FIFO in the ISR.
  80569. + *
  80570. + * @param core_if Programming view of DWC_otg controller.
  80571. + * @param ep The EP to start the transfer on.
  80572. + */
  80573. +
  80574. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  80575. + dwc_ep_t * ep)
  80576. +{
  80577. + if (core_if->dma_enable) {
  80578. + if (core_if->dma_desc_enable) {
  80579. + if (ep->is_in) {
  80580. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  80581. + } else {
  80582. + ep->desc_cnt = ep->pkt_cnt;
  80583. + }
  80584. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  80585. + } else {
  80586. + if (core_if->pti_enh_enable) {
  80587. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  80588. + } else {
  80589. + ep->cur_pkt_addr =
  80590. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  80591. + xfer_buff0;
  80592. + ep->cur_pkt_dma_addr =
  80593. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  80594. + dma_addr0;
  80595. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  80596. + }
  80597. + }
  80598. + } else {
  80599. + ep->cur_pkt_addr =
  80600. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  80601. + ep->cur_pkt_dma_addr =
  80602. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  80603. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  80604. + }
  80605. +}
  80606. +
  80607. +/**
  80608. + * This function stops transfer for an EP and
  80609. + * resets the ep's variables.
  80610. + *
  80611. + * @param core_if Programming view of DWC_otg controller.
  80612. + * @param ep The EP to start the transfer on.
  80613. + */
  80614. +
  80615. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  80616. +{
  80617. + depctl_data_t depctl = {.d32 = 0 };
  80618. + volatile uint32_t *addr;
  80619. +
  80620. + if (ep->is_in == 1) {
  80621. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  80622. + } else {
  80623. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  80624. + }
  80625. +
  80626. + /* disable the ep */
  80627. + depctl.d32 = DWC_READ_REG32(addr);
  80628. +
  80629. + depctl.b.epdis = 1;
  80630. + depctl.b.snak = 1;
  80631. +
  80632. + DWC_WRITE_REG32(addr, depctl.d32);
  80633. +
  80634. + if (core_if->dma_desc_enable &&
  80635. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  80636. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  80637. + ep->iso_dma_desc_addr,
  80638. + ep->desc_cnt * 2);
  80639. + }
  80640. +
  80641. + /* reset varibales */
  80642. + ep->dma_addr0 = 0;
  80643. + ep->dma_addr1 = 0;
  80644. + ep->xfer_buff0 = 0;
  80645. + ep->xfer_buff1 = 0;
  80646. + ep->data_per_frame = 0;
  80647. + ep->data_pattern_frame = 0;
  80648. + ep->sync_frame = 0;
  80649. + ep->buf_proc_intrvl = 0;
  80650. + ep->bInterval = 0;
  80651. + ep->proc_buf_num = 0;
  80652. + ep->pkt_per_frm = 0;
  80653. + ep->pkt_per_frm = 0;
  80654. + ep->desc_cnt = 0;
  80655. + ep->iso_desc_addr = 0;
  80656. + ep->iso_dma_desc_addr = 0;
  80657. +}
  80658. +
  80659. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  80660. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  80661. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  80662. + int data_per_frame, int start_frame,
  80663. + int buf_proc_intrvl, void *req_handle,
  80664. + int atomic_alloc)
  80665. +{
  80666. + dwc_otg_pcd_ep_t *ep;
  80667. + dwc_irqflags_t flags = 0;
  80668. + dwc_ep_t *dwc_ep;
  80669. + int32_t frm_data;
  80670. + dsts_data_t dsts;
  80671. + dwc_otg_core_if_t *core_if;
  80672. +
  80673. + ep = get_ep_from_handle(pcd, ep_handle);
  80674. +
  80675. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  80676. + DWC_WARN("bad ep\n");
  80677. + return -DWC_E_INVALID;
  80678. + }
  80679. +
  80680. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80681. + core_if = GET_CORE_IF(pcd);
  80682. + dwc_ep = &ep->dwc_ep;
  80683. +
  80684. + if (ep->iso_req_handle) {
  80685. + DWC_WARN("ISO request in progress\n");
  80686. + }
  80687. +
  80688. + dwc_ep->dma_addr0 = dma0;
  80689. + dwc_ep->dma_addr1 = dma1;
  80690. +
  80691. + dwc_ep->xfer_buff0 = buf0;
  80692. + dwc_ep->xfer_buff1 = buf1;
  80693. +
  80694. + dwc_ep->data_per_frame = data_per_frame;
  80695. +
  80696. + /** @todo - pattern data support is to be implemented in the future */
  80697. + dwc_ep->data_pattern_frame = dp_frame;
  80698. + dwc_ep->sync_frame = sync_frame;
  80699. +
  80700. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  80701. +
  80702. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  80703. +
  80704. + dwc_ep->proc_buf_num = 0;
  80705. +
  80706. + dwc_ep->pkt_per_frm = 0;
  80707. + frm_data = ep->dwc_ep.data_per_frame;
  80708. + while (frm_data > 0) {
  80709. + dwc_ep->pkt_per_frm++;
  80710. + frm_data -= ep->dwc_ep.maxpacket;
  80711. + }
  80712. +
  80713. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80714. +
  80715. + if (start_frame == -1) {
  80716. + dwc_ep->next_frame = dsts.b.soffn + 1;
  80717. + if (dwc_ep->bInterval != 1) {
  80718. + dwc_ep->next_frame =
  80719. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  80720. + dwc_ep->next_frame %
  80721. + dwc_ep->bInterval);
  80722. + }
  80723. + } else {
  80724. + dwc_ep->next_frame = start_frame;
  80725. + }
  80726. +
  80727. + if (!core_if->pti_enh_enable) {
  80728. + dwc_ep->pkt_cnt =
  80729. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  80730. + dwc_ep->bInterval;
  80731. + } else {
  80732. + dwc_ep->pkt_cnt =
  80733. + (dwc_ep->data_per_frame *
  80734. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  80735. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  80736. + }
  80737. +
  80738. + if (core_if->dma_desc_enable) {
  80739. + dwc_ep->desc_cnt =
  80740. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  80741. + dwc_ep->bInterval;
  80742. + }
  80743. +
  80744. + if (atomic_alloc) {
  80745. + dwc_ep->pkt_info =
  80746. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  80747. + } else {
  80748. + dwc_ep->pkt_info =
  80749. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  80750. + }
  80751. + if (!dwc_ep->pkt_info) {
  80752. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80753. + return -DWC_E_NO_MEMORY;
  80754. + }
  80755. + if (core_if->pti_enh_enable) {
  80756. + dwc_memset(dwc_ep->pkt_info, 0,
  80757. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  80758. + }
  80759. +
  80760. + dwc_ep->cur_pkt = 0;
  80761. + ep->iso_req_handle = req_handle;
  80762. +
  80763. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80764. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  80765. + return 0;
  80766. +}
  80767. +
  80768. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  80769. + void *req_handle)
  80770. +{
  80771. + dwc_irqflags_t flags = 0;
  80772. + dwc_otg_pcd_ep_t *ep;
  80773. + dwc_ep_t *dwc_ep;
  80774. +
  80775. + ep = get_ep_from_handle(pcd, ep_handle);
  80776. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  80777. + DWC_WARN("bad ep\n");
  80778. + return -DWC_E_INVALID;
  80779. + }
  80780. + dwc_ep = &ep->dwc_ep;
  80781. +
  80782. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  80783. +
  80784. + DWC_FREE(dwc_ep->pkt_info);
  80785. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80786. + if (ep->iso_req_handle != req_handle) {
  80787. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80788. + return -DWC_E_INVALID;
  80789. + }
  80790. +
  80791. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80792. +
  80793. + ep->iso_req_handle = 0;
  80794. + return 0;
  80795. +}
  80796. +
  80797. +/**
  80798. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  80799. + * for Isochronous EPs
  80800. + *
  80801. + * - Every time a sync period completes this function is called to
  80802. + * perform data exchange between PCD and gadget
  80803. + */
  80804. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  80805. + void *req_handle)
  80806. +{
  80807. + int i;
  80808. + dwc_ep_t *dwc_ep;
  80809. +
  80810. + dwc_ep = &ep->dwc_ep;
  80811. +
  80812. + DWC_SPINUNLOCK(ep->pcd->lock);
  80813. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  80814. + dwc_ep->proc_buf_num ^ 0x1);
  80815. + DWC_SPINLOCK(ep->pcd->lock);
  80816. +
  80817. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  80818. + dwc_ep->pkt_info[i].status = 0;
  80819. + dwc_ep->pkt_info[i].offset = 0;
  80820. + dwc_ep->pkt_info[i].length = 0;
  80821. + }
  80822. +}
  80823. +
  80824. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  80825. + void *iso_req_handle)
  80826. +{
  80827. + dwc_otg_pcd_ep_t *ep;
  80828. + dwc_ep_t *dwc_ep;
  80829. +
  80830. + ep = get_ep_from_handle(pcd, ep_handle);
  80831. + if (!ep->desc || ep->dwc_ep.num == 0) {
  80832. + DWC_WARN("bad ep\n");
  80833. + return -DWC_E_INVALID;
  80834. + }
  80835. + dwc_ep = &ep->dwc_ep;
  80836. +
  80837. + return dwc_ep->pkt_cnt;
  80838. +}
  80839. +
  80840. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  80841. + void *iso_req_handle, int packet,
  80842. + int *status, int *actual, int *offset)
  80843. +{
  80844. + dwc_otg_pcd_ep_t *ep;
  80845. + dwc_ep_t *dwc_ep;
  80846. +
  80847. + ep = get_ep_from_handle(pcd, ep_handle);
  80848. + if (!ep)
  80849. + DWC_WARN("bad ep\n");
  80850. +
  80851. + dwc_ep = &ep->dwc_ep;
  80852. +
  80853. + *status = dwc_ep->pkt_info[packet].status;
  80854. + *actual = dwc_ep->pkt_info[packet].length;
  80855. + *offset = dwc_ep->pkt_info[packet].offset;
  80856. +}
  80857. +
  80858. +#endif /* DWC_EN_ISOC */
  80859. +
  80860. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  80861. + uint32_t is_in, uint32_t ep_num)
  80862. +{
  80863. + /* Init EP structure */
  80864. + pcd_ep->desc = 0;
  80865. + pcd_ep->pcd = pcd;
  80866. + pcd_ep->stopped = 1;
  80867. + pcd_ep->queue_sof = 0;
  80868. +
  80869. + /* Init DWC ep structure */
  80870. + pcd_ep->dwc_ep.is_in = is_in;
  80871. + pcd_ep->dwc_ep.num = ep_num;
  80872. + pcd_ep->dwc_ep.active = 0;
  80873. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  80874. + /* Control until ep is actvated */
  80875. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  80876. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  80877. + pcd_ep->dwc_ep.dma_addr = 0;
  80878. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  80879. + pcd_ep->dwc_ep.xfer_buff = 0;
  80880. + pcd_ep->dwc_ep.xfer_len = 0;
  80881. + pcd_ep->dwc_ep.xfer_count = 0;
  80882. + pcd_ep->dwc_ep.sent_zlp = 0;
  80883. + pcd_ep->dwc_ep.total_len = 0;
  80884. + pcd_ep->dwc_ep.desc_addr = 0;
  80885. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  80886. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  80887. +}
  80888. +
  80889. +/**
  80890. + * Initialize ep's
  80891. + */
  80892. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  80893. +{
  80894. + int i;
  80895. + uint32_t hwcfg1;
  80896. + dwc_otg_pcd_ep_t *ep;
  80897. + int in_ep_cntr, out_ep_cntr;
  80898. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  80899. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  80900. +
  80901. + /**
  80902. + * Initialize the EP0 structure.
  80903. + */
  80904. + ep = &pcd->ep0;
  80905. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  80906. +
  80907. + in_ep_cntr = 0;
  80908. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  80909. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  80910. + if ((hwcfg1 & 0x1) == 0) {
  80911. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  80912. + in_ep_cntr++;
  80913. + /**
  80914. + * @todo NGS: Add direction to EP, based on contents
  80915. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  80916. + * sprintf(";r
  80917. + */
  80918. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  80919. +
  80920. + DWC_CIRCLEQ_INIT(&ep->queue);
  80921. + }
  80922. + hwcfg1 >>= 2;
  80923. + }
  80924. +
  80925. + out_ep_cntr = 0;
  80926. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  80927. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  80928. + if ((hwcfg1 & 0x1) == 0) {
  80929. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  80930. + out_ep_cntr++;
  80931. + /**
  80932. + * @todo NGS: Add direction to EP, based on contents
  80933. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  80934. + * sprintf(";r
  80935. + */
  80936. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  80937. + DWC_CIRCLEQ_INIT(&ep->queue);
  80938. + }
  80939. + hwcfg1 >>= 2;
  80940. + }
  80941. +
  80942. + pcd->ep0state = EP0_DISCONNECT;
  80943. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  80944. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  80945. +}
  80946. +
  80947. +/**
  80948. + * This function is called when the SRP timer expires. The SRP should
  80949. + * complete within 6 seconds.
  80950. + */
  80951. +static void srp_timeout(void *ptr)
  80952. +{
  80953. + gotgctl_data_t gotgctl;
  80954. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  80955. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  80956. +
  80957. + gotgctl.d32 = DWC_READ_REG32(addr);
  80958. +
  80959. + core_if->srp_timer_started = 0;
  80960. +
  80961. + if (core_if->adp_enable) {
  80962. + if (gotgctl.b.bsesvld == 0) {
  80963. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80964. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  80965. + /* Power off the core */
  80966. + if (core_if->power_down == 2) {
  80967. + gpwrdn.b.pwrdnswtch = 1;
  80968. + DWC_MODIFY_REG32(&core_if->
  80969. + core_global_regs->gpwrdn,
  80970. + gpwrdn.d32, 0);
  80971. + }
  80972. +
  80973. + gpwrdn.d32 = 0;
  80974. + gpwrdn.b.pmuintsel = 1;
  80975. + gpwrdn.b.pmuactv = 1;
  80976. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  80977. + gpwrdn.d32);
  80978. + dwc_otg_adp_probe_start(core_if);
  80979. + } else {
  80980. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  80981. + core_if->op_state = B_PERIPHERAL;
  80982. + dwc_otg_core_init(core_if);
  80983. + dwc_otg_enable_global_interrupts(core_if);
  80984. + cil_pcd_start(core_if);
  80985. + }
  80986. + }
  80987. +
  80988. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  80989. + (core_if->core_params->i2c_enable)) {
  80990. + DWC_PRINTF("SRP Timeout\n");
  80991. +
  80992. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  80993. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  80994. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  80995. + }
  80996. +
  80997. + /* Clear Session Request */
  80998. + gotgctl.d32 = 0;
  80999. + gotgctl.b.sesreq = 1;
  81000. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  81001. + gotgctl.d32, 0);
  81002. +
  81003. + core_if->srp_success = 0;
  81004. + } else {
  81005. + __DWC_ERROR("Device not connected/responding\n");
  81006. + gotgctl.b.sesreq = 0;
  81007. + DWC_WRITE_REG32(addr, gotgctl.d32);
  81008. + }
  81009. + } else if (gotgctl.b.sesreq) {
  81010. + DWC_PRINTF("SRP Timeout\n");
  81011. +
  81012. + __DWC_ERROR("Device not connected/responding\n");
  81013. + gotgctl.b.sesreq = 0;
  81014. + DWC_WRITE_REG32(addr, gotgctl.d32);
  81015. + } else {
  81016. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  81017. + }
  81018. +}
  81019. +
  81020. +/**
  81021. + * Tasklet
  81022. + *
  81023. + */
  81024. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  81025. +
  81026. +static void start_xfer_tasklet_func(void *data)
  81027. +{
  81028. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  81029. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81030. +
  81031. + int i;
  81032. + depctl_data_t diepctl;
  81033. +
  81034. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  81035. +
  81036. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  81037. +
  81038. + if (pcd->ep0.queue_sof) {
  81039. + pcd->ep0.queue_sof = 0;
  81040. + start_next_request(&pcd->ep0);
  81041. + // break;
  81042. + }
  81043. +
  81044. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  81045. + depctl_data_t diepctl;
  81046. + diepctl.d32 =
  81047. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  81048. +
  81049. + if (pcd->in_ep[i].queue_sof) {
  81050. + pcd->in_ep[i].queue_sof = 0;
  81051. + start_next_request(&pcd->in_ep[i]);
  81052. + // break;
  81053. + }
  81054. + }
  81055. +
  81056. + return;
  81057. +}
  81058. +
  81059. +/**
  81060. + * This function initialized the PCD portion of the driver.
  81061. + *
  81062. + */
  81063. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  81064. +{
  81065. + dwc_otg_pcd_t *pcd = NULL;
  81066. + dwc_otg_dev_if_t *dev_if;
  81067. + int i;
  81068. +
  81069. + /*
  81070. + * Allocate PCD structure
  81071. + */
  81072. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  81073. +
  81074. + if (pcd == NULL) {
  81075. + return NULL;
  81076. + }
  81077. +
  81078. + pcd->lock = DWC_SPINLOCK_ALLOC();
  81079. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  81080. + pcd, core_if);//GRAYG
  81081. + if (!pcd->lock) {
  81082. + DWC_ERROR("Could not allocate lock for pcd");
  81083. + DWC_FREE(pcd);
  81084. + return NULL;
  81085. + }
  81086. + /* Set core_if's lock pointer to hcd->lock */
  81087. + core_if->lock = pcd->lock;
  81088. + pcd->core_if = core_if;
  81089. +
  81090. + dev_if = core_if->dev_if;
  81091. + dev_if->isoc_ep = NULL;
  81092. +
  81093. + if (core_if->hwcfg4.b.ded_fifo_en) {
  81094. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  81095. + } else {
  81096. + DWC_PRINTF("Shared Tx FIFO mode\n");
  81097. + }
  81098. +
  81099. + /*
  81100. + * Initialized the Core for Device mode here if there is nod ADP support.
  81101. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  81102. + */
  81103. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  81104. + dwc_otg_core_dev_init(core_if);
  81105. + }
  81106. +
  81107. + /*
  81108. + * Register the PCD Callbacks.
  81109. + */
  81110. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  81111. +
  81112. + /*
  81113. + * Initialize the DMA buffer for SETUP packets
  81114. + */
  81115. + if (GET_CORE_IF(pcd)->dma_enable) {
  81116. + pcd->setup_pkt =
  81117. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  81118. + &pcd->setup_pkt_dma_handle);
  81119. + if (pcd->setup_pkt == NULL) {
  81120. + DWC_FREE(pcd);
  81121. + return NULL;
  81122. + }
  81123. +
  81124. + pcd->status_buf =
  81125. + DWC_DMA_ALLOC(sizeof(uint16_t),
  81126. + &pcd->status_buf_dma_handle);
  81127. + if (pcd->status_buf == NULL) {
  81128. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  81129. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  81130. + DWC_FREE(pcd);
  81131. + return NULL;
  81132. + }
  81133. +
  81134. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81135. + dev_if->setup_desc_addr[0] =
  81136. + dwc_otg_ep_alloc_desc_chain
  81137. + (&dev_if->dma_setup_desc_addr[0], 1);
  81138. + dev_if->setup_desc_addr[1] =
  81139. + dwc_otg_ep_alloc_desc_chain
  81140. + (&dev_if->dma_setup_desc_addr[1], 1);
  81141. + dev_if->in_desc_addr =
  81142. + dwc_otg_ep_alloc_desc_chain
  81143. + (&dev_if->dma_in_desc_addr, 1);
  81144. + dev_if->out_desc_addr =
  81145. + dwc_otg_ep_alloc_desc_chain
  81146. + (&dev_if->dma_out_desc_addr, 1);
  81147. + pcd->data_terminated = 0;
  81148. +
  81149. + if (dev_if->setup_desc_addr[0] == 0
  81150. + || dev_if->setup_desc_addr[1] == 0
  81151. + || dev_if->in_desc_addr == 0
  81152. + || dev_if->out_desc_addr == 0) {
  81153. +
  81154. + if (dev_if->out_desc_addr)
  81155. + dwc_otg_ep_free_desc_chain
  81156. + (dev_if->out_desc_addr,
  81157. + dev_if->dma_out_desc_addr, 1);
  81158. + if (dev_if->in_desc_addr)
  81159. + dwc_otg_ep_free_desc_chain
  81160. + (dev_if->in_desc_addr,
  81161. + dev_if->dma_in_desc_addr, 1);
  81162. + if (dev_if->setup_desc_addr[1])
  81163. + dwc_otg_ep_free_desc_chain
  81164. + (dev_if->setup_desc_addr[1],
  81165. + dev_if->dma_setup_desc_addr[1], 1);
  81166. + if (dev_if->setup_desc_addr[0])
  81167. + dwc_otg_ep_free_desc_chain
  81168. + (dev_if->setup_desc_addr[0],
  81169. + dev_if->dma_setup_desc_addr[0], 1);
  81170. +
  81171. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  81172. + pcd->setup_pkt,
  81173. + pcd->setup_pkt_dma_handle);
  81174. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  81175. + pcd->status_buf,
  81176. + pcd->status_buf_dma_handle);
  81177. +
  81178. + DWC_FREE(pcd);
  81179. +
  81180. + return NULL;
  81181. + }
  81182. + }
  81183. + } else {
  81184. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  81185. + if (pcd->setup_pkt == NULL) {
  81186. + DWC_FREE(pcd);
  81187. + return NULL;
  81188. + }
  81189. +
  81190. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  81191. + if (pcd->status_buf == NULL) {
  81192. + DWC_FREE(pcd->setup_pkt);
  81193. + DWC_FREE(pcd);
  81194. + return NULL;
  81195. + }
  81196. + }
  81197. +
  81198. + dwc_otg_pcd_reinit(pcd);
  81199. +
  81200. + /* Allocate the cfi object for the PCD */
  81201. +#ifdef DWC_UTE_CFI
  81202. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  81203. + if (NULL == pcd->cfi)
  81204. + goto fail;
  81205. + if (init_cfi(pcd->cfi)) {
  81206. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  81207. + goto fail;
  81208. + }
  81209. +#endif
  81210. +
  81211. + /* Initialize tasklets */
  81212. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  81213. + start_xfer_tasklet_func, pcd);
  81214. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  81215. + do_test_mode, pcd);
  81216. +
  81217. + /* Initialize SRP timer */
  81218. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  81219. +
  81220. + if (core_if->core_params->dev_out_nak) {
  81221. + /**
  81222. + * Initialize xfer timeout timer. Implemented for
  81223. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  81224. + */
  81225. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  81226. + pcd->core_if->ep_xfer_timer[i] =
  81227. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  81228. + &pcd->core_if->ep_xfer_info[i]);
  81229. + }
  81230. + }
  81231. +
  81232. + return pcd;
  81233. +#ifdef DWC_UTE_CFI
  81234. +fail:
  81235. +#endif
  81236. + if (pcd->setup_pkt)
  81237. + DWC_FREE(pcd->setup_pkt);
  81238. + if (pcd->status_buf)
  81239. + DWC_FREE(pcd->status_buf);
  81240. +#ifdef DWC_UTE_CFI
  81241. + if (pcd->cfi)
  81242. + DWC_FREE(pcd->cfi);
  81243. +#endif
  81244. + if (pcd)
  81245. + DWC_FREE(pcd);
  81246. + return NULL;
  81247. +
  81248. +}
  81249. +
  81250. +/**
  81251. + * Remove PCD specific data
  81252. + */
  81253. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  81254. +{
  81255. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  81256. + int i;
  81257. + if (pcd->core_if->core_params->dev_out_nak) {
  81258. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  81259. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  81260. + pcd->core_if->ep_xfer_info[i].state = 0;
  81261. + }
  81262. + }
  81263. +
  81264. + if (GET_CORE_IF(pcd)->dma_enable) {
  81265. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  81266. + pcd->setup_pkt_dma_handle);
  81267. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  81268. + pcd->status_buf_dma_handle);
  81269. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81270. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  81271. + dev_if->dma_setup_desc_addr
  81272. + [0], 1);
  81273. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  81274. + dev_if->dma_setup_desc_addr
  81275. + [1], 1);
  81276. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  81277. + dev_if->dma_in_desc_addr, 1);
  81278. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  81279. + dev_if->dma_out_desc_addr,
  81280. + 1);
  81281. + }
  81282. + } else {
  81283. + DWC_FREE(pcd->setup_pkt);
  81284. + DWC_FREE(pcd->status_buf);
  81285. + }
  81286. + DWC_SPINLOCK_FREE(pcd->lock);
  81287. + /* Set core_if's lock pointer to NULL */
  81288. + pcd->core_if->lock = NULL;
  81289. +
  81290. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  81291. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  81292. + if (pcd->core_if->core_params->dev_out_nak) {
  81293. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  81294. + if (pcd->core_if->ep_xfer_timer[i]) {
  81295. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  81296. + }
  81297. + }
  81298. + }
  81299. +
  81300. +/* Release the CFI object's dynamic memory */
  81301. +#ifdef DWC_UTE_CFI
  81302. + if (pcd->cfi->ops.release) {
  81303. + pcd->cfi->ops.release(pcd->cfi);
  81304. + }
  81305. +#endif
  81306. +
  81307. + DWC_FREE(pcd);
  81308. +}
  81309. +
  81310. +/**
  81311. + * Returns whether registered pcd is dual speed or not
  81312. + */
  81313. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  81314. +{
  81315. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81316. +
  81317. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  81318. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  81319. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  81320. + (core_if->core_params->ulpi_fs_ls))) {
  81321. + return 0;
  81322. + }
  81323. +
  81324. + return 1;
  81325. +}
  81326. +
  81327. +/**
  81328. + * Returns whether registered pcd is OTG capable or not
  81329. + */
  81330. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  81331. +{
  81332. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81333. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  81334. +
  81335. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  81336. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  81337. + return 0;
  81338. + }
  81339. +
  81340. + return 1;
  81341. +}
  81342. +
  81343. +/**
  81344. + * This function assigns periodic Tx FIFO to an periodic EP
  81345. + * in shared Tx FIFO mode
  81346. + */
  81347. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  81348. +{
  81349. + uint32_t TxMsk = 1;
  81350. + int i;
  81351. +
  81352. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  81353. + if ((TxMsk & core_if->tx_msk) == 0) {
  81354. + core_if->tx_msk |= TxMsk;
  81355. + return i + 1;
  81356. + }
  81357. + TxMsk <<= 1;
  81358. + }
  81359. + return 0;
  81360. +}
  81361. +
  81362. +/**
  81363. + * This function assigns periodic Tx FIFO to an periodic EP
  81364. + * in shared Tx FIFO mode
  81365. + */
  81366. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  81367. +{
  81368. + uint32_t PerTxMsk = 1;
  81369. + int i;
  81370. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  81371. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  81372. + core_if->p_tx_msk |= PerTxMsk;
  81373. + return i + 1;
  81374. + }
  81375. + PerTxMsk <<= 1;
  81376. + }
  81377. + return 0;
  81378. +}
  81379. +
  81380. +/**
  81381. + * This function releases periodic Tx FIFO
  81382. + * in shared Tx FIFO mode
  81383. + */
  81384. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  81385. + uint32_t fifo_num)
  81386. +{
  81387. + core_if->p_tx_msk =
  81388. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  81389. +}
  81390. +
  81391. +/**
  81392. + * This function releases periodic Tx FIFO
  81393. + * in shared Tx FIFO mode
  81394. + */
  81395. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  81396. +{
  81397. + core_if->tx_msk =
  81398. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  81399. +}
  81400. +
  81401. +/**
  81402. + * This function is being called from gadget
  81403. + * to enable PCD endpoint.
  81404. + */
  81405. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  81406. + const uint8_t * ep_desc, void *usb_ep)
  81407. +{
  81408. + int num, dir;
  81409. + dwc_otg_pcd_ep_t *ep = NULL;
  81410. + const usb_endpoint_descriptor_t *desc;
  81411. + dwc_irqflags_t flags;
  81412. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  81413. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  81414. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  81415. + int retval = 0;
  81416. + int i, epcount;
  81417. +
  81418. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  81419. +
  81420. + if (!desc) {
  81421. + pcd->ep0.priv = usb_ep;
  81422. + ep = &pcd->ep0;
  81423. + retval = -DWC_E_INVALID;
  81424. + goto out;
  81425. + }
  81426. +
  81427. + num = UE_GET_ADDR(desc->bEndpointAddress);
  81428. + dir = UE_GET_DIR(desc->bEndpointAddress);
  81429. +
  81430. + if (!desc->wMaxPacketSize) {
  81431. + DWC_WARN("bad maxpacketsize\n");
  81432. + retval = -DWC_E_INVALID;
  81433. + goto out;
  81434. + }
  81435. +
  81436. + if (dir == UE_DIR_IN) {
  81437. + epcount = pcd->core_if->dev_if->num_in_eps;
  81438. + for (i = 0; i < epcount; i++) {
  81439. + if (num == pcd->in_ep[i].dwc_ep.num) {
  81440. + ep = &pcd->in_ep[i];
  81441. + break;
  81442. + }
  81443. + }
  81444. + } else {
  81445. + epcount = pcd->core_if->dev_if->num_out_eps;
  81446. + for (i = 0; i < epcount; i++) {
  81447. + if (num == pcd->out_ep[i].dwc_ep.num) {
  81448. + ep = &pcd->out_ep[i];
  81449. + break;
  81450. + }
  81451. + }
  81452. + }
  81453. +
  81454. + if (!ep) {
  81455. + DWC_WARN("bad address\n");
  81456. + retval = -DWC_E_INVALID;
  81457. + goto out;
  81458. + }
  81459. +
  81460. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81461. +
  81462. + ep->desc = desc;
  81463. + ep->priv = usb_ep;
  81464. +
  81465. + /*
  81466. + * Activate the EP
  81467. + */
  81468. + ep->stopped = 0;
  81469. +
  81470. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  81471. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  81472. +
  81473. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  81474. +
  81475. + if (ep->dwc_ep.is_in) {
  81476. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  81477. + ep->dwc_ep.tx_fifo_num = 0;
  81478. +
  81479. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  81480. + /*
  81481. + * if ISOC EP then assign a Periodic Tx FIFO.
  81482. + */
  81483. + ep->dwc_ep.tx_fifo_num =
  81484. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  81485. + }
  81486. + } else {
  81487. + /*
  81488. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  81489. + */
  81490. + ep->dwc_ep.tx_fifo_num =
  81491. + assign_tx_fifo(GET_CORE_IF(pcd));
  81492. + }
  81493. +
  81494. + /* Calculating EP info controller base address */
  81495. + if (ep->dwc_ep.tx_fifo_num
  81496. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  81497. + gdfifocfg.d32 =
  81498. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  81499. + core_global_regs->gdfifocfg);
  81500. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  81501. + dptxfsiz.d32 =
  81502. + (DWC_READ_REG32
  81503. + (&GET_CORE_IF(pcd)->core_global_regs->
  81504. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  81505. + gdfifocfg.b.epinfobase =
  81506. + gdfifocfgbase.d32 + dptxfsiz.d32;
  81507. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  81508. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  81509. + core_global_regs->gdfifocfg,
  81510. + gdfifocfg.d32);
  81511. + }
  81512. + }
  81513. + }
  81514. + /* Set initial data PID. */
  81515. + if (ep->dwc_ep.type == UE_BULK) {
  81516. + ep->dwc_ep.data_pid_start = 0;
  81517. + }
  81518. +
  81519. + /* Alloc DMA Descriptors */
  81520. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81521. +#ifndef DWC_UTE_PER_IO
  81522. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  81523. +#endif
  81524. + ep->dwc_ep.desc_addr =
  81525. + dwc_otg_ep_alloc_desc_chain(&ep->
  81526. + dwc_ep.dma_desc_addr,
  81527. + MAX_DMA_DESC_CNT);
  81528. + if (!ep->dwc_ep.desc_addr) {
  81529. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  81530. + __func__);
  81531. + retval = -DWC_E_SHUTDOWN;
  81532. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81533. + goto out;
  81534. + }
  81535. +#ifndef DWC_UTE_PER_IO
  81536. + }
  81537. +#endif
  81538. + }
  81539. +
  81540. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  81541. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  81542. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  81543. +#ifdef DWC_UTE_PER_IO
  81544. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  81545. +#endif
  81546. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  81547. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  81548. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  81549. + }
  81550. +
  81551. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  81552. +
  81553. +#ifdef DWC_UTE_CFI
  81554. + if (pcd->cfi->ops.ep_enable) {
  81555. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  81556. + }
  81557. +#endif
  81558. +
  81559. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81560. +
  81561. +out:
  81562. + return retval;
  81563. +}
  81564. +
  81565. +/**
  81566. + * This function is being called from gadget
  81567. + * to disable PCD endpoint.
  81568. + */
  81569. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  81570. +{
  81571. + dwc_otg_pcd_ep_t *ep;
  81572. + dwc_irqflags_t flags;
  81573. + dwc_otg_dev_dma_desc_t *desc_addr;
  81574. + dwc_dma_t dma_desc_addr;
  81575. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  81576. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  81577. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  81578. +
  81579. + ep = get_ep_from_handle(pcd, ep_handle);
  81580. +
  81581. + if (!ep || !ep->desc) {
  81582. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  81583. + return -DWC_E_INVALID;
  81584. + }
  81585. +
  81586. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81587. +
  81588. + dwc_otg_request_nuke(ep);
  81589. +
  81590. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  81591. + if (pcd->core_if->core_params->dev_out_nak) {
  81592. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  81593. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  81594. + }
  81595. + ep->desc = NULL;
  81596. + ep->stopped = 1;
  81597. +
  81598. + gdfifocfg.d32 =
  81599. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  81600. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  81601. +
  81602. + if (ep->dwc_ep.is_in) {
  81603. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  81604. + /* Flush the Tx FIFO */
  81605. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  81606. + ep->dwc_ep.tx_fifo_num);
  81607. + }
  81608. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  81609. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  81610. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  81611. + /* Decreasing EPinfo Base Addr */
  81612. + dptxfsiz.d32 =
  81613. + (DWC_READ_REG32
  81614. + (&GET_CORE_IF(pcd)->
  81615. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  81616. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  81617. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  81618. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  81619. + gdfifocfg.d32);
  81620. + }
  81621. + }
  81622. + }
  81623. +
  81624. + /* Free DMA Descriptors */
  81625. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81626. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  81627. + desc_addr = ep->dwc_ep.desc_addr;
  81628. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  81629. +
  81630. + /* Cannot call dma_free_coherent() with IRQs disabled */
  81631. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81632. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  81633. + MAX_DMA_DESC_CNT);
  81634. +
  81635. + goto out_unlocked;
  81636. + }
  81637. + }
  81638. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81639. +
  81640. +out_unlocked:
  81641. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  81642. + ep->dwc_ep.is_in ? "IN" : "OUT");
  81643. + return 0;
  81644. +
  81645. +}
  81646. +
  81647. +/******************************************************************************/
  81648. +#ifdef DWC_UTE_PER_IO
  81649. +
  81650. +/**
  81651. + * Free the request and its extended parts
  81652. + *
  81653. + */
  81654. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  81655. +{
  81656. + DWC_FREE(req->ext_req.per_io_frame_descs);
  81657. + DWC_FREE(req);
  81658. +}
  81659. +
  81660. +/**
  81661. + * Start the next request in the endpoint's queue.
  81662. + *
  81663. + */
  81664. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  81665. + dwc_otg_pcd_ep_t * ep)
  81666. +{
  81667. + int i;
  81668. + dwc_otg_pcd_request_t *req = NULL;
  81669. + dwc_ep_t *dwcep = NULL;
  81670. + struct dwc_iso_xreq_port *ereq = NULL;
  81671. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  81672. + uint16_t nat;
  81673. + depctl_data_t diepctl;
  81674. +
  81675. + dwcep = &ep->dwc_ep;
  81676. +
  81677. + if (dwcep->xiso_active_xfers > 0) {
  81678. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  81679. + DWC_WARN("There are currently active transfers for EP%d \
  81680. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  81681. + dwcep->xiso_queued_xfers);
  81682. +#endif
  81683. + return 0;
  81684. + }
  81685. +
  81686. + nat = UGETW(ep->desc->wMaxPacketSize);
  81687. + nat = (nat >> 11) & 0x03;
  81688. +
  81689. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81690. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81691. + ereq = &req->ext_req;
  81692. + ep->stopped = 0;
  81693. +
  81694. + /* Get the frame number */
  81695. + dwcep->xiso_frame_num =
  81696. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  81697. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  81698. +
  81699. + ddesc_iso = ereq->per_io_frame_descs;
  81700. +
  81701. + if (dwcep->is_in) {
  81702. + /* Setup DMA Descriptor chain for IN Isoc request */
  81703. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81704. + //if ((i % (nat + 1)) == 0)
  81705. + if ( i > 0 )
  81706. + dwcep->xiso_frame_num =
  81707. + (dwcep->xiso_bInterval +
  81708. + dwcep->xiso_frame_num) & 0x3FFF;
  81709. + dwcep->desc_addr[i].buf =
  81710. + req->dma + ddesc_iso[i].offset;
  81711. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  81712. + ddesc_iso[i].length;
  81713. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  81714. + dwcep->xiso_frame_num;
  81715. + dwcep->desc_addr[i].status.b_iso_in.bs =
  81716. + BS_HOST_READY;
  81717. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  81718. + dwcep->desc_addr[i].status.b_iso_in.sp =
  81719. + (ddesc_iso[i].length %
  81720. + dwcep->maxpacket) ? 1 : 0;
  81721. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  81722. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  81723. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  81724. +
  81725. + /* Process the last descriptor */
  81726. + if (i == ereq->pio_pkt_count - 1) {
  81727. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  81728. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  81729. + }
  81730. + }
  81731. +
  81732. + /* Setup and start the transfer for this endpoint */
  81733. + dwcep->xiso_active_xfers++;
  81734. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  81735. + in_ep_regs[dwcep->num]->diepdma,
  81736. + dwcep->dma_desc_addr);
  81737. + diepctl.d32 = 0;
  81738. + diepctl.b.epena = 1;
  81739. + diepctl.b.cnak = 1;
  81740. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  81741. + in_ep_regs[dwcep->num]->diepctl, 0,
  81742. + diepctl.d32);
  81743. + } else {
  81744. + /* Setup DMA Descriptor chain for OUT Isoc request */
  81745. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81746. + //if ((i % (nat + 1)) == 0)
  81747. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  81748. + dwcep->xiso_frame_num) & 0x3FFF;
  81749. + dwcep->desc_addr[i].buf =
  81750. + req->dma + ddesc_iso[i].offset;
  81751. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  81752. + ddesc_iso[i].length;
  81753. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  81754. + dwcep->xiso_frame_num;
  81755. + dwcep->desc_addr[i].status.b_iso_out.bs =
  81756. + BS_HOST_READY;
  81757. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  81758. + dwcep->desc_addr[i].status.b_iso_out.sp =
  81759. + (ddesc_iso[i].length %
  81760. + dwcep->maxpacket) ? 1 : 0;
  81761. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  81762. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  81763. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  81764. +
  81765. + /* Process the last descriptor */
  81766. + if (i == ereq->pio_pkt_count - 1) {
  81767. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  81768. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  81769. + }
  81770. + }
  81771. +
  81772. + /* Setup and start the transfer for this endpoint */
  81773. + dwcep->xiso_active_xfers++;
  81774. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  81775. + dev_if->out_ep_regs[dwcep->num]->
  81776. + doepdma, dwcep->dma_desc_addr);
  81777. + diepctl.d32 = 0;
  81778. + diepctl.b.epena = 1;
  81779. + diepctl.b.cnak = 1;
  81780. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  81781. + dev_if->out_ep_regs[dwcep->num]->
  81782. + doepctl, 0, diepctl.d32);
  81783. + }
  81784. +
  81785. + } else {
  81786. + ep->stopped = 1;
  81787. + }
  81788. +
  81789. + return 0;
  81790. +}
  81791. +
  81792. +/**
  81793. + * - Remove the request from the queue
  81794. + */
  81795. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  81796. +{
  81797. + dwc_otg_pcd_request_t *req = NULL;
  81798. + struct dwc_iso_xreq_port *ereq = NULL;
  81799. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  81800. + dwc_ep_t *dwcep = NULL;
  81801. + int i;
  81802. +
  81803. + //DWC_DEBUG();
  81804. + dwcep = &ep->dwc_ep;
  81805. +
  81806. + /* Get the first pending request from the queue */
  81807. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81808. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81809. + if (!req) {
  81810. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  81811. + return;
  81812. + }
  81813. + dwcep->xiso_active_xfers--;
  81814. + dwcep->xiso_queued_xfers--;
  81815. + /* Remove this request from the queue */
  81816. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  81817. + } else {
  81818. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  81819. + return;
  81820. + }
  81821. +
  81822. + ep->stopped = 1;
  81823. + ereq = &req->ext_req;
  81824. + ddesc_iso = ereq->per_io_frame_descs;
  81825. +
  81826. + if (dwcep->xiso_active_xfers < 0) {
  81827. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  81828. + dwcep->xiso_active_xfers);
  81829. + }
  81830. +
  81831. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  81832. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81833. + if (dwcep->is_in) { /* IN endpoints */
  81834. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  81835. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  81836. + ddesc_iso[i].status =
  81837. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  81838. + } else { /* OUT endpoints */
  81839. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  81840. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  81841. + ddesc_iso[i].status =
  81842. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  81843. + }
  81844. + }
  81845. +
  81846. + DWC_SPINUNLOCK(ep->pcd->lock);
  81847. +
  81848. + /* Call the completion function in the non-portable logic */
  81849. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  81850. + &req->ext_req);
  81851. +
  81852. + DWC_SPINLOCK(ep->pcd->lock);
  81853. +
  81854. + /* Free the request - specific freeing needed for extended request object */
  81855. + dwc_pcd_xiso_ereq_free(ep, req);
  81856. +
  81857. + /* Start the next request */
  81858. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  81859. +
  81860. + return;
  81861. +}
  81862. +
  81863. +/**
  81864. + * Create and initialize the Isoc pkt descriptors of the extended request.
  81865. + *
  81866. + */
  81867. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  81868. + void *ereq_nonport,
  81869. + int atomic_alloc)
  81870. +{
  81871. + struct dwc_iso_xreq_port *ereq = NULL;
  81872. + struct dwc_iso_xreq_port *req_mapped = NULL;
  81873. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  81874. + uint32_t pkt_count;
  81875. + int i;
  81876. +
  81877. + ereq = &req->ext_req;
  81878. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  81879. + pkt_count = req_mapped->pio_pkt_count;
  81880. +
  81881. + /* Create the isoc descs */
  81882. + if (atomic_alloc) {
  81883. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  81884. + } else {
  81885. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  81886. + }
  81887. +
  81888. + if (!ipds) {
  81889. + DWC_ERROR("Failed to allocate isoc descriptors");
  81890. + return -DWC_E_NO_MEMORY;
  81891. + }
  81892. +
  81893. + /* Initialize the extended request fields */
  81894. + ereq->per_io_frame_descs = ipds;
  81895. + ereq->error_count = 0;
  81896. + ereq->pio_alloc_pkt_count = pkt_count;
  81897. + ereq->pio_pkt_count = pkt_count;
  81898. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  81899. +
  81900. + /* Init the Isoc descriptors */
  81901. + for (i = 0; i < pkt_count; i++) {
  81902. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  81903. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  81904. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  81905. + ipds[i].actual_length =
  81906. + req_mapped->per_io_frame_descs[i].actual_length;
  81907. + }
  81908. +
  81909. + return 0;
  81910. +}
  81911. +
  81912. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  81913. +{
  81914. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  81915. + int i;
  81916. +
  81917. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  81918. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  81919. + DWC_DEBUG("error_count=%d", ereq->error_count);
  81920. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  81921. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  81922. + DWC_DEBUG("res=%d", ereq->res);
  81923. +
  81924. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81925. + xfd = &ereq->per_io_frame_descs[0];
  81926. + DWC_DEBUG("FD #%d", i);
  81927. +
  81928. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  81929. + DWC_DEBUG("xfd->length=%d", xfd->length);
  81930. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  81931. + DWC_DEBUG("xfd->status=%d", xfd->status);
  81932. + }
  81933. +}
  81934. +
  81935. +/**
  81936. + *
  81937. + */
  81938. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81939. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  81940. + int zero, void *req_handle, int atomic_alloc,
  81941. + void *ereq_nonport)
  81942. +{
  81943. + dwc_otg_pcd_request_t *req = NULL;
  81944. + dwc_otg_pcd_ep_t *ep;
  81945. + dwc_irqflags_t flags;
  81946. + int res;
  81947. +
  81948. + ep = get_ep_from_handle(pcd, ep_handle);
  81949. + if (!ep) {
  81950. + DWC_WARN("bad ep\n");
  81951. + return -DWC_E_INVALID;
  81952. + }
  81953. +
  81954. + /* We support this extension only for DDMA mode */
  81955. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  81956. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  81957. + return -DWC_E_INVALID;
  81958. +
  81959. + /* Create a dwc_otg_pcd_request_t object */
  81960. + if (atomic_alloc) {
  81961. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  81962. + } else {
  81963. + req = DWC_ALLOC(sizeof(*req));
  81964. + }
  81965. +
  81966. + if (!req) {
  81967. + return -DWC_E_NO_MEMORY;
  81968. + }
  81969. +
  81970. + /* Create the Isoc descs for this request which shall be the exact match
  81971. + * of the structure sent to us from the non-portable logic */
  81972. + res =
  81973. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  81974. + if (res) {
  81975. + DWC_WARN("Failed to init the Isoc descriptors");
  81976. + DWC_FREE(req);
  81977. + return res;
  81978. + }
  81979. +
  81980. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81981. +
  81982. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  81983. + req->buf = buf;
  81984. + req->dma = dma_buf;
  81985. + req->length = buflen;
  81986. + req->sent_zlp = zero;
  81987. + req->priv = req_handle;
  81988. +
  81989. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81990. + ep->dwc_ep.dma_addr = dma_buf;
  81991. + ep->dwc_ep.start_xfer_buff = buf;
  81992. + ep->dwc_ep.xfer_buff = buf;
  81993. + ep->dwc_ep.xfer_len = 0;
  81994. + ep->dwc_ep.xfer_count = 0;
  81995. + ep->dwc_ep.sent_zlp = 0;
  81996. + ep->dwc_ep.total_len = buflen;
  81997. +
  81998. + /* Add this request to the tail */
  81999. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  82000. + ep->dwc_ep.xiso_queued_xfers++;
  82001. +
  82002. +//DWC_DEBUG("CP_0");
  82003. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  82004. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  82005. +//prn_ext_request(&req->ext_req);
  82006. +
  82007. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82008. +
  82009. + /* If the req->status == ASAP then check if there is any active transfer
  82010. + * for this endpoint. If no active transfers, then get the first entry
  82011. + * from the queue and start that transfer
  82012. + */
  82013. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  82014. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  82015. + if (res) {
  82016. + DWC_WARN("Failed to start the next Isoc transfer");
  82017. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82018. + DWC_FREE(req);
  82019. + return res;
  82020. + }
  82021. + }
  82022. +
  82023. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82024. + return 0;
  82025. +}
  82026. +
  82027. +#endif
  82028. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  82029. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82030. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  82031. + int zero, void *req_handle, int atomic_alloc)
  82032. +{
  82033. + dwc_irqflags_t flags;
  82034. + dwc_otg_pcd_request_t *req;
  82035. + dwc_otg_pcd_ep_t *ep;
  82036. + uint32_t max_transfer;
  82037. +
  82038. + ep = get_ep_from_handle(pcd, ep_handle);
  82039. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  82040. + DWC_WARN("bad ep\n");
  82041. + return -DWC_E_INVALID;
  82042. + }
  82043. +
  82044. + if (atomic_alloc) {
  82045. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  82046. + } else {
  82047. + req = DWC_ALLOC(sizeof(*req));
  82048. + }
  82049. +
  82050. + if (!req) {
  82051. + return -DWC_E_NO_MEMORY;
  82052. + }
  82053. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  82054. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  82055. + if (ep->dwc_ep.num != 0) {
  82056. + DWC_ERROR("queue req %p, len %d buf %p\n",
  82057. + req_handle, buflen, buf);
  82058. + }
  82059. + }
  82060. +
  82061. + req->buf = buf;
  82062. + req->dma = dma_buf;
  82063. + req->length = buflen;
  82064. + req->sent_zlp = zero;
  82065. + req->priv = req_handle;
  82066. + req->dw_align_buf = NULL;
  82067. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  82068. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  82069. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  82070. + &req->dw_align_buf_dma);
  82071. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82072. +
  82073. + /*
  82074. + * After adding request to the queue for IN ISOC wait for In Token Received
  82075. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  82076. + * Received when EP is disabled interrupt to obtain starting microframe
  82077. + * (odd/even) start transfer
  82078. + */
  82079. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  82080. + if (req != 0) {
  82081. + depctl_data_t depctl = {.d32 =
  82082. + DWC_READ_REG32(&pcd->core_if->dev_if->
  82083. + in_ep_regs[ep->dwc_ep.num]->
  82084. + diepctl) };
  82085. + ++pcd->request_pending;
  82086. +
  82087. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  82088. + if (ep->dwc_ep.is_in) {
  82089. + depctl.b.cnak = 1;
  82090. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  82091. + in_ep_regs[ep->dwc_ep.num]->
  82092. + diepctl, depctl.d32);
  82093. + }
  82094. +
  82095. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82096. + }
  82097. + return 0;
  82098. + }
  82099. +
  82100. + /*
  82101. + * For EP0 IN without premature status, zlp is required?
  82102. + */
  82103. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  82104. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  82105. + //_req->zero = 1;
  82106. + }
  82107. +
  82108. + /* Start the transfer */
  82109. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  82110. + /* EP0 Transfer? */
  82111. + if (ep->dwc_ep.num == 0) {
  82112. + switch (pcd->ep0state) {
  82113. + case EP0_IN_DATA_PHASE:
  82114. + DWC_DEBUGPL(DBG_PCD,
  82115. + "%s ep0: EP0_IN_DATA_PHASE\n",
  82116. + __func__);
  82117. + break;
  82118. +
  82119. + case EP0_OUT_DATA_PHASE:
  82120. + DWC_DEBUGPL(DBG_PCD,
  82121. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  82122. + __func__);
  82123. + if (pcd->request_config) {
  82124. + /* Complete STATUS PHASE */
  82125. + ep->dwc_ep.is_in = 1;
  82126. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  82127. + }
  82128. + break;
  82129. +
  82130. + case EP0_IN_STATUS_PHASE:
  82131. + DWC_DEBUGPL(DBG_PCD,
  82132. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  82133. + __func__);
  82134. + break;
  82135. +
  82136. + default:
  82137. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  82138. + pcd->ep0state);
  82139. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82140. + return -DWC_E_SHUTDOWN;
  82141. + }
  82142. +
  82143. + ep->dwc_ep.dma_addr = dma_buf;
  82144. + ep->dwc_ep.start_xfer_buff = buf;
  82145. + ep->dwc_ep.xfer_buff = buf;
  82146. + ep->dwc_ep.xfer_len = buflen;
  82147. + ep->dwc_ep.xfer_count = 0;
  82148. + ep->dwc_ep.sent_zlp = 0;
  82149. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  82150. +
  82151. + if (zero) {
  82152. + if ((ep->dwc_ep.xfer_len %
  82153. + ep->dwc_ep.maxpacket == 0)
  82154. + && (ep->dwc_ep.xfer_len != 0)) {
  82155. + ep->dwc_ep.sent_zlp = 1;
  82156. + }
  82157. +
  82158. + }
  82159. +
  82160. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  82161. + &ep->dwc_ep);
  82162. + } // non-ep0 endpoints
  82163. + else {
  82164. +#ifdef DWC_UTE_CFI
  82165. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  82166. + /* store the request length */
  82167. + ep->dwc_ep.cfi_req_len = buflen;
  82168. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  82169. + ep, req);
  82170. + } else {
  82171. +#endif
  82172. + max_transfer =
  82173. + GET_CORE_IF(ep->pcd)->core_params->
  82174. + max_transfer_size;
  82175. +
  82176. + /* Setup and start the Transfer */
  82177. + if (req->dw_align_buf){
  82178. + if (ep->dwc_ep.is_in)
  82179. + dwc_memcpy(req->dw_align_buf,
  82180. + buf, buflen);
  82181. + ep->dwc_ep.dma_addr =
  82182. + req->dw_align_buf_dma;
  82183. + ep->dwc_ep.start_xfer_buff =
  82184. + req->dw_align_buf;
  82185. + ep->dwc_ep.xfer_buff =
  82186. + req->dw_align_buf;
  82187. + } else {
  82188. + ep->dwc_ep.dma_addr = dma_buf;
  82189. + ep->dwc_ep.start_xfer_buff = buf;
  82190. + ep->dwc_ep.xfer_buff = buf;
  82191. + }
  82192. + ep->dwc_ep.xfer_len = 0;
  82193. + ep->dwc_ep.xfer_count = 0;
  82194. + ep->dwc_ep.sent_zlp = 0;
  82195. + ep->dwc_ep.total_len = buflen;
  82196. +
  82197. + ep->dwc_ep.maxxfer = max_transfer;
  82198. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82199. + uint32_t out_max_xfer =
  82200. + DDMA_MAX_TRANSFER_SIZE -
  82201. + (DDMA_MAX_TRANSFER_SIZE % 4);
  82202. + if (ep->dwc_ep.is_in) {
  82203. + if (ep->dwc_ep.maxxfer >
  82204. + DDMA_MAX_TRANSFER_SIZE) {
  82205. + ep->dwc_ep.maxxfer =
  82206. + DDMA_MAX_TRANSFER_SIZE;
  82207. + }
  82208. + } else {
  82209. + if (ep->dwc_ep.maxxfer >
  82210. + out_max_xfer) {
  82211. + ep->dwc_ep.maxxfer =
  82212. + out_max_xfer;
  82213. + }
  82214. + }
  82215. + }
  82216. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  82217. + ep->dwc_ep.maxxfer -=
  82218. + (ep->dwc_ep.maxxfer %
  82219. + ep->dwc_ep.maxpacket);
  82220. + }
  82221. +
  82222. + if (zero) {
  82223. + if ((ep->dwc_ep.total_len %
  82224. + ep->dwc_ep.maxpacket == 0)
  82225. + && (ep->dwc_ep.total_len != 0)) {
  82226. + ep->dwc_ep.sent_zlp = 1;
  82227. + }
  82228. + }
  82229. +#ifdef DWC_UTE_CFI
  82230. + }
  82231. +#endif
  82232. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  82233. + &ep->dwc_ep);
  82234. + }
  82235. + }
  82236. +
  82237. + if (req != 0) {
  82238. + ++pcd->request_pending;
  82239. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  82240. + if (ep->dwc_ep.is_in && ep->stopped
  82241. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  82242. + /** @todo NGS Create a function for this. */
  82243. + diepmsk_data_t diepmsk = {.d32 = 0 };
  82244. + diepmsk.b.intktxfemp = 1;
  82245. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  82246. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  82247. + dev_if->dev_global_regs->diepeachintmsk
  82248. + [ep->dwc_ep.num], 0,
  82249. + diepmsk.d32);
  82250. + } else {
  82251. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  82252. + dev_if->dev_global_regs->
  82253. + diepmsk, 0, diepmsk.d32);
  82254. + }
  82255. +
  82256. + }
  82257. + }
  82258. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82259. +
  82260. + return 0;
  82261. +}
  82262. +
  82263. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82264. + void *req_handle)
  82265. +{
  82266. + dwc_irqflags_t flags;
  82267. + dwc_otg_pcd_request_t *req;
  82268. + dwc_otg_pcd_ep_t *ep;
  82269. +
  82270. + ep = get_ep_from_handle(pcd, ep_handle);
  82271. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  82272. + DWC_WARN("bad argument\n");
  82273. + return -DWC_E_INVALID;
  82274. + }
  82275. +
  82276. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82277. +
  82278. + /* make sure it's actually queued on this endpoint */
  82279. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  82280. + if (req->priv == (void *)req_handle) {
  82281. + break;
  82282. + }
  82283. + }
  82284. +
  82285. + if (req->priv != (void *)req_handle) {
  82286. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82287. + return -DWC_E_INVALID;
  82288. + }
  82289. +
  82290. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  82291. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  82292. + } else {
  82293. + req = NULL;
  82294. + }
  82295. +
  82296. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82297. +
  82298. + return req ? 0 : -DWC_E_SHUTDOWN;
  82299. +
  82300. +}
  82301. +
  82302. +/**
  82303. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  82304. + *
  82305. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  82306. + * requests. If the gadget driver clears the halt status, it will
  82307. + * automatically unwedge the endpoint.
  82308. + *
  82309. + * Returns zero on success, else negative DWC error code.
  82310. + */
  82311. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  82312. +{
  82313. + dwc_otg_pcd_ep_t *ep;
  82314. + dwc_irqflags_t flags;
  82315. + int retval = 0;
  82316. +
  82317. + ep = get_ep_from_handle(pcd, ep_handle);
  82318. +
  82319. + if ((!ep->desc && ep != &pcd->ep0) ||
  82320. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  82321. + DWC_WARN("%s, bad ep\n", __func__);
  82322. + return -DWC_E_INVALID;
  82323. + }
  82324. +
  82325. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82326. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82327. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  82328. + ep->dwc_ep.is_in ? "IN" : "OUT");
  82329. + retval = -DWC_E_AGAIN;
  82330. + } else {
  82331. + /* This code needs to be reviewed */
  82332. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  82333. + dtxfsts_data_t txstatus;
  82334. + fifosize_data_t txfifosize;
  82335. +
  82336. + txfifosize.d32 =
  82337. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  82338. + core_global_regs->dtxfsiz[ep->dwc_ep.
  82339. + tx_fifo_num]);
  82340. + txstatus.d32 =
  82341. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  82342. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  82343. + dtxfsts);
  82344. +
  82345. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  82346. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  82347. + retval = -DWC_E_AGAIN;
  82348. + } else {
  82349. + if (ep->dwc_ep.num == 0) {
  82350. + pcd->ep0state = EP0_STALL;
  82351. + }
  82352. +
  82353. + ep->stopped = 1;
  82354. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  82355. + &ep->dwc_ep);
  82356. + }
  82357. + } else {
  82358. + if (ep->dwc_ep.num == 0) {
  82359. + pcd->ep0state = EP0_STALL;
  82360. + }
  82361. +
  82362. + ep->stopped = 1;
  82363. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  82364. + }
  82365. + }
  82366. +
  82367. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82368. +
  82369. + return retval;
  82370. +}
  82371. +
  82372. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  82373. +{
  82374. + dwc_otg_pcd_ep_t *ep;
  82375. + dwc_irqflags_t flags;
  82376. + int retval = 0;
  82377. +
  82378. + ep = get_ep_from_handle(pcd, ep_handle);
  82379. +
  82380. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  82381. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  82382. + DWC_WARN("%s, bad ep\n", __func__);
  82383. + return -DWC_E_INVALID;
  82384. + }
  82385. +
  82386. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82387. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82388. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  82389. + ep->dwc_ep.is_in ? "IN" : "OUT");
  82390. + retval = -DWC_E_AGAIN;
  82391. + } else if (value == 0) {
  82392. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  82393. + } else if (value == 1) {
  82394. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  82395. + dtxfsts_data_t txstatus;
  82396. + fifosize_data_t txfifosize;
  82397. +
  82398. + txfifosize.d32 =
  82399. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  82400. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  82401. + txstatus.d32 =
  82402. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  82403. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  82404. +
  82405. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  82406. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  82407. + retval = -DWC_E_AGAIN;
  82408. + } else {
  82409. + if (ep->dwc_ep.num == 0) {
  82410. + pcd->ep0state = EP0_STALL;
  82411. + }
  82412. +
  82413. + ep->stopped = 1;
  82414. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  82415. + &ep->dwc_ep);
  82416. + }
  82417. + } else {
  82418. + if (ep->dwc_ep.num == 0) {
  82419. + pcd->ep0state = EP0_STALL;
  82420. + }
  82421. +
  82422. + ep->stopped = 1;
  82423. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  82424. + }
  82425. + } else if (value == 2) {
  82426. + ep->dwc_ep.stall_clear_flag = 0;
  82427. + } else if (value == 3) {
  82428. + ep->dwc_ep.stall_clear_flag = 1;
  82429. + }
  82430. +
  82431. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82432. +
  82433. + return retval;
  82434. +}
  82435. +
  82436. +/**
  82437. + * This function initiates remote wakeup of the host from suspend state.
  82438. + */
  82439. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  82440. +{
  82441. + dctl_data_t dctl = { 0 };
  82442. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82443. + dsts_data_t dsts;
  82444. +
  82445. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82446. + if (!dsts.b.suspsts) {
  82447. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  82448. + }
  82449. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  82450. + if (pcd->remote_wakeup_enable) {
  82451. + if (set) {
  82452. +
  82453. + if (core_if->adp_enable) {
  82454. + gpwrdn_data_t gpwrdn;
  82455. +
  82456. + dwc_otg_adp_probe_stop(core_if);
  82457. +
  82458. + /* Mask SRP detected interrupt from Power Down Logic */
  82459. + gpwrdn.d32 = 0;
  82460. + gpwrdn.b.srp_det_msk = 1;
  82461. + DWC_MODIFY_REG32(&core_if->
  82462. + core_global_regs->gpwrdn,
  82463. + gpwrdn.d32, 0);
  82464. +
  82465. + /* Disable Power Down Logic */
  82466. + gpwrdn.d32 = 0;
  82467. + gpwrdn.b.pmuactv = 1;
  82468. + DWC_MODIFY_REG32(&core_if->
  82469. + core_global_regs->gpwrdn,
  82470. + gpwrdn.d32, 0);
  82471. +
  82472. + /*
  82473. + * Initialize the Core for Device mode.
  82474. + */
  82475. + core_if->op_state = B_PERIPHERAL;
  82476. + dwc_otg_core_init(core_if);
  82477. + dwc_otg_enable_global_interrupts(core_if);
  82478. + cil_pcd_start(core_if);
  82479. +
  82480. + dwc_otg_initiate_srp(core_if);
  82481. + }
  82482. +
  82483. + dctl.b.rmtwkupsig = 1;
  82484. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  82485. + dctl, 0, dctl.d32);
  82486. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  82487. +
  82488. + dwc_mdelay(2);
  82489. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  82490. + dctl, dctl.d32, 0);
  82491. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  82492. + }
  82493. + } else {
  82494. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  82495. + }
  82496. +}
  82497. +
  82498. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82499. +/**
  82500. + * This function initiates remote wakeup of the host from L1 sleep state.
  82501. + */
  82502. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  82503. +{
  82504. + glpmcfg_data_t lpmcfg;
  82505. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82506. +
  82507. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  82508. +
  82509. + /* Check if we are in L1 state */
  82510. + if (!lpmcfg.b.prt_sleep_sts) {
  82511. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  82512. + return;
  82513. + }
  82514. +
  82515. + /* Check if host allows remote wakeup */
  82516. + if (!lpmcfg.b.rem_wkup_en) {
  82517. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  82518. + return;
  82519. + }
  82520. +
  82521. + /* Check if Resume OK */
  82522. + if (!lpmcfg.b.sleep_state_resumeok) {
  82523. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  82524. + return;
  82525. + }
  82526. +
  82527. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  82528. + lpmcfg.b.en_utmi_sleep = 0;
  82529. + lpmcfg.b.hird_thres &= (~(1 << 4));
  82530. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  82531. +
  82532. + if (set) {
  82533. + dctl_data_t dctl = {.d32 = 0 };
  82534. + dctl.b.rmtwkupsig = 1;
  82535. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  82536. + * Hardware will automatically clear this bit.
  82537. + */
  82538. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  82539. + 0, dctl.d32);
  82540. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  82541. + }
  82542. +
  82543. +}
  82544. +#endif
  82545. +
  82546. +/**
  82547. + * Performs remote wakeup.
  82548. + */
  82549. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  82550. +{
  82551. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82552. + dwc_irqflags_t flags;
  82553. + if (dwc_otg_is_device_mode(core_if)) {
  82554. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82555. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82556. + if (core_if->lx_state == DWC_OTG_L1) {
  82557. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  82558. + } else {
  82559. +#endif
  82560. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  82561. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82562. + }
  82563. +#endif
  82564. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82565. + }
  82566. + return;
  82567. +}
  82568. +
  82569. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  82570. +{
  82571. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82572. + dctl_data_t dctl = { 0 };
  82573. +
  82574. + if (dwc_otg_is_device_mode(core_if)) {
  82575. + dctl.b.sftdiscon = 1;
  82576. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  82577. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  82578. + dwc_udelay(no_of_usecs);
  82579. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  82580. +
  82581. + } else{
  82582. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  82583. + }
  82584. + return;
  82585. +
  82586. +}
  82587. +
  82588. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  82589. +{
  82590. + dsts_data_t dsts;
  82591. + gotgctl_data_t gotgctl;
  82592. +
  82593. + /*
  82594. + * This function starts the Protocol if no session is in progress. If
  82595. + * a session is already in progress, but the device is suspended,
  82596. + * remote wakeup signaling is started.
  82597. + */
  82598. +
  82599. + /* Check if valid session */
  82600. + gotgctl.d32 =
  82601. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  82602. + if (gotgctl.b.bsesvld) {
  82603. + /* Check if suspend state */
  82604. + dsts.d32 =
  82605. + DWC_READ_REG32(&
  82606. + (GET_CORE_IF(pcd)->dev_if->
  82607. + dev_global_regs->dsts));
  82608. + if (dsts.b.suspsts) {
  82609. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  82610. + }
  82611. + } else {
  82612. + dwc_otg_pcd_initiate_srp(pcd);
  82613. + }
  82614. +
  82615. + return 0;
  82616. +
  82617. +}
  82618. +
  82619. +/**
  82620. + * Start the SRP timer to detect when the SRP does not complete within
  82621. + * 6 seconds.
  82622. + *
  82623. + * @param pcd the pcd structure.
  82624. + */
  82625. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  82626. +{
  82627. + dwc_irqflags_t flags;
  82628. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82629. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  82630. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82631. +}
  82632. +
  82633. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  82634. +{
  82635. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  82636. +}
  82637. +
  82638. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  82639. +{
  82640. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  82641. +}
  82642. +
  82643. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  82644. +{
  82645. + return pcd->b_hnp_enable;
  82646. +}
  82647. +
  82648. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  82649. +{
  82650. + return pcd->a_hnp_support;
  82651. +}
  82652. +
  82653. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  82654. +{
  82655. + return pcd->a_alt_hnp_support;
  82656. +}
  82657. +
  82658. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  82659. +{
  82660. + return pcd->remote_wakeup_enable;
  82661. +}
  82662. +
  82663. +#endif /* DWC_HOST_ONLY */
  82664. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  82665. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  82666. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-03-13 12:46:39.520097997 +0100
  82667. @@ -0,0 +1,266 @@
  82668. +/* ==========================================================================
  82669. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  82670. + * $Revision: #48 $
  82671. + * $Date: 2012/08/10 $
  82672. + * $Change: 2047372 $
  82673. + *
  82674. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82675. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82676. + * otherwise expressly agreed to in writing between Synopsys and you.
  82677. + *
  82678. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82679. + * any End User Software License Agreement or Agreement for Licensed Product
  82680. + * with Synopsys or any supplement thereto. You are permitted to use and
  82681. + * redistribute this Software in source and binary forms, with or without
  82682. + * modification, provided that redistributions of source code must retain this
  82683. + * notice. You may not view, use, disclose, copy or distribute this file or
  82684. + * any information contained herein except pursuant to this license grant from
  82685. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82686. + * below, then you are not authorized to use the Software.
  82687. + *
  82688. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82689. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82690. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82691. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82692. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82693. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82694. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82695. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82696. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82697. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82698. + * DAMAGE.
  82699. + * ========================================================================== */
  82700. +#ifndef DWC_HOST_ONLY
  82701. +#if !defined(__DWC_PCD_H__)
  82702. +#define __DWC_PCD_H__
  82703. +
  82704. +#include "dwc_otg_os_dep.h"
  82705. +#include "usb.h"
  82706. +#include "dwc_otg_cil.h"
  82707. +#include "dwc_otg_pcd_if.h"
  82708. +struct cfiobject;
  82709. +
  82710. +/**
  82711. + * @file
  82712. + *
  82713. + * This file contains the structures, constants, and interfaces for
  82714. + * the Perpherial Contoller Driver (PCD).
  82715. + *
  82716. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  82717. + * Gadget API, so that the existing Gadget drivers can be used. For
  82718. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  82719. + * (FBS) driver will be used. The FBS driver supports the
  82720. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  82721. + * transports.
  82722. + *
  82723. + */
  82724. +
  82725. +/** Invalid DMA Address */
  82726. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  82727. +
  82728. +/** Max Transfer size for any EP */
  82729. +#define DDMA_MAX_TRANSFER_SIZE 65535
  82730. +
  82731. +/**
  82732. + * Get the pointer to the core_if from the pcd pointer.
  82733. + */
  82734. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  82735. +
  82736. +/**
  82737. + * States of EP0.
  82738. + */
  82739. +typedef enum ep0_state {
  82740. + EP0_DISCONNECT, /* no host */
  82741. + EP0_IDLE,
  82742. + EP0_IN_DATA_PHASE,
  82743. + EP0_OUT_DATA_PHASE,
  82744. + EP0_IN_STATUS_PHASE,
  82745. + EP0_OUT_STATUS_PHASE,
  82746. + EP0_STALL,
  82747. +} ep0state_e;
  82748. +
  82749. +/** Fordward declaration.*/
  82750. +struct dwc_otg_pcd;
  82751. +
  82752. +/** DWC_otg iso request structure.
  82753. + *
  82754. + */
  82755. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  82756. +
  82757. +#ifdef DWC_UTE_PER_IO
  82758. +
  82759. +/**
  82760. + * This shall be the exact analogy of the same type structure defined in the
  82761. + * usb_gadget.h. Each descriptor contains
  82762. + */
  82763. +struct dwc_iso_pkt_desc_port {
  82764. + uint32_t offset;
  82765. + uint32_t length; /* expected length */
  82766. + uint32_t actual_length;
  82767. + uint32_t status;
  82768. +};
  82769. +
  82770. +struct dwc_iso_xreq_port {
  82771. + /** transfer/submission flag */
  82772. + uint32_t tr_sub_flags;
  82773. + /** Start the request ASAP */
  82774. +#define DWC_EREQ_TF_ASAP 0x00000002
  82775. + /** Just enqueue the request w/o initiating a transfer */
  82776. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  82777. +
  82778. + /**
  82779. + * count of ISO packets attached to this request - shall
  82780. + * not exceed the pio_alloc_pkt_count
  82781. + */
  82782. + uint32_t pio_pkt_count;
  82783. + /** count of ISO packets allocated for this request */
  82784. + uint32_t pio_alloc_pkt_count;
  82785. + /** number of ISO packet errors */
  82786. + uint32_t error_count;
  82787. + /** reserved for future extension */
  82788. + uint32_t res;
  82789. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  82790. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  82791. +};
  82792. +#endif
  82793. +/** DWC_otg request structure.
  82794. + * This structure is a list of requests.
  82795. + */
  82796. +typedef struct dwc_otg_pcd_request {
  82797. + void *priv;
  82798. + void *buf;
  82799. + dwc_dma_t dma;
  82800. + uint32_t length;
  82801. + uint32_t actual;
  82802. + unsigned sent_zlp:1;
  82803. + /**
  82804. + * Used instead of original buffer if
  82805. + * it(physical address) is not dword-aligned.
  82806. + **/
  82807. + uint8_t *dw_align_buf;
  82808. + dwc_dma_t dw_align_buf_dma;
  82809. +
  82810. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  82811. +#ifdef DWC_UTE_PER_IO
  82812. + struct dwc_iso_xreq_port ext_req;
  82813. + //void *priv_ereq_nport; /* */
  82814. +#endif
  82815. +} dwc_otg_pcd_request_t;
  82816. +
  82817. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  82818. +
  82819. +/** PCD EP structure.
  82820. + * This structure describes an EP, there is an array of EPs in the PCD
  82821. + * structure.
  82822. + */
  82823. +typedef struct dwc_otg_pcd_ep {
  82824. + /** USB EP Descriptor */
  82825. + const usb_endpoint_descriptor_t *desc;
  82826. +
  82827. + /** queue of dwc_otg_pcd_requests. */
  82828. + struct req_list queue;
  82829. + unsigned stopped:1;
  82830. + unsigned disabling:1;
  82831. + unsigned dma:1;
  82832. + unsigned queue_sof:1;
  82833. +
  82834. +#ifdef DWC_EN_ISOC
  82835. + /** ISOC req handle passed */
  82836. + void *iso_req_handle;
  82837. +#endif //_EN_ISOC_
  82838. +
  82839. + /** DWC_otg ep data. */
  82840. + dwc_ep_t dwc_ep;
  82841. +
  82842. + /** Pointer to PCD */
  82843. + struct dwc_otg_pcd *pcd;
  82844. +
  82845. + void *priv;
  82846. +} dwc_otg_pcd_ep_t;
  82847. +
  82848. +/** DWC_otg PCD Structure.
  82849. + * This structure encapsulates the data for the dwc_otg PCD.
  82850. + */
  82851. +struct dwc_otg_pcd {
  82852. + const struct dwc_otg_pcd_function_ops *fops;
  82853. + /** The DWC otg device pointer */
  82854. + struct dwc_otg_device *otg_dev;
  82855. + /** Core Interface */
  82856. + dwc_otg_core_if_t *core_if;
  82857. + /** State of EP0 */
  82858. + ep0state_e ep0state;
  82859. + /** EP0 Request is pending */
  82860. + unsigned ep0_pending:1;
  82861. + /** Indicates when SET CONFIGURATION Request is in process */
  82862. + unsigned request_config:1;
  82863. + /** The state of the Remote Wakeup Enable. */
  82864. + unsigned remote_wakeup_enable:1;
  82865. + /** The state of the B-Device HNP Enable. */
  82866. + unsigned b_hnp_enable:1;
  82867. + /** The state of A-Device HNP Support. */
  82868. + unsigned a_hnp_support:1;
  82869. + /** The state of the A-Device Alt HNP support. */
  82870. + unsigned a_alt_hnp_support:1;
  82871. + /** Count of pending Requests */
  82872. + unsigned request_pending;
  82873. +
  82874. + /** SETUP packet for EP0
  82875. + * This structure is allocated as a DMA buffer on PCD initialization
  82876. + * with enough space for up to 3 setup packets.
  82877. + */
  82878. + union {
  82879. + usb_device_request_t req;
  82880. + uint32_t d32[2];
  82881. + } *setup_pkt;
  82882. +
  82883. + dwc_dma_t setup_pkt_dma_handle;
  82884. +
  82885. + /* Additional buffer and flag for CTRL_WR premature case */
  82886. + uint8_t *backup_buf;
  82887. + unsigned data_terminated;
  82888. +
  82889. + /** 2-byte dma buffer used to return status from GET_STATUS */
  82890. + uint16_t *status_buf;
  82891. + dwc_dma_t status_buf_dma_handle;
  82892. +
  82893. + /** EP0 */
  82894. + dwc_otg_pcd_ep_t ep0;
  82895. +
  82896. + /** Array of IN EPs. */
  82897. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  82898. + /** Array of OUT EPs. */
  82899. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  82900. + /** number of valid EPs in the above array. */
  82901. +// unsigned num_eps : 4;
  82902. + dwc_spinlock_t *lock;
  82903. +
  82904. + /** Tasklet to defer starting of TEST mode transmissions until
  82905. + * Status Phase has been completed.
  82906. + */
  82907. + dwc_tasklet_t *test_mode_tasklet;
  82908. +
  82909. + /** Tasklet to delay starting of xfer in DMA mode */
  82910. + dwc_tasklet_t *start_xfer_tasklet;
  82911. +
  82912. + /** The test mode to enter when the tasklet is executed. */
  82913. + unsigned test_mode;
  82914. + /** The cfi_api structure that implements most of the CFI API
  82915. + * and OTG specific core configuration functionality
  82916. + */
  82917. +#ifdef DWC_UTE_CFI
  82918. + struct cfiobject *cfi;
  82919. +#endif
  82920. +
  82921. +};
  82922. +
  82923. +//FIXME this functions should be static, and this prototypes should be removed
  82924. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  82925. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  82926. + dwc_otg_pcd_request_t * req, int32_t status);
  82927. +
  82928. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  82929. + void *req_handle);
  82930. +
  82931. +extern void do_test_mode(void *data);
  82932. +#endif
  82933. +#endif /* DWC_HOST_ONLY */
  82934. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  82935. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  82936. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-03-13 12:46:39.520097997 +0100
  82937. @@ -0,0 +1,360 @@
  82938. +/* ==========================================================================
  82939. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  82940. + * $Revision: #11 $
  82941. + * $Date: 2011/10/26 $
  82942. + * $Change: 1873028 $
  82943. + *
  82944. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82945. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82946. + * otherwise expressly agreed to in writing between Synopsys and you.
  82947. + *
  82948. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82949. + * any End User Software License Agreement or Agreement for Licensed Product
  82950. + * with Synopsys or any supplement thereto. You are permitted to use and
  82951. + * redistribute this Software in source and binary forms, with or without
  82952. + * modification, provided that redistributions of source code must retain this
  82953. + * notice. You may not view, use, disclose, copy or distribute this file or
  82954. + * any information contained herein except pursuant to this license grant from
  82955. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82956. + * below, then you are not authorized to use the Software.
  82957. + *
  82958. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82959. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82960. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82961. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82962. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82963. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82964. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82965. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82966. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82967. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82968. + * DAMAGE.
  82969. + * ========================================================================== */
  82970. +#ifndef DWC_HOST_ONLY
  82971. +
  82972. +#if !defined(__DWC_PCD_IF_H__)
  82973. +#define __DWC_PCD_IF_H__
  82974. +
  82975. +//#include "dwc_os.h"
  82976. +#include "dwc_otg_core_if.h"
  82977. +
  82978. +/** @file
  82979. + * This file defines DWC_OTG PCD Core API.
  82980. + */
  82981. +
  82982. +struct dwc_otg_pcd;
  82983. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  82984. +
  82985. +/** Maxpacket size for EP0 */
  82986. +#define MAX_EP0_SIZE 64
  82987. +/** Maxpacket size for any EP */
  82988. +#define MAX_PACKET_SIZE 1024
  82989. +
  82990. +/** @name Function Driver Callbacks */
  82991. +/** @{ */
  82992. +
  82993. +/** This function will be called whenever a previously queued request has
  82994. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  82995. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  82996. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  82997. + * parameters. */
  82998. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82999. + void *req_handle, int32_t status,
  83000. + uint32_t actual);
  83001. +/**
  83002. + * This function will be called whenever a previousle queued ISOC request has
  83003. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  83004. + * function.
  83005. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  83006. + * functions.
  83007. + */
  83008. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  83009. + void *req_handle, int proc_buf_num);
  83010. +/** This function should handle any SETUP request that cannot be handled by the
  83011. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  83012. + * class-specific requests, etc. The function must non-blocking.
  83013. + *
  83014. + * Returns 0 on success.
  83015. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  83016. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  83017. + * Returns -DWC_E_SHUTDOWN on any other error. */
  83018. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  83019. +/** This is called whenever the device has been disconnected. The function
  83020. + * driver should take appropriate action to clean up all pending requests in the
  83021. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  83022. + * state. */
  83023. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  83024. +/** This function is called when device has been connected. */
  83025. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  83026. +/** This function is called when device has been suspended */
  83027. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  83028. +/** This function is called when device has received LPM tokens, i.e.
  83029. + * device has been sent to sleep state. */
  83030. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  83031. +/** This function is called when device has been resumed
  83032. + * from suspend(L2) or L1 sleep state. */
  83033. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  83034. +/** This function is called whenever hnp params has been changed.
  83035. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  83036. + * to get hnp parameters. */
  83037. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  83038. +/** This function is called whenever USB RESET is detected. */
  83039. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  83040. +
  83041. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  83042. +
  83043. +/**
  83044. + *
  83045. + * @param ep_handle Void pointer to the usb_ep structure
  83046. + * @param ereq_port Pointer to the extended request structure created in the
  83047. + * portable part.
  83048. + */
  83049. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  83050. + void *req_handle, int32_t status,
  83051. + void *ereq_port);
  83052. +/** Function Driver Ops Data Structure */
  83053. +struct dwc_otg_pcd_function_ops {
  83054. + dwc_connect_cb_t connect;
  83055. + dwc_disconnect_cb_t disconnect;
  83056. + dwc_setup_cb_t setup;
  83057. + dwc_completion_cb_t complete;
  83058. + dwc_isoc_completion_cb_t isoc_complete;
  83059. + dwc_suspend_cb_t suspend;
  83060. + dwc_sleep_cb_t sleep;
  83061. + dwc_resume_cb_t resume;
  83062. + dwc_reset_cb_t reset;
  83063. + dwc_hnp_params_changed_cb_t hnp_changed;
  83064. + cfi_setup_cb_t cfi_setup;
  83065. +#ifdef DWC_UTE_PER_IO
  83066. + xiso_completion_cb_t xisoc_complete;
  83067. +#endif
  83068. +};
  83069. +/** @} */
  83070. +
  83071. +/** @name Function Driver Functions */
  83072. +/** @{ */
  83073. +
  83074. +/** Call this function to get pointer on dwc_otg_pcd_t,
  83075. + * this pointer will be used for all PCD API functions.
  83076. + *
  83077. + * @param core_if The DWC_OTG Core
  83078. + */
  83079. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  83080. +
  83081. +/** Frees PCD allocated by dwc_otg_pcd_init
  83082. + *
  83083. + * @param pcd The PCD
  83084. + */
  83085. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  83086. +
  83087. +/** Call this to bind the function driver to the PCD Core.
  83088. + *
  83089. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  83090. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  83091. + */
  83092. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  83093. + const struct dwc_otg_pcd_function_ops *fops);
  83094. +
  83095. +/** Enables an endpoint for use. This function enables an endpoint in
  83096. + * the PCD. The endpoint is described by the ep_desc which has the
  83097. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  83098. + * to the endpoint from other API functions and in callbacks. Normally this
  83099. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  83100. + * core for that interface.
  83101. + *
  83102. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  83103. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  83104. + * Returns 0 on success.
  83105. + *
  83106. + * @param pcd The PCD
  83107. + * @param ep_desc Endpoint descriptor
  83108. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  83109. + */
  83110. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  83111. + const uint8_t * ep_desc, void *usb_ep);
  83112. +
  83113. +/** Disable the endpoint referenced by ep_handle.
  83114. + *
  83115. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  83116. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  83117. + * Returns 0 on success. */
  83118. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  83119. +
  83120. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  83121. + * After the transfer is completes, the complete callback will be called with
  83122. + * the request status.
  83123. + *
  83124. + * @param pcd The PCD
  83125. + * @param ep_handle The handle of the endpoint
  83126. + * @param buf The buffer for the data
  83127. + * @param dma_buf The DMA buffer for the data
  83128. + * @param buflen The length of the data transfer
  83129. + * @param zero Specifies whether to send zero length last packet.
  83130. + * @param req_handle Set this handle to any value to use to reference this
  83131. + * request in the ep_dequeue function or from the complete callback
  83132. + * @param atomic_alloc If driver need to perform atomic allocations
  83133. + * for internal data structures.
  83134. + *
  83135. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  83136. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  83137. + * Returns 0 on success. */
  83138. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83139. + uint8_t * buf, dwc_dma_t dma_buf,
  83140. + uint32_t buflen, int zero, void *req_handle,
  83141. + int atomic_alloc);
  83142. +#ifdef DWC_UTE_PER_IO
  83143. +/**
  83144. + *
  83145. + * @param ereq_nonport Pointer to the extended request part of the
  83146. + * usb_request structure defined in usb_gadget.h file.
  83147. + */
  83148. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83149. + uint8_t * buf, dwc_dma_t dma_buf,
  83150. + uint32_t buflen, int zero,
  83151. + void *req_handle, int atomic_alloc,
  83152. + void *ereq_nonport);
  83153. +
  83154. +#endif
  83155. +
  83156. +/** De-queue the specified data transfer that has not yet completed.
  83157. + *
  83158. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  83159. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  83160. + * Returns 0 on success. */
  83161. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83162. + void *req_handle);
  83163. +
  83164. +/** Halt (STALL) an endpoint or clear it.
  83165. + *
  83166. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  83167. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  83168. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  83169. + * Returns 0 on success. */
  83170. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  83171. +
  83172. +/** This function */
  83173. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  83174. +
  83175. +/** This function should be called on every hardware interrupt */
  83176. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  83177. +
  83178. +/** This function returns current frame number */
  83179. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  83180. +
  83181. +/**
  83182. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  83183. + * For isochronous transfers duble buffering is used.
  83184. + * After processing each of buffers comlete callback will be called with
  83185. + * status for each transaction.
  83186. + *
  83187. + * @param pcd The PCD
  83188. + * @param ep_handle The handle of the endpoint
  83189. + * @param buf0 The virtual address of first data buffer
  83190. + * @param buf1 The virtual address of second data buffer
  83191. + * @param dma0 The DMA address of first data buffer
  83192. + * @param dma1 The DMA address of second data buffer
  83193. + * @param sync_frame Data pattern frame number
  83194. + * @param dp_frame Data size for pattern frame
  83195. + * @param data_per_frame Data size for regular frame
  83196. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  83197. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  83198. + * @param req_handle Handle of ISOC request
  83199. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  83200. + * internal data structures.
  83201. + *
  83202. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  83203. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  83204. + * Returns -DW_E_SHUTDOWN for any other error.
  83205. + * Returns 0 on success
  83206. + */
  83207. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  83208. + uint8_t * buf0, uint8_t * buf1,
  83209. + dwc_dma_t dma0, dwc_dma_t dma1,
  83210. + int sync_frame, int dp_frame,
  83211. + int data_per_frame, int start_frame,
  83212. + int buf_proc_intrvl, void *req_handle,
  83213. + int atomic_alloc);
  83214. +
  83215. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  83216. + *
  83217. + * @param pcd The PCD
  83218. + * @param ep_handle The handle of the endpoint
  83219. + * @param req_handle Handle of ISOC request
  83220. + *
  83221. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  83222. + * Returns 0 on success
  83223. + */
  83224. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  83225. + void *req_handle);
  83226. +
  83227. +/** Get ISOC packet status.
  83228. + *
  83229. + * @param pcd The PCD
  83230. + * @param ep_handle The handle of the endpoint
  83231. + * @param iso_req_handle Isochronoush request handle
  83232. + * @param packet Number of packet
  83233. + * @param status Out parameter for returning status
  83234. + * @param actual Out parameter for returning actual length
  83235. + * @param offset Out parameter for returning offset
  83236. + *
  83237. + */
  83238. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  83239. + void *ep_handle,
  83240. + void *iso_req_handle, int packet,
  83241. + int *status, int *actual,
  83242. + int *offset);
  83243. +
  83244. +/** Get ISOC packet count.
  83245. + *
  83246. + * @param pcd The PCD
  83247. + * @param ep_handle The handle of the endpoint
  83248. + * @param iso_req_handle
  83249. + */
  83250. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  83251. + void *ep_handle,
  83252. + void *iso_req_handle);
  83253. +
  83254. +/** This function starts the SRP Protocol if no session is in progress. If
  83255. + * a session is already in progress, but the device is suspended,
  83256. + * remote wakeup signaling is started.
  83257. + */
  83258. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  83259. +
  83260. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  83261. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  83262. +
  83263. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  83264. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  83265. +
  83266. +/** Initiate SRP */
  83267. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  83268. +
  83269. +/** Starts remote wakeup signaling. */
  83270. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  83271. +
  83272. +/** Starts micorsecond soft disconnect. */
  83273. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  83274. +/** This function returns whether device is dualspeed.*/
  83275. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  83276. +
  83277. +/** This function returns whether device is otg. */
  83278. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  83279. +
  83280. +/** These functions allow to get hnp parameters */
  83281. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  83282. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  83283. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  83284. +
  83285. +/** CFI specific Interface functions */
  83286. +/** Allocate a cfi buffer */
  83287. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  83288. + dwc_dma_t * addr, size_t buflen,
  83289. + int flags);
  83290. +
  83291. +/******************************************************************************/
  83292. +
  83293. +/** @} */
  83294. +
  83295. +#endif /* __DWC_PCD_IF_H__ */
  83296. +
  83297. +#endif /* DWC_HOST_ONLY */
  83298. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  83299. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  83300. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-03-13 12:46:39.520097997 +0100
  83301. @@ -0,0 +1,5147 @@
  83302. +/* ==========================================================================
  83303. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  83304. + * $Revision: #116 $
  83305. + * $Date: 2012/08/10 $
  83306. + * $Change: 2047372 $
  83307. + *
  83308. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  83309. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  83310. + * otherwise expressly agreed to in writing between Synopsys and you.
  83311. + *
  83312. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  83313. + * any End User Software License Agreement or Agreement for Licensed Product
  83314. + * with Synopsys or any supplement thereto. You are permitted to use and
  83315. + * redistribute this Software in source and binary forms, with or without
  83316. + * modification, provided that redistributions of source code must retain this
  83317. + * notice. You may not view, use, disclose, copy or distribute this file or
  83318. + * any information contained herein except pursuant to this license grant from
  83319. + * Synopsys. If you do not agree with this notice, including the disclaimer
  83320. + * below, then you are not authorized to use the Software.
  83321. + *
  83322. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  83323. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  83324. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  83325. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  83326. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  83327. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  83328. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  83329. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  83330. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  83331. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  83332. + * DAMAGE.
  83333. + * ========================================================================== */
  83334. +#ifndef DWC_HOST_ONLY
  83335. +
  83336. +#include "dwc_otg_pcd.h"
  83337. +
  83338. +#ifdef DWC_UTE_CFI
  83339. +#include "dwc_otg_cfi.h"
  83340. +#endif
  83341. +
  83342. +#ifdef DWC_UTE_PER_IO
  83343. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  83344. +#endif
  83345. +//#define PRINT_CFI_DMA_DESCS
  83346. +
  83347. +#define DEBUG_EP0
  83348. +
  83349. +/**
  83350. + * This function updates OTG.
  83351. + */
  83352. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  83353. +{
  83354. +
  83355. + if (reset) {
  83356. + pcd->b_hnp_enable = 0;
  83357. + pcd->a_hnp_support = 0;
  83358. + pcd->a_alt_hnp_support = 0;
  83359. + }
  83360. +
  83361. + if (pcd->fops->hnp_changed) {
  83362. + pcd->fops->hnp_changed(pcd);
  83363. + }
  83364. +}
  83365. +
  83366. +/** @file
  83367. + * This file contains the implementation of the PCD Interrupt handlers.
  83368. + *
  83369. + * The PCD handles the device interrupts. Many conditions can cause a
  83370. + * device interrupt. When an interrupt occurs, the device interrupt
  83371. + * service routine determines the cause of the interrupt and
  83372. + * dispatches handling to the appropriate function. These interrupt
  83373. + * handling functions are described below.
  83374. + * All interrupt registers are processed from LSB to MSB.
  83375. + */
  83376. +
  83377. +/**
  83378. + * This function prints the ep0 state for debug purposes.
  83379. + */
  83380. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  83381. +{
  83382. +#ifdef DEBUG
  83383. + char str[40];
  83384. +
  83385. + switch (pcd->ep0state) {
  83386. + case EP0_DISCONNECT:
  83387. + dwc_strcpy(str, "EP0_DISCONNECT");
  83388. + break;
  83389. + case EP0_IDLE:
  83390. + dwc_strcpy(str, "EP0_IDLE");
  83391. + break;
  83392. + case EP0_IN_DATA_PHASE:
  83393. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  83394. + break;
  83395. + case EP0_OUT_DATA_PHASE:
  83396. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  83397. + break;
  83398. + case EP0_IN_STATUS_PHASE:
  83399. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  83400. + break;
  83401. + case EP0_OUT_STATUS_PHASE:
  83402. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  83403. + break;
  83404. + case EP0_STALL:
  83405. + dwc_strcpy(str, "EP0_STALL");
  83406. + break;
  83407. + default:
  83408. + dwc_strcpy(str, "EP0_INVALID");
  83409. + }
  83410. +
  83411. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  83412. +#endif
  83413. +}
  83414. +
  83415. +/**
  83416. + * This function calculate the size of the payload in the memory
  83417. + * for out endpoints and prints size for debug purposes(used in
  83418. + * 2.93a DevOutNak feature).
  83419. + */
  83420. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  83421. +{
  83422. +#ifdef DEBUG
  83423. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  83424. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  83425. + int pack_num;
  83426. + unsigned payload;
  83427. +
  83428. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  83429. + deptsiz_updt.d32 =
  83430. + DWC_READ_REG32(&pcd->core_if->dev_if->
  83431. + out_ep_regs[ep->num]->doeptsiz);
  83432. + /* Payload will be */
  83433. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  83434. + /* Packet count is decremented every time a packet
  83435. + * is written to the RxFIFO not in to the external memory
  83436. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  83437. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  83438. + DWC_DEBUGPL(DBG_PCDV,
  83439. + "Payload for EP%d-%s\n",
  83440. + ep->num, (ep->is_in ? "IN" : "OUT"));
  83441. + DWC_DEBUGPL(DBG_PCDV,
  83442. + "Number of transfered bytes = 0x%08x\n", payload);
  83443. + DWC_DEBUGPL(DBG_PCDV,
  83444. + "Number of transfered packets = %d\n", pack_num);
  83445. +#endif
  83446. +}
  83447. +
  83448. +
  83449. +#ifdef DWC_UTE_CFI
  83450. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  83451. + const uint8_t * epname, int descnum)
  83452. +{
  83453. + CFI_INFO
  83454. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  83455. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  83456. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  83457. + ddesc->status.b.bs);
  83458. +}
  83459. +#endif
  83460. +
  83461. +/**
  83462. + * This function returns pointer to in ep struct with number ep_num
  83463. + */
  83464. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  83465. +{
  83466. + int i;
  83467. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  83468. + if (ep_num == 0) {
  83469. + return &pcd->ep0;
  83470. + } else {
  83471. + for (i = 0; i < num_in_eps; ++i) {
  83472. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  83473. + return &pcd->in_ep[i];
  83474. + }
  83475. + return 0;
  83476. + }
  83477. +}
  83478. +
  83479. +/**
  83480. + * This function returns pointer to out ep struct with number ep_num
  83481. + */
  83482. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  83483. +{
  83484. + int i;
  83485. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  83486. + if (ep_num == 0) {
  83487. + return &pcd->ep0;
  83488. + } else {
  83489. + for (i = 0; i < num_out_eps; ++i) {
  83490. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  83491. + return &pcd->out_ep[i];
  83492. + }
  83493. + return 0;
  83494. + }
  83495. +}
  83496. +
  83497. +/**
  83498. + * This functions gets a pointer to an EP from the wIndex address
  83499. + * value of the control request.
  83500. + */
  83501. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  83502. +{
  83503. + dwc_otg_pcd_ep_t *ep;
  83504. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  83505. +
  83506. + if (ep_num == 0) {
  83507. + ep = &pcd->ep0;
  83508. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  83509. + ep = &pcd->in_ep[ep_num - 1];
  83510. + } else {
  83511. + ep = &pcd->out_ep[ep_num - 1];
  83512. + }
  83513. +
  83514. + return ep;
  83515. +}
  83516. +
  83517. +/**
  83518. + * This function checks the EP request queue, if the queue is not
  83519. + * empty the next request is started.
  83520. + */
  83521. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  83522. +{
  83523. + dwc_otg_pcd_request_t *req = 0;
  83524. + uint32_t max_transfer =
  83525. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  83526. +
  83527. +#ifdef DWC_UTE_CFI
  83528. + struct dwc_otg_pcd *pcd;
  83529. + pcd = ep->pcd;
  83530. +#endif
  83531. +
  83532. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83533. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83534. +
  83535. +#ifdef DWC_UTE_CFI
  83536. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  83537. + ep->dwc_ep.cfi_req_len = req->length;
  83538. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  83539. + } else {
  83540. +#endif
  83541. + /* Setup and start the Transfer */
  83542. + if (req->dw_align_buf) {
  83543. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  83544. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  83545. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  83546. + } else {
  83547. + ep->dwc_ep.dma_addr = req->dma;
  83548. + ep->dwc_ep.start_xfer_buff = req->buf;
  83549. + ep->dwc_ep.xfer_buff = req->buf;
  83550. + }
  83551. + ep->dwc_ep.sent_zlp = 0;
  83552. + ep->dwc_ep.total_len = req->length;
  83553. + ep->dwc_ep.xfer_len = 0;
  83554. + ep->dwc_ep.xfer_count = 0;
  83555. +
  83556. + ep->dwc_ep.maxxfer = max_transfer;
  83557. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  83558. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  83559. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  83560. + if (ep->dwc_ep.is_in) {
  83561. + if (ep->dwc_ep.maxxfer >
  83562. + DDMA_MAX_TRANSFER_SIZE) {
  83563. + ep->dwc_ep.maxxfer =
  83564. + DDMA_MAX_TRANSFER_SIZE;
  83565. + }
  83566. + } else {
  83567. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  83568. + ep->dwc_ep.maxxfer =
  83569. + out_max_xfer;
  83570. + }
  83571. + }
  83572. + }
  83573. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  83574. + ep->dwc_ep.maxxfer -=
  83575. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  83576. + }
  83577. + if (req->sent_zlp) {
  83578. + if ((ep->dwc_ep.total_len %
  83579. + ep->dwc_ep.maxpacket == 0)
  83580. + && (ep->dwc_ep.total_len != 0)) {
  83581. + ep->dwc_ep.sent_zlp = 1;
  83582. + }
  83583. +
  83584. + }
  83585. +#ifdef DWC_UTE_CFI
  83586. + }
  83587. +#endif
  83588. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  83589. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  83590. + DWC_PRINTF("There are no more ISOC requests \n");
  83591. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  83592. + }
  83593. +}
  83594. +
  83595. +/**
  83596. + * This function handles the SOF Interrupts. At this time the SOF
  83597. + * Interrupt is disabled.
  83598. + */
  83599. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  83600. +{
  83601. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83602. +
  83603. + gintsts_data_t gintsts;
  83604. +
  83605. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  83606. +
  83607. + /* Clear interrupt */
  83608. + gintsts.d32 = 0;
  83609. + gintsts.b.sofintr = 1;
  83610. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83611. +
  83612. + return 1;
  83613. +}
  83614. +
  83615. +/**
  83616. + * This function handles the Rx Status Queue Level Interrupt, which
  83617. + * indicates that there is a least one packet in the Rx FIFO. The
  83618. + * packets are moved from the FIFO to memory, where they will be
  83619. + * processed when the Endpoint Interrupt Register indicates Transfer
  83620. + * Complete or SETUP Phase Done.
  83621. + *
  83622. + * Repeat the following until the Rx Status Queue is empty:
  83623. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  83624. + * info
  83625. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  83626. + * and exit
  83627. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  83628. + * SETUP data to the buffer
  83629. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  83630. + * to the destination buffer
  83631. + */
  83632. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  83633. +{
  83634. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83635. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83636. + gintmsk_data_t gintmask = {.d32 = 0 };
  83637. + device_grxsts_data_t status;
  83638. + dwc_otg_pcd_ep_t *ep;
  83639. + gintsts_data_t gintsts;
  83640. +#ifdef DEBUG
  83641. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  83642. +#endif
  83643. +
  83644. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  83645. + /* Disable the Rx Status Queue Level interrupt */
  83646. + gintmask.b.rxstsqlvl = 1;
  83647. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  83648. +
  83649. + /* Get the Status from the top of the FIFO */
  83650. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  83651. +
  83652. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  83653. + "pktsts:%x Frame:%d(0x%0x)\n",
  83654. + status.b.epnum, status.b.bcnt,
  83655. + dpid_str[status.b.dpid],
  83656. + status.b.pktsts, status.b.fn, status.b.fn);
  83657. + /* Get pointer to EP structure */
  83658. + ep = get_out_ep(pcd, status.b.epnum);
  83659. +
  83660. + switch (status.b.pktsts) {
  83661. + case DWC_DSTS_GOUT_NAK:
  83662. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  83663. + break;
  83664. + case DWC_STS_DATA_UPDT:
  83665. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  83666. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  83667. + /** @todo NGS Check for buffer overflow? */
  83668. + dwc_otg_read_packet(core_if,
  83669. + ep->dwc_ep.xfer_buff,
  83670. + status.b.bcnt);
  83671. + ep->dwc_ep.xfer_count += status.b.bcnt;
  83672. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  83673. + }
  83674. + break;
  83675. + case DWC_STS_XFER_COMP:
  83676. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  83677. + break;
  83678. + case DWC_DSTS_SETUP_COMP:
  83679. +#ifdef DEBUG_EP0
  83680. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  83681. +#endif
  83682. + break;
  83683. + case DWC_DSTS_SETUP_UPDT:
  83684. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  83685. +#ifdef DEBUG_EP0
  83686. + DWC_DEBUGPL(DBG_PCD,
  83687. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  83688. + pcd->setup_pkt->req.bmRequestType,
  83689. + pcd->setup_pkt->req.bRequest,
  83690. + UGETW(pcd->setup_pkt->req.wValue),
  83691. + UGETW(pcd->setup_pkt->req.wIndex),
  83692. + UGETW(pcd->setup_pkt->req.wLength));
  83693. +#endif
  83694. + ep->dwc_ep.xfer_count += status.b.bcnt;
  83695. + break;
  83696. + default:
  83697. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  83698. + status.b.pktsts);
  83699. + break;
  83700. + }
  83701. +
  83702. + /* Enable the Rx Status Queue Level interrupt */
  83703. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  83704. + /* Clear interrupt */
  83705. + gintsts.d32 = 0;
  83706. + gintsts.b.rxstsqlvl = 1;
  83707. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  83708. +
  83709. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  83710. + return 1;
  83711. +}
  83712. +
  83713. +/**
  83714. + * This function examines the Device IN Token Learning Queue to
  83715. + * determine the EP number of the last IN token received. This
  83716. + * implementation is for the Mass Storage device where there are only
  83717. + * 2 IN EPs (Control-IN and BULK-IN).
  83718. + *
  83719. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  83720. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  83721. + *
  83722. + * @param core_if Programming view of DWC_otg controller.
  83723. + *
  83724. + */
  83725. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  83726. +{
  83727. + dwc_otg_device_global_regs_t *dev_global_regs =
  83728. + core_if->dev_if->dev_global_regs;
  83729. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  83730. + /* Number of Token Queue Registers */
  83731. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  83732. + dtknq1_data_t dtknqr1;
  83733. + uint32_t in_tkn_epnums[4];
  83734. + int ndx = 0;
  83735. + int i = 0;
  83736. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  83737. + int epnum = 0;
  83738. +
  83739. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  83740. +
  83741. + /* Read the DTKNQ Registers */
  83742. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  83743. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  83744. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  83745. + in_tkn_epnums[i]);
  83746. + if (addr == &dev_global_regs->dvbusdis) {
  83747. + addr = &dev_global_regs->dtknqr3_dthrctl;
  83748. + } else {
  83749. + ++addr;
  83750. + }
  83751. +
  83752. + }
  83753. +
  83754. + /* Copy the DTKNQR1 data to the bit field. */
  83755. + dtknqr1.d32 = in_tkn_epnums[0];
  83756. + /* Get the EP numbers */
  83757. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  83758. + ndx = dtknqr1.b.intknwptr - 1;
  83759. +
  83760. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  83761. + if (ndx == -1) {
  83762. + /** @todo Find a simpler way to calculate the max
  83763. + * queue position.*/
  83764. + int cnt = TOKEN_Q_DEPTH;
  83765. + if (TOKEN_Q_DEPTH <= 6) {
  83766. + cnt = TOKEN_Q_DEPTH - 1;
  83767. + } else if (TOKEN_Q_DEPTH <= 14) {
  83768. + cnt = TOKEN_Q_DEPTH - 7;
  83769. + } else if (TOKEN_Q_DEPTH <= 22) {
  83770. + cnt = TOKEN_Q_DEPTH - 15;
  83771. + } else {
  83772. + cnt = TOKEN_Q_DEPTH - 23;
  83773. + }
  83774. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  83775. + } else {
  83776. + if (ndx <= 5) {
  83777. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  83778. + } else if (ndx <= 13) {
  83779. + ndx -= 6;
  83780. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  83781. + } else if (ndx <= 21) {
  83782. + ndx -= 14;
  83783. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  83784. + } else if (ndx <= 29) {
  83785. + ndx -= 22;
  83786. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  83787. + }
  83788. + }
  83789. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  83790. + return epnum;
  83791. +}
  83792. +
  83793. +/**
  83794. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  83795. + * The active request is checked for the next packet to be loaded into
  83796. + * the non-periodic Tx FIFO.
  83797. + */
  83798. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  83799. +{
  83800. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83801. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83802. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  83803. + gnptxsts_data_t txstatus = {.d32 = 0 };
  83804. + gintsts_data_t gintsts;
  83805. +
  83806. + int epnum = 0;
  83807. + dwc_otg_pcd_ep_t *ep = 0;
  83808. + uint32_t len = 0;
  83809. + int dwords;
  83810. +
  83811. + /* Get the epnum from the IN Token Learning Queue. */
  83812. + epnum = get_ep_of_last_in_token(core_if);
  83813. + ep = get_in_ep(pcd, epnum);
  83814. +
  83815. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  83816. +
  83817. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  83818. +
  83819. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83820. + if (len > ep->dwc_ep.maxpacket) {
  83821. + len = ep->dwc_ep.maxpacket;
  83822. + }
  83823. + dwords = (len + 3) / 4;
  83824. +
  83825. + /* While there is space in the queue and space in the FIFO and
  83826. + * More data to tranfer, Write packets to the Tx FIFO */
  83827. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  83828. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  83829. +
  83830. + while (txstatus.b.nptxqspcavail > 0 &&
  83831. + txstatus.b.nptxfspcavail > dwords &&
  83832. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  83833. + /* Write the FIFO */
  83834. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  83835. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83836. +
  83837. + if (len > ep->dwc_ep.maxpacket) {
  83838. + len = ep->dwc_ep.maxpacket;
  83839. + }
  83840. +
  83841. + dwords = (len + 3) / 4;
  83842. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  83843. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  83844. + }
  83845. +
  83846. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  83847. + DWC_READ_REG32(&global_regs->gnptxsts));
  83848. +
  83849. + /* Clear interrupt */
  83850. + gintsts.d32 = 0;
  83851. + gintsts.b.nptxfempty = 1;
  83852. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  83853. +
  83854. + return 1;
  83855. +}
  83856. +
  83857. +/**
  83858. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  83859. + * The active request is checked for the next packet to be loaded into
  83860. + * apropriate Tx FIFO.
  83861. + */
  83862. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  83863. +{
  83864. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83865. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83866. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  83867. + dtxfsts_data_t txstatus = {.d32 = 0 };
  83868. + dwc_otg_pcd_ep_t *ep = 0;
  83869. + uint32_t len = 0;
  83870. + int dwords;
  83871. +
  83872. + ep = get_in_ep(pcd, epnum);
  83873. +
  83874. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  83875. +
  83876. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  83877. +
  83878. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83879. +
  83880. + if (len > ep->dwc_ep.maxpacket) {
  83881. + len = ep->dwc_ep.maxpacket;
  83882. + }
  83883. +
  83884. + dwords = (len + 3) / 4;
  83885. +
  83886. + /* While there is space in the queue and space in the FIFO and
  83887. + * More data to tranfer, Write packets to the Tx FIFO */
  83888. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  83889. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  83890. +
  83891. + while (txstatus.b.txfspcavail > dwords &&
  83892. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  83893. + ep->dwc_ep.xfer_len != 0) {
  83894. + /* Write the FIFO */
  83895. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  83896. +
  83897. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83898. + if (len > ep->dwc_ep.maxpacket) {
  83899. + len = ep->dwc_ep.maxpacket;
  83900. + }
  83901. +
  83902. + dwords = (len + 3) / 4;
  83903. + txstatus.d32 =
  83904. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  83905. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  83906. + txstatus.d32);
  83907. + }
  83908. +
  83909. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  83910. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  83911. +
  83912. + return 1;
  83913. +}
  83914. +
  83915. +/**
  83916. + * This function is called when the Device is disconnected. It stops
  83917. + * any active requests and informs the Gadget driver of the
  83918. + * disconnect.
  83919. + */
  83920. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  83921. +{
  83922. + int i, num_in_eps, num_out_eps;
  83923. + dwc_otg_pcd_ep_t *ep;
  83924. +
  83925. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83926. +
  83927. + DWC_SPINLOCK(pcd->lock);
  83928. +
  83929. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  83930. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  83931. +
  83932. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  83933. + /* don't disconnect drivers more than once */
  83934. + if (pcd->ep0state == EP0_DISCONNECT) {
  83935. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  83936. + DWC_SPINUNLOCK(pcd->lock);
  83937. + return;
  83938. + }
  83939. + pcd->ep0state = EP0_DISCONNECT;
  83940. +
  83941. + /* Reset the OTG state. */
  83942. + dwc_otg_pcd_update_otg(pcd, 1);
  83943. +
  83944. + /* Disable the NP Tx Fifo Empty Interrupt. */
  83945. + intr_mask.b.nptxfempty = 1;
  83946. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83947. + intr_mask.d32, 0);
  83948. +
  83949. + /* Flush the FIFOs */
  83950. + /**@todo NGS Flush Periodic FIFOs */
  83951. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  83952. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  83953. +
  83954. + /* prevent new request submissions, kill any outstanding requests */
  83955. + ep = &pcd->ep0;
  83956. + dwc_otg_request_nuke(ep);
  83957. + /* prevent new request submissions, kill any outstanding requests */
  83958. + for (i = 0; i < num_in_eps; i++) {
  83959. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  83960. + dwc_otg_request_nuke(ep);
  83961. + }
  83962. + /* prevent new request submissions, kill any outstanding requests */
  83963. + for (i = 0; i < num_out_eps; i++) {
  83964. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  83965. + dwc_otg_request_nuke(ep);
  83966. + }
  83967. +
  83968. + /* report disconnect; the driver is already quiesced */
  83969. + if (pcd->fops->disconnect) {
  83970. + DWC_SPINUNLOCK(pcd->lock);
  83971. + pcd->fops->disconnect(pcd);
  83972. + DWC_SPINLOCK(pcd->lock);
  83973. + }
  83974. + DWC_SPINUNLOCK(pcd->lock);
  83975. +}
  83976. +
  83977. +/**
  83978. + * This interrupt indicates that ...
  83979. + */
  83980. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  83981. +{
  83982. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83983. + gintsts_data_t gintsts;
  83984. +
  83985. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  83986. + intr_mask.b.i2cintr = 1;
  83987. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83988. + intr_mask.d32, 0);
  83989. +
  83990. + /* Clear interrupt */
  83991. + gintsts.d32 = 0;
  83992. + gintsts.b.i2cintr = 1;
  83993. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83994. + gintsts.d32);
  83995. + return 1;
  83996. +}
  83997. +
  83998. +/**
  83999. + * This interrupt indicates that ...
  84000. + */
  84001. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  84002. +{
  84003. + gintsts_data_t gintsts;
  84004. +#if defined(VERBOSE)
  84005. + DWC_PRINTF("Early Suspend Detected\n");
  84006. +#endif
  84007. +
  84008. + /* Clear interrupt */
  84009. + gintsts.d32 = 0;
  84010. + gintsts.b.erlysuspend = 1;
  84011. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  84012. + gintsts.d32);
  84013. + return 1;
  84014. +}
  84015. +
  84016. +/**
  84017. + * This function configures EPO to receive SETUP packets.
  84018. + *
  84019. + * @todo NGS: Update the comments from the HW FS.
  84020. + *
  84021. + * -# Program the following fields in the endpoint specific registers
  84022. + * for Control OUT EP 0, in order to receive a setup packet
  84023. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  84024. + * setup packets)
  84025. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  84026. + * to back setup packets)
  84027. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  84028. + * store any setup packets received
  84029. + *
  84030. + * @param core_if Programming view of DWC_otg controller.
  84031. + * @param pcd Programming view of the PCD.
  84032. + */
  84033. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  84034. + dwc_otg_pcd_t * pcd)
  84035. +{
  84036. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84037. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  84038. + dwc_otg_dev_dma_desc_t *dma_desc;
  84039. + depctl_data_t doepctl = {.d32 = 0 };
  84040. +
  84041. +#ifdef VERBOSE
  84042. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  84043. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  84044. +#endif
  84045. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  84046. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  84047. + if (doepctl.b.epena) {
  84048. + return;
  84049. + }
  84050. + }
  84051. +
  84052. + doeptsize0.b.supcnt = 3;
  84053. + doeptsize0.b.pktcnt = 1;
  84054. + doeptsize0.b.xfersize = 8 * 3;
  84055. +
  84056. + if (core_if->dma_enable) {
  84057. + if (!core_if->dma_desc_enable) {
  84058. + /** put here as for Hermes mode deptisz register should not be written */
  84059. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  84060. + doeptsize0.d32);
  84061. +
  84062. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  84063. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  84064. + pcd->setup_pkt_dma_handle);
  84065. + } else {
  84066. + dev_if->setup_desc_index =
  84067. + (dev_if->setup_desc_index + 1) & 1;
  84068. + dma_desc =
  84069. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  84070. +
  84071. + /** DMA Descriptor Setup */
  84072. + dma_desc->status.b.bs = BS_HOST_BUSY;
  84073. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  84074. + dma_desc->status.b.sr = 0;
  84075. + dma_desc->status.b.mtrf = 0;
  84076. + }
  84077. + dma_desc->status.b.l = 1;
  84078. + dma_desc->status.b.ioc = 1;
  84079. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  84080. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  84081. + dma_desc->status.b.sts = 0;
  84082. + dma_desc->status.b.bs = BS_HOST_READY;
  84083. +
  84084. + /** DOEPDMA0 Register write */
  84085. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  84086. + dev_if->dma_setup_desc_addr
  84087. + [dev_if->setup_desc_index]);
  84088. + }
  84089. +
  84090. + } else {
  84091. + /** put here as for Hermes mode deptisz register should not be written */
  84092. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  84093. + doeptsize0.d32);
  84094. + }
  84095. +
  84096. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  84097. + doepctl.d32 = 0;
  84098. + doepctl.b.epena = 1;
  84099. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  84100. + doepctl.b.cnak = 1;
  84101. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  84102. + } else {
  84103. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  84104. + }
  84105. +
  84106. +#ifdef VERBOSE
  84107. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  84108. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  84109. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  84110. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  84111. +#endif
  84112. +}
  84113. +
  84114. +/**
  84115. + * This interrupt occurs when a USB Reset is detected. When the USB
  84116. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  84117. + * EP0 state is set to IDLE.
  84118. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  84119. + * -# Unmask the following interrupt bits
  84120. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  84121. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  84122. + * - DOEPMSK.SETUP = 1
  84123. + * - DOEPMSK.XferCompl = 1
  84124. + * - DIEPMSK.XferCompl = 1
  84125. + * - DIEPMSK.TimeOut = 1
  84126. + * -# Program the following fields in the endpoint specific registers
  84127. + * for Control OUT EP 0, in order to receive a setup packet
  84128. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  84129. + * setup packets)
  84130. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  84131. + * to back setup packets)
  84132. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  84133. + * store any setup packets received
  84134. + * At this point, all the required initialization, except for enabling
  84135. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  84136. + */
  84137. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  84138. +{
  84139. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84140. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84141. + depctl_data_t doepctl = {.d32 = 0 };
  84142. + depctl_data_t diepctl = {.d32 = 0 };
  84143. + daint_data_t daintmsk = {.d32 = 0 };
  84144. + doepmsk_data_t doepmsk = {.d32 = 0 };
  84145. + diepmsk_data_t diepmsk = {.d32 = 0 };
  84146. + dcfg_data_t dcfg = {.d32 = 0 };
  84147. + grstctl_t resetctl = {.d32 = 0 };
  84148. + dctl_data_t dctl = {.d32 = 0 };
  84149. + int i = 0;
  84150. + gintsts_data_t gintsts;
  84151. + pcgcctl_data_t power = {.d32 = 0 };
  84152. +
  84153. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  84154. + if (power.b.stoppclk) {
  84155. + power.d32 = 0;
  84156. + power.b.stoppclk = 1;
  84157. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  84158. +
  84159. + power.b.pwrclmp = 1;
  84160. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  84161. +
  84162. + power.b.rstpdwnmodule = 1;
  84163. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  84164. + }
  84165. +
  84166. + core_if->lx_state = DWC_OTG_L0;
  84167. +
  84168. + DWC_PRINTF("USB RESET\n");
  84169. +#ifdef DWC_EN_ISOC
  84170. + for (i = 1; i < 16; ++i) {
  84171. + dwc_otg_pcd_ep_t *ep;
  84172. + dwc_ep_t *dwc_ep;
  84173. + ep = get_in_ep(pcd, i);
  84174. + if (ep != 0) {
  84175. + dwc_ep = &ep->dwc_ep;
  84176. + dwc_ep->next_frame = 0xffffffff;
  84177. + }
  84178. + }
  84179. +#endif /* DWC_EN_ISOC */
  84180. +
  84181. + /* reset the HNP settings */
  84182. + dwc_otg_pcd_update_otg(pcd, 1);
  84183. +
  84184. + /* Clear the Remote Wakeup Signalling */
  84185. + dctl.b.rmtwkupsig = 1;
  84186. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  84187. +
  84188. + /* Set NAK for all OUT EPs */
  84189. + doepctl.b.snak = 1;
  84190. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  84191. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  84192. + }
  84193. +
  84194. + /* Flush the NP Tx FIFO */
  84195. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  84196. + /* Flush the Learning Queue */
  84197. + resetctl.b.intknqflsh = 1;
  84198. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  84199. +
  84200. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  84201. + core_if->start_predict = 0;
  84202. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  84203. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  84204. + }
  84205. + core_if->nextep_seq[0] = 0;
  84206. + core_if->first_in_nextep_seq = 0;
  84207. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  84208. + diepctl.b.nextep = 0;
  84209. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  84210. +
  84211. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  84212. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  84213. + dcfg.b.epmscnt = 2;
  84214. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  84215. +
  84216. + DWC_DEBUGPL(DBG_PCDV,
  84217. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  84218. + __func__, core_if->first_in_nextep_seq);
  84219. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  84220. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  84221. + }
  84222. + }
  84223. +
  84224. + if (core_if->multiproc_int_enable) {
  84225. + daintmsk.b.inep0 = 1;
  84226. + daintmsk.b.outep0 = 1;
  84227. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  84228. + daintmsk.d32);
  84229. +
  84230. + doepmsk.b.setup = 1;
  84231. + doepmsk.b.xfercompl = 1;
  84232. + doepmsk.b.ahberr = 1;
  84233. + doepmsk.b.epdisabled = 1;
  84234. +
  84235. + if ((core_if->dma_desc_enable) ||
  84236. + (core_if->dma_enable
  84237. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  84238. + doepmsk.b.stsphsercvd = 1;
  84239. + }
  84240. + if (core_if->dma_desc_enable)
  84241. + doepmsk.b.bna = 1;
  84242. +/*
  84243. + doepmsk.b.babble = 1;
  84244. + doepmsk.b.nyet = 1;
  84245. +
  84246. + if (core_if->dma_enable) {
  84247. + doepmsk.b.nak = 1;
  84248. + }
  84249. +*/
  84250. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  84251. + doepmsk.d32);
  84252. +
  84253. + diepmsk.b.xfercompl = 1;
  84254. + diepmsk.b.timeout = 1;
  84255. + diepmsk.b.epdisabled = 1;
  84256. + diepmsk.b.ahberr = 1;
  84257. + diepmsk.b.intknepmis = 1;
  84258. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  84259. + diepmsk.b.intknepmis = 0;
  84260. +
  84261. +/* if (core_if->dma_desc_enable) {
  84262. + diepmsk.b.bna = 1;
  84263. + }
  84264. +*/
  84265. +/*
  84266. + if (core_if->dma_enable) {
  84267. + diepmsk.b.nak = 1;
  84268. + }
  84269. +*/
  84270. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  84271. + diepmsk.d32);
  84272. + } else {
  84273. + daintmsk.b.inep0 = 1;
  84274. + daintmsk.b.outep0 = 1;
  84275. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  84276. + daintmsk.d32);
  84277. +
  84278. + doepmsk.b.setup = 1;
  84279. + doepmsk.b.xfercompl = 1;
  84280. + doepmsk.b.ahberr = 1;
  84281. + doepmsk.b.epdisabled = 1;
  84282. +
  84283. + if ((core_if->dma_desc_enable) ||
  84284. + (core_if->dma_enable
  84285. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  84286. + doepmsk.b.stsphsercvd = 1;
  84287. + }
  84288. + if (core_if->dma_desc_enable)
  84289. + doepmsk.b.bna = 1;
  84290. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  84291. +
  84292. + diepmsk.b.xfercompl = 1;
  84293. + diepmsk.b.timeout = 1;
  84294. + diepmsk.b.epdisabled = 1;
  84295. + diepmsk.b.ahberr = 1;
  84296. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  84297. + diepmsk.b.intknepmis = 0;
  84298. +/*
  84299. + if (core_if->dma_desc_enable) {
  84300. + diepmsk.b.bna = 1;
  84301. + }
  84302. +*/
  84303. +
  84304. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  84305. + }
  84306. +
  84307. + /* Reset Device Address */
  84308. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  84309. + dcfg.b.devaddr = 0;
  84310. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  84311. +
  84312. + /* setup EP0 to receive SETUP packets */
  84313. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  84314. + ep0_out_start(core_if, pcd);
  84315. +
  84316. + /* Clear interrupt */
  84317. + gintsts.d32 = 0;
  84318. + gintsts.b.usbreset = 1;
  84319. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84320. +
  84321. + return 1;
  84322. +}
  84323. +
  84324. +/**
  84325. + * Get the device speed from the device status register and convert it
  84326. + * to USB speed constant.
  84327. + *
  84328. + * @param core_if Programming view of DWC_otg controller.
  84329. + */
  84330. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  84331. +{
  84332. + dsts_data_t dsts;
  84333. + int speed = 0;
  84334. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  84335. +
  84336. + switch (dsts.b.enumspd) {
  84337. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  84338. + speed = USB_SPEED_HIGH;
  84339. + break;
  84340. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  84341. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  84342. + speed = USB_SPEED_FULL;
  84343. + break;
  84344. +
  84345. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  84346. + speed = USB_SPEED_LOW;
  84347. + break;
  84348. + }
  84349. +
  84350. + return speed;
  84351. +}
  84352. +
  84353. +/**
  84354. + * Read the device status register and set the device speed in the
  84355. + * data structure.
  84356. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  84357. + */
  84358. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  84359. +{
  84360. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84361. + gintsts_data_t gintsts;
  84362. + gusbcfg_data_t gusbcfg;
  84363. + dwc_otg_core_global_regs_t *global_regs =
  84364. + GET_CORE_IF(pcd)->core_global_regs;
  84365. + uint8_t utmi16b, utmi8b;
  84366. + int speed;
  84367. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  84368. +
  84369. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  84370. + utmi16b = 6; //vahrama old value was 6;
  84371. + utmi8b = 9;
  84372. + } else {
  84373. + utmi16b = 4;
  84374. + utmi8b = 8;
  84375. + }
  84376. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84377. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  84378. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  84379. + }
  84380. +
  84381. +#ifdef DEBUG_EP0
  84382. + print_ep0_state(pcd);
  84383. +#endif
  84384. +
  84385. + if (pcd->ep0state == EP0_DISCONNECT) {
  84386. + pcd->ep0state = EP0_IDLE;
  84387. + } else if (pcd->ep0state == EP0_STALL) {
  84388. + pcd->ep0state = EP0_IDLE;
  84389. + }
  84390. +
  84391. + pcd->ep0state = EP0_IDLE;
  84392. +
  84393. + ep0->stopped = 0;
  84394. +
  84395. + speed = get_device_speed(GET_CORE_IF(pcd));
  84396. + pcd->fops->connect(pcd, speed);
  84397. +
  84398. + /* Set USB turnaround time based on device speed and PHY interface. */
  84399. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  84400. + if (speed == USB_SPEED_HIGH) {
  84401. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  84402. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  84403. + /* ULPI interface */
  84404. + gusbcfg.b.usbtrdtim = 9;
  84405. + }
  84406. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  84407. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  84408. + /* UTMI+ interface */
  84409. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  84410. + gusbcfg.b.usbtrdtim = utmi8b;
  84411. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  84412. + b.utmi_phy_data_width == 1) {
  84413. + gusbcfg.b.usbtrdtim = utmi16b;
  84414. + } else if (GET_CORE_IF(pcd)->
  84415. + core_params->phy_utmi_width == 8) {
  84416. + gusbcfg.b.usbtrdtim = utmi8b;
  84417. + } else {
  84418. + gusbcfg.b.usbtrdtim = utmi16b;
  84419. + }
  84420. + }
  84421. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  84422. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  84423. + /* UTMI+ OR ULPI interface */
  84424. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  84425. + /* ULPI interface */
  84426. + gusbcfg.b.usbtrdtim = 9;
  84427. + } else {
  84428. + /* UTMI+ interface */
  84429. + if (GET_CORE_IF(pcd)->
  84430. + core_params->phy_utmi_width == 16) {
  84431. + gusbcfg.b.usbtrdtim = utmi16b;
  84432. + } else {
  84433. + gusbcfg.b.usbtrdtim = utmi8b;
  84434. + }
  84435. + }
  84436. + }
  84437. + } else {
  84438. + /* Full or low speed */
  84439. + gusbcfg.b.usbtrdtim = 9;
  84440. + }
  84441. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  84442. +
  84443. + /* Clear interrupt */
  84444. + gintsts.d32 = 0;
  84445. + gintsts.b.enumdone = 1;
  84446. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  84447. + gintsts.d32);
  84448. + return 1;
  84449. +}
  84450. +
  84451. +/**
  84452. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  84453. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  84454. + * read all the data from the Rx FIFO.
  84455. + */
  84456. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  84457. +{
  84458. + gintmsk_data_t intr_mask = {.d32 = 0 };
  84459. + gintsts_data_t gintsts;
  84460. +
  84461. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  84462. + "ISOC Out Dropped");
  84463. +
  84464. + intr_mask.b.isooutdrop = 1;
  84465. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  84466. + intr_mask.d32, 0);
  84467. +
  84468. + /* Clear interrupt */
  84469. + gintsts.d32 = 0;
  84470. + gintsts.b.isooutdrop = 1;
  84471. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  84472. + gintsts.d32);
  84473. +
  84474. + return 1;
  84475. +}
  84476. +
  84477. +/**
  84478. + * This interrupt indicates the end of the portion of the micro-frame
  84479. + * for periodic transactions. If there is a periodic transaction for
  84480. + * the next frame, load the packets into the EP periodic Tx FIFO.
  84481. + */
  84482. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  84483. +{
  84484. + gintmsk_data_t intr_mask = {.d32 = 0 };
  84485. + gintsts_data_t gintsts;
  84486. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  84487. +
  84488. + intr_mask.b.eopframe = 1;
  84489. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  84490. + intr_mask.d32, 0);
  84491. +
  84492. + /* Clear interrupt */
  84493. + gintsts.d32 = 0;
  84494. + gintsts.b.eopframe = 1;
  84495. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  84496. + gintsts.d32);
  84497. +
  84498. + return 1;
  84499. +}
  84500. +
  84501. +/**
  84502. + * This interrupt indicates that EP of the packet on the top of the
  84503. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  84504. + *
  84505. + * The "Device IN Token Queue" Registers are read to determine the
  84506. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  84507. + * is flushed, so it can be reloaded in the order seen in the IN Token
  84508. + * Queue.
  84509. + */
  84510. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  84511. +{
  84512. + gintsts_data_t gintsts;
  84513. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84514. + dctl_data_t dctl;
  84515. + gintmsk_data_t intr_mask = {.d32 = 0 };
  84516. +
  84517. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  84518. + core_if->start_predict = 1;
  84519. +
  84520. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  84521. +
  84522. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  84523. + if (!gintsts.b.ginnakeff) {
  84524. + /* Disable EP Mismatch interrupt */
  84525. + intr_mask.d32 = 0;
  84526. + intr_mask.b.epmismatch = 1;
  84527. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  84528. + /* Enable the Global IN NAK Effective Interrupt */
  84529. + intr_mask.d32 = 0;
  84530. + intr_mask.b.ginnakeff = 1;
  84531. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  84532. + /* Set the global non-periodic IN NAK handshake */
  84533. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  84534. + dctl.b.sgnpinnak = 1;
  84535. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  84536. + } else {
  84537. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  84538. + }
  84539. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  84540. + * handler after Global IN NAK Effective interrupt will be asserted */
  84541. + }
  84542. + /* Clear interrupt */
  84543. + gintsts.d32 = 0;
  84544. + gintsts.b.epmismatch = 1;
  84545. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84546. +
  84547. + return 1;
  84548. +}
  84549. +
  84550. +/**
  84551. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  84552. + * core has stopped fetching data for IN endpoints due to the unavailability of
  84553. + * TxFIFO space or Request Queue space. This interrupt is used by the
  84554. + * application for an endpoint mismatch algorithm.
  84555. + *
  84556. + * @param pcd The PCD
  84557. + */
  84558. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  84559. +{
  84560. + gintsts_data_t gintsts;
  84561. + gintmsk_data_t gintmsk_data;
  84562. + dctl_data_t dctl;
  84563. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84564. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  84565. +
  84566. + /* Clear the global non-periodic IN NAK handshake */
  84567. + dctl.d32 = 0;
  84568. + dctl.b.cgnpinnak = 1;
  84569. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  84570. +
  84571. + /* Mask GINTSTS.FETSUSP interrupt */
  84572. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  84573. + gintmsk_data.b.fetsusp = 0;
  84574. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  84575. +
  84576. + /* Clear interrupt */
  84577. + gintsts.d32 = 0;
  84578. + gintsts.b.fetsusp = 1;
  84579. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84580. +
  84581. + return 1;
  84582. +}
  84583. +/**
  84584. + * This funcion stalls EP0.
  84585. + */
  84586. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  84587. +{
  84588. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84589. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  84590. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  84591. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  84592. +
  84593. + ep0->dwc_ep.is_in = 1;
  84594. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84595. + pcd->ep0.stopped = 1;
  84596. + pcd->ep0state = EP0_IDLE;
  84597. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  84598. +}
  84599. +
  84600. +/**
  84601. + * This functions delegates the setup command to the gadget driver.
  84602. + */
  84603. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  84604. + usb_device_request_t * ctrl)
  84605. +{
  84606. + int ret = 0;
  84607. + DWC_SPINUNLOCK(pcd->lock);
  84608. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  84609. + DWC_SPINLOCK(pcd->lock);
  84610. + if (ret < 0) {
  84611. + ep0_do_stall(pcd, ret);
  84612. + }
  84613. +
  84614. + /** @todo This is a g_file_storage gadget driver specific
  84615. + * workaround: a DELAYED_STATUS result from the fsg_setup
  84616. + * routine will result in the gadget queueing a EP0 IN status
  84617. + * phase for a two-stage control transfer. Exactly the same as
  84618. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  84619. + * specific request. Need a generic way to know when the gadget
  84620. + * driver will queue the status phase. Can we assume when we
  84621. + * call the gadget driver setup() function that it will always
  84622. + * queue and require the following flag? Need to look into
  84623. + * this.
  84624. + */
  84625. +
  84626. + if (ret == 256 + 999) {
  84627. + pcd->request_config = 1;
  84628. + }
  84629. +}
  84630. +
  84631. +#ifdef DWC_UTE_CFI
  84632. +/**
  84633. + * This functions delegates the CFI setup commands to the gadget driver.
  84634. + * This function will return a negative value to indicate a failure.
  84635. + */
  84636. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  84637. + struct cfi_usb_ctrlrequest *ctrl_req)
  84638. +{
  84639. + int ret = 0;
  84640. +
  84641. + if (pcd->fops && pcd->fops->cfi_setup) {
  84642. + DWC_SPINUNLOCK(pcd->lock);
  84643. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  84644. + DWC_SPINLOCK(pcd->lock);
  84645. + if (ret < 0) {
  84646. + ep0_do_stall(pcd, ret);
  84647. + return ret;
  84648. + }
  84649. + }
  84650. +
  84651. + return ret;
  84652. +}
  84653. +#endif
  84654. +
  84655. +/**
  84656. + * This function starts the Zero-Length Packet for the IN status phase
  84657. + * of a 2 stage control transfer.
  84658. + */
  84659. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  84660. +{
  84661. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84662. + if (pcd->ep0state == EP0_STALL) {
  84663. + return;
  84664. + }
  84665. +
  84666. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  84667. +
  84668. + /* Prepare for more SETUP Packets */
  84669. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  84670. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  84671. + && (pcd->core_if->dma_desc_enable)
  84672. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  84673. + DWC_DEBUGPL(DBG_PCDV,
  84674. + "Data terminated wait next packet in out_desc_addr\n");
  84675. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  84676. + pcd->data_terminated = 1;
  84677. + }
  84678. + ep0->dwc_ep.xfer_len = 0;
  84679. + ep0->dwc_ep.xfer_count = 0;
  84680. + ep0->dwc_ep.is_in = 1;
  84681. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  84682. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84683. +
  84684. + /* Prepare for more SETUP Packets */
  84685. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  84686. +}
  84687. +
  84688. +/**
  84689. + * This function starts the Zero-Length Packet for the OUT status phase
  84690. + * of a 2 stage control transfer.
  84691. + */
  84692. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  84693. +{
  84694. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84695. + if (pcd->ep0state == EP0_STALL) {
  84696. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  84697. + return;
  84698. + }
  84699. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  84700. +
  84701. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  84702. + ep0->dwc_ep.xfer_len = 0;
  84703. + ep0->dwc_ep.xfer_count = 0;
  84704. + ep0->dwc_ep.is_in = 0;
  84705. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  84706. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84707. +
  84708. + /* Prepare for more SETUP Packets */
  84709. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  84710. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  84711. + }
  84712. +}
  84713. +
  84714. +/**
  84715. + * Clear the EP halt (STALL) and if pending requests start the
  84716. + * transfer.
  84717. + */
  84718. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  84719. +{
  84720. + if (ep->dwc_ep.stall_clear_flag == 0)
  84721. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84722. +
  84723. + /* Reactive the EP */
  84724. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  84725. + if (ep->stopped) {
  84726. + ep->stopped = 0;
  84727. + /* If there is a request in the EP queue start it */
  84728. +
  84729. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  84730. + * epmismatch not yet implemented. */
  84731. +
  84732. + /*
  84733. + * Above fixme is solved by implmenting a tasklet to call the
  84734. + * start_next_request(), outside of interrupt context at some
  84735. + * time after the current time, after a clear-halt setup packet.
  84736. + * Still need to implement ep mismatch in the future if a gadget
  84737. + * ever uses more than one endpoint at once
  84738. + */
  84739. + ep->queue_sof = 1;
  84740. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  84741. + }
  84742. + /* Start Control Status Phase */
  84743. + do_setup_in_status_phase(pcd);
  84744. +}
  84745. +
  84746. +/**
  84747. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  84748. + * is sent from the host. The Device Control register is written with
  84749. + * the Test Mode bits set to the specified Test Mode. This is done as
  84750. + * a tasklet so that the "Status" phase of the control transfer
  84751. + * completes before transmitting the TEST packets.
  84752. + *
  84753. + * @todo This has not been tested since the tasklet struct was put
  84754. + * into the PCD struct!
  84755. + *
  84756. + */
  84757. +void do_test_mode(void *data)
  84758. +{
  84759. + dctl_data_t dctl;
  84760. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  84761. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84762. + int test_mode = pcd->test_mode;
  84763. +
  84764. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  84765. +
  84766. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  84767. + switch (test_mode) {
  84768. + case 1: // TEST_J
  84769. + dctl.b.tstctl = 1;
  84770. + break;
  84771. +
  84772. + case 2: // TEST_K
  84773. + dctl.b.tstctl = 2;
  84774. + break;
  84775. +
  84776. + case 3: // TEST_SE0_NAK
  84777. + dctl.b.tstctl = 3;
  84778. + break;
  84779. +
  84780. + case 4: // TEST_PACKET
  84781. + dctl.b.tstctl = 4;
  84782. + break;
  84783. +
  84784. + case 5: // TEST_FORCE_ENABLE
  84785. + dctl.b.tstctl = 5;
  84786. + break;
  84787. + }
  84788. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  84789. +}
  84790. +
  84791. +/**
  84792. + * This function process the GET_STATUS Setup Commands.
  84793. + */
  84794. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  84795. +{
  84796. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84797. + dwc_otg_pcd_ep_t *ep;
  84798. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84799. + uint16_t *status = pcd->status_buf;
  84800. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84801. +
  84802. +#ifdef DEBUG_EP0
  84803. + DWC_DEBUGPL(DBG_PCD,
  84804. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  84805. + ctrl.bmRequestType, ctrl.bRequest,
  84806. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84807. + UGETW(ctrl.wLength));
  84808. +#endif
  84809. +
  84810. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84811. + case UT_DEVICE:
  84812. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  84813. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  84814. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  84815. + DWC_PRINTF("OTG CAP - %d, %d\n",
  84816. + core_if->core_params->otg_cap,
  84817. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  84818. + if (core_if->otg_ver == 1
  84819. + && core_if->core_params->otg_cap ==
  84820. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84821. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  84822. + *otgsts = (core_if->otg_sts & 0x1);
  84823. + pcd->ep0_pending = 1;
  84824. + ep0->dwc_ep.start_xfer_buff =
  84825. + (uint8_t *) otgsts;
  84826. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  84827. + ep0->dwc_ep.dma_addr =
  84828. + pcd->status_buf_dma_handle;
  84829. + ep0->dwc_ep.xfer_len = 1;
  84830. + ep0->dwc_ep.xfer_count = 0;
  84831. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  84832. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  84833. + &ep0->dwc_ep);
  84834. + return;
  84835. + } else {
  84836. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84837. + return;
  84838. + }
  84839. + break;
  84840. + } else {
  84841. + *status = 0x1; /* Self powered */
  84842. + *status |= pcd->remote_wakeup_enable << 1;
  84843. + break;
  84844. + }
  84845. + case UT_INTERFACE:
  84846. + *status = 0;
  84847. + break;
  84848. +
  84849. + case UT_ENDPOINT:
  84850. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84851. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  84852. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84853. + return;
  84854. + }
  84855. + /** @todo check for EP stall */
  84856. + *status = ep->stopped;
  84857. + break;
  84858. + }
  84859. + pcd->ep0_pending = 1;
  84860. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  84861. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  84862. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  84863. + ep0->dwc_ep.xfer_len = 2;
  84864. + ep0->dwc_ep.xfer_count = 0;
  84865. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  84866. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84867. +}
  84868. +
  84869. +/**
  84870. + * This function process the SET_FEATURE Setup Commands.
  84871. + */
  84872. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  84873. +{
  84874. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84875. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  84876. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84877. + dwc_otg_pcd_ep_t *ep = 0;
  84878. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  84879. + gotgctl_data_t gotgctl = {.d32 = 0 };
  84880. +
  84881. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  84882. + ctrl.bmRequestType, ctrl.bRequest,
  84883. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84884. + UGETW(ctrl.wLength));
  84885. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  84886. +
  84887. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84888. + case UT_DEVICE:
  84889. + switch (UGETW(ctrl.wValue)) {
  84890. + case UF_DEVICE_REMOTE_WAKEUP:
  84891. + pcd->remote_wakeup_enable = 1;
  84892. + break;
  84893. +
  84894. + case UF_TEST_MODE:
  84895. + /* Setup the Test Mode tasklet to do the Test
  84896. + * Packet generation after the SETUP Status
  84897. + * phase has completed. */
  84898. +
  84899. + /** @todo This has not been tested since the
  84900. + * tasklet struct was put into the PCD
  84901. + * struct! */
  84902. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  84903. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  84904. + break;
  84905. +
  84906. + case UF_DEVICE_B_HNP_ENABLE:
  84907. + DWC_DEBUGPL(DBG_PCDV,
  84908. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  84909. +
  84910. + /* dev may initiate HNP */
  84911. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84912. + pcd->b_hnp_enable = 1;
  84913. + dwc_otg_pcd_update_otg(pcd, 0);
  84914. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  84915. + /**@todo Is the gotgctl.devhnpen cleared
  84916. + * by a USB Reset? */
  84917. + gotgctl.b.devhnpen = 1;
  84918. + gotgctl.b.hnpreq = 1;
  84919. + DWC_WRITE_REG32(&global_regs->gotgctl,
  84920. + gotgctl.d32);
  84921. + } else {
  84922. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84923. + return;
  84924. + }
  84925. + break;
  84926. +
  84927. + case UF_DEVICE_A_HNP_SUPPORT:
  84928. + /* RH port supports HNP */
  84929. + DWC_DEBUGPL(DBG_PCDV,
  84930. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  84931. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84932. + pcd->a_hnp_support = 1;
  84933. + dwc_otg_pcd_update_otg(pcd, 0);
  84934. + } else {
  84935. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84936. + return;
  84937. + }
  84938. + break;
  84939. +
  84940. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  84941. + /* other RH port does */
  84942. + DWC_DEBUGPL(DBG_PCDV,
  84943. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  84944. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84945. + pcd->a_alt_hnp_support = 1;
  84946. + dwc_otg_pcd_update_otg(pcd, 0);
  84947. + } else {
  84948. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84949. + return;
  84950. + }
  84951. + break;
  84952. +
  84953. + default:
  84954. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84955. + return;
  84956. +
  84957. + }
  84958. + do_setup_in_status_phase(pcd);
  84959. + break;
  84960. +
  84961. + case UT_INTERFACE:
  84962. + do_gadget_setup(pcd, &ctrl);
  84963. + break;
  84964. +
  84965. + case UT_ENDPOINT:
  84966. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  84967. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84968. + if (ep == 0) {
  84969. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84970. + return;
  84971. + }
  84972. + ep->stopped = 1;
  84973. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  84974. + }
  84975. + do_setup_in_status_phase(pcd);
  84976. + break;
  84977. + }
  84978. +}
  84979. +
  84980. +/**
  84981. + * This function process the CLEAR_FEATURE Setup Commands.
  84982. + */
  84983. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  84984. +{
  84985. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84986. + dwc_otg_pcd_ep_t *ep = 0;
  84987. +
  84988. + DWC_DEBUGPL(DBG_PCD,
  84989. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  84990. + ctrl.bmRequestType, ctrl.bRequest,
  84991. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84992. + UGETW(ctrl.wLength));
  84993. +
  84994. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84995. + case UT_DEVICE:
  84996. + switch (UGETW(ctrl.wValue)) {
  84997. + case UF_DEVICE_REMOTE_WAKEUP:
  84998. + pcd->remote_wakeup_enable = 0;
  84999. + break;
  85000. +
  85001. + case UF_TEST_MODE:
  85002. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  85003. + break;
  85004. +
  85005. + default:
  85006. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  85007. + return;
  85008. + }
  85009. + do_setup_in_status_phase(pcd);
  85010. + break;
  85011. +
  85012. + case UT_ENDPOINT:
  85013. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  85014. + if (ep == 0) {
  85015. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  85016. + return;
  85017. + }
  85018. +
  85019. + pcd_clear_halt(pcd, ep);
  85020. +
  85021. + break;
  85022. + }
  85023. +}
  85024. +
  85025. +/**
  85026. + * This function process the SET_ADDRESS Setup Commands.
  85027. + */
  85028. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  85029. +{
  85030. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  85031. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  85032. +
  85033. + if (ctrl.bmRequestType == UT_DEVICE) {
  85034. + dcfg_data_t dcfg = {.d32 = 0 };
  85035. +
  85036. +#ifdef DEBUG_EP0
  85037. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  85038. +#endif
  85039. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  85040. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  85041. + do_setup_in_status_phase(pcd);
  85042. + }
  85043. +}
  85044. +
  85045. +/**
  85046. + * This function processes SETUP commands. In Linux, the USB Command
  85047. + * processing is done in two places - the first being the PCD and the
  85048. + * second in the Gadget Driver (for example, the File-Backed Storage
  85049. + * Gadget Driver).
  85050. + *
  85051. + * <table>
  85052. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  85053. + *
  85054. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  85055. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  85056. + * </td></tr>
  85057. + *
  85058. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  85059. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  85060. + * interface requests are ignored.</td></tr>
  85061. + *
  85062. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  85063. + * requests are processed by the PCD. Interface requests are passed
  85064. + * to the Gadget Driver.</td></tr>
  85065. + *
  85066. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  85067. + * with device address received </td></tr>
  85068. + *
  85069. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  85070. + * requested descriptor</td></tr>
  85071. + *
  85072. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  85073. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  85074. + *
  85075. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  85076. + * all EPs and enable EPs for new configuration.</td></tr>
  85077. + *
  85078. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  85079. + * the current configuration</td></tr>
  85080. + *
  85081. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  85082. + * EPs and enable EPs for new configuration.</td></tr>
  85083. + *
  85084. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  85085. + * current interface.</td></tr>
  85086. + *
  85087. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  85088. + * message.</td></tr>
  85089. + * </table>
  85090. + *
  85091. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  85092. + * processed by pcd_setup. Calling the Function Driver's setup function from
  85093. + * pcd_setup processes the gadget SETUP commands.
  85094. + */
  85095. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  85096. +{
  85097. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85098. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85099. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  85100. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85101. +
  85102. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  85103. +
  85104. +#ifdef DWC_UTE_CFI
  85105. + int retval = 0;
  85106. + struct cfi_usb_ctrlrequest cfi_req;
  85107. +#endif
  85108. +
  85109. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  85110. +
  85111. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  85112. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  85113. + && (doeptsize0.b.supcnt < 2)
  85114. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  85115. + DWC_ERROR
  85116. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  85117. + }
  85118. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  85119. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  85120. + ctrl =
  85121. + (pcd->setup_pkt +
  85122. + (3 - doeptsize0.b.supcnt - 1 +
  85123. + ep0->dwc_ep.stp_rollover))->req;
  85124. + }
  85125. +#ifdef DEBUG_EP0
  85126. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  85127. + ctrl.bmRequestType, ctrl.bRequest,
  85128. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  85129. + UGETW(ctrl.wLength));
  85130. +#endif
  85131. +
  85132. + /* Clean up the request queue */
  85133. + dwc_otg_request_nuke(ep0);
  85134. + ep0->stopped = 0;
  85135. +
  85136. + if (ctrl.bmRequestType & UE_DIR_IN) {
  85137. + ep0->dwc_ep.is_in = 1;
  85138. + pcd->ep0state = EP0_IN_DATA_PHASE;
  85139. + } else {
  85140. + ep0->dwc_ep.is_in = 0;
  85141. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  85142. + }
  85143. +
  85144. + if (UGETW(ctrl.wLength) == 0) {
  85145. + ep0->dwc_ep.is_in = 1;
  85146. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  85147. + }
  85148. +
  85149. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  85150. +
  85151. +#ifdef DWC_UTE_CFI
  85152. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  85153. +
  85154. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  85155. + ctrl.bRequestType, ctrl.bRequest);
  85156. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  85157. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  85158. + retval = cfi_setup(pcd, &cfi_req);
  85159. + if (retval < 0) {
  85160. + ep0_do_stall(pcd, retval);
  85161. + pcd->ep0_pending = 0;
  85162. + return;
  85163. + }
  85164. +
  85165. + /* if need gadget setup then call it and check the retval */
  85166. + if (pcd->cfi->need_gadget_att) {
  85167. + retval =
  85168. + cfi_gadget_setup(pcd,
  85169. + &pcd->
  85170. + cfi->ctrl_req);
  85171. + if (retval < 0) {
  85172. + pcd->ep0_pending = 0;
  85173. + return;
  85174. + }
  85175. + }
  85176. +
  85177. + if (pcd->cfi->need_status_in_complete) {
  85178. + do_setup_in_status_phase(pcd);
  85179. + }
  85180. + return;
  85181. + }
  85182. + }
  85183. +#endif
  85184. +
  85185. + /* handle non-standard (class/vendor) requests in the gadget driver */
  85186. + do_gadget_setup(pcd, &ctrl);
  85187. + return;
  85188. + }
  85189. +
  85190. + /** @todo NGS: Handle bad setup packet? */
  85191. +
  85192. +///////////////////////////////////////////
  85193. +//// --- Standard Request handling --- ////
  85194. +
  85195. + switch (ctrl.bRequest) {
  85196. + case UR_GET_STATUS:
  85197. + do_get_status(pcd);
  85198. + break;
  85199. +
  85200. + case UR_CLEAR_FEATURE:
  85201. + do_clear_feature(pcd);
  85202. + break;
  85203. +
  85204. + case UR_SET_FEATURE:
  85205. + do_set_feature(pcd);
  85206. + break;
  85207. +
  85208. + case UR_SET_ADDRESS:
  85209. + do_set_address(pcd);
  85210. + break;
  85211. +
  85212. + case UR_SET_INTERFACE:
  85213. + case UR_SET_CONFIG:
  85214. +// _pcd->request_config = 1; /* Configuration changed */
  85215. + do_gadget_setup(pcd, &ctrl);
  85216. + break;
  85217. +
  85218. + case UR_SYNCH_FRAME:
  85219. + do_gadget_setup(pcd, &ctrl);
  85220. + break;
  85221. +
  85222. + default:
  85223. + /* Call the Gadget Driver's setup functions */
  85224. + do_gadget_setup(pcd, &ctrl);
  85225. + break;
  85226. + }
  85227. +}
  85228. +
  85229. +/**
  85230. + * This function completes the ep0 control transfer.
  85231. + */
  85232. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  85233. +{
  85234. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  85235. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85236. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  85237. + dev_if->in_ep_regs[ep->dwc_ep.num];
  85238. +#ifdef DEBUG_EP0
  85239. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  85240. + dev_if->out_ep_regs[ep->dwc_ep.num];
  85241. +#endif
  85242. + deptsiz0_data_t deptsiz;
  85243. + dev_dma_desc_sts_t desc_sts;
  85244. + dwc_otg_pcd_request_t *req;
  85245. + int is_last = 0;
  85246. + dwc_otg_pcd_t *pcd = ep->pcd;
  85247. +
  85248. +#ifdef DWC_UTE_CFI
  85249. + struct cfi_usb_ctrlrequest *ctrlreq;
  85250. + int retval = -DWC_E_NOT_SUPPORTED;
  85251. +#endif
  85252. +
  85253. + desc_sts.b.bytes = 0;
  85254. +
  85255. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85256. + if (ep->dwc_ep.is_in) {
  85257. +#ifdef DEBUG_EP0
  85258. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  85259. +#endif
  85260. + do_setup_out_status_phase(pcd);
  85261. + } else {
  85262. +#ifdef DEBUG_EP0
  85263. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  85264. +#endif
  85265. +
  85266. +#ifdef DWC_UTE_CFI
  85267. + ctrlreq = &pcd->cfi->ctrl_req;
  85268. +
  85269. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  85270. + if (ctrlreq->bRequest > 0xB0
  85271. + && ctrlreq->bRequest < 0xBF) {
  85272. +
  85273. + /* Return if the PCD failed to handle the request */
  85274. + if ((retval =
  85275. + pcd->cfi->ops.
  85276. + ctrl_write_complete(pcd->cfi,
  85277. + pcd)) < 0) {
  85278. + CFI_INFO
  85279. + ("ERROR setting a new value in the PCD(%d)\n",
  85280. + retval);
  85281. + ep0_do_stall(pcd, retval);
  85282. + pcd->ep0_pending = 0;
  85283. + return 0;
  85284. + }
  85285. +
  85286. + /* If the gadget needs to be notified on the request */
  85287. + if (pcd->cfi->need_gadget_att == 1) {
  85288. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  85289. + retval =
  85290. + cfi_gadget_setup(pcd,
  85291. + &pcd->cfi->
  85292. + ctrl_req);
  85293. +
  85294. + /* Return from the function if the gadget failed to process
  85295. + * the request properly - this should never happen !!!
  85296. + */
  85297. + if (retval < 0) {
  85298. + CFI_INFO
  85299. + ("ERROR setting a new value in the gadget(%d)\n",
  85300. + retval);
  85301. + pcd->ep0_pending = 0;
  85302. + return 0;
  85303. + }
  85304. + }
  85305. +
  85306. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  85307. + retval);
  85308. + /* If we hit here then the PCD and the gadget has properly
  85309. + * handled the request - so send the ZLP IN to the host.
  85310. + */
  85311. + /* @todo: MAS - decide whether we need to start the setup
  85312. + * stage based on the need_setup value of the cfi object
  85313. + */
  85314. + do_setup_in_status_phase(pcd);
  85315. + pcd->ep0_pending = 0;
  85316. + return 1;
  85317. + }
  85318. + }
  85319. +#endif
  85320. +
  85321. + do_setup_in_status_phase(pcd);
  85322. + }
  85323. + pcd->ep0_pending = 0;
  85324. + return 1;
  85325. + }
  85326. +
  85327. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85328. + return 0;
  85329. + }
  85330. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  85331. +
  85332. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  85333. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  85334. + is_last = 1;
  85335. + } else if (ep->dwc_ep.is_in) {
  85336. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  85337. + if (core_if->dma_desc_enable != 0)
  85338. + desc_sts = dev_if->in_desc_addr->status;
  85339. +#ifdef DEBUG_EP0
  85340. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  85341. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  85342. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85343. +#endif
  85344. +
  85345. + if (((core_if->dma_desc_enable == 0)
  85346. + && (deptsiz.b.xfersize == 0))
  85347. + || ((core_if->dma_desc_enable != 0)
  85348. + && (desc_sts.b.bytes == 0))) {
  85349. + req->actual = ep->dwc_ep.xfer_count;
  85350. + /* Is a Zero Len Packet needed? */
  85351. + if (req->sent_zlp) {
  85352. +#ifdef DEBUG_EP0
  85353. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  85354. +#endif
  85355. + req->sent_zlp = 0;
  85356. + }
  85357. + do_setup_out_status_phase(pcd);
  85358. + }
  85359. + } else {
  85360. + /* ep0-OUT */
  85361. +#ifdef DEBUG_EP0
  85362. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  85363. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  85364. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  85365. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85366. +#endif
  85367. + req->actual = ep->dwc_ep.xfer_count;
  85368. +
  85369. + /* Is a Zero Len Packet needed? */
  85370. + if (req->sent_zlp) {
  85371. +#ifdef DEBUG_EP0
  85372. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  85373. +#endif
  85374. + req->sent_zlp = 0;
  85375. + }
  85376. + /* For older cores do setup in status phase in Slave/BDMA modes,
  85377. + * starting from 3.00 do that only in slave, and for DMA modes
  85378. + * just re-enable ep 0 OUT here*/
  85379. + if (core_if->dma_enable == 0
  85380. + || (core_if->dma_desc_enable == 0
  85381. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  85382. + do_setup_in_status_phase(pcd);
  85383. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85384. + DWC_DEBUGPL(DBG_PCDV,
  85385. + "Enable out ep before in status phase\n");
  85386. + ep0_out_start(core_if, pcd);
  85387. + }
  85388. + }
  85389. +
  85390. + /* Complete the request */
  85391. + if (is_last) {
  85392. + dwc_otg_request_done(ep, req, 0);
  85393. + ep->dwc_ep.start_xfer_buff = 0;
  85394. + ep->dwc_ep.xfer_buff = 0;
  85395. + ep->dwc_ep.xfer_len = 0;
  85396. + return 1;
  85397. + }
  85398. + return 0;
  85399. +}
  85400. +
  85401. +#ifdef DWC_UTE_CFI
  85402. +/**
  85403. + * This function calculates traverses all the CFI DMA descriptors and
  85404. + * and accumulates the bytes that are left to be transfered.
  85405. + *
  85406. + * @return The total bytes left to transfered, or a negative value as failure
  85407. + */
  85408. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  85409. +{
  85410. + int32_t ret = 0;
  85411. + int i;
  85412. + struct dwc_otg_dma_desc *ddesc = NULL;
  85413. + struct cfi_ep *cfiep;
  85414. +
  85415. + /* See if the pcd_ep has its respective cfi_ep mapped */
  85416. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  85417. + if (!cfiep) {
  85418. + CFI_INFO("%s: Failed to find ep\n", __func__);
  85419. + return -1;
  85420. + }
  85421. +
  85422. + ddesc = ep->dwc_ep.descs;
  85423. +
  85424. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  85425. +
  85426. +#if defined(PRINT_CFI_DMA_DESCS)
  85427. + print_desc(ddesc, ep->ep.name, i);
  85428. +#endif
  85429. + ret += ddesc->status.b.bytes;
  85430. + ddesc++;
  85431. + }
  85432. +
  85433. + if (ret)
  85434. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  85435. + ret);
  85436. +
  85437. + return ret;
  85438. +}
  85439. +#endif
  85440. +
  85441. +/**
  85442. + * This function completes the request for the EP. If there are
  85443. + * additional requests for the EP in the queue they will be started.
  85444. + */
  85445. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  85446. +{
  85447. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  85448. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85449. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  85450. + dev_if->in_ep_regs[ep->dwc_ep.num];
  85451. + deptsiz_data_t deptsiz;
  85452. + dev_dma_desc_sts_t desc_sts;
  85453. + dwc_otg_pcd_request_t *req = 0;
  85454. + dwc_otg_dev_dma_desc_t *dma_desc;
  85455. + uint32_t byte_count = 0;
  85456. + int is_last = 0;
  85457. + int i;
  85458. +
  85459. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  85460. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  85461. +
  85462. + /* Get any pending requests */
  85463. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85464. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  85465. + if (!req) {
  85466. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  85467. + return;
  85468. + }
  85469. + } else {
  85470. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  85471. + return;
  85472. + }
  85473. +
  85474. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  85475. +
  85476. + if (ep->dwc_ep.is_in) {
  85477. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  85478. +
  85479. + if (core_if->dma_enable) {
  85480. + if (core_if->dma_desc_enable == 0) {
  85481. + if (deptsiz.b.xfersize == 0
  85482. + && deptsiz.b.pktcnt == 0) {
  85483. + byte_count =
  85484. + ep->dwc_ep.xfer_len -
  85485. + ep->dwc_ep.xfer_count;
  85486. +
  85487. + ep->dwc_ep.xfer_buff += byte_count;
  85488. + ep->dwc_ep.dma_addr += byte_count;
  85489. + ep->dwc_ep.xfer_count += byte_count;
  85490. +
  85491. + DWC_DEBUGPL(DBG_PCDV,
  85492. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  85493. + ep->dwc_ep.num,
  85494. + (ep->dwc_ep.
  85495. + is_in ? "IN" : "OUT"),
  85496. + ep->dwc_ep.xfer_len,
  85497. + deptsiz.b.xfersize,
  85498. + deptsiz.b.pktcnt);
  85499. +
  85500. + if (ep->dwc_ep.xfer_len <
  85501. + ep->dwc_ep.total_len) {
  85502. + dwc_otg_ep_start_transfer
  85503. + (core_if, &ep->dwc_ep);
  85504. + } else if (ep->dwc_ep.sent_zlp) {
  85505. + /*
  85506. + * This fragment of code should initiate 0
  85507. + * length transfer in case if it is queued
  85508. + * a transfer with size divisible to EPs max
  85509. + * packet size and with usb_request zero field
  85510. + * is set, which means that after data is transfered,
  85511. + * it is also should be transfered
  85512. + * a 0 length packet at the end. For Slave and
  85513. + * Buffer DMA modes in this case SW has
  85514. + * to initiate 2 transfers one with transfer size,
  85515. + * and the second with 0 size. For Descriptor
  85516. + * DMA mode SW is able to initiate a transfer,
  85517. + * which will handle all the packets including
  85518. + * the last 0 length.
  85519. + */
  85520. + ep->dwc_ep.sent_zlp = 0;
  85521. + dwc_otg_ep_start_zl_transfer
  85522. + (core_if, &ep->dwc_ep);
  85523. + } else {
  85524. + is_last = 1;
  85525. + }
  85526. + } else {
  85527. + if (ep->dwc_ep.type ==
  85528. + DWC_OTG_EP_TYPE_ISOC) {
  85529. + req->actual = 0;
  85530. + dwc_otg_request_done(ep, req, 0);
  85531. +
  85532. + ep->dwc_ep.start_xfer_buff = 0;
  85533. + ep->dwc_ep.xfer_buff = 0;
  85534. + ep->dwc_ep.xfer_len = 0;
  85535. +
  85536. + /* If there is a request in the queue start it. */
  85537. + start_next_request(ep);
  85538. + } else
  85539. + DWC_WARN
  85540. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  85541. + ep->dwc_ep.num,
  85542. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  85543. + deptsiz.b.xfersize,
  85544. + deptsiz.b.pktcnt);
  85545. + }
  85546. + } else {
  85547. + dma_desc = ep->dwc_ep.desc_addr;
  85548. + byte_count = 0;
  85549. + ep->dwc_ep.sent_zlp = 0;
  85550. +
  85551. +#ifdef DWC_UTE_CFI
  85552. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  85553. + ep->dwc_ep.buff_mode);
  85554. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85555. + int residue;
  85556. +
  85557. + residue = cfi_calc_desc_residue(ep);
  85558. + if (residue < 0)
  85559. + return;
  85560. +
  85561. + byte_count = residue;
  85562. + } else {
  85563. +#endif
  85564. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  85565. + ++i) {
  85566. + desc_sts = dma_desc->status;
  85567. + byte_count += desc_sts.b.bytes;
  85568. + dma_desc++;
  85569. + }
  85570. +#ifdef DWC_UTE_CFI
  85571. + }
  85572. +#endif
  85573. + if (byte_count == 0) {
  85574. + ep->dwc_ep.xfer_count =
  85575. + ep->dwc_ep.total_len;
  85576. + is_last = 1;
  85577. + } else {
  85578. + DWC_WARN("Incomplete transfer\n");
  85579. + }
  85580. + }
  85581. + } else {
  85582. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  85583. + DWC_DEBUGPL(DBG_PCDV,
  85584. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  85585. + ep->dwc_ep.num,
  85586. + ep->dwc_ep.is_in ? "IN" : "OUT",
  85587. + ep->dwc_ep.xfer_len,
  85588. + deptsiz.b.xfersize,
  85589. + deptsiz.b.pktcnt);
  85590. +
  85591. + /* Check if the whole transfer was completed,
  85592. + * if no, setup transfer for next portion of data
  85593. + */
  85594. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  85595. + dwc_otg_ep_start_transfer(core_if,
  85596. + &ep->dwc_ep);
  85597. + } else if (ep->dwc_ep.sent_zlp) {
  85598. + /*
  85599. + * This fragment of code should initiate 0
  85600. + * length trasfer in case if it is queued
  85601. + * a trasfer with size divisible to EPs max
  85602. + * packet size and with usb_request zero field
  85603. + * is set, which means that after data is transfered,
  85604. + * it is also should be transfered
  85605. + * a 0 length packet at the end. For Slave and
  85606. + * Buffer DMA modes in this case SW has
  85607. + * to initiate 2 transfers one with transfer size,
  85608. + * and the second with 0 size. For Desriptor
  85609. + * DMA mode SW is able to initiate a transfer,
  85610. + * which will handle all the packets including
  85611. + * the last 0 legth.
  85612. + */
  85613. + ep->dwc_ep.sent_zlp = 0;
  85614. + dwc_otg_ep_start_zl_transfer(core_if,
  85615. + &ep->dwc_ep);
  85616. + } else {
  85617. + is_last = 1;
  85618. + }
  85619. + } else {
  85620. + DWC_WARN
  85621. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  85622. + ep->dwc_ep.num,
  85623. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  85624. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85625. + }
  85626. + }
  85627. + } else {
  85628. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  85629. + dev_if->out_ep_regs[ep->dwc_ep.num];
  85630. + desc_sts.d32 = 0;
  85631. + if (core_if->dma_enable) {
  85632. + if (core_if->dma_desc_enable) {
  85633. + dma_desc = ep->dwc_ep.desc_addr;
  85634. + byte_count = 0;
  85635. + ep->dwc_ep.sent_zlp = 0;
  85636. +
  85637. +#ifdef DWC_UTE_CFI
  85638. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  85639. + ep->dwc_ep.buff_mode);
  85640. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85641. + int residue;
  85642. + residue = cfi_calc_desc_residue(ep);
  85643. + if (residue < 0)
  85644. + return;
  85645. + byte_count = residue;
  85646. + } else {
  85647. +#endif
  85648. +
  85649. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  85650. + ++i) {
  85651. + desc_sts = dma_desc->status;
  85652. + byte_count += desc_sts.b.bytes;
  85653. + dma_desc++;
  85654. + }
  85655. +
  85656. +#ifdef DWC_UTE_CFI
  85657. + }
  85658. +#endif
  85659. + /* Checking for interrupt Out transfers with not
  85660. + * dword aligned mps sizes
  85661. + */
  85662. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  85663. + (ep->dwc_ep.maxpacket%4)) {
  85664. + ep->dwc_ep.xfer_count =
  85665. + ep->dwc_ep.total_len - byte_count;
  85666. + if ((ep->dwc_ep.xfer_len %
  85667. + ep->dwc_ep.maxpacket)
  85668. + && (ep->dwc_ep.xfer_len /
  85669. + ep->dwc_ep.maxpacket <
  85670. + MAX_DMA_DESC_CNT))
  85671. + ep->dwc_ep.xfer_len -=
  85672. + (ep->dwc_ep.desc_cnt -
  85673. + 1) * ep->dwc_ep.maxpacket +
  85674. + ep->dwc_ep.xfer_len %
  85675. + ep->dwc_ep.maxpacket;
  85676. + else
  85677. + ep->dwc_ep.xfer_len -=
  85678. + ep->dwc_ep.desc_cnt *
  85679. + ep->dwc_ep.maxpacket;
  85680. + if (ep->dwc_ep.xfer_len > 0) {
  85681. + dwc_otg_ep_start_transfer
  85682. + (core_if, &ep->dwc_ep);
  85683. + } else {
  85684. + is_last = 1;
  85685. + }
  85686. + } else {
  85687. + ep->dwc_ep.xfer_count =
  85688. + ep->dwc_ep.total_len - byte_count +
  85689. + ((4 -
  85690. + (ep->dwc_ep.
  85691. + total_len & 0x3)) & 0x3);
  85692. + is_last = 1;
  85693. + }
  85694. + } else {
  85695. + deptsiz.d32 = 0;
  85696. + deptsiz.d32 =
  85697. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  85698. +
  85699. + byte_count = (ep->dwc_ep.xfer_len -
  85700. + ep->dwc_ep.xfer_count -
  85701. + deptsiz.b.xfersize);
  85702. + ep->dwc_ep.xfer_buff += byte_count;
  85703. + ep->dwc_ep.dma_addr += byte_count;
  85704. + ep->dwc_ep.xfer_count += byte_count;
  85705. +
  85706. + /* Check if the whole transfer was completed,
  85707. + * if no, setup transfer for next portion of data
  85708. + */
  85709. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  85710. + dwc_otg_ep_start_transfer(core_if,
  85711. + &ep->dwc_ep);
  85712. + } else if (ep->dwc_ep.sent_zlp) {
  85713. + /*
  85714. + * This fragment of code should initiate 0
  85715. + * length trasfer in case if it is queued
  85716. + * a trasfer with size divisible to EPs max
  85717. + * packet size and with usb_request zero field
  85718. + * is set, which means that after data is transfered,
  85719. + * it is also should be transfered
  85720. + * a 0 length packet at the end. For Slave and
  85721. + * Buffer DMA modes in this case SW has
  85722. + * to initiate 2 transfers one with transfer size,
  85723. + * and the second with 0 size. For Desriptor
  85724. + * DMA mode SW is able to initiate a transfer,
  85725. + * which will handle all the packets including
  85726. + * the last 0 legth.
  85727. + */
  85728. + ep->dwc_ep.sent_zlp = 0;
  85729. + dwc_otg_ep_start_zl_transfer(core_if,
  85730. + &ep->dwc_ep);
  85731. + } else {
  85732. + is_last = 1;
  85733. + }
  85734. + }
  85735. + } else {
  85736. + /* Check if the whole transfer was completed,
  85737. + * if no, setup transfer for next portion of data
  85738. + */
  85739. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  85740. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  85741. + } else if (ep->dwc_ep.sent_zlp) {
  85742. + /*
  85743. + * This fragment of code should initiate 0
  85744. + * length transfer in case if it is queued
  85745. + * a transfer with size divisible to EPs max
  85746. + * packet size and with usb_request zero field
  85747. + * is set, which means that after data is transfered,
  85748. + * it is also should be transfered
  85749. + * a 0 length packet at the end. For Slave and
  85750. + * Buffer DMA modes in this case SW has
  85751. + * to initiate 2 transfers one with transfer size,
  85752. + * and the second with 0 size. For Descriptor
  85753. + * DMA mode SW is able to initiate a transfer,
  85754. + * which will handle all the packets including
  85755. + * the last 0 length.
  85756. + */
  85757. + ep->dwc_ep.sent_zlp = 0;
  85758. + dwc_otg_ep_start_zl_transfer(core_if,
  85759. + &ep->dwc_ep);
  85760. + } else {
  85761. + is_last = 1;
  85762. + }
  85763. + }
  85764. +
  85765. + DWC_DEBUGPL(DBG_PCDV,
  85766. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  85767. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  85768. + ep->dwc_ep.is_in ? "IN" : "OUT",
  85769. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  85770. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85771. + }
  85772. +
  85773. + /* Complete the request */
  85774. + if (is_last) {
  85775. +#ifdef DWC_UTE_CFI
  85776. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85777. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  85778. + } else {
  85779. +#endif
  85780. + req->actual = ep->dwc_ep.xfer_count;
  85781. +#ifdef DWC_UTE_CFI
  85782. + }
  85783. +#endif
  85784. + if (req->dw_align_buf) {
  85785. + if (!ep->dwc_ep.is_in) {
  85786. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  85787. + }
  85788. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  85789. + req->dw_align_buf_dma);
  85790. + }
  85791. +
  85792. + dwc_otg_request_done(ep, req, 0);
  85793. +
  85794. + ep->dwc_ep.start_xfer_buff = 0;
  85795. + ep->dwc_ep.xfer_buff = 0;
  85796. + ep->dwc_ep.xfer_len = 0;
  85797. +
  85798. + /* If there is a request in the queue start it. */
  85799. + start_next_request(ep);
  85800. + }
  85801. +}
  85802. +
  85803. +#ifdef DWC_EN_ISOC
  85804. +
  85805. +/**
  85806. + * This function BNA interrupt for Isochronous EPs
  85807. + *
  85808. + */
  85809. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  85810. +{
  85811. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  85812. + volatile uint32_t *addr;
  85813. + depctl_data_t depctl = {.d32 = 0 };
  85814. + dwc_otg_pcd_t *pcd = ep->pcd;
  85815. + dwc_otg_dev_dma_desc_t *dma_desc;
  85816. + int i;
  85817. +
  85818. + dma_desc =
  85819. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  85820. +
  85821. + if (dwc_ep->is_in) {
  85822. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85823. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  85824. + sts.d32 = dma_desc->status.d32;
  85825. + sts.b_iso_in.bs = BS_HOST_READY;
  85826. + dma_desc->status.d32 = sts.d32;
  85827. + }
  85828. + } else {
  85829. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85830. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  85831. + sts.d32 = dma_desc->status.d32;
  85832. + sts.b_iso_out.bs = BS_HOST_READY;
  85833. + dma_desc->status.d32 = sts.d32;
  85834. + }
  85835. + }
  85836. +
  85837. + if (dwc_ep->is_in == 0) {
  85838. + addr =
  85839. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  85840. + num]->doepctl;
  85841. + } else {
  85842. + addr =
  85843. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  85844. + }
  85845. + depctl.b.epena = 1;
  85846. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  85847. +}
  85848. +
  85849. +/**
  85850. + * This function sets latest iso packet information(non-PTI mode)
  85851. + *
  85852. + * @param core_if Programming view of DWC_otg controller.
  85853. + * @param ep The EP to start the transfer on.
  85854. + *
  85855. + */
  85856. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85857. +{
  85858. + deptsiz_data_t deptsiz = {.d32 = 0 };
  85859. + dma_addr_t dma_addr;
  85860. + uint32_t offset;
  85861. +
  85862. + if (ep->proc_buf_num)
  85863. + dma_addr = ep->dma_addr1;
  85864. + else
  85865. + dma_addr = ep->dma_addr0;
  85866. +
  85867. + if (ep->is_in) {
  85868. + deptsiz.d32 =
  85869. + DWC_READ_REG32(&core_if->dev_if->
  85870. + in_ep_regs[ep->num]->dieptsiz);
  85871. + offset = ep->data_per_frame;
  85872. + } else {
  85873. + deptsiz.d32 =
  85874. + DWC_READ_REG32(&core_if->dev_if->
  85875. + out_ep_regs[ep->num]->doeptsiz);
  85876. + offset =
  85877. + ep->data_per_frame +
  85878. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  85879. + }
  85880. +
  85881. + if (!deptsiz.b.xfersize) {
  85882. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  85883. + ep->pkt_info[ep->cur_pkt].offset =
  85884. + ep->cur_pkt_dma_addr - dma_addr;
  85885. + ep->pkt_info[ep->cur_pkt].status = 0;
  85886. + } else {
  85887. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  85888. + ep->pkt_info[ep->cur_pkt].offset =
  85889. + ep->cur_pkt_dma_addr - dma_addr;
  85890. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  85891. + }
  85892. + ep->cur_pkt_addr += offset;
  85893. + ep->cur_pkt_dma_addr += offset;
  85894. + ep->cur_pkt++;
  85895. +}
  85896. +
  85897. +/**
  85898. + * This function sets latest iso packet information(DDMA mode)
  85899. + *
  85900. + * @param core_if Programming view of DWC_otg controller.
  85901. + * @param dwc_ep The EP to start the transfer on.
  85902. + *
  85903. + */
  85904. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  85905. + dwc_ep_t * dwc_ep)
  85906. +{
  85907. + dwc_otg_dev_dma_desc_t *dma_desc;
  85908. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85909. + iso_pkt_info_t *iso_packet;
  85910. + uint32_t data_per_desc;
  85911. + uint32_t offset;
  85912. + int i, j;
  85913. +
  85914. + iso_packet = dwc_ep->pkt_info;
  85915. +
  85916. + /** Reinit closed DMA Descriptors*/
  85917. + /** ISO OUT EP */
  85918. + if (dwc_ep->is_in == 0) {
  85919. + dma_desc =
  85920. + dwc_ep->iso_desc_addr +
  85921. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85922. + offset = 0;
  85923. +
  85924. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  85925. + i += dwc_ep->pkt_per_frm) {
  85926. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  85927. + data_per_desc =
  85928. + ((j + 1) * dwc_ep->maxpacket >
  85929. + dwc_ep->
  85930. + data_per_frame) ? dwc_ep->data_per_frame -
  85931. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85932. + data_per_desc +=
  85933. + (data_per_desc % 4) ? (4 -
  85934. + data_per_desc %
  85935. + 4) : 0;
  85936. +
  85937. + sts.d32 = dma_desc->status.d32;
  85938. +
  85939. + /* Write status in iso_packet_decsriptor */
  85940. + iso_packet->status =
  85941. + sts.b_iso_out.rxsts +
  85942. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85943. + if (iso_packet->status) {
  85944. + iso_packet->status = -DWC_E_NO_DATA;
  85945. + }
  85946. +
  85947. + /* Received data length */
  85948. + if (!sts.b_iso_out.rxbytes) {
  85949. + iso_packet->length =
  85950. + data_per_desc -
  85951. + sts.b_iso_out.rxbytes;
  85952. + } else {
  85953. + iso_packet->length =
  85954. + data_per_desc -
  85955. + sts.b_iso_out.rxbytes + (4 -
  85956. + dwc_ep->data_per_frame
  85957. + % 4);
  85958. + }
  85959. +
  85960. + iso_packet->offset = offset;
  85961. +
  85962. + offset += data_per_desc;
  85963. + dma_desc++;
  85964. + iso_packet++;
  85965. + }
  85966. + }
  85967. +
  85968. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  85969. + data_per_desc =
  85970. + ((j + 1) * dwc_ep->maxpacket >
  85971. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85972. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85973. + data_per_desc +=
  85974. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85975. +
  85976. + sts.d32 = dma_desc->status.d32;
  85977. +
  85978. + /* Write status in iso_packet_decsriptor */
  85979. + iso_packet->status =
  85980. + sts.b_iso_out.rxsts +
  85981. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85982. + if (iso_packet->status) {
  85983. + iso_packet->status = -DWC_E_NO_DATA;
  85984. + }
  85985. +
  85986. + /* Received data length */
  85987. + iso_packet->length =
  85988. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  85989. +
  85990. + iso_packet->offset = offset;
  85991. +
  85992. + offset += data_per_desc;
  85993. + iso_packet++;
  85994. + dma_desc++;
  85995. + }
  85996. +
  85997. + sts.d32 = dma_desc->status.d32;
  85998. +
  85999. + /* Write status in iso_packet_decsriptor */
  86000. + iso_packet->status =
  86001. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  86002. + if (iso_packet->status) {
  86003. + iso_packet->status = -DWC_E_NO_DATA;
  86004. + }
  86005. + /* Received data length */
  86006. + if (!sts.b_iso_out.rxbytes) {
  86007. + iso_packet->length =
  86008. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  86009. + } else {
  86010. + iso_packet->length =
  86011. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  86012. + (4 - dwc_ep->data_per_frame % 4);
  86013. + }
  86014. +
  86015. + iso_packet->offset = offset;
  86016. + } else {
  86017. +/** ISO IN EP */
  86018. +
  86019. + dma_desc =
  86020. + dwc_ep->iso_desc_addr +
  86021. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  86022. +
  86023. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  86024. + sts.d32 = dma_desc->status.d32;
  86025. +
  86026. + /* Write status in iso packet descriptor */
  86027. + iso_packet->status =
  86028. + sts.b_iso_in.txsts +
  86029. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  86030. + if (iso_packet->status != 0) {
  86031. + iso_packet->status = -DWC_E_NO_DATA;
  86032. +
  86033. + }
  86034. + /* Bytes has been transfered */
  86035. + iso_packet->length =
  86036. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  86037. +
  86038. + dma_desc++;
  86039. + iso_packet++;
  86040. + }
  86041. +
  86042. + sts.d32 = dma_desc->status.d32;
  86043. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  86044. + sts.d32 = dma_desc->status.d32;
  86045. + }
  86046. +
  86047. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  86048. + iso_packet->status =
  86049. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  86050. + if (iso_packet->status != 0) {
  86051. + iso_packet->status = -DWC_E_NO_DATA;
  86052. + }
  86053. +
  86054. + /* Bytes has been transfered */
  86055. + iso_packet->length =
  86056. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  86057. + }
  86058. +}
  86059. +
  86060. +/**
  86061. + * This function reinitialize DMA Descriptors for Isochronous transfer
  86062. + *
  86063. + * @param core_if Programming view of DWC_otg controller.
  86064. + * @param dwc_ep The EP to start the transfer on.
  86065. + *
  86066. + */
  86067. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  86068. +{
  86069. + int i, j;
  86070. + dwc_otg_dev_dma_desc_t *dma_desc;
  86071. + dma_addr_t dma_ad;
  86072. + volatile uint32_t *addr;
  86073. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  86074. + uint32_t data_per_desc;
  86075. +
  86076. + if (dwc_ep->is_in == 0) {
  86077. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  86078. + } else {
  86079. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  86080. + }
  86081. +
  86082. + if (dwc_ep->proc_buf_num == 0) {
  86083. + /** Buffer 0 descriptors setup */
  86084. + dma_ad = dwc_ep->dma_addr0;
  86085. + } else {
  86086. + /** Buffer 1 descriptors setup */
  86087. + dma_ad = dwc_ep->dma_addr1;
  86088. + }
  86089. +
  86090. + /** Reinit closed DMA Descriptors*/
  86091. + /** ISO OUT EP */
  86092. + if (dwc_ep->is_in == 0) {
  86093. + dma_desc =
  86094. + dwc_ep->iso_desc_addr +
  86095. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  86096. +
  86097. + sts.b_iso_out.bs = BS_HOST_READY;
  86098. + sts.b_iso_out.rxsts = 0;
  86099. + sts.b_iso_out.l = 0;
  86100. + sts.b_iso_out.sp = 0;
  86101. + sts.b_iso_out.ioc = 0;
  86102. + sts.b_iso_out.pid = 0;
  86103. + sts.b_iso_out.framenum = 0;
  86104. +
  86105. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  86106. + i += dwc_ep->pkt_per_frm) {
  86107. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  86108. + data_per_desc =
  86109. + ((j + 1) * dwc_ep->maxpacket >
  86110. + dwc_ep->
  86111. + data_per_frame) ? dwc_ep->data_per_frame -
  86112. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  86113. + data_per_desc +=
  86114. + (data_per_desc % 4) ? (4 -
  86115. + data_per_desc %
  86116. + 4) : 0;
  86117. + sts.b_iso_out.rxbytes = data_per_desc;
  86118. + dma_desc->buf = dma_ad;
  86119. + dma_desc->status.d32 = sts.d32;
  86120. +
  86121. + dma_ad += data_per_desc;
  86122. + dma_desc++;
  86123. + }
  86124. + }
  86125. +
  86126. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  86127. +
  86128. + data_per_desc =
  86129. + ((j + 1) * dwc_ep->maxpacket >
  86130. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  86131. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  86132. + data_per_desc +=
  86133. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  86134. + sts.b_iso_out.rxbytes = data_per_desc;
  86135. +
  86136. + dma_desc->buf = dma_ad;
  86137. + dma_desc->status.d32 = sts.d32;
  86138. +
  86139. + dma_desc++;
  86140. + dma_ad += data_per_desc;
  86141. + }
  86142. +
  86143. + sts.b_iso_out.ioc = 1;
  86144. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  86145. +
  86146. + data_per_desc =
  86147. + ((j + 1) * dwc_ep->maxpacket >
  86148. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  86149. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  86150. + data_per_desc +=
  86151. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  86152. + sts.b_iso_out.rxbytes = data_per_desc;
  86153. +
  86154. + dma_desc->buf = dma_ad;
  86155. + dma_desc->status.d32 = sts.d32;
  86156. + } else {
  86157. +/** ISO IN EP */
  86158. +
  86159. + dma_desc =
  86160. + dwc_ep->iso_desc_addr +
  86161. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  86162. +
  86163. + sts.b_iso_in.bs = BS_HOST_READY;
  86164. + sts.b_iso_in.txsts = 0;
  86165. + sts.b_iso_in.sp = 0;
  86166. + sts.b_iso_in.ioc = 0;
  86167. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  86168. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  86169. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  86170. + sts.b_iso_in.l = 0;
  86171. +
  86172. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  86173. + dma_desc->buf = dma_ad;
  86174. + dma_desc->status.d32 = sts.d32;
  86175. +
  86176. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  86177. + dma_ad += dwc_ep->data_per_frame;
  86178. + dma_desc++;
  86179. + }
  86180. +
  86181. + sts.b_iso_in.ioc = 1;
  86182. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  86183. +
  86184. + dma_desc->buf = dma_ad;
  86185. + dma_desc->status.d32 = sts.d32;
  86186. +
  86187. + dwc_ep->next_frame =
  86188. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  86189. + }
  86190. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  86191. +}
  86192. +
  86193. +/**
  86194. + * This function is to handle Iso EP transfer complete interrupt
  86195. + * in case Iso out packet was dropped
  86196. + *
  86197. + * @param core_if Programming view of DWC_otg controller.
  86198. + * @param dwc_ep The EP for wihich transfer complete was asserted
  86199. + *
  86200. + */
  86201. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  86202. + dwc_ep_t * dwc_ep)
  86203. +{
  86204. + uint32_t dma_addr;
  86205. + uint32_t drp_pkt;
  86206. + uint32_t drp_pkt_cnt;
  86207. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86208. + depctl_data_t depctl = {.d32 = 0 };
  86209. + int i;
  86210. +
  86211. + deptsiz.d32 =
  86212. + DWC_READ_REG32(&core_if->dev_if->
  86213. + out_ep_regs[dwc_ep->num]->doeptsiz);
  86214. +
  86215. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  86216. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  86217. +
  86218. + /* Setting dropped packets status */
  86219. + for (i = 0; i < drp_pkt_cnt; ++i) {
  86220. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  86221. + drp_pkt++;
  86222. + deptsiz.b.pktcnt--;
  86223. + }
  86224. +
  86225. + if (deptsiz.b.pktcnt > 0) {
  86226. + deptsiz.b.xfersize =
  86227. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  86228. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  86229. + } else {
  86230. + deptsiz.b.xfersize = 0;
  86231. + deptsiz.b.pktcnt = 0;
  86232. + }
  86233. +
  86234. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  86235. + deptsiz.d32);
  86236. +
  86237. + if (deptsiz.b.pktcnt > 0) {
  86238. + if (dwc_ep->proc_buf_num) {
  86239. + dma_addr =
  86240. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  86241. + deptsiz.b.xfersize;
  86242. + } else {
  86243. + dma_addr =
  86244. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  86245. + deptsiz.b.xfersize;;
  86246. + }
  86247. +
  86248. + DWC_WRITE_REG32(&core_if->dev_if->
  86249. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  86250. +
  86251. + /** Re-enable endpoint, clear nak */
  86252. + depctl.d32 = 0;
  86253. + depctl.b.epena = 1;
  86254. + depctl.b.cnak = 1;
  86255. +
  86256. + DWC_MODIFY_REG32(&core_if->dev_if->
  86257. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  86258. + depctl.d32);
  86259. + return 0;
  86260. + } else {
  86261. + return 1;
  86262. + }
  86263. +}
  86264. +
  86265. +/**
  86266. + * This function sets iso packets information(PTI mode)
  86267. + *
  86268. + * @param core_if Programming view of DWC_otg controller.
  86269. + * @param ep The EP to start the transfer on.
  86270. + *
  86271. + */
  86272. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  86273. +{
  86274. + int i, j;
  86275. + dma_addr_t dma_ad;
  86276. + iso_pkt_info_t *packet_info = ep->pkt_info;
  86277. + uint32_t offset;
  86278. + uint32_t frame_data;
  86279. + deptsiz_data_t deptsiz;
  86280. +
  86281. + if (ep->proc_buf_num == 0) {
  86282. + /** Buffer 0 descriptors setup */
  86283. + dma_ad = ep->dma_addr0;
  86284. + } else {
  86285. + /** Buffer 1 descriptors setup */
  86286. + dma_ad = ep->dma_addr1;
  86287. + }
  86288. +
  86289. + if (ep->is_in) {
  86290. + deptsiz.d32 =
  86291. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  86292. + dieptsiz);
  86293. + } else {
  86294. + deptsiz.d32 =
  86295. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  86296. + doeptsiz);
  86297. + }
  86298. +
  86299. + if (!deptsiz.b.xfersize) {
  86300. + offset = 0;
  86301. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  86302. + frame_data = ep->data_per_frame;
  86303. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  86304. +
  86305. + /* Packet status - is not set as initially
  86306. + * it is set to 0 and if packet was sent
  86307. + successfully, status field will remain 0*/
  86308. +
  86309. + /* Bytes has been transfered */
  86310. + packet_info->length =
  86311. + (ep->maxpacket <
  86312. + frame_data) ? ep->maxpacket : frame_data;
  86313. +
  86314. + /* Received packet offset */
  86315. + packet_info->offset = offset;
  86316. + offset += packet_info->length;
  86317. + frame_data -= packet_info->length;
  86318. +
  86319. + packet_info++;
  86320. + }
  86321. + }
  86322. + return 1;
  86323. + } else {
  86324. + /* This is a workaround for in case of Transfer Complete with
  86325. + * PktDrpSts interrupts merging - in this case Transfer complete
  86326. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  86327. + * set and with DOEPTSIZ register non zero. Investigations showed,
  86328. + * that this happens when Out packet is dropped, but because of
  86329. + * interrupts merging during first interrupt handling PktDrpSts
  86330. + * bit is cleared and for next merged interrupts it is not reset.
  86331. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  86332. + */
  86333. + if (ep->is_in) {
  86334. + return 1;
  86335. + } else {
  86336. + return handle_iso_out_pkt_dropped(core_if, ep);
  86337. + }
  86338. + }
  86339. +}
  86340. +
  86341. +/**
  86342. + * This function is to handle Iso EP transfer complete interrupt
  86343. + *
  86344. + * @param pcd The PCD
  86345. + * @param ep The EP for which transfer complete was asserted
  86346. + *
  86347. + */
  86348. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  86349. +{
  86350. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  86351. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  86352. + uint8_t is_last = 0;
  86353. +
  86354. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  86355. + DWC_WARN("Next frame is not set!\n");
  86356. + return;
  86357. + }
  86358. +
  86359. + if (core_if->dma_enable) {
  86360. + if (core_if->dma_desc_enable) {
  86361. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  86362. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  86363. + is_last = 1;
  86364. + } else {
  86365. + if (core_if->pti_enh_enable) {
  86366. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  86367. + dwc_ep->proc_buf_num =
  86368. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  86369. + dwc_otg_iso_ep_start_buf_transfer
  86370. + (core_if, dwc_ep);
  86371. + is_last = 1;
  86372. + }
  86373. + } else {
  86374. + set_current_pkt_info(core_if, dwc_ep);
  86375. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  86376. + is_last = 1;
  86377. + dwc_ep->cur_pkt = 0;
  86378. + dwc_ep->proc_buf_num =
  86379. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  86380. + if (dwc_ep->proc_buf_num) {
  86381. + dwc_ep->cur_pkt_addr =
  86382. + dwc_ep->xfer_buff1;
  86383. + dwc_ep->cur_pkt_dma_addr =
  86384. + dwc_ep->dma_addr1;
  86385. + } else {
  86386. + dwc_ep->cur_pkt_addr =
  86387. + dwc_ep->xfer_buff0;
  86388. + dwc_ep->cur_pkt_dma_addr =
  86389. + dwc_ep->dma_addr0;
  86390. + }
  86391. +
  86392. + }
  86393. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  86394. + dwc_ep);
  86395. + }
  86396. + }
  86397. + } else {
  86398. + set_current_pkt_info(core_if, dwc_ep);
  86399. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  86400. + is_last = 1;
  86401. + dwc_ep->cur_pkt = 0;
  86402. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  86403. + if (dwc_ep->proc_buf_num) {
  86404. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  86405. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  86406. + } else {
  86407. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  86408. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  86409. + }
  86410. +
  86411. + }
  86412. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  86413. + }
  86414. + if (is_last)
  86415. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  86416. +}
  86417. +#endif /* DWC_EN_ISOC */
  86418. +
  86419. +/**
  86420. + * This function handle BNA interrupt for Non Isochronous EPs
  86421. + *
  86422. + */
  86423. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  86424. +{
  86425. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  86426. + volatile uint32_t *addr;
  86427. + depctl_data_t depctl = {.d32 = 0 };
  86428. + dwc_otg_pcd_t *pcd = ep->pcd;
  86429. + dwc_otg_dev_dma_desc_t *dma_desc;
  86430. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  86431. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  86432. + int i, start;
  86433. +
  86434. + if (!dwc_ep->desc_cnt)
  86435. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  86436. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  86437. +
  86438. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  86439. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  86440. + uint32_t doepdma;
  86441. + dwc_otg_dev_out_ep_regs_t *out_regs =
  86442. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  86443. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  86444. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  86445. + dma_desc = &(dwc_ep->desc_addr[start]);
  86446. + } else {
  86447. + start = 0;
  86448. + dma_desc = dwc_ep->desc_addr;
  86449. + }
  86450. +
  86451. +
  86452. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  86453. + sts.d32 = dma_desc->status.d32;
  86454. + sts.b.bs = BS_HOST_READY;
  86455. + dma_desc->status.d32 = sts.d32;
  86456. + }
  86457. +
  86458. + if (dwc_ep->is_in == 0) {
  86459. + addr =
  86460. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  86461. + doepctl;
  86462. + } else {
  86463. + addr =
  86464. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  86465. + }
  86466. + depctl.b.epena = 1;
  86467. + depctl.b.cnak = 1;
  86468. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  86469. +}
  86470. +
  86471. +/**
  86472. + * This function handles EP0 Control transfers.
  86473. + *
  86474. + * The state of the control transfers are tracked in
  86475. + * <code>ep0state</code>.
  86476. + */
  86477. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  86478. +{
  86479. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86480. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86481. + dev_dma_desc_sts_t desc_sts;
  86482. + deptsiz0_data_t deptsiz;
  86483. + uint32_t byte_count;
  86484. +
  86485. +#ifdef DEBUG_EP0
  86486. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  86487. + print_ep0_state(pcd);
  86488. +#endif
  86489. +
  86490. +// DWC_PRINTF("HANDLE EP0\n");
  86491. +
  86492. + switch (pcd->ep0state) {
  86493. + case EP0_DISCONNECT:
  86494. + break;
  86495. +
  86496. + case EP0_IDLE:
  86497. + pcd->request_config = 0;
  86498. +
  86499. + pcd_setup(pcd);
  86500. + break;
  86501. +
  86502. + case EP0_IN_DATA_PHASE:
  86503. +#ifdef DEBUG_EP0
  86504. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  86505. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  86506. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  86507. +#endif
  86508. +
  86509. + if (core_if->dma_enable != 0) {
  86510. + /*
  86511. + * For EP0 we can only program 1 packet at a time so we
  86512. + * need to do the make calculations after each complete.
  86513. + * Call write_packet to make the calculations, as in
  86514. + * slave mode, and use those values to determine if we
  86515. + * can complete.
  86516. + */
  86517. + if (core_if->dma_desc_enable == 0) {
  86518. + deptsiz.d32 =
  86519. + DWC_READ_REG32(&core_if->
  86520. + dev_if->in_ep_regs[0]->
  86521. + dieptsiz);
  86522. + byte_count =
  86523. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  86524. + } else {
  86525. + desc_sts =
  86526. + core_if->dev_if->in_desc_addr->status;
  86527. + byte_count =
  86528. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  86529. + }
  86530. + ep0->dwc_ep.xfer_count += byte_count;
  86531. + ep0->dwc_ep.xfer_buff += byte_count;
  86532. + ep0->dwc_ep.dma_addr += byte_count;
  86533. + }
  86534. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  86535. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86536. + &ep0->dwc_ep);
  86537. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  86538. + } else if (ep0->dwc_ep.sent_zlp) {
  86539. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86540. + &ep0->dwc_ep);
  86541. + ep0->dwc_ep.sent_zlp = 0;
  86542. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  86543. + } else {
  86544. + ep0_complete_request(ep0);
  86545. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  86546. + }
  86547. + break;
  86548. + case EP0_OUT_DATA_PHASE:
  86549. +#ifdef DEBUG_EP0
  86550. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  86551. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  86552. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  86553. +#endif
  86554. + if (core_if->dma_enable != 0) {
  86555. + if (core_if->dma_desc_enable == 0) {
  86556. + deptsiz.d32 =
  86557. + DWC_READ_REG32(&core_if->
  86558. + dev_if->out_ep_regs[0]->
  86559. + doeptsiz);
  86560. + byte_count =
  86561. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  86562. + } else {
  86563. + desc_sts =
  86564. + core_if->dev_if->out_desc_addr->status;
  86565. + byte_count =
  86566. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  86567. + }
  86568. + ep0->dwc_ep.xfer_count += byte_count;
  86569. + ep0->dwc_ep.xfer_buff += byte_count;
  86570. + ep0->dwc_ep.dma_addr += byte_count;
  86571. + }
  86572. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  86573. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86574. + &ep0->dwc_ep);
  86575. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  86576. + } else if (ep0->dwc_ep.sent_zlp) {
  86577. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86578. + &ep0->dwc_ep);
  86579. + ep0->dwc_ep.sent_zlp = 0;
  86580. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  86581. + } else {
  86582. + ep0_complete_request(ep0);
  86583. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  86584. + }
  86585. + break;
  86586. +
  86587. + case EP0_IN_STATUS_PHASE:
  86588. + case EP0_OUT_STATUS_PHASE:
  86589. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  86590. + ep0_complete_request(ep0);
  86591. + pcd->ep0state = EP0_IDLE;
  86592. + ep0->stopped = 1;
  86593. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  86594. +
  86595. + /* Prepare for more SETUP Packets */
  86596. + if (core_if->dma_enable) {
  86597. + ep0_out_start(core_if, pcd);
  86598. + }
  86599. + break;
  86600. +
  86601. + case EP0_STALL:
  86602. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  86603. + break;
  86604. + }
  86605. +#ifdef DEBUG_EP0
  86606. + print_ep0_state(pcd);
  86607. +#endif
  86608. +}
  86609. +
  86610. +/**
  86611. + * Restart transfer
  86612. + */
  86613. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  86614. +{
  86615. + dwc_otg_core_if_t *core_if;
  86616. + dwc_otg_dev_if_t *dev_if;
  86617. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86618. + dwc_otg_pcd_ep_t *ep;
  86619. +
  86620. + ep = get_in_ep(pcd, epnum);
  86621. +
  86622. +#ifdef DWC_EN_ISOC
  86623. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86624. + return;
  86625. + }
  86626. +#endif /* DWC_EN_ISOC */
  86627. +
  86628. + core_if = GET_CORE_IF(pcd);
  86629. + dev_if = core_if->dev_if;
  86630. +
  86631. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  86632. +
  86633. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  86634. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  86635. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  86636. + /*
  86637. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  86638. + */
  86639. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  86640. + ep->dwc_ep.start_xfer_buff != 0) {
  86641. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  86642. + ep->dwc_ep.xfer_count = 0;
  86643. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  86644. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  86645. + } else {
  86646. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  86647. + /* convert packet size to dwords. */
  86648. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  86649. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  86650. + }
  86651. + ep->stopped = 0;
  86652. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  86653. + "xfer_len=%0x stopped=%d\n",
  86654. + ep->dwc_ep.xfer_buff,
  86655. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  86656. + ep->stopped);
  86657. + if (epnum == 0) {
  86658. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  86659. + } else {
  86660. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  86661. + }
  86662. + }
  86663. +}
  86664. +
  86665. +/*
  86666. + * This function create new nextep sequnce based on Learn Queue.
  86667. + *
  86668. + * @param core_if Programming view of DWC_otg controller
  86669. + */
  86670. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  86671. +{
  86672. + dwc_otg_device_global_regs_t *dev_global_regs =
  86673. + core_if->dev_if->dev_global_regs;
  86674. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  86675. + /* Number of Token Queue Registers */
  86676. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  86677. + dtknq1_data_t dtknqr1;
  86678. + uint32_t in_tkn_epnums[4];
  86679. + uint8_t seqnum[MAX_EPS_CHANNELS];
  86680. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  86681. + grstctl_t resetctl = {.d32 = 0 };
  86682. + uint8_t temp;
  86683. + int ndx = 0;
  86684. + int start = 0;
  86685. + int end = 0;
  86686. + int sort_done = 0;
  86687. + int i = 0;
  86688. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  86689. +
  86690. +
  86691. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  86692. +
  86693. + /* Read the DTKNQ Registers */
  86694. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  86695. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  86696. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  86697. + in_tkn_epnums[i]);
  86698. + if (addr == &dev_global_regs->dvbusdis) {
  86699. + addr = &dev_global_regs->dtknqr3_dthrctl;
  86700. + } else {
  86701. + ++addr;
  86702. + }
  86703. +
  86704. + }
  86705. +
  86706. + /* Copy the DTKNQR1 data to the bit field. */
  86707. + dtknqr1.d32 = in_tkn_epnums[0];
  86708. + if (dtknqr1.b.wrap_bit) {
  86709. + ndx = dtknqr1.b.intknwptr;
  86710. + end = ndx -1;
  86711. + if (end < 0)
  86712. + end = TOKEN_Q_DEPTH -1;
  86713. + } else {
  86714. + ndx = 0;
  86715. + end = dtknqr1.b.intknwptr -1;
  86716. + if (end < 0)
  86717. + end = 0;
  86718. + }
  86719. + start = ndx;
  86720. +
  86721. + /* Fill seqnum[] by initial values: EP number + 31 */
  86722. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  86723. + seqnum[i] = i +31;
  86724. + }
  86725. +
  86726. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  86727. + for (i=0; i < 6; i++)
  86728. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  86729. +
  86730. + if (TOKEN_Q_DEPTH > 6) {
  86731. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  86732. + for (i=6; i < 14; i++)
  86733. + intkn_seq[i] =
  86734. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  86735. + }
  86736. +
  86737. + if (TOKEN_Q_DEPTH > 14) {
  86738. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  86739. + for (i=14; i < 22; i++)
  86740. + intkn_seq[i] =
  86741. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  86742. + }
  86743. +
  86744. + if (TOKEN_Q_DEPTH > 22) {
  86745. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  86746. + for (i=22; i < 30; i++)
  86747. + intkn_seq[i] =
  86748. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  86749. + }
  86750. +
  86751. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  86752. + start, end);
  86753. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  86754. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  86755. +
  86756. + /* Update seqnum based on intkn_seq[] */
  86757. + i = 0;
  86758. + do {
  86759. + seqnum[intkn_seq[ndx]] = i;
  86760. + ndx++;
  86761. + i++;
  86762. + if (ndx == TOKEN_Q_DEPTH)
  86763. + ndx = 0;
  86764. + } while ( i < TOKEN_Q_DEPTH );
  86765. +
  86766. + /* Mark non active EP's in seqnum[] by 0xff */
  86767. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  86768. + if (core_if->nextep_seq[i] == 0xff )
  86769. + seqnum[i] = 0xff;
  86770. + }
  86771. +
  86772. + /* Sort seqnum[] */
  86773. + sort_done = 0;
  86774. + while (!sort_done) {
  86775. + sort_done = 1;
  86776. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  86777. + if (seqnum[i] > seqnum[i+1]) {
  86778. + temp = seqnum[i];
  86779. + seqnum[i] = seqnum[i+1];
  86780. + seqnum[i+1] = temp;
  86781. + sort_done = 0;
  86782. + }
  86783. + }
  86784. + }
  86785. +
  86786. + ndx = start + seqnum[0];
  86787. + if (ndx >= TOKEN_Q_DEPTH)
  86788. + ndx = ndx % TOKEN_Q_DEPTH;
  86789. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  86790. +
  86791. + /* Update seqnum[] by EP numbers */
  86792. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  86793. + ndx = start + i;
  86794. + if (seqnum[i] < 31) {
  86795. + ndx = start + seqnum[i];
  86796. + if (ndx >= TOKEN_Q_DEPTH)
  86797. + ndx = ndx % TOKEN_Q_DEPTH;
  86798. + seqnum[i] = intkn_seq[ndx];
  86799. + } else {
  86800. + if (seqnum[i] < 0xff) {
  86801. + seqnum[i] = seqnum[i] - 31;
  86802. + } else {
  86803. + break;
  86804. + }
  86805. + }
  86806. + }
  86807. +
  86808. + /* Update nextep_seq[] based on seqnum[] */
  86809. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  86810. + if (seqnum[i] != 0xff) {
  86811. + if (seqnum[i+1] != 0xff) {
  86812. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  86813. + } else {
  86814. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  86815. + break;
  86816. + }
  86817. + } else {
  86818. + break;
  86819. + }
  86820. + }
  86821. +
  86822. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  86823. + __func__, core_if->first_in_nextep_seq);
  86824. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  86825. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  86826. + }
  86827. +
  86828. + /* Flush the Learning Queue */
  86829. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  86830. + resetctl.b.intknqflsh = 1;
  86831. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  86832. +
  86833. +
  86834. +}
  86835. +
  86836. +/**
  86837. + * handle the IN EP disable interrupt.
  86838. + */
  86839. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  86840. + const uint32_t epnum)
  86841. +{
  86842. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86843. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86844. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86845. + dctl_data_t dctl = {.d32 = 0 };
  86846. + dwc_otg_pcd_ep_t *ep;
  86847. + dwc_ep_t *dwc_ep;
  86848. + gintmsk_data_t gintmsk_data;
  86849. + depctl_data_t depctl;
  86850. + uint32_t diepdma;
  86851. + uint32_t remain_to_transfer = 0;
  86852. + uint8_t i;
  86853. + uint32_t xfer_size;
  86854. +
  86855. + ep = get_in_ep(pcd, epnum);
  86856. + dwc_ep = &ep->dwc_ep;
  86857. +
  86858. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86859. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  86860. + complete_ep(ep);
  86861. + return;
  86862. + }
  86863. +
  86864. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  86865. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  86866. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  86867. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  86868. +
  86869. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  86870. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  86871. +
  86872. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  86873. + if (ep->stopped) {
  86874. + if (core_if->en_multiple_tx_fifo)
  86875. + /* Flush the Tx FIFO */
  86876. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  86877. + /* Clear the Global IN NP NAK */
  86878. + dctl.d32 = 0;
  86879. + dctl.b.cgnpinnak = 1;
  86880. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86881. + /* Restart the transaction */
  86882. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  86883. + restart_transfer(pcd, epnum);
  86884. + }
  86885. + } else {
  86886. + /* Restart the transaction */
  86887. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  86888. + restart_transfer(pcd, epnum);
  86889. + }
  86890. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  86891. + }
  86892. + return;
  86893. + }
  86894. +
  86895. + if (core_if->start_predict > 2) { // NP IN EP
  86896. + core_if->start_predict--;
  86897. + return;
  86898. + }
  86899. +
  86900. + core_if->start_predict--;
  86901. +
  86902. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  86903. +
  86904. + predict_nextep_seq(core_if);
  86905. +
  86906. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  86907. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  86908. + depctl.d32 =
  86909. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86910. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  86911. + depctl.b.nextep = core_if->nextep_seq[i];
  86912. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  86913. + }
  86914. + }
  86915. + /* Flush Shared NP TxFIFO */
  86916. + dwc_otg_flush_tx_fifo(core_if, 0);
  86917. + /* Rewind buffers */
  86918. + if (!core_if->dma_desc_enable) {
  86919. + i = core_if->first_in_nextep_seq;
  86920. + do {
  86921. + ep = get_in_ep(pcd, i);
  86922. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  86923. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  86924. + if (xfer_size > ep->dwc_ep.maxxfer)
  86925. + xfer_size = ep->dwc_ep.maxxfer;
  86926. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86927. + if (dieptsiz.b.pktcnt != 0) {
  86928. + if (xfer_size == 0) {
  86929. + remain_to_transfer = 0;
  86930. + } else {
  86931. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  86932. + remain_to_transfer =
  86933. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  86934. + } else {
  86935. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  86936. + + (xfer_size % ep->dwc_ep.maxpacket);
  86937. + }
  86938. + }
  86939. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  86940. + dieptsiz.b.xfersize = remain_to_transfer;
  86941. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  86942. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  86943. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  86944. + }
  86945. + i = core_if->nextep_seq[i];
  86946. + } while (i != core_if->first_in_nextep_seq);
  86947. + } else { // dma_desc_enable
  86948. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  86949. + }
  86950. +
  86951. + /* Restart transfers in predicted sequences */
  86952. + i = core_if->first_in_nextep_seq;
  86953. + do {
  86954. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  86955. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86956. + if (dieptsiz.b.pktcnt != 0) {
  86957. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86958. + depctl.b.epena = 1;
  86959. + depctl.b.cnak = 1;
  86960. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  86961. + }
  86962. + i = core_if->nextep_seq[i];
  86963. + } while (i != core_if->first_in_nextep_seq);
  86964. +
  86965. + /* Clear the global non-periodic IN NAK handshake */
  86966. + dctl.d32 = 0;
  86967. + dctl.b.cgnpinnak = 1;
  86968. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86969. +
  86970. + /* Unmask EP Mismatch interrupt */
  86971. + gintmsk_data.d32 = 0;
  86972. + gintmsk_data.b.epmismatch = 1;
  86973. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  86974. +
  86975. + core_if->start_predict = 0;
  86976. +
  86977. + }
  86978. +}
  86979. +
  86980. +/**
  86981. + * Handler for the IN EP timeout handshake interrupt.
  86982. + */
  86983. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  86984. + const uint32_t epnum)
  86985. +{
  86986. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86987. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86988. +
  86989. +#ifdef DEBUG
  86990. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86991. + uint32_t num = 0;
  86992. +#endif
  86993. + dctl_data_t dctl = {.d32 = 0 };
  86994. + dwc_otg_pcd_ep_t *ep;
  86995. +
  86996. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86997. +
  86998. + ep = get_in_ep(pcd, epnum);
  86999. +
  87000. + /* Disable the NP Tx Fifo Empty Interrrupt */
  87001. + if (!core_if->dma_enable) {
  87002. + intr_mask.b.nptxfempty = 1;
  87003. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  87004. + intr_mask.d32, 0);
  87005. + }
  87006. + /** @todo NGS Check EP type.
  87007. + * Implement for Periodic EPs */
  87008. + /*
  87009. + * Non-periodic EP
  87010. + */
  87011. + /* Enable the Global IN NAK Effective Interrupt */
  87012. + intr_mask.b.ginnakeff = 1;
  87013. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  87014. +
  87015. + /* Set Global IN NAK */
  87016. + dctl.b.sgnpinnak = 1;
  87017. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  87018. +
  87019. + ep->stopped = 1;
  87020. +
  87021. +#ifdef DEBUG
  87022. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  87023. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  87024. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  87025. +#endif
  87026. +
  87027. +#ifdef DISABLE_PERIODIC_EP
  87028. + /*
  87029. + * Set the NAK bit for this EP to
  87030. + * start the disable process.
  87031. + */
  87032. + diepctl.d32 = 0;
  87033. + diepctl.b.snak = 1;
  87034. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  87035. + diepctl.d32);
  87036. + ep->disabling = 1;
  87037. + ep->stopped = 1;
  87038. +#endif
  87039. +}
  87040. +
  87041. +/**
  87042. + * Handler for the IN EP NAK interrupt.
  87043. + */
  87044. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  87045. + const uint32_t epnum)
  87046. +{
  87047. + /** @todo implement ISR */
  87048. + dwc_otg_core_if_t *core_if;
  87049. + diepmsk_data_t intr_mask = {.d32 = 0 };
  87050. +
  87051. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  87052. + core_if = GET_CORE_IF(pcd);
  87053. + intr_mask.b.nak = 1;
  87054. +
  87055. + if (core_if->multiproc_int_enable) {
  87056. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  87057. + diepeachintmsk[epnum], intr_mask.d32, 0);
  87058. + } else {
  87059. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  87060. + intr_mask.d32, 0);
  87061. + }
  87062. +
  87063. + return 1;
  87064. +}
  87065. +
  87066. +/**
  87067. + * Handler for the OUT EP Babble interrupt.
  87068. + */
  87069. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  87070. + const uint32_t epnum)
  87071. +{
  87072. + /** @todo implement ISR */
  87073. + dwc_otg_core_if_t *core_if;
  87074. + doepmsk_data_t intr_mask = {.d32 = 0 };
  87075. +
  87076. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  87077. + "OUT EP Babble");
  87078. + core_if = GET_CORE_IF(pcd);
  87079. + intr_mask.b.babble = 1;
  87080. +
  87081. + if (core_if->multiproc_int_enable) {
  87082. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  87083. + doepeachintmsk[epnum], intr_mask.d32, 0);
  87084. + } else {
  87085. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  87086. + intr_mask.d32, 0);
  87087. + }
  87088. +
  87089. + return 1;
  87090. +}
  87091. +
  87092. +/**
  87093. + * Handler for the OUT EP NAK interrupt.
  87094. + */
  87095. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  87096. + const uint32_t epnum)
  87097. +{
  87098. + /** @todo implement ISR */
  87099. + dwc_otg_core_if_t *core_if;
  87100. + doepmsk_data_t intr_mask = {.d32 = 0 };
  87101. +
  87102. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  87103. + core_if = GET_CORE_IF(pcd);
  87104. + intr_mask.b.nak = 1;
  87105. +
  87106. + if (core_if->multiproc_int_enable) {
  87107. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  87108. + doepeachintmsk[epnum], intr_mask.d32, 0);
  87109. + } else {
  87110. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  87111. + intr_mask.d32, 0);
  87112. + }
  87113. +
  87114. + return 1;
  87115. +}
  87116. +
  87117. +/**
  87118. + * Handler for the OUT EP NYET interrupt.
  87119. + */
  87120. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  87121. + const uint32_t epnum)
  87122. +{
  87123. + /** @todo implement ISR */
  87124. + dwc_otg_core_if_t *core_if;
  87125. + doepmsk_data_t intr_mask = {.d32 = 0 };
  87126. +
  87127. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  87128. + core_if = GET_CORE_IF(pcd);
  87129. + intr_mask.b.nyet = 1;
  87130. +
  87131. + if (core_if->multiproc_int_enable) {
  87132. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  87133. + doepeachintmsk[epnum], intr_mask.d32, 0);
  87134. + } else {
  87135. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  87136. + intr_mask.d32, 0);
  87137. + }
  87138. +
  87139. + return 1;
  87140. +}
  87141. +
  87142. +/**
  87143. + * This interrupt indicates that an IN EP has a pending Interrupt.
  87144. + * The sequence for handling the IN EP interrupt is shown below:
  87145. + * -# Read the Device All Endpoint Interrupt register
  87146. + * -# Repeat the following for each IN EP interrupt bit set (from
  87147. + * LSB to MSB).
  87148. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  87149. + * -# If "Transfer Complete" call the request complete function
  87150. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  87151. + * -# If "AHB Error Interrupt" log error
  87152. + * -# If "Time-out Handshake" log error
  87153. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  87154. + * FIFO.
  87155. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  87156. + * Mismatch Interrupt)
  87157. + */
  87158. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  87159. +{
  87160. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  87161. +do { \
  87162. + diepint_data_t diepint = {.d32=0}; \
  87163. + diepint.b.__intr = 1; \
  87164. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  87165. + diepint.d32); \
  87166. +} while (0)
  87167. +
  87168. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87169. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87170. + diepint_data_t diepint = {.d32 = 0 };
  87171. + depctl_data_t depctl = {.d32 = 0 };
  87172. + uint32_t ep_intr;
  87173. + uint32_t epnum = 0;
  87174. + dwc_otg_pcd_ep_t *ep;
  87175. + dwc_ep_t *dwc_ep;
  87176. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87177. +
  87178. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  87179. +
  87180. + /* Read in the device interrupt bits */
  87181. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  87182. +
  87183. + /* Service the Device IN interrupts for each endpoint */
  87184. + while (ep_intr) {
  87185. + if (ep_intr & 0x1) {
  87186. + uint32_t empty_msk;
  87187. + /* Get EP pointer */
  87188. + ep = get_in_ep(pcd, epnum);
  87189. + dwc_ep = &ep->dwc_ep;
  87190. +
  87191. + depctl.d32 =
  87192. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  87193. + empty_msk =
  87194. + DWC_READ_REG32(&dev_if->
  87195. + dev_global_regs->dtknqr4_fifoemptymsk);
  87196. +
  87197. + DWC_DEBUGPL(DBG_PCDV,
  87198. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  87199. + epnum, empty_msk, depctl.d32);
  87200. +
  87201. + DWC_DEBUGPL(DBG_PCD,
  87202. + "EP%d-%s: type=%d, mps=%d\n",
  87203. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  87204. + dwc_ep->type, dwc_ep->maxpacket);
  87205. +
  87206. + diepint.d32 =
  87207. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  87208. +
  87209. + DWC_DEBUGPL(DBG_PCDV,
  87210. + "EP %d Interrupt Register - 0x%x\n", epnum,
  87211. + diepint.d32);
  87212. + /* Transfer complete */
  87213. + if (diepint.b.xfercompl) {
  87214. + /* Disable the NP Tx FIFO Empty
  87215. + * Interrupt */
  87216. + if (core_if->en_multiple_tx_fifo == 0) {
  87217. + intr_mask.b.nptxfempty = 1;
  87218. + DWC_MODIFY_REG32
  87219. + (&core_if->core_global_regs->gintmsk,
  87220. + intr_mask.d32, 0);
  87221. + } else {
  87222. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  87223. + uint32_t fifoemptymsk =
  87224. + 0x1 << dwc_ep->num;
  87225. + DWC_MODIFY_REG32(&core_if->
  87226. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  87227. + fifoemptymsk, 0);
  87228. + }
  87229. + /* Clear the bit in DIEPINTn for this interrupt */
  87230. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  87231. +
  87232. + /* Complete the transfer */
  87233. + if (epnum == 0) {
  87234. + handle_ep0(pcd);
  87235. + }
  87236. +#ifdef DWC_EN_ISOC
  87237. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87238. + if (!ep->stopped)
  87239. + complete_iso_ep(pcd, ep);
  87240. + }
  87241. +#endif /* DWC_EN_ISOC */
  87242. +#ifdef DWC_UTE_PER_IO
  87243. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87244. + if (!ep->stopped)
  87245. + complete_xiso_ep(ep);
  87246. + }
  87247. +#endif /* DWC_UTE_PER_IO */
  87248. + else {
  87249. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  87250. + dwc_ep->bInterval > 1) {
  87251. + dwc_ep->frame_num += dwc_ep->bInterval;
  87252. + if (dwc_ep->frame_num > 0x3FFF)
  87253. + {
  87254. + dwc_ep->frm_overrun = 1;
  87255. + dwc_ep->frame_num &= 0x3FFF;
  87256. + } else
  87257. + dwc_ep->frm_overrun = 0;
  87258. + }
  87259. + complete_ep(ep);
  87260. + if(diepint.b.nak)
  87261. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  87262. + }
  87263. + }
  87264. + /* Endpoint disable */
  87265. + if (diepint.b.epdisabled) {
  87266. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  87267. + epnum);
  87268. + handle_in_ep_disable_intr(pcd, epnum);
  87269. +
  87270. + /* Clear the bit in DIEPINTn for this interrupt */
  87271. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  87272. + }
  87273. + /* AHB Error */
  87274. + if (diepint.b.ahberr) {
  87275. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  87276. + /* Clear the bit in DIEPINTn for this interrupt */
  87277. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  87278. + }
  87279. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  87280. + if (diepint.b.timeout) {
  87281. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  87282. + handle_in_ep_timeout_intr(pcd, epnum);
  87283. +
  87284. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  87285. + }
  87286. + /** IN Token received with TxF Empty */
  87287. + if (diepint.b.intktxfemp) {
  87288. + DWC_DEBUGPL(DBG_ANY,
  87289. + "EP%d IN TKN TxFifo Empty\n",
  87290. + epnum);
  87291. + if (!ep->stopped && epnum != 0) {
  87292. +
  87293. + diepmsk_data_t diepmsk = {.d32 = 0 };
  87294. + diepmsk.b.intktxfemp = 1;
  87295. +
  87296. + if (core_if->multiproc_int_enable) {
  87297. + DWC_MODIFY_REG32
  87298. + (&dev_if->dev_global_regs->diepeachintmsk
  87299. + [epnum], diepmsk.d32, 0);
  87300. + } else {
  87301. + DWC_MODIFY_REG32
  87302. + (&dev_if->dev_global_regs->diepmsk,
  87303. + diepmsk.d32, 0);
  87304. + }
  87305. + } else if (core_if->dma_desc_enable
  87306. + && epnum == 0
  87307. + && pcd->ep0state ==
  87308. + EP0_OUT_STATUS_PHASE) {
  87309. + // EP0 IN set STALL
  87310. + depctl.d32 =
  87311. + DWC_READ_REG32(&dev_if->in_ep_regs
  87312. + [epnum]->diepctl);
  87313. +
  87314. + /* set the disable and stall bits */
  87315. + if (depctl.b.epena) {
  87316. + depctl.b.epdis = 1;
  87317. + }
  87318. + depctl.b.stall = 1;
  87319. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  87320. + [epnum]->diepctl,
  87321. + depctl.d32);
  87322. + }
  87323. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  87324. + }
  87325. + /** IN Token Received with EP mismatch */
  87326. + if (diepint.b.intknepmis) {
  87327. + DWC_DEBUGPL(DBG_ANY,
  87328. + "EP%d IN TKN EP Mismatch\n", epnum);
  87329. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  87330. + }
  87331. + /** IN Endpoint NAK Effective */
  87332. + if (diepint.b.inepnakeff) {
  87333. + DWC_DEBUGPL(DBG_ANY,
  87334. + "EP%d IN EP NAK Effective\n",
  87335. + epnum);
  87336. + /* Periodic EP */
  87337. + if (ep->disabling) {
  87338. + depctl.d32 = 0;
  87339. + depctl.b.snak = 1;
  87340. + depctl.b.epdis = 1;
  87341. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  87342. + [epnum]->diepctl,
  87343. + depctl.d32,
  87344. + depctl.d32);
  87345. + }
  87346. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  87347. +
  87348. + }
  87349. +
  87350. + /** IN EP Tx FIFO Empty Intr */
  87351. + if (diepint.b.emptyintr) {
  87352. + DWC_DEBUGPL(DBG_ANY,
  87353. + "EP%d Tx FIFO Empty Intr \n",
  87354. + epnum);
  87355. + write_empty_tx_fifo(pcd, epnum);
  87356. +
  87357. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  87358. +
  87359. + }
  87360. +
  87361. + /** IN EP BNA Intr */
  87362. + if (diepint.b.bna) {
  87363. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  87364. + if (core_if->dma_desc_enable) {
  87365. +#ifdef DWC_EN_ISOC
  87366. + if (dwc_ep->type ==
  87367. + DWC_OTG_EP_TYPE_ISOC) {
  87368. + /*
  87369. + * This checking is performed to prevent first "false" BNA
  87370. + * handling occuring right after reconnect
  87371. + */
  87372. + if (dwc_ep->next_frame !=
  87373. + 0xffffffff)
  87374. + dwc_otg_pcd_handle_iso_bna(ep);
  87375. + } else
  87376. +#endif /* DWC_EN_ISOC */
  87377. + {
  87378. + dwc_otg_pcd_handle_noniso_bna(ep);
  87379. + }
  87380. + }
  87381. + }
  87382. + /* NAK Interrutp */
  87383. + if (diepint.b.nak) {
  87384. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  87385. + epnum);
  87386. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87387. + depctl_data_t depctl;
  87388. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  87389. + ep->dwc_ep.frame_num = core_if->frame_num;
  87390. + if (ep->dwc_ep.bInterval > 1) {
  87391. + depctl.d32 = 0;
  87392. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  87393. + if (ep->dwc_ep.frame_num & 0x1) {
  87394. + depctl.b.setd1pid = 1;
  87395. + depctl.b.setd0pid = 0;
  87396. + } else {
  87397. + depctl.b.setd0pid = 1;
  87398. + depctl.b.setd1pid = 0;
  87399. + }
  87400. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  87401. + }
  87402. + start_next_request(ep);
  87403. + }
  87404. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  87405. + if (dwc_ep->frame_num > 0x3FFF) {
  87406. + dwc_ep->frm_overrun = 1;
  87407. + dwc_ep->frame_num &= 0x3FFF;
  87408. + } else
  87409. + dwc_ep->frm_overrun = 0;
  87410. + }
  87411. +
  87412. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  87413. + }
  87414. + }
  87415. + epnum++;
  87416. + ep_intr >>= 1;
  87417. + }
  87418. +
  87419. + return 1;
  87420. +#undef CLEAR_IN_EP_INTR
  87421. +}
  87422. +
  87423. +/**
  87424. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  87425. + * The sequence for handling the OUT EP interrupt is shown below:
  87426. + * -# Read the Device All Endpoint Interrupt register
  87427. + * -# Repeat the following for each OUT EP interrupt bit set (from
  87428. + * LSB to MSB).
  87429. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  87430. + * -# If "Transfer Complete" call the request complete function
  87431. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  87432. + * -# If "AHB Error Interrupt" log error
  87433. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  87434. + * Command Processing)
  87435. + */
  87436. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  87437. +{
  87438. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  87439. +do { \
  87440. + doepint_data_t doepint = {.d32=0}; \
  87441. + doepint.b.__intr = 1; \
  87442. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  87443. + doepint.d32); \
  87444. +} while (0)
  87445. +
  87446. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87447. + uint32_t ep_intr;
  87448. + doepint_data_t doepint = {.d32 = 0 };
  87449. + uint32_t epnum = 0;
  87450. + dwc_otg_pcd_ep_t *ep;
  87451. + dwc_ep_t *dwc_ep;
  87452. + dctl_data_t dctl = {.d32 = 0 };
  87453. + gintmsk_data_t gintmsk = {.d32 = 0 };
  87454. +
  87455. +
  87456. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  87457. +
  87458. + /* Read in the device interrupt bits */
  87459. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  87460. +
  87461. + while (ep_intr) {
  87462. + if (ep_intr & 0x1) {
  87463. + /* Get EP pointer */
  87464. + ep = get_out_ep(pcd, epnum);
  87465. + dwc_ep = &ep->dwc_ep;
  87466. +
  87467. +#ifdef VERBOSE
  87468. + DWC_DEBUGPL(DBG_PCDV,
  87469. + "EP%d-%s: type=%d, mps=%d\n",
  87470. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  87471. + dwc_ep->type, dwc_ep->maxpacket);
  87472. +#endif
  87473. + doepint.d32 =
  87474. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  87475. + /* Moved this interrupt upper due to core deffect of asserting
  87476. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  87477. + if (doepint.b.stsphsercvd) {
  87478. + deptsiz0_data_t deptsiz;
  87479. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  87480. + deptsiz.d32 =
  87481. + DWC_READ_REG32(&core_if->dev_if->
  87482. + out_ep_regs[0]->doeptsiz);
  87483. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  87484. + && core_if->dma_enable
  87485. + && core_if->dma_desc_enable == 0
  87486. + && doepint.b.xfercompl
  87487. + && deptsiz.b.xfersize == 24) {
  87488. + CLEAR_OUT_EP_INTR(core_if, epnum,
  87489. + xfercompl);
  87490. + doepint.b.xfercompl = 0;
  87491. + ep0_out_start(core_if, pcd);
  87492. + }
  87493. + if ((core_if->dma_desc_enable) ||
  87494. + (core_if->dma_enable
  87495. + && core_if->snpsid >=
  87496. + OTG_CORE_REV_3_00a)) {
  87497. + do_setup_in_status_phase(pcd);
  87498. + }
  87499. + }
  87500. + /* Transfer complete */
  87501. + if (doepint.b.xfercompl) {
  87502. +
  87503. + if (epnum == 0) {
  87504. + /* Clear the bit in DOEPINTn for this interrupt */
  87505. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  87506. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  87507. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  87508. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  87509. + doepint.d32);
  87510. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  87511. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  87512. +
  87513. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  87514. + && core_if->dma_enable == 0) {
  87515. + doepint_data_t doepint;
  87516. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87517. + out_ep_regs[0]->doepint);
  87518. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  87519. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  87520. + goto exit_xfercompl;
  87521. + }
  87522. + }
  87523. + /* In case of DDMA look at SR bit to go to the Data Stage */
  87524. + if (core_if->dma_desc_enable) {
  87525. + dev_dma_desc_sts_t status = {.d32 = 0};
  87526. + if (pcd->ep0state == EP0_IDLE) {
  87527. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  87528. + dev_if->setup_desc_index]->status.d32;
  87529. + if(pcd->data_terminated) {
  87530. + pcd->data_terminated = 0;
  87531. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  87532. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  87533. + }
  87534. + if (status.b.sr) {
  87535. + if (doepint.b.setup) {
  87536. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  87537. + /* Already started data stage, clear setup */
  87538. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87539. + doepint.b.setup = 0;
  87540. + handle_ep0(pcd);
  87541. + /* Prepare for more setup packets */
  87542. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  87543. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  87544. + ep0_out_start(core_if, pcd);
  87545. + }
  87546. +
  87547. + goto exit_xfercompl;
  87548. + } else {
  87549. + /* Prepare for more setup packets */
  87550. + DWC_DEBUGPL(DBG_PCDV,
  87551. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  87552. + ep0_out_start(core_if, pcd);
  87553. + }
  87554. + }
  87555. + } else {
  87556. + dwc_otg_pcd_request_t *req;
  87557. + dev_dma_desc_sts_t status = {.d32 = 0};
  87558. + diepint_data_t diepint0;
  87559. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87560. + in_ep_regs[0]->diepint);
  87561. +
  87562. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  87563. + DWC_ERROR("EP0 is stalled/disconnected\n");
  87564. + }
  87565. +
  87566. + /* Clear IN xfercompl if set */
  87567. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  87568. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  87569. + DWC_WRITE_REG32(&core_if->dev_if->
  87570. + in_ep_regs[0]->diepint, diepint0.d32);
  87571. + }
  87572. +
  87573. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  87574. + dev_if->setup_desc_index]->status.d32;
  87575. +
  87576. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  87577. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  87578. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  87579. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  87580. + status.d32 = core_if->dev_if->
  87581. + out_desc_addr->status.d32;
  87582. +
  87583. + if (status.b.sr) {
  87584. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87585. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  87586. + } else {
  87587. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  87588. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87589. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  87590. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  87591. + /* Read arrived setup packet from req->buf */
  87592. + dwc_memcpy(&pcd->setup_pkt->req,
  87593. + req->buf + ep->dwc_ep.xfer_count, 8);
  87594. + }
  87595. + req->actual = ep->dwc_ep.xfer_count;
  87596. + dwc_otg_request_done(ep, req, -ECONNRESET);
  87597. + ep->dwc_ep.start_xfer_buff = 0;
  87598. + ep->dwc_ep.xfer_buff = 0;
  87599. + ep->dwc_ep.xfer_len = 0;
  87600. + }
  87601. + pcd->ep0state = EP0_IDLE;
  87602. + if (doepint.b.setup) {
  87603. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  87604. + /* Data stage started, clear setup */
  87605. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87606. + doepint.b.setup = 0;
  87607. + handle_ep0(pcd);
  87608. + /* Prepare for setup packets if ep0in was enabled*/
  87609. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87610. + ep0_out_start(core_if, pcd);
  87611. + }
  87612. +
  87613. + goto exit_xfercompl;
  87614. + } else {
  87615. + /* Prepare for more setup packets */
  87616. + DWC_DEBUGPL(DBG_PCDV,
  87617. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  87618. + ep0_out_start(core_if, pcd);
  87619. + }
  87620. + }
  87621. + }
  87622. + }
  87623. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  87624. + && core_if->dma_desc_enable == 0) {
  87625. + doepint_data_t doepint_temp = {.d32 = 0};
  87626. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  87627. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  87628. + out_ep_regs[ep->dwc_ep.num]->doepint);
  87629. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87630. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  87631. + if (pcd->ep0state == EP0_IDLE) {
  87632. + if (doepint_temp.b.sr) {
  87633. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  87634. + }
  87635. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87636. + out_ep_regs[0]->doepint);
  87637. + if (doeptsize0.b.supcnt == 3) {
  87638. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  87639. + ep->dwc_ep.stp_rollover = 1;
  87640. + }
  87641. + if (doepint.b.setup) {
  87642. +retry:
  87643. + /* Already started data stage, clear setup */
  87644. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87645. + doepint.b.setup = 0;
  87646. + handle_ep0(pcd);
  87647. + ep->dwc_ep.stp_rollover = 0;
  87648. + /* Prepare for more setup packets */
  87649. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  87650. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  87651. + ep0_out_start(core_if, pcd);
  87652. + }
  87653. + goto exit_xfercompl;
  87654. + } else {
  87655. + /* Prepare for more setup packets */
  87656. + DWC_DEBUGPL(DBG_ANY,
  87657. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  87658. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87659. + out_ep_regs[0]->doepint);
  87660. + if(doepint.b.setup)
  87661. + goto retry;
  87662. + ep0_out_start(core_if, pcd);
  87663. + }
  87664. + } else {
  87665. + dwc_otg_pcd_request_t *req;
  87666. + diepint_data_t diepint0 = {.d32 = 0};
  87667. + doepint_data_t doepint_temp = {.d32 = 0};
  87668. + depctl_data_t diepctl0;
  87669. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87670. + in_ep_regs[0]->diepint);
  87671. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87672. + in_ep_regs[0]->diepctl);
  87673. +
  87674. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  87675. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87676. + if (diepint0.b.xfercompl) {
  87677. + DWC_WRITE_REG32(&core_if->dev_if->
  87678. + in_ep_regs[0]->diepint, diepint0.d32);
  87679. + }
  87680. + if (diepctl0.b.epena) {
  87681. + diepint_data_t diepint = {.d32 = 0};
  87682. + diepctl0.b.snak = 1;
  87683. + DWC_WRITE_REG32(&core_if->dev_if->
  87684. + in_ep_regs[0]->diepctl, diepctl0.d32);
  87685. + do {
  87686. + dwc_udelay(10);
  87687. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87688. + in_ep_regs[0]->diepint);
  87689. + } while (!diepint.b.inepnakeff);
  87690. + diepint.b.inepnakeff = 1;
  87691. + DWC_WRITE_REG32(&core_if->dev_if->
  87692. + in_ep_regs[0]->diepint, diepint.d32);
  87693. + diepctl0.d32 = 0;
  87694. + diepctl0.b.epdis = 1;
  87695. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  87696. + diepctl0.d32);
  87697. + do {
  87698. + dwc_udelay(10);
  87699. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87700. + in_ep_regs[0]->diepint);
  87701. + } while (!diepint.b.epdisabled);
  87702. + diepint.b.epdisabled = 1;
  87703. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  87704. + diepint.d32);
  87705. + }
  87706. + }
  87707. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  87708. + out_ep_regs[ep->dwc_ep.num]->doepint);
  87709. + if (doepint_temp.b.sr) {
  87710. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  87711. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87712. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  87713. + } else {
  87714. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  87715. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87716. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  87717. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  87718. + /* Read arrived setup packet from req->buf */
  87719. + dwc_memcpy(&pcd->setup_pkt->req,
  87720. + req->buf + ep->dwc_ep.xfer_count, 8);
  87721. + }
  87722. + req->actual = ep->dwc_ep.xfer_count;
  87723. + dwc_otg_request_done(ep, req, -ECONNRESET);
  87724. + ep->dwc_ep.start_xfer_buff = 0;
  87725. + ep->dwc_ep.xfer_buff = 0;
  87726. + ep->dwc_ep.xfer_len = 0;
  87727. + }
  87728. + pcd->ep0state = EP0_IDLE;
  87729. + if (doepint.b.setup) {
  87730. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  87731. + /* Data stage started, clear setup */
  87732. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87733. + doepint.b.setup = 0;
  87734. + handle_ep0(pcd);
  87735. + /* Prepare for setup packets if ep0in was enabled*/
  87736. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87737. + ep0_out_start(core_if, pcd);
  87738. + }
  87739. + goto exit_xfercompl;
  87740. + } else {
  87741. + /* Prepare for more setup packets */
  87742. + DWC_DEBUGPL(DBG_PCDV,
  87743. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  87744. + ep0_out_start(core_if, pcd);
  87745. + }
  87746. + }
  87747. + }
  87748. + }
  87749. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  87750. + handle_ep0(pcd);
  87751. +exit_xfercompl:
  87752. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  87753. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  87754. + } else {
  87755. + if (core_if->dma_desc_enable == 0
  87756. + || pcd->ep0state != EP0_IDLE)
  87757. + handle_ep0(pcd);
  87758. + }
  87759. +#ifdef DWC_EN_ISOC
  87760. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87761. + if (doepint.b.pktdrpsts == 0) {
  87762. + /* Clear the bit in DOEPINTn for this interrupt */
  87763. + CLEAR_OUT_EP_INTR(core_if,
  87764. + epnum,
  87765. + xfercompl);
  87766. + complete_iso_ep(pcd, ep);
  87767. + } else {
  87768. +
  87769. + doepint_data_t doepint = {.d32 = 0 };
  87770. + doepint.b.xfercompl = 1;
  87771. + doepint.b.pktdrpsts = 1;
  87772. + DWC_WRITE_REG32
  87773. + (&core_if->dev_if->out_ep_regs
  87774. + [epnum]->doepint,
  87775. + doepint.d32);
  87776. + if (handle_iso_out_pkt_dropped
  87777. + (core_if, dwc_ep)) {
  87778. + complete_iso_ep(pcd,
  87779. + ep);
  87780. + }
  87781. + }
  87782. +#endif /* DWC_EN_ISOC */
  87783. +#ifdef DWC_UTE_PER_IO
  87784. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87785. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  87786. + if (!ep->stopped)
  87787. + complete_xiso_ep(ep);
  87788. +#endif /* DWC_UTE_PER_IO */
  87789. + } else {
  87790. + /* Clear the bit in DOEPINTn for this interrupt */
  87791. + CLEAR_OUT_EP_INTR(core_if, epnum,
  87792. + xfercompl);
  87793. +
  87794. + if (core_if->core_params->dev_out_nak) {
  87795. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  87796. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  87797. +#ifdef DEBUG
  87798. + print_memory_payload(pcd, dwc_ep);
  87799. +#endif
  87800. + }
  87801. + complete_ep(ep);
  87802. + }
  87803. +
  87804. + }
  87805. +
  87806. + /* Endpoint disable */
  87807. + if (doepint.b.epdisabled) {
  87808. +
  87809. + /* Clear the bit in DOEPINTn for this interrupt */
  87810. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  87811. + if (core_if->core_params->dev_out_nak) {
  87812. +#ifdef DEBUG
  87813. + print_memory_payload(pcd, dwc_ep);
  87814. +#endif
  87815. + /* In case of timeout condition */
  87816. + if (core_if->ep_xfer_info[epnum].state == 2) {
  87817. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  87818. + dev_global_regs->dctl);
  87819. + dctl.b.cgoutnak = 1;
  87820. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  87821. + dctl.d32);
  87822. + /* Unmask goutnakeff interrupt which was masked
  87823. + * during handle nak out interrupt */
  87824. + gintmsk.b.goutnakeff = 1;
  87825. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  87826. + 0, gintmsk.d32);
  87827. +
  87828. + complete_ep(ep);
  87829. + }
  87830. + }
  87831. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  87832. + {
  87833. + dctl_data_t dctl;
  87834. + gintmsk_data_t intr_mask = {.d32 = 0};
  87835. + dwc_otg_pcd_request_t *req = 0;
  87836. +
  87837. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  87838. + dev_global_regs->dctl);
  87839. + dctl.b.cgoutnak = 1;
  87840. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  87841. + dctl.d32);
  87842. +
  87843. + intr_mask.d32 = 0;
  87844. + intr_mask.b.incomplisoout = 1;
  87845. +
  87846. + /* Get any pending requests */
  87847. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87848. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87849. + if (!req) {
  87850. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  87851. + } else {
  87852. + dwc_otg_request_done(ep, req, 0);
  87853. + start_next_request(ep);
  87854. + }
  87855. + } else {
  87856. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  87857. + }
  87858. + }
  87859. + }
  87860. + /* AHB Error */
  87861. + if (doepint.b.ahberr) {
  87862. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  87863. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  87864. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  87865. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  87866. + }
  87867. + /* Setup Phase Done (contorl EPs) */
  87868. + if (doepint.b.setup) {
  87869. +#ifdef DEBUG_EP0
  87870. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  87871. +#endif
  87872. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87873. +
  87874. + handle_ep0(pcd);
  87875. + }
  87876. +
  87877. + /** OUT EP BNA Intr */
  87878. + if (doepint.b.bna) {
  87879. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  87880. + if (core_if->dma_desc_enable) {
  87881. +#ifdef DWC_EN_ISOC
  87882. + if (dwc_ep->type ==
  87883. + DWC_OTG_EP_TYPE_ISOC) {
  87884. + /*
  87885. + * This checking is performed to prevent first "false" BNA
  87886. + * handling occuring right after reconnect
  87887. + */
  87888. + if (dwc_ep->next_frame !=
  87889. + 0xffffffff)
  87890. + dwc_otg_pcd_handle_iso_bna(ep);
  87891. + } else
  87892. +#endif /* DWC_EN_ISOC */
  87893. + {
  87894. + dwc_otg_pcd_handle_noniso_bna(ep);
  87895. + }
  87896. + }
  87897. + }
  87898. + /* Babble Interrupt */
  87899. + if (doepint.b.babble) {
  87900. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  87901. + epnum);
  87902. + handle_out_ep_babble_intr(pcd, epnum);
  87903. +
  87904. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  87905. + }
  87906. + if (doepint.b.outtknepdis) {
  87907. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  87908. + disabled\n",epnum);
  87909. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87910. + doepmsk_data_t doepmsk = {.d32 = 0};
  87911. + ep->dwc_ep.frame_num = core_if->frame_num;
  87912. + if (ep->dwc_ep.bInterval > 1) {
  87913. + depctl_data_t depctl;
  87914. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  87915. + out_ep_regs[epnum]->doepctl);
  87916. + if (ep->dwc_ep.frame_num & 0x1) {
  87917. + depctl.b.setd1pid = 1;
  87918. + depctl.b.setd0pid = 0;
  87919. + } else {
  87920. + depctl.b.setd0pid = 1;
  87921. + depctl.b.setd1pid = 0;
  87922. + }
  87923. + DWC_WRITE_REG32(&core_if->dev_if->
  87924. + out_ep_regs[epnum]->doepctl, depctl.d32);
  87925. + }
  87926. + start_next_request(ep);
  87927. + doepmsk.b.outtknepdis = 1;
  87928. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  87929. + doepmsk.d32, 0);
  87930. + }
  87931. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  87932. + }
  87933. +
  87934. + /* NAK Interrutp */
  87935. + if (doepint.b.nak) {
  87936. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  87937. + handle_out_ep_nak_intr(pcd, epnum);
  87938. +
  87939. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  87940. + }
  87941. + /* NYET Interrutp */
  87942. + if (doepint.b.nyet) {
  87943. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  87944. + handle_out_ep_nyet_intr(pcd, epnum);
  87945. +
  87946. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  87947. + }
  87948. + }
  87949. +
  87950. + epnum++;
  87951. + ep_intr >>= 1;
  87952. + }
  87953. +
  87954. + return 1;
  87955. +
  87956. +#undef CLEAR_OUT_EP_INTR
  87957. +}
  87958. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  87959. +{
  87960. + int retval = 0;
  87961. + if(!frm_overrun && curr_fr >= trgt_fr)
  87962. + retval = 1;
  87963. + else if (frm_overrun
  87964. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  87965. + retval = 1;
  87966. + return retval;
  87967. +}
  87968. +/**
  87969. + * Incomplete ISO IN Transfer Interrupt.
  87970. + * This interrupt indicates one of the following conditions occurred
  87971. + * while transmitting an ISOC transaction.
  87972. + * - Corrupted IN Token for ISOC EP.
  87973. + * - Packet not complete in FIFO.
  87974. + * The follow actions will be taken:
  87975. + * -# Determine the EP
  87976. + * -# Set incomplete flag in dwc_ep structure
  87977. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  87978. + * Flush FIFO
  87979. + */
  87980. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  87981. +{
  87982. + gintsts_data_t gintsts;
  87983. +
  87984. +#ifdef DWC_EN_ISOC
  87985. + dwc_otg_dev_if_t *dev_if;
  87986. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87987. + depctl_data_t depctl = {.d32 = 0 };
  87988. + dsts_data_t dsts = {.d32 = 0 };
  87989. + dwc_ep_t *dwc_ep;
  87990. + int i;
  87991. +
  87992. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87993. +
  87994. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  87995. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  87996. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87997. + deptsiz.d32 =
  87998. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  87999. + depctl.d32 =
  88000. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88001. +
  88002. + if (depctl.b.epdis && deptsiz.d32) {
  88003. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  88004. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  88005. + dwc_ep->cur_pkt = 0;
  88006. + dwc_ep->proc_buf_num =
  88007. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88008. +
  88009. + if (dwc_ep->proc_buf_num) {
  88010. + dwc_ep->cur_pkt_addr =
  88011. + dwc_ep->xfer_buff1;
  88012. + dwc_ep->cur_pkt_dma_addr =
  88013. + dwc_ep->dma_addr1;
  88014. + } else {
  88015. + dwc_ep->cur_pkt_addr =
  88016. + dwc_ep->xfer_buff0;
  88017. + dwc_ep->cur_pkt_dma_addr =
  88018. + dwc_ep->dma_addr0;
  88019. + }
  88020. +
  88021. + }
  88022. +
  88023. + dsts.d32 =
  88024. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  88025. + dev_global_regs->dsts);
  88026. + dwc_ep->next_frame = dsts.b.soffn;
  88027. +
  88028. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  88029. + (pcd),
  88030. + dwc_ep);
  88031. + }
  88032. + }
  88033. + }
  88034. +
  88035. +#else
  88036. + depctl_data_t depctl = {.d32 = 0 };
  88037. + dwc_ep_t *dwc_ep;
  88038. + dwc_otg_dev_if_t *dev_if;
  88039. + int i;
  88040. + dev_if = GET_CORE_IF(pcd)->dev_if;
  88041. +
  88042. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  88043. +
  88044. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  88045. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  88046. + depctl.d32 =
  88047. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88048. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88049. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  88050. + dwc_ep->frm_overrun))
  88051. + {
  88052. + depctl.d32 =
  88053. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88054. + depctl.b.snak = 1;
  88055. + depctl.b.epdis = 1;
  88056. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  88057. + }
  88058. + }
  88059. + }
  88060. +
  88061. + /*intr_mask.b.incomplisoin = 1;
  88062. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  88063. + intr_mask.d32, 0); */
  88064. +#endif //DWC_EN_ISOC
  88065. +
  88066. + /* Clear interrupt */
  88067. + gintsts.d32 = 0;
  88068. + gintsts.b.incomplisoin = 1;
  88069. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  88070. + gintsts.d32);
  88071. +
  88072. + return 1;
  88073. +}
  88074. +
  88075. +/**
  88076. + * Incomplete ISO OUT Transfer Interrupt.
  88077. + *
  88078. + * This interrupt indicates that the core has dropped an ISO OUT
  88079. + * packet. The following conditions can be the cause:
  88080. + * - FIFO Full, the entire packet would not fit in the FIFO.
  88081. + * - CRC Error
  88082. + * - Corrupted Token
  88083. + * The follow actions will be taken:
  88084. + * -# Determine the EP
  88085. + * -# Set incomplete flag in dwc_ep structure
  88086. + * -# Read any data from the FIFO
  88087. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  88088. + * re-enable EP.
  88089. + */
  88090. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  88091. +{
  88092. +
  88093. + gintsts_data_t gintsts;
  88094. +
  88095. +#ifdef DWC_EN_ISOC
  88096. + dwc_otg_dev_if_t *dev_if;
  88097. + deptsiz_data_t deptsiz = {.d32 = 0 };
  88098. + depctl_data_t depctl = {.d32 = 0 };
  88099. + dsts_data_t dsts = {.d32 = 0 };
  88100. + dwc_ep_t *dwc_ep;
  88101. + int i;
  88102. +
  88103. + dev_if = GET_CORE_IF(pcd)->dev_if;
  88104. +
  88105. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  88106. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  88107. + if (pcd->out_ep[i].dwc_ep.active &&
  88108. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  88109. + deptsiz.d32 =
  88110. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  88111. + depctl.d32 =
  88112. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  88113. +
  88114. + if (depctl.b.epdis && deptsiz.d32) {
  88115. + set_current_pkt_info(GET_CORE_IF(pcd),
  88116. + &pcd->out_ep[i].dwc_ep);
  88117. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  88118. + dwc_ep->cur_pkt = 0;
  88119. + dwc_ep->proc_buf_num =
  88120. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88121. +
  88122. + if (dwc_ep->proc_buf_num) {
  88123. + dwc_ep->cur_pkt_addr =
  88124. + dwc_ep->xfer_buff1;
  88125. + dwc_ep->cur_pkt_dma_addr =
  88126. + dwc_ep->dma_addr1;
  88127. + } else {
  88128. + dwc_ep->cur_pkt_addr =
  88129. + dwc_ep->xfer_buff0;
  88130. + dwc_ep->cur_pkt_dma_addr =
  88131. + dwc_ep->dma_addr0;
  88132. + }
  88133. +
  88134. + }
  88135. +
  88136. + dsts.d32 =
  88137. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  88138. + dev_global_regs->dsts);
  88139. + dwc_ep->next_frame = dsts.b.soffn;
  88140. +
  88141. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  88142. + (pcd),
  88143. + dwc_ep);
  88144. + }
  88145. + }
  88146. + }
  88147. +#else
  88148. + /** @todo implement ISR */
  88149. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88150. + dwc_otg_core_if_t *core_if;
  88151. + deptsiz_data_t deptsiz = {.d32 = 0 };
  88152. + depctl_data_t depctl = {.d32 = 0 };
  88153. + dctl_data_t dctl = {.d32 = 0 };
  88154. + dwc_ep_t *dwc_ep = NULL;
  88155. + int i;
  88156. + core_if = GET_CORE_IF(pcd);
  88157. +
  88158. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  88159. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  88160. + depctl.d32 =
  88161. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  88162. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  88163. + core_if->dev_if->isoc_ep = dwc_ep;
  88164. + deptsiz.d32 =
  88165. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  88166. + break;
  88167. + }
  88168. + }
  88169. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  88170. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  88171. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  88172. +
  88173. + if (!intr_mask.b.goutnakeff) {
  88174. + /* Unmask it */
  88175. + intr_mask.b.goutnakeff = 1;
  88176. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  88177. + }
  88178. + if (!gintsts.b.goutnakeff) {
  88179. + dctl.b.sgoutnak = 1;
  88180. + }
  88181. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  88182. +
  88183. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  88184. + if (depctl.b.epena) {
  88185. + depctl.b.epdis = 1;
  88186. + depctl.b.snak = 1;
  88187. + }
  88188. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  88189. +
  88190. + intr_mask.d32 = 0;
  88191. + intr_mask.b.incomplisoout = 1;
  88192. +
  88193. +#endif /* DWC_EN_ISOC */
  88194. +
  88195. + /* Clear interrupt */
  88196. + gintsts.d32 = 0;
  88197. + gintsts.b.incomplisoout = 1;
  88198. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  88199. + gintsts.d32);
  88200. +
  88201. + return 1;
  88202. +}
  88203. +
  88204. +/**
  88205. + * This function handles the Global IN NAK Effective interrupt.
  88206. + *
  88207. + */
  88208. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  88209. +{
  88210. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  88211. + depctl_data_t diepctl = {.d32 = 0 };
  88212. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88213. + gintsts_data_t gintsts;
  88214. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88215. + int i;
  88216. +
  88217. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  88218. +
  88219. + /* Disable all active IN EPs */
  88220. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  88221. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88222. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  88223. + if (core_if->start_predict > 0)
  88224. + core_if->start_predict++;
  88225. + diepctl.b.epdis = 1;
  88226. + diepctl.b.snak = 1;
  88227. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  88228. + }
  88229. + }
  88230. +
  88231. +
  88232. + /* Disable the Global IN NAK Effective Interrupt */
  88233. + intr_mask.b.ginnakeff = 1;
  88234. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  88235. + intr_mask.d32, 0);
  88236. +
  88237. + /* Clear interrupt */
  88238. + gintsts.d32 = 0;
  88239. + gintsts.b.ginnakeff = 1;
  88240. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  88241. + gintsts.d32);
  88242. +
  88243. + return 1;
  88244. +}
  88245. +
  88246. +/**
  88247. + * OUT NAK Effective.
  88248. + *
  88249. + */
  88250. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  88251. +{
  88252. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  88253. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88254. + gintsts_data_t gintsts;
  88255. + depctl_data_t doepctl;
  88256. + int i;
  88257. +
  88258. + /* Disable the Global OUT NAK Effective Interrupt */
  88259. + intr_mask.b.goutnakeff = 1;
  88260. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  88261. + intr_mask.d32, 0);
  88262. +
  88263. + /* If DEV OUT NAK enabled*/
  88264. + if (pcd->core_if->core_params->dev_out_nak) {
  88265. + /* Run over all out endpoints to determine the ep number on
  88266. + * which the timeout has happened
  88267. + */
  88268. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  88269. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  88270. + break;
  88271. + }
  88272. + if (i > dev_if->num_out_eps) {
  88273. + dctl_data_t dctl;
  88274. + dctl.d32 =
  88275. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  88276. + dctl.b.cgoutnak = 1;
  88277. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  88278. + dctl.d32);
  88279. + goto out;
  88280. + }
  88281. +
  88282. + /* Disable the endpoint */
  88283. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  88284. + if (doepctl.b.epena) {
  88285. + doepctl.b.epdis = 1;
  88286. + doepctl.b.snak = 1;
  88287. + }
  88288. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  88289. + return 1;
  88290. + }
  88291. + /* We come here from Incomplete ISO OUT handler */
  88292. + if (dev_if->isoc_ep) {
  88293. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  88294. + uint32_t epnum = dwc_ep->num;
  88295. + doepint_data_t doepint;
  88296. + doepint.d32 =
  88297. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  88298. + dev_if->isoc_ep = NULL;
  88299. + doepctl.d32 =
  88300. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  88301. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  88302. + if (doepctl.b.epena) {
  88303. + doepctl.b.epdis = 1;
  88304. + doepctl.b.snak = 1;
  88305. + }
  88306. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  88307. + doepctl.d32);
  88308. + return 1;
  88309. + } else
  88310. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  88311. + "Global OUT NAK Effective\n");
  88312. +
  88313. +out:
  88314. + /* Clear interrupt */
  88315. + gintsts.d32 = 0;
  88316. + gintsts.b.goutnakeff = 1;
  88317. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  88318. + gintsts.d32);
  88319. +
  88320. + return 1;
  88321. +}
  88322. +
  88323. +/**
  88324. + * PCD interrupt handler.
  88325. + *
  88326. + * The PCD handles the device interrupts. Many conditions can cause a
  88327. + * device interrupt. When an interrupt occurs, the device interrupt
  88328. + * service routine determines the cause of the interrupt and
  88329. + * dispatches handling to the appropriate function. These interrupt
  88330. + * handling functions are described below.
  88331. + *
  88332. + * All interrupt registers are processed from LSB to MSB.
  88333. + *
  88334. + */
  88335. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  88336. +{
  88337. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88338. +#ifdef VERBOSE
  88339. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  88340. +#endif
  88341. + gintsts_data_t gintr_status;
  88342. + int32_t retval = 0;
  88343. +
  88344. + /* Exit from ISR if core is hibernated */
  88345. + if (core_if->hibernation_suspend == 1) {
  88346. + return retval;
  88347. + }
  88348. +#ifdef VERBOSE
  88349. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  88350. + __func__,
  88351. + DWC_READ_REG32(&global_regs->gintsts),
  88352. + DWC_READ_REG32(&global_regs->gintmsk));
  88353. +#endif
  88354. +
  88355. + if (dwc_otg_is_device_mode(core_if)) {
  88356. + DWC_SPINLOCK(pcd->lock);
  88357. +#ifdef VERBOSE
  88358. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  88359. + __func__,
  88360. + DWC_READ_REG32(&global_regs->gintsts),
  88361. + DWC_READ_REG32(&global_regs->gintmsk));
  88362. +#endif
  88363. +
  88364. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  88365. +
  88366. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  88367. + __func__, gintr_status.d32);
  88368. +
  88369. + if (gintr_status.b.sofintr) {
  88370. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  88371. + }
  88372. + if (gintr_status.b.rxstsqlvl) {
  88373. + retval |=
  88374. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  88375. + }
  88376. + if (gintr_status.b.nptxfempty) {
  88377. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  88378. + }
  88379. + if (gintr_status.b.goutnakeff) {
  88380. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  88381. + }
  88382. + if (gintr_status.b.i2cintr) {
  88383. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  88384. + }
  88385. + if (gintr_status.b.erlysuspend) {
  88386. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  88387. + }
  88388. + if (gintr_status.b.usbreset) {
  88389. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  88390. + }
  88391. + if (gintr_status.b.enumdone) {
  88392. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  88393. + }
  88394. + if (gintr_status.b.isooutdrop) {
  88395. + retval |=
  88396. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  88397. + (pcd);
  88398. + }
  88399. + if (gintr_status.b.eopframe) {
  88400. + retval |=
  88401. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  88402. + }
  88403. + if (gintr_status.b.inepint) {
  88404. + if (!core_if->multiproc_int_enable) {
  88405. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  88406. + }
  88407. + }
  88408. + if (gintr_status.b.outepintr) {
  88409. + if (!core_if->multiproc_int_enable) {
  88410. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  88411. + }
  88412. + }
  88413. + if (gintr_status.b.epmismatch) {
  88414. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  88415. + }
  88416. + if (gintr_status.b.fetsusp) {
  88417. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  88418. + }
  88419. + if (gintr_status.b.ginnakeff) {
  88420. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  88421. + }
  88422. + if (gintr_status.b.incomplisoin) {
  88423. + retval |=
  88424. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  88425. + }
  88426. + if (gintr_status.b.incomplisoout) {
  88427. + retval |=
  88428. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  88429. + }
  88430. +
  88431. + /* In MPI mode Device Endpoints interrupts are asserted
  88432. + * without setting outepintr and inepint bits set, so these
  88433. + * Interrupt handlers are called without checking these bit-fields
  88434. + */
  88435. + if (core_if->multiproc_int_enable) {
  88436. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  88437. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  88438. + }
  88439. +#ifdef VERBOSE
  88440. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  88441. + DWC_READ_REG32(&global_regs->gintsts));
  88442. +#endif
  88443. + DWC_SPINUNLOCK(pcd->lock);
  88444. + }
  88445. + return retval;
  88446. +}
  88447. +
  88448. +#endif /* DWC_HOST_ONLY */
  88449. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  88450. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  88451. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-03-13 12:46:39.520097997 +0100
  88452. @@ -0,0 +1,1358 @@
  88453. + /* ==========================================================================
  88454. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  88455. + * $Revision: #21 $
  88456. + * $Date: 2012/08/10 $
  88457. + * $Change: 2047372 $
  88458. + *
  88459. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  88460. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  88461. + * otherwise expressly agreed to in writing between Synopsys and you.
  88462. + *
  88463. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  88464. + * any End User Software License Agreement or Agreement for Licensed Product
  88465. + * with Synopsys or any supplement thereto. You are permitted to use and
  88466. + * redistribute this Software in source and binary forms, with or without
  88467. + * modification, provided that redistributions of source code must retain this
  88468. + * notice. You may not view, use, disclose, copy or distribute this file or
  88469. + * any information contained herein except pursuant to this license grant from
  88470. + * Synopsys. If you do not agree with this notice, including the disclaimer
  88471. + * below, then you are not authorized to use the Software.
  88472. + *
  88473. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  88474. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  88475. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  88476. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  88477. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  88478. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  88479. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  88480. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  88481. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  88482. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  88483. + * DAMAGE.
  88484. + * ========================================================================== */
  88485. +#ifndef DWC_HOST_ONLY
  88486. +
  88487. +/** @file
  88488. + * This file implements the Peripheral Controller Driver.
  88489. + *
  88490. + * The Peripheral Controller Driver (PCD) is responsible for
  88491. + * translating requests from the Function Driver into the appropriate
  88492. + * actions on the DWC_otg controller. It isolates the Function Driver
  88493. + * from the specifics of the controller by providing an API to the
  88494. + * Function Driver.
  88495. + *
  88496. + * The Peripheral Controller Driver for Linux will implement the
  88497. + * Gadget API, so that the existing Gadget drivers can be used.
  88498. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  88499. + *
  88500. + * The Linux Gadget API is defined in the header file
  88501. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  88502. + * defined in the structure <code>usb_ep_ops</code> and the USB
  88503. + * Controller API is defined in the structure
  88504. + * <code>usb_gadget_ops</code>.
  88505. + *
  88506. + */
  88507. +
  88508. +#include "dwc_otg_os_dep.h"
  88509. +#include "dwc_otg_pcd_if.h"
  88510. +#include "dwc_otg_pcd.h"
  88511. +#include "dwc_otg_driver.h"
  88512. +#include "dwc_otg_dbg.h"
  88513. +
  88514. +static struct gadget_wrapper {
  88515. + dwc_otg_pcd_t *pcd;
  88516. +
  88517. + struct usb_gadget gadget;
  88518. + struct usb_gadget_driver *driver;
  88519. +
  88520. + struct usb_ep ep0;
  88521. + struct usb_ep in_ep[16];
  88522. + struct usb_ep out_ep[16];
  88523. +
  88524. +} *gadget_wrapper;
  88525. +
  88526. +/* Display the contents of the buffer */
  88527. +extern void dump_msg(const u8 * buf, unsigned int length);
  88528. +/**
  88529. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  88530. + * if the endpoint is not found
  88531. + */
  88532. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  88533. +{
  88534. + int i;
  88535. + if (pcd->ep0.priv == handle) {
  88536. + return &pcd->ep0;
  88537. + }
  88538. +
  88539. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  88540. + if (pcd->in_ep[i].priv == handle)
  88541. + return &pcd->in_ep[i];
  88542. + if (pcd->out_ep[i].priv == handle)
  88543. + return &pcd->out_ep[i];
  88544. + }
  88545. +
  88546. + return NULL;
  88547. +}
  88548. +
  88549. +/* USB Endpoint Operations */
  88550. +/*
  88551. + * The following sections briefly describe the behavior of the Gadget
  88552. + * API endpoint operations implemented in the DWC_otg driver
  88553. + * software. Detailed descriptions of the generic behavior of each of
  88554. + * these functions can be found in the Linux header file
  88555. + * include/linux/usb_gadget.h.
  88556. + *
  88557. + * The Gadget API provides wrapper functions for each of the function
  88558. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  88559. + * function, which then calls the underlying PCD function. The
  88560. + * following sections are named according to the wrapper
  88561. + * functions. Within each section, the corresponding DWC_otg PCD
  88562. + * function name is specified.
  88563. + *
  88564. + */
  88565. +
  88566. +/**
  88567. + * This function is called by the Gadget Driver for each EP to be
  88568. + * configured for the current configuration (SET_CONFIGURATION).
  88569. + *
  88570. + * This function initializes the dwc_otg_ep_t data structure, and then
  88571. + * calls dwc_otg_ep_activate.
  88572. + */
  88573. +static int ep_enable(struct usb_ep *usb_ep,
  88574. + const struct usb_endpoint_descriptor *ep_desc)
  88575. +{
  88576. + int retval;
  88577. +
  88578. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  88579. +
  88580. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  88581. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  88582. + return -EINVAL;
  88583. + }
  88584. + if (usb_ep == &gadget_wrapper->ep0) {
  88585. + DWC_WARN("%s, bad ep(0)\n", __func__);
  88586. + return -EINVAL;
  88587. + }
  88588. +
  88589. + /* Check FIFO size? */
  88590. + if (!ep_desc->wMaxPacketSize) {
  88591. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  88592. + return -ERANGE;
  88593. + }
  88594. +
  88595. + if (!gadget_wrapper->driver ||
  88596. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88597. + DWC_WARN("%s, bogus device state\n", __func__);
  88598. + return -ESHUTDOWN;
  88599. + }
  88600. +
  88601. + /* Delete after check - MAS */
  88602. +#if 0
  88603. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  88604. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  88605. + nat = (nat >> 11) & 0x03;
  88606. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  88607. +#endif
  88608. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  88609. + (const uint8_t *)ep_desc,
  88610. + (void *)usb_ep);
  88611. + if (retval) {
  88612. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  88613. + return -EINVAL;
  88614. + }
  88615. +
  88616. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  88617. +
  88618. + return 0;
  88619. +}
  88620. +
  88621. +/**
  88622. + * This function is called when an EP is disabled due to disconnect or
  88623. + * change in configuration. Any pending requests will terminate with a
  88624. + * status of -ESHUTDOWN.
  88625. + *
  88626. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  88627. + * and then calls dwc_otg_ep_deactivate.
  88628. + */
  88629. +static int ep_disable(struct usb_ep *usb_ep)
  88630. +{
  88631. + int retval;
  88632. +
  88633. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  88634. + if (!usb_ep) {
  88635. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  88636. + usb_ep ? usb_ep->name : NULL);
  88637. + return -EINVAL;
  88638. + }
  88639. +
  88640. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  88641. + if (retval) {
  88642. + retval = -EINVAL;
  88643. + }
  88644. +
  88645. + return retval;
  88646. +}
  88647. +
  88648. +/**
  88649. + * This function allocates a request object to use with the specified
  88650. + * endpoint.
  88651. + *
  88652. + * @param ep The endpoint to be used with with the request
  88653. + * @param gfp_flags the GFP_* flags to use.
  88654. + */
  88655. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  88656. + gfp_t gfp_flags)
  88657. +{
  88658. + struct usb_request *usb_req;
  88659. +
  88660. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  88661. + if (0 == ep) {
  88662. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  88663. + return 0;
  88664. + }
  88665. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  88666. + if (0 == usb_req) {
  88667. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  88668. + return 0;
  88669. + }
  88670. + memset(usb_req, 0, sizeof(*usb_req));
  88671. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  88672. +
  88673. + return usb_req;
  88674. +}
  88675. +
  88676. +/**
  88677. + * This function frees a request object.
  88678. + *
  88679. + * @param ep The endpoint associated with the request
  88680. + * @param req The request being freed
  88681. + */
  88682. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  88683. +{
  88684. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  88685. +
  88686. + if (0 == ep || 0 == req) {
  88687. + DWC_WARN("%s() %s\n", __func__,
  88688. + "Invalid ep or req argument!\n");
  88689. + return;
  88690. + }
  88691. +
  88692. + kfree(req);
  88693. +}
  88694. +
  88695. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88696. +/**
  88697. + * This function allocates an I/O buffer to be used for a transfer
  88698. + * to/from the specified endpoint.
  88699. + *
  88700. + * @param usb_ep The endpoint to be used with with the request
  88701. + * @param bytes The desired number of bytes for the buffer
  88702. + * @param dma Pointer to the buffer's DMA address; must be valid
  88703. + * @param gfp_flags the GFP_* flags to use.
  88704. + * @return address of a new buffer or null is buffer could not be allocated.
  88705. + */
  88706. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  88707. + dma_addr_t * dma, gfp_t gfp_flags)
  88708. +{
  88709. + void *buf;
  88710. + dwc_otg_pcd_t *pcd = 0;
  88711. +
  88712. + pcd = gadget_wrapper->pcd;
  88713. +
  88714. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  88715. + dma, gfp_flags);
  88716. +
  88717. + /* Check dword alignment */
  88718. + if ((bytes & 0x3UL) != 0) {
  88719. + DWC_WARN("%s() Buffer size is not a multiple of"
  88720. + "DWORD size (%d)", __func__, bytes);
  88721. + }
  88722. +
  88723. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  88724. +
  88725. + /* Check dword alignment */
  88726. + if (((int)buf & 0x3UL) != 0) {
  88727. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  88728. + __func__, buf);
  88729. + }
  88730. +
  88731. + return buf;
  88732. +}
  88733. +
  88734. +/**
  88735. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  88736. + *
  88737. + * @param usb_ep the endpoint associated with the buffer
  88738. + * @param buf address of the buffer
  88739. + * @param dma The buffer's DMA address
  88740. + * @param bytes The number of bytes of the buffer
  88741. + */
  88742. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  88743. + dma_addr_t dma, unsigned bytes)
  88744. +{
  88745. + dwc_otg_pcd_t *pcd = 0;
  88746. +
  88747. + pcd = gadget_wrapper->pcd;
  88748. +
  88749. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  88750. +
  88751. + dma_free_coherent(NULL, bytes, buf, dma);
  88752. +}
  88753. +#endif
  88754. +
  88755. +/**
  88756. + * This function is used to submit an I/O Request to an EP.
  88757. + *
  88758. + * - When the request completes the request's completion callback
  88759. + * is called to return the request to the driver.
  88760. + * - An EP, except control EPs, may have multiple requests
  88761. + * pending.
  88762. + * - Once submitted the request cannot be examined or modified.
  88763. + * - Each request is turned into one or more packets.
  88764. + * - A BULK EP can queue any amount of data; the transfer is
  88765. + * packetized.
  88766. + * - Zero length Packets are specified with the request 'zero'
  88767. + * flag.
  88768. + */
  88769. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  88770. + gfp_t gfp_flags)
  88771. +{
  88772. + dwc_otg_pcd_t *pcd;
  88773. + struct dwc_otg_pcd_ep *ep = NULL;
  88774. + int retval = 0, is_isoc_ep = 0;
  88775. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  88776. +
  88777. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  88778. + __func__, usb_ep, usb_req, gfp_flags);
  88779. +
  88780. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  88781. + DWC_WARN("bad params\n");
  88782. + return -EINVAL;
  88783. + }
  88784. +
  88785. + if (!usb_ep) {
  88786. + DWC_WARN("bad ep\n");
  88787. + return -EINVAL;
  88788. + }
  88789. +
  88790. + pcd = gadget_wrapper->pcd;
  88791. + if (!gadget_wrapper->driver ||
  88792. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88793. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  88794. + gadget_wrapper->gadget.speed);
  88795. + DWC_WARN("bogus device state\n");
  88796. + return -ESHUTDOWN;
  88797. + }
  88798. +
  88799. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  88800. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  88801. +
  88802. + usb_req->status = -EINPROGRESS;
  88803. + usb_req->actual = 0;
  88804. +
  88805. + ep = ep_from_handle(pcd, usb_ep);
  88806. + if (ep == NULL)
  88807. + is_isoc_ep = 0;
  88808. + else
  88809. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  88810. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88811. + dma_addr = usb_req->dma;
  88812. +#else
  88813. + if (GET_CORE_IF(pcd)->dma_enable) {
  88814. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  88815. + struct device *dev = NULL;
  88816. +
  88817. + if (otg_dev != NULL)
  88818. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  88819. +
  88820. + if (usb_req->length != 0 &&
  88821. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  88822. + dma_addr = dma_map_single(dev, usb_req->buf,
  88823. + usb_req->length,
  88824. + ep->dwc_ep.is_in ?
  88825. + DMA_TO_DEVICE:
  88826. + DMA_FROM_DEVICE);
  88827. + }
  88828. + }
  88829. +#endif
  88830. +
  88831. +#ifdef DWC_UTE_PER_IO
  88832. + if (is_isoc_ep == 1) {
  88833. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  88834. + usb_req->length, usb_req->zero, usb_req,
  88835. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  88836. + if (retval)
  88837. + return -EINVAL;
  88838. +
  88839. + return 0;
  88840. + }
  88841. +#endif
  88842. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  88843. + usb_req->length, usb_req->zero, usb_req,
  88844. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  88845. + if (retval) {
  88846. + return -EINVAL;
  88847. + }
  88848. +
  88849. + return 0;
  88850. +}
  88851. +
  88852. +/**
  88853. + * This function cancels an I/O request from an EP.
  88854. + */
  88855. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  88856. +{
  88857. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  88858. +
  88859. + if (!usb_ep || !usb_req) {
  88860. + DWC_WARN("bad argument\n");
  88861. + return -EINVAL;
  88862. + }
  88863. + if (!gadget_wrapper->driver ||
  88864. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88865. + DWC_WARN("bogus device state\n");
  88866. + return -ESHUTDOWN;
  88867. + }
  88868. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  88869. + return -EINVAL;
  88870. + }
  88871. +
  88872. + return 0;
  88873. +}
  88874. +
  88875. +/**
  88876. + * usb_ep_set_halt stalls an endpoint.
  88877. + *
  88878. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  88879. + * toggle.
  88880. + *
  88881. + * Both of these functions are implemented with the same underlying
  88882. + * function. The behavior depends on the value argument.
  88883. + *
  88884. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  88885. + * @param[in] value
  88886. + * - 0 means clear_halt.
  88887. + * - 1 means set_halt,
  88888. + * - 2 means clear stall lock flag.
  88889. + * - 3 means set stall lock flag.
  88890. + */
  88891. +static int ep_halt(struct usb_ep *usb_ep, int value)
  88892. +{
  88893. + int retval = 0;
  88894. +
  88895. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  88896. +
  88897. + if (!usb_ep) {
  88898. + DWC_WARN("bad ep\n");
  88899. + return -EINVAL;
  88900. + }
  88901. +
  88902. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  88903. + if (retval == -DWC_E_AGAIN) {
  88904. + return -EAGAIN;
  88905. + } else if (retval) {
  88906. + retval = -EINVAL;
  88907. + }
  88908. +
  88909. + return retval;
  88910. +}
  88911. +
  88912. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  88913. +#if 0
  88914. +/**
  88915. + * ep_wedge: sets the halt feature and ignores clear requests
  88916. + *
  88917. + * @usb_ep: the endpoint being wedged
  88918. + *
  88919. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  88920. + * requests. If the gadget driver clears the halt status, it will
  88921. + * automatically unwedge the endpoint.
  88922. + *
  88923. + * Returns zero on success, else negative errno. *
  88924. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  88925. + */
  88926. +static int ep_wedge(struct usb_ep *usb_ep)
  88927. +{
  88928. + int retval = 0;
  88929. +
  88930. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  88931. +
  88932. + if (!usb_ep) {
  88933. + DWC_WARN("bad ep\n");
  88934. + return -EINVAL;
  88935. + }
  88936. +
  88937. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  88938. + if (retval == -DWC_E_AGAIN) {
  88939. + retval = -EAGAIN;
  88940. + } else if (retval) {
  88941. + retval = -EINVAL;
  88942. + }
  88943. +
  88944. + return retval;
  88945. +}
  88946. +#endif
  88947. +
  88948. +#ifdef DWC_EN_ISOC
  88949. +/**
  88950. + * This function is used to submit an ISOC Transfer Request to an EP.
  88951. + *
  88952. + * - Every time a sync period completes the request's completion callback
  88953. + * is called to provide data to the gadget driver.
  88954. + * - Once submitted the request cannot be modified.
  88955. + * - Each request is turned into periodic data packets untill ISO
  88956. + * Transfer is stopped..
  88957. + */
  88958. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  88959. + gfp_t gfp_flags)
  88960. +{
  88961. + int retval = 0;
  88962. +
  88963. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  88964. + DWC_WARN("bad params\n");
  88965. + return -EINVAL;
  88966. + }
  88967. +
  88968. + if (!usb_ep) {
  88969. + DWC_PRINTF("bad params\n");
  88970. + return -EINVAL;
  88971. + }
  88972. +
  88973. + req->status = -EINPROGRESS;
  88974. +
  88975. + retval =
  88976. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  88977. + req->buf1, req->dma0, req->dma1,
  88978. + req->sync_frame, req->data_pattern_frame,
  88979. + req->data_per_frame,
  88980. + req->
  88981. + flags & USB_REQ_ISO_ASAP ? -1 :
  88982. + req->start_frame, req->buf_proc_intrvl,
  88983. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  88984. +
  88985. + if (retval) {
  88986. + return -EINVAL;
  88987. + }
  88988. +
  88989. + return retval;
  88990. +}
  88991. +
  88992. +/**
  88993. + * This function stops ISO EP Periodic Data Transfer.
  88994. + */
  88995. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  88996. +{
  88997. + int retval = 0;
  88998. + if (!usb_ep) {
  88999. + DWC_WARN("bad ep\n");
  89000. + }
  89001. +
  89002. + if (!gadget_wrapper->driver ||
  89003. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89004. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  89005. + gadget_wrapper->gadget.speed);
  89006. + DWC_WARN("bogus device state\n");
  89007. + }
  89008. +
  89009. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  89010. + if (retval) {
  89011. + retval = -EINVAL;
  89012. + }
  89013. +
  89014. + return retval;
  89015. +}
  89016. +
  89017. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  89018. + int packets, gfp_t gfp_flags)
  89019. +{
  89020. + struct usb_iso_request *pReq = NULL;
  89021. + uint32_t req_size;
  89022. +
  89023. + req_size = sizeof(struct usb_iso_request);
  89024. + req_size +=
  89025. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  89026. +
  89027. + pReq = kmalloc(req_size, gfp_flags);
  89028. + if (!pReq) {
  89029. + DWC_WARN("Can't allocate Iso Request\n");
  89030. + return 0;
  89031. + }
  89032. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  89033. +
  89034. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  89035. +
  89036. + return pReq;
  89037. +}
  89038. +
  89039. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  89040. +{
  89041. + kfree(req);
  89042. +}
  89043. +
  89044. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  89045. + .ep_ops = {
  89046. + .enable = ep_enable,
  89047. + .disable = ep_disable,
  89048. +
  89049. + .alloc_request = dwc_otg_pcd_alloc_request,
  89050. + .free_request = dwc_otg_pcd_free_request,
  89051. +
  89052. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  89053. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  89054. + .free_buffer = dwc_otg_pcd_free_buffer,
  89055. +#endif
  89056. +
  89057. + .queue = ep_queue,
  89058. + .dequeue = ep_dequeue,
  89059. +
  89060. + .set_halt = ep_halt,
  89061. + .fifo_status = 0,
  89062. + .fifo_flush = 0,
  89063. + },
  89064. + .iso_ep_start = iso_ep_start,
  89065. + .iso_ep_stop = iso_ep_stop,
  89066. + .alloc_iso_request = alloc_iso_request,
  89067. + .free_iso_request = free_iso_request,
  89068. +};
  89069. +
  89070. +#else
  89071. +
  89072. + int (*enable) (struct usb_ep *ep,
  89073. + const struct usb_endpoint_descriptor *desc);
  89074. + int (*disable) (struct usb_ep *ep);
  89075. +
  89076. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  89077. + gfp_t gfp_flags);
  89078. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  89079. +
  89080. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  89081. + gfp_t gfp_flags);
  89082. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  89083. +
  89084. + int (*set_halt) (struct usb_ep *ep, int value);
  89085. + int (*set_wedge) (struct usb_ep *ep);
  89086. +
  89087. + int (*fifo_status) (struct usb_ep *ep);
  89088. + void (*fifo_flush) (struct usb_ep *ep);
  89089. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  89090. + .enable = ep_enable,
  89091. + .disable = ep_disable,
  89092. +
  89093. + .alloc_request = dwc_otg_pcd_alloc_request,
  89094. + .free_request = dwc_otg_pcd_free_request,
  89095. +
  89096. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  89097. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  89098. + .free_buffer = dwc_otg_pcd_free_buffer,
  89099. +#else
  89100. + /* .set_wedge = ep_wedge, */
  89101. + .set_wedge = NULL, /* uses set_halt instead */
  89102. +#endif
  89103. +
  89104. + .queue = ep_queue,
  89105. + .dequeue = ep_dequeue,
  89106. +
  89107. + .set_halt = ep_halt,
  89108. + .fifo_status = 0,
  89109. + .fifo_flush = 0,
  89110. +
  89111. +};
  89112. +
  89113. +#endif /* _EN_ISOC_ */
  89114. +/* Gadget Operations */
  89115. +/**
  89116. + * The following gadget operations will be implemented in the DWC_otg
  89117. + * PCD. Functions in the API that are not described below are not
  89118. + * implemented.
  89119. + *
  89120. + * The Gadget API provides wrapper functions for each of the function
  89121. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  89122. + * wrapper function, which then calls the underlying PCD function. The
  89123. + * following sections are named according to the wrapper functions
  89124. + * (except for ioctl, which doesn't have a wrapper function). Within
  89125. + * each section, the corresponding DWC_otg PCD function name is
  89126. + * specified.
  89127. + *
  89128. + */
  89129. +
  89130. +/**
  89131. + *Gets the USB Frame number of the last SOF.
  89132. + */
  89133. +static int get_frame_number(struct usb_gadget *gadget)
  89134. +{
  89135. + struct gadget_wrapper *d;
  89136. +
  89137. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  89138. +
  89139. + if (gadget == 0) {
  89140. + return -ENODEV;
  89141. + }
  89142. +
  89143. + d = container_of(gadget, struct gadget_wrapper, gadget);
  89144. + return dwc_otg_pcd_get_frame_number(d->pcd);
  89145. +}
  89146. +
  89147. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89148. +static int test_lpm_enabled(struct usb_gadget *gadget)
  89149. +{
  89150. + struct gadget_wrapper *d;
  89151. +
  89152. + d = container_of(gadget, struct gadget_wrapper, gadget);
  89153. +
  89154. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  89155. +}
  89156. +#endif
  89157. +
  89158. +/**
  89159. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  89160. + * session is in progress. If a session is already in progress, but
  89161. + * the device is suspended, remote wakeup signaling is started.
  89162. + *
  89163. + */
  89164. +static int wakeup(struct usb_gadget *gadget)
  89165. +{
  89166. + struct gadget_wrapper *d;
  89167. +
  89168. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  89169. +
  89170. + if (gadget == 0) {
  89171. + return -ENODEV;
  89172. + } else {
  89173. + d = container_of(gadget, struct gadget_wrapper, gadget);
  89174. + }
  89175. + dwc_otg_pcd_wakeup(d->pcd);
  89176. + return 0;
  89177. +}
  89178. +
  89179. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  89180. + .get_frame = get_frame_number,
  89181. + .wakeup = wakeup,
  89182. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89183. + .lpm_support = test_lpm_enabled,
  89184. +#endif
  89185. + // current versions must always be self-powered
  89186. +};
  89187. +
  89188. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  89189. +{
  89190. + int retval = -DWC_E_NOT_SUPPORTED;
  89191. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  89192. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  89193. + (struct usb_ctrlrequest
  89194. + *)bytes);
  89195. + }
  89196. +
  89197. + if (retval == -ENOTSUPP) {
  89198. + retval = -DWC_E_NOT_SUPPORTED;
  89199. + } else if (retval < 0) {
  89200. + retval = -DWC_E_INVALID;
  89201. + }
  89202. +
  89203. + return retval;
  89204. +}
  89205. +
  89206. +#ifdef DWC_EN_ISOC
  89207. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  89208. + void *req_handle, int proc_buf_num)
  89209. +{
  89210. + int i, packet_count;
  89211. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  89212. + struct usb_iso_request *iso_req = req_handle;
  89213. +
  89214. + if (proc_buf_num) {
  89215. + iso_packet = iso_req->iso_packet_desc1;
  89216. + } else {
  89217. + iso_packet = iso_req->iso_packet_desc0;
  89218. + }
  89219. + packet_count =
  89220. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  89221. + for (i = 0; i < packet_count; ++i) {
  89222. + int status;
  89223. + int actual;
  89224. + int offset;
  89225. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  89226. + i, &status, &actual, &offset);
  89227. + switch (status) {
  89228. + case -DWC_E_NO_DATA:
  89229. + status = -ENODATA;
  89230. + break;
  89231. + default:
  89232. + if (status) {
  89233. + DWC_PRINTF("unknown status in isoc packet\n");
  89234. + }
  89235. +
  89236. + }
  89237. + iso_packet[i].status = status;
  89238. + iso_packet[i].offset = offset;
  89239. + iso_packet[i].actual_length = actual;
  89240. + }
  89241. +
  89242. + iso_req->status = 0;
  89243. + iso_req->process_buffer(ep_handle, iso_req);
  89244. +
  89245. + return 0;
  89246. +}
  89247. +#endif /* DWC_EN_ISOC */
  89248. +
  89249. +#ifdef DWC_UTE_PER_IO
  89250. +/**
  89251. + * Copy the contents of the extended request to the Linux usb_request's
  89252. + * extended part and call the gadget's completion.
  89253. + *
  89254. + * @param pcd Pointer to the pcd structure
  89255. + * @param ep_handle Void pointer to the usb_ep structure
  89256. + * @param req_handle Void pointer to the usb_request structure
  89257. + * @param status Request status returned from the portable logic
  89258. + * @param ereq_port Void pointer to the extended request structure
  89259. + * created in the the portable part that contains the
  89260. + * results of the processed iso packets.
  89261. + */
  89262. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  89263. + void *req_handle, int32_t status, void *ereq_port)
  89264. +{
  89265. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  89266. + struct dwc_iso_xreq_port *ereqport = NULL;
  89267. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  89268. + int i;
  89269. + struct usb_request *req;
  89270. + //struct dwc_ute_iso_packet_descriptor *
  89271. + //int status = 0;
  89272. +
  89273. + req = (struct usb_request *)req_handle;
  89274. + ereqorg = &req->ext_req;
  89275. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  89276. + desc_org = ereqorg->per_io_frame_descs;
  89277. +
  89278. + if (req && req->complete) {
  89279. + /* Copy the request data from the portable logic to our request */
  89280. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  89281. + desc_org[i].actual_length =
  89282. + ereqport->per_io_frame_descs[i].actual_length;
  89283. + desc_org[i].status =
  89284. + ereqport->per_io_frame_descs[i].status;
  89285. + }
  89286. +
  89287. + switch (status) {
  89288. + case -DWC_E_SHUTDOWN:
  89289. + req->status = -ESHUTDOWN;
  89290. + break;
  89291. + case -DWC_E_RESTART:
  89292. + req->status = -ECONNRESET;
  89293. + break;
  89294. + case -DWC_E_INVALID:
  89295. + req->status = -EINVAL;
  89296. + break;
  89297. + case -DWC_E_TIMEOUT:
  89298. + req->status = -ETIMEDOUT;
  89299. + break;
  89300. + default:
  89301. + req->status = status;
  89302. + }
  89303. +
  89304. + /* And call the gadget's completion */
  89305. + req->complete(ep_handle, req);
  89306. + }
  89307. +
  89308. + return 0;
  89309. +}
  89310. +#endif /* DWC_UTE_PER_IO */
  89311. +
  89312. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  89313. + void *req_handle, int32_t status, uint32_t actual)
  89314. +{
  89315. + struct usb_request *req = (struct usb_request *)req_handle;
  89316. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  89317. + struct dwc_otg_pcd_ep *ep = NULL;
  89318. +#endif
  89319. +
  89320. + if (req && req->complete) {
  89321. + switch (status) {
  89322. + case -DWC_E_SHUTDOWN:
  89323. + req->status = -ESHUTDOWN;
  89324. + break;
  89325. + case -DWC_E_RESTART:
  89326. + req->status = -ECONNRESET;
  89327. + break;
  89328. + case -DWC_E_INVALID:
  89329. + req->status = -EINVAL;
  89330. + break;
  89331. + case -DWC_E_TIMEOUT:
  89332. + req->status = -ETIMEDOUT;
  89333. + break;
  89334. + default:
  89335. + req->status = status;
  89336. +
  89337. + }
  89338. +
  89339. + req->actual = actual;
  89340. + DWC_SPINUNLOCK(pcd->lock);
  89341. + req->complete(ep_handle, req);
  89342. + DWC_SPINLOCK(pcd->lock);
  89343. + }
  89344. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  89345. + ep = ep_from_handle(pcd, ep_handle);
  89346. + if (GET_CORE_IF(pcd)->dma_enable) {
  89347. + if (req->length != 0) {
  89348. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  89349. + struct device *dev = NULL;
  89350. +
  89351. + if (otg_dev != NULL)
  89352. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  89353. +
  89354. + dma_unmap_single(dev, req->dma, req->length,
  89355. + ep->dwc_ep.is_in ?
  89356. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  89357. + }
  89358. + }
  89359. +#endif
  89360. +
  89361. + return 0;
  89362. +}
  89363. +
  89364. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  89365. +{
  89366. + gadget_wrapper->gadget.speed = speed;
  89367. + return 0;
  89368. +}
  89369. +
  89370. +static int _disconnect(dwc_otg_pcd_t * pcd)
  89371. +{
  89372. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  89373. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  89374. + }
  89375. + return 0;
  89376. +}
  89377. +
  89378. +static int _resume(dwc_otg_pcd_t * pcd)
  89379. +{
  89380. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  89381. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  89382. + }
  89383. +
  89384. + return 0;
  89385. +}
  89386. +
  89387. +static int _suspend(dwc_otg_pcd_t * pcd)
  89388. +{
  89389. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  89390. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  89391. + }
  89392. + return 0;
  89393. +}
  89394. +
  89395. +/**
  89396. + * This function updates the otg values in the gadget structure.
  89397. + */
  89398. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  89399. +{
  89400. +
  89401. + if (!gadget_wrapper->gadget.is_otg)
  89402. + return 0;
  89403. +
  89404. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  89405. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  89406. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  89407. + return 0;
  89408. +}
  89409. +
  89410. +static int _reset(dwc_otg_pcd_t * pcd)
  89411. +{
  89412. + return 0;
  89413. +}
  89414. +
  89415. +#ifdef DWC_UTE_CFI
  89416. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  89417. +{
  89418. + int retval = -DWC_E_INVALID;
  89419. + if (gadget_wrapper->driver->cfi_feature_setup) {
  89420. + retval =
  89421. + gadget_wrapper->driver->
  89422. + cfi_feature_setup(&gadget_wrapper->gadget,
  89423. + (struct cfi_usb_ctrlrequest *)cfi_req);
  89424. + }
  89425. +
  89426. + return retval;
  89427. +}
  89428. +#endif
  89429. +
  89430. +static const struct dwc_otg_pcd_function_ops fops = {
  89431. + .complete = _complete,
  89432. +#ifdef DWC_EN_ISOC
  89433. + .isoc_complete = _isoc_complete,
  89434. +#endif
  89435. + .setup = _setup,
  89436. + .disconnect = _disconnect,
  89437. + .connect = _connect,
  89438. + .resume = _resume,
  89439. + .suspend = _suspend,
  89440. + .hnp_changed = _hnp_changed,
  89441. + .reset = _reset,
  89442. +#ifdef DWC_UTE_CFI
  89443. + .cfi_setup = _cfi_setup,
  89444. +#endif
  89445. +#ifdef DWC_UTE_PER_IO
  89446. + .xisoc_complete = _xisoc_complete,
  89447. +#endif
  89448. +};
  89449. +
  89450. +/**
  89451. + * This function is the top level PCD interrupt handler.
  89452. + */
  89453. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  89454. +{
  89455. + dwc_otg_pcd_t *pcd = dev;
  89456. + int32_t retval = IRQ_NONE;
  89457. +
  89458. + retval = dwc_otg_pcd_handle_intr(pcd);
  89459. + if (retval != 0) {
  89460. + S3C2410X_CLEAR_EINTPEND();
  89461. + }
  89462. + return IRQ_RETVAL(retval);
  89463. +}
  89464. +
  89465. +/**
  89466. + * This function initialized the usb_ep structures to there default
  89467. + * state.
  89468. + *
  89469. + * @param d Pointer on gadget_wrapper.
  89470. + */
  89471. +void gadget_add_eps(struct gadget_wrapper *d)
  89472. +{
  89473. + static const char *names[] = {
  89474. +
  89475. + "ep0",
  89476. + "ep1in",
  89477. + "ep2in",
  89478. + "ep3in",
  89479. + "ep4in",
  89480. + "ep5in",
  89481. + "ep6in",
  89482. + "ep7in",
  89483. + "ep8in",
  89484. + "ep9in",
  89485. + "ep10in",
  89486. + "ep11in",
  89487. + "ep12in",
  89488. + "ep13in",
  89489. + "ep14in",
  89490. + "ep15in",
  89491. + "ep1out",
  89492. + "ep2out",
  89493. + "ep3out",
  89494. + "ep4out",
  89495. + "ep5out",
  89496. + "ep6out",
  89497. + "ep7out",
  89498. + "ep8out",
  89499. + "ep9out",
  89500. + "ep10out",
  89501. + "ep11out",
  89502. + "ep12out",
  89503. + "ep13out",
  89504. + "ep14out",
  89505. + "ep15out"
  89506. + };
  89507. +
  89508. + int i;
  89509. + struct usb_ep *ep;
  89510. + int8_t dev_endpoints;
  89511. +
  89512. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  89513. +
  89514. + INIT_LIST_HEAD(&d->gadget.ep_list);
  89515. + d->gadget.ep0 = &d->ep0;
  89516. + d->gadget.speed = USB_SPEED_UNKNOWN;
  89517. +
  89518. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  89519. +
  89520. + /**
  89521. + * Initialize the EP0 structure.
  89522. + */
  89523. + ep = &d->ep0;
  89524. +
  89525. + /* Init the usb_ep structure. */
  89526. + ep->name = names[0];
  89527. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  89528. +
  89529. + /**
  89530. + * @todo NGS: What should the max packet size be set to
  89531. + * here? Before EP type is set?
  89532. + */
  89533. + ep->maxpacket = MAX_PACKET_SIZE;
  89534. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  89535. +
  89536. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  89537. +
  89538. + /**
  89539. + * Initialize the EP structures.
  89540. + */
  89541. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  89542. +
  89543. + for (i = 0; i < dev_endpoints; i++) {
  89544. + ep = &d->in_ep[i];
  89545. +
  89546. + /* Init the usb_ep structure. */
  89547. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  89548. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  89549. +
  89550. + /**
  89551. + * @todo NGS: What should the max packet size be set to
  89552. + * here? Before EP type is set?
  89553. + */
  89554. + ep->maxpacket = MAX_PACKET_SIZE;
  89555. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  89556. + }
  89557. +
  89558. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  89559. +
  89560. + for (i = 0; i < dev_endpoints; i++) {
  89561. + ep = &d->out_ep[i];
  89562. +
  89563. + /* Init the usb_ep structure. */
  89564. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  89565. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  89566. +
  89567. + /**
  89568. + * @todo NGS: What should the max packet size be set to
  89569. + * here? Before EP type is set?
  89570. + */
  89571. + ep->maxpacket = MAX_PACKET_SIZE;
  89572. +
  89573. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  89574. + }
  89575. +
  89576. + /* remove ep0 from the list. There is a ep0 pointer. */
  89577. + list_del_init(&d->ep0.ep_list);
  89578. +
  89579. + d->ep0.maxpacket = MAX_EP0_SIZE;
  89580. +}
  89581. +
  89582. +/**
  89583. + * This function releases the Gadget device.
  89584. + * required by device_unregister().
  89585. + *
  89586. + * @todo Should this do something? Should it free the PCD?
  89587. + */
  89588. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  89589. +{
  89590. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  89591. +}
  89592. +
  89593. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  89594. +{
  89595. + static char pcd_name[] = "dwc_otg_pcd";
  89596. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  89597. + struct gadget_wrapper *d;
  89598. + int retval;
  89599. +
  89600. + d = DWC_ALLOC(sizeof(*d));
  89601. + if (d == NULL) {
  89602. + return NULL;
  89603. + }
  89604. +
  89605. + memset(d, 0, sizeof(*d));
  89606. +
  89607. + d->gadget.name = pcd_name;
  89608. + d->pcd = otg_dev->pcd;
  89609. +
  89610. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  89611. + strcpy(d->gadget.dev.bus_id, "gadget");
  89612. +#else
  89613. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  89614. +#endif
  89615. +
  89616. + d->gadget.dev.parent = &_dev->dev;
  89617. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  89618. + d->gadget.ops = &dwc_otg_pcd_ops;
  89619. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  89620. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  89621. +
  89622. + d->driver = 0;
  89623. + /* Register the gadget device */
  89624. + retval = device_register(&d->gadget.dev);
  89625. + if (retval != 0) {
  89626. + DWC_ERROR("device_register failed\n");
  89627. + DWC_FREE(d);
  89628. + return NULL;
  89629. + }
  89630. +
  89631. + return d;
  89632. +}
  89633. +
  89634. +static void free_wrapper(struct gadget_wrapper *d)
  89635. +{
  89636. + if (d->driver) {
  89637. + /* should have been done already by driver model core */
  89638. + DWC_WARN("driver '%s' is still registered\n",
  89639. + d->driver->driver.name);
  89640. + usb_gadget_unregister_driver(d->driver);
  89641. + }
  89642. +
  89643. + device_unregister(&d->gadget.dev);
  89644. + DWC_FREE(d);
  89645. +}
  89646. +
  89647. +/**
  89648. + * This function initialized the PCD portion of the driver.
  89649. + *
  89650. + */
  89651. +int pcd_init(dwc_bus_dev_t *_dev)
  89652. +{
  89653. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  89654. + int retval = 0;
  89655. +
  89656. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  89657. +
  89658. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  89659. +
  89660. + if (!otg_dev->pcd) {
  89661. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  89662. + return -ENOMEM;
  89663. + }
  89664. +
  89665. + otg_dev->pcd->otg_dev = otg_dev;
  89666. + gadget_wrapper = alloc_wrapper(_dev);
  89667. +
  89668. + /*
  89669. + * Initialize EP structures
  89670. + */
  89671. + gadget_add_eps(gadget_wrapper);
  89672. + /*
  89673. + * Setup interupt handler
  89674. + */
  89675. +#ifdef PLATFORM_INTERFACE
  89676. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  89677. + platform_get_irq(_dev, 0));
  89678. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  89679. + IRQF_SHARED, gadget_wrapper->gadget.name,
  89680. + otg_dev->pcd);
  89681. + if (retval != 0) {
  89682. + DWC_ERROR("request of irq%d failed\n",
  89683. + platform_get_irq(_dev, 0));
  89684. + free_wrapper(gadget_wrapper);
  89685. + return -EBUSY;
  89686. + }
  89687. +#else
  89688. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  89689. + _dev->irq);
  89690. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  89691. + IRQF_SHARED | IRQF_DISABLED,
  89692. + gadget_wrapper->gadget.name, otg_dev->pcd);
  89693. + if (retval != 0) {
  89694. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  89695. + free_wrapper(gadget_wrapper);
  89696. + return -EBUSY;
  89697. + }
  89698. +#endif
  89699. +
  89700. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  89701. +
  89702. + return retval;
  89703. +}
  89704. +
  89705. +/**
  89706. + * Cleanup the PCD.
  89707. + */
  89708. +void pcd_remove(dwc_bus_dev_t *_dev)
  89709. +{
  89710. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  89711. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  89712. +
  89713. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  89714. +
  89715. + /*
  89716. + * Free the IRQ
  89717. + */
  89718. +#ifdef PLATFORM_INTERFACE
  89719. + free_irq(platform_get_irq(_dev, 0), pcd);
  89720. +#else
  89721. + free_irq(_dev->irq, pcd);
  89722. +#endif
  89723. + dwc_otg_pcd_remove(otg_dev->pcd);
  89724. + free_wrapper(gadget_wrapper);
  89725. + otg_dev->pcd = 0;
  89726. +}
  89727. +
  89728. +/**
  89729. + * This function registers a gadget driver with the PCD.
  89730. + *
  89731. + * When a driver is successfully registered, it will receive control
  89732. + * requests including set_configuration(), which enables non-control
  89733. + * requests. then usb traffic follows until a disconnect is reported.
  89734. + * then a host may connect again, or the driver might get unbound.
  89735. + *
  89736. + * @param driver The driver being registered
  89737. + * @param bind The bind function of gadget driver
  89738. + */
  89739. +
  89740. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  89741. +{
  89742. + int retval;
  89743. +
  89744. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  89745. + driver->driver.name);
  89746. +
  89747. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  89748. + !driver->bind ||
  89749. + !driver->unbind || !driver->disconnect || !driver->setup) {
  89750. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  89751. + return -EINVAL;
  89752. + }
  89753. + if (gadget_wrapper == 0) {
  89754. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  89755. + return -ENODEV;
  89756. + }
  89757. + if (gadget_wrapper->driver != 0) {
  89758. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  89759. + return -EBUSY;
  89760. + }
  89761. +
  89762. + /* hook up the driver */
  89763. + gadget_wrapper->driver = driver;
  89764. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  89765. +
  89766. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  89767. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  89768. + if (retval) {
  89769. + DWC_ERROR("bind to driver %s --> error %d\n",
  89770. + driver->driver.name, retval);
  89771. + gadget_wrapper->driver = 0;
  89772. + gadget_wrapper->gadget.dev.driver = 0;
  89773. + return retval;
  89774. + }
  89775. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  89776. + driver->driver.name);
  89777. + return 0;
  89778. +}
  89779. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  89780. +
  89781. +/**
  89782. + * This function unregisters a gadget driver
  89783. + *
  89784. + * @param driver The driver being unregistered
  89785. + */
  89786. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  89787. +{
  89788. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  89789. +
  89790. + if (gadget_wrapper == 0) {
  89791. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  89792. + -ENODEV);
  89793. + return -ENODEV;
  89794. + }
  89795. + if (driver == 0 || driver != gadget_wrapper->driver) {
  89796. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  89797. + -EINVAL);
  89798. + return -EINVAL;
  89799. + }
  89800. +
  89801. + driver->unbind(&gadget_wrapper->gadget);
  89802. + gadget_wrapper->driver = 0;
  89803. +
  89804. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  89805. + return 0;
  89806. +}
  89807. +
  89808. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  89809. +
  89810. +#endif /* DWC_HOST_ONLY */
  89811. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  89812. --- linux-3.10.33/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  89813. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-03-13 12:46:39.524098005 +0100
  89814. @@ -0,0 +1,2550 @@
  89815. +/* ==========================================================================
  89816. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  89817. + * $Revision: #98 $
  89818. + * $Date: 2012/08/10 $
  89819. + * $Change: 2047372 $
  89820. + *
  89821. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  89822. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  89823. + * otherwise expressly agreed to in writing between Synopsys and you.
  89824. + *
  89825. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  89826. + * any End User Software License Agreement or Agreement for Licensed Product
  89827. + * with Synopsys or any supplement thereto. You are permitted to use and
  89828. + * redistribute this Software in source and binary forms, with or without
  89829. + * modification, provided that redistributions of source code must retain this
  89830. + * notice. You may not view, use, disclose, copy or distribute this file or
  89831. + * any information contained herein except pursuant to this license grant from
  89832. + * Synopsys. If you do not agree with this notice, including the disclaimer
  89833. + * below, then you are not authorized to use the Software.
  89834. + *
  89835. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  89836. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  89837. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  89838. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  89839. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89840. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  89841. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  89842. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  89843. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  89844. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  89845. + * DAMAGE.
  89846. + * ========================================================================== */
  89847. +
  89848. +#ifndef __DWC_OTG_REGS_H__
  89849. +#define __DWC_OTG_REGS_H__
  89850. +
  89851. +#include "dwc_otg_core_if.h"
  89852. +
  89853. +/**
  89854. + * @file
  89855. + *
  89856. + * This file contains the data structures for accessing the DWC_otg core registers.
  89857. + *
  89858. + * The application interfaces with the HS OTG core by reading from and
  89859. + * writing to the Control and Status Register (CSR) space through the
  89860. + * AHB Slave interface. These registers are 32 bits wide, and the
  89861. + * addresses are 32-bit-block aligned.
  89862. + * CSRs are classified as follows:
  89863. + * - Core Global Registers
  89864. + * - Device Mode Registers
  89865. + * - Device Global Registers
  89866. + * - Device Endpoint Specific Registers
  89867. + * - Host Mode Registers
  89868. + * - Host Global Registers
  89869. + * - Host Port CSRs
  89870. + * - Host Channel Specific Registers
  89871. + *
  89872. + * Only the Core Global registers can be accessed in both Device and
  89873. + * Host modes. When the HS OTG core is operating in one mode, either
  89874. + * Device or Host, the application must not access registers from the
  89875. + * other mode. When the core switches from one mode to another, the
  89876. + * registers in the new mode of operation must be reprogrammed as they
  89877. + * would be after a power-on reset.
  89878. + */
  89879. +
  89880. +/****************************************************************************/
  89881. +/** DWC_otg Core registers .
  89882. + * The dwc_otg_core_global_regs structure defines the size
  89883. + * and relative field offsets for the Core Global registers.
  89884. + */
  89885. +typedef struct dwc_otg_core_global_regs {
  89886. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  89887. + volatile uint32_t gotgctl;
  89888. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  89889. + volatile uint32_t gotgint;
  89890. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  89891. + volatile uint32_t gahbcfg;
  89892. +
  89893. +#define DWC_GLBINTRMASK 0x0001
  89894. +#define DWC_DMAENABLE 0x0020
  89895. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  89896. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  89897. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  89898. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  89899. +
  89900. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  89901. + volatile uint32_t gusbcfg;
  89902. + /**Core Reset Register. <i>Offset: 010h</i> */
  89903. + volatile uint32_t grstctl;
  89904. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  89905. + volatile uint32_t gintsts;
  89906. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  89907. + volatile uint32_t gintmsk;
  89908. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  89909. + volatile uint32_t grxstsr;
  89910. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  89911. + volatile uint32_t grxstsp;
  89912. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  89913. + volatile uint32_t grxfsiz;
  89914. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  89915. + volatile uint32_t gnptxfsiz;
  89916. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  89917. + * Only). <i>Offset: 02Ch</i> */
  89918. + volatile uint32_t gnptxsts;
  89919. + /**I2C Access Register. <i>Offset: 030h</i> */
  89920. + volatile uint32_t gi2cctl;
  89921. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  89922. + volatile uint32_t gpvndctl;
  89923. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  89924. + volatile uint32_t ggpio;
  89925. + /**User ID Register. <i>Offset: 03Ch</i> */
  89926. + volatile uint32_t guid;
  89927. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  89928. + volatile uint32_t gsnpsid;
  89929. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  89930. + volatile uint32_t ghwcfg1;
  89931. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  89932. + volatile uint32_t ghwcfg2;
  89933. +#define DWC_SLAVE_ONLY_ARCH 0
  89934. +#define DWC_EXT_DMA_ARCH 1
  89935. +#define DWC_INT_DMA_ARCH 2
  89936. +
  89937. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  89938. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  89939. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  89940. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  89941. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  89942. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  89943. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  89944. +
  89945. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  89946. + volatile uint32_t ghwcfg3;
  89947. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  89948. + volatile uint32_t ghwcfg4;
  89949. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  89950. + volatile uint32_t glpmcfg;
  89951. + /** Global PowerDn Register <i>Offset: 058h</i> */
  89952. + volatile uint32_t gpwrdn;
  89953. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  89954. + volatile uint32_t gdfifocfg;
  89955. + /** ADP Control Register <i>Offset: 060h</i> */
  89956. + volatile uint32_t adpctl;
  89957. + /** Reserved <i>Offset: 064h-0FFh</i> */
  89958. + volatile uint32_t reserved39[39];
  89959. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  89960. + volatile uint32_t hptxfsiz;
  89961. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  89962. + otherwise Device Transmit FIFO#n Register.
  89963. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  89964. + volatile uint32_t dtxfsiz[15];
  89965. +} dwc_otg_core_global_regs_t;
  89966. +
  89967. +/**
  89968. + * This union represents the bit fields of the Core OTG Control
  89969. + * and Status Register (GOTGCTL). Set the bits using the bit
  89970. + * fields then write the <i>d32</i> value to the register.
  89971. + */
  89972. +typedef union gotgctl_data {
  89973. + /** raw register data */
  89974. + uint32_t d32;
  89975. + /** register bits */
  89976. + struct {
  89977. + unsigned sesreqscs:1;
  89978. + unsigned sesreq:1;
  89979. + unsigned vbvalidoven:1;
  89980. + unsigned vbvalidovval:1;
  89981. + unsigned avalidoven:1;
  89982. + unsigned avalidovval:1;
  89983. + unsigned bvalidoven:1;
  89984. + unsigned bvalidovval:1;
  89985. + unsigned hstnegscs:1;
  89986. + unsigned hnpreq:1;
  89987. + unsigned hstsethnpen:1;
  89988. + unsigned devhnpen:1;
  89989. + unsigned reserved12_15:4;
  89990. + unsigned conidsts:1;
  89991. + unsigned dbnctime:1;
  89992. + unsigned asesvld:1;
  89993. + unsigned bsesvld:1;
  89994. + unsigned otgver:1;
  89995. + unsigned reserved1:1;
  89996. + unsigned multvalidbc:5;
  89997. + unsigned chirpen:1;
  89998. + unsigned reserved28_31:4;
  89999. + } b;
  90000. +} gotgctl_data_t;
  90001. +
  90002. +/**
  90003. + * This union represents the bit fields of the Core OTG Interrupt Register
  90004. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  90005. + * value to the register.
  90006. + */
  90007. +typedef union gotgint_data {
  90008. + /** raw register data */
  90009. + uint32_t d32;
  90010. + /** register bits */
  90011. + struct {
  90012. + /** Current Mode */
  90013. + unsigned reserved0_1:2;
  90014. +
  90015. + /** Session End Detected */
  90016. + unsigned sesenddet:1;
  90017. +
  90018. + unsigned reserved3_7:5;
  90019. +
  90020. + /** Session Request Success Status Change */
  90021. + unsigned sesreqsucstschng:1;
  90022. + /** Host Negotiation Success Status Change */
  90023. + unsigned hstnegsucstschng:1;
  90024. +
  90025. + unsigned reserved10_16:7;
  90026. +
  90027. + /** Host Negotiation Detected */
  90028. + unsigned hstnegdet:1;
  90029. + /** A-Device Timeout Change */
  90030. + unsigned adevtoutchng:1;
  90031. + /** Debounce Done */
  90032. + unsigned debdone:1;
  90033. + /** Multi-Valued input changed */
  90034. + unsigned mvic:1;
  90035. +
  90036. + unsigned reserved31_21:11;
  90037. +
  90038. + } b;
  90039. +} gotgint_data_t;
  90040. +
  90041. +/**
  90042. + * This union represents the bit fields of the Core AHB Configuration
  90043. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  90044. + * write the <i>d32</i> value to the register.
  90045. + */
  90046. +typedef union gahbcfg_data {
  90047. + /** raw register data */
  90048. + uint32_t d32;
  90049. + /** register bits */
  90050. + struct {
  90051. + unsigned glblintrmsk:1;
  90052. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  90053. +
  90054. + unsigned hburstlen:4;
  90055. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  90056. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  90057. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  90058. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  90059. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  90060. +
  90061. + unsigned dmaenable:1;
  90062. +#define DWC_GAHBCFG_DMAENABLE 1
  90063. + unsigned reserved:1;
  90064. + unsigned nptxfemplvl_txfemplvl:1;
  90065. + unsigned ptxfemplvl:1;
  90066. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  90067. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  90068. + unsigned reserved9_20:12;
  90069. + unsigned remmemsupp:1;
  90070. + unsigned notialldmawrit:1;
  90071. + unsigned ahbsingle:1;
  90072. + unsigned reserved24_31:8;
  90073. + } b;
  90074. +} gahbcfg_data_t;
  90075. +
  90076. +/**
  90077. + * This union represents the bit fields of the Core USB Configuration
  90078. + * Register (GUSBCFG). Set the bits using the bit fields then write
  90079. + * the <i>d32</i> value to the register.
  90080. + */
  90081. +typedef union gusbcfg_data {
  90082. + /** raw register data */
  90083. + uint32_t d32;
  90084. + /** register bits */
  90085. + struct {
  90086. + unsigned toutcal:3;
  90087. + unsigned phyif:1;
  90088. + unsigned ulpi_utmi_sel:1;
  90089. + unsigned fsintf:1;
  90090. + unsigned physel:1;
  90091. + unsigned ddrsel:1;
  90092. + unsigned srpcap:1;
  90093. + unsigned hnpcap:1;
  90094. + unsigned usbtrdtim:4;
  90095. + unsigned reserved1:1;
  90096. + unsigned phylpwrclksel:1;
  90097. + unsigned otgutmifssel:1;
  90098. + unsigned ulpi_fsls:1;
  90099. + unsigned ulpi_auto_res:1;
  90100. + unsigned ulpi_clk_sus_m:1;
  90101. + unsigned ulpi_ext_vbus_drv:1;
  90102. + unsigned ulpi_int_vbus_indicator:1;
  90103. + unsigned term_sel_dl_pulse:1;
  90104. + unsigned indicator_complement:1;
  90105. + unsigned indicator_pass_through:1;
  90106. + unsigned ulpi_int_prot_dis:1;
  90107. + unsigned ic_usb_cap:1;
  90108. + unsigned ic_traffic_pull_remove:1;
  90109. + unsigned tx_end_delay:1;
  90110. + unsigned force_host_mode:1;
  90111. + unsigned force_dev_mode:1;
  90112. + unsigned reserved31:1;
  90113. + } b;
  90114. +} gusbcfg_data_t;
  90115. +
  90116. +/**
  90117. + * This union represents the bit fields of the Core Reset Register
  90118. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  90119. + * <i>d32</i> value to the register.
  90120. + */
  90121. +typedef union grstctl_data {
  90122. + /** raw register data */
  90123. + uint32_t d32;
  90124. + /** register bits */
  90125. + struct {
  90126. + /** Core Soft Reset (CSftRst) (Device and Host)
  90127. + *
  90128. + * The application can flush the control logic in the
  90129. + * entire core using this bit. This bit resets the
  90130. + * pipelines in the AHB Clock domain as well as the
  90131. + * PHY Clock domain.
  90132. + *
  90133. + * The state machines are reset to an IDLE state, the
  90134. + * control bits in the CSRs are cleared, all the
  90135. + * transmit FIFOs and the receive FIFO are flushed.
  90136. + *
  90137. + * The status mask bits that control the generation of
  90138. + * the interrupt, are cleared, to clear the
  90139. + * interrupt. The interrupt status bits are not
  90140. + * cleared, so the application can get the status of
  90141. + * any events that occurred in the core after it has
  90142. + * set this bit.
  90143. + *
  90144. + * Any transactions on the AHB are terminated as soon
  90145. + * as possible following the protocol. Any
  90146. + * transactions on the USB are terminated immediately.
  90147. + *
  90148. + * The configuration settings in the CSRs are
  90149. + * unchanged, so the software doesn't have to
  90150. + * reprogram these registers (Device
  90151. + * Configuration/Host Configuration/Core System
  90152. + * Configuration/Core PHY Configuration).
  90153. + *
  90154. + * The application can write to this bit, any time it
  90155. + * wants to reset the core. This is a self clearing
  90156. + * bit and the core clears this bit after all the
  90157. + * necessary logic is reset in the core, which may
  90158. + * take several clocks, depending on the current state
  90159. + * of the core.
  90160. + */
  90161. + unsigned csftrst:1;
  90162. + /** Hclk Soft Reset
  90163. + *
  90164. + * The application uses this bit to reset the control logic in
  90165. + * the AHB clock domain. Only AHB clock domain pipelines are
  90166. + * reset.
  90167. + */
  90168. + unsigned hsftrst:1;
  90169. + /** Host Frame Counter Reset (Host Only)<br>
  90170. + *
  90171. + * The application can reset the (micro)frame number
  90172. + * counter inside the core, using this bit. When the
  90173. + * (micro)frame counter is reset, the subsequent SOF
  90174. + * sent out by the core, will have a (micro)frame
  90175. + * number of 0.
  90176. + */
  90177. + unsigned hstfrm:1;
  90178. + /** In Token Sequence Learning Queue Flush
  90179. + * (INTknQFlsh) (Device Only)
  90180. + */
  90181. + unsigned intknqflsh:1;
  90182. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  90183. + *
  90184. + * The application can flush the entire Receive FIFO
  90185. + * using this bit. The application must first
  90186. + * ensure that the core is not in the middle of a
  90187. + * transaction. The application should write into
  90188. + * this bit, only after making sure that neither the
  90189. + * DMA engine is reading from the RxFIFO nor the MAC
  90190. + * is writing the data in to the FIFO. The
  90191. + * application should wait until the bit is cleared
  90192. + * before performing any other operations. This bit
  90193. + * will takes 8 clocks (slowest of PHY or AHB clock)
  90194. + * to clear.
  90195. + */
  90196. + unsigned rxfflsh:1;
  90197. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  90198. + *
  90199. + * This bit is used to selectively flush a single or
  90200. + * all transmit FIFOs. The application must first
  90201. + * ensure that the core is not in the middle of a
  90202. + * transaction. The application should write into
  90203. + * this bit, only after making sure that neither the
  90204. + * DMA engine is writing into the TxFIFO nor the MAC
  90205. + * is reading the data out of the FIFO. The
  90206. + * application should wait until the core clears this
  90207. + * bit, before performing any operations. This bit
  90208. + * will takes 8 clocks (slowest of PHY or AHB clock)
  90209. + * to clear.
  90210. + */
  90211. + unsigned txfflsh:1;
  90212. +
  90213. + /** TxFIFO Number (TxFNum) (Device and Host).
  90214. + *
  90215. + * This is the FIFO number which needs to be flushed,
  90216. + * using the TxFIFO Flush bit. This field should not
  90217. + * be changed until the TxFIFO Flush bit is cleared by
  90218. + * the core.
  90219. + * - 0x0 : Non Periodic TxFIFO Flush
  90220. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  90221. + * or Periodic TxFIFO in host mode
  90222. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  90223. + * - ...
  90224. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  90225. + * - 0x10: Flush all the Transmit NonPeriodic and
  90226. + * Transmit Periodic FIFOs in the core
  90227. + */
  90228. + unsigned txfnum:5;
  90229. + /** Reserved */
  90230. + unsigned reserved11_29:19;
  90231. + /** DMA Request Signal. Indicated DMA request is in
  90232. + * probress. Used for debug purpose. */
  90233. + unsigned dmareq:1;
  90234. + /** AHB Master Idle. Indicates the AHB Master State
  90235. + * Machine is in IDLE condition. */
  90236. + unsigned ahbidle:1;
  90237. + } b;
  90238. +} grstctl_t;
  90239. +
  90240. +/**
  90241. + * This union represents the bit fields of the Core Interrupt Mask
  90242. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  90243. + * write the <i>d32</i> value to the register.
  90244. + */
  90245. +typedef union gintmsk_data {
  90246. + /** raw register data */
  90247. + uint32_t d32;
  90248. + /** register bits */
  90249. + struct {
  90250. + unsigned reserved0:1;
  90251. + unsigned modemismatch:1;
  90252. + unsigned otgintr:1;
  90253. + unsigned sofintr:1;
  90254. + unsigned rxstsqlvl:1;
  90255. + unsigned nptxfempty:1;
  90256. + unsigned ginnakeff:1;
  90257. + unsigned goutnakeff:1;
  90258. + unsigned ulpickint:1;
  90259. + unsigned i2cintr:1;
  90260. + unsigned erlysuspend:1;
  90261. + unsigned usbsuspend:1;
  90262. + unsigned usbreset:1;
  90263. + unsigned enumdone:1;
  90264. + unsigned isooutdrop:1;
  90265. + unsigned eopframe:1;
  90266. + unsigned restoredone:1;
  90267. + unsigned epmismatch:1;
  90268. + unsigned inepintr:1;
  90269. + unsigned outepintr:1;
  90270. + unsigned incomplisoin:1;
  90271. + unsigned incomplisoout:1;
  90272. + unsigned fetsusp:1;
  90273. + unsigned resetdet:1;
  90274. + unsigned portintr:1;
  90275. + unsigned hcintr:1;
  90276. + unsigned ptxfempty:1;
  90277. + unsigned lpmtranrcvd:1;
  90278. + unsigned conidstschng:1;
  90279. + unsigned disconnect:1;
  90280. + unsigned sessreqintr:1;
  90281. + unsigned wkupintr:1;
  90282. + } b;
  90283. +} gintmsk_data_t;
  90284. +/**
  90285. + * This union represents the bit fields of the Core Interrupt Register
  90286. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  90287. + * <i>d32</i> value to the register.
  90288. + */
  90289. +typedef union gintsts_data {
  90290. + /** raw register data */
  90291. + uint32_t d32;
  90292. +#define DWC_SOF_INTR_MASK 0x0008
  90293. + /** register bits */
  90294. + struct {
  90295. +#define DWC_HOST_MODE 1
  90296. + unsigned curmode:1;
  90297. + unsigned modemismatch:1;
  90298. + unsigned otgintr:1;
  90299. + unsigned sofintr:1;
  90300. + unsigned rxstsqlvl:1;
  90301. + unsigned nptxfempty:1;
  90302. + unsigned ginnakeff:1;
  90303. + unsigned goutnakeff:1;
  90304. + unsigned ulpickint:1;
  90305. + unsigned i2cintr:1;
  90306. + unsigned erlysuspend:1;
  90307. + unsigned usbsuspend:1;
  90308. + unsigned usbreset:1;
  90309. + unsigned enumdone:1;
  90310. + unsigned isooutdrop:1;
  90311. + unsigned eopframe:1;
  90312. + unsigned restoredone:1;
  90313. + unsigned epmismatch:1;
  90314. + unsigned inepint:1;
  90315. + unsigned outepintr:1;
  90316. + unsigned incomplisoin:1;
  90317. + unsigned incomplisoout:1;
  90318. + unsigned fetsusp:1;
  90319. + unsigned resetdet:1;
  90320. + unsigned portintr:1;
  90321. + unsigned hcintr:1;
  90322. + unsigned ptxfempty:1;
  90323. + unsigned lpmtranrcvd:1;
  90324. + unsigned conidstschng:1;
  90325. + unsigned disconnect:1;
  90326. + unsigned sessreqintr:1;
  90327. + unsigned wkupintr:1;
  90328. + } b;
  90329. +} gintsts_data_t;
  90330. +
  90331. +/**
  90332. + * This union represents the bit fields in the Device Receive Status Read and
  90333. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  90334. + * element then read out the bits using the <i>b</i>it elements.
  90335. + */
  90336. +typedef union device_grxsts_data {
  90337. + /** raw register data */
  90338. + uint32_t d32;
  90339. + /** register bits */
  90340. + struct {
  90341. + unsigned epnum:4;
  90342. + unsigned bcnt:11;
  90343. + unsigned dpid:2;
  90344. +
  90345. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  90346. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  90347. +
  90348. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  90349. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  90350. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  90351. + unsigned pktsts:4;
  90352. + unsigned fn:4;
  90353. + unsigned reserved25_31:7;
  90354. + } b;
  90355. +} device_grxsts_data_t;
  90356. +
  90357. +/**
  90358. + * This union represents the bit fields in the Host Receive Status Read and
  90359. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  90360. + * element then read out the bits using the <i>b</i>it elements.
  90361. + */
  90362. +typedef union host_grxsts_data {
  90363. + /** raw register data */
  90364. + uint32_t d32;
  90365. + /** register bits */
  90366. + struct {
  90367. + unsigned chnum:4;
  90368. + unsigned bcnt:11;
  90369. + unsigned dpid:2;
  90370. +
  90371. + unsigned pktsts:4;
  90372. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  90373. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  90374. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  90375. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  90376. +
  90377. + unsigned reserved21_31:11;
  90378. + } b;
  90379. +} host_grxsts_data_t;
  90380. +
  90381. +/**
  90382. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  90383. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  90384. + * then read out the bits using the <i>b</i>it elements.
  90385. + */
  90386. +typedef union fifosize_data {
  90387. + /** raw register data */
  90388. + uint32_t d32;
  90389. + /** register bits */
  90390. + struct {
  90391. + unsigned startaddr:16;
  90392. + unsigned depth:16;
  90393. + } b;
  90394. +} fifosize_data_t;
  90395. +
  90396. +/**
  90397. + * This union represents the bit fields in the Non-Periodic Transmit
  90398. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  90399. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  90400. + * elements.
  90401. + */
  90402. +typedef union gnptxsts_data {
  90403. + /** raw register data */
  90404. + uint32_t d32;
  90405. + /** register bits */
  90406. + struct {
  90407. + unsigned nptxfspcavail:16;
  90408. + unsigned nptxqspcavail:8;
  90409. + /** Top of the Non-Periodic Transmit Request Queue
  90410. + * - bit 24 - Terminate (Last entry for the selected
  90411. + * channel/EP)
  90412. + * - bits 26:25 - Token Type
  90413. + * - 2'b00 - IN/OUT
  90414. + * - 2'b01 - Zero Length OUT
  90415. + * - 2'b10 - PING/Complete Split
  90416. + * - 2'b11 - Channel Halt
  90417. + * - bits 30:27 - Channel/EP Number
  90418. + */
  90419. + unsigned nptxqtop_terminate:1;
  90420. + unsigned nptxqtop_token:2;
  90421. + unsigned nptxqtop_chnep:4;
  90422. + unsigned reserved:1;
  90423. + } b;
  90424. +} gnptxsts_data_t;
  90425. +
  90426. +/**
  90427. + * This union represents the bit fields in the Transmit
  90428. + * FIFO Status Register (DTXFSTS). Read the register into the
  90429. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  90430. + * elements.
  90431. + */
  90432. +typedef union dtxfsts_data {
  90433. + /** raw register data */
  90434. + uint32_t d32;
  90435. + /** register bits */
  90436. + struct {
  90437. + unsigned txfspcavail:16;
  90438. + unsigned reserved:16;
  90439. + } b;
  90440. +} dtxfsts_data_t;
  90441. +
  90442. +/**
  90443. + * This union represents the bit fields in the I2C Control Register
  90444. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  90445. + * bits using the <i>b</i>it elements.
  90446. + */
  90447. +typedef union gi2cctl_data {
  90448. + /** raw register data */
  90449. + uint32_t d32;
  90450. + /** register bits */
  90451. + struct {
  90452. + unsigned rwdata:8;
  90453. + unsigned regaddr:8;
  90454. + unsigned addr:7;
  90455. + unsigned i2cen:1;
  90456. + unsigned ack:1;
  90457. + unsigned i2csuspctl:1;
  90458. + unsigned i2cdevaddr:2;
  90459. + unsigned i2cdatse0:1;
  90460. + unsigned reserved:1;
  90461. + unsigned rw:1;
  90462. + unsigned bsydne:1;
  90463. + } b;
  90464. +} gi2cctl_data_t;
  90465. +
  90466. +/**
  90467. + * This union represents the bit fields in the PHY Vendor Control Register
  90468. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  90469. + * bits using the <i>b</i>it elements.
  90470. + */
  90471. +typedef union gpvndctl_data {
  90472. + /** raw register data */
  90473. + uint32_t d32;
  90474. + /** register bits */
  90475. + struct {
  90476. + unsigned regdata:8;
  90477. + unsigned vctrl:8;
  90478. + unsigned regaddr16_21:6;
  90479. + unsigned regwr:1;
  90480. + unsigned reserved23_24:2;
  90481. + unsigned newregreq:1;
  90482. + unsigned vstsbsy:1;
  90483. + unsigned vstsdone:1;
  90484. + unsigned reserved28_30:3;
  90485. + unsigned disulpidrvr:1;
  90486. + } b;
  90487. +} gpvndctl_data_t;
  90488. +
  90489. +/**
  90490. + * This union represents the bit fields in the General Purpose
  90491. + * Input/Output Register (GGPIO).
  90492. + * Read the register into the <i>d32</i> element then read out the
  90493. + * bits using the <i>b</i>it elements.
  90494. + */
  90495. +typedef union ggpio_data {
  90496. + /** raw register data */
  90497. + uint32_t d32;
  90498. + /** register bits */
  90499. + struct {
  90500. + unsigned gpi:16;
  90501. + unsigned gpo:16;
  90502. + } b;
  90503. +} ggpio_data_t;
  90504. +
  90505. +/**
  90506. + * This union represents the bit fields in the User ID Register
  90507. + * (GUID). Read the register into the <i>d32</i> element then read out the
  90508. + * bits using the <i>b</i>it elements.
  90509. + */
  90510. +typedef union guid_data {
  90511. + /** raw register data */
  90512. + uint32_t d32;
  90513. + /** register bits */
  90514. + struct {
  90515. + unsigned rwdata:32;
  90516. + } b;
  90517. +} guid_data_t;
  90518. +
  90519. +/**
  90520. + * This union represents the bit fields in the Synopsys ID Register
  90521. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  90522. + * bits using the <i>b</i>it elements.
  90523. + */
  90524. +typedef union gsnpsid_data {
  90525. + /** raw register data */
  90526. + uint32_t d32;
  90527. + /** register bits */
  90528. + struct {
  90529. + unsigned rwdata:32;
  90530. + } b;
  90531. +} gsnpsid_data_t;
  90532. +
  90533. +/**
  90534. + * This union represents the bit fields in the User HW Config1
  90535. + * Register. Read the register into the <i>d32</i> element then read
  90536. + * out the bits using the <i>b</i>it elements.
  90537. + */
  90538. +typedef union hwcfg1_data {
  90539. + /** raw register data */
  90540. + uint32_t d32;
  90541. + /** register bits */
  90542. + struct {
  90543. + unsigned ep_dir0:2;
  90544. + unsigned ep_dir1:2;
  90545. + unsigned ep_dir2:2;
  90546. + unsigned ep_dir3:2;
  90547. + unsigned ep_dir4:2;
  90548. + unsigned ep_dir5:2;
  90549. + unsigned ep_dir6:2;
  90550. + unsigned ep_dir7:2;
  90551. + unsigned ep_dir8:2;
  90552. + unsigned ep_dir9:2;
  90553. + unsigned ep_dir10:2;
  90554. + unsigned ep_dir11:2;
  90555. + unsigned ep_dir12:2;
  90556. + unsigned ep_dir13:2;
  90557. + unsigned ep_dir14:2;
  90558. + unsigned ep_dir15:2;
  90559. + } b;
  90560. +} hwcfg1_data_t;
  90561. +
  90562. +/**
  90563. + * This union represents the bit fields in the User HW Config2
  90564. + * Register. Read the register into the <i>d32</i> element then read
  90565. + * out the bits using the <i>b</i>it elements.
  90566. + */
  90567. +typedef union hwcfg2_data {
  90568. + /** raw register data */
  90569. + uint32_t d32;
  90570. + /** register bits */
  90571. + struct {
  90572. + /* GHWCFG2 */
  90573. + unsigned op_mode:3;
  90574. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  90575. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  90576. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  90577. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  90578. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  90579. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  90580. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  90581. +
  90582. + unsigned architecture:2;
  90583. + unsigned point2point:1;
  90584. + unsigned hs_phy_type:2;
  90585. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  90586. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  90587. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  90588. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  90589. +
  90590. + unsigned fs_phy_type:2;
  90591. + unsigned num_dev_ep:4;
  90592. + unsigned num_host_chan:4;
  90593. + unsigned perio_ep_supported:1;
  90594. + unsigned dynamic_fifo:1;
  90595. + unsigned multi_proc_int:1;
  90596. + unsigned reserved21:1;
  90597. + unsigned nonperio_tx_q_depth:2;
  90598. + unsigned host_perio_tx_q_depth:2;
  90599. + unsigned dev_token_q_depth:5;
  90600. + unsigned otg_enable_ic_usb:1;
  90601. + } b;
  90602. +} hwcfg2_data_t;
  90603. +
  90604. +/**
  90605. + * This union represents the bit fields in the User HW Config3
  90606. + * Register. Read the register into the <i>d32</i> element then read
  90607. + * out the bits using the <i>b</i>it elements.
  90608. + */
  90609. +typedef union hwcfg3_data {
  90610. + /** raw register data */
  90611. + uint32_t d32;
  90612. + /** register bits */
  90613. + struct {
  90614. + /* GHWCFG3 */
  90615. + unsigned xfer_size_cntr_width:4;
  90616. + unsigned packet_size_cntr_width:3;
  90617. + unsigned otg_func:1;
  90618. + unsigned i2c:1;
  90619. + unsigned vendor_ctrl_if:1;
  90620. + unsigned optional_features:1;
  90621. + unsigned synch_reset_type:1;
  90622. + unsigned adp_supp:1;
  90623. + unsigned otg_enable_hsic:1;
  90624. + unsigned bc_support:1;
  90625. + unsigned otg_lpm_en:1;
  90626. + unsigned dfifo_depth:16;
  90627. + } b;
  90628. +} hwcfg3_data_t;
  90629. +
  90630. +/**
  90631. + * This union represents the bit fields in the User HW Config4
  90632. + * Register. Read the register into the <i>d32</i> element then read
  90633. + * out the bits using the <i>b</i>it elements.
  90634. + */
  90635. +typedef union hwcfg4_data {
  90636. + /** raw register data */
  90637. + uint32_t d32;
  90638. + /** register bits */
  90639. + struct {
  90640. + unsigned num_dev_perio_in_ep:4;
  90641. + unsigned power_optimiz:1;
  90642. + unsigned min_ahb_freq:1;
  90643. + unsigned hiber:1;
  90644. + unsigned xhiber:1;
  90645. + unsigned reserved:6;
  90646. + unsigned utmi_phy_data_width:2;
  90647. + unsigned num_dev_mode_ctrl_ep:4;
  90648. + unsigned iddig_filt_en:1;
  90649. + unsigned vbus_valid_filt_en:1;
  90650. + unsigned a_valid_filt_en:1;
  90651. + unsigned b_valid_filt_en:1;
  90652. + unsigned session_end_filt_en:1;
  90653. + unsigned ded_fifo_en:1;
  90654. + unsigned num_in_eps:4;
  90655. + unsigned desc_dma:1;
  90656. + unsigned desc_dma_dyn:1;
  90657. + } b;
  90658. +} hwcfg4_data_t;
  90659. +
  90660. +/**
  90661. + * This union represents the bit fields of the Core LPM Configuration
  90662. + * Register (GLPMCFG). Set the bits using bit fields then write
  90663. + * the <i>d32</i> value to the register.
  90664. + */
  90665. +typedef union glpmctl_data {
  90666. + /** raw register data */
  90667. + uint32_t d32;
  90668. + /** register bits */
  90669. + struct {
  90670. + /** LPM-Capable (LPMCap) (Device and Host)
  90671. + * The application uses this bit to control
  90672. + * the DWC_otg core LPM capabilities.
  90673. + */
  90674. + unsigned lpm_cap_en:1;
  90675. + /** LPM response programmed by application (AppL1Res) (Device)
  90676. + * Handshake response to LPM token pre-programmed
  90677. + * by device application software.
  90678. + */
  90679. + unsigned appl_resp:1;
  90680. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  90681. + * In Host mode this field indicates the value of HIRD
  90682. + * to be sent in an LPM transaction.
  90683. + * In Device mode this field is updated with the
  90684. + * Received LPM Token HIRD bmAttribute
  90685. + * when an ACK/NYET/STALL response is sent
  90686. + * to an LPM transaction.
  90687. + */
  90688. + unsigned hird:4;
  90689. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  90690. + * In Host mode this bit indicates the value of remote
  90691. + * wake up to be sent in wIndex field of LPM transaction.
  90692. + * In Device mode this field is updated with the
  90693. + * Received LPM Token bRemoteWake bmAttribute
  90694. + * when an ACK/NYET/STALL response is sent
  90695. + * to an LPM transaction.
  90696. + */
  90697. + unsigned rem_wkup_en:1;
  90698. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  90699. + * The application uses this bit to control
  90700. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  90701. + */
  90702. + unsigned en_utmi_sleep:1;
  90703. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  90704. + */
  90705. + unsigned hird_thres:5;
  90706. + /** LPM Response (CoreL1Res) (Device and Host)
  90707. + * In Host mode this bit contains handsake response to
  90708. + * LPM transaction.
  90709. + * In Device mode the response of the core to
  90710. + * LPM transaction received is reflected in these two bits.
  90711. + - 0x0 : ERROR (No handshake response)
  90712. + - 0x1 : STALL
  90713. + - 0x2 : NYET
  90714. + - 0x3 : ACK
  90715. + */
  90716. + unsigned lpm_resp:2;
  90717. + /** Port Sleep Status (SlpSts) (Device and Host)
  90718. + * This bit is set as long as a Sleep condition
  90719. + * is present on the USB bus.
  90720. + */
  90721. + unsigned prt_sleep_sts:1;
  90722. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  90723. + * Indicates that the application or host
  90724. + * can start resume from Sleep state.
  90725. + */
  90726. + unsigned sleep_state_resumeok:1;
  90727. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  90728. + * The channel number on which the LPM transaction
  90729. + * has to be applied while sending
  90730. + * an LPM transaction to the local device.
  90731. + */
  90732. + unsigned lpm_chan_index:4;
  90733. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  90734. + * Number host retries that would be performed
  90735. + * if the device response was not valid response.
  90736. + */
  90737. + unsigned retry_count:3;
  90738. + /** Send LPM Transaction (SndLPM) (Host)
  90739. + * When set by application software,
  90740. + * an LPM transaction containing two tokens
  90741. + * is sent.
  90742. + */
  90743. + unsigned send_lpm:1;
  90744. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  90745. + * Number of LPM Host Retries still remaining
  90746. + * to be transmitted for the current LPM sequence
  90747. + */
  90748. + unsigned retry_count_sts:3;
  90749. + unsigned reserved28_29:2;
  90750. + /** In host mode once this bit is set, the host
  90751. + * configures to drive the HSIC Idle state on the bus.
  90752. + * It then waits for the device to initiate the Connect sequence.
  90753. + * In device mode once this bit is set, the device waits for
  90754. + * the HSIC Idle line state on the bus. Upon receving the Idle
  90755. + * line state, it initiates the HSIC Connect sequence.
  90756. + */
  90757. + unsigned hsic_connect:1;
  90758. + /** This bit overrides and functionally inverts
  90759. + * the if_select_hsic input port signal.
  90760. + */
  90761. + unsigned inv_sel_hsic:1;
  90762. + } b;
  90763. +} glpmcfg_data_t;
  90764. +
  90765. +/**
  90766. + * This union represents the bit fields of the Core ADP Timer, Control and
  90767. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  90768. + * the <i>d32</i> value to the register.
  90769. + */
  90770. +typedef union adpctl_data {
  90771. + /** raw register data */
  90772. + uint32_t d32;
  90773. + /** register bits */
  90774. + struct {
  90775. + /** Probe Discharge (PRB_DSCHG)
  90776. + * These bits set the times for TADP_DSCHG.
  90777. + * These bits are defined as follows:
  90778. + * 2'b00 - 4 msec
  90779. + * 2'b01 - 8 msec
  90780. + * 2'b10 - 16 msec
  90781. + * 2'b11 - 32 msec
  90782. + */
  90783. + unsigned prb_dschg:2;
  90784. + /** Probe Delta (PRB_DELTA)
  90785. + * These bits set the resolution for RTIM value.
  90786. + * The bits are defined in units of 32 kHz clock cycles as follows:
  90787. + * 2'b00 - 1 cycles
  90788. + * 2'b01 - 2 cycles
  90789. + * 2'b10 - 3 cycles
  90790. + * 2'b11 - 4 cycles
  90791. + * For example if this value is chosen to 2'b01, it means that RTIM
  90792. + * increments for every 3(three) 32Khz clock cycles.
  90793. + */
  90794. + unsigned prb_delta:2;
  90795. + /** Probe Period (PRB_PER)
  90796. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  90797. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  90798. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  90799. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  90800. + * 2'b11 - Reserved
  90801. + */
  90802. + unsigned prb_per:2;
  90803. + /** These bits capture the latest time it took for VBUS to ramp from
  90804. + * VADP_SINK to VADP_PRB.
  90805. + * 0x000 - 1 cycles
  90806. + * 0x001 - 2 cycles
  90807. + * 0x002 - 3 cycles
  90808. + * etc
  90809. + * 0x7FF - 2048 cycles
  90810. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  90811. + */
  90812. + unsigned rtim:11;
  90813. + /** Enable Probe (EnaPrb)
  90814. + * When programmed to 1'b1, the core performs a probe operation.
  90815. + * This bit is valid only if OTG_Ver = 1'b1.
  90816. + */
  90817. + unsigned enaprb:1;
  90818. + /** Enable Sense (EnaSns)
  90819. + * When programmed to 1'b1, the core performs a Sense operation.
  90820. + * This bit is valid only if OTG_Ver = 1'b1.
  90821. + */
  90822. + unsigned enasns:1;
  90823. + /** ADP Reset (ADPRes)
  90824. + * When set, ADP controller is reset.
  90825. + * This bit is valid only if OTG_Ver = 1'b1.
  90826. + */
  90827. + unsigned adpres:1;
  90828. + /** ADP Enable (ADPEn)
  90829. + * When set, the core performs either ADP probing or sensing
  90830. + * based on EnaPrb or EnaSns.
  90831. + * This bit is valid only if OTG_Ver = 1'b1.
  90832. + */
  90833. + unsigned adpen:1;
  90834. + /** ADP Probe Interrupt (ADP_PRB_INT)
  90835. + * When this bit is set, it means that the VBUS
  90836. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  90837. + * This bit is valid only if OTG_Ver = 1'b1.
  90838. + */
  90839. + unsigned adp_prb_int:1;
  90840. + /**
  90841. + * ADP Sense Interrupt (ADP_SNS_INT)
  90842. + * When this bit is set, it means that the VBUS voltage is greater than
  90843. + * VADP_SNS value or VADP_SNS is reached.
  90844. + * This bit is valid only if OTG_Ver = 1'b1.
  90845. + */
  90846. + unsigned adp_sns_int:1;
  90847. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  90848. + * This bit is relevant only for an ADP probe.
  90849. + * When this bit is set, it means that the ramp time has
  90850. + * completed ie ADPCTL.RTIM has reached its terminal value
  90851. + * of 0x7FF. This is a debug feature that allows software
  90852. + * to read the ramp time after each cycle.
  90853. + * This bit is valid only if OTG_Ver = 1'b1.
  90854. + */
  90855. + unsigned adp_tmout_int:1;
  90856. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  90857. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  90858. + * This bit is valid only if OTG_Ver = 1'b1.
  90859. + */
  90860. + unsigned adp_prb_int_msk:1;
  90861. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  90862. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  90863. + * This bit is valid only if OTG_Ver = 1'b1.
  90864. + */
  90865. + unsigned adp_sns_int_msk:1;
  90866. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  90867. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  90868. + * This bit is valid only if OTG_Ver = 1'b1.
  90869. + */
  90870. + unsigned adp_tmout_int_msk:1;
  90871. + /** Access Request
  90872. + * 2'b00 - Read/Write Valid (updated by the core)
  90873. + * 2'b01 - Read
  90874. + * 2'b00 - Write
  90875. + * 2'b00 - Reserved
  90876. + */
  90877. + unsigned ar:2;
  90878. + /** Reserved */
  90879. + unsigned reserved29_31:3;
  90880. + } b;
  90881. +} adpctl_data_t;
  90882. +
  90883. +////////////////////////////////////////////
  90884. +// Device Registers
  90885. +/**
  90886. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  90887. + *
  90888. + * The following structures define the size and relative field offsets
  90889. + * for the Device Mode Registers.
  90890. + *
  90891. + * <i>These registers are visible only in Device mode and must not be
  90892. + * accessed in Host mode, as the results are unknown.</i>
  90893. + */
  90894. +typedef struct dwc_otg_dev_global_regs {
  90895. + /** Device Configuration Register. <i>Offset 800h</i> */
  90896. + volatile uint32_t dcfg;
  90897. + /** Device Control Register. <i>Offset: 804h</i> */
  90898. + volatile uint32_t dctl;
  90899. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  90900. + volatile uint32_t dsts;
  90901. + /** Reserved. <i>Offset: 80Ch</i> */
  90902. + uint32_t unused;
  90903. + /** Device IN Endpoint Common Interrupt Mask
  90904. + * Register. <i>Offset: 810h</i> */
  90905. + volatile uint32_t diepmsk;
  90906. + /** Device OUT Endpoint Common Interrupt Mask
  90907. + * Register. <i>Offset: 814h</i> */
  90908. + volatile uint32_t doepmsk;
  90909. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  90910. + volatile uint32_t daint;
  90911. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  90912. + * 81Ch</i> */
  90913. + volatile uint32_t daintmsk;
  90914. + /** Device IN Token Queue Read Register-1 (Read Only).
  90915. + * <i>Offset: 820h</i> */
  90916. + volatile uint32_t dtknqr1;
  90917. + /** Device IN Token Queue Read Register-2 (Read Only).
  90918. + * <i>Offset: 824h</i> */
  90919. + volatile uint32_t dtknqr2;
  90920. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  90921. + volatile uint32_t dvbusdis;
  90922. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  90923. + volatile uint32_t dvbuspulse;
  90924. + /** Device IN Token Queue Read Register-3 (Read Only). /
  90925. + * Device Thresholding control register (Read/Write)
  90926. + * <i>Offset: 830h</i> */
  90927. + volatile uint32_t dtknqr3_dthrctl;
  90928. + /** Device IN Token Queue Read Register-4 (Read Only). /
  90929. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  90930. + * <i>Offset: 834h</i> */
  90931. + volatile uint32_t dtknqr4_fifoemptymsk;
  90932. + /** Device Each Endpoint Interrupt Register (Read Only). /
  90933. + * <i>Offset: 838h</i> */
  90934. + volatile uint32_t deachint;
  90935. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  90936. + * <i>Offset: 83Ch</i> */
  90937. + volatile uint32_t deachintmsk;
  90938. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  90939. + * <i>Offset: 840h</i> */
  90940. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  90941. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  90942. + * <i>Offset: 880h</i> */
  90943. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  90944. +} dwc_otg_device_global_regs_t;
  90945. +
  90946. +/**
  90947. + * This union represents the bit fields in the Device Configuration
  90948. + * Register. Read the register into the <i>d32</i> member then
  90949. + * set/clear the bits using the <i>b</i>it elements. Write the
  90950. + * <i>d32</i> member to the dcfg register.
  90951. + */
  90952. +typedef union dcfg_data {
  90953. + /** raw register data */
  90954. + uint32_t d32;
  90955. + /** register bits */
  90956. + struct {
  90957. + /** Device Speed */
  90958. + unsigned devspd:2;
  90959. + /** Non Zero Length Status OUT Handshake */
  90960. + unsigned nzstsouthshk:1;
  90961. +#define DWC_DCFG_SEND_STALL 1
  90962. +
  90963. + unsigned ena32khzs:1;
  90964. + /** Device Addresses */
  90965. + unsigned devaddr:7;
  90966. + /** Periodic Frame Interval */
  90967. + unsigned perfrint:2;
  90968. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  90969. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  90970. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  90971. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  90972. +
  90973. + /** Enable Device OUT NAK for bulk in DDMA mode */
  90974. + unsigned endevoutnak:1;
  90975. +
  90976. + unsigned reserved14_17:4;
  90977. + /** In Endpoint Mis-match count */
  90978. + unsigned epmscnt:5;
  90979. + /** Enable Descriptor DMA in Device mode */
  90980. + unsigned descdma:1;
  90981. + unsigned perschintvl:2;
  90982. + unsigned resvalid:6;
  90983. + } b;
  90984. +} dcfg_data_t;
  90985. +
  90986. +/**
  90987. + * This union represents the bit fields in the Device Control
  90988. + * Register. Read the register into the <i>d32</i> member then
  90989. + * set/clear the bits using the <i>b</i>it elements.
  90990. + */
  90991. +typedef union dctl_data {
  90992. + /** raw register data */
  90993. + uint32_t d32;
  90994. + /** register bits */
  90995. + struct {
  90996. + /** Remote Wakeup */
  90997. + unsigned rmtwkupsig:1;
  90998. + /** Soft Disconnect */
  90999. + unsigned sftdiscon:1;
  91000. + /** Global Non-Periodic IN NAK Status */
  91001. + unsigned gnpinnaksts:1;
  91002. + /** Global OUT NAK Status */
  91003. + unsigned goutnaksts:1;
  91004. + /** Test Control */
  91005. + unsigned tstctl:3;
  91006. + /** Set Global Non-Periodic IN NAK */
  91007. + unsigned sgnpinnak:1;
  91008. + /** Clear Global Non-Periodic IN NAK */
  91009. + unsigned cgnpinnak:1;
  91010. + /** Set Global OUT NAK */
  91011. + unsigned sgoutnak:1;
  91012. + /** Clear Global OUT NAK */
  91013. + unsigned cgoutnak:1;
  91014. + /** Power-On Programming Done */
  91015. + unsigned pwronprgdone:1;
  91016. + /** Reserved */
  91017. + unsigned reserved:1;
  91018. + /** Global Multi Count */
  91019. + unsigned gmc:2;
  91020. + /** Ignore Frame Number for ISOC EPs */
  91021. + unsigned ifrmnum:1;
  91022. + /** NAK on Babble */
  91023. + unsigned nakonbble:1;
  91024. + /** Enable Continue on BNA */
  91025. + unsigned encontonbna:1;
  91026. +
  91027. + unsigned reserved18_31:14;
  91028. + } b;
  91029. +} dctl_data_t;
  91030. +
  91031. +/**
  91032. + * This union represents the bit fields in the Device Status
  91033. + * Register. Read the register into the <i>d32</i> member then
  91034. + * set/clear the bits using the <i>b</i>it elements.
  91035. + */
  91036. +typedef union dsts_data {
  91037. + /** raw register data */
  91038. + uint32_t d32;
  91039. + /** register bits */
  91040. + struct {
  91041. + /** Suspend Status */
  91042. + unsigned suspsts:1;
  91043. + /** Enumerated Speed */
  91044. + unsigned enumspd:2;
  91045. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  91046. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  91047. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  91048. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  91049. + /** Erratic Error */
  91050. + unsigned errticerr:1;
  91051. + unsigned reserved4_7:4;
  91052. + /** Frame or Microframe Number of the received SOF */
  91053. + unsigned soffn:14;
  91054. + unsigned reserved22_31:10;
  91055. + } b;
  91056. +} dsts_data_t;
  91057. +
  91058. +/**
  91059. + * This union represents the bit fields in the Device IN EP Interrupt
  91060. + * Register and the Device IN EP Common Mask Register.
  91061. + *
  91062. + * - Read the register into the <i>d32</i> member then set/clear the
  91063. + * bits using the <i>b</i>it elements.
  91064. + */
  91065. +typedef union diepint_data {
  91066. + /** raw register data */
  91067. + uint32_t d32;
  91068. + /** register bits */
  91069. + struct {
  91070. + /** Transfer complete mask */
  91071. + unsigned xfercompl:1;
  91072. + /** Endpoint disable mask */
  91073. + unsigned epdisabled:1;
  91074. + /** AHB Error mask */
  91075. + unsigned ahberr:1;
  91076. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  91077. + unsigned timeout:1;
  91078. + /** IN Token received with TxF Empty mask */
  91079. + unsigned intktxfemp:1;
  91080. + /** IN Token Received with EP mismatch mask */
  91081. + unsigned intknepmis:1;
  91082. + /** IN Endpoint NAK Effective mask */
  91083. + unsigned inepnakeff:1;
  91084. + /** Reserved */
  91085. + unsigned emptyintr:1;
  91086. +
  91087. + unsigned txfifoundrn:1;
  91088. +
  91089. + /** BNA Interrupt mask */
  91090. + unsigned bna:1;
  91091. +
  91092. + unsigned reserved10_12:3;
  91093. + /** BNA Interrupt mask */
  91094. + unsigned nak:1;
  91095. +
  91096. + unsigned reserved14_31:18;
  91097. + } b;
  91098. +} diepint_data_t;
  91099. +
  91100. +/**
  91101. + * This union represents the bit fields in the Device IN EP
  91102. + * Common/Dedicated Interrupt Mask Register.
  91103. + */
  91104. +typedef union diepint_data diepmsk_data_t;
  91105. +
  91106. +/**
  91107. + * This union represents the bit fields in the Device OUT EP Interrupt
  91108. + * Registerand Device OUT EP Common Interrupt Mask Register.
  91109. + *
  91110. + * - Read the register into the <i>d32</i> member then set/clear the
  91111. + * bits using the <i>b</i>it elements.
  91112. + */
  91113. +typedef union doepint_data {
  91114. + /** raw register data */
  91115. + uint32_t d32;
  91116. + /** register bits */
  91117. + struct {
  91118. + /** Transfer complete */
  91119. + unsigned xfercompl:1;
  91120. + /** Endpoint disable */
  91121. + unsigned epdisabled:1;
  91122. + /** AHB Error */
  91123. + unsigned ahberr:1;
  91124. + /** Setup Phase Done (contorl EPs) */
  91125. + unsigned setup:1;
  91126. + /** OUT Token Received when Endpoint Disabled */
  91127. + unsigned outtknepdis:1;
  91128. +
  91129. + unsigned stsphsercvd:1;
  91130. + /** Back-to-Back SETUP Packets Received */
  91131. + unsigned back2backsetup:1;
  91132. +
  91133. + unsigned reserved7:1;
  91134. + /** OUT packet Error */
  91135. + unsigned outpkterr:1;
  91136. + /** BNA Interrupt */
  91137. + unsigned bna:1;
  91138. +
  91139. + unsigned reserved10:1;
  91140. + /** Packet Drop Status */
  91141. + unsigned pktdrpsts:1;
  91142. + /** Babble Interrupt */
  91143. + unsigned babble:1;
  91144. + /** NAK Interrupt */
  91145. + unsigned nak:1;
  91146. + /** NYET Interrupt */
  91147. + unsigned nyet:1;
  91148. + /** Bit indicating setup packet received */
  91149. + unsigned sr:1;
  91150. +
  91151. + unsigned reserved16_31:16;
  91152. + } b;
  91153. +} doepint_data_t;
  91154. +
  91155. +/**
  91156. + * This union represents the bit fields in the Device OUT EP
  91157. + * Common/Dedicated Interrupt Mask Register.
  91158. + */
  91159. +typedef union doepint_data doepmsk_data_t;
  91160. +
  91161. +/**
  91162. + * This union represents the bit fields in the Device All EP Interrupt
  91163. + * and Mask Registers.
  91164. + * - Read the register into the <i>d32</i> member then set/clear the
  91165. + * bits using the <i>b</i>it elements.
  91166. + */
  91167. +typedef union daint_data {
  91168. + /** raw register data */
  91169. + uint32_t d32;
  91170. + /** register bits */
  91171. + struct {
  91172. + /** IN Endpoint bits */
  91173. + unsigned in:16;
  91174. + /** OUT Endpoint bits */
  91175. + unsigned out:16;
  91176. + } ep;
  91177. + struct {
  91178. + /** IN Endpoint bits */
  91179. + unsigned inep0:1;
  91180. + unsigned inep1:1;
  91181. + unsigned inep2:1;
  91182. + unsigned inep3:1;
  91183. + unsigned inep4:1;
  91184. + unsigned inep5:1;
  91185. + unsigned inep6:1;
  91186. + unsigned inep7:1;
  91187. + unsigned inep8:1;
  91188. + unsigned inep9:1;
  91189. + unsigned inep10:1;
  91190. + unsigned inep11:1;
  91191. + unsigned inep12:1;
  91192. + unsigned inep13:1;
  91193. + unsigned inep14:1;
  91194. + unsigned inep15:1;
  91195. + /** OUT Endpoint bits */
  91196. + unsigned outep0:1;
  91197. + unsigned outep1:1;
  91198. + unsigned outep2:1;
  91199. + unsigned outep3:1;
  91200. + unsigned outep4:1;
  91201. + unsigned outep5:1;
  91202. + unsigned outep6:1;
  91203. + unsigned outep7:1;
  91204. + unsigned outep8:1;
  91205. + unsigned outep9:1;
  91206. + unsigned outep10:1;
  91207. + unsigned outep11:1;
  91208. + unsigned outep12:1;
  91209. + unsigned outep13:1;
  91210. + unsigned outep14:1;
  91211. + unsigned outep15:1;
  91212. + } b;
  91213. +} daint_data_t;
  91214. +
  91215. +/**
  91216. + * This union represents the bit fields in the Device IN Token Queue
  91217. + * Read Registers.
  91218. + * - Read the register into the <i>d32</i> member.
  91219. + * - READ-ONLY Register
  91220. + */
  91221. +typedef union dtknq1_data {
  91222. + /** raw register data */
  91223. + uint32_t d32;
  91224. + /** register bits */
  91225. + struct {
  91226. + /** In Token Queue Write Pointer */
  91227. + unsigned intknwptr:5;
  91228. + /** Reserved */
  91229. + unsigned reserved05_06:2;
  91230. + /** write pointer has wrapped. */
  91231. + unsigned wrap_bit:1;
  91232. + /** EP Numbers of IN Tokens 0 ... 4 */
  91233. + unsigned epnums0_5:24;
  91234. + } b;
  91235. +} dtknq1_data_t;
  91236. +
  91237. +/**
  91238. + * This union represents Threshold control Register
  91239. + * - Read and write the register into the <i>d32</i> member.
  91240. + * - READ-WRITABLE Register
  91241. + */
  91242. +typedef union dthrctl_data {
  91243. + /** raw register data */
  91244. + uint32_t d32;
  91245. + /** register bits */
  91246. + struct {
  91247. + /** non ISO Tx Thr. Enable */
  91248. + unsigned non_iso_thr_en:1;
  91249. + /** ISO Tx Thr. Enable */
  91250. + unsigned iso_thr_en:1;
  91251. + /** Tx Thr. Length */
  91252. + unsigned tx_thr_len:9;
  91253. + /** AHB Threshold ratio */
  91254. + unsigned ahb_thr_ratio:2;
  91255. + /** Reserved */
  91256. + unsigned reserved13_15:3;
  91257. + /** Rx Thr. Enable */
  91258. + unsigned rx_thr_en:1;
  91259. + /** Rx Thr. Length */
  91260. + unsigned rx_thr_len:9;
  91261. + unsigned reserved26:1;
  91262. + /** Arbiter Parking Enable*/
  91263. + unsigned arbprken:1;
  91264. + /** Reserved */
  91265. + unsigned reserved28_31:4;
  91266. + } b;
  91267. +} dthrctl_data_t;
  91268. +
  91269. +/**
  91270. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  91271. + * 900h-AFCh</i>
  91272. + *
  91273. + * There will be one set of endpoint registers per logical endpoint
  91274. + * implemented.
  91275. + *
  91276. + * <i>These registers are visible only in Device mode and must not be
  91277. + * accessed in Host mode, as the results are unknown.</i>
  91278. + */
  91279. +typedef struct dwc_otg_dev_in_ep_regs {
  91280. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  91281. + * (ep_num * 20h) + 00h</i> */
  91282. + volatile uint32_t diepctl;
  91283. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  91284. + uint32_t reserved04;
  91285. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  91286. + * (ep_num * 20h) + 08h</i> */
  91287. + volatile uint32_t diepint;
  91288. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  91289. + uint32_t reserved0C;
  91290. + /** Device IN Endpoint Transfer Size
  91291. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  91292. + volatile uint32_t dieptsiz;
  91293. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  91294. + * (ep_num * 20h) + 14h</i> */
  91295. + volatile uint32_t diepdma;
  91296. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  91297. + * (ep_num * 20h) + 18h</i> */
  91298. + volatile uint32_t dtxfsts;
  91299. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  91300. + * (ep_num * 20h) + 1Ch</i> */
  91301. + volatile uint32_t diepdmab;
  91302. +} dwc_otg_dev_in_ep_regs_t;
  91303. +
  91304. +/**
  91305. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  91306. + * B00h-CFCh</i>
  91307. + *
  91308. + * There will be one set of endpoint registers per logical endpoint
  91309. + * implemented.
  91310. + *
  91311. + * <i>These registers are visible only in Device mode and must not be
  91312. + * accessed in Host mode, as the results are unknown.</i>
  91313. + */
  91314. +typedef struct dwc_otg_dev_out_ep_regs {
  91315. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  91316. + * (ep_num * 20h) + 00h</i> */
  91317. + volatile uint32_t doepctl;
  91318. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  91319. + uint32_t reserved04;
  91320. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  91321. + * (ep_num * 20h) + 08h</i> */
  91322. + volatile uint32_t doepint;
  91323. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  91324. + uint32_t reserved0C;
  91325. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  91326. + * B00h + (ep_num * 20h) + 10h</i> */
  91327. + volatile uint32_t doeptsiz;
  91328. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  91329. + * + (ep_num * 20h) + 14h</i> */
  91330. + volatile uint32_t doepdma;
  91331. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  91332. + uint32_t unused;
  91333. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  91334. + * + (ep_num * 20h) + 1Ch</i> */
  91335. + uint32_t doepdmab;
  91336. +} dwc_otg_dev_out_ep_regs_t;
  91337. +
  91338. +/**
  91339. + * This union represents the bit fields in the Device EP Control
  91340. + * Register. Read the register into the <i>d32</i> member then
  91341. + * set/clear the bits using the <i>b</i>it elements.
  91342. + */
  91343. +typedef union depctl_data {
  91344. + /** raw register data */
  91345. + uint32_t d32;
  91346. + /** register bits */
  91347. + struct {
  91348. + /** Maximum Packet Size
  91349. + * IN/OUT EPn
  91350. + * IN/OUT EP0 - 2 bits
  91351. + * 2'b00: 64 Bytes
  91352. + * 2'b01: 32
  91353. + * 2'b10: 16
  91354. + * 2'b11: 8 */
  91355. + unsigned mps:11;
  91356. +#define DWC_DEP0CTL_MPS_64 0
  91357. +#define DWC_DEP0CTL_MPS_32 1
  91358. +#define DWC_DEP0CTL_MPS_16 2
  91359. +#define DWC_DEP0CTL_MPS_8 3
  91360. +
  91361. + /** Next Endpoint
  91362. + * IN EPn/IN EP0
  91363. + * OUT EPn/OUT EP0 - reserved */
  91364. + unsigned nextep:4;
  91365. +
  91366. + /** USB Active Endpoint */
  91367. + unsigned usbactep:1;
  91368. +
  91369. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  91370. + * This field contains the PID of the packet going to
  91371. + * be received or transmitted on this endpoint. The
  91372. + * application should program the PID of the first
  91373. + * packet going to be received or transmitted on this
  91374. + * endpoint , after the endpoint is
  91375. + * activated. Application use the SetD1PID and
  91376. + * SetD0PID fields of this register to program either
  91377. + * D0 or D1 PID.
  91378. + *
  91379. + * The encoding for this field is
  91380. + * - 0: D0
  91381. + * - 1: D1
  91382. + */
  91383. + unsigned dpid:1;
  91384. +
  91385. + /** NAK Status */
  91386. + unsigned naksts:1;
  91387. +
  91388. + /** Endpoint Type
  91389. + * 2'b00: Control
  91390. + * 2'b01: Isochronous
  91391. + * 2'b10: Bulk
  91392. + * 2'b11: Interrupt */
  91393. + unsigned eptype:2;
  91394. +
  91395. + /** Snoop Mode
  91396. + * OUT EPn/OUT EP0
  91397. + * IN EPn/IN EP0 - reserved */
  91398. + unsigned snp:1;
  91399. +
  91400. + /** Stall Handshake */
  91401. + unsigned stall:1;
  91402. +
  91403. + /** Tx Fifo Number
  91404. + * IN EPn/IN EP0
  91405. + * OUT EPn/OUT EP0 - reserved */
  91406. + unsigned txfnum:4;
  91407. +
  91408. + /** Clear NAK */
  91409. + unsigned cnak:1;
  91410. + /** Set NAK */
  91411. + unsigned snak:1;
  91412. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  91413. + * Writing to this field sets the Endpoint DPID (DPID)
  91414. + * field in this register to DATA0. Set Even
  91415. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  91416. + * Writing to this field sets the Even/Odd
  91417. + * (micro)frame (EO_FrNum) field to even (micro)
  91418. + * frame.
  91419. + */
  91420. + unsigned setd0pid:1;
  91421. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  91422. + * Writing to this field sets the Endpoint DPID (DPID)
  91423. + * field in this register to DATA1 Set Odd
  91424. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  91425. + * Writing to this field sets the Even/Odd
  91426. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  91427. + */
  91428. + unsigned setd1pid:1;
  91429. +
  91430. + /** Endpoint Disable */
  91431. + unsigned epdis:1;
  91432. + /** Endpoint Enable */
  91433. + unsigned epena:1;
  91434. + } b;
  91435. +} depctl_data_t;
  91436. +
  91437. +/**
  91438. + * This union represents the bit fields in the Device EP Transfer
  91439. + * Size Register. Read the register into the <i>d32</i> member then
  91440. + * set/clear the bits using the <i>b</i>it elements.
  91441. + */
  91442. +typedef union deptsiz_data {
  91443. + /** raw register data */
  91444. + uint32_t d32;
  91445. + /** register bits */
  91446. + struct {
  91447. + /** Transfer size */
  91448. + unsigned xfersize:19;
  91449. +/** Max packet count for EP (pow(2,10)-1) */
  91450. +#define MAX_PKT_CNT 1023
  91451. + /** Packet Count */
  91452. + unsigned pktcnt:10;
  91453. + /** Multi Count - Periodic IN endpoints */
  91454. + unsigned mc:2;
  91455. + unsigned reserved:1;
  91456. + } b;
  91457. +} deptsiz_data_t;
  91458. +
  91459. +/**
  91460. + * This union represents the bit fields in the Device EP 0 Transfer
  91461. + * Size Register. Read the register into the <i>d32</i> member then
  91462. + * set/clear the bits using the <i>b</i>it elements.
  91463. + */
  91464. +typedef union deptsiz0_data {
  91465. + /** raw register data */
  91466. + uint32_t d32;
  91467. + /** register bits */
  91468. + struct {
  91469. + /** Transfer size */
  91470. + unsigned xfersize:7;
  91471. + /** Reserved */
  91472. + unsigned reserved7_18:12;
  91473. + /** Packet Count */
  91474. + unsigned pktcnt:2;
  91475. + /** Reserved */
  91476. + unsigned reserved21_28:8;
  91477. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  91478. + unsigned supcnt:2;
  91479. + unsigned reserved31;
  91480. + } b;
  91481. +} deptsiz0_data_t;
  91482. +
  91483. +/////////////////////////////////////////////////
  91484. +// DMA Descriptor Specific Structures
  91485. +//
  91486. +
  91487. +/** Buffer status definitions */
  91488. +
  91489. +#define BS_HOST_READY 0x0
  91490. +#define BS_DMA_BUSY 0x1
  91491. +#define BS_DMA_DONE 0x2
  91492. +#define BS_HOST_BUSY 0x3
  91493. +
  91494. +/** Receive/Transmit status definitions */
  91495. +
  91496. +#define RTS_SUCCESS 0x0
  91497. +#define RTS_BUFFLUSH 0x1
  91498. +#define RTS_RESERVED 0x2
  91499. +#define RTS_BUFERR 0x3
  91500. +
  91501. +/**
  91502. + * This union represents the bit fields in the DMA Descriptor
  91503. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  91504. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  91505. + * <i>b_iso_in</i> elements.
  91506. + */
  91507. +typedef union dev_dma_desc_sts {
  91508. + /** raw register data */
  91509. + uint32_t d32;
  91510. + /** quadlet bits */
  91511. + struct {
  91512. + /** Received number of bytes */
  91513. + unsigned bytes:16;
  91514. + /** NAK bit - only for OUT EPs */
  91515. + unsigned nak:1;
  91516. + unsigned reserved17_22:6;
  91517. + /** Multiple Transfer - only for OUT EPs */
  91518. + unsigned mtrf:1;
  91519. + /** Setup Packet received - only for OUT EPs */
  91520. + unsigned sr:1;
  91521. + /** Interrupt On Complete */
  91522. + unsigned ioc:1;
  91523. + /** Short Packet */
  91524. + unsigned sp:1;
  91525. + /** Last */
  91526. + unsigned l:1;
  91527. + /** Receive Status */
  91528. + unsigned sts:2;
  91529. + /** Buffer Status */
  91530. + unsigned bs:2;
  91531. + } b;
  91532. +
  91533. +//#ifdef DWC_EN_ISOC
  91534. + /** iso out quadlet bits */
  91535. + struct {
  91536. + /** Received number of bytes */
  91537. + unsigned rxbytes:11;
  91538. +
  91539. + unsigned reserved11:1;
  91540. + /** Frame Number */
  91541. + unsigned framenum:11;
  91542. + /** Received ISO Data PID */
  91543. + unsigned pid:2;
  91544. + /** Interrupt On Complete */
  91545. + unsigned ioc:1;
  91546. + /** Short Packet */
  91547. + unsigned sp:1;
  91548. + /** Last */
  91549. + unsigned l:1;
  91550. + /** Receive Status */
  91551. + unsigned rxsts:2;
  91552. + /** Buffer Status */
  91553. + unsigned bs:2;
  91554. + } b_iso_out;
  91555. +
  91556. + /** iso in quadlet bits */
  91557. + struct {
  91558. + /** Transmited number of bytes */
  91559. + unsigned txbytes:12;
  91560. + /** Frame Number */
  91561. + unsigned framenum:11;
  91562. + /** Transmited ISO Data PID */
  91563. + unsigned pid:2;
  91564. + /** Interrupt On Complete */
  91565. + unsigned ioc:1;
  91566. + /** Short Packet */
  91567. + unsigned sp:1;
  91568. + /** Last */
  91569. + unsigned l:1;
  91570. + /** Transmit Status */
  91571. + unsigned txsts:2;
  91572. + /** Buffer Status */
  91573. + unsigned bs:2;
  91574. + } b_iso_in;
  91575. +//#endif /* DWC_EN_ISOC */
  91576. +} dev_dma_desc_sts_t;
  91577. +
  91578. +/**
  91579. + * DMA Descriptor structure
  91580. + *
  91581. + * DMA Descriptor structure contains two quadlets:
  91582. + * Status quadlet and Data buffer pointer.
  91583. + */
  91584. +typedef struct dwc_otg_dev_dma_desc {
  91585. + /** DMA Descriptor status quadlet */
  91586. + dev_dma_desc_sts_t status;
  91587. + /** DMA Descriptor data buffer pointer */
  91588. + uint32_t buf;
  91589. +} dwc_otg_dev_dma_desc_t;
  91590. +
  91591. +/**
  91592. + * The dwc_otg_dev_if structure contains information needed to manage
  91593. + * the DWC_otg controller acting in device mode. It represents the
  91594. + * programming view of the device-specific aspects of the controller.
  91595. + */
  91596. +typedef struct dwc_otg_dev_if {
  91597. + /** Pointer to device Global registers.
  91598. + * Device Global Registers starting at offset 800h
  91599. + */
  91600. + dwc_otg_device_global_regs_t *dev_global_regs;
  91601. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  91602. +
  91603. + /**
  91604. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  91605. + */
  91606. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  91607. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  91608. +#define DWC_EP_REG_OFFSET 0x20
  91609. +
  91610. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  91611. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  91612. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  91613. +
  91614. + /* Device configuration information */
  91615. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  91616. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  91617. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  91618. +
  91619. + /** Size of periodic FIFOs (Bytes) */
  91620. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  91621. +
  91622. + /** Size of Tx FIFOs (Bytes) */
  91623. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  91624. +
  91625. + /** Thresholding enable flags and length varaiables **/
  91626. + uint16_t rx_thr_en;
  91627. + uint16_t iso_tx_thr_en;
  91628. + uint16_t non_iso_tx_thr_en;
  91629. +
  91630. + uint16_t rx_thr_length;
  91631. + uint16_t tx_thr_length;
  91632. +
  91633. + /**
  91634. + * Pointers to the DMA Descriptors for EP0 Control
  91635. + * transfers (virtual and physical)
  91636. + */
  91637. +
  91638. + /** 2 descriptors for SETUP packets */
  91639. + dwc_dma_t dma_setup_desc_addr[2];
  91640. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  91641. +
  91642. + /** Pointer to Descriptor with latest SETUP packet */
  91643. + dwc_otg_dev_dma_desc_t *psetup;
  91644. +
  91645. + /** Index of current SETUP handler descriptor */
  91646. + uint32_t setup_desc_index;
  91647. +
  91648. + /** Descriptor for Data In or Status In phases */
  91649. + dwc_dma_t dma_in_desc_addr;
  91650. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  91651. +
  91652. + /** Descriptor for Data Out or Status Out phases */
  91653. + dwc_dma_t dma_out_desc_addr;
  91654. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  91655. +
  91656. + /** Setup Packet Detected - if set clear NAK when queueing */
  91657. + uint32_t spd;
  91658. + /** Isoc ep pointer on which incomplete happens */
  91659. + void *isoc_ep;
  91660. +
  91661. +} dwc_otg_dev_if_t;
  91662. +
  91663. +/////////////////////////////////////////////////
  91664. +// Host Mode Register Structures
  91665. +//
  91666. +/**
  91667. + * The Host Global Registers structure defines the size and relative
  91668. + * field offsets for the Host Mode Global Registers. Host Global
  91669. + * Registers offsets 400h-7FFh.
  91670. +*/
  91671. +typedef struct dwc_otg_host_global_regs {
  91672. + /** Host Configuration Register. <i>Offset: 400h</i> */
  91673. + volatile uint32_t hcfg;
  91674. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  91675. + volatile uint32_t hfir;
  91676. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  91677. + volatile uint32_t hfnum;
  91678. + /** Reserved. <i>Offset: 40Ch</i> */
  91679. + uint32_t reserved40C;
  91680. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  91681. + volatile uint32_t hptxsts;
  91682. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  91683. + volatile uint32_t haint;
  91684. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  91685. + volatile uint32_t haintmsk;
  91686. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  91687. + volatile uint32_t hflbaddr;
  91688. +} dwc_otg_host_global_regs_t;
  91689. +
  91690. +/**
  91691. + * This union represents the bit fields in the Host Configuration Register.
  91692. + * Read the register into the <i>d32</i> member then set/clear the bits using
  91693. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  91694. + */
  91695. +typedef union hcfg_data {
  91696. + /** raw register data */
  91697. + uint32_t d32;
  91698. +
  91699. + /** register bits */
  91700. + struct {
  91701. + /** FS/LS Phy Clock Select */
  91702. + unsigned fslspclksel:2;
  91703. +#define DWC_HCFG_30_60_MHZ 0
  91704. +#define DWC_HCFG_48_MHZ 1
  91705. +#define DWC_HCFG_6_MHZ 2
  91706. +
  91707. + /** FS/LS Only Support */
  91708. + unsigned fslssupp:1;
  91709. + unsigned reserved3_6:4;
  91710. + /** Enable 32-KHz Suspend Mode */
  91711. + unsigned ena32khzs:1;
  91712. + /** Resume Validation Periiod */
  91713. + unsigned resvalid:8;
  91714. + unsigned reserved16_22:7;
  91715. + /** Enable Scatter/gather DMA in Host mode */
  91716. + unsigned descdma:1;
  91717. + /** Frame List Entries */
  91718. + unsigned frlisten:2;
  91719. + /** Enable Periodic Scheduling */
  91720. + unsigned perschedena:1;
  91721. + unsigned reserved27_30:4;
  91722. + unsigned modechtimen:1;
  91723. + } b;
  91724. +} hcfg_data_t;
  91725. +
  91726. +/**
  91727. + * This union represents the bit fields in the Host Frame Remaing/Number
  91728. + * Register.
  91729. + */
  91730. +typedef union hfir_data {
  91731. + /** raw register data */
  91732. + uint32_t d32;
  91733. +
  91734. + /** register bits */
  91735. + struct {
  91736. + unsigned frint:16;
  91737. + unsigned hfirrldctrl:1;
  91738. + unsigned reserved:15;
  91739. + } b;
  91740. +} hfir_data_t;
  91741. +
  91742. +/**
  91743. + * This union represents the bit fields in the Host Frame Remaing/Number
  91744. + * Register.
  91745. + */
  91746. +typedef union hfnum_data {
  91747. + /** raw register data */
  91748. + uint32_t d32;
  91749. +
  91750. + /** register bits */
  91751. + struct {
  91752. + unsigned frnum:16;
  91753. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  91754. + unsigned frrem:16;
  91755. + } b;
  91756. +} hfnum_data_t;
  91757. +
  91758. +typedef union hptxsts_data {
  91759. + /** raw register data */
  91760. + uint32_t d32;
  91761. +
  91762. + /** register bits */
  91763. + struct {
  91764. + unsigned ptxfspcavail:16;
  91765. + unsigned ptxqspcavail:8;
  91766. + /** Top of the Periodic Transmit Request Queue
  91767. + * - bit 24 - Terminate (last entry for the selected channel)
  91768. + * - bits 26:25 - Token Type
  91769. + * - 2'b00 - Zero length
  91770. + * - 2'b01 - Ping
  91771. + * - 2'b10 - Disable
  91772. + * - bits 30:27 - Channel Number
  91773. + * - bit 31 - Odd/even microframe
  91774. + */
  91775. + unsigned ptxqtop_terminate:1;
  91776. + unsigned ptxqtop_token:2;
  91777. + unsigned ptxqtop_chnum:4;
  91778. + unsigned ptxqtop_odd:1;
  91779. + } b;
  91780. +} hptxsts_data_t;
  91781. +
  91782. +/**
  91783. + * This union represents the bit fields in the Host Port Control and Status
  91784. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91785. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91786. + * hprt0 register.
  91787. + */
  91788. +typedef union hprt0_data {
  91789. + /** raw register data */
  91790. + uint32_t d32;
  91791. + /** register bits */
  91792. + struct {
  91793. + unsigned prtconnsts:1;
  91794. + unsigned prtconndet:1;
  91795. + unsigned prtena:1;
  91796. + unsigned prtenchng:1;
  91797. + unsigned prtovrcurract:1;
  91798. + unsigned prtovrcurrchng:1;
  91799. + unsigned prtres:1;
  91800. + unsigned prtsusp:1;
  91801. + unsigned prtrst:1;
  91802. + unsigned reserved9:1;
  91803. + unsigned prtlnsts:2;
  91804. + unsigned prtpwr:1;
  91805. + unsigned prttstctl:4;
  91806. + unsigned prtspd:2;
  91807. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  91808. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  91809. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  91810. + unsigned reserved19_31:13;
  91811. + } b;
  91812. +} hprt0_data_t;
  91813. +
  91814. +/**
  91815. + * This union represents the bit fields in the Host All Interrupt
  91816. + * Register.
  91817. + */
  91818. +typedef union haint_data {
  91819. + /** raw register data */
  91820. + uint32_t d32;
  91821. + /** register bits */
  91822. + struct {
  91823. + unsigned ch0:1;
  91824. + unsigned ch1:1;
  91825. + unsigned ch2:1;
  91826. + unsigned ch3:1;
  91827. + unsigned ch4:1;
  91828. + unsigned ch5:1;
  91829. + unsigned ch6:1;
  91830. + unsigned ch7:1;
  91831. + unsigned ch8:1;
  91832. + unsigned ch9:1;
  91833. + unsigned ch10:1;
  91834. + unsigned ch11:1;
  91835. + unsigned ch12:1;
  91836. + unsigned ch13:1;
  91837. + unsigned ch14:1;
  91838. + unsigned ch15:1;
  91839. + unsigned reserved:16;
  91840. + } b;
  91841. +
  91842. + struct {
  91843. + unsigned chint:16;
  91844. + unsigned reserved:16;
  91845. + } b2;
  91846. +} haint_data_t;
  91847. +
  91848. +/**
  91849. + * This union represents the bit fields in the Host All Interrupt
  91850. + * Register.
  91851. + */
  91852. +typedef union haintmsk_data {
  91853. + /** raw register data */
  91854. + uint32_t d32;
  91855. + /** register bits */
  91856. + struct {
  91857. + unsigned ch0:1;
  91858. + unsigned ch1:1;
  91859. + unsigned ch2:1;
  91860. + unsigned ch3:1;
  91861. + unsigned ch4:1;
  91862. + unsigned ch5:1;
  91863. + unsigned ch6:1;
  91864. + unsigned ch7:1;
  91865. + unsigned ch8:1;
  91866. + unsigned ch9:1;
  91867. + unsigned ch10:1;
  91868. + unsigned ch11:1;
  91869. + unsigned ch12:1;
  91870. + unsigned ch13:1;
  91871. + unsigned ch14:1;
  91872. + unsigned ch15:1;
  91873. + unsigned reserved:16;
  91874. + } b;
  91875. +
  91876. + struct {
  91877. + unsigned chint:16;
  91878. + unsigned reserved:16;
  91879. + } b2;
  91880. +} haintmsk_data_t;
  91881. +
  91882. +/**
  91883. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  91884. + */
  91885. +typedef struct dwc_otg_hc_regs {
  91886. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  91887. + volatile uint32_t hcchar;
  91888. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  91889. + volatile uint32_t hcsplt;
  91890. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  91891. + volatile uint32_t hcint;
  91892. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  91893. + volatile uint32_t hcintmsk;
  91894. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  91895. + volatile uint32_t hctsiz;
  91896. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  91897. + volatile uint32_t hcdma;
  91898. + volatile uint32_t reserved;
  91899. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  91900. + volatile uint32_t hcdmab;
  91901. +} dwc_otg_hc_regs_t;
  91902. +
  91903. +/**
  91904. + * This union represents the bit fields in the Host Channel Characteristics
  91905. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91906. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91907. + * hcchar register.
  91908. + */
  91909. +typedef union hcchar_data {
  91910. + /** raw register data */
  91911. + uint32_t d32;
  91912. +
  91913. + /** register bits */
  91914. + struct {
  91915. + /** Maximum packet size in bytes */
  91916. + unsigned mps:11;
  91917. +
  91918. + /** Endpoint number */
  91919. + unsigned epnum:4;
  91920. +
  91921. + /** 0: OUT, 1: IN */
  91922. + unsigned epdir:1;
  91923. +
  91924. + unsigned reserved:1;
  91925. +
  91926. + /** 0: Full/high speed device, 1: Low speed device */
  91927. + unsigned lspddev:1;
  91928. +
  91929. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  91930. + unsigned eptype:2;
  91931. +
  91932. + /** Packets per frame for periodic transfers. 0 is reserved. */
  91933. + unsigned multicnt:2;
  91934. +
  91935. + /** Device address */
  91936. + unsigned devaddr:7;
  91937. +
  91938. + /**
  91939. + * Frame to transmit periodic transaction.
  91940. + * 0: even, 1: odd
  91941. + */
  91942. + unsigned oddfrm:1;
  91943. +
  91944. + /** Channel disable */
  91945. + unsigned chdis:1;
  91946. +
  91947. + /** Channel enable */
  91948. + unsigned chen:1;
  91949. + } b;
  91950. +} hcchar_data_t;
  91951. +
  91952. +typedef union hcsplt_data {
  91953. + /** raw register data */
  91954. + uint32_t d32;
  91955. +
  91956. + /** register bits */
  91957. + struct {
  91958. + /** Port Address */
  91959. + unsigned prtaddr:7;
  91960. +
  91961. + /** Hub Address */
  91962. + unsigned hubaddr:7;
  91963. +
  91964. + /** Transaction Position */
  91965. + unsigned xactpos:2;
  91966. +#define DWC_HCSPLIT_XACTPOS_MID 0
  91967. +#define DWC_HCSPLIT_XACTPOS_END 1
  91968. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  91969. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  91970. +
  91971. + /** Do Complete Split */
  91972. + unsigned compsplt:1;
  91973. +
  91974. + /** Reserved */
  91975. + unsigned reserved:14;
  91976. +
  91977. + /** Split Enble */
  91978. + unsigned spltena:1;
  91979. + } b;
  91980. +} hcsplt_data_t;
  91981. +
  91982. +/**
  91983. + * This union represents the bit fields in the Host All Interrupt
  91984. + * Register.
  91985. + */
  91986. +typedef union hcint_data {
  91987. + /** raw register data */
  91988. + uint32_t d32;
  91989. + /** register bits */
  91990. + struct {
  91991. + /** Transfer Complete */
  91992. + unsigned xfercomp:1;
  91993. + /** Channel Halted */
  91994. + unsigned chhltd:1;
  91995. + /** AHB Error */
  91996. + unsigned ahberr:1;
  91997. + /** STALL Response Received */
  91998. + unsigned stall:1;
  91999. + /** NAK Response Received */
  92000. + unsigned nak:1;
  92001. + /** ACK Response Received */
  92002. + unsigned ack:1;
  92003. + /** NYET Response Received */
  92004. + unsigned nyet:1;
  92005. + /** Transaction Err */
  92006. + unsigned xacterr:1;
  92007. + /** Babble Error */
  92008. + unsigned bblerr:1;
  92009. + /** Frame Overrun */
  92010. + unsigned frmovrun:1;
  92011. + /** Data Toggle Error */
  92012. + unsigned datatglerr:1;
  92013. + /** Buffer Not Available (only for DDMA mode) */
  92014. + unsigned bna:1;
  92015. + /** Exessive transaction error (only for DDMA mode) */
  92016. + unsigned xcs_xact:1;
  92017. + /** Frame List Rollover interrupt */
  92018. + unsigned frm_list_roll:1;
  92019. + /** Reserved */
  92020. + unsigned reserved14_31:18;
  92021. + } b;
  92022. +} hcint_data_t;
  92023. +
  92024. +/**
  92025. + * This union represents the bit fields in the Host Channel Interrupt Mask
  92026. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92027. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  92028. + * hcintmsk register.
  92029. + */
  92030. +typedef union hcintmsk_data {
  92031. + /** raw register data */
  92032. + uint32_t d32;
  92033. +
  92034. + /** register bits */
  92035. + struct {
  92036. + unsigned xfercompl:1;
  92037. + unsigned chhltd:1;
  92038. + unsigned ahberr:1;
  92039. + unsigned stall:1;
  92040. + unsigned nak:1;
  92041. + unsigned ack:1;
  92042. + unsigned nyet:1;
  92043. + unsigned xacterr:1;
  92044. + unsigned bblerr:1;
  92045. + unsigned frmovrun:1;
  92046. + unsigned datatglerr:1;
  92047. + unsigned bna:1;
  92048. + unsigned xcs_xact:1;
  92049. + unsigned frm_list_roll:1;
  92050. + unsigned reserved14_31:18;
  92051. + } b;
  92052. +} hcintmsk_data_t;
  92053. +
  92054. +/**
  92055. + * This union represents the bit fields in the Host Channel Transfer Size
  92056. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92057. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  92058. + * hcchar register.
  92059. + */
  92060. +
  92061. +typedef union hctsiz_data {
  92062. + /** raw register data */
  92063. + uint32_t d32;
  92064. +
  92065. + /** register bits */
  92066. + struct {
  92067. + /** Total transfer size in bytes */
  92068. + unsigned xfersize:19;
  92069. +
  92070. + /** Data packets to transfer */
  92071. + unsigned pktcnt:10;
  92072. +
  92073. + /**
  92074. + * Packet ID for next data packet
  92075. + * 0: DATA0
  92076. + * 1: DATA2
  92077. + * 2: DATA1
  92078. + * 3: MDATA (non-Control), SETUP (Control)
  92079. + */
  92080. + unsigned pid:2;
  92081. +#define DWC_HCTSIZ_DATA0 0
  92082. +#define DWC_HCTSIZ_DATA1 2
  92083. +#define DWC_HCTSIZ_DATA2 1
  92084. +#define DWC_HCTSIZ_MDATA 3
  92085. +#define DWC_HCTSIZ_SETUP 3
  92086. +
  92087. + /** Do PING protocol when 1 */
  92088. + unsigned dopng:1;
  92089. + } b;
  92090. +
  92091. + /** register bits */
  92092. + struct {
  92093. + /** Scheduling information */
  92094. + unsigned schinfo:8;
  92095. +
  92096. + /** Number of transfer descriptors.
  92097. + * Max value:
  92098. + * 64 in general,
  92099. + * 256 only for HS isochronous endpoint.
  92100. + */
  92101. + unsigned ntd:8;
  92102. +
  92103. + /** Data packets to transfer */
  92104. + unsigned reserved16_28:13;
  92105. +
  92106. + /**
  92107. + * Packet ID for next data packet
  92108. + * 0: DATA0
  92109. + * 1: DATA2
  92110. + * 2: DATA1
  92111. + * 3: MDATA (non-Control)
  92112. + */
  92113. + unsigned pid:2;
  92114. +
  92115. + /** Do PING protocol when 1 */
  92116. + unsigned dopng:1;
  92117. + } b_ddma;
  92118. +} hctsiz_data_t;
  92119. +
  92120. +/**
  92121. + * This union represents the bit fields in the Host DMA Address
  92122. + * Register used in Descriptor DMA mode.
  92123. + */
  92124. +typedef union hcdma_data {
  92125. + /** raw register data */
  92126. + uint32_t d32;
  92127. + /** register bits */
  92128. + struct {
  92129. + unsigned reserved0_2:3;
  92130. + /** Current Transfer Descriptor. Not used for ISOC */
  92131. + unsigned ctd:8;
  92132. + /** Start Address of Descriptor List */
  92133. + unsigned dma_addr:21;
  92134. + } b;
  92135. +} hcdma_data_t;
  92136. +
  92137. +/**
  92138. + * This union represents the bit fields in the DMA Descriptor
  92139. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  92140. + * set/clear the bits using the <i>b</i>it elements.
  92141. + */
  92142. +typedef union host_dma_desc_sts {
  92143. + /** raw register data */
  92144. + uint32_t d32;
  92145. + /** quadlet bits */
  92146. +
  92147. + /* for non-isochronous */
  92148. + struct {
  92149. + /** Number of bytes */
  92150. + unsigned n_bytes:17;
  92151. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  92152. + unsigned qtd_offset:6;
  92153. + /**
  92154. + * Set to request the core to jump to alternate QTD if
  92155. + * Short Packet received - only for IN EPs
  92156. + */
  92157. + unsigned a_qtd:1;
  92158. + /**
  92159. + * Setup Packet bit. When set indicates that buffer contains
  92160. + * setup packet.
  92161. + */
  92162. + unsigned sup:1;
  92163. + /** Interrupt On Complete */
  92164. + unsigned ioc:1;
  92165. + /** End of List */
  92166. + unsigned eol:1;
  92167. + unsigned reserved27:1;
  92168. + /** Rx/Tx Status */
  92169. + unsigned sts:2;
  92170. +#define DMA_DESC_STS_PKTERR 1
  92171. + unsigned reserved30:1;
  92172. + /** Active Bit */
  92173. + unsigned a:1;
  92174. + } b;
  92175. + /* for isochronous */
  92176. + struct {
  92177. + /** Number of bytes */
  92178. + unsigned n_bytes:12;
  92179. + unsigned reserved12_24:13;
  92180. + /** Interrupt On Complete */
  92181. + unsigned ioc:1;
  92182. + unsigned reserved26_27:2;
  92183. + /** Rx/Tx Status */
  92184. + unsigned sts:2;
  92185. + unsigned reserved30:1;
  92186. + /** Active Bit */
  92187. + unsigned a:1;
  92188. + } b_isoc;
  92189. +} host_dma_desc_sts_t;
  92190. +
  92191. +#define MAX_DMA_DESC_SIZE 131071
  92192. +#define MAX_DMA_DESC_NUM_GENERIC 64
  92193. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  92194. +#define MAX_FRLIST_EN_NUM 64
  92195. +/**
  92196. + * Host-mode DMA Descriptor structure
  92197. + *
  92198. + * DMA Descriptor structure contains two quadlets:
  92199. + * Status quadlet and Data buffer pointer.
  92200. + */
  92201. +typedef struct dwc_otg_host_dma_desc {
  92202. + /** DMA Descriptor status quadlet */
  92203. + host_dma_desc_sts_t status;
  92204. + /** DMA Descriptor data buffer pointer */
  92205. + uint32_t buf;
  92206. +} dwc_otg_host_dma_desc_t;
  92207. +
  92208. +/** OTG Host Interface Structure.
  92209. + *
  92210. + * The OTG Host Interface Structure structure contains information
  92211. + * needed to manage the DWC_otg controller acting in host mode. It
  92212. + * represents the programming view of the host-specific aspects of the
  92213. + * controller.
  92214. + */
  92215. +typedef struct dwc_otg_host_if {
  92216. + /** Host Global Registers starting at offset 400h.*/
  92217. + dwc_otg_host_global_regs_t *host_global_regs;
  92218. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  92219. +
  92220. + /** Host Port 0 Control and Status Register */
  92221. + volatile uint32_t *hprt0;
  92222. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  92223. +
  92224. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  92225. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  92226. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  92227. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  92228. +
  92229. + /* Host configuration information */
  92230. + /** Number of Host Channels (range: 1-16) */
  92231. + uint8_t num_host_channels;
  92232. + /** Periodic EPs supported (0: no, 1: yes) */
  92233. + uint8_t perio_eps_supported;
  92234. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  92235. + uint16_t perio_tx_fifo_size;
  92236. +
  92237. +} dwc_otg_host_if_t;
  92238. +
  92239. +/**
  92240. + * This union represents the bit fields in the Power and Clock Gating Control
  92241. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92242. + * bits using the <i>b</i>it elements.
  92243. + */
  92244. +typedef union pcgcctl_data {
  92245. + /** raw register data */
  92246. + uint32_t d32;
  92247. +
  92248. + /** register bits */
  92249. + struct {
  92250. + /** Stop Pclk */
  92251. + unsigned stoppclk:1;
  92252. + /** Gate Hclk */
  92253. + unsigned gatehclk:1;
  92254. + /** Power Clamp */
  92255. + unsigned pwrclmp:1;
  92256. + /** Reset Power Down Modules */
  92257. + unsigned rstpdwnmodule:1;
  92258. + /** Reserved */
  92259. + unsigned reserved:1;
  92260. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  92261. + unsigned enbl_sleep_gating:1;
  92262. + /** PHY In Sleep (PhySleep) */
  92263. + unsigned phy_in_sleep:1;
  92264. + /** Deep Sleep*/
  92265. + unsigned deep_sleep:1;
  92266. + unsigned resetaftsusp:1;
  92267. + unsigned restoremode:1;
  92268. + unsigned enbl_extnd_hiber:1;
  92269. + unsigned extnd_hiber_pwrclmp:1;
  92270. + unsigned extnd_hiber_switch:1;
  92271. + unsigned ess_reg_restored:1;
  92272. + unsigned prt_clk_sel:2;
  92273. + unsigned port_power:1;
  92274. + unsigned max_xcvrselect:2;
  92275. + unsigned max_termsel:1;
  92276. + unsigned mac_dev_addr:7;
  92277. + unsigned p2hd_dev_enum_spd:2;
  92278. + unsigned p2hd_prt_spd:2;
  92279. + unsigned if_dev_mode:1;
  92280. + } b;
  92281. +} pcgcctl_data_t;
  92282. +
  92283. +/**
  92284. + * This union represents the bit fields in the Global Data FIFO Software
  92285. + * Configuration Register. Read the register into the <i>d32</i> member then
  92286. + * set/clear the bits using the <i>b</i>it elements.
  92287. + */
  92288. +typedef union gdfifocfg_data {
  92289. + /* raw register data */
  92290. + uint32_t d32;
  92291. + /** register bits */
  92292. + struct {
  92293. + /** OTG Data FIFO depth */
  92294. + unsigned gdfifocfg:16;
  92295. + /** Start address of EP info controller */
  92296. + unsigned epinfobase:16;
  92297. + } b;
  92298. +} gdfifocfg_data_t;
  92299. +
  92300. +/**
  92301. + * This union represents the bit fields in the Global Power Down Register
  92302. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92303. + * bits using the <i>b</i>it elements.
  92304. + */
  92305. +typedef union gpwrdn_data {
  92306. + /* raw register data */
  92307. + uint32_t d32;
  92308. +
  92309. + /** register bits */
  92310. + struct {
  92311. + /** PMU Interrupt Select */
  92312. + unsigned pmuintsel:1;
  92313. + /** PMU Active */
  92314. + unsigned pmuactv:1;
  92315. + /** Restore */
  92316. + unsigned restore:1;
  92317. + /** Power Down Clamp */
  92318. + unsigned pwrdnclmp:1;
  92319. + /** Power Down Reset */
  92320. + unsigned pwrdnrstn:1;
  92321. + /** Power Down Switch */
  92322. + unsigned pwrdnswtch:1;
  92323. + /** Disable VBUS */
  92324. + unsigned dis_vbus:1;
  92325. + /** Line State Change */
  92326. + unsigned lnstschng:1;
  92327. + /** Line state change mask */
  92328. + unsigned lnstchng_msk:1;
  92329. + /** Reset Detected */
  92330. + unsigned rst_det:1;
  92331. + /** Reset Detect mask */
  92332. + unsigned rst_det_msk:1;
  92333. + /** Disconnect Detected */
  92334. + unsigned disconn_det:1;
  92335. + /** Disconnect Detect mask */
  92336. + unsigned disconn_det_msk:1;
  92337. + /** Connect Detected*/
  92338. + unsigned connect_det:1;
  92339. + /** Connect Detected Mask*/
  92340. + unsigned connect_det_msk:1;
  92341. + /** SRP Detected */
  92342. + unsigned srp_det:1;
  92343. + /** SRP Detect mask */
  92344. + unsigned srp_det_msk:1;
  92345. + /** Status Change Interrupt */
  92346. + unsigned sts_chngint:1;
  92347. + /** Status Change Interrupt Mask */
  92348. + unsigned sts_chngint_msk:1;
  92349. + /** Line State */
  92350. + unsigned linestate:2;
  92351. + /** Indicates current mode(status of IDDIG signal) */
  92352. + unsigned idsts:1;
  92353. + /** B Session Valid signal status*/
  92354. + unsigned bsessvld:1;
  92355. + /** ADP Event Detected */
  92356. + unsigned adp_int:1;
  92357. + /** Multi Valued ID pin */
  92358. + unsigned mult_val_id_bc:5;
  92359. + /** Reserved 24_31 */
  92360. + unsigned reserved29_31:3;
  92361. + } b;
  92362. +} gpwrdn_data_t;
  92363. +
  92364. +#endif
  92365. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/Makefile linux-raspberry-pi/drivers/usb/host/dwc_otg/Makefile
  92366. --- linux-3.10.33/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  92367. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/Makefile 2014-03-13 12:46:39.512097981 +0100
  92368. @@ -0,0 +1,81 @@
  92369. +#
  92370. +# Makefile for DWC_otg Highspeed USB controller driver
  92371. +#
  92372. +
  92373. +ifneq ($(KERNELRELEASE),)
  92374. +
  92375. +# Use the BUS_INTERFACE variable to compile the software for either
  92376. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  92377. +ifeq ($(BUS_INTERFACE),)
  92378. +# BUS_INTERFACE = -DPCI_INTERFACE
  92379. +# BUS_INTERFACE = -DLM_INTERFACE
  92380. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  92381. +endif
  92382. +
  92383. +#ccflags-y += -DDEBUG
  92384. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  92385. +
  92386. +# Use one of the following flags to compile the software in host-only or
  92387. +# device-only mode.
  92388. +#ccflags-y += -DDWC_HOST_ONLY
  92389. +#ccflags-y += -DDWC_DEVICE_ONLY
  92390. +
  92391. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  92392. +#ccflags-y += -DDWC_EN_ISOC
  92393. +ccflags-y += -I$(obj)/../dwc_common_port
  92394. +#ccflags-y += -I$(PORTLIB)
  92395. +ccflags-y += -DDWC_LINUX
  92396. +ccflags-y += $(CFI)
  92397. +ccflags-y += $(BUS_INTERFACE)
  92398. +#ccflags-y += -DDWC_DEV_SRPCAP
  92399. +
  92400. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  92401. +
  92402. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  92403. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  92404. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  92405. +dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_linux.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o dwc_otg_hcd_ddma.o
  92406. +dwc_otg-objs += dwc_otg_adp.o
  92407. +dwc_otg-objs += dwc_otg_mphi_fix.o
  92408. +ifneq ($(CFI),)
  92409. +dwc_otg-objs += dwc_otg_cfi.o
  92410. +endif
  92411. +
  92412. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  92413. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  92414. +
  92415. +ifneq ($(kernrel3),2.6.20)
  92416. +ccflags-y += $(CPPFLAGS)
  92417. +endif
  92418. +
  92419. +else
  92420. +
  92421. +PWD := $(shell pwd)
  92422. +PORTLIB := $(PWD)/../dwc_common_port
  92423. +
  92424. +# Command paths
  92425. +CTAGS := $(CTAGS)
  92426. +DOXYGEN := $(DOXYGEN)
  92427. +
  92428. +default: portlib
  92429. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  92430. +
  92431. +install: default
  92432. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  92433. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  92434. +
  92435. +portlib:
  92436. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  92437. + cp $(PORTLIB)/Module.symvers $(PWD)/
  92438. +
  92439. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  92440. + $(DOXYGEN) doc/doxygen.cfg
  92441. +
  92442. +tags: $(wildcard *.[hc])
  92443. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  92444. +
  92445. +
  92446. +clean:
  92447. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  92448. +
  92449. +endif
  92450. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-raspberry-pi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  92451. --- linux-3.10.33/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  92452. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-03-13 12:46:39.560098077 +0100
  92453. @@ -0,0 +1,337 @@
  92454. +package dwc_otg_test;
  92455. +
  92456. +use strict;
  92457. +use Exporter ();
  92458. +
  92459. +use vars qw(@ISA @EXPORT
  92460. +$sysfsdir $paramdir $errors $params
  92461. +);
  92462. +
  92463. +@ISA = qw(Exporter);
  92464. +
  92465. +#
  92466. +# Globals
  92467. +#
  92468. +$sysfsdir = "/sys/devices/lm0";
  92469. +$paramdir = "/sys/module/dwc_otg";
  92470. +$errors = 0;
  92471. +
  92472. +$params = [
  92473. + {
  92474. + NAME => "otg_cap",
  92475. + DEFAULT => 0,
  92476. + ENUM => [],
  92477. + LOW => 0,
  92478. + HIGH => 2
  92479. + },
  92480. + {
  92481. + NAME => "dma_enable",
  92482. + DEFAULT => 0,
  92483. + ENUM => [],
  92484. + LOW => 0,
  92485. + HIGH => 1
  92486. + },
  92487. + {
  92488. + NAME => "dma_burst_size",
  92489. + DEFAULT => 32,
  92490. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  92491. + LOW => 1,
  92492. + HIGH => 256
  92493. + },
  92494. + {
  92495. + NAME => "host_speed",
  92496. + DEFAULT => 0,
  92497. + ENUM => [],
  92498. + LOW => 0,
  92499. + HIGH => 1
  92500. + },
  92501. + {
  92502. + NAME => "host_support_fs_ls_low_power",
  92503. + DEFAULT => 0,
  92504. + ENUM => [],
  92505. + LOW => 0,
  92506. + HIGH => 1
  92507. + },
  92508. + {
  92509. + NAME => "host_ls_low_power_phy_clk",
  92510. + DEFAULT => 0,
  92511. + ENUM => [],
  92512. + LOW => 0,
  92513. + HIGH => 1
  92514. + },
  92515. + {
  92516. + NAME => "dev_speed",
  92517. + DEFAULT => 0,
  92518. + ENUM => [],
  92519. + LOW => 0,
  92520. + HIGH => 1
  92521. + },
  92522. + {
  92523. + NAME => "enable_dynamic_fifo",
  92524. + DEFAULT => 1,
  92525. + ENUM => [],
  92526. + LOW => 0,
  92527. + HIGH => 1
  92528. + },
  92529. + {
  92530. + NAME => "data_fifo_size",
  92531. + DEFAULT => 8192,
  92532. + ENUM => [],
  92533. + LOW => 32,
  92534. + HIGH => 32768
  92535. + },
  92536. + {
  92537. + NAME => "dev_rx_fifo_size",
  92538. + DEFAULT => 1064,
  92539. + ENUM => [],
  92540. + LOW => 16,
  92541. + HIGH => 32768
  92542. + },
  92543. + {
  92544. + NAME => "dev_nperio_tx_fifo_size",
  92545. + DEFAULT => 1024,
  92546. + ENUM => [],
  92547. + LOW => 16,
  92548. + HIGH => 32768
  92549. + },
  92550. + {
  92551. + NAME => "dev_perio_tx_fifo_size_1",
  92552. + DEFAULT => 256,
  92553. + ENUM => [],
  92554. + LOW => 4,
  92555. + HIGH => 768
  92556. + },
  92557. + {
  92558. + NAME => "dev_perio_tx_fifo_size_2",
  92559. + DEFAULT => 256,
  92560. + ENUM => [],
  92561. + LOW => 4,
  92562. + HIGH => 768
  92563. + },
  92564. + {
  92565. + NAME => "dev_perio_tx_fifo_size_3",
  92566. + DEFAULT => 256,
  92567. + ENUM => [],
  92568. + LOW => 4,
  92569. + HIGH => 768
  92570. + },
  92571. + {
  92572. + NAME => "dev_perio_tx_fifo_size_4",
  92573. + DEFAULT => 256,
  92574. + ENUM => [],
  92575. + LOW => 4,
  92576. + HIGH => 768
  92577. + },
  92578. + {
  92579. + NAME => "dev_perio_tx_fifo_size_5",
  92580. + DEFAULT => 256,
  92581. + ENUM => [],
  92582. + LOW => 4,
  92583. + HIGH => 768
  92584. + },
  92585. + {
  92586. + NAME => "dev_perio_tx_fifo_size_6",
  92587. + DEFAULT => 256,
  92588. + ENUM => [],
  92589. + LOW => 4,
  92590. + HIGH => 768
  92591. + },
  92592. + {
  92593. + NAME => "dev_perio_tx_fifo_size_7",
  92594. + DEFAULT => 256,
  92595. + ENUM => [],
  92596. + LOW => 4,
  92597. + HIGH => 768
  92598. + },
  92599. + {
  92600. + NAME => "dev_perio_tx_fifo_size_8",
  92601. + DEFAULT => 256,
  92602. + ENUM => [],
  92603. + LOW => 4,
  92604. + HIGH => 768
  92605. + },
  92606. + {
  92607. + NAME => "dev_perio_tx_fifo_size_9",
  92608. + DEFAULT => 256,
  92609. + ENUM => [],
  92610. + LOW => 4,
  92611. + HIGH => 768
  92612. + },
  92613. + {
  92614. + NAME => "dev_perio_tx_fifo_size_10",
  92615. + DEFAULT => 256,
  92616. + ENUM => [],
  92617. + LOW => 4,
  92618. + HIGH => 768
  92619. + },
  92620. + {
  92621. + NAME => "dev_perio_tx_fifo_size_11",
  92622. + DEFAULT => 256,
  92623. + ENUM => [],
  92624. + LOW => 4,
  92625. + HIGH => 768
  92626. + },
  92627. + {
  92628. + NAME => "dev_perio_tx_fifo_size_12",
  92629. + DEFAULT => 256,
  92630. + ENUM => [],
  92631. + LOW => 4,
  92632. + HIGH => 768
  92633. + },
  92634. + {
  92635. + NAME => "dev_perio_tx_fifo_size_13",
  92636. + DEFAULT => 256,
  92637. + ENUM => [],
  92638. + LOW => 4,
  92639. + HIGH => 768
  92640. + },
  92641. + {
  92642. + NAME => "dev_perio_tx_fifo_size_14",
  92643. + DEFAULT => 256,
  92644. + ENUM => [],
  92645. + LOW => 4,
  92646. + HIGH => 768
  92647. + },
  92648. + {
  92649. + NAME => "dev_perio_tx_fifo_size_15",
  92650. + DEFAULT => 256,
  92651. + ENUM => [],
  92652. + LOW => 4,
  92653. + HIGH => 768
  92654. + },
  92655. + {
  92656. + NAME => "host_rx_fifo_size",
  92657. + DEFAULT => 1024,
  92658. + ENUM => [],
  92659. + LOW => 16,
  92660. + HIGH => 32768
  92661. + },
  92662. + {
  92663. + NAME => "host_nperio_tx_fifo_size",
  92664. + DEFAULT => 1024,
  92665. + ENUM => [],
  92666. + LOW => 16,
  92667. + HIGH => 32768
  92668. + },
  92669. + {
  92670. + NAME => "host_perio_tx_fifo_size",
  92671. + DEFAULT => 1024,
  92672. + ENUM => [],
  92673. + LOW => 16,
  92674. + HIGH => 32768
  92675. + },
  92676. + {
  92677. + NAME => "max_transfer_size",
  92678. + DEFAULT => 65535,
  92679. + ENUM => [],
  92680. + LOW => 2047,
  92681. + HIGH => 65535
  92682. + },
  92683. + {
  92684. + NAME => "max_packet_count",
  92685. + DEFAULT => 511,
  92686. + ENUM => [],
  92687. + LOW => 15,
  92688. + HIGH => 511
  92689. + },
  92690. + {
  92691. + NAME => "host_channels",
  92692. + DEFAULT => 12,
  92693. + ENUM => [],
  92694. + LOW => 1,
  92695. + HIGH => 16
  92696. + },
  92697. + {
  92698. + NAME => "dev_endpoints",
  92699. + DEFAULT => 6,
  92700. + ENUM => [],
  92701. + LOW => 1,
  92702. + HIGH => 15
  92703. + },
  92704. + {
  92705. + NAME => "phy_type",
  92706. + DEFAULT => 1,
  92707. + ENUM => [],
  92708. + LOW => 0,
  92709. + HIGH => 2
  92710. + },
  92711. + {
  92712. + NAME => "phy_utmi_width",
  92713. + DEFAULT => 16,
  92714. + ENUM => [8, 16],
  92715. + LOW => 8,
  92716. + HIGH => 16
  92717. + },
  92718. + {
  92719. + NAME => "phy_ulpi_ddr",
  92720. + DEFAULT => 0,
  92721. + ENUM => [],
  92722. + LOW => 0,
  92723. + HIGH => 1
  92724. + },
  92725. + ];
  92726. +
  92727. +
  92728. +#
  92729. +#
  92730. +sub check_arch {
  92731. + $_ = `uname -m`;
  92732. + chomp;
  92733. + unless (m/armv4tl/) {
  92734. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  92735. + return 0;
  92736. + }
  92737. + return 1;
  92738. +}
  92739. +
  92740. +#
  92741. +#
  92742. +sub load_module {
  92743. + my $params = shift;
  92744. + print "\nRemoving Module\n";
  92745. + system "rmmod dwc_otg";
  92746. + print "Loading Module\n";
  92747. + if ($params ne "") {
  92748. + print "Module Parameters: $params\n";
  92749. + }
  92750. + if (system("modprobe dwc_otg $params")) {
  92751. + warn "Unable to load module\n";
  92752. + return 0;
  92753. + }
  92754. + return 1;
  92755. +}
  92756. +
  92757. +#
  92758. +#
  92759. +sub test_status {
  92760. + my $arg = shift;
  92761. +
  92762. + print "\n";
  92763. +
  92764. + if (defined $arg) {
  92765. + warn "WARNING: $arg\n";
  92766. + }
  92767. +
  92768. + if ($errors > 0) {
  92769. + warn "TEST FAILED with $errors errors\n";
  92770. + return 0;
  92771. + } else {
  92772. + print "TEST PASSED\n";
  92773. + return 0 if (defined $arg);
  92774. + }
  92775. + return 1;
  92776. +}
  92777. +
  92778. +#
  92779. +#
  92780. +@EXPORT = qw(
  92781. +$sysfsdir
  92782. +$paramdir
  92783. +$params
  92784. +$errors
  92785. +check_arch
  92786. +load_module
  92787. +test_status
  92788. +);
  92789. +
  92790. +1;
  92791. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/test/Makefile linux-raspberry-pi/drivers/usb/host/dwc_otg/test/Makefile
  92792. --- linux-3.10.33/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  92793. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/test/Makefile 2014-03-13 12:46:39.560098077 +0100
  92794. @@ -0,0 +1,16 @@
  92795. +
  92796. +PERL=/usr/bin/perl
  92797. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  92798. +
  92799. +.PHONY : test
  92800. +test : perl_tests
  92801. +
  92802. +perl_tests :
  92803. + @echo
  92804. + @echo Running perl tests
  92805. + @for test in $(PL_TESTS); do \
  92806. + if $(PERL) ./$$test ; then \
  92807. + echo "=======> $$test, PASSED" ; \
  92808. + else echo "=======> $$test, FAILED" ; \
  92809. + fi \
  92810. + done
  92811. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-raspberry-pi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  92812. --- linux-3.10.33/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  92813. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-03-13 12:46:39.560098077 +0100
  92814. @@ -0,0 +1,133 @@
  92815. +#!/usr/bin/perl -w
  92816. +#
  92817. +# Run this program on the integrator.
  92818. +#
  92819. +# - Tests module parameter default values.
  92820. +# - Tests setting of valid module parameter values via modprobe.
  92821. +# - Tests invalid module parameter values.
  92822. +# -----------------------------------------------------------------------------
  92823. +use strict;
  92824. +use dwc_otg_test;
  92825. +
  92826. +check_arch() or die;
  92827. +
  92828. +#
  92829. +#
  92830. +sub test {
  92831. + my ($param,$expected) = @_;
  92832. + my $value = get($param);
  92833. +
  92834. + if ($value == $expected) {
  92835. + print "$param = $value, okay\n";
  92836. + }
  92837. +
  92838. + else {
  92839. + warn "ERROR: value of $param != $expected, $value\n";
  92840. + $errors ++;
  92841. + }
  92842. +}
  92843. +
  92844. +#
  92845. +#
  92846. +sub get {
  92847. + my $param = shift;
  92848. + my $tmp = `cat $paramdir/$param`;
  92849. + chomp $tmp;
  92850. + return $tmp;
  92851. +}
  92852. +
  92853. +#
  92854. +#
  92855. +sub test_main {
  92856. +
  92857. + print "\nTesting Module Parameters\n";
  92858. +
  92859. + load_module("") or die;
  92860. +
  92861. + # Test initial values
  92862. + print "\nTesting Default Values\n";
  92863. + foreach (@{$params}) {
  92864. + test ($_->{NAME}, $_->{DEFAULT});
  92865. + }
  92866. +
  92867. + # Test low value
  92868. + print "\nTesting Low Value\n";
  92869. + my $cmd_params = "";
  92870. + foreach (@{$params}) {
  92871. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  92872. + }
  92873. + load_module($cmd_params) or die;
  92874. +
  92875. + foreach (@{$params}) {
  92876. + test ($_->{NAME}, $_->{LOW});
  92877. + }
  92878. +
  92879. + # Test high value
  92880. + print "\nTesting High Value\n";
  92881. + $cmd_params = "";
  92882. + foreach (@{$params}) {
  92883. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  92884. + }
  92885. + load_module($cmd_params) or die;
  92886. +
  92887. + foreach (@{$params}) {
  92888. + test ($_->{NAME}, $_->{HIGH});
  92889. + }
  92890. +
  92891. + # Test Enum
  92892. + print "\nTesting Enumerated\n";
  92893. + foreach (@{$params}) {
  92894. + if (defined $_->{ENUM}) {
  92895. + my $value;
  92896. + foreach $value (@{$_->{ENUM}}) {
  92897. + $cmd_params = "$_->{NAME}=$value";
  92898. + load_module($cmd_params) or die;
  92899. + test ($_->{NAME}, $value);
  92900. + }
  92901. + }
  92902. + }
  92903. +
  92904. + # Test Invalid Values
  92905. + print "\nTesting Invalid Values\n";
  92906. + $cmd_params = "";
  92907. + foreach (@{$params}) {
  92908. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  92909. + }
  92910. + load_module($cmd_params) or die;
  92911. +
  92912. + foreach (@{$params}) {
  92913. + test ($_->{NAME}, $_->{DEFAULT});
  92914. + }
  92915. +
  92916. + $cmd_params = "";
  92917. + foreach (@{$params}) {
  92918. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  92919. + }
  92920. + load_module($cmd_params) or die;
  92921. +
  92922. + foreach (@{$params}) {
  92923. + test ($_->{NAME}, $_->{DEFAULT});
  92924. + }
  92925. +
  92926. + print "\nTesting Enumerated\n";
  92927. + foreach (@{$params}) {
  92928. + if (defined $_->{ENUM}) {
  92929. + my $value;
  92930. + foreach $value (@{$_->{ENUM}}) {
  92931. + $value = $value + 1;
  92932. + $cmd_params = "$_->{NAME}=$value";
  92933. + load_module($cmd_params) or die;
  92934. + test ($_->{NAME}, $_->{DEFAULT});
  92935. + $value = $value - 2;
  92936. + $cmd_params = "$_->{NAME}=$value";
  92937. + load_module($cmd_params) or die;
  92938. + test ($_->{NAME}, $_->{DEFAULT});
  92939. + }
  92940. + }
  92941. + }
  92942. +
  92943. + test_status() or die;
  92944. +}
  92945. +
  92946. +test_main();
  92947. +0;
  92948. diff -Nur linux-3.10.33/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-raspberry-pi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  92949. --- linux-3.10.33/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  92950. +++ linux-raspberry-pi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-03-13 12:46:39.560098077 +0100
  92951. @@ -0,0 +1,193 @@
  92952. +#!/usr/bin/perl -w
  92953. +#
  92954. +# Run this program on the integrator
  92955. +# - Tests select sysfs attributes.
  92956. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  92957. +# -----------------------------------------------------------------------------
  92958. +use strict;
  92959. +use dwc_otg_test;
  92960. +
  92961. +check_arch() or die;
  92962. +
  92963. +#
  92964. +#
  92965. +sub test {
  92966. + my ($attr,$expected) = @_;
  92967. + my $string = get($attr);
  92968. +
  92969. + if ($string eq $expected) {
  92970. + printf("$attr = $string, okay\n");
  92971. + }
  92972. + else {
  92973. + warn "ERROR: value of $attr != $expected, $string\n";
  92974. + $errors ++;
  92975. + }
  92976. +}
  92977. +
  92978. +#
  92979. +#
  92980. +sub set {
  92981. + my ($reg, $value) = @_;
  92982. + system "echo $value > $sysfsdir/$reg";
  92983. +}
  92984. +
  92985. +#
  92986. +#
  92987. +sub get {
  92988. + my $attr = shift;
  92989. + my $string = `cat $sysfsdir/$attr`;
  92990. + chomp $string;
  92991. + if ($string =~ m/\s\=\s/) {
  92992. + my $tmp;
  92993. + ($tmp, $string) = split /\s=\s/, $string;
  92994. + }
  92995. + return $string;
  92996. +}
  92997. +
  92998. +#
  92999. +#
  93000. +sub test_main {
  93001. + print("\nTesting Sysfs Attributes\n");
  93002. +
  93003. + load_module("") or die;
  93004. +
  93005. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  93006. + print("\nTesting Default Values\n");
  93007. +
  93008. + test("regoffset", "0xffffffff");
  93009. + test("regvalue", "invalid offset");
  93010. + test("guid", "0x12345678"); # this will fail if it has been changed
  93011. + test("gsnpsid", "0x4f54200a");
  93012. +
  93013. + # Test operation of regoffset/regvalue
  93014. + print("\nTesting regoffset\n");
  93015. + set('regoffset', '5a5a5a5a');
  93016. + test("regoffset", "0xffffffff");
  93017. +
  93018. + set('regoffset', '0');
  93019. + test("regoffset", "0x00000000");
  93020. +
  93021. + set('regoffset', '40000');
  93022. + test("regoffset", "0x00000000");
  93023. +
  93024. + set('regoffset', '3ffff');
  93025. + test("regoffset", "0x0003ffff");
  93026. +
  93027. + set('regoffset', '1');
  93028. + test("regoffset", "0x00000001");
  93029. +
  93030. + print("\nTesting regvalue\n");
  93031. + set('regoffset', '3c');
  93032. + test("regvalue", "0x12345678");
  93033. + set('regvalue', '5a5a5a5a');
  93034. + test("regvalue", "0x5a5a5a5a");
  93035. + set('regvalue','a5a5a5a5');
  93036. + test("regvalue", "0xa5a5a5a5");
  93037. + set('guid','12345678');
  93038. +
  93039. + # Test HNP Capable
  93040. + print("\nTesting HNP Capable bit\n");
  93041. + set('hnpcapable', '1');
  93042. + test("hnpcapable", "0x1");
  93043. + set('hnpcapable','0');
  93044. + test("hnpcapable", "0x0");
  93045. +
  93046. + set('regoffset','0c');
  93047. +
  93048. + my $old = get('gusbcfg');
  93049. + print("setting hnpcapable\n");
  93050. + set('hnpcapable', '1');
  93051. + test("hnpcapable", "0x1");
  93052. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  93053. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  93054. +
  93055. + $old = get('gusbcfg');
  93056. + print("clearing hnpcapable\n");
  93057. + set('hnpcapable', '0');
  93058. + test("hnpcapable", "0x0");
  93059. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  93060. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  93061. +
  93062. + # Test SRP Capable
  93063. + print("\nTesting SRP Capable bit\n");
  93064. + set('srpcapable', '1');
  93065. + test("srpcapable", "0x1");
  93066. + set('srpcapable','0');
  93067. + test("srpcapable", "0x0");
  93068. +
  93069. + set('regoffset','0c');
  93070. +
  93071. + $old = get('gusbcfg');
  93072. + print("setting srpcapable\n");
  93073. + set('srpcapable', '1');
  93074. + test("srpcapable", "0x1");
  93075. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  93076. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  93077. +
  93078. + $old = get('gusbcfg');
  93079. + print("clearing srpcapable\n");
  93080. + set('srpcapable', '0');
  93081. + test("srpcapable", "0x0");
  93082. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  93083. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  93084. +
  93085. + # Test GGPIO
  93086. + print("\nTesting GGPIO\n");
  93087. + set('ggpio','5a5a5a5a');
  93088. + test('ggpio','0x5a5a0000');
  93089. + set('ggpio','a5a5a5a5');
  93090. + test('ggpio','0xa5a50000');
  93091. + set('ggpio','11110000');
  93092. + test('ggpio','0x11110000');
  93093. + set('ggpio','00001111');
  93094. + test('ggpio','0x00000000');
  93095. +
  93096. + # Test DEVSPEED
  93097. + print("\nTesting DEVSPEED\n");
  93098. + set('regoffset','800');
  93099. + $old = get('regvalue');
  93100. + set('devspeed','0');
  93101. + test('devspeed','0x0');
  93102. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  93103. + set('devspeed','1');
  93104. + test('devspeed','0x1');
  93105. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  93106. + set('devspeed','2');
  93107. + test('devspeed','0x2');
  93108. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  93109. + set('devspeed','3');
  93110. + test('devspeed','0x3');
  93111. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  93112. + set('devspeed','4');
  93113. + test('devspeed','0x0');
  93114. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  93115. + set('devspeed','5');
  93116. + test('devspeed','0x1');
  93117. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  93118. +
  93119. +
  93120. + # mode Returns the current mode:0 for device mode1 for host mode Read
  93121. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  93122. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  93123. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  93124. + # bussuspend Suspend the USB bus. Read/Write
  93125. + # busconnected Get the connection status of the bus Read
  93126. +
  93127. + # gotgctl Get or set the Core Control Status Register. Read/Write
  93128. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  93129. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  93130. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  93131. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  93132. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  93133. + ## guid Get or set the value of the User ID Register Read/Write
  93134. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  93135. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  93136. + # enumspeed Gets the device enumeration Speed. Read
  93137. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  93138. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  93139. +
  93140. + test_status("TEST NYI") or die;
  93141. +}
  93142. +
  93143. +test_main();
  93144. +0;
  93145. diff -Nur linux-3.10.33/drivers/usb/host/Kconfig linux-raspberry-pi/drivers/usb/host/Kconfig
  93146. --- linux-3.10.33/drivers/usb/host/Kconfig 2014-03-07 06:58:45.000000000 +0100
  93147. +++ linux-raspberry-pi/drivers/usb/host/Kconfig 2014-03-13 12:46:38.980096914 +0100
  93148. @@ -663,6 +663,19 @@
  93149. To compile this driver a module, choose M here: the module
  93150. will be called "hwa-hc".
  93151. +config USB_DWCOTG
  93152. + tristate "Synopsis DWC host support"
  93153. + depends on USB
  93154. + help
  93155. + The Synopsis DWC controller is a dual-role
  93156. + host/peripheral/OTG ("On The Go") USB controllers.
  93157. +
  93158. + Enable this option to support this IP in host controller mode.
  93159. + If unsure, say N.
  93160. +
  93161. + To compile this driver as a module, choose M here: the
  93162. + modules built will be called dwc_otg and dwc_common_port.
  93163. +
  93164. config USB_IMX21_HCD
  93165. tristate "i.MX21 HCD support"
  93166. depends on ARM && ARCH_MXC
  93167. diff -Nur linux-3.10.33/drivers/usb/host/Makefile linux-raspberry-pi/drivers/usb/host/Makefile
  93168. --- linux-3.10.33/drivers/usb/host/Makefile 2014-03-07 06:58:45.000000000 +0100
  93169. +++ linux-raspberry-pi/drivers/usb/host/Makefile 2014-03-13 12:46:38.980096914 +0100
  93170. @@ -47,6 +47,8 @@
  93171. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  93172. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  93173. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  93174. +
  93175. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  93176. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  93177. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  93178. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  93179. diff -Nur linux-3.10.33/drivers/usb/Makefile linux-raspberry-pi/drivers/usb/Makefile
  93180. --- linux-3.10.33/drivers/usb/Makefile 2014-03-07 06:58:45.000000000 +0100
  93181. +++ linux-raspberry-pi/drivers/usb/Makefile 2014-03-13 12:46:38.904096761 +0100
  93182. @@ -23,6 +23,7 @@
  93183. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  93184. obj-$(CONFIG_USB_HWA_HCD) += host/
  93185. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  93186. +obj-$(CONFIG_USB_DWCOTG) += host/
  93187. obj-$(CONFIG_USB_IMX21_HCD) += host/
  93188. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  93189. diff -Nur linux-3.10.33/drivers/video/bcm2708_fb.c linux-raspberry-pi/drivers/video/bcm2708_fb.c
  93190. --- linux-3.10.33/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  93191. +++ linux-raspberry-pi/drivers/video/bcm2708_fb.c 2014-03-13 12:46:40.304099570 +0100
  93192. @@ -0,0 +1,763 @@
  93193. +/*
  93194. + * linux/drivers/video/bcm2708_fb.c
  93195. + *
  93196. + * Copyright (C) 2010 Broadcom
  93197. + *
  93198. + * This file is subject to the terms and conditions of the GNU General Public
  93199. + * License. See the file COPYING in the main directory of this archive
  93200. + * for more details.
  93201. + *
  93202. + * Broadcom simple framebuffer driver
  93203. + *
  93204. + * This file is derived from cirrusfb.c
  93205. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  93206. + *
  93207. + */
  93208. +#include <linux/module.h>
  93209. +#include <linux/kernel.h>
  93210. +#include <linux/errno.h>
  93211. +#include <linux/string.h>
  93212. +#include <linux/slab.h>
  93213. +#include <linux/mm.h>
  93214. +#include <linux/fb.h>
  93215. +#include <linux/init.h>
  93216. +#include <linux/interrupt.h>
  93217. +#include <linux/ioport.h>
  93218. +#include <linux/list.h>
  93219. +#include <linux/platform_device.h>
  93220. +#include <linux/clk.h>
  93221. +#include <linux/printk.h>
  93222. +#include <linux/console.h>
  93223. +#include <linux/debugfs.h>
  93224. +
  93225. +#include <mach/dma.h>
  93226. +#include <mach/platform.h>
  93227. +#include <mach/vcio.h>
  93228. +
  93229. +#include <asm/sizes.h>
  93230. +#include <linux/io.h>
  93231. +#include <linux/dma-mapping.h>
  93232. +
  93233. +#ifdef BCM2708_FB_DEBUG
  93234. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  93235. +#else
  93236. +#define print_debug(fmt,...)
  93237. +#endif
  93238. +
  93239. +/* This is limited to 16 characters when displayed by X startup */
  93240. +static const char *bcm2708_name = "BCM2708 FB";
  93241. +
  93242. +#define DRIVER_NAME "bcm2708_fb"
  93243. +
  93244. +static u32 dma_busy_wait_threshold = 1<<15;
  93245. +module_param(dma_busy_wait_threshold, int, 0644);
  93246. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  93247. +
  93248. +static int fbswap = 0; /* module parameter */
  93249. +
  93250. +/* this data structure describes each frame buffer device we find */
  93251. +
  93252. +struct fbinfo_s {
  93253. + u32 xres, yres, xres_virtual, yres_virtual;
  93254. + u32 pitch, bpp;
  93255. + u32 xoffset, yoffset;
  93256. + u32 base;
  93257. + u32 screen_size;
  93258. + u16 cmap[256];
  93259. +};
  93260. +
  93261. +struct bcm2708_fb_stats {
  93262. + struct debugfs_regset32 regset;
  93263. + u32 dma_copies;
  93264. + u32 dma_irqs;
  93265. +};
  93266. +
  93267. +struct bcm2708_fb {
  93268. + struct fb_info fb;
  93269. + struct platform_device *dev;
  93270. + struct fbinfo_s *info;
  93271. + dma_addr_t dma;
  93272. + u32 cmap[16];
  93273. + int dma_chan;
  93274. + int dma_irq;
  93275. + void __iomem *dma_chan_base;
  93276. + void *cb_base; /* DMA control blocks */
  93277. + dma_addr_t cb_handle;
  93278. + struct dentry *debugfs_dir;
  93279. + wait_queue_head_t dma_waitq;
  93280. + struct bcm2708_fb_stats stats;
  93281. +};
  93282. +
  93283. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  93284. +
  93285. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  93286. +{
  93287. + debugfs_remove_recursive(fb->debugfs_dir);
  93288. + fb->debugfs_dir = NULL;
  93289. +}
  93290. +
  93291. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  93292. +{
  93293. + static struct debugfs_reg32 stats_registers[] = {
  93294. + {
  93295. + "dma_copies",
  93296. + offsetof(struct bcm2708_fb_stats, dma_copies)
  93297. + },
  93298. + {
  93299. + "dma_irqs",
  93300. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  93301. + },
  93302. + };
  93303. +
  93304. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  93305. + if (!fb->debugfs_dir) {
  93306. + pr_warn("%s: could not create debugfs entry\n",
  93307. + __func__);
  93308. + return -EFAULT;
  93309. + }
  93310. +
  93311. + fb->stats.regset.regs = stats_registers;
  93312. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  93313. + fb->stats.regset.base = &fb->stats;
  93314. +
  93315. + if (!debugfs_create_regset32(
  93316. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  93317. + pr_warn("%s: could not create statistics registers\n",
  93318. + __func__);
  93319. + goto fail;
  93320. + }
  93321. + return 0;
  93322. +
  93323. +fail:
  93324. + bcm2708_fb_debugfs_deinit(fb);
  93325. + return -EFAULT;
  93326. +}
  93327. +
  93328. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  93329. +{
  93330. + int ret = 0;
  93331. +
  93332. + memset(&var->transp, 0, sizeof(var->transp));
  93333. +
  93334. + var->red.msb_right = 0;
  93335. + var->green.msb_right = 0;
  93336. + var->blue.msb_right = 0;
  93337. +
  93338. + switch (var->bits_per_pixel) {
  93339. + case 1:
  93340. + case 2:
  93341. + case 4:
  93342. + case 8:
  93343. + var->red.length = var->bits_per_pixel;
  93344. + var->red.offset = 0;
  93345. + var->green.length = var->bits_per_pixel;
  93346. + var->green.offset = 0;
  93347. + var->blue.length = var->bits_per_pixel;
  93348. + var->blue.offset = 0;
  93349. + break;
  93350. + case 16:
  93351. + var->red.length = 5;
  93352. + var->blue.length = 5;
  93353. + /*
  93354. + * Green length can be 5 or 6 depending whether
  93355. + * we're operating in RGB555 or RGB565 mode.
  93356. + */
  93357. + if (var->green.length != 5 && var->green.length != 6)
  93358. + var->green.length = 6;
  93359. + break;
  93360. + case 24:
  93361. + var->red.length = 8;
  93362. + var->blue.length = 8;
  93363. + var->green.length = 8;
  93364. + break;
  93365. + case 32:
  93366. + var->red.length = 8;
  93367. + var->green.length = 8;
  93368. + var->blue.length = 8;
  93369. + var->transp.length = 8;
  93370. + break;
  93371. + default:
  93372. + ret = -EINVAL;
  93373. + break;
  93374. + }
  93375. +
  93376. + /*
  93377. + * >= 16bpp displays have separate colour component bitfields
  93378. + * encoded in the pixel data. Calculate their position from
  93379. + * the bitfield length defined above.
  93380. + */
  93381. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  93382. + var->blue.offset = 0;
  93383. + var->green.offset = var->blue.offset + var->blue.length;
  93384. + var->red.offset = var->green.offset + var->green.length;
  93385. + var->transp.offset = var->red.offset + var->red.length;
  93386. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  93387. + var->red.offset = 0;
  93388. + var->green.offset = var->red.offset + var->red.length;
  93389. + var->blue.offset = var->green.offset + var->green.length;
  93390. + var->transp.offset = var->blue.offset + var->blue.length;
  93391. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  93392. + var->blue.offset = 0;
  93393. + var->green.offset = var->blue.offset + var->blue.length;
  93394. + var->red.offset = var->green.offset + var->green.length;
  93395. + var->transp.offset = var->red.offset + var->red.length;
  93396. + }
  93397. +
  93398. + return ret;
  93399. +}
  93400. +
  93401. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  93402. + struct fb_info *info)
  93403. +{
  93404. + /* info input, var output */
  93405. + int yres;
  93406. +
  93407. + /* info input, var output */
  93408. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  93409. + info->var.xres, info->var.yres, info->var.xres_virtual,
  93410. + info->var.yres_virtual, (int)info->screen_size,
  93411. + info->var.bits_per_pixel);
  93412. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  93413. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  93414. + var->bits_per_pixel);
  93415. +
  93416. + if (!var->bits_per_pixel)
  93417. + var->bits_per_pixel = 16;
  93418. +
  93419. + if (bcm2708_fb_set_bitfields(var) != 0) {
  93420. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  93421. + var->bits_per_pixel);
  93422. + return -EINVAL;
  93423. + }
  93424. +
  93425. +
  93426. + if (var->xres_virtual < var->xres)
  93427. + var->xres_virtual = var->xres;
  93428. + /* use highest possible virtual resolution */
  93429. + if (var->yres_virtual == -1) {
  93430. + var->yres_virtual = 480;
  93431. +
  93432. + pr_err
  93433. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  93434. + var->xres_virtual, var->yres_virtual);
  93435. + }
  93436. + if (var->yres_virtual < var->yres)
  93437. + var->yres_virtual = var->yres;
  93438. +
  93439. + if (var->xoffset < 0)
  93440. + var->xoffset = 0;
  93441. + if (var->yoffset < 0)
  93442. + var->yoffset = 0;
  93443. +
  93444. + /* truncate xoffset and yoffset to maximum if too high */
  93445. + if (var->xoffset > var->xres_virtual - var->xres)
  93446. + var->xoffset = var->xres_virtual - var->xres - 1;
  93447. + if (var->yoffset > var->yres_virtual - var->yres)
  93448. + var->yoffset = var->yres_virtual - var->yres - 1;
  93449. +
  93450. + yres = var->yres;
  93451. + if (var->vmode & FB_VMODE_DOUBLE)
  93452. + yres *= 2;
  93453. + else if (var->vmode & FB_VMODE_INTERLACED)
  93454. + yres = (yres + 1) / 2;
  93455. +
  93456. + if (var->xres * yres > 1920 * 1200) {
  93457. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  93458. + "special treatment required! (TODO)\n");
  93459. + return -EINVAL;
  93460. + }
  93461. +
  93462. + return 0;
  93463. +}
  93464. +
  93465. +static int bcm2708_fb_set_par(struct fb_info *info)
  93466. +{
  93467. + uint32_t val = 0;
  93468. + struct bcm2708_fb *fb = to_bcm2708(info);
  93469. + volatile struct fbinfo_s *fbinfo = fb->info;
  93470. + fbinfo->xres = info->var.xres;
  93471. + fbinfo->yres = info->var.yres;
  93472. + fbinfo->xres_virtual = info->var.xres_virtual;
  93473. + fbinfo->yres_virtual = info->var.yres_virtual;
  93474. + fbinfo->bpp = info->var.bits_per_pixel;
  93475. + fbinfo->xoffset = info->var.xoffset;
  93476. + fbinfo->yoffset = info->var.yoffset;
  93477. + fbinfo->base = 0; /* filled in by VC */
  93478. + fbinfo->pitch = 0; /* filled in by VC */
  93479. +
  93480. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  93481. + info->var.xres, info->var.yres, info->var.xres_virtual,
  93482. + info->var.yres_virtual, (int)info->screen_size,
  93483. + info->var.bits_per_pixel);
  93484. +
  93485. + /* ensure last write to fbinfo is visible to GPU */
  93486. + wmb();
  93487. +
  93488. + /* inform vc about new framebuffer */
  93489. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  93490. +
  93491. + /* TODO: replace fb driver with vchiq version */
  93492. + /* wait for response */
  93493. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  93494. +
  93495. + /* ensure GPU writes are visible to us */
  93496. + rmb();
  93497. +
  93498. + if (val == 0) {
  93499. + fb->fb.fix.line_length = fbinfo->pitch;
  93500. +
  93501. + if (info->var.bits_per_pixel <= 8)
  93502. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  93503. + else
  93504. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  93505. +
  93506. + fb->fb.fix.smem_start = fbinfo->base;
  93507. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  93508. + fb->fb.screen_size = fbinfo->screen_size;
  93509. + if (fb->fb.screen_base)
  93510. + iounmap(fb->fb.screen_base);
  93511. + fb->fb.screen_base =
  93512. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  93513. + if (!fb->fb.screen_base) {
  93514. + /* the console may currently be locked */
  93515. + console_trylock();
  93516. + console_unlock();
  93517. +
  93518. + BUG(); /* what can we do here */
  93519. + }
  93520. + }
  93521. + print_debug
  93522. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  93523. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  93524. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  93525. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  93526. +
  93527. + return val;
  93528. +}
  93529. +
  93530. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  93531. +{
  93532. + unsigned int mask = (1 << bf->length) - 1;
  93533. +
  93534. + return (val >> (16 - bf->length) & mask) << bf->offset;
  93535. +}
  93536. +
  93537. +
  93538. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  93539. + unsigned int green, unsigned int blue,
  93540. + unsigned int transp, struct fb_info *info)
  93541. +{
  93542. + struct bcm2708_fb *fb = to_bcm2708(info);
  93543. +
  93544. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  93545. + if (fb->fb.var.bits_per_pixel <= 8) {
  93546. + if (regno < 256) {
  93547. + /* blue [0:4], green [5:10], red [11:15] */
  93548. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  93549. + ((green >> (16-6)) & 0x3f) << 5 |
  93550. + ((blue >> (16-5)) & 0x1f) << 0;
  93551. + }
  93552. + /* Hack: we need to tell GPU the palette has changed, but currently bcm2708_fb_set_par takes noticable time when called for every (256) colour */
  93553. + /* So just call it for what looks like the last colour in a list for now. */
  93554. + if (regno == 15 || regno == 255)
  93555. + bcm2708_fb_set_par(info);
  93556. + } else if (regno < 16) {
  93557. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  93558. + convert_bitfield(blue, &fb->fb.var.blue) |
  93559. + convert_bitfield(green, &fb->fb.var.green) |
  93560. + convert_bitfield(red, &fb->fb.var.red);
  93561. + }
  93562. + return regno > 255;
  93563. +}
  93564. +
  93565. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  93566. +{
  93567. + /*print_debug("bcm2708_fb_blank\n"); */
  93568. + return -1;
  93569. +}
  93570. +
  93571. +static void bcm2708_fb_fillrect(struct fb_info *info,
  93572. + const struct fb_fillrect *rect)
  93573. +{
  93574. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  93575. + cfb_fillrect(info, rect);
  93576. +}
  93577. +
  93578. +/* A helper function for configuring dma control block */
  93579. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  93580. + int burst_size,
  93581. + dma_addr_t dst,
  93582. + int dst_stride,
  93583. + dma_addr_t src,
  93584. + int src_stride,
  93585. + int w,
  93586. + int h)
  93587. +{
  93588. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  93589. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  93590. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  93591. + cb->dst = dst;
  93592. + cb->src = src;
  93593. + /*
  93594. + * This is not really obvious from the DMA documentation,
  93595. + * but the top 16 bits must be programmmed to "height -1"
  93596. + * and not "height" in 2D mode.
  93597. + */
  93598. + cb->length = ((h - 1) << 16) | w;
  93599. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  93600. + cb->pad[0] = 0;
  93601. + cb->pad[1] = 0;
  93602. +}
  93603. +
  93604. +static void bcm2708_fb_copyarea(struct fb_info *info,
  93605. + const struct fb_copyarea *region)
  93606. +{
  93607. + struct bcm2708_fb *fb = to_bcm2708(info);
  93608. + struct bcm2708_dma_cb *cb = fb->cb_base;
  93609. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  93610. + /* Channel 0 supports larger bursts and is a bit faster */
  93611. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  93612. + int pixels = region->width * region->height;
  93613. +
  93614. + /* Fallback to cfb_copyarea() if we don't like something */
  93615. + if (bytes_per_pixel > 4 ||
  93616. + info->var.xres * info->var.yres > 1920 * 1200 ||
  93617. + region->width <= 0 || region->width > info->var.xres ||
  93618. + region->height <= 0 || region->height > info->var.yres ||
  93619. + region->sx < 0 || region->sx >= info->var.xres ||
  93620. + region->sy < 0 || region->sy >= info->var.yres ||
  93621. + region->dx < 0 || region->dx >= info->var.xres ||
  93622. + region->dy < 0 || region->dy >= info->var.yres ||
  93623. + region->sx + region->width > info->var.xres ||
  93624. + region->dx + region->width > info->var.xres ||
  93625. + region->sy + region->height > info->var.yres ||
  93626. + region->dy + region->height > info->var.yres) {
  93627. + cfb_copyarea(info, region);
  93628. + return;
  93629. + }
  93630. +
  93631. + if (region->dy == region->sy && region->dx > region->sx) {
  93632. + /*
  93633. + * A difficult case of overlapped copy. Because DMA can't
  93634. + * copy individual scanlines in backwards direction, we need
  93635. + * two-pass processing. We do it by programming a chain of dma
  93636. + * control blocks in the first 16K part of the buffer and use
  93637. + * the remaining 48K as the intermediate temporary scratch
  93638. + * buffer. The buffer size is sufficient to handle up to
  93639. + * 1920x1200 resolution at 32bpp pixel depth.
  93640. + */
  93641. + int y;
  93642. + dma_addr_t control_block_pa = fb->cb_handle;
  93643. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  93644. + int scanline_size = bytes_per_pixel * region->width;
  93645. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  93646. +
  93647. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  93648. + dma_addr_t src =
  93649. + fb->fb.fix.smem_start +
  93650. + bytes_per_pixel * region->sx +
  93651. + (region->sy + y) * fb->fb.fix.line_length;
  93652. + dma_addr_t dst =
  93653. + fb->fb.fix.smem_start +
  93654. + bytes_per_pixel * region->dx +
  93655. + (region->dy + y) * fb->fb.fix.line_length;
  93656. +
  93657. + if (region->height - y < scanlines_per_cb)
  93658. + scanlines_per_cb = region->height - y;
  93659. +
  93660. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  93661. + src, fb->fb.fix.line_length,
  93662. + scanline_size, scanlines_per_cb);
  93663. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  93664. + cb->next = control_block_pa;
  93665. + cb++;
  93666. +
  93667. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  93668. + scratchbuf, scanline_size,
  93669. + scanline_size, scanlines_per_cb);
  93670. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  93671. + cb->next = control_block_pa;
  93672. + cb++;
  93673. + }
  93674. + /* move the pointer back to the last dma control block */
  93675. + cb--;
  93676. + } else {
  93677. + /* A single dma control block is enough. */
  93678. + int sy, dy, stride;
  93679. + if (region->dy <= region->sy) {
  93680. + /* processing from top to bottom */
  93681. + dy = region->dy;
  93682. + sy = region->sy;
  93683. + stride = fb->fb.fix.line_length;
  93684. + } else {
  93685. + /* processing from bottom to top */
  93686. + dy = region->dy + region->height - 1;
  93687. + sy = region->sy + region->height - 1;
  93688. + stride = -fb->fb.fix.line_length;
  93689. + }
  93690. + set_dma_cb(cb, burst_size,
  93691. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  93692. + bytes_per_pixel * region->dx,
  93693. + stride,
  93694. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  93695. + bytes_per_pixel * region->sx,
  93696. + stride,
  93697. + region->width * bytes_per_pixel,
  93698. + region->height);
  93699. + }
  93700. +
  93701. + /* end of dma control blocks chain */
  93702. + cb->next = 0;
  93703. +
  93704. +
  93705. + if (pixels < dma_busy_wait_threshold) {
  93706. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  93707. + bcm_dma_wait_idle(fb->dma_chan_base);
  93708. + } else {
  93709. + void __iomem *dma_chan = fb->dma_chan_base;
  93710. + cb->info |= BCM2708_DMA_INT_EN;
  93711. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  93712. + while (bcm_dma_is_busy(dma_chan)) {
  93713. + wait_event_interruptible(
  93714. + fb->dma_waitq,
  93715. + !bcm_dma_is_busy(dma_chan));
  93716. + }
  93717. + fb->stats.dma_irqs++;
  93718. + }
  93719. + fb->stats.dma_copies++;
  93720. +}
  93721. +
  93722. +static void bcm2708_fb_imageblit(struct fb_info *info,
  93723. + const struct fb_image *image)
  93724. +{
  93725. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  93726. + cfb_imageblit(info, image);
  93727. +}
  93728. +
  93729. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  93730. +{
  93731. + struct bcm2708_fb *fb = cxt;
  93732. +
  93733. + /* FIXME: should read status register to check if this is
  93734. + * actually interrupting us or not, in case this interrupt
  93735. + * ever becomes shared amongst several DMA channels
  93736. + *
  93737. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  93738. + */
  93739. +
  93740. + /* acknowledge the interrupt */
  93741. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  93742. +
  93743. + wake_up(&fb->dma_waitq);
  93744. + return IRQ_HANDLED;
  93745. +}
  93746. +
  93747. +static struct fb_ops bcm2708_fb_ops = {
  93748. + .owner = THIS_MODULE,
  93749. + .fb_check_var = bcm2708_fb_check_var,
  93750. + .fb_set_par = bcm2708_fb_set_par,
  93751. + .fb_setcolreg = bcm2708_fb_setcolreg,
  93752. + .fb_blank = bcm2708_fb_blank,
  93753. + .fb_fillrect = bcm2708_fb_fillrect,
  93754. + .fb_copyarea = bcm2708_fb_copyarea,
  93755. + .fb_imageblit = bcm2708_fb_imageblit,
  93756. +};
  93757. +
  93758. +static int fbwidth = 800; /* module parameter */
  93759. +static int fbheight = 480; /* module parameter */
  93760. +static int fbdepth = 16; /* module parameter */
  93761. +
  93762. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  93763. +{
  93764. + int ret;
  93765. + dma_addr_t dma;
  93766. + void *mem;
  93767. +
  93768. + mem =
  93769. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  93770. + GFP_KERNEL);
  93771. +
  93772. + if (NULL == mem) {
  93773. + pr_err(": unable to allocate fbinfo buffer\n");
  93774. + ret = -ENOMEM;
  93775. + } else {
  93776. + fb->info = (struct fbinfo_s *)mem;
  93777. + fb->dma = dma;
  93778. + }
  93779. + fb->fb.fbops = &bcm2708_fb_ops;
  93780. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  93781. + fb->fb.pseudo_palette = fb->cmap;
  93782. +
  93783. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  93784. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  93785. + fb->fb.fix.type_aux = 0;
  93786. + fb->fb.fix.xpanstep = 0;
  93787. + fb->fb.fix.ypanstep = 0;
  93788. + fb->fb.fix.ywrapstep = 0;
  93789. + fb->fb.fix.accel = FB_ACCEL_NONE;
  93790. +
  93791. + fb->fb.var.xres = fbwidth;
  93792. + fb->fb.var.yres = fbheight;
  93793. + fb->fb.var.xres_virtual = fbwidth;
  93794. + fb->fb.var.yres_virtual = fbheight;
  93795. + fb->fb.var.bits_per_pixel = fbdepth;
  93796. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  93797. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  93798. + fb->fb.var.nonstd = 0;
  93799. + fb->fb.var.height = -1; /* height of picture in mm */
  93800. + fb->fb.var.width = -1; /* width of picture in mm */
  93801. + fb->fb.var.accel_flags = 0;
  93802. +
  93803. + fb->fb.monspecs.hfmin = 0;
  93804. + fb->fb.monspecs.hfmax = 100000;
  93805. + fb->fb.monspecs.vfmin = 0;
  93806. + fb->fb.monspecs.vfmax = 400;
  93807. + fb->fb.monspecs.dclkmin = 1000000;
  93808. + fb->fb.monspecs.dclkmax = 100000000;
  93809. +
  93810. + bcm2708_fb_set_bitfields(&fb->fb.var);
  93811. + init_waitqueue_head(&fb->dma_waitq);
  93812. +
  93813. + /*
  93814. + * Allocate colourmap.
  93815. + */
  93816. +
  93817. + fb_set_var(&fb->fb, &fb->fb.var);
  93818. +
  93819. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  93820. + fbheight, fbdepth, fbswap);
  93821. +
  93822. + ret = register_framebuffer(&fb->fb);
  93823. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  93824. + if (ret == 0)
  93825. + goto out;
  93826. +
  93827. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  93828. +out:
  93829. + return ret;
  93830. +}
  93831. +
  93832. +static int bcm2708_fb_probe(struct platform_device *dev)
  93833. +{
  93834. + struct bcm2708_fb *fb;
  93835. + int ret;
  93836. +
  93837. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  93838. + if (!fb) {
  93839. + dev_err(&dev->dev,
  93840. + "could not allocate new bcm2708_fb struct\n");
  93841. + ret = -ENOMEM;
  93842. + goto free_region;
  93843. + }
  93844. +
  93845. + bcm2708_fb_debugfs_init(fb);
  93846. +
  93847. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  93848. + &fb->cb_handle, GFP_KERNEL);
  93849. + if (!fb->cb_base) {
  93850. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  93851. + ret = -ENOMEM;
  93852. + goto free_fb;
  93853. + }
  93854. +
  93855. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  93856. + fb->cb_handle);
  93857. +
  93858. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  93859. + &fb->dma_chan_base, &fb->dma_irq);
  93860. + if (ret < 0) {
  93861. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  93862. + goto free_cb;
  93863. + }
  93864. + fb->dma_chan = ret;
  93865. +
  93866. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  93867. + 0, "bcm2708_fb dma", fb);
  93868. + if (ret) {
  93869. + pr_err("%s: failed to request DMA irq\n", __func__);
  93870. + goto free_dma_chan;
  93871. + }
  93872. +
  93873. +
  93874. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  93875. + fb->dma_chan, fb->dma_chan_base);
  93876. +
  93877. + fb->dev = dev;
  93878. +
  93879. + ret = bcm2708_fb_register(fb);
  93880. + if (ret == 0) {
  93881. + platform_set_drvdata(dev, fb);
  93882. + goto out;
  93883. + }
  93884. +
  93885. +free_dma_chan:
  93886. + bcm_dma_chan_free(fb->dma_chan);
  93887. +free_cb:
  93888. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  93889. +free_fb:
  93890. + kfree(fb);
  93891. +free_region:
  93892. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  93893. +out:
  93894. + return ret;
  93895. +}
  93896. +
  93897. +static int bcm2708_fb_remove(struct platform_device *dev)
  93898. +{
  93899. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  93900. +
  93901. + platform_set_drvdata(dev, NULL);
  93902. +
  93903. + if (fb->fb.screen_base)
  93904. + iounmap(fb->fb.screen_base);
  93905. + unregister_framebuffer(&fb->fb);
  93906. +
  93907. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  93908. + bcm_dma_chan_free(fb->dma_chan);
  93909. +
  93910. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  93911. + fb->dma);
  93912. + bcm2708_fb_debugfs_deinit(fb);
  93913. +
  93914. + free_irq(fb->dma_irq, fb);
  93915. +
  93916. + kfree(fb);
  93917. +
  93918. + return 0;
  93919. +}
  93920. +
  93921. +static struct platform_driver bcm2708_fb_driver = {
  93922. + .probe = bcm2708_fb_probe,
  93923. + .remove = bcm2708_fb_remove,
  93924. + .driver = {
  93925. + .name = DRIVER_NAME,
  93926. + .owner = THIS_MODULE,
  93927. + },
  93928. +};
  93929. +
  93930. +static int __init bcm2708_fb_init(void)
  93931. +{
  93932. + return platform_driver_register(&bcm2708_fb_driver);
  93933. +}
  93934. +
  93935. +module_init(bcm2708_fb_init);
  93936. +
  93937. +static void __exit bcm2708_fb_exit(void)
  93938. +{
  93939. + platform_driver_unregister(&bcm2708_fb_driver);
  93940. +}
  93941. +
  93942. +module_exit(bcm2708_fb_exit);
  93943. +
  93944. +module_param(fbwidth, int, 0644);
  93945. +module_param(fbheight, int, 0644);
  93946. +module_param(fbdepth, int, 0644);
  93947. +module_param(fbswap, int, 0644);
  93948. +
  93949. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  93950. +MODULE_LICENSE("GPL");
  93951. +
  93952. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  93953. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  93954. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  93955. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  93956. diff -Nur linux-3.10.33/drivers/video/cfbimgblt.c linux-raspberry-pi/drivers/video/cfbimgblt.c
  93957. --- linux-3.10.33/drivers/video/cfbimgblt.c 2014-03-07 06:58:45.000000000 +0100
  93958. +++ linux-raspberry-pi/drivers/video/cfbimgblt.c 2014-03-13 12:46:40.308099578 +0100
  93959. @@ -28,6 +28,11 @@
  93960. *
  93961. * Also need to add code to deal with cards endians that are different than
  93962. * the native cpu endians. I also need to deal with MSB position in the word.
  93963. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  93964. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  93965. + * significantly faster than the previous implementation.
  93966. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  93967. + * divides.
  93968. */
  93969. #include <linux/module.h>
  93970. #include <linux/string.h>
  93971. @@ -262,6 +267,133 @@
  93972. }
  93973. }
  93974. +/*
  93975. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  93976. + * into the code, main loop unrolled.
  93977. + */
  93978. +
  93979. +static inline void fast_imageblit16(const struct fb_image *image,
  93980. + struct fb_info *p, u8 __iomem * dst1,
  93981. + u32 fgcolor, u32 bgcolor)
  93982. +{
  93983. + u32 fgx = fgcolor, bgx = bgcolor;
  93984. + u32 spitch = (image->width + 7) / 8;
  93985. + u32 end_mask, eorx;
  93986. + const char *s = image->data, *src;
  93987. + u32 __iomem *dst;
  93988. + const u32 *tab = NULL;
  93989. + int i, j, k;
  93990. +
  93991. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  93992. +
  93993. + fgx <<= 16;
  93994. + bgx <<= 16;
  93995. + fgx |= fgcolor;
  93996. + bgx |= bgcolor;
  93997. +
  93998. + eorx = fgx ^ bgx;
  93999. + k = image->width / 2;
  94000. +
  94001. + for (i = image->height; i--;) {
  94002. + dst = (u32 __iomem *) dst1;
  94003. + src = s;
  94004. +
  94005. + j = k;
  94006. + while (j >= 4) {
  94007. + u8 bits = *src;
  94008. + end_mask = tab[(bits >> 6) & 3];
  94009. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94010. + end_mask = tab[(bits >> 4) & 3];
  94011. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94012. + end_mask = tab[(bits >> 2) & 3];
  94013. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94014. + end_mask = tab[bits & 3];
  94015. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94016. + src++;
  94017. + j -= 4;
  94018. + }
  94019. + if (j != 0) {
  94020. + u8 bits = *src;
  94021. + end_mask = tab[(bits >> 6) & 3];
  94022. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94023. + if (j >= 2) {
  94024. + end_mask = tab[(bits >> 4) & 3];
  94025. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94026. + if (j == 3) {
  94027. + end_mask = tab[(bits >> 2) & 3];
  94028. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  94029. + }
  94030. + }
  94031. + }
  94032. + dst1 += p->fix.line_length;
  94033. + s += spitch;
  94034. + }
  94035. +}
  94036. +
  94037. +/*
  94038. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  94039. + * into the code, main loop unrolled.
  94040. + */
  94041. +
  94042. +static inline void fast_imageblit32(const struct fb_image *image,
  94043. + struct fb_info *p, u8 __iomem * dst1,
  94044. + u32 fgcolor, u32 bgcolor)
  94045. +{
  94046. + u32 fgx = fgcolor, bgx = bgcolor;
  94047. + u32 spitch = (image->width + 7) / 8;
  94048. + u32 end_mask, eorx;
  94049. + const char *s = image->data, *src;
  94050. + u32 __iomem *dst;
  94051. + const u32 *tab = NULL;
  94052. + int i, j, k;
  94053. +
  94054. + tab = cfb_tab32;
  94055. +
  94056. + eorx = fgx ^ bgx;
  94057. + k = image->width;
  94058. +
  94059. + for (i = image->height; i--;) {
  94060. + dst = (u32 __iomem *) dst1;
  94061. + src = s;
  94062. +
  94063. + j = k;
  94064. + while (j >= 8) {
  94065. + u8 bits = *src;
  94066. + end_mask = tab[(bits >> 7) & 1];
  94067. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94068. + end_mask = tab[(bits >> 6) & 1];
  94069. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94070. + end_mask = tab[(bits >> 5) & 1];
  94071. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94072. + end_mask = tab[(bits >> 4) & 1];
  94073. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94074. + end_mask = tab[(bits >> 3) & 1];
  94075. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94076. + end_mask = tab[(bits >> 2) & 1];
  94077. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94078. + end_mask = tab[(bits >> 1) & 1];
  94079. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94080. + end_mask = tab[bits & 1];
  94081. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94082. + src++;
  94083. + j -= 8;
  94084. + }
  94085. + if (j != 0) {
  94086. + u32 bits = (u32) * src;
  94087. + while (j > 1) {
  94088. + end_mask = tab[(bits >> 7) & 1];
  94089. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  94090. + bits <<= 1;
  94091. + j--;
  94092. + }
  94093. + end_mask = tab[(bits >> 7) & 1];
  94094. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  94095. + }
  94096. + dst1 += p->fix.line_length;
  94097. + s += spitch;
  94098. + }
  94099. +}
  94100. +
  94101. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  94102. {
  94103. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  94104. @@ -294,11 +426,21 @@
  94105. bgcolor = image->bg_color;
  94106. }
  94107. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  94108. - ((width & (32/bpp-1)) == 0) &&
  94109. - bpp >= 8 && bpp <= 32)
  94110. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  94111. - else
  94112. + if (!start_index && !pitch_index) {
  94113. + if (bpp == 32)
  94114. + fast_imageblit32(image, p, dst1, fgcolor,
  94115. + bgcolor);
  94116. + else if (bpp == 16 && (width & 1) == 0)
  94117. + fast_imageblit16(image, p, dst1, fgcolor,
  94118. + bgcolor);
  94119. + else if (bpp == 8 && (width & 3) == 0)
  94120. + fast_imageblit(image, p, dst1, fgcolor,
  94121. + bgcolor);
  94122. + else
  94123. + slow_imageblit(image, p, dst1, fgcolor,
  94124. + bgcolor,
  94125. + start_index, pitch_index);
  94126. + } else
  94127. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  94128. start_index, pitch_index);
  94129. } else
  94130. diff -Nur linux-3.10.33/drivers/video/fbmem.c linux-raspberry-pi/drivers/video/fbmem.c
  94131. --- linux-3.10.33/drivers/video/fbmem.c 2014-03-07 06:58:45.000000000 +0100
  94132. +++ linux-raspberry-pi/drivers/video/fbmem.c 2014-03-13 12:46:40.316099594 +0100
  94133. @@ -1074,6 +1074,25 @@
  94134. return ret;
  94135. }
  94136. +static int fb_copyarea_user(struct fb_info *info,
  94137. + struct fb_copyarea *copy)
  94138. +{
  94139. + int ret = 0;
  94140. + if (!lock_fb_info(info))
  94141. + return -ENODEV;
  94142. + if (copy->dx + copy->width > info->var.xres ||
  94143. + copy->sx + copy->width > info->var.xres ||
  94144. + copy->dy + copy->height > info->var.yres ||
  94145. + copy->sy + copy->height > info->var.yres) {
  94146. + ret = -EINVAL;
  94147. + goto out;
  94148. + }
  94149. + info->fbops->fb_copyarea(info, copy);
  94150. +out:
  94151. + unlock_fb_info(info);
  94152. + return ret;
  94153. +}
  94154. +
  94155. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  94156. unsigned long arg)
  94157. {
  94158. @@ -1084,6 +1103,7 @@
  94159. struct fb_cmap cmap_from;
  94160. struct fb_cmap_user cmap;
  94161. struct fb_event event;
  94162. + struct fb_copyarea copy;
  94163. void __user *argp = (void __user *)arg;
  94164. long ret = 0;
  94165. @@ -1193,6 +1213,15 @@
  94166. console_unlock();
  94167. unlock_fb_info(info);
  94168. break;
  94169. + case FBIOCOPYAREA:
  94170. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  94171. + /* only provide this ioctl if it is accelerated */
  94172. + if (copy_from_user(&copy, argp, sizeof(copy)))
  94173. + return -EFAULT;
  94174. + ret = fb_copyarea_user(info, &copy);
  94175. + break;
  94176. + }
  94177. + /* fall through */
  94178. default:
  94179. if (!lock_fb_info(info))
  94180. return -ENODEV;
  94181. @@ -1345,6 +1374,7 @@
  94182. case FBIOPAN_DISPLAY:
  94183. case FBIOGET_CON2FBMAP:
  94184. case FBIOPUT_CON2FBMAP:
  94185. + case FBIOCOPYAREA:
  94186. arg = (unsigned long) compat_ptr(arg);
  94187. case FBIOBLANK:
  94188. ret = do_fb_ioctl(info, cmd, arg);
  94189. diff -Nur linux-3.10.33/drivers/video/Kconfig linux-raspberry-pi/drivers/video/Kconfig
  94190. --- linux-3.10.33/drivers/video/Kconfig 2014-03-07 06:58:45.000000000 +0100
  94191. +++ linux-raspberry-pi/drivers/video/Kconfig 2014-03-13 12:46:40.288099538 +0100
  94192. @@ -310,6 +310,20 @@
  94193. help
  94194. Support the Permedia2 FIFO disconnect feature.
  94195. +config FB_BCM2708
  94196. + tristate "BCM2708 framebuffer support"
  94197. + depends on FB && ARM
  94198. + select FB_CFB_FILLRECT
  94199. + select FB_CFB_COPYAREA
  94200. + select FB_CFB_IMAGEBLIT
  94201. + help
  94202. + This framebuffer device driver is for the BCM2708 framebuffer.
  94203. +
  94204. + If you want to compile this as a module (=code which can be
  94205. + inserted into and removed from the running kernel), say M
  94206. + here and read <file:Documentation/kbuild/modules.txt>. The module
  94207. + will be called bcm2708_fb.
  94208. +
  94209. config FB_ARMCLCD
  94210. tristate "ARM PrimeCell PL110 support"
  94211. depends on FB && ARM && ARM_AMBA
  94212. diff -Nur linux-3.10.33/drivers/video/logo/logo_linux_clut224.ppm linux-raspberry-pi/drivers/video/logo/logo_linux_clut224.ppm
  94213. --- linux-3.10.33/drivers/video/logo/logo_linux_clut224.ppm 2014-03-07 06:58:45.000000000 +0100
  94214. +++ linux-raspberry-pi/drivers/video/logo/logo_linux_clut224.ppm 2014-03-13 12:46:40.328099618 +0100
  94215. @@ -1,1604 +1,883 @@
  94216. P3
  94217. -# Standard 224-color Linux logo
  94218. -80 80
  94219. +63 80
  94220. 255
  94221. - 0 0 0 0 0 0 0 0 0 0 0 0
  94222. - 0 0 0 0 0 0 0 0 0 0 0 0
  94223. - 0 0 0 0 0 0 0 0 0 0 0 0
  94224. - 0 0 0 0 0 0 0 0 0 0 0 0
  94225. - 0 0 0 0 0 0 0 0 0 0 0 0
  94226. - 0 0 0 0 0 0 0 0 0 0 0 0
  94227. - 0 0 0 0 0 0 0 0 0 0 0 0
  94228. - 0 0 0 0 0 0 0 0 0 0 0 0
  94229. - 0 0 0 0 0 0 0 0 0 0 0 0
  94230. - 6 6 6 6 6 6 10 10 10 10 10 10
  94231. - 10 10 10 6 6 6 6 6 6 6 6 6
  94232. - 0 0 0 0 0 0 0 0 0 0 0 0
  94233. - 0 0 0 0 0 0 0 0 0 0 0 0
  94234. - 0 0 0 0 0 0 0 0 0 0 0 0
  94235. - 0 0 0 0 0 0 0 0 0 0 0 0
  94236. - 0 0 0 0 0 0 0 0 0 0 0 0
  94237. - 0 0 0 0 0 0 0 0 0 0 0 0
  94238. - 0 0 0 0 0 0 0 0 0 0 0 0
  94239. - 0 0 0 0 0 0 0 0 0 0 0 0
  94240. - 0 0 0 0 0 0 0 0 0 0 0 0
  94241. - 0 0 0 0 0 0 0 0 0 0 0 0
  94242. - 0 0 0 0 0 0 0 0 0 0 0 0
  94243. - 0 0 0 0 0 0 0 0 0 0 0 0
  94244. - 0 0 0 0 0 0 0 0 0 0 0 0
  94245. - 0 0 0 0 0 0 0 0 0 0 0 0
  94246. - 0 0 0 0 0 0 0 0 0 0 0 0
  94247. - 0 0 0 0 0 0 0 0 0 0 0 0
  94248. - 0 0 0 0 0 0 0 0 0 0 0 0
  94249. - 0 0 0 6 6 6 10 10 10 14 14 14
  94250. - 22 22 22 26 26 26 30 30 30 34 34 34
  94251. - 30 30 30 30 30 30 26 26 26 18 18 18
  94252. - 14 14 14 10 10 10 6 6 6 0 0 0
  94253. - 0 0 0 0 0 0 0 0 0 0 0 0
  94254. - 0 0 0 0 0 0 0 0 0 0 0 0
  94255. - 0 0 0 0 0 0 0 0 0 0 0 0
  94256. - 0 0 0 0 0 0 0 0 0 0 0 0
  94257. - 0 0 0 0 0 0 0 0 0 0 0 0
  94258. - 0 0 0 0 0 0 0 0 0 0 0 0
  94259. - 0 0 0 0 0 0 0 0 0 0 0 0
  94260. - 0 0 0 0 0 0 0 0 0 0 0 0
  94261. - 0 0 0 0 0 0 0 0 0 0 0 0
  94262. - 0 0 0 0 0 1 0 0 1 0 0 0
  94263. - 0 0 0 0 0 0 0 0 0 0 0 0
  94264. - 0 0 0 0 0 0 0 0 0 0 0 0
  94265. - 0 0 0 0 0 0 0 0 0 0 0 0
  94266. - 0 0 0 0 0 0 0 0 0 0 0 0
  94267. - 0 0 0 0 0 0 0 0 0 0 0 0
  94268. - 0 0 0 0 0 0 0 0 0 0 0 0
  94269. - 6 6 6 14 14 14 26 26 26 42 42 42
  94270. - 54 54 54 66 66 66 78 78 78 78 78 78
  94271. - 78 78 78 74 74 74 66 66 66 54 54 54
  94272. - 42 42 42 26 26 26 18 18 18 10 10 10
  94273. - 6 6 6 0 0 0 0 0 0 0 0 0
  94274. - 0 0 0 0 0 0 0 0 0 0 0 0
  94275. - 0 0 0 0 0 0 0 0 0 0 0 0
  94276. - 0 0 0 0 0 0 0 0 0 0 0 0
  94277. - 0 0 0 0 0 0 0 0 0 0 0 0
  94278. - 0 0 0 0 0 0 0 0 0 0 0 0
  94279. - 0 0 0 0 0 0 0 0 0 0 0 0
  94280. - 0 0 0 0 0 0 0 0 0 0 0 0
  94281. - 0 0 0 0 0 0 0 0 0 0 0 0
  94282. - 0 0 1 0 0 0 0 0 0 0 0 0
  94283. - 0 0 0 0 0 0 0 0 0 0 0 0
  94284. - 0 0 0 0 0 0 0 0 0 0 0 0
  94285. - 0 0 0 0 0 0 0 0 0 0 0 0
  94286. - 0 0 0 0 0 0 0 0 0 0 0 0
  94287. - 0 0 0 0 0 0 0 0 0 0 0 0
  94288. - 0 0 0 0 0 0 0 0 0 10 10 10
  94289. - 22 22 22 42 42 42 66 66 66 86 86 86
  94290. - 66 66 66 38 38 38 38 38 38 22 22 22
  94291. - 26 26 26 34 34 34 54 54 54 66 66 66
  94292. - 86 86 86 70 70 70 46 46 46 26 26 26
  94293. - 14 14 14 6 6 6 0 0 0 0 0 0
  94294. - 0 0 0 0 0 0 0 0 0 0 0 0
  94295. - 0 0 0 0 0 0 0 0 0 0 0 0
  94296. - 0 0 0 0 0 0 0 0 0 0 0 0
  94297. - 0 0 0 0 0 0 0 0 0 0 0 0
  94298. - 0 0 0 0 0 0 0 0 0 0 0 0
  94299. - 0 0 0 0 0 0 0 0 0 0 0 0
  94300. - 0 0 0 0 0 0 0 0 0 0 0 0
  94301. - 0 0 0 0 0 0 0 0 0 0 0 0
  94302. - 0 0 1 0 0 1 0 0 1 0 0 0
  94303. - 0 0 0 0 0 0 0 0 0 0 0 0
  94304. - 0 0 0 0 0 0 0 0 0 0 0 0
  94305. - 0 0 0 0 0 0 0 0 0 0 0 0
  94306. - 0 0 0 0 0 0 0 0 0 0 0 0
  94307. - 0 0 0 0 0 0 0 0 0 0 0 0
  94308. - 0 0 0 0 0 0 10 10 10 26 26 26
  94309. - 50 50 50 82 82 82 58 58 58 6 6 6
  94310. - 2 2 6 2 2 6 2 2 6 2 2 6
  94311. - 2 2 6 2 2 6 2 2 6 2 2 6
  94312. - 6 6 6 54 54 54 86 86 86 66 66 66
  94313. - 38 38 38 18 18 18 6 6 6 0 0 0
  94314. - 0 0 0 0 0 0 0 0 0 0 0 0
  94315. - 0 0 0 0 0 0 0 0 0 0 0 0
  94316. - 0 0 0 0 0 0 0 0 0 0 0 0
  94317. - 0 0 0 0 0 0 0 0 0 0 0 0
  94318. - 0 0 0 0 0 0 0 0 0 0 0 0
  94319. - 0 0 0 0 0 0 0 0 0 0 0 0
  94320. - 0 0 0 0 0 0 0 0 0 0 0 0
  94321. - 0 0 0 0 0 0 0 0 0 0 0 0
  94322. - 0 0 0 0 0 0 0 0 0 0 0 0
  94323. - 0 0 0 0 0 0 0 0 0 0 0 0
  94324. - 0 0 0 0 0 0 0 0 0 0 0 0
  94325. - 0 0 0 0 0 0 0 0 0 0 0 0
  94326. - 0 0 0 0 0 0 0 0 0 0 0 0
  94327. - 0 0 0 0 0 0 0 0 0 0 0 0
  94328. - 0 0 0 6 6 6 22 22 22 50 50 50
  94329. - 78 78 78 34 34 34 2 2 6 2 2 6
  94330. - 2 2 6 2 2 6 2 2 6 2 2 6
  94331. - 2 2 6 2 2 6 2 2 6 2 2 6
  94332. - 2 2 6 2 2 6 6 6 6 70 70 70
  94333. - 78 78 78 46 46 46 22 22 22 6 6 6
  94334. - 0 0 0 0 0 0 0 0 0 0 0 0
  94335. - 0 0 0 0 0 0 0 0 0 0 0 0
  94336. - 0 0 0 0 0 0 0 0 0 0 0 0
  94337. - 0 0 0 0 0 0 0 0 0 0 0 0
  94338. - 0 0 0 0 0 0 0 0 0 0 0 0
  94339. - 0 0 0 0 0 0 0 0 0 0 0 0
  94340. - 0 0 0 0 0 0 0 0 0 0 0 0
  94341. - 0 0 0 0 0 0 0 0 0 0 0 0
  94342. - 0 0 1 0 0 1 0 0 1 0 0 0
  94343. - 0 0 0 0 0 0 0 0 0 0 0 0
  94344. - 0 0 0 0 0 0 0 0 0 0 0 0
  94345. - 0 0 0 0 0 0 0 0 0 0 0 0
  94346. - 0 0 0 0 0 0 0 0 0 0 0 0
  94347. - 0 0 0 0 0 0 0 0 0 0 0 0
  94348. - 6 6 6 18 18 18 42 42 42 82 82 82
  94349. - 26 26 26 2 2 6 2 2 6 2 2 6
  94350. - 2 2 6 2 2 6 2 2 6 2 2 6
  94351. - 2 2 6 2 2 6 2 2 6 14 14 14
  94352. - 46 46 46 34 34 34 6 6 6 2 2 6
  94353. - 42 42 42 78 78 78 42 42 42 18 18 18
  94354. - 6 6 6 0 0 0 0 0 0 0 0 0
  94355. - 0 0 0 0 0 0 0 0 0 0 0 0
  94356. - 0 0 0 0 0 0 0 0 0 0 0 0
  94357. - 0 0 0 0 0 0 0 0 0 0 0 0
  94358. - 0 0 0 0 0 0 0 0 0 0 0 0
  94359. - 0 0 0 0 0 0 0 0 0 0 0 0
  94360. - 0 0 0 0 0 0 0 0 0 0 0 0
  94361. - 0 0 0 0 0 0 0 0 0 0 0 0
  94362. - 0 0 1 0 0 0 0 0 1 0 0 0
  94363. - 0 0 0 0 0 0 0 0 0 0 0 0
  94364. - 0 0 0 0 0 0 0 0 0 0 0 0
  94365. - 0 0 0 0 0 0 0 0 0 0 0 0
  94366. - 0 0 0 0 0 0 0 0 0 0 0 0
  94367. - 0 0 0 0 0 0 0 0 0 0 0 0
  94368. - 10 10 10 30 30 30 66 66 66 58 58 58
  94369. - 2 2 6 2 2 6 2 2 6 2 2 6
  94370. - 2 2 6 2 2 6 2 2 6 2 2 6
  94371. - 2 2 6 2 2 6 2 2 6 26 26 26
  94372. - 86 86 86 101 101 101 46 46 46 10 10 10
  94373. - 2 2 6 58 58 58 70 70 70 34 34 34
  94374. - 10 10 10 0 0 0 0 0 0 0 0 0
  94375. - 0 0 0 0 0 0 0 0 0 0 0 0
  94376. - 0 0 0 0 0 0 0 0 0 0 0 0
  94377. - 0 0 0 0 0 0 0 0 0 0 0 0
  94378. - 0 0 0 0 0 0 0 0 0 0 0 0
  94379. - 0 0 0 0 0 0 0 0 0 0 0 0
  94380. - 0 0 0 0 0 0 0 0 0 0 0 0
  94381. - 0 0 0 0 0 0 0 0 0 0 0 0
  94382. - 0 0 1 0 0 1 0 0 1 0 0 0
  94383. - 0 0 0 0 0 0 0 0 0 0 0 0
  94384. - 0 0 0 0 0 0 0 0 0 0 0 0
  94385. - 0 0 0 0 0 0 0 0 0 0 0 0
  94386. - 0 0 0 0 0 0 0 0 0 0 0 0
  94387. - 0 0 0 0 0 0 0 0 0 0 0 0
  94388. - 14 14 14 42 42 42 86 86 86 10 10 10
  94389. - 2 2 6 2 2 6 2 2 6 2 2 6
  94390. - 2 2 6 2 2 6 2 2 6 2 2 6
  94391. - 2 2 6 2 2 6 2 2 6 30 30 30
  94392. - 94 94 94 94 94 94 58 58 58 26 26 26
  94393. - 2 2 6 6 6 6 78 78 78 54 54 54
  94394. - 22 22 22 6 6 6 0 0 0 0 0 0
  94395. - 0 0 0 0 0 0 0 0 0 0 0 0
  94396. - 0 0 0 0 0 0 0 0 0 0 0 0
  94397. - 0 0 0 0 0 0 0 0 0 0 0 0
  94398. - 0 0 0 0 0 0 0 0 0 0 0 0
  94399. - 0 0 0 0 0 0 0 0 0 0 0 0
  94400. - 0 0 0 0 0 0 0 0 0 0 0 0
  94401. - 0 0 0 0 0 0 0 0 0 0 0 0
  94402. - 0 0 0 0 0 0 0 0 0 0 0 0
  94403. - 0 0 0 0 0 0 0 0 0 0 0 0
  94404. - 0 0 0 0 0 0 0 0 0 0 0 0
  94405. - 0 0 0 0 0 0 0 0 0 0 0 0
  94406. - 0 0 0 0 0 0 0 0 0 0 0 0
  94407. - 0 0 0 0 0 0 0 0 0 6 6 6
  94408. - 22 22 22 62 62 62 62 62 62 2 2 6
  94409. - 2 2 6 2 2 6 2 2 6 2 2 6
  94410. - 2 2 6 2 2 6 2 2 6 2 2 6
  94411. - 2 2 6 2 2 6 2 2 6 26 26 26
  94412. - 54 54 54 38 38 38 18 18 18 10 10 10
  94413. - 2 2 6 2 2 6 34 34 34 82 82 82
  94414. - 38 38 38 14 14 14 0 0 0 0 0 0
  94415. - 0 0 0 0 0 0 0 0 0 0 0 0
  94416. - 0 0 0 0 0 0 0 0 0 0 0 0
  94417. - 0 0 0 0 0 0 0 0 0 0 0 0
  94418. - 0 0 0 0 0 0 0 0 0 0 0 0
  94419. - 0 0 0 0 0 0 0 0 0 0 0 0
  94420. - 0 0 0 0 0 0 0 0 0 0 0 0
  94421. - 0 0 0 0 0 0 0 0 0 0 0 0
  94422. - 0 0 0 0 0 1 0 0 1 0 0 0
  94423. - 0 0 0 0 0 0 0 0 0 0 0 0
  94424. - 0 0 0 0 0 0 0 0 0 0 0 0
  94425. - 0 0 0 0 0 0 0 0 0 0 0 0
  94426. - 0 0 0 0 0 0 0 0 0 0 0 0
  94427. - 0 0 0 0 0 0 0 0 0 6 6 6
  94428. - 30 30 30 78 78 78 30 30 30 2 2 6
  94429. - 2 2 6 2 2 6 2 2 6 2 2 6
  94430. - 2 2 6 2 2 6 2 2 6 2 2 6
  94431. - 2 2 6 2 2 6 2 2 6 10 10 10
  94432. - 10 10 10 2 2 6 2 2 6 2 2 6
  94433. - 2 2 6 2 2 6 2 2 6 78 78 78
  94434. - 50 50 50 18 18 18 6 6 6 0 0 0
  94435. - 0 0 0 0 0 0 0 0 0 0 0 0
  94436. - 0 0 0 0 0 0 0 0 0 0 0 0
  94437. - 0 0 0 0 0 0 0 0 0 0 0 0
  94438. - 0 0 0 0 0 0 0 0 0 0 0 0
  94439. - 0 0 0 0 0 0 0 0 0 0 0 0
  94440. - 0 0 0 0 0 0 0 0 0 0 0 0
  94441. - 0 0 0 0 0 0 0 0 0 0 0 0
  94442. - 0 0 1 0 0 0 0 0 0 0 0 0
  94443. - 0 0 0 0 0 0 0 0 0 0 0 0
  94444. - 0 0 0 0 0 0 0 0 0 0 0 0
  94445. - 0 0 0 0 0 0 0 0 0 0 0 0
  94446. - 0 0 0 0 0 0 0 0 0 0 0 0
  94447. - 0 0 0 0 0 0 0 0 0 10 10 10
  94448. - 38 38 38 86 86 86 14 14 14 2 2 6
  94449. - 2 2 6 2 2 6 2 2 6 2 2 6
  94450. - 2 2 6 2 2 6 2 2 6 2 2 6
  94451. - 2 2 6 2 2 6 2 2 6 2 2 6
  94452. - 2 2 6 2 2 6 2 2 6 2 2 6
  94453. - 2 2 6 2 2 6 2 2 6 54 54 54
  94454. - 66 66 66 26 26 26 6 6 6 0 0 0
  94455. - 0 0 0 0 0 0 0 0 0 0 0 0
  94456. - 0 0 0 0 0 0 0 0 0 0 0 0
  94457. - 0 0 0 0 0 0 0 0 0 0 0 0
  94458. - 0 0 0 0 0 0 0 0 0 0 0 0
  94459. - 0 0 0 0 0 0 0 0 0 0 0 0
  94460. - 0 0 0 0 0 0 0 0 0 0 0 0
  94461. - 0 0 0 0 0 0 0 0 0 0 0 0
  94462. - 0 0 0 0 0 1 0 0 1 0 0 0
  94463. - 0 0 0 0 0 0 0 0 0 0 0 0
  94464. - 0 0 0 0 0 0 0 0 0 0 0 0
  94465. - 0 0 0 0 0 0 0 0 0 0 0 0
  94466. - 0 0 0 0 0 0 0 0 0 0 0 0
  94467. - 0 0 0 0 0 0 0 0 0 14 14 14
  94468. - 42 42 42 82 82 82 2 2 6 2 2 6
  94469. - 2 2 6 6 6 6 10 10 10 2 2 6
  94470. - 2 2 6 2 2 6 2 2 6 2 2 6
  94471. - 2 2 6 2 2 6 2 2 6 6 6 6
  94472. - 14 14 14 10 10 10 2 2 6 2 2 6
  94473. - 2 2 6 2 2 6 2 2 6 18 18 18
  94474. - 82 82 82 34 34 34 10 10 10 0 0 0
  94475. - 0 0 0 0 0 0 0 0 0 0 0 0
  94476. - 0 0 0 0 0 0 0 0 0 0 0 0
  94477. - 0 0 0 0 0 0 0 0 0 0 0 0
  94478. - 0 0 0 0 0 0 0 0 0 0 0 0
  94479. - 0 0 0 0 0 0 0 0 0 0 0 0
  94480. - 0 0 0 0 0 0 0 0 0 0 0 0
  94481. - 0 0 0 0 0 0 0 0 0 0 0 0
  94482. - 0 0 1 0 0 0 0 0 0 0 0 0
  94483. - 0 0 0 0 0 0 0 0 0 0 0 0
  94484. - 0 0 0 0 0 0 0 0 0 0 0 0
  94485. - 0 0 0 0 0 0 0 0 0 0 0 0
  94486. - 0 0 0 0 0 0 0 0 0 0 0 0
  94487. - 0 0 0 0 0 0 0 0 0 14 14 14
  94488. - 46 46 46 86 86 86 2 2 6 2 2 6
  94489. - 6 6 6 6 6 6 22 22 22 34 34 34
  94490. - 6 6 6 2 2 6 2 2 6 2 2 6
  94491. - 2 2 6 2 2 6 18 18 18 34 34 34
  94492. - 10 10 10 50 50 50 22 22 22 2 2 6
  94493. - 2 2 6 2 2 6 2 2 6 10 10 10
  94494. - 86 86 86 42 42 42 14 14 14 0 0 0
  94495. - 0 0 0 0 0 0 0 0 0 0 0 0
  94496. - 0 0 0 0 0 0 0 0 0 0 0 0
  94497. - 0 0 0 0 0 0 0 0 0 0 0 0
  94498. - 0 0 0 0 0 0 0 0 0 0 0 0
  94499. - 0 0 0 0 0 0 0 0 0 0 0 0
  94500. - 0 0 0 0 0 0 0 0 0 0 0 0
  94501. - 0 0 0 0 0 0 0 0 0 0 0 0
  94502. - 0 0 1 0 0 1 0 0 1 0 0 0
  94503. - 0 0 0 0 0 0 0 0 0 0 0 0
  94504. - 0 0 0 0 0 0 0 0 0 0 0 0
  94505. - 0 0 0 0 0 0 0 0 0 0 0 0
  94506. - 0 0 0 0 0 0 0 0 0 0 0 0
  94507. - 0 0 0 0 0 0 0 0 0 14 14 14
  94508. - 46 46 46 86 86 86 2 2 6 2 2 6
  94509. - 38 38 38 116 116 116 94 94 94 22 22 22
  94510. - 22 22 22 2 2 6 2 2 6 2 2 6
  94511. - 14 14 14 86 86 86 138 138 138 162 162 162
  94512. -154 154 154 38 38 38 26 26 26 6 6 6
  94513. - 2 2 6 2 2 6 2 2 6 2 2 6
  94514. - 86 86 86 46 46 46 14 14 14 0 0 0
  94515. - 0 0 0 0 0 0 0 0 0 0 0 0
  94516. - 0 0 0 0 0 0 0 0 0 0 0 0
  94517. - 0 0 0 0 0 0 0 0 0 0 0 0
  94518. - 0 0 0 0 0 0 0 0 0 0 0 0
  94519. - 0 0 0 0 0 0 0 0 0 0 0 0
  94520. - 0 0 0 0 0 0 0 0 0 0 0 0
  94521. - 0 0 0 0 0 0 0 0 0 0 0 0
  94522. - 0 0 0 0 0 0 0 0 0 0 0 0
  94523. - 0 0 0 0 0 0 0 0 0 0 0 0
  94524. - 0 0 0 0 0 0 0 0 0 0 0 0
  94525. - 0 0 0 0 0 0 0 0 0 0 0 0
  94526. - 0 0 0 0 0 0 0 0 0 0 0 0
  94527. - 0 0 0 0 0 0 0 0 0 14 14 14
  94528. - 46 46 46 86 86 86 2 2 6 14 14 14
  94529. -134 134 134 198 198 198 195 195 195 116 116 116
  94530. - 10 10 10 2 2 6 2 2 6 6 6 6
  94531. -101 98 89 187 187 187 210 210 210 218 218 218
  94532. -214 214 214 134 134 134 14 14 14 6 6 6
  94533. - 2 2 6 2 2 6 2 2 6 2 2 6
  94534. - 86 86 86 50 50 50 18 18 18 6 6 6
  94535. - 0 0 0 0 0 0 0 0 0 0 0 0
  94536. - 0 0 0 0 0 0 0 0 0 0 0 0
  94537. - 0 0 0 0 0 0 0 0 0 0 0 0
  94538. - 0 0 0 0 0 0 0 0 0 0 0 0
  94539. - 0 0 0 0 0 0 0 0 0 0 0 0
  94540. - 0 0 0 0 0 0 0 0 0 0 0 0
  94541. - 0 0 0 0 0 0 0 0 1 0 0 0
  94542. - 0 0 1 0 0 1 0 0 1 0 0 0
  94543. - 0 0 0 0 0 0 0 0 0 0 0 0
  94544. - 0 0 0 0 0 0 0 0 0 0 0 0
  94545. - 0 0 0 0 0 0 0 0 0 0 0 0
  94546. - 0 0 0 0 0 0 0 0 0 0 0 0
  94547. - 0 0 0 0 0 0 0 0 0 14 14 14
  94548. - 46 46 46 86 86 86 2 2 6 54 54 54
  94549. -218 218 218 195 195 195 226 226 226 246 246 246
  94550. - 58 58 58 2 2 6 2 2 6 30 30 30
  94551. -210 210 210 253 253 253 174 174 174 123 123 123
  94552. -221 221 221 234 234 234 74 74 74 2 2 6
  94553. - 2 2 6 2 2 6 2 2 6 2 2 6
  94554. - 70 70 70 58 58 58 22 22 22 6 6 6
  94555. - 0 0 0 0 0 0 0 0 0 0 0 0
  94556. - 0 0 0 0 0 0 0 0 0 0 0 0
  94557. - 0 0 0 0 0 0 0 0 0 0 0 0
  94558. - 0 0 0 0 0 0 0 0 0 0 0 0
  94559. - 0 0 0 0 0 0 0 0 0 0 0 0
  94560. - 0 0 0 0 0 0 0 0 0 0 0 0
  94561. - 0 0 0 0 0 0 0 0 0 0 0 0
  94562. - 0 0 0 0 0 0 0 0 0 0 0 0
  94563. - 0 0 0 0 0 0 0 0 0 0 0 0
  94564. - 0 0 0 0 0 0 0 0 0 0 0 0
  94565. - 0 0 0 0 0 0 0 0 0 0 0 0
  94566. - 0 0 0 0 0 0 0 0 0 0 0 0
  94567. - 0 0 0 0 0 0 0 0 0 14 14 14
  94568. - 46 46 46 82 82 82 2 2 6 106 106 106
  94569. -170 170 170 26 26 26 86 86 86 226 226 226
  94570. -123 123 123 10 10 10 14 14 14 46 46 46
  94571. -231 231 231 190 190 190 6 6 6 70 70 70
  94572. - 90 90 90 238 238 238 158 158 158 2 2 6
  94573. - 2 2 6 2 2 6 2 2 6 2 2 6
  94574. - 70 70 70 58 58 58 22 22 22 6 6 6
  94575. - 0 0 0 0 0 0 0 0 0 0 0 0
  94576. - 0 0 0 0 0 0 0 0 0 0 0 0
  94577. - 0 0 0 0 0 0 0 0 0 0 0 0
  94578. - 0 0 0 0 0 0 0 0 0 0 0 0
  94579. - 0 0 0 0 0 0 0 0 0 0 0 0
  94580. - 0 0 0 0 0 0 0 0 0 0 0 0
  94581. - 0 0 0 0 0 0 0 0 1 0 0 0
  94582. - 0 0 1 0 0 1 0 0 1 0 0 0
  94583. - 0 0 0 0 0 0 0 0 0 0 0 0
  94584. - 0 0 0 0 0 0 0 0 0 0 0 0
  94585. - 0 0 0 0 0 0 0 0 0 0 0 0
  94586. - 0 0 0 0 0 0 0 0 0 0 0 0
  94587. - 0 0 0 0 0 0 0 0 0 14 14 14
  94588. - 42 42 42 86 86 86 6 6 6 116 116 116
  94589. -106 106 106 6 6 6 70 70 70 149 149 149
  94590. -128 128 128 18 18 18 38 38 38 54 54 54
  94591. -221 221 221 106 106 106 2 2 6 14 14 14
  94592. - 46 46 46 190 190 190 198 198 198 2 2 6
  94593. - 2 2 6 2 2 6 2 2 6 2 2 6
  94594. - 74 74 74 62 62 62 22 22 22 6 6 6
  94595. - 0 0 0 0 0 0 0 0 0 0 0 0
  94596. - 0 0 0 0 0 0 0 0 0 0 0 0
  94597. - 0 0 0 0 0 0 0 0 0 0 0 0
  94598. - 0 0 0 0 0 0 0 0 0 0 0 0
  94599. - 0 0 0 0 0 0 0 0 0 0 0 0
  94600. - 0 0 0 0 0 0 0 0 0 0 0 0
  94601. - 0 0 0 0 0 0 0 0 1 0 0 0
  94602. - 0 0 1 0 0 0 0 0 1 0 0 0
  94603. - 0 0 0 0 0 0 0 0 0 0 0 0
  94604. - 0 0 0 0 0 0 0 0 0 0 0 0
  94605. - 0 0 0 0 0 0 0 0 0 0 0 0
  94606. - 0 0 0 0 0 0 0 0 0 0 0 0
  94607. - 0 0 0 0 0 0 0 0 0 14 14 14
  94608. - 42 42 42 94 94 94 14 14 14 101 101 101
  94609. -128 128 128 2 2 6 18 18 18 116 116 116
  94610. -118 98 46 121 92 8 121 92 8 98 78 10
  94611. -162 162 162 106 106 106 2 2 6 2 2 6
  94612. - 2 2 6 195 195 195 195 195 195 6 6 6
  94613. - 2 2 6 2 2 6 2 2 6 2 2 6
  94614. - 74 74 74 62 62 62 22 22 22 6 6 6
  94615. - 0 0 0 0 0 0 0 0 0 0 0 0
  94616. - 0 0 0 0 0 0 0 0 0 0 0 0
  94617. - 0 0 0 0 0 0 0 0 0 0 0 0
  94618. - 0 0 0 0 0 0 0 0 0 0 0 0
  94619. - 0 0 0 0 0 0 0 0 0 0 0 0
  94620. - 0 0 0 0 0 0 0 0 0 0 0 0
  94621. - 0 0 0 0 0 0 0 0 1 0 0 1
  94622. - 0 0 1 0 0 0 0 0 1 0 0 0
  94623. - 0 0 0 0 0 0 0 0 0 0 0 0
  94624. - 0 0 0 0 0 0 0 0 0 0 0 0
  94625. - 0 0 0 0 0 0 0 0 0 0 0 0
  94626. - 0 0 0 0 0 0 0 0 0 0 0 0
  94627. - 0 0 0 0 0 0 0 0 0 10 10 10
  94628. - 38 38 38 90 90 90 14 14 14 58 58 58
  94629. -210 210 210 26 26 26 54 38 6 154 114 10
  94630. -226 170 11 236 186 11 225 175 15 184 144 12
  94631. -215 174 15 175 146 61 37 26 9 2 2 6
  94632. - 70 70 70 246 246 246 138 138 138 2 2 6
  94633. - 2 2 6 2 2 6 2 2 6 2 2 6
  94634. - 70 70 70 66 66 66 26 26 26 6 6 6
  94635. - 0 0 0 0 0 0 0 0 0 0 0 0
  94636. - 0 0 0 0 0 0 0 0 0 0 0 0
  94637. - 0 0 0 0 0 0 0 0 0 0 0 0
  94638. - 0 0 0 0 0 0 0 0 0 0 0 0
  94639. - 0 0 0 0 0 0 0 0 0 0 0 0
  94640. - 0 0 0 0 0 0 0 0 0 0 0 0
  94641. - 0 0 0 0 0 0 0 0 0 0 0 0
  94642. - 0 0 0 0 0 0 0 0 0 0 0 0
  94643. - 0 0 0 0 0 0 0 0 0 0 0 0
  94644. - 0 0 0 0 0 0 0 0 0 0 0 0
  94645. - 0 0 0 0 0 0 0 0 0 0 0 0
  94646. - 0 0 0 0 0 0 0 0 0 0 0 0
  94647. - 0 0 0 0 0 0 0 0 0 10 10 10
  94648. - 38 38 38 86 86 86 14 14 14 10 10 10
  94649. -195 195 195 188 164 115 192 133 9 225 175 15
  94650. -239 182 13 234 190 10 232 195 16 232 200 30
  94651. -245 207 45 241 208 19 232 195 16 184 144 12
  94652. -218 194 134 211 206 186 42 42 42 2 2 6
  94653. - 2 2 6 2 2 6 2 2 6 2 2 6
  94654. - 50 50 50 74 74 74 30 30 30 6 6 6
  94655. - 0 0 0 0 0 0 0 0 0 0 0 0
  94656. - 0 0 0 0 0 0 0 0 0 0 0 0
  94657. - 0 0 0 0 0 0 0 0 0 0 0 0
  94658. - 0 0 0 0 0 0 0 0 0 0 0 0
  94659. - 0 0 0 0 0 0 0 0 0 0 0 0
  94660. - 0 0 0 0 0 0 0 0 0 0 0 0
  94661. - 0 0 0 0 0 0 0 0 0 0 0 0
  94662. - 0 0 0 0 0 0 0 0 0 0 0 0
  94663. - 0 0 0 0 0 0 0 0 0 0 0 0
  94664. - 0 0 0 0 0 0 0 0 0 0 0 0
  94665. - 0 0 0 0 0 0 0 0 0 0 0 0
  94666. - 0 0 0 0 0 0 0 0 0 0 0 0
  94667. - 0 0 0 0 0 0 0 0 0 10 10 10
  94668. - 34 34 34 86 86 86 14 14 14 2 2 6
  94669. -121 87 25 192 133 9 219 162 10 239 182 13
  94670. -236 186 11 232 195 16 241 208 19 244 214 54
  94671. -246 218 60 246 218 38 246 215 20 241 208 19
  94672. -241 208 19 226 184 13 121 87 25 2 2 6
  94673. - 2 2 6 2 2 6 2 2 6 2 2 6
  94674. - 50 50 50 82 82 82 34 34 34 10 10 10
  94675. - 0 0 0 0 0 0 0 0 0 0 0 0
  94676. - 0 0 0 0 0 0 0 0 0 0 0 0
  94677. - 0 0 0 0 0 0 0 0 0 0 0 0
  94678. - 0 0 0 0 0 0 0 0 0 0 0 0
  94679. - 0 0 0 0 0 0 0 0 0 0 0 0
  94680. - 0 0 0 0 0 0 0 0 0 0 0 0
  94681. - 0 0 0 0 0 0 0 0 0 0 0 0
  94682. - 0 0 0 0 0 0 0 0 0 0 0 0
  94683. - 0 0 0 0 0 0 0 0 0 0 0 0
  94684. - 0 0 0 0 0 0 0 0 0 0 0 0
  94685. - 0 0 0 0 0 0 0 0 0 0 0 0
  94686. - 0 0 0 0 0 0 0 0 0 0 0 0
  94687. - 0 0 0 0 0 0 0 0 0 10 10 10
  94688. - 34 34 34 82 82 82 30 30 30 61 42 6
  94689. -180 123 7 206 145 10 230 174 11 239 182 13
  94690. -234 190 10 238 202 15 241 208 19 246 218 74
  94691. -246 218 38 246 215 20 246 215 20 246 215 20
  94692. -226 184 13 215 174 15 184 144 12 6 6 6
  94693. - 2 2 6 2 2 6 2 2 6 2 2 6
  94694. - 26 26 26 94 94 94 42 42 42 14 14 14
  94695. - 0 0 0 0 0 0 0 0 0 0 0 0
  94696. - 0 0 0 0 0 0 0 0 0 0 0 0
  94697. - 0 0 0 0 0 0 0 0 0 0 0 0
  94698. - 0 0 0 0 0 0 0 0 0 0 0 0
  94699. - 0 0 0 0 0 0 0 0 0 0 0 0
  94700. - 0 0 0 0 0 0 0 0 0 0 0 0
  94701. - 0 0 0 0 0 0 0 0 0 0 0 0
  94702. - 0 0 0 0 0 0 0 0 0 0 0 0
  94703. - 0 0 0 0 0 0 0 0 0 0 0 0
  94704. - 0 0 0 0 0 0 0 0 0 0 0 0
  94705. - 0 0 0 0 0 0 0 0 0 0 0 0
  94706. - 0 0 0 0 0 0 0 0 0 0 0 0
  94707. - 0 0 0 0 0 0 0 0 0 10 10 10
  94708. - 30 30 30 78 78 78 50 50 50 104 69 6
  94709. -192 133 9 216 158 10 236 178 12 236 186 11
  94710. -232 195 16 241 208 19 244 214 54 245 215 43
  94711. -246 215 20 246 215 20 241 208 19 198 155 10
  94712. -200 144 11 216 158 10 156 118 10 2 2 6
  94713. - 2 2 6 2 2 6 2 2 6 2 2 6
  94714. - 6 6 6 90 90 90 54 54 54 18 18 18
  94715. - 6 6 6 0 0 0 0 0 0 0 0 0
  94716. - 0 0 0 0 0 0 0 0 0 0 0 0
  94717. - 0 0 0 0 0 0 0 0 0 0 0 0
  94718. - 0 0 0 0 0 0 0 0 0 0 0 0
  94719. - 0 0 0 0 0 0 0 0 0 0 0 0
  94720. - 0 0 0 0 0 0 0 0 0 0 0 0
  94721. - 0 0 0 0 0 0 0 0 0 0 0 0
  94722. - 0 0 0 0 0 0 0 0 0 0 0 0
  94723. - 0 0 0 0 0 0 0 0 0 0 0 0
  94724. - 0 0 0 0 0 0 0 0 0 0 0 0
  94725. - 0 0 0 0 0 0 0 0 0 0 0 0
  94726. - 0 0 0 0 0 0 0 0 0 0 0 0
  94727. - 0 0 0 0 0 0 0 0 0 10 10 10
  94728. - 30 30 30 78 78 78 46 46 46 22 22 22
  94729. -137 92 6 210 162 10 239 182 13 238 190 10
  94730. -238 202 15 241 208 19 246 215 20 246 215 20
  94731. -241 208 19 203 166 17 185 133 11 210 150 10
  94732. -216 158 10 210 150 10 102 78 10 2 2 6
  94733. - 6 6 6 54 54 54 14 14 14 2 2 6
  94734. - 2 2 6 62 62 62 74 74 74 30 30 30
  94735. - 10 10 10 0 0 0 0 0 0 0 0 0
  94736. - 0 0 0 0 0 0 0 0 0 0 0 0
  94737. - 0 0 0 0 0 0 0 0 0 0 0 0
  94738. - 0 0 0 0 0 0 0 0 0 0 0 0
  94739. - 0 0 0 0 0 0 0 0 0 0 0 0
  94740. - 0 0 0 0 0 0 0 0 0 0 0 0
  94741. - 0 0 0 0 0 0 0 0 0 0 0 0
  94742. - 0 0 0 0 0 0 0 0 0 0 0 0
  94743. - 0 0 0 0 0 0 0 0 0 0 0 0
  94744. - 0 0 0 0 0 0 0 0 0 0 0 0
  94745. - 0 0 0 0 0 0 0 0 0 0 0 0
  94746. - 0 0 0 0 0 0 0 0 0 0 0 0
  94747. - 0 0 0 0 0 0 0 0 0 10 10 10
  94748. - 34 34 34 78 78 78 50 50 50 6 6 6
  94749. - 94 70 30 139 102 15 190 146 13 226 184 13
  94750. -232 200 30 232 195 16 215 174 15 190 146 13
  94751. -168 122 10 192 133 9 210 150 10 213 154 11
  94752. -202 150 34 182 157 106 101 98 89 2 2 6
  94753. - 2 2 6 78 78 78 116 116 116 58 58 58
  94754. - 2 2 6 22 22 22 90 90 90 46 46 46
  94755. - 18 18 18 6 6 6 0 0 0 0 0 0
  94756. - 0 0 0 0 0 0 0 0 0 0 0 0
  94757. - 0 0 0 0 0 0 0 0 0 0 0 0
  94758. - 0 0 0 0 0 0 0 0 0 0 0 0
  94759. - 0 0 0 0 0 0 0 0 0 0 0 0
  94760. - 0 0 0 0 0 0 0 0 0 0 0 0
  94761. - 0 0 0 0 0 0 0 0 0 0 0 0
  94762. - 0 0 0 0 0 0 0 0 0 0 0 0
  94763. - 0 0 0 0 0 0 0 0 0 0 0 0
  94764. - 0 0 0 0 0 0 0 0 0 0 0 0
  94765. - 0 0 0 0 0 0 0 0 0 0 0 0
  94766. - 0 0 0 0 0 0 0 0 0 0 0 0
  94767. - 0 0 0 0 0 0 0 0 0 10 10 10
  94768. - 38 38 38 86 86 86 50 50 50 6 6 6
  94769. -128 128 128 174 154 114 156 107 11 168 122 10
  94770. -198 155 10 184 144 12 197 138 11 200 144 11
  94771. -206 145 10 206 145 10 197 138 11 188 164 115
  94772. -195 195 195 198 198 198 174 174 174 14 14 14
  94773. - 2 2 6 22 22 22 116 116 116 116 116 116
  94774. - 22 22 22 2 2 6 74 74 74 70 70 70
  94775. - 30 30 30 10 10 10 0 0 0 0 0 0
  94776. - 0 0 0 0 0 0 0 0 0 0 0 0
  94777. - 0 0 0 0 0 0 0 0 0 0 0 0
  94778. - 0 0 0 0 0 0 0 0 0 0 0 0
  94779. - 0 0 0 0 0 0 0 0 0 0 0 0
  94780. - 0 0 0 0 0 0 0 0 0 0 0 0
  94781. - 0 0 0 0 0 0 0 0 0 0 0 0
  94782. - 0 0 0 0 0 0 0 0 0 0 0 0
  94783. - 0 0 0 0 0 0 0 0 0 0 0 0
  94784. - 0 0 0 0 0 0 0 0 0 0 0 0
  94785. - 0 0 0 0 0 0 0 0 0 0 0 0
  94786. - 0 0 0 0 0 0 0 0 0 0 0 0
  94787. - 0 0 0 0 0 0 6 6 6 18 18 18
  94788. - 50 50 50 101 101 101 26 26 26 10 10 10
  94789. -138 138 138 190 190 190 174 154 114 156 107 11
  94790. -197 138 11 200 144 11 197 138 11 192 133 9
  94791. -180 123 7 190 142 34 190 178 144 187 187 187
  94792. -202 202 202 221 221 221 214 214 214 66 66 66
  94793. - 2 2 6 2 2 6 50 50 50 62 62 62
  94794. - 6 6 6 2 2 6 10 10 10 90 90 90
  94795. - 50 50 50 18 18 18 6 6 6 0 0 0
  94796. - 0 0 0 0 0 0 0 0 0 0 0 0
  94797. - 0 0 0 0 0 0 0 0 0 0 0 0
  94798. - 0 0 0 0 0 0 0 0 0 0 0 0
  94799. - 0 0 0 0 0 0 0 0 0 0 0 0
  94800. - 0 0 0 0 0 0 0 0 0 0 0 0
  94801. - 0 0 0 0 0 0 0 0 0 0 0 0
  94802. - 0 0 0 0 0 0 0 0 0 0 0 0
  94803. - 0 0 0 0 0 0 0 0 0 0 0 0
  94804. - 0 0 0 0 0 0 0 0 0 0 0 0
  94805. - 0 0 0 0 0 0 0 0 0 0 0 0
  94806. - 0 0 0 0 0 0 0 0 0 0 0 0
  94807. - 0 0 0 0 0 0 10 10 10 34 34 34
  94808. - 74 74 74 74 74 74 2 2 6 6 6 6
  94809. -144 144 144 198 198 198 190 190 190 178 166 146
  94810. -154 121 60 156 107 11 156 107 11 168 124 44
  94811. -174 154 114 187 187 187 190 190 190 210 210 210
  94812. -246 246 246 253 253 253 253 253 253 182 182 182
  94813. - 6 6 6 2 2 6 2 2 6 2 2 6
  94814. - 2 2 6 2 2 6 2 2 6 62 62 62
  94815. - 74 74 74 34 34 34 14 14 14 0 0 0
  94816. - 0 0 0 0 0 0 0 0 0 0 0 0
  94817. - 0 0 0 0 0 0 0 0 0 0 0 0
  94818. - 0 0 0 0 0 0 0 0 0 0 0 0
  94819. - 0 0 0 0 0 0 0 0 0 0 0 0
  94820. - 0 0 0 0 0 0 0 0 0 0 0 0
  94821. - 0 0 0 0 0 0 0 0 0 0 0 0
  94822. - 0 0 0 0 0 0 0 0 0 0 0 0
  94823. - 0 0 0 0 0 0 0 0 0 0 0 0
  94824. - 0 0 0 0 0 0 0 0 0 0 0 0
  94825. - 0 0 0 0 0 0 0 0 0 0 0 0
  94826. - 0 0 0 0 0 0 0 0 0 0 0 0
  94827. - 0 0 0 10 10 10 22 22 22 54 54 54
  94828. - 94 94 94 18 18 18 2 2 6 46 46 46
  94829. -234 234 234 221 221 221 190 190 190 190 190 190
  94830. -190 190 190 187 187 187 187 187 187 190 190 190
  94831. -190 190 190 195 195 195 214 214 214 242 242 242
  94832. -253 253 253 253 253 253 253 253 253 253 253 253
  94833. - 82 82 82 2 2 6 2 2 6 2 2 6
  94834. - 2 2 6 2 2 6 2 2 6 14 14 14
  94835. - 86 86 86 54 54 54 22 22 22 6 6 6
  94836. - 0 0 0 0 0 0 0 0 0 0 0 0
  94837. - 0 0 0 0 0 0 0 0 0 0 0 0
  94838. - 0 0 0 0 0 0 0 0 0 0 0 0
  94839. - 0 0 0 0 0 0 0 0 0 0 0 0
  94840. - 0 0 0 0 0 0 0 0 0 0 0 0
  94841. - 0 0 0 0 0 0 0 0 0 0 0 0
  94842. - 0 0 0 0 0 0 0 0 0 0 0 0
  94843. - 0 0 0 0 0 0 0 0 0 0 0 0
  94844. - 0 0 0 0 0 0 0 0 0 0 0 0
  94845. - 0 0 0 0 0 0 0 0 0 0 0 0
  94846. - 0 0 0 0 0 0 0 0 0 0 0 0
  94847. - 6 6 6 18 18 18 46 46 46 90 90 90
  94848. - 46 46 46 18 18 18 6 6 6 182 182 182
  94849. -253 253 253 246 246 246 206 206 206 190 190 190
  94850. -190 190 190 190 190 190 190 190 190 190 190 190
  94851. -206 206 206 231 231 231 250 250 250 253 253 253
  94852. -253 253 253 253 253 253 253 253 253 253 253 253
  94853. -202 202 202 14 14 14 2 2 6 2 2 6
  94854. - 2 2 6 2 2 6 2 2 6 2 2 6
  94855. - 42 42 42 86 86 86 42 42 42 18 18 18
  94856. - 6 6 6 0 0 0 0 0 0 0 0 0
  94857. - 0 0 0 0 0 0 0 0 0 0 0 0
  94858. - 0 0 0 0 0 0 0 0 0 0 0 0
  94859. - 0 0 0 0 0 0 0 0 0 0 0 0
  94860. - 0 0 0 0 0 0 0 0 0 0 0 0
  94861. - 0 0 0 0 0 0 0 0 0 0 0 0
  94862. - 0 0 0 0 0 0 0 0 0 0 0 0
  94863. - 0 0 0 0 0 0 0 0 0 0 0 0
  94864. - 0 0 0 0 0 0 0 0 0 0 0 0
  94865. - 0 0 0 0 0 0 0 0 0 0 0 0
  94866. - 0 0 0 0 0 0 0 0 0 6 6 6
  94867. - 14 14 14 38 38 38 74 74 74 66 66 66
  94868. - 2 2 6 6 6 6 90 90 90 250 250 250
  94869. -253 253 253 253 253 253 238 238 238 198 198 198
  94870. -190 190 190 190 190 190 195 195 195 221 221 221
  94871. -246 246 246 253 253 253 253 253 253 253 253 253
  94872. -253 253 253 253 253 253 253 253 253 253 253 253
  94873. -253 253 253 82 82 82 2 2 6 2 2 6
  94874. - 2 2 6 2 2 6 2 2 6 2 2 6
  94875. - 2 2 6 78 78 78 70 70 70 34 34 34
  94876. - 14 14 14 6 6 6 0 0 0 0 0 0
  94877. - 0 0 0 0 0 0 0 0 0 0 0 0
  94878. - 0 0 0 0 0 0 0 0 0 0 0 0
  94879. - 0 0 0 0 0 0 0 0 0 0 0 0
  94880. - 0 0 0 0 0 0 0 0 0 0 0 0
  94881. - 0 0 0 0 0 0 0 0 0 0 0 0
  94882. - 0 0 0 0 0 0 0 0 0 0 0 0
  94883. - 0 0 0 0 0 0 0 0 0 0 0 0
  94884. - 0 0 0 0 0 0 0 0 0 0 0 0
  94885. - 0 0 0 0 0 0 0 0 0 0 0 0
  94886. - 0 0 0 0 0 0 0 0 0 14 14 14
  94887. - 34 34 34 66 66 66 78 78 78 6 6 6
  94888. - 2 2 6 18 18 18 218 218 218 253 253 253
  94889. -253 253 253 253 253 253 253 253 253 246 246 246
  94890. -226 226 226 231 231 231 246 246 246 253 253 253
  94891. -253 253 253 253 253 253 253 253 253 253 253 253
  94892. -253 253 253 253 253 253 253 253 253 253 253 253
  94893. -253 253 253 178 178 178 2 2 6 2 2 6
  94894. - 2 2 6 2 2 6 2 2 6 2 2 6
  94895. - 2 2 6 18 18 18 90 90 90 62 62 62
  94896. - 30 30 30 10 10 10 0 0 0 0 0 0
  94897. - 0 0 0 0 0 0 0 0 0 0 0 0
  94898. - 0 0 0 0 0 0 0 0 0 0 0 0
  94899. - 0 0 0 0 0 0 0 0 0 0 0 0
  94900. - 0 0 0 0 0 0 0 0 0 0 0 0
  94901. - 0 0 0 0 0 0 0 0 0 0 0 0
  94902. - 0 0 0 0 0 0 0 0 0 0 0 0
  94903. - 0 0 0 0 0 0 0 0 0 0 0 0
  94904. - 0 0 0 0 0 0 0 0 0 0 0 0
  94905. - 0 0 0 0 0 0 0 0 0 0 0 0
  94906. - 0 0 0 0 0 0 10 10 10 26 26 26
  94907. - 58 58 58 90 90 90 18 18 18 2 2 6
  94908. - 2 2 6 110 110 110 253 253 253 253 253 253
  94909. -253 253 253 253 253 253 253 253 253 253 253 253
  94910. -250 250 250 253 253 253 253 253 253 253 253 253
  94911. -253 253 253 253 253 253 253 253 253 253 253 253
  94912. -253 253 253 253 253 253 253 253 253 253 253 253
  94913. -253 253 253 231 231 231 18 18 18 2 2 6
  94914. - 2 2 6 2 2 6 2 2 6 2 2 6
  94915. - 2 2 6 2 2 6 18 18 18 94 94 94
  94916. - 54 54 54 26 26 26 10 10 10 0 0 0
  94917. - 0 0 0 0 0 0 0 0 0 0 0 0
  94918. - 0 0 0 0 0 0 0 0 0 0 0 0
  94919. - 0 0 0 0 0 0 0 0 0 0 0 0
  94920. - 0 0 0 0 0 0 0 0 0 0 0 0
  94921. - 0 0 0 0 0 0 0 0 0 0 0 0
  94922. - 0 0 0 0 0 0 0 0 0 0 0 0
  94923. - 0 0 0 0 0 0 0 0 0 0 0 0
  94924. - 0 0 0 0 0 0 0 0 0 0 0 0
  94925. - 0 0 0 0 0 0 0 0 0 0 0 0
  94926. - 0 0 0 6 6 6 22 22 22 50 50 50
  94927. - 90 90 90 26 26 26 2 2 6 2 2 6
  94928. - 14 14 14 195 195 195 250 250 250 253 253 253
  94929. -253 253 253 253 253 253 253 253 253 253 253 253
  94930. -253 253 253 253 253 253 253 253 253 253 253 253
  94931. -253 253 253 253 253 253 253 253 253 253 253 253
  94932. -253 253 253 253 253 253 253 253 253 253 253 253
  94933. -250 250 250 242 242 242 54 54 54 2 2 6
  94934. - 2 2 6 2 2 6 2 2 6 2 2 6
  94935. - 2 2 6 2 2 6 2 2 6 38 38 38
  94936. - 86 86 86 50 50 50 22 22 22 6 6 6
  94937. - 0 0 0 0 0 0 0 0 0 0 0 0
  94938. - 0 0 0 0 0 0 0 0 0 0 0 0
  94939. - 0 0 0 0 0 0 0 0 0 0 0 0
  94940. - 0 0 0 0 0 0 0 0 0 0 0 0
  94941. - 0 0 0 0 0 0 0 0 0 0 0 0
  94942. - 0 0 0 0 0 0 0 0 0 0 0 0
  94943. - 0 0 0 0 0 0 0 0 0 0 0 0
  94944. - 0 0 0 0 0 0 0 0 0 0 0 0
  94945. - 0 0 0 0 0 0 0 0 0 0 0 0
  94946. - 6 6 6 14 14 14 38 38 38 82 82 82
  94947. - 34 34 34 2 2 6 2 2 6 2 2 6
  94948. - 42 42 42 195 195 195 246 246 246 253 253 253
  94949. -253 253 253 253 253 253 253 253 253 250 250 250
  94950. -242 242 242 242 242 242 250 250 250 253 253 253
  94951. -253 253 253 253 253 253 253 253 253 253 253 253
  94952. -253 253 253 250 250 250 246 246 246 238 238 238
  94953. -226 226 226 231 231 231 101 101 101 6 6 6
  94954. - 2 2 6 2 2 6 2 2 6 2 2 6
  94955. - 2 2 6 2 2 6 2 2 6 2 2 6
  94956. - 38 38 38 82 82 82 42 42 42 14 14 14
  94957. - 6 6 6 0 0 0 0 0 0 0 0 0
  94958. - 0 0 0 0 0 0 0 0 0 0 0 0
  94959. - 0 0 0 0 0 0 0 0 0 0 0 0
  94960. - 0 0 0 0 0 0 0 0 0 0 0 0
  94961. - 0 0 0 0 0 0 0 0 0 0 0 0
  94962. - 0 0 0 0 0 0 0 0 0 0 0 0
  94963. - 0 0 0 0 0 0 0 0 0 0 0 0
  94964. - 0 0 0 0 0 0 0 0 0 0 0 0
  94965. - 0 0 0 0 0 0 0 0 0 0 0 0
  94966. - 10 10 10 26 26 26 62 62 62 66 66 66
  94967. - 2 2 6 2 2 6 2 2 6 6 6 6
  94968. - 70 70 70 170 170 170 206 206 206 234 234 234
  94969. -246 246 246 250 250 250 250 250 250 238 238 238
  94970. -226 226 226 231 231 231 238 238 238 250 250 250
  94971. -250 250 250 250 250 250 246 246 246 231 231 231
  94972. -214 214 214 206 206 206 202 202 202 202 202 202
  94973. -198 198 198 202 202 202 182 182 182 18 18 18
  94974. - 2 2 6 2 2 6 2 2 6 2 2 6
  94975. - 2 2 6 2 2 6 2 2 6 2 2 6
  94976. - 2 2 6 62 62 62 66 66 66 30 30 30
  94977. - 10 10 10 0 0 0 0 0 0 0 0 0
  94978. - 0 0 0 0 0 0 0 0 0 0 0 0
  94979. - 0 0 0 0 0 0 0 0 0 0 0 0
  94980. - 0 0 0 0 0 0 0 0 0 0 0 0
  94981. - 0 0 0 0 0 0 0 0 0 0 0 0
  94982. - 0 0 0 0 0 0 0 0 0 0 0 0
  94983. - 0 0 0 0 0 0 0 0 0 0 0 0
  94984. - 0 0 0 0 0 0 0 0 0 0 0 0
  94985. - 0 0 0 0 0 0 0 0 0 0 0 0
  94986. - 14 14 14 42 42 42 82 82 82 18 18 18
  94987. - 2 2 6 2 2 6 2 2 6 10 10 10
  94988. - 94 94 94 182 182 182 218 218 218 242 242 242
  94989. -250 250 250 253 253 253 253 253 253 250 250 250
  94990. -234 234 234 253 253 253 253 253 253 253 253 253
  94991. -253 253 253 253 253 253 253 253 253 246 246 246
  94992. -238 238 238 226 226 226 210 210 210 202 202 202
  94993. -195 195 195 195 195 195 210 210 210 158 158 158
  94994. - 6 6 6 14 14 14 50 50 50 14 14 14
  94995. - 2 2 6 2 2 6 2 2 6 2 2 6
  94996. - 2 2 6 6 6 6 86 86 86 46 46 46
  94997. - 18 18 18 6 6 6 0 0 0 0 0 0
  94998. - 0 0 0 0 0 0 0 0 0 0 0 0
  94999. - 0 0 0 0 0 0 0 0 0 0 0 0
  95000. - 0 0 0 0 0 0 0 0 0 0 0 0
  95001. - 0 0 0 0 0 0 0 0 0 0 0 0
  95002. - 0 0 0 0 0 0 0 0 0 0 0 0
  95003. - 0 0 0 0 0 0 0 0 0 0 0 0
  95004. - 0 0 0 0 0 0 0 0 0 0 0 0
  95005. - 0 0 0 0 0 0 0 0 0 6 6 6
  95006. - 22 22 22 54 54 54 70 70 70 2 2 6
  95007. - 2 2 6 10 10 10 2 2 6 22 22 22
  95008. -166 166 166 231 231 231 250 250 250 253 253 253
  95009. -253 253 253 253 253 253 253 253 253 250 250 250
  95010. -242 242 242 253 253 253 253 253 253 253 253 253
  95011. -253 253 253 253 253 253 253 253 253 253 253 253
  95012. -253 253 253 253 253 253 253 253 253 246 246 246
  95013. -231 231 231 206 206 206 198 198 198 226 226 226
  95014. - 94 94 94 2 2 6 6 6 6 38 38 38
  95015. - 30 30 30 2 2 6 2 2 6 2 2 6
  95016. - 2 2 6 2 2 6 62 62 62 66 66 66
  95017. - 26 26 26 10 10 10 0 0 0 0 0 0
  95018. - 0 0 0 0 0 0 0 0 0 0 0 0
  95019. - 0 0 0 0 0 0 0 0 0 0 0 0
  95020. - 0 0 0 0 0 0 0 0 0 0 0 0
  95021. - 0 0 0 0 0 0 0 0 0 0 0 0
  95022. - 0 0 0 0 0 0 0 0 0 0 0 0
  95023. - 0 0 0 0 0 0 0 0 0 0 0 0
  95024. - 0 0 0 0 0 0 0 0 0 0 0 0
  95025. - 0 0 0 0 0 0 0 0 0 10 10 10
  95026. - 30 30 30 74 74 74 50 50 50 2 2 6
  95027. - 26 26 26 26 26 26 2 2 6 106 106 106
  95028. -238 238 238 253 253 253 253 253 253 253 253 253
  95029. -253 253 253 253 253 253 253 253 253 253 253 253
  95030. -253 253 253 253 253 253 253 253 253 253 253 253
  95031. -253 253 253 253 253 253 253 253 253 253 253 253
  95032. -253 253 253 253 253 253 253 253 253 253 253 253
  95033. -253 253 253 246 246 246 218 218 218 202 202 202
  95034. -210 210 210 14 14 14 2 2 6 2 2 6
  95035. - 30 30 30 22 22 22 2 2 6 2 2 6
  95036. - 2 2 6 2 2 6 18 18 18 86 86 86
  95037. - 42 42 42 14 14 14 0 0 0 0 0 0
  95038. - 0 0 0 0 0 0 0 0 0 0 0 0
  95039. - 0 0 0 0 0 0 0 0 0 0 0 0
  95040. - 0 0 0 0 0 0 0 0 0 0 0 0
  95041. - 0 0 0 0 0 0 0 0 0 0 0 0
  95042. - 0 0 0 0 0 0 0 0 0 0 0 0
  95043. - 0 0 0 0 0 0 0 0 0 0 0 0
  95044. - 0 0 0 0 0 0 0 0 0 0 0 0
  95045. - 0 0 0 0 0 0 0 0 0 14 14 14
  95046. - 42 42 42 90 90 90 22 22 22 2 2 6
  95047. - 42 42 42 2 2 6 18 18 18 218 218 218
  95048. -253 253 253 253 253 253 253 253 253 253 253 253
  95049. -253 253 253 253 253 253 253 253 253 253 253 253
  95050. -253 253 253 253 253 253 253 253 253 253 253 253
  95051. -253 253 253 253 253 253 253 253 253 253 253 253
  95052. -253 253 253 253 253 253 253 253 253 253 253 253
  95053. -253 253 253 253 253 253 250 250 250 221 221 221
  95054. -218 218 218 101 101 101 2 2 6 14 14 14
  95055. - 18 18 18 38 38 38 10 10 10 2 2 6
  95056. - 2 2 6 2 2 6 2 2 6 78 78 78
  95057. - 58 58 58 22 22 22 6 6 6 0 0 0
  95058. - 0 0 0 0 0 0 0 0 0 0 0 0
  95059. - 0 0 0 0 0 0 0 0 0 0 0 0
  95060. - 0 0 0 0 0 0 0 0 0 0 0 0
  95061. - 0 0 0 0 0 0 0 0 0 0 0 0
  95062. - 0 0 0 0 0 0 0 0 0 0 0 0
  95063. - 0 0 0 0 0 0 0 0 0 0 0 0
  95064. - 0 0 0 0 0 0 0 0 0 0 0 0
  95065. - 0 0 0 0 0 0 6 6 6 18 18 18
  95066. - 54 54 54 82 82 82 2 2 6 26 26 26
  95067. - 22 22 22 2 2 6 123 123 123 253 253 253
  95068. -253 253 253 253 253 253 253 253 253 253 253 253
  95069. -253 253 253 253 253 253 253 253 253 253 253 253
  95070. -253 253 253 253 253 253 253 253 253 253 253 253
  95071. -253 253 253 253 253 253 253 253 253 253 253 253
  95072. -253 253 253 253 253 253 253 253 253 253 253 253
  95073. -253 253 253 253 253 253 253 253 253 250 250 250
  95074. -238 238 238 198 198 198 6 6 6 38 38 38
  95075. - 58 58 58 26 26 26 38 38 38 2 2 6
  95076. - 2 2 6 2 2 6 2 2 6 46 46 46
  95077. - 78 78 78 30 30 30 10 10 10 0 0 0
  95078. - 0 0 0 0 0 0 0 0 0 0 0 0
  95079. - 0 0 0 0 0 0 0 0 0 0 0 0
  95080. - 0 0 0 0 0 0 0 0 0 0 0 0
  95081. - 0 0 0 0 0 0 0 0 0 0 0 0
  95082. - 0 0 0 0 0 0 0 0 0 0 0 0
  95083. - 0 0 0 0 0 0 0 0 0 0 0 0
  95084. - 0 0 0 0 0 0 0 0 0 0 0 0
  95085. - 0 0 0 0 0 0 10 10 10 30 30 30
  95086. - 74 74 74 58 58 58 2 2 6 42 42 42
  95087. - 2 2 6 22 22 22 231 231 231 253 253 253
  95088. -253 253 253 253 253 253 253 253 253 253 253 253
  95089. -253 253 253 253 253 253 253 253 253 250 250 250
  95090. -253 253 253 253 253 253 253 253 253 253 253 253
  95091. -253 253 253 253 253 253 253 253 253 253 253 253
  95092. -253 253 253 253 253 253 253 253 253 253 253 253
  95093. -253 253 253 253 253 253 253 253 253 253 253 253
  95094. -253 253 253 246 246 246 46 46 46 38 38 38
  95095. - 42 42 42 14 14 14 38 38 38 14 14 14
  95096. - 2 2 6 2 2 6 2 2 6 6 6 6
  95097. - 86 86 86 46 46 46 14 14 14 0 0 0
  95098. - 0 0 0 0 0 0 0 0 0 0 0 0
  95099. - 0 0 0 0 0 0 0 0 0 0 0 0
  95100. - 0 0 0 0 0 0 0 0 0 0 0 0
  95101. - 0 0 0 0 0 0 0 0 0 0 0 0
  95102. - 0 0 0 0 0 0 0 0 0 0 0 0
  95103. - 0 0 0 0 0 0 0 0 0 0 0 0
  95104. - 0 0 0 0 0 0 0 0 0 0 0 0
  95105. - 0 0 0 6 6 6 14 14 14 42 42 42
  95106. - 90 90 90 18 18 18 18 18 18 26 26 26
  95107. - 2 2 6 116 116 116 253 253 253 253 253 253
  95108. -253 253 253 253 253 253 253 253 253 253 253 253
  95109. -253 253 253 253 253 253 250 250 250 238 238 238
  95110. -253 253 253 253 253 253 253 253 253 253 253 253
  95111. -253 253 253 253 253 253 253 253 253 253 253 253
  95112. -253 253 253 253 253 253 253 253 253 253 253 253
  95113. -253 253 253 253 253 253 253 253 253 253 253 253
  95114. -253 253 253 253 253 253 94 94 94 6 6 6
  95115. - 2 2 6 2 2 6 10 10 10 34 34 34
  95116. - 2 2 6 2 2 6 2 2 6 2 2 6
  95117. - 74 74 74 58 58 58 22 22 22 6 6 6
  95118. - 0 0 0 0 0 0 0 0 0 0 0 0
  95119. - 0 0 0 0 0 0 0 0 0 0 0 0
  95120. - 0 0 0 0 0 0 0 0 0 0 0 0
  95121. - 0 0 0 0 0 0 0 0 0 0 0 0
  95122. - 0 0 0 0 0 0 0 0 0 0 0 0
  95123. - 0 0 0 0 0 0 0 0 0 0 0 0
  95124. - 0 0 0 0 0 0 0 0 0 0 0 0
  95125. - 0 0 0 10 10 10 26 26 26 66 66 66
  95126. - 82 82 82 2 2 6 38 38 38 6 6 6
  95127. - 14 14 14 210 210 210 253 253 253 253 253 253
  95128. -253 253 253 253 253 253 253 253 253 253 253 253
  95129. -253 253 253 253 253 253 246 246 246 242 242 242
  95130. -253 253 253 253 253 253 253 253 253 253 253 253
  95131. -253 253 253 253 253 253 253 253 253 253 253 253
  95132. -253 253 253 253 253 253 253 253 253 253 253 253
  95133. -253 253 253 253 253 253 253 253 253 253 253 253
  95134. -253 253 253 253 253 253 144 144 144 2 2 6
  95135. - 2 2 6 2 2 6 2 2 6 46 46 46
  95136. - 2 2 6 2 2 6 2 2 6 2 2 6
  95137. - 42 42 42 74 74 74 30 30 30 10 10 10
  95138. - 0 0 0 0 0 0 0 0 0 0 0 0
  95139. - 0 0 0 0 0 0 0 0 0 0 0 0
  95140. - 0 0 0 0 0 0 0 0 0 0 0 0
  95141. - 0 0 0 0 0 0 0 0 0 0 0 0
  95142. - 0 0 0 0 0 0 0 0 0 0 0 0
  95143. - 0 0 0 0 0 0 0 0 0 0 0 0
  95144. - 0 0 0 0 0 0 0 0 0 0 0 0
  95145. - 6 6 6 14 14 14 42 42 42 90 90 90
  95146. - 26 26 26 6 6 6 42 42 42 2 2 6
  95147. - 74 74 74 250 250 250 253 253 253 253 253 253
  95148. -253 253 253 253 253 253 253 253 253 253 253 253
  95149. -253 253 253 253 253 253 242 242 242 242 242 242
  95150. -253 253 253 253 253 253 253 253 253 253 253 253
  95151. -253 253 253 253 253 253 253 253 253 253 253 253
  95152. -253 253 253 253 253 253 253 253 253 253 253 253
  95153. -253 253 253 253 253 253 253 253 253 253 253 253
  95154. -253 253 253 253 253 253 182 182 182 2 2 6
  95155. - 2 2 6 2 2 6 2 2 6 46 46 46
  95156. - 2 2 6 2 2 6 2 2 6 2 2 6
  95157. - 10 10 10 86 86 86 38 38 38 10 10 10
  95158. - 0 0 0 0 0 0 0 0 0 0 0 0
  95159. - 0 0 0 0 0 0 0 0 0 0 0 0
  95160. - 0 0 0 0 0 0 0 0 0 0 0 0
  95161. - 0 0 0 0 0 0 0 0 0 0 0 0
  95162. - 0 0 0 0 0 0 0 0 0 0 0 0
  95163. - 0 0 0 0 0 0 0 0 0 0 0 0
  95164. - 0 0 0 0 0 0 0 0 0 0 0 0
  95165. - 10 10 10 26 26 26 66 66 66 82 82 82
  95166. - 2 2 6 22 22 22 18 18 18 2 2 6
  95167. -149 149 149 253 253 253 253 253 253 253 253 253
  95168. -253 253 253 253 253 253 253 253 253 253 253 253
  95169. -253 253 253 253 253 253 234 234 234 242 242 242
  95170. -253 253 253 253 253 253 253 253 253 253 253 253
  95171. -253 253 253 253 253 253 253 253 253 253 253 253
  95172. -253 253 253 253 253 253 253 253 253 253 253 253
  95173. -253 253 253 253 253 253 253 253 253 253 253 253
  95174. -253 253 253 253 253 253 206 206 206 2 2 6
  95175. - 2 2 6 2 2 6 2 2 6 38 38 38
  95176. - 2 2 6 2 2 6 2 2 6 2 2 6
  95177. - 6 6 6 86 86 86 46 46 46 14 14 14
  95178. - 0 0 0 0 0 0 0 0 0 0 0 0
  95179. - 0 0 0 0 0 0 0 0 0 0 0 0
  95180. - 0 0 0 0 0 0 0 0 0 0 0 0
  95181. - 0 0 0 0 0 0 0 0 0 0 0 0
  95182. - 0 0 0 0 0 0 0 0 0 0 0 0
  95183. - 0 0 0 0 0 0 0 0 0 0 0 0
  95184. - 0 0 0 0 0 0 0 0 0 6 6 6
  95185. - 18 18 18 46 46 46 86 86 86 18 18 18
  95186. - 2 2 6 34 34 34 10 10 10 6 6 6
  95187. -210 210 210 253 253 253 253 253 253 253 253 253
  95188. -253 253 253 253 253 253 253 253 253 253 253 253
  95189. -253 253 253 253 253 253 234 234 234 242 242 242
  95190. -253 253 253 253 253 253 253 253 253 253 253 253
  95191. -253 253 253 253 253 253 253 253 253 253 253 253
  95192. -253 253 253 253 253 253 253 253 253 253 253 253
  95193. -253 253 253 253 253 253 253 253 253 253 253 253
  95194. -253 253 253 253 253 253 221 221 221 6 6 6
  95195. - 2 2 6 2 2 6 6 6 6 30 30 30
  95196. - 2 2 6 2 2 6 2 2 6 2 2 6
  95197. - 2 2 6 82 82 82 54 54 54 18 18 18
  95198. - 6 6 6 0 0 0 0 0 0 0 0 0
  95199. - 0 0 0 0 0 0 0 0 0 0 0 0
  95200. - 0 0 0 0 0 0 0 0 0 0 0 0
  95201. - 0 0 0 0 0 0 0 0 0 0 0 0
  95202. - 0 0 0 0 0 0 0 0 0 0 0 0
  95203. - 0 0 0 0 0 0 0 0 0 0 0 0
  95204. - 0 0 0 0 0 0 0 0 0 10 10 10
  95205. - 26 26 26 66 66 66 62 62 62 2 2 6
  95206. - 2 2 6 38 38 38 10 10 10 26 26 26
  95207. -238 238 238 253 253 253 253 253 253 253 253 253
  95208. -253 253 253 253 253 253 253 253 253 253 253 253
  95209. -253 253 253 253 253 253 231 231 231 238 238 238
  95210. -253 253 253 253 253 253 253 253 253 253 253 253
  95211. -253 253 253 253 253 253 253 253 253 253 253 253
  95212. -253 253 253 253 253 253 253 253 253 253 253 253
  95213. -253 253 253 253 253 253 253 253 253 253 253 253
  95214. -253 253 253 253 253 253 231 231 231 6 6 6
  95215. - 2 2 6 2 2 6 10 10 10 30 30 30
  95216. - 2 2 6 2 2 6 2 2 6 2 2 6
  95217. - 2 2 6 66 66 66 58 58 58 22 22 22
  95218. - 6 6 6 0 0 0 0 0 0 0 0 0
  95219. - 0 0 0 0 0 0 0 0 0 0 0 0
  95220. - 0 0 0 0 0 0 0 0 0 0 0 0
  95221. - 0 0 0 0 0 0 0 0 0 0 0 0
  95222. - 0 0 0 0 0 0 0 0 0 0 0 0
  95223. - 0 0 0 0 0 0 0 0 0 0 0 0
  95224. - 0 0 0 0 0 0 0 0 0 10 10 10
  95225. - 38 38 38 78 78 78 6 6 6 2 2 6
  95226. - 2 2 6 46 46 46 14 14 14 42 42 42
  95227. -246 246 246 253 253 253 253 253 253 253 253 253
  95228. -253 253 253 253 253 253 253 253 253 253 253 253
  95229. -253 253 253 253 253 253 231 231 231 242 242 242
  95230. -253 253 253 253 253 253 253 253 253 253 253 253
  95231. -253 253 253 253 253 253 253 253 253 253 253 253
  95232. -253 253 253 253 253 253 253 253 253 253 253 253
  95233. -253 253 253 253 253 253 253 253 253 253 253 253
  95234. -253 253 253 253 253 253 234 234 234 10 10 10
  95235. - 2 2 6 2 2 6 22 22 22 14 14 14
  95236. - 2 2 6 2 2 6 2 2 6 2 2 6
  95237. - 2 2 6 66 66 66 62 62 62 22 22 22
  95238. - 6 6 6 0 0 0 0 0 0 0 0 0
  95239. - 0 0 0 0 0 0 0 0 0 0 0 0
  95240. - 0 0 0 0 0 0 0 0 0 0 0 0
  95241. - 0 0 0 0 0 0 0 0 0 0 0 0
  95242. - 0 0 0 0 0 0 0 0 0 0 0 0
  95243. - 0 0 0 0 0 0 0 0 0 0 0 0
  95244. - 0 0 0 0 0 0 6 6 6 18 18 18
  95245. - 50 50 50 74 74 74 2 2 6 2 2 6
  95246. - 14 14 14 70 70 70 34 34 34 62 62 62
  95247. -250 250 250 253 253 253 253 253 253 253 253 253
  95248. -253 253 253 253 253 253 253 253 253 253 253 253
  95249. -253 253 253 253 253 253 231 231 231 246 246 246
  95250. -253 253 253 253 253 253 253 253 253 253 253 253
  95251. -253 253 253 253 253 253 253 253 253 253 253 253
  95252. -253 253 253 253 253 253 253 253 253 253 253 253
  95253. -253 253 253 253 253 253 253 253 253 253 253 253
  95254. -253 253 253 253 253 253 234 234 234 14 14 14
  95255. - 2 2 6 2 2 6 30 30 30 2 2 6
  95256. - 2 2 6 2 2 6 2 2 6 2 2 6
  95257. - 2 2 6 66 66 66 62 62 62 22 22 22
  95258. - 6 6 6 0 0 0 0 0 0 0 0 0
  95259. - 0 0 0 0 0 0 0 0 0 0 0 0
  95260. - 0 0 0 0 0 0 0 0 0 0 0 0
  95261. - 0 0 0 0 0 0 0 0 0 0 0 0
  95262. - 0 0 0 0 0 0 0 0 0 0 0 0
  95263. - 0 0 0 0 0 0 0 0 0 0 0 0
  95264. - 0 0 0 0 0 0 6 6 6 18 18 18
  95265. - 54 54 54 62 62 62 2 2 6 2 2 6
  95266. - 2 2 6 30 30 30 46 46 46 70 70 70
  95267. -250 250 250 253 253 253 253 253 253 253 253 253
  95268. -253 253 253 253 253 253 253 253 253 253 253 253
  95269. -253 253 253 253 253 253 231 231 231 246 246 246
  95270. -253 253 253 253 253 253 253 253 253 253 253 253
  95271. -253 253 253 253 253 253 253 253 253 253 253 253
  95272. -253 253 253 253 253 253 253 253 253 253 253 253
  95273. -253 253 253 253 253 253 253 253 253 253 253 253
  95274. -253 253 253 253 253 253 226 226 226 10 10 10
  95275. - 2 2 6 6 6 6 30 30 30 2 2 6
  95276. - 2 2 6 2 2 6 2 2 6 2 2 6
  95277. - 2 2 6 66 66 66 58 58 58 22 22 22
  95278. - 6 6 6 0 0 0 0 0 0 0 0 0
  95279. - 0 0 0 0 0 0 0 0 0 0 0 0
  95280. - 0 0 0 0 0 0 0 0 0 0 0 0
  95281. - 0 0 0 0 0 0 0 0 0 0 0 0
  95282. - 0 0 0 0 0 0 0 0 0 0 0 0
  95283. - 0 0 0 0 0 0 0 0 0 0 0 0
  95284. - 0 0 0 0 0 0 6 6 6 22 22 22
  95285. - 58 58 58 62 62 62 2 2 6 2 2 6
  95286. - 2 2 6 2 2 6 30 30 30 78 78 78
  95287. -250 250 250 253 253 253 253 253 253 253 253 253
  95288. -253 253 253 253 253 253 253 253 253 253 253 253
  95289. -253 253 253 253 253 253 231 231 231 246 246 246
  95290. -253 253 253 253 253 253 253 253 253 253 253 253
  95291. -253 253 253 253 253 253 253 253 253 253 253 253
  95292. -253 253 253 253 253 253 253 253 253 253 253 253
  95293. -253 253 253 253 253 253 253 253 253 253 253 253
  95294. -253 253 253 253 253 253 206 206 206 2 2 6
  95295. - 22 22 22 34 34 34 18 14 6 22 22 22
  95296. - 26 26 26 18 18 18 6 6 6 2 2 6
  95297. - 2 2 6 82 82 82 54 54 54 18 18 18
  95298. - 6 6 6 0 0 0 0 0 0 0 0 0
  95299. - 0 0 0 0 0 0 0 0 0 0 0 0
  95300. - 0 0 0 0 0 0 0 0 0 0 0 0
  95301. - 0 0 0 0 0 0 0 0 0 0 0 0
  95302. - 0 0 0 0 0 0 0 0 0 0 0 0
  95303. - 0 0 0 0 0 0 0 0 0 0 0 0
  95304. - 0 0 0 0 0 0 6 6 6 26 26 26
  95305. - 62 62 62 106 106 106 74 54 14 185 133 11
  95306. -210 162 10 121 92 8 6 6 6 62 62 62
  95307. -238 238 238 253 253 253 253 253 253 253 253 253
  95308. -253 253 253 253 253 253 253 253 253 253 253 253
  95309. -253 253 253 253 253 253 231 231 231 246 246 246
  95310. -253 253 253 253 253 253 253 253 253 253 253 253
  95311. -253 253 253 253 253 253 253 253 253 253 253 253
  95312. -253 253 253 253 253 253 253 253 253 253 253 253
  95313. -253 253 253 253 253 253 253 253 253 253 253 253
  95314. -253 253 253 253 253 253 158 158 158 18 18 18
  95315. - 14 14 14 2 2 6 2 2 6 2 2 6
  95316. - 6 6 6 18 18 18 66 66 66 38 38 38
  95317. - 6 6 6 94 94 94 50 50 50 18 18 18
  95318. - 6 6 6 0 0 0 0 0 0 0 0 0
  95319. - 0 0 0 0 0 0 0 0 0 0 0 0
  95320. - 0 0 0 0 0 0 0 0 0 0 0 0
  95321. - 0 0 0 0 0 0 0 0 0 0 0 0
  95322. - 0 0 0 0 0 0 0 0 0 0 0 0
  95323. - 0 0 0 0 0 0 0 0 0 6 6 6
  95324. - 10 10 10 10 10 10 18 18 18 38 38 38
  95325. - 78 78 78 142 134 106 216 158 10 242 186 14
  95326. -246 190 14 246 190 14 156 118 10 10 10 10
  95327. - 90 90 90 238 238 238 253 253 253 253 253 253
  95328. -253 253 253 253 253 253 253 253 253 253 253 253
  95329. -253 253 253 253 253 253 231 231 231 250 250 250
  95330. -253 253 253 253 253 253 253 253 253 253 253 253
  95331. -253 253 253 253 253 253 253 253 253 253 253 253
  95332. -253 253 253 253 253 253 253 253 253 253 253 253
  95333. -253 253 253 253 253 253 253 253 253 246 230 190
  95334. -238 204 91 238 204 91 181 142 44 37 26 9
  95335. - 2 2 6 2 2 6 2 2 6 2 2 6
  95336. - 2 2 6 2 2 6 38 38 38 46 46 46
  95337. - 26 26 26 106 106 106 54 54 54 18 18 18
  95338. - 6 6 6 0 0 0 0 0 0 0 0 0
  95339. - 0 0 0 0 0 0 0 0 0 0 0 0
  95340. - 0 0 0 0 0 0 0 0 0 0 0 0
  95341. - 0 0 0 0 0 0 0 0 0 0 0 0
  95342. - 0 0 0 0 0 0 0 0 0 0 0 0
  95343. - 0 0 0 6 6 6 14 14 14 22 22 22
  95344. - 30 30 30 38 38 38 50 50 50 70 70 70
  95345. -106 106 106 190 142 34 226 170 11 242 186 14
  95346. -246 190 14 246 190 14 246 190 14 154 114 10
  95347. - 6 6 6 74 74 74 226 226 226 253 253 253
  95348. -253 253 253 253 253 253 253 253 253 253 253 253
  95349. -253 253 253 253 253 253 231 231 231 250 250 250
  95350. -253 253 253 253 253 253 253 253 253 253 253 253
  95351. -253 253 253 253 253 253 253 253 253 253 253 253
  95352. -253 253 253 253 253 253 253 253 253 253 253 253
  95353. -253 253 253 253 253 253 253 253 253 228 184 62
  95354. -241 196 14 241 208 19 232 195 16 38 30 10
  95355. - 2 2 6 2 2 6 2 2 6 2 2 6
  95356. - 2 2 6 6 6 6 30 30 30 26 26 26
  95357. -203 166 17 154 142 90 66 66 66 26 26 26
  95358. - 6 6 6 0 0 0 0 0 0 0 0 0
  95359. - 0 0 0 0 0 0 0 0 0 0 0 0
  95360. - 0 0 0 0 0 0 0 0 0 0 0 0
  95361. - 0 0 0 0 0 0 0 0 0 0 0 0
  95362. - 0 0 0 0 0 0 0 0 0 0 0 0
  95363. - 6 6 6 18 18 18 38 38 38 58 58 58
  95364. - 78 78 78 86 86 86 101 101 101 123 123 123
  95365. -175 146 61 210 150 10 234 174 13 246 186 14
  95366. -246 190 14 246 190 14 246 190 14 238 190 10
  95367. -102 78 10 2 2 6 46 46 46 198 198 198
  95368. -253 253 253 253 253 253 253 253 253 253 253 253
  95369. -253 253 253 253 253 253 234 234 234 242 242 242
  95370. -253 253 253 253 253 253 253 253 253 253 253 253
  95371. -253 253 253 253 253 253 253 253 253 253 253 253
  95372. -253 253 253 253 253 253 253 253 253 253 253 253
  95373. -253 253 253 253 253 253 253 253 253 224 178 62
  95374. -242 186 14 241 196 14 210 166 10 22 18 6
  95375. - 2 2 6 2 2 6 2 2 6 2 2 6
  95376. - 2 2 6 2 2 6 6 6 6 121 92 8
  95377. -238 202 15 232 195 16 82 82 82 34 34 34
  95378. - 10 10 10 0 0 0 0 0 0 0 0 0
  95379. - 0 0 0 0 0 0 0 0 0 0 0 0
  95380. - 0 0 0 0 0 0 0 0 0 0 0 0
  95381. - 0 0 0 0 0 0 0 0 0 0 0 0
  95382. - 0 0 0 0 0 0 0 0 0 0 0 0
  95383. - 14 14 14 38 38 38 70 70 70 154 122 46
  95384. -190 142 34 200 144 11 197 138 11 197 138 11
  95385. -213 154 11 226 170 11 242 186 14 246 190 14
  95386. -246 190 14 246 190 14 246 190 14 246 190 14
  95387. -225 175 15 46 32 6 2 2 6 22 22 22
  95388. -158 158 158 250 250 250 253 253 253 253 253 253
  95389. -253 253 253 253 253 253 253 253 253 253 253 253
  95390. -253 253 253 253 253 253 253 253 253 253 253 253
  95391. -253 253 253 253 253 253 253 253 253 253 253 253
  95392. -253 253 253 253 253 253 253 253 253 253 253 253
  95393. -253 253 253 250 250 250 242 242 242 224 178 62
  95394. -239 182 13 236 186 11 213 154 11 46 32 6
  95395. - 2 2 6 2 2 6 2 2 6 2 2 6
  95396. - 2 2 6 2 2 6 61 42 6 225 175 15
  95397. -238 190 10 236 186 11 112 100 78 42 42 42
  95398. - 14 14 14 0 0 0 0 0 0 0 0 0
  95399. - 0 0 0 0 0 0 0 0 0 0 0 0
  95400. - 0 0 0 0 0 0 0 0 0 0 0 0
  95401. - 0 0 0 0 0 0 0 0 0 0 0 0
  95402. - 0 0 0 0 0 0 0 0 0 6 6 6
  95403. - 22 22 22 54 54 54 154 122 46 213 154 11
  95404. -226 170 11 230 174 11 226 170 11 226 170 11
  95405. -236 178 12 242 186 14 246 190 14 246 190 14
  95406. -246 190 14 246 190 14 246 190 14 246 190 14
  95407. -241 196 14 184 144 12 10 10 10 2 2 6
  95408. - 6 6 6 116 116 116 242 242 242 253 253 253
  95409. -253 253 253 253 253 253 253 253 253 253 253 253
  95410. -253 253 253 253 253 253 253 253 253 253 253 253
  95411. -253 253 253 253 253 253 253 253 253 253 253 253
  95412. -253 253 253 253 253 253 253 253 253 253 253 253
  95413. -253 253 253 231 231 231 198 198 198 214 170 54
  95414. -236 178 12 236 178 12 210 150 10 137 92 6
  95415. - 18 14 6 2 2 6 2 2 6 2 2 6
  95416. - 6 6 6 70 47 6 200 144 11 236 178 12
  95417. -239 182 13 239 182 13 124 112 88 58 58 58
  95418. - 22 22 22 6 6 6 0 0 0 0 0 0
  95419. - 0 0 0 0 0 0 0 0 0 0 0 0
  95420. - 0 0 0 0 0 0 0 0 0 0 0 0
  95421. - 0 0 0 0 0 0 0 0 0 0 0 0
  95422. - 0 0 0 0 0 0 0 0 0 10 10 10
  95423. - 30 30 30 70 70 70 180 133 36 226 170 11
  95424. -239 182 13 242 186 14 242 186 14 246 186 14
  95425. -246 190 14 246 190 14 246 190 14 246 190 14
  95426. -246 190 14 246 190 14 246 190 14 246 190 14
  95427. -246 190 14 232 195 16 98 70 6 2 2 6
  95428. - 2 2 6 2 2 6 66 66 66 221 221 221
  95429. -253 253 253 253 253 253 253 253 253 253 253 253
  95430. -253 253 253 253 253 253 253 253 253 253 253 253
  95431. -253 253 253 253 253 253 253 253 253 253 253 253
  95432. -253 253 253 253 253 253 253 253 253 253 253 253
  95433. -253 253 253 206 206 206 198 198 198 214 166 58
  95434. -230 174 11 230 174 11 216 158 10 192 133 9
  95435. -163 110 8 116 81 8 102 78 10 116 81 8
  95436. -167 114 7 197 138 11 226 170 11 239 182 13
  95437. -242 186 14 242 186 14 162 146 94 78 78 78
  95438. - 34 34 34 14 14 14 6 6 6 0 0 0
  95439. - 0 0 0 0 0 0 0 0 0 0 0 0
  95440. - 0 0 0 0 0 0 0 0 0 0 0 0
  95441. - 0 0 0 0 0 0 0 0 0 0 0 0
  95442. - 0 0 0 0 0 0 0 0 0 6 6 6
  95443. - 30 30 30 78 78 78 190 142 34 226 170 11
  95444. -239 182 13 246 190 14 246 190 14 246 190 14
  95445. -246 190 14 246 190 14 246 190 14 246 190 14
  95446. -246 190 14 246 190 14 246 190 14 246 190 14
  95447. -246 190 14 241 196 14 203 166 17 22 18 6
  95448. - 2 2 6 2 2 6 2 2 6 38 38 38
  95449. -218 218 218 253 253 253 253 253 253 253 253 253
  95450. -253 253 253 253 253 253 253 253 253 253 253 253
  95451. -253 253 253 253 253 253 253 253 253 253 253 253
  95452. -253 253 253 253 253 253 253 253 253 253 253 253
  95453. -250 250 250 206 206 206 198 198 198 202 162 69
  95454. -226 170 11 236 178 12 224 166 10 210 150 10
  95455. -200 144 11 197 138 11 192 133 9 197 138 11
  95456. -210 150 10 226 170 11 242 186 14 246 190 14
  95457. -246 190 14 246 186 14 225 175 15 124 112 88
  95458. - 62 62 62 30 30 30 14 14 14 6 6 6
  95459. - 0 0 0 0 0 0 0 0 0 0 0 0
  95460. - 0 0 0 0 0 0 0 0 0 0 0 0
  95461. - 0 0 0 0 0 0 0 0 0 0 0 0
  95462. - 0 0 0 0 0 0 0 0 0 10 10 10
  95463. - 30 30 30 78 78 78 174 135 50 224 166 10
  95464. -239 182 13 246 190 14 246 190 14 246 190 14
  95465. -246 190 14 246 190 14 246 190 14 246 190 14
  95466. -246 190 14 246 190 14 246 190 14 246 190 14
  95467. -246 190 14 246 190 14 241 196 14 139 102 15
  95468. - 2 2 6 2 2 6 2 2 6 2 2 6
  95469. - 78 78 78 250 250 250 253 253 253 253 253 253
  95470. -253 253 253 253 253 253 253 253 253 253 253 253
  95471. -253 253 253 253 253 253 253 253 253 253 253 253
  95472. -253 253 253 253 253 253 253 253 253 253 253 253
  95473. -250 250 250 214 214 214 198 198 198 190 150 46
  95474. -219 162 10 236 178 12 234 174 13 224 166 10
  95475. -216 158 10 213 154 11 213 154 11 216 158 10
  95476. -226 170 11 239 182 13 246 190 14 246 190 14
  95477. -246 190 14 246 190 14 242 186 14 206 162 42
  95478. -101 101 101 58 58 58 30 30 30 14 14 14
  95479. - 6 6 6 0 0 0 0 0 0 0 0 0
  95480. - 0 0 0 0 0 0 0 0 0 0 0 0
  95481. - 0 0 0 0 0 0 0 0 0 0 0 0
  95482. - 0 0 0 0 0 0 0 0 0 10 10 10
  95483. - 30 30 30 74 74 74 174 135 50 216 158 10
  95484. -236 178 12 246 190 14 246 190 14 246 190 14
  95485. -246 190 14 246 190 14 246 190 14 246 190 14
  95486. -246 190 14 246 190 14 246 190 14 246 190 14
  95487. -246 190 14 246 190 14 241 196 14 226 184 13
  95488. - 61 42 6 2 2 6 2 2 6 2 2 6
  95489. - 22 22 22 238 238 238 253 253 253 253 253 253
  95490. -253 253 253 253 253 253 253 253 253 253 253 253
  95491. -253 253 253 253 253 253 253 253 253 253 253 253
  95492. -253 253 253 253 253 253 253 253 253 253 253 253
  95493. -253 253 253 226 226 226 187 187 187 180 133 36
  95494. -216 158 10 236 178 12 239 182 13 236 178 12
  95495. -230 174 11 226 170 11 226 170 11 230 174 11
  95496. -236 178 12 242 186 14 246 190 14 246 190 14
  95497. -246 190 14 246 190 14 246 186 14 239 182 13
  95498. -206 162 42 106 106 106 66 66 66 34 34 34
  95499. - 14 14 14 6 6 6 0 0 0 0 0 0
  95500. - 0 0 0 0 0 0 0 0 0 0 0 0
  95501. - 0 0 0 0 0 0 0 0 0 0 0 0
  95502. - 0 0 0 0 0 0 0 0 0 6 6 6
  95503. - 26 26 26 70 70 70 163 133 67 213 154 11
  95504. -236 178 12 246 190 14 246 190 14 246 190 14
  95505. -246 190 14 246 190 14 246 190 14 246 190 14
  95506. -246 190 14 246 190 14 246 190 14 246 190 14
  95507. -246 190 14 246 190 14 246 190 14 241 196 14
  95508. -190 146 13 18 14 6 2 2 6 2 2 6
  95509. - 46 46 46 246 246 246 253 253 253 253 253 253
  95510. -253 253 253 253 253 253 253 253 253 253 253 253
  95511. -253 253 253 253 253 253 253 253 253 253 253 253
  95512. -253 253 253 253 253 253 253 253 253 253 253 253
  95513. -253 253 253 221 221 221 86 86 86 156 107 11
  95514. -216 158 10 236 178 12 242 186 14 246 186 14
  95515. -242 186 14 239 182 13 239 182 13 242 186 14
  95516. -242 186 14 246 186 14 246 190 14 246 190 14
  95517. -246 190 14 246 190 14 246 190 14 246 190 14
  95518. -242 186 14 225 175 15 142 122 72 66 66 66
  95519. - 30 30 30 10 10 10 0 0 0 0 0 0
  95520. - 0 0 0 0 0 0 0 0 0 0 0 0
  95521. - 0 0 0 0 0 0 0 0 0 0 0 0
  95522. - 0 0 0 0 0 0 0 0 0 6 6 6
  95523. - 26 26 26 70 70 70 163 133 67 210 150 10
  95524. -236 178 12 246 190 14 246 190 14 246 190 14
  95525. -246 190 14 246 190 14 246 190 14 246 190 14
  95526. -246 190 14 246 190 14 246 190 14 246 190 14
  95527. -246 190 14 246 190 14 246 190 14 246 190 14
  95528. -232 195 16 121 92 8 34 34 34 106 106 106
  95529. -221 221 221 253 253 253 253 253 253 253 253 253
  95530. -253 253 253 253 253 253 253 253 253 253 253 253
  95531. -253 253 253 253 253 253 253 253 253 253 253 253
  95532. -253 253 253 253 253 253 253 253 253 253 253 253
  95533. -242 242 242 82 82 82 18 14 6 163 110 8
  95534. -216 158 10 236 178 12 242 186 14 246 190 14
  95535. -246 190 14 246 190 14 246 190 14 246 190 14
  95536. -246 190 14 246 190 14 246 190 14 246 190 14
  95537. -246 190 14 246 190 14 246 190 14 246 190 14
  95538. -246 190 14 246 190 14 242 186 14 163 133 67
  95539. - 46 46 46 18 18 18 6 6 6 0 0 0
  95540. - 0 0 0 0 0 0 0 0 0 0 0 0
  95541. - 0 0 0 0 0 0 0 0 0 0 0 0
  95542. - 0 0 0 0 0 0 0 0 0 10 10 10
  95543. - 30 30 30 78 78 78 163 133 67 210 150 10
  95544. -236 178 12 246 186 14 246 190 14 246 190 14
  95545. -246 190 14 246 190 14 246 190 14 246 190 14
  95546. -246 190 14 246 190 14 246 190 14 246 190 14
  95547. -246 190 14 246 190 14 246 190 14 246 190 14
  95548. -241 196 14 215 174 15 190 178 144 253 253 253
  95549. -253 253 253 253 253 253 253 253 253 253 253 253
  95550. -253 253 253 253 253 253 253 253 253 253 253 253
  95551. -253 253 253 253 253 253 253 253 253 253 253 253
  95552. -253 253 253 253 253 253 253 253 253 218 218 218
  95553. - 58 58 58 2 2 6 22 18 6 167 114 7
  95554. -216 158 10 236 178 12 246 186 14 246 190 14
  95555. -246 190 14 246 190 14 246 190 14 246 190 14
  95556. -246 190 14 246 190 14 246 190 14 246 190 14
  95557. -246 190 14 246 190 14 246 190 14 246 190 14
  95558. -246 190 14 246 186 14 242 186 14 190 150 46
  95559. - 54 54 54 22 22 22 6 6 6 0 0 0
  95560. - 0 0 0 0 0 0 0 0 0 0 0 0
  95561. - 0 0 0 0 0 0 0 0 0 0 0 0
  95562. - 0 0 0 0 0 0 0 0 0 14 14 14
  95563. - 38 38 38 86 86 86 180 133 36 213 154 11
  95564. -236 178 12 246 186 14 246 190 14 246 190 14
  95565. -246 190 14 246 190 14 246 190 14 246 190 14
  95566. -246 190 14 246 190 14 246 190 14 246 190 14
  95567. -246 190 14 246 190 14 246 190 14 246 190 14
  95568. -246 190 14 232 195 16 190 146 13 214 214 214
  95569. -253 253 253 253 253 253 253 253 253 253 253 253
  95570. -253 253 253 253 253 253 253 253 253 253 253 253
  95571. -253 253 253 253 253 253 253 253 253 253 253 253
  95572. -253 253 253 250 250 250 170 170 170 26 26 26
  95573. - 2 2 6 2 2 6 37 26 9 163 110 8
  95574. -219 162 10 239 182 13 246 186 14 246 190 14
  95575. -246 190 14 246 190 14 246 190 14 246 190 14
  95576. -246 190 14 246 190 14 246 190 14 246 190 14
  95577. -246 190 14 246 190 14 246 190 14 246 190 14
  95578. -246 186 14 236 178 12 224 166 10 142 122 72
  95579. - 46 46 46 18 18 18 6 6 6 0 0 0
  95580. - 0 0 0 0 0 0 0 0 0 0 0 0
  95581. - 0 0 0 0 0 0 0 0 0 0 0 0
  95582. - 0 0 0 0 0 0 6 6 6 18 18 18
  95583. - 50 50 50 109 106 95 192 133 9 224 166 10
  95584. -242 186 14 246 190 14 246 190 14 246 190 14
  95585. -246 190 14 246 190 14 246 190 14 246 190 14
  95586. -246 190 14 246 190 14 246 190 14 246 190 14
  95587. -246 190 14 246 190 14 246 190 14 246 190 14
  95588. -242 186 14 226 184 13 210 162 10 142 110 46
  95589. -226 226 226 253 253 253 253 253 253 253 253 253
  95590. -253 253 253 253 253 253 253 253 253 253 253 253
  95591. -253 253 253 253 253 253 253 253 253 253 253 253
  95592. -198 198 198 66 66 66 2 2 6 2 2 6
  95593. - 2 2 6 2 2 6 50 34 6 156 107 11
  95594. -219 162 10 239 182 13 246 186 14 246 190 14
  95595. -246 190 14 246 190 14 246 190 14 246 190 14
  95596. -246 190 14 246 190 14 246 190 14 246 190 14
  95597. -246 190 14 246 190 14 246 190 14 242 186 14
  95598. -234 174 13 213 154 11 154 122 46 66 66 66
  95599. - 30 30 30 10 10 10 0 0 0 0 0 0
  95600. - 0 0 0 0 0 0 0 0 0 0 0 0
  95601. - 0 0 0 0 0 0 0 0 0 0 0 0
  95602. - 0 0 0 0 0 0 6 6 6 22 22 22
  95603. - 58 58 58 154 121 60 206 145 10 234 174 13
  95604. -242 186 14 246 186 14 246 190 14 246 190 14
  95605. -246 190 14 246 190 14 246 190 14 246 190 14
  95606. -246 190 14 246 190 14 246 190 14 246 190 14
  95607. -246 190 14 246 190 14 246 190 14 246 190 14
  95608. -246 186 14 236 178 12 210 162 10 163 110 8
  95609. - 61 42 6 138 138 138 218 218 218 250 250 250
  95610. -253 253 253 253 253 253 253 253 253 250 250 250
  95611. -242 242 242 210 210 210 144 144 144 66 66 66
  95612. - 6 6 6 2 2 6 2 2 6 2 2 6
  95613. - 2 2 6 2 2 6 61 42 6 163 110 8
  95614. -216 158 10 236 178 12 246 190 14 246 190 14
  95615. -246 190 14 246 190 14 246 190 14 246 190 14
  95616. -246 190 14 246 190 14 246 190 14 246 190 14
  95617. -246 190 14 239 182 13 230 174 11 216 158 10
  95618. -190 142 34 124 112 88 70 70 70 38 38 38
  95619. - 18 18 18 6 6 6 0 0 0 0 0 0
  95620. - 0 0 0 0 0 0 0 0 0 0 0 0
  95621. - 0 0 0 0 0 0 0 0 0 0 0 0
  95622. - 0 0 0 0 0 0 6 6 6 22 22 22
  95623. - 62 62 62 168 124 44 206 145 10 224 166 10
  95624. -236 178 12 239 182 13 242 186 14 242 186 14
  95625. -246 186 14 246 190 14 246 190 14 246 190 14
  95626. -246 190 14 246 190 14 246 190 14 246 190 14
  95627. -246 190 14 246 190 14 246 190 14 246 190 14
  95628. -246 190 14 236 178 12 216 158 10 175 118 6
  95629. - 80 54 7 2 2 6 6 6 6 30 30 30
  95630. - 54 54 54 62 62 62 50 50 50 38 38 38
  95631. - 14 14 14 2 2 6 2 2 6 2 2 6
  95632. - 2 2 6 2 2 6 2 2 6 2 2 6
  95633. - 2 2 6 6 6 6 80 54 7 167 114 7
  95634. -213 154 11 236 178 12 246 190 14 246 190 14
  95635. -246 190 14 246 190 14 246 190 14 246 190 14
  95636. -246 190 14 242 186 14 239 182 13 239 182 13
  95637. -230 174 11 210 150 10 174 135 50 124 112 88
  95638. - 82 82 82 54 54 54 34 34 34 18 18 18
  95639. - 6 6 6 0 0 0 0 0 0 0 0 0
  95640. - 0 0 0 0 0 0 0 0 0 0 0 0
  95641. - 0 0 0 0 0 0 0 0 0 0 0 0
  95642. - 0 0 0 0 0 0 6 6 6 18 18 18
  95643. - 50 50 50 158 118 36 192 133 9 200 144 11
  95644. -216 158 10 219 162 10 224 166 10 226 170 11
  95645. -230 174 11 236 178 12 239 182 13 239 182 13
  95646. -242 186 14 246 186 14 246 190 14 246 190 14
  95647. -246 190 14 246 190 14 246 190 14 246 190 14
  95648. -246 186 14 230 174 11 210 150 10 163 110 8
  95649. -104 69 6 10 10 10 2 2 6 2 2 6
  95650. - 2 2 6 2 2 6 2 2 6 2 2 6
  95651. - 2 2 6 2 2 6 2 2 6 2 2 6
  95652. - 2 2 6 2 2 6 2 2 6 2 2 6
  95653. - 2 2 6 6 6 6 91 60 6 167 114 7
  95654. -206 145 10 230 174 11 242 186 14 246 190 14
  95655. -246 190 14 246 190 14 246 186 14 242 186 14
  95656. -239 182 13 230 174 11 224 166 10 213 154 11
  95657. -180 133 36 124 112 88 86 86 86 58 58 58
  95658. - 38 38 38 22 22 22 10 10 10 6 6 6
  95659. - 0 0 0 0 0 0 0 0 0 0 0 0
  95660. - 0 0 0 0 0 0 0 0 0 0 0 0
  95661. - 0 0 0 0 0 0 0 0 0 0 0 0
  95662. - 0 0 0 0 0 0 0 0 0 14 14 14
  95663. - 34 34 34 70 70 70 138 110 50 158 118 36
  95664. -167 114 7 180 123 7 192 133 9 197 138 11
  95665. -200 144 11 206 145 10 213 154 11 219 162 10
  95666. -224 166 10 230 174 11 239 182 13 242 186 14
  95667. -246 186 14 246 186 14 246 186 14 246 186 14
  95668. -239 182 13 216 158 10 185 133 11 152 99 6
  95669. -104 69 6 18 14 6 2 2 6 2 2 6
  95670. - 2 2 6 2 2 6 2 2 6 2 2 6
  95671. - 2 2 6 2 2 6 2 2 6 2 2 6
  95672. - 2 2 6 2 2 6 2 2 6 2 2 6
  95673. - 2 2 6 6 6 6 80 54 7 152 99 6
  95674. -192 133 9 219 162 10 236 178 12 239 182 13
  95675. -246 186 14 242 186 14 239 182 13 236 178 12
  95676. -224 166 10 206 145 10 192 133 9 154 121 60
  95677. - 94 94 94 62 62 62 42 42 42 22 22 22
  95678. - 14 14 14 6 6 6 0 0 0 0 0 0
  95679. - 0 0 0 0 0 0 0 0 0 0 0 0
  95680. - 0 0 0 0 0 0 0 0 0 0 0 0
  95681. - 0 0 0 0 0 0 0 0 0 0 0 0
  95682. - 0 0 0 0 0 0 0 0 0 6 6 6
  95683. - 18 18 18 34 34 34 58 58 58 78 78 78
  95684. -101 98 89 124 112 88 142 110 46 156 107 11
  95685. -163 110 8 167 114 7 175 118 6 180 123 7
  95686. -185 133 11 197 138 11 210 150 10 219 162 10
  95687. -226 170 11 236 178 12 236 178 12 234 174 13
  95688. -219 162 10 197 138 11 163 110 8 130 83 6
  95689. - 91 60 6 10 10 10 2 2 6 2 2 6
  95690. - 18 18 18 38 38 38 38 38 38 38 38 38
  95691. - 38 38 38 38 38 38 38 38 38 38 38 38
  95692. - 38 38 38 38 38 38 26 26 26 2 2 6
  95693. - 2 2 6 6 6 6 70 47 6 137 92 6
  95694. -175 118 6 200 144 11 219 162 10 230 174 11
  95695. -234 174 13 230 174 11 219 162 10 210 150 10
  95696. -192 133 9 163 110 8 124 112 88 82 82 82
  95697. - 50 50 50 30 30 30 14 14 14 6 6 6
  95698. - 0 0 0 0 0 0 0 0 0 0 0 0
  95699. - 0 0 0 0 0 0 0 0 0 0 0 0
  95700. - 0 0 0 0 0 0 0 0 0 0 0 0
  95701. - 0 0 0 0 0 0 0 0 0 0 0 0
  95702. - 0 0 0 0 0 0 0 0 0 0 0 0
  95703. - 6 6 6 14 14 14 22 22 22 34 34 34
  95704. - 42 42 42 58 58 58 74 74 74 86 86 86
  95705. -101 98 89 122 102 70 130 98 46 121 87 25
  95706. -137 92 6 152 99 6 163 110 8 180 123 7
  95707. -185 133 11 197 138 11 206 145 10 200 144 11
  95708. -180 123 7 156 107 11 130 83 6 104 69 6
  95709. - 50 34 6 54 54 54 110 110 110 101 98 89
  95710. - 86 86 86 82 82 82 78 78 78 78 78 78
  95711. - 78 78 78 78 78 78 78 78 78 78 78 78
  95712. - 78 78 78 82 82 82 86 86 86 94 94 94
  95713. -106 106 106 101 101 101 86 66 34 124 80 6
  95714. -156 107 11 180 123 7 192 133 9 200 144 11
  95715. -206 145 10 200 144 11 192 133 9 175 118 6
  95716. -139 102 15 109 106 95 70 70 70 42 42 42
  95717. - 22 22 22 10 10 10 0 0 0 0 0 0
  95718. - 0 0 0 0 0 0 0 0 0 0 0 0
  95719. - 0 0 0 0 0 0 0 0 0 0 0 0
  95720. - 0 0 0 0 0 0 0 0 0 0 0 0
  95721. - 0 0 0 0 0 0 0 0 0 0 0 0
  95722. - 0 0 0 0 0 0 0 0 0 0 0 0
  95723. - 0 0 0 0 0 0 6 6 6 10 10 10
  95724. - 14 14 14 22 22 22 30 30 30 38 38 38
  95725. - 50 50 50 62 62 62 74 74 74 90 90 90
  95726. -101 98 89 112 100 78 121 87 25 124 80 6
  95727. -137 92 6 152 99 6 152 99 6 152 99 6
  95728. -138 86 6 124 80 6 98 70 6 86 66 30
  95729. -101 98 89 82 82 82 58 58 58 46 46 46
  95730. - 38 38 38 34 34 34 34 34 34 34 34 34
  95731. - 34 34 34 34 34 34 34 34 34 34 34 34
  95732. - 34 34 34 34 34 34 38 38 38 42 42 42
  95733. - 54 54 54 82 82 82 94 86 76 91 60 6
  95734. -134 86 6 156 107 11 167 114 7 175 118 6
  95735. -175 118 6 167 114 7 152 99 6 121 87 25
  95736. -101 98 89 62 62 62 34 34 34 18 18 18
  95737. - 6 6 6 0 0 0 0 0 0 0 0 0
  95738. - 0 0 0 0 0 0 0 0 0 0 0 0
  95739. - 0 0 0 0 0 0 0 0 0 0 0 0
  95740. - 0 0 0 0 0 0 0 0 0 0 0 0
  95741. - 0 0 0 0 0 0 0 0 0 0 0 0
  95742. - 0 0 0 0 0 0 0 0 0 0 0 0
  95743. - 0 0 0 0 0 0 0 0 0 0 0 0
  95744. - 0 0 0 6 6 6 6 6 6 10 10 10
  95745. - 18 18 18 22 22 22 30 30 30 42 42 42
  95746. - 50 50 50 66 66 66 86 86 86 101 98 89
  95747. -106 86 58 98 70 6 104 69 6 104 69 6
  95748. -104 69 6 91 60 6 82 62 34 90 90 90
  95749. - 62 62 62 38 38 38 22 22 22 14 14 14
  95750. - 10 10 10 10 10 10 10 10 10 10 10 10
  95751. - 10 10 10 10 10 10 6 6 6 10 10 10
  95752. - 10 10 10 10 10 10 10 10 10 14 14 14
  95753. - 22 22 22 42 42 42 70 70 70 89 81 66
  95754. - 80 54 7 104 69 6 124 80 6 137 92 6
  95755. -134 86 6 116 81 8 100 82 52 86 86 86
  95756. - 58 58 58 30 30 30 14 14 14 6 6 6
  95757. - 0 0 0 0 0 0 0 0 0 0 0 0
  95758. - 0 0 0 0 0 0 0 0 0 0 0 0
  95759. - 0 0 0 0 0 0 0 0 0 0 0 0
  95760. - 0 0 0 0 0 0 0 0 0 0 0 0
  95761. - 0 0 0 0 0 0 0 0 0 0 0 0
  95762. - 0 0 0 0 0 0 0 0 0 0 0 0
  95763. - 0 0 0 0 0 0 0 0 0 0 0 0
  95764. - 0 0 0 0 0 0 0 0 0 0 0 0
  95765. - 0 0 0 6 6 6 10 10 10 14 14 14
  95766. - 18 18 18 26 26 26 38 38 38 54 54 54
  95767. - 70 70 70 86 86 86 94 86 76 89 81 66
  95768. - 89 81 66 86 86 86 74 74 74 50 50 50
  95769. - 30 30 30 14 14 14 6 6 6 0 0 0
  95770. - 0 0 0 0 0 0 0 0 0 0 0 0
  95771. - 0 0 0 0 0 0 0 0 0 0 0 0
  95772. - 0 0 0 0 0 0 0 0 0 0 0 0
  95773. - 6 6 6 18 18 18 34 34 34 58 58 58
  95774. - 82 82 82 89 81 66 89 81 66 89 81 66
  95775. - 94 86 66 94 86 76 74 74 74 50 50 50
  95776. - 26 26 26 14 14 14 6 6 6 0 0 0
  95777. - 0 0 0 0 0 0 0 0 0 0 0 0
  95778. - 0 0 0 0 0 0 0 0 0 0 0 0
  95779. - 0 0 0 0 0 0 0 0 0 0 0 0
  95780. - 0 0 0 0 0 0 0 0 0 0 0 0
  95781. - 0 0 0 0 0 0 0 0 0 0 0 0
  95782. - 0 0 0 0 0 0 0 0 0 0 0 0
  95783. - 0 0 0 0 0 0 0 0 0 0 0 0
  95784. - 0 0 0 0 0 0 0 0 0 0 0 0
  95785. - 0 0 0 0 0 0 0 0 0 0 0 0
  95786. - 6 6 6 6 6 6 14 14 14 18 18 18
  95787. - 30 30 30 38 38 38 46 46 46 54 54 54
  95788. - 50 50 50 42 42 42 30 30 30 18 18 18
  95789. - 10 10 10 0 0 0 0 0 0 0 0 0
  95790. - 0 0 0 0 0 0 0 0 0 0 0 0
  95791. - 0 0 0 0 0 0 0 0 0 0 0 0
  95792. - 0 0 0 0 0 0 0 0 0 0 0 0
  95793. - 0 0 0 6 6 6 14 14 14 26 26 26
  95794. - 38 38 38 50 50 50 58 58 58 58 58 58
  95795. - 54 54 54 42 42 42 30 30 30 18 18 18
  95796. - 10 10 10 0 0 0 0 0 0 0 0 0
  95797. - 0 0 0 0 0 0 0 0 0 0 0 0
  95798. - 0 0 0 0 0 0 0 0 0 0 0 0
  95799. - 0 0 0 0 0 0 0 0 0 0 0 0
  95800. - 0 0 0 0 0 0 0 0 0 0 0 0
  95801. - 0 0 0 0 0 0 0 0 0 0 0 0
  95802. - 0 0 0 0 0 0 0 0 0 0 0 0
  95803. - 0 0 0 0 0 0 0 0 0 0 0 0
  95804. - 0 0 0 0 0 0 0 0 0 0 0 0
  95805. - 0 0 0 0 0 0 0 0 0 0 0 0
  95806. - 0 0 0 0 0 0 0 0 0 6 6 6
  95807. - 6 6 6 10 10 10 14 14 14 18 18 18
  95808. - 18 18 18 14 14 14 10 10 10 6 6 6
  95809. - 0 0 0 0 0 0 0 0 0 0 0 0
  95810. - 0 0 0 0 0 0 0 0 0 0 0 0
  95811. - 0 0 0 0 0 0 0 0 0 0 0 0
  95812. - 0 0 0 0 0 0 0 0 0 0 0 0
  95813. - 0 0 0 0 0 0 0 0 0 6 6 6
  95814. - 14 14 14 18 18 18 22 22 22 22 22 22
  95815. - 18 18 18 14 14 14 10 10 10 6 6 6
  95816. - 0 0 0 0 0 0 0 0 0 0 0 0
  95817. - 0 0 0 0 0 0 0 0 0 0 0 0
  95818. - 0 0 0 0 0 0 0 0 0 0 0 0
  95819. - 0 0 0 0 0 0 0 0 0 0 0 0
  95820. - 0 0 0 0 0 0 0 0 0 0 0 0
  95821. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95822. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95823. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95824. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95825. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95826. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95827. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95828. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95829. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95830. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95831. +0 0 0 0 0 0 0 0 0
  95832. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95833. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95834. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  95835. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95836. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95837. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95838. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95839. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  95840. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95841. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95842. +0 0 0 0 0 0 0 0 0
  95843. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95844. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  95845. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  95846. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  95847. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95848. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95849. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  95850. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  95851. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  95852. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95853. +0 0 0 0 0 0 0 0 0
  95854. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95855. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  95856. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  95857. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  95858. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95859. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95860. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  95861. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  95862. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  95863. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  95864. +0 0 0 0 0 0 0 0 0
  95865. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  95866. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  95867. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  95868. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  95869. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  95870. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95871. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  95872. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  95873. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  95874. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  95875. +0 0 0 0 0 0 0 0 0
  95876. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  95877. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  95878. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95879. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  95880. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  95881. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  95882. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  95883. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95884. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  95885. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  95886. +0 0 0 0 0 0 0 0 0
  95887. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95888. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  95889. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  95890. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95891. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  95892. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  95893. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  95894. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95895. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  95896. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  95897. +0 0 0 0 0 0 0 0 0
  95898. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  95899. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  95900. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  95901. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95902. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  95903. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  95904. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95905. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  95906. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  95907. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  95908. +0 0 0 0 0 0 0 0 0
  95909. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  95910. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95911. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  95912. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95913. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  95914. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  95915. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95916. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  95917. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  95918. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  95919. +0 0 0 0 0 0 0 0 0
  95920. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95921. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  95922. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  95923. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  95924. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  95925. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  95926. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95927. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  95928. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  95929. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  95930. +0 0 0 0 0 0 0 0 0
  95931. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  95932. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  95933. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  95934. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  95935. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  95936. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  95937. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  95938. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  95939. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  95940. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  95941. +0 0 0 0 0 0 0 0 0
  95942. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95943. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  95944. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  95945. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  95946. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  95947. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  95948. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  95949. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  95950. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95951. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  95952. +0 0 0 0 0 0 0 0 0
  95953. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95954. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  95955. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95956. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  95957. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  95958. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  95959. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  95960. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  95961. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95962. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  95963. +0 0 0 0 0 0 0 0 0
  95964. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95965. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  95966. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95967. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  95968. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  95969. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  95970. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  95971. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  95972. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95973. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  95974. +0 0 0 0 0 0 0 0 0
  95975. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95976. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  95977. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95978. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  95979. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  95980. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  95981. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  95982. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95983. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95984. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  95985. +0 0 0 0 0 0 0 0 0
  95986. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95987. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  95988. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95989. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  95990. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  95991. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  95992. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  95993. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95994. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  95995. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  95996. +0 0 0 0 0 0 0 0 0
  95997. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95998. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  95999. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96000. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  96001. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  96002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  96003. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  96004. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96005. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  96006. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  96007. +0 0 0 0 0 0 0 0 0
  96008. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96009. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  96010. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96011. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96012. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  96013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96014. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  96015. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96016. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  96017. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96018. +0 0 0 0 0 0 0 0 0
  96019. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96020. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  96021. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  96022. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96023. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  96024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96025. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  96026. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96027. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  96028. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96029. +0 0 0 0 0 0 0 0 0
  96030. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96031. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  96032. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  96033. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  96034. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  96035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96036. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  96037. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96038. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  96039. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96040. +0 0 0 0 0 0 0 0 0
  96041. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96042. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96043. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  96044. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  96045. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96047. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  96048. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  96049. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  96050. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96051. +0 0 0 0 0 0 0 0 0
  96052. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96053. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96054. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  96055. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  96056. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96058. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  96059. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  96060. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  96061. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96062. +0 0 0 0 0 0 0 0 0
  96063. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96064. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96065. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  96066. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  96067. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  96068. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  96069. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96070. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  96071. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96072. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96073. +0 0 0 0 0 0 0 0 0
  96074. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96075. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96076. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  96077. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  96078. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  96079. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  96080. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  96081. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96082. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96083. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96084. +0 0 0 0 0 0 0 0 0
  96085. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96086. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96087. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  96088. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  96089. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  96090. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  96091. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  96092. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  96093. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96094. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96095. +0 0 0 0 0 0 0 0 0
  96096. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96097. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96098. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  96099. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  96100. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  96101. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96102. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  96103. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  96104. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  96105. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96106. +0 0 0 0 0 0 0 0 0
  96107. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96108. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  96109. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  96110. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  96111. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  96112. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96113. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  96114. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  96115. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  96116. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96117. +0 0 0 0 0 0 0 0 0
  96118. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96119. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  96120. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96121. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  96122. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96123. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96124. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  96125. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  96126. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  96127. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96128. +0 0 0 0 0 0 0 0 0
  96129. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96130. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  96131. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  96132. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  96133. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96134. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96135. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  96136. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  96137. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  96138. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96139. +0 0 0 0 0 0 0 0 0
  96140. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96141. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  96142. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  96143. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  96144. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  96145. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96146. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  96147. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  96148. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  96149. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96150. +0 0 0 0 0 0 0 0 0
  96151. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96152. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  96153. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  96154. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96155. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  96156. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  96157. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  96158. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  96159. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  96160. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96161. +0 0 0 0 0 0 0 0 0
  96162. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96163. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  96164. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  96165. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96166. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  96167. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  96168. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  96169. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  96170. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  96171. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96172. +0 0 0 0 0 0 0 0 0
  96173. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96174. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  96175. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  96176. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  96177. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  96178. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  96179. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  96180. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  96181. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  96182. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96183. +0 0 0 0 0 0 0 0 0
  96184. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96185. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  96186. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  96187. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  96188. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  96189. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  96190. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  96191. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  96192. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  96193. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96194. +0 0 0 0 0 0 0 0 0
  96195. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96196. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  96197. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  96198. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  96199. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  96200. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  96201. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  96202. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  96203. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  96204. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96205. +0 0 0 0 0 0 0 0 0
  96206. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96207. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  96208. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  96209. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96210. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  96211. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  96212. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96213. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  96214. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  96215. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96216. +0 0 0 0 0 0 0 0 0
  96217. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96218. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96219. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  96220. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96221. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  96222. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  96223. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96224. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  96225. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96226. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96227. +0 0 0 0 0 0 0 0 0
  96228. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96229. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  96230. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  96231. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96232. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  96233. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  96234. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96235. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  96236. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  96237. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  96238. +0 0 0 0 0 0 0 0 0
  96239. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96240. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  96241. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  96242. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96243. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  96244. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  96245. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96246. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96247. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  96248. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  96249. +0 0 0 0 0 0 0 0 0
  96250. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  96251. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  96252. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  96253. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96254. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  96255. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  96256. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96257. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96258. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  96259. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  96260. +0 0 0 0 0 0 0 0 0
  96261. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  96262. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  96263. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  96264. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96265. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  96266. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  96267. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96268. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96269. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  96270. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  96271. +0 0 0 0 0 0 0 0 0
  96272. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  96273. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  96274. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  96275. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96276. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  96277. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  96278. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96279. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96280. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  96281. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  96282. +0 0 0 0 0 0 0 0 0
  96283. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  96284. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  96285. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  96286. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96287. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  96288. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  96289. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96290. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96291. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  96292. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  96293. +0 0 0 0 0 0 0 0 0
  96294. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  96295. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  96296. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  96297. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96298. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  96299. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  96300. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96301. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96302. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  96303. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  96304. +0 0 0 0 0 0 0 0 0
  96305. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  96306. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  96307. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  96308. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96309. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  96310. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  96311. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96312. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96313. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  96314. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  96315. +0 0 0 0 0 0 0 0 0
  96316. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  96317. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  96318. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  96319. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96320. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  96321. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  96322. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96323. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96324. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  96325. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  96326. +0 0 0 0 0 0 0 0 0
  96327. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  96328. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  96329. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  96330. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96331. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  96332. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  96333. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96334. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96335. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  96336. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  96337. +0 0 0 0 0 0 0 0 0
  96338. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  96339. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  96340. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  96341. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96342. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  96343. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  96344. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  96345. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  96346. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  96347. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  96348. +0 0 0 0 0 0 0 0 0
  96349. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  96350. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  96351. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  96352. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96353. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  96354. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96355. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  96356. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  96357. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  96358. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  96359. +0 0 0 0 0 0 0 0 0
  96360. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  96361. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  96362. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  96363. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  96364. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  96365. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  96366. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  96367. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  96368. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  96369. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  96370. +0 0 0 0 0 0 0 0 0
  96371. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  96372. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  96373. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  96374. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  96375. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  96376. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  96377. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  96378. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  96379. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  96380. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  96381. +0 0 0 0 0 0 0 0 0
  96382. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  96383. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  96384. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  96385. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  96386. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  96387. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  96388. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  96389. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96390. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  96391. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  96392. +0 0 0 0 0 0 0 0 0
  96393. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  96394. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  96395. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96396. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96397. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  96398. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96399. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  96400. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96401. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  96402. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  96403. +0 0 0 0 0 0 0 0 0
  96404. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  96405. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  96406. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  96407. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  96408. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  96409. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96410. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  96411. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  96412. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  96413. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  96414. +0 0 0 0 0 0 0 0 0
  96415. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96416. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  96417. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  96418. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  96419. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96420. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96421. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  96422. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  96423. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  96424. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96425. +0 0 0 0 0 0 0 0 0
  96426. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96427. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  96428. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  96429. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  96430. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96431. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96432. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  96433. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  96434. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  96435. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  96436. +0 0 0 0 0 0 0 0 0
  96437. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96438. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  96439. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  96440. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  96441. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96442. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96443. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  96444. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  96445. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  96446. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  96447. +0 0 0 0 0 0 0 0 0
  96448. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96449. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  96450. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  96451. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  96452. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96453. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96454. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  96455. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  96456. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96457. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  96458. +0 0 0 0 0 0 0 0 0
  96459. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96460. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  96461. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  96462. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  96463. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96464. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96465. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  96466. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  96467. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96468. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  96469. +0 0 0 0 0 0 0 0 0
  96470. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96471. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  96472. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96473. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  96474. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96475. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96476. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  96477. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  96478. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96479. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  96480. +0 0 0 0 0 0 0 0 0
  96481. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96482. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  96483. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96484. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  96485. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96486. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96487. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  96488. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  96489. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  96490. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  96491. +0 0 0 0 0 0 0 0 0
  96492. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96493. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  96494. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96495. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  96496. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96497. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96498. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  96499. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  96500. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  96501. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  96502. +0 0 0 0 0 0 0 0 0
  96503. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96504. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  96505. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96506. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  96507. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  96508. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96509. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  96510. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  96511. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  96512. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96513. +0 0 0 0 0 0 0 0 0
  96514. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96515. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  96516. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96517. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  96518. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  96519. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96520. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  96521. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96522. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  96523. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96524. +0 0 0 0 0 0 0 0 0
  96525. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96526. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  96527. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96528. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  96529. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  96530. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  96531. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  96532. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96533. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  96534. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96535. +0 0 0 0 0 0 0 0 0
  96536. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96537. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  96538. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96539. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  96540. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  96541. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  96542. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  96543. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96544. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  96545. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96546. +0 0 0 0 0 0 0 0 0
  96547. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96548. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  96549. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  96550. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  96551. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  96552. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  96553. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  96554. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96555. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  96556. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96557. +0 0 0 0 0 0 0 0 0
  96558. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96559. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  96560. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  96561. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  96562. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96563. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96564. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  96565. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  96566. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  96567. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96568. +0 0 0 0 0 0 0 0 0
  96569. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96570. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96571. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  96572. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  96573. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  96574. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  96575. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  96576. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  96577. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  96578. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96579. +0 0 0 0 0 0 0 0 0
  96580. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96581. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96582. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  96583. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  96584. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  96585. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  96586. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  96587. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  96588. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96589. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96590. +0 0 0 0 0 0 0 0 0
  96591. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96592. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96593. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96594. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  96595. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  96596. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  96597. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  96598. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96599. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96600. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96601. +0 0 0 0 0 0 0 0 0
  96602. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96603. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96604. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96605. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  96606. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96607. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96608. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  96609. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96610. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96611. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96612. +0 0 0 0 0 0 0 0 0
  96613. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96614. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96615. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96616. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  96617. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96618. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96619. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  96620. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96621. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96622. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96623. +0 0 0 0 0 0 0 0 0
  96624. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96625. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96626. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96627. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  96628. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96629. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96630. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  96631. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96632. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96633. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96634. +0 0 0 0 0 0 0 0 0
  96635. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96636. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96637. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96638. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  96639. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  96640. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96641. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  96642. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96643. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96644. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96645. +0 0 0 0 0 0 0 0 0
  96646. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96647. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96648. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96649. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96650. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  96651. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  96652. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  96653. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96654. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96655. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96656. +0 0 0 0 0 0 0 0 0
  96657. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96658. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96659. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96660. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96661. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  96662. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  96663. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96664. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96665. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96666. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96667. +0 0 0 0 0 0 0 0 0
  96668. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96669. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96670. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96671. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96672. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  96673. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  96674. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96675. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96676. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96677. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96678. +0 0 0 0 0 0 0 0 0
  96679. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96680. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96681. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96682. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96683. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96684. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96685. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96686. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96687. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96688. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96689. +0 0 0 0 0 0 0 0 0
  96690. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96691. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96692. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96693. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96694. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96695. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96696. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96697. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96698. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96699. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96700. +0 0 0 0 0 0 0 0 0
  96701. diff -Nur linux-3.10.33/drivers/video/Makefile linux-raspberry-pi/drivers/video/Makefile
  96702. --- linux-3.10.33/drivers/video/Makefile 2014-03-07 06:58:45.000000000 +0100
  96703. +++ linux-raspberry-pi/drivers/video/Makefile 2014-03-13 12:46:40.288099538 +0100
  96704. @@ -100,6 +100,7 @@
  96705. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  96706. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  96707. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  96708. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  96709. obj-$(CONFIG_FB_68328) += 68328fb.o
  96710. obj-$(CONFIG_FB_GBE) += gbefb.o
  96711. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  96712. diff -Nur linux-3.10.33/drivers/w1/masters/w1-gpio.c linux-raspberry-pi/drivers/w1/masters/w1-gpio.c
  96713. --- linux-3.10.33/drivers/w1/masters/w1-gpio.c 2014-03-07 06:58:45.000000000 +0100
  96714. +++ linux-raspberry-pi/drivers/w1/masters/w1-gpio.c 2014-03-13 12:46:40.752100469 +0100
  96715. @@ -23,6 +23,9 @@
  96716. #include "../w1.h"
  96717. #include "../w1_int.h"
  96718. +static int w1_gpio_pullup = 0;
  96719. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  96720. +
  96721. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  96722. {
  96723. struct w1_gpio_platform_data *pdata = data;
  96724. @@ -47,6 +50,16 @@
  96725. return gpio_get_value(pdata->pin) ? 1 : 0;
  96726. }
  96727. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  96728. +{
  96729. + struct w1_gpio_platform_data *pdata = data;
  96730. +
  96731. + if (on)
  96732. + gpio_direction_output(pdata->pin, 1);
  96733. + else
  96734. + gpio_direction_input(pdata->pin);
  96735. +}
  96736. +
  96737. #if defined(CONFIG_OF)
  96738. static struct of_device_id w1_gpio_dt_ids[] = {
  96739. { .compatible = "w1-gpio" },
  96740. @@ -133,6 +146,13 @@
  96741. master->write_bit = w1_gpio_write_bit_dir;
  96742. }
  96743. + if (w1_gpio_pullup)
  96744. + if (pdata->is_open_drain)
  96745. + printk(KERN_ERR "w1-gpio 'pullup' option "
  96746. + "doesn't work with open drain GPIO\n");
  96747. + else
  96748. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  96749. +
  96750. err = w1_add_master_device(master);
  96751. if (err) {
  96752. dev_err(&pdev->dev, "w1_add_master device failed\n");
  96753. diff -Nur linux-3.10.33/drivers/w1/w1.h linux-raspberry-pi/drivers/w1/w1.h
  96754. --- linux-3.10.33/drivers/w1/w1.h 2014-03-07 06:58:45.000000000 +0100
  96755. +++ linux-raspberry-pi/drivers/w1/w1.h 2014-03-13 12:46:40.756100477 +0100
  96756. @@ -148,6 +148,12 @@
  96757. */
  96758. u8 (*set_pullup)(void *, int);
  96759. + /**
  96760. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  96761. + * @return -1=Error, 0=completed
  96762. + */
  96763. + void (*bitbang_pullup) (void *, u8);
  96764. +
  96765. /** Really nice hardware can handles the different types of ROM search
  96766. * w1_master* is passed to the slave found callback.
  96767. */
  96768. diff -Nur linux-3.10.33/drivers/w1/w1_int.c linux-raspberry-pi/drivers/w1/w1_int.c
  96769. --- linux-3.10.33/drivers/w1/w1_int.c 2014-03-07 06:58:45.000000000 +0100
  96770. +++ linux-raspberry-pi/drivers/w1/w1_int.c 2014-03-13 12:46:40.756100477 +0100
  96771. @@ -117,19 +117,21 @@
  96772. printk(KERN_ERR "w1_add_master_device: invalid function set\n");
  96773. return(-EINVAL);
  96774. }
  96775. - /* While it would be electrically possible to make a device that
  96776. - * generated a strong pullup in bit bang mode, only hardware that
  96777. - * controls 1-wire time frames are even expected to support a strong
  96778. - * pullup. w1_io.c would need to support calling set_pullup before
  96779. - * the last write_bit operation of a w1_write_8 which it currently
  96780. - * doesn't.
  96781. - */
  96782. +
  96783. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  96784. + * and takes care of timing itself */
  96785. if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  96786. printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  96787. "write_byte or touch_bit, disabling\n");
  96788. master->set_pullup = NULL;
  96789. }
  96790. + if (master->set_pullup && master->bitbang_pullup) {
  96791. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  96792. + "be set when bitbang_pullup is used, disabling\n");
  96793. + master->set_pullup = NULL;
  96794. + }
  96795. +
  96796. /* Lock until the device is added (or not) to w1_masters. */
  96797. mutex_lock(&w1_mlock);
  96798. /* Search for the first available id (starting at 1). */
  96799. diff -Nur linux-3.10.33/drivers/w1/w1_io.c linux-raspberry-pi/drivers/w1/w1_io.c
  96800. --- linux-3.10.33/drivers/w1/w1_io.c 2014-03-07 06:58:45.000000000 +0100
  96801. +++ linux-raspberry-pi/drivers/w1/w1_io.c 2014-03-13 12:46:40.756100477 +0100
  96802. @@ -127,10 +127,22 @@
  96803. static void w1_post_write(struct w1_master *dev)
  96804. {
  96805. if (dev->pullup_duration) {
  96806. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  96807. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  96808. - else
  96809. + if (dev->enable_pullup) {
  96810. + if (dev->bus_master->set_pullup) {
  96811. + dev->bus_master->set_pullup(dev->
  96812. + bus_master->data,
  96813. + 0);
  96814. + } else if (dev->bus_master->bitbang_pullup) {
  96815. + dev->bus_master->
  96816. + bitbang_pullup(dev->bus_master->data, 1);
  96817. msleep(dev->pullup_duration);
  96818. + dev->bus_master->
  96819. + bitbang_pullup(dev->bus_master->data, 0);
  96820. + }
  96821. + } else {
  96822. + msleep(dev->pullup_duration);
  96823. + }
  96824. +
  96825. dev->pullup_duration = 0;
  96826. }
  96827. }
  96828. diff -Nur linux-3.10.33/drivers/watchdog/bcm2708_wdog.c linux-raspberry-pi/drivers/watchdog/bcm2708_wdog.c
  96829. --- linux-3.10.33/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  96830. +++ linux-raspberry-pi/drivers/watchdog/bcm2708_wdog.c 2014-03-13 12:46:40.756100477 +0100
  96831. @@ -0,0 +1,385 @@
  96832. +/*
  96833. + * Broadcom BCM2708 watchdog driver.
  96834. + *
  96835. + * (c) Copyright 2010 Broadcom Europe Ltd
  96836. + *
  96837. + * This program is free software; you can redistribute it and/or
  96838. + * modify it under the terms of the GNU General Public License
  96839. + * as published by the Free Software Foundation; either version
  96840. + * 2 of the License, or (at your option) any later version.
  96841. + *
  96842. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  96843. + */
  96844. +
  96845. +#include <linux/interrupt.h>
  96846. +#include <linux/module.h>
  96847. +#include <linux/moduleparam.h>
  96848. +#include <linux/types.h>
  96849. +#include <linux/miscdevice.h>
  96850. +#include <linux/watchdog.h>
  96851. +#include <linux/fs.h>
  96852. +#include <linux/ioport.h>
  96853. +#include <linux/notifier.h>
  96854. +#include <linux/reboot.h>
  96855. +#include <linux/init.h>
  96856. +#include <linux/io.h>
  96857. +#include <linux/uaccess.h>
  96858. +#include <mach/platform.h>
  96859. +
  96860. +#include <asm/system.h>
  96861. +
  96862. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  96863. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  96864. +
  96865. +static unsigned long wdog_is_open;
  96866. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  96867. +static char expect_close;
  96868. +
  96869. +/*
  96870. + * Module parameters
  96871. + */
  96872. +
  96873. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  96874. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  96875. +
  96876. +module_param(heartbeat, int, 0);
  96877. +MODULE_PARM_DESC(heartbeat,
  96878. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  96879. + __MODULE_STRING(WD_TIMO) ")");
  96880. +
  96881. +static int nowayout = WATCHDOG_NOWAYOUT;
  96882. +module_param(nowayout, int, 0);
  96883. +MODULE_PARM_DESC(nowayout,
  96884. + "Watchdog cannot be stopped once started (default="
  96885. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  96886. +
  96887. +static DEFINE_SPINLOCK(wdog_lock);
  96888. +
  96889. +/**
  96890. + * Start the watchdog driver.
  96891. + */
  96892. +
  96893. +static int wdog_start(unsigned long timeout)
  96894. +{
  96895. + uint32_t cur;
  96896. + unsigned long flags;
  96897. + spin_lock_irqsave(&wdog_lock, flags);
  96898. +
  96899. + /* enable the watchdog */
  96900. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  96901. + __io_address(PM_WDOG));
  96902. + cur = ioread32(__io_address(PM_RSTC));
  96903. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  96904. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  96905. +
  96906. + spin_unlock_irqrestore(&wdog_lock, flags);
  96907. + return 0;
  96908. +}
  96909. +
  96910. +/**
  96911. + * Stop the watchdog driver.
  96912. + */
  96913. +
  96914. +static int wdog_stop(void)
  96915. +{
  96916. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  96917. + printk(KERN_INFO "watchdog stopped\n");
  96918. + return 0;
  96919. +}
  96920. +
  96921. +/**
  96922. + * Reload counter one with the watchdog heartbeat. We don't bother
  96923. + * reloading the cascade counter.
  96924. + */
  96925. +
  96926. +static void wdog_ping(void)
  96927. +{
  96928. + wdog_start(wdog_ticks);
  96929. +}
  96930. +
  96931. +/**
  96932. + * @t: the new heartbeat value that needs to be set.
  96933. + *
  96934. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  96935. + * value is incorrect we keep the old value and return -EINVAL. If
  96936. + * successful we return 0.
  96937. + */
  96938. +
  96939. +static int wdog_set_heartbeat(int t)
  96940. +{
  96941. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  96942. + return -EINVAL;
  96943. +
  96944. + heartbeat = t;
  96945. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  96946. + return 0;
  96947. +}
  96948. +
  96949. +/**
  96950. + * @file: file handle to the watchdog
  96951. + * @buf: buffer to write (unused as data does not matter here
  96952. + * @count: count of bytes
  96953. + * @ppos: pointer to the position to write. No seeks allowed
  96954. + *
  96955. + * A write to a watchdog device is defined as a keepalive signal.
  96956. + *
  96957. + * if 'nowayout' is set then normally a close() is ignored. But
  96958. + * if you write 'V' first then the close() will stop the timer.
  96959. + */
  96960. +
  96961. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  96962. + size_t count, loff_t *ppos)
  96963. +{
  96964. + if (count) {
  96965. + if (!nowayout) {
  96966. + size_t i;
  96967. +
  96968. + /* In case it was set long ago */
  96969. + expect_close = 0;
  96970. +
  96971. + for (i = 0; i != count; i++) {
  96972. + char c;
  96973. + if (get_user(c, buf + i))
  96974. + return -EFAULT;
  96975. + if (c == 'V')
  96976. + expect_close = 42;
  96977. + }
  96978. + }
  96979. + wdog_ping();
  96980. + }
  96981. + return count;
  96982. +}
  96983. +
  96984. +static int wdog_get_status(void)
  96985. +{
  96986. + unsigned long flags;
  96987. + int status = 0;
  96988. + spin_lock_irqsave(&wdog_lock, flags);
  96989. + /* FIXME: readback reset reason */
  96990. + spin_unlock_irqrestore(&wdog_lock, flags);
  96991. + return status;
  96992. +}
  96993. +
  96994. +static uint32_t wdog_get_remaining(void)
  96995. +{
  96996. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  96997. + return ret & PM_WDOG_TIME_SET;
  96998. +}
  96999. +
  97000. +/**
  97001. + * @file: file handle to the device
  97002. + * @cmd: watchdog command
  97003. + * @arg: argument pointer
  97004. + *
  97005. + * The watchdog API defines a common set of functions for all watchdogs
  97006. + * according to their available features. We only actually usefully support
  97007. + * querying capabilities and current status.
  97008. + */
  97009. +
  97010. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  97011. +{
  97012. + void __user *argp = (void __user *)arg;
  97013. + int __user *p = argp;
  97014. + int new_heartbeat;
  97015. + int status;
  97016. + int options;
  97017. + uint32_t remaining;
  97018. +
  97019. + struct watchdog_info ident = {
  97020. + .options = WDIOF_SETTIMEOUT|
  97021. + WDIOF_MAGICCLOSE|
  97022. + WDIOF_KEEPALIVEPING,
  97023. + .firmware_version = 1,
  97024. + .identity = "BCM2708",
  97025. + };
  97026. +
  97027. + switch (cmd) {
  97028. + case WDIOC_GETSUPPORT:
  97029. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  97030. + case WDIOC_GETSTATUS:
  97031. + status = wdog_get_status();
  97032. + return put_user(status, p);
  97033. + case WDIOC_GETBOOTSTATUS:
  97034. + return put_user(0, p);
  97035. + case WDIOC_KEEPALIVE:
  97036. + wdog_ping();
  97037. + return 0;
  97038. + case WDIOC_SETTIMEOUT:
  97039. + if (get_user(new_heartbeat, p))
  97040. + return -EFAULT;
  97041. + if (wdog_set_heartbeat(new_heartbeat))
  97042. + return -EINVAL;
  97043. + wdog_ping();
  97044. + /* Fall */
  97045. + case WDIOC_GETTIMEOUT:
  97046. + return put_user(heartbeat, p);
  97047. + case WDIOC_GETTIMELEFT:
  97048. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  97049. + return put_user(remaining, p);
  97050. + case WDIOC_SETOPTIONS:
  97051. + if (get_user(options, p))
  97052. + return -EFAULT;
  97053. + if (options & WDIOS_DISABLECARD)
  97054. + wdog_stop();
  97055. + if (options & WDIOS_ENABLECARD)
  97056. + wdog_start(wdog_ticks);
  97057. + return 0;
  97058. + default:
  97059. + return -ENOTTY;
  97060. + }
  97061. +}
  97062. +
  97063. +/**
  97064. + * @inode: inode of device
  97065. + * @file: file handle to device
  97066. + *
  97067. + * The watchdog device has been opened. The watchdog device is single
  97068. + * open and on opening we load the counters.
  97069. + */
  97070. +
  97071. +static int wdog_open(struct inode *inode, struct file *file)
  97072. +{
  97073. + if (test_and_set_bit(0, &wdog_is_open))
  97074. + return -EBUSY;
  97075. + /*
  97076. + * Activate
  97077. + */
  97078. + wdog_start(wdog_ticks);
  97079. + return nonseekable_open(inode, file);
  97080. +}
  97081. +
  97082. +/**
  97083. + * @inode: inode to board
  97084. + * @file: file handle to board
  97085. + *
  97086. + * The watchdog has a configurable API. There is a religious dispute
  97087. + * between people who want their watchdog to be able to shut down and
  97088. + * those who want to be sure if the watchdog manager dies the machine
  97089. + * reboots. In the former case we disable the counters, in the latter
  97090. + * case you have to open it again very soon.
  97091. + */
  97092. +
  97093. +static int wdog_release(struct inode *inode, struct file *file)
  97094. +{
  97095. + if (expect_close == 42) {
  97096. + wdog_stop();
  97097. + } else {
  97098. + printk(KERN_CRIT
  97099. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  97100. + wdog_ping();
  97101. + }
  97102. + clear_bit(0, &wdog_is_open);
  97103. + expect_close = 0;
  97104. + return 0;
  97105. +}
  97106. +
  97107. +/**
  97108. + * @this: our notifier block
  97109. + * @code: the event being reported
  97110. + * @unused: unused
  97111. + *
  97112. + * Our notifier is called on system shutdowns. Turn the watchdog
  97113. + * off so that it does not fire during the next reboot.
  97114. + */
  97115. +
  97116. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  97117. + void *unused)
  97118. +{
  97119. + if (code == SYS_DOWN || code == SYS_HALT)
  97120. + wdog_stop();
  97121. + return NOTIFY_DONE;
  97122. +}
  97123. +
  97124. +/*
  97125. + * Kernel Interfaces
  97126. + */
  97127. +
  97128. +
  97129. +static const struct file_operations wdog_fops = {
  97130. + .owner = THIS_MODULE,
  97131. + .llseek = no_llseek,
  97132. + .write = wdog_write,
  97133. + .unlocked_ioctl = wdog_ioctl,
  97134. + .open = wdog_open,
  97135. + .release = wdog_release,
  97136. +};
  97137. +
  97138. +static struct miscdevice wdog_miscdev = {
  97139. + .minor = WATCHDOG_MINOR,
  97140. + .name = "watchdog",
  97141. + .fops = &wdog_fops,
  97142. +};
  97143. +
  97144. +/*
  97145. + * The WDT card needs to learn about soft shutdowns in order to
  97146. + * turn the timebomb registers off.
  97147. + */
  97148. +
  97149. +static struct notifier_block wdog_notifier = {
  97150. + .notifier_call = wdog_notify_sys,
  97151. +};
  97152. +
  97153. +/**
  97154. + * cleanup_module:
  97155. + *
  97156. + * Unload the watchdog. You cannot do this with any file handles open.
  97157. + * If your watchdog is set to continue ticking on close and you unload
  97158. + * it, well it keeps ticking. We won't get the interrupt but the board
  97159. + * will not touch PC memory so all is fine. You just have to load a new
  97160. + * module in 60 seconds or reboot.
  97161. + */
  97162. +
  97163. +static void __exit wdog_exit(void)
  97164. +{
  97165. + misc_deregister(&wdog_miscdev);
  97166. + unregister_reboot_notifier(&wdog_notifier);
  97167. +}
  97168. +
  97169. +static int __init wdog_init(void)
  97170. +{
  97171. + int ret;
  97172. +
  97173. + /* Check that the heartbeat value is within it's range;
  97174. + if not reset to the default */
  97175. + if (wdog_set_heartbeat(heartbeat)) {
  97176. + wdog_set_heartbeat(WD_TIMO);
  97177. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  97178. + "0 < heartbeat < %d, using %d\n",
  97179. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  97180. + WD_TIMO);
  97181. + }
  97182. +
  97183. + ret = register_reboot_notifier(&wdog_notifier);
  97184. + if (ret) {
  97185. + printk(KERN_ERR
  97186. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  97187. + goto out_reboot;
  97188. + }
  97189. +
  97190. + ret = misc_register(&wdog_miscdev);
  97191. + if (ret) {
  97192. + printk(KERN_ERR
  97193. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  97194. + WATCHDOG_MINOR, ret);
  97195. + goto out_misc;
  97196. + }
  97197. +
  97198. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  97199. + heartbeat, nowayout);
  97200. + return 0;
  97201. +
  97202. +out_misc:
  97203. + unregister_reboot_notifier(&wdog_notifier);
  97204. +out_reboot:
  97205. + return ret;
  97206. +}
  97207. +
  97208. +module_init(wdog_init);
  97209. +module_exit(wdog_exit);
  97210. +
  97211. +MODULE_AUTHOR("Luke Diamand");
  97212. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  97213. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  97214. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  97215. +MODULE_LICENSE("GPL");
  97216. +
  97217. diff -Nur linux-3.10.33/drivers/watchdog/Kconfig linux-raspberry-pi/drivers/watchdog/Kconfig
  97218. --- linux-3.10.33/drivers/watchdog/Kconfig 2014-03-07 06:58:45.000000000 +0100
  97219. +++ linux-raspberry-pi/drivers/watchdog/Kconfig 2014-03-13 12:46:40.756100477 +0100
  97220. @@ -391,6 +391,12 @@
  97221. To compile this driver as a module, choose M here: the
  97222. module will be called retu_wdt.
  97223. +config BCM2708_WDT
  97224. + tristate "BCM2708 Watchdog"
  97225. + depends on ARCH_BCM2708
  97226. + help
  97227. + Enables BCM2708 watchdog support.
  97228. +
  97229. # AVR32 Architecture
  97230. config AT32AP700X_WDT
  97231. diff -Nur linux-3.10.33/drivers/watchdog/Makefile linux-raspberry-pi/drivers/watchdog/Makefile
  97232. --- linux-3.10.33/drivers/watchdog/Makefile 2014-03-07 06:58:45.000000000 +0100
  97233. +++ linux-raspberry-pi/drivers/watchdog/Makefile 2014-03-13 12:46:40.756100477 +0100
  97234. @@ -54,6 +54,7 @@
  97235. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  97236. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  97237. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  97238. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  97239. # AVR32 Architecture
  97240. obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
  97241. diff -Nur linux-3.10.33/include/linux/broadcom/vc_cma.h linux-raspberry-pi/include/linux/broadcom/vc_cma.h
  97242. --- linux-3.10.33/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  97243. +++ linux-raspberry-pi/include/linux/broadcom/vc_cma.h 2014-03-13 12:46:41.852102677 +0100
  97244. @@ -0,0 +1,30 @@
  97245. +/*****************************************************************************
  97246. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  97247. +*
  97248. +* Unless you and Broadcom execute a separate written software license
  97249. +* agreement governing use of this software, this software is licensed to you
  97250. +* under the terms of the GNU General Public License version 2, available at
  97251. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97252. +*
  97253. +* Notwithstanding the above, under no circumstances may you combine this
  97254. +* software in any way with any other Broadcom software provided under a
  97255. +* license other than the GPL, without Broadcom's express prior written
  97256. +* consent.
  97257. +*****************************************************************************/
  97258. +
  97259. +#if !defined( VC_CMA_H )
  97260. +#define VC_CMA_H
  97261. +
  97262. +#include <linux/ioctl.h>
  97263. +
  97264. +#define VC_CMA_IOC_MAGIC 0xc5
  97265. +
  97266. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  97267. +
  97268. +#ifdef __KERNEL__
  97269. +extern void __init vc_cma_early_init(void);
  97270. +extern void __init vc_cma_reserve(void);
  97271. +#endif
  97272. +
  97273. +#endif /* VC_CMA_H */
  97274. +
  97275. diff -Nur linux-3.10.33/include/linux/mmc/host.h linux-raspberry-pi/include/linux/mmc/host.h
  97276. --- linux-3.10.33/include/linux/mmc/host.h 2014-03-07 06:58:45.000000000 +0100
  97277. +++ linux-raspberry-pi/include/linux/mmc/host.h 2014-03-13 12:46:42.008102990 +0100
  97278. @@ -281,6 +281,7 @@
  97279. #define MMC_CAP2_PACKED_CMD (MMC_CAP2_PACKED_RD | \
  97280. MMC_CAP2_PACKED_WR)
  97281. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  97282. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  97283. mmc_pm_flag_t pm_caps; /* supported pm features */
  97284. diff -Nur linux-3.10.33/include/linux/mmc/sdhci.h linux-raspberry-pi/include/linux/mmc/sdhci.h
  97285. --- linux-3.10.33/include/linux/mmc/sdhci.h 2014-03-07 06:58:45.000000000 +0100
  97286. +++ linux-raspberry-pi/include/linux/mmc/sdhci.h 2014-03-13 12:46:42.008102990 +0100
  97287. @@ -97,6 +97,7 @@
  97288. #define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3)
  97289. int irq; /* Device IRQ */
  97290. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  97291. void __iomem *ioaddr; /* Mapped address */
  97292. const struct sdhci_ops *ops; /* Low level hw interface */
  97293. @@ -128,6 +129,7 @@
  97294. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  97295. #define SDHCI_HS200_NEEDS_TUNING (1<<10) /* HS200 needs tuning */
  97296. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  97297. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  97298. unsigned int version; /* SDHCI spec. version */
  97299. @@ -142,6 +144,7 @@
  97300. struct mmc_request *mrq; /* Current request */
  97301. struct mmc_command *cmd; /* Current command */
  97302. + int last_cmdop; /* Opcode of last cmd sent */
  97303. struct mmc_data *data; /* Current data request */
  97304. unsigned int data_early:1; /* Data finished before cmd */
  97305. diff -Nur linux-3.10.33/include/sound/soc-dai.h linux-raspberry-pi/include/sound/soc-dai.h
  97306. --- linux-3.10.33/include/sound/soc-dai.h 2014-03-07 06:58:45.000000000 +0100
  97307. +++ linux-raspberry-pi/include/sound/soc-dai.h 2014-03-13 12:46:42.236103447 +0100
  97308. @@ -105,6 +105,8 @@
  97309. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  97310. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  97311. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  97312. +
  97313. /* Digital Audio interface formatting */
  97314. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  97315. @@ -131,6 +133,7 @@
  97316. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  97317. unsigned int freq_in, unsigned int freq_out);
  97318. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  97319. + int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  97320. /*
  97321. * DAI format configuration
  97322. diff -Nur linux-3.10.33/include/uapi/linux/fb.h linux-raspberry-pi/include/uapi/linux/fb.h
  97323. --- linux-3.10.33/include/uapi/linux/fb.h 2014-03-07 06:58:45.000000000 +0100
  97324. +++ linux-raspberry-pi/include/uapi/linux/fb.h 2014-03-13 12:46:42.300103576 +0100
  97325. @@ -34,6 +34,11 @@
  97326. #define FBIOPUT_MODEINFO 0x4617
  97327. #define FBIOGET_DISPINFO 0x4618
  97328. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  97329. +/*
  97330. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  97331. + * be concurrently added to the mainline kernel
  97332. + */
  97333. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  97334. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  97335. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  97336. diff -Nur linux-3.10.33/kernel/cgroup.c linux-raspberry-pi/kernel/cgroup.c
  97337. --- linux-3.10.33/kernel/cgroup.c 2014-03-07 06:58:45.000000000 +0100
  97338. +++ linux-raspberry-pi/kernel/cgroup.c 2014-03-13 12:46:42.456103889 +0100
  97339. @@ -5127,6 +5127,37 @@
  97340. }
  97341. __setup("cgroup_disable=", cgroup_disable);
  97342. +static int __init cgroup_enable(char *str)
  97343. +{
  97344. + int i;
  97345. + char *token;
  97346. +
  97347. + while ((token = strsep(&str, ",")) != NULL) {
  97348. + if (!*token)
  97349. + continue;
  97350. + for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
  97351. + struct cgroup_subsys *ss = subsys[i];
  97352. +
  97353. + /*
  97354. + * cgroup_enable, being at boot time, can't
  97355. + * know about module subsystems, so we don't
  97356. + * worry about them.
  97357. + */
  97358. + if (!ss || ss->module)
  97359. + continue;
  97360. +
  97361. + if (!strcmp(token, ss->name)) {
  97362. + ss->disabled = 0;
  97363. + printk(KERN_INFO "Enabling %s control group"
  97364. + " subsystem\n", ss->name);
  97365. + break;
  97366. + }
  97367. + }
  97368. + }
  97369. + return 1;
  97370. +}
  97371. +__setup("cgroup_enable=", cgroup_enable);
  97372. +
  97373. /*
  97374. * Functons for CSS ID.
  97375. */
  97376. diff -Nur linux-3.10.33/mm/memcontrol.c linux-raspberry-pi/mm/memcontrol.c
  97377. --- linux-3.10.33/mm/memcontrol.c 2014-03-07 06:58:45.000000000 +0100
  97378. +++ linux-raspberry-pi/mm/memcontrol.c 2014-03-13 12:46:42.696104370 +0100
  97379. @@ -6956,6 +6956,7 @@
  97380. .base_cftypes = mem_cgroup_files,
  97381. .early_init = 0,
  97382. .use_id = 1,
  97383. + .disabled = 1,
  97384. };
  97385. #ifdef CONFIG_MEMCG_SWAP
  97386. diff -Nur linux-3.10.33/sound/arm/bcm2835.c linux-raspberry-pi/sound/arm/bcm2835.c
  97387. --- linux-3.10.33/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  97388. +++ linux-raspberry-pi/sound/arm/bcm2835.c 2014-03-13 12:46:44.060107108 +0100
  97389. @@ -0,0 +1,413 @@
  97390. +/*****************************************************************************
  97391. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97392. +*
  97393. +* Unless you and Broadcom execute a separate written software license
  97394. +* agreement governing use of this software, this software is licensed to you
  97395. +* under the terms of the GNU General Public License version 2, available at
  97396. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97397. +*
  97398. +* Notwithstanding the above, under no circumstances may you combine this
  97399. +* software in any way with any other Broadcom software provided under a
  97400. +* license other than the GPL, without Broadcom's express prior written
  97401. +* consent.
  97402. +*****************************************************************************/
  97403. +
  97404. +#include <linux/platform_device.h>
  97405. +
  97406. +#include <linux/init.h>
  97407. +#include <linux/slab.h>
  97408. +#include <linux/module.h>
  97409. +
  97410. +#include "bcm2835.h"
  97411. +
  97412. +/* module parameters (see "Module Parameters") */
  97413. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  97414. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  97415. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  97416. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  97417. +
  97418. +/* HACKY global pointers needed for successive probes to work : ssp
  97419. + * But compared against the changes we will have to do in VC audio_ipc code
  97420. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  97421. + * four devices in a thread, this gets things done quickly and should be easier
  97422. + * to debug if we run into issues
  97423. + */
  97424. +
  97425. +static struct snd_card *g_card = NULL;
  97426. +static bcm2835_chip_t *g_chip = NULL;
  97427. +
  97428. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  97429. +{
  97430. + kfree(chip);
  97431. + return 0;
  97432. +}
  97433. +
  97434. +/* component-destructor
  97435. + * (see "Management of Cards and Components")
  97436. + */
  97437. +static int snd_bcm2835_dev_free(struct snd_device *device)
  97438. +{
  97439. + return snd_bcm2835_free(device->device_data);
  97440. +}
  97441. +
  97442. +/* chip-specific constructor
  97443. + * (see "Management of Cards and Components")
  97444. + */
  97445. +static int snd_bcm2835_create(struct snd_card *card,
  97446. + struct platform_device *pdev,
  97447. + bcm2835_chip_t ** rchip)
  97448. +{
  97449. + bcm2835_chip_t *chip;
  97450. + int err;
  97451. + static struct snd_device_ops ops = {
  97452. + .dev_free = snd_bcm2835_dev_free,
  97453. + };
  97454. +
  97455. + *rchip = NULL;
  97456. +
  97457. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  97458. + if (chip == NULL)
  97459. + return -ENOMEM;
  97460. +
  97461. + chip->card = card;
  97462. +
  97463. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  97464. + if (err < 0) {
  97465. + snd_bcm2835_free(chip);
  97466. + return err;
  97467. + }
  97468. +
  97469. + *rchip = chip;
  97470. + return 0;
  97471. +}
  97472. +
  97473. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  97474. +{
  97475. + static int dev;
  97476. + bcm2835_chip_t *chip;
  97477. + struct snd_card *card;
  97478. + int err;
  97479. +
  97480. + if (dev >= MAX_SUBSTREAMS)
  97481. + return -ENODEV;
  97482. +
  97483. + if (!enable[dev]) {
  97484. + dev++;
  97485. + return -ENOENT;
  97486. + }
  97487. +
  97488. + if (dev > 0)
  97489. + goto add_register_map;
  97490. +
  97491. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  97492. + if (err < 0)
  97493. + goto out;
  97494. +
  97495. + snd_card_set_dev(g_card, &pdev->dev);
  97496. + strcpy(g_card->driver, "BRCM bcm2835 ALSA Driver");
  97497. + strcpy(g_card->shortname, "bcm2835 ALSA");
  97498. + sprintf(g_card->longname, "%s", g_card->shortname);
  97499. +
  97500. + err = snd_bcm2835_create(g_card, pdev, &chip);
  97501. + if (err < 0) {
  97502. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  97503. + goto out_bcm2835_create;
  97504. + }
  97505. +
  97506. + g_chip = chip;
  97507. + err = snd_bcm2835_new_pcm(chip);
  97508. + if (err < 0) {
  97509. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  97510. + goto out_bcm2835_new_pcm;
  97511. + }
  97512. +
  97513. + err = snd_bcm2835_new_ctl(chip);
  97514. + if (err < 0) {
  97515. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  97516. + goto out_bcm2835_new_ctl;
  97517. + }
  97518. +
  97519. +add_register_map:
  97520. + card = g_card;
  97521. + chip = g_chip;
  97522. +
  97523. + BUG_ON(!(card && chip));
  97524. +
  97525. + chip->avail_substreams |= (1 << dev);
  97526. + chip->pdev[dev] = pdev;
  97527. +
  97528. + if (dev == 0) {
  97529. + err = snd_card_register(card);
  97530. + if (err < 0) {
  97531. + dev_err(&pdev->dev,
  97532. + "Failed to register bcm2835 ALSA card \n");
  97533. + goto out_card_register;
  97534. + }
  97535. + platform_set_drvdata(pdev, card);
  97536. + audio_info("bcm2835 ALSA card created!\n");
  97537. + } else {
  97538. + audio_info("bcm2835 ALSA chip created!\n");
  97539. + platform_set_drvdata(pdev, (void *)dev);
  97540. + }
  97541. +
  97542. + dev++;
  97543. +
  97544. + return 0;
  97545. +
  97546. +out_card_register:
  97547. +out_bcm2835_new_ctl:
  97548. +out_bcm2835_new_pcm:
  97549. +out_bcm2835_create:
  97550. + BUG_ON(!g_card);
  97551. + if (snd_card_free(g_card))
  97552. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  97553. + g_card = NULL;
  97554. +out:
  97555. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  97556. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  97557. + return err;
  97558. +}
  97559. +
  97560. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  97561. +{
  97562. + uint32_t idx;
  97563. + void *drv_data;
  97564. +
  97565. + drv_data = platform_get_drvdata(pdev);
  97566. +
  97567. + if (drv_data == (void *)g_card) {
  97568. + /* This is the card device */
  97569. + snd_card_free((struct snd_card *)drv_data);
  97570. + g_card = NULL;
  97571. + g_chip = NULL;
  97572. + } else {
  97573. + idx = (uint32_t) drv_data;
  97574. + if (g_card != NULL) {
  97575. + BUG_ON(!g_chip);
  97576. + /* We pass chip device numbers in audio ipc devices
  97577. + * other than the one we registered our card with
  97578. + */
  97579. + idx = (uint32_t) drv_data;
  97580. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  97581. + g_chip->avail_substreams &= ~(1 << idx);
  97582. + /* There should be atleast one substream registered
  97583. + * after we are done here, as it wil be removed when
  97584. + * the *remove* is called for the card device
  97585. + */
  97586. + BUG_ON(!g_chip->avail_substreams);
  97587. + }
  97588. + }
  97589. +
  97590. + platform_set_drvdata(pdev, NULL);
  97591. +
  97592. + return 0;
  97593. +}
  97594. +
  97595. +#ifdef CONFIG_PM
  97596. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  97597. + pm_message_t state)
  97598. +{
  97599. + return 0;
  97600. +}
  97601. +
  97602. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  97603. +{
  97604. + return 0;
  97605. +}
  97606. +
  97607. +#endif
  97608. +
  97609. +static struct platform_driver bcm2835_alsa0_driver = {
  97610. + .probe = snd_bcm2835_alsa_probe,
  97611. + .remove = snd_bcm2835_alsa_remove,
  97612. +#ifdef CONFIG_PM
  97613. + .suspend = snd_bcm2835_alsa_suspend,
  97614. + .resume = snd_bcm2835_alsa_resume,
  97615. +#endif
  97616. + .driver = {
  97617. + .name = "bcm2835_AUD0",
  97618. + .owner = THIS_MODULE,
  97619. + },
  97620. +};
  97621. +
  97622. +static struct platform_driver bcm2835_alsa1_driver = {
  97623. + .probe = snd_bcm2835_alsa_probe,
  97624. + .remove = snd_bcm2835_alsa_remove,
  97625. +#ifdef CONFIG_PM
  97626. + .suspend = snd_bcm2835_alsa_suspend,
  97627. + .resume = snd_bcm2835_alsa_resume,
  97628. +#endif
  97629. + .driver = {
  97630. + .name = "bcm2835_AUD1",
  97631. + .owner = THIS_MODULE,
  97632. + },
  97633. +};
  97634. +
  97635. +static struct platform_driver bcm2835_alsa2_driver = {
  97636. + .probe = snd_bcm2835_alsa_probe,
  97637. + .remove = snd_bcm2835_alsa_remove,
  97638. +#ifdef CONFIG_PM
  97639. + .suspend = snd_bcm2835_alsa_suspend,
  97640. + .resume = snd_bcm2835_alsa_resume,
  97641. +#endif
  97642. + .driver = {
  97643. + .name = "bcm2835_AUD2",
  97644. + .owner = THIS_MODULE,
  97645. + },
  97646. +};
  97647. +
  97648. +static struct platform_driver bcm2835_alsa3_driver = {
  97649. + .probe = snd_bcm2835_alsa_probe,
  97650. + .remove = snd_bcm2835_alsa_remove,
  97651. +#ifdef CONFIG_PM
  97652. + .suspend = snd_bcm2835_alsa_suspend,
  97653. + .resume = snd_bcm2835_alsa_resume,
  97654. +#endif
  97655. + .driver = {
  97656. + .name = "bcm2835_AUD3",
  97657. + .owner = THIS_MODULE,
  97658. + },
  97659. +};
  97660. +
  97661. +static struct platform_driver bcm2835_alsa4_driver = {
  97662. + .probe = snd_bcm2835_alsa_probe,
  97663. + .remove = snd_bcm2835_alsa_remove,
  97664. +#ifdef CONFIG_PM
  97665. + .suspend = snd_bcm2835_alsa_suspend,
  97666. + .resume = snd_bcm2835_alsa_resume,
  97667. +#endif
  97668. + .driver = {
  97669. + .name = "bcm2835_AUD4",
  97670. + .owner = THIS_MODULE,
  97671. + },
  97672. +};
  97673. +
  97674. +static struct platform_driver bcm2835_alsa5_driver = {
  97675. + .probe = snd_bcm2835_alsa_probe,
  97676. + .remove = snd_bcm2835_alsa_remove,
  97677. +#ifdef CONFIG_PM
  97678. + .suspend = snd_bcm2835_alsa_suspend,
  97679. + .resume = snd_bcm2835_alsa_resume,
  97680. +#endif
  97681. + .driver = {
  97682. + .name = "bcm2835_AUD5",
  97683. + .owner = THIS_MODULE,
  97684. + },
  97685. +};
  97686. +
  97687. +static struct platform_driver bcm2835_alsa6_driver = {
  97688. + .probe = snd_bcm2835_alsa_probe,
  97689. + .remove = snd_bcm2835_alsa_remove,
  97690. +#ifdef CONFIG_PM
  97691. + .suspend = snd_bcm2835_alsa_suspend,
  97692. + .resume = snd_bcm2835_alsa_resume,
  97693. +#endif
  97694. + .driver = {
  97695. + .name = "bcm2835_AUD6",
  97696. + .owner = THIS_MODULE,
  97697. + },
  97698. +};
  97699. +
  97700. +static struct platform_driver bcm2835_alsa7_driver = {
  97701. + .probe = snd_bcm2835_alsa_probe,
  97702. + .remove = snd_bcm2835_alsa_remove,
  97703. +#ifdef CONFIG_PM
  97704. + .suspend = snd_bcm2835_alsa_suspend,
  97705. + .resume = snd_bcm2835_alsa_resume,
  97706. +#endif
  97707. + .driver = {
  97708. + .name = "bcm2835_AUD7",
  97709. + .owner = THIS_MODULE,
  97710. + },
  97711. +};
  97712. +
  97713. +static int bcm2835_alsa_device_init(void)
  97714. +{
  97715. + int err;
  97716. + err = platform_driver_register(&bcm2835_alsa0_driver);
  97717. + if (err) {
  97718. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97719. + goto out;
  97720. + }
  97721. +
  97722. + err = platform_driver_register(&bcm2835_alsa1_driver);
  97723. + if (err) {
  97724. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97725. + goto unregister_0;
  97726. + }
  97727. +
  97728. + err = platform_driver_register(&bcm2835_alsa2_driver);
  97729. + if (err) {
  97730. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97731. + goto unregister_1;
  97732. + }
  97733. +
  97734. + err = platform_driver_register(&bcm2835_alsa3_driver);
  97735. + if (err) {
  97736. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97737. + goto unregister_2;
  97738. + }
  97739. +
  97740. + err = platform_driver_register(&bcm2835_alsa4_driver);
  97741. + if (err) {
  97742. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97743. + goto unregister_3;
  97744. + }
  97745. +
  97746. + err = platform_driver_register(&bcm2835_alsa5_driver);
  97747. + if (err) {
  97748. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97749. + goto unregister_4;
  97750. + }
  97751. +
  97752. + err = platform_driver_register(&bcm2835_alsa6_driver);
  97753. + if (err) {
  97754. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97755. + goto unregister_5;
  97756. + }
  97757. +
  97758. + err = platform_driver_register(&bcm2835_alsa7_driver);
  97759. + if (err) {
  97760. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97761. + goto unregister_6;
  97762. + }
  97763. +
  97764. + return 0;
  97765. +
  97766. +unregister_6:
  97767. + platform_driver_unregister(&bcm2835_alsa6_driver);
  97768. +unregister_5:
  97769. + platform_driver_unregister(&bcm2835_alsa5_driver);
  97770. +unregister_4:
  97771. + platform_driver_unregister(&bcm2835_alsa4_driver);
  97772. +unregister_3:
  97773. + platform_driver_unregister(&bcm2835_alsa3_driver);
  97774. +unregister_2:
  97775. + platform_driver_unregister(&bcm2835_alsa2_driver);
  97776. +unregister_1:
  97777. + platform_driver_unregister(&bcm2835_alsa1_driver);
  97778. +unregister_0:
  97779. + platform_driver_unregister(&bcm2835_alsa0_driver);
  97780. +out:
  97781. + return err;
  97782. +}
  97783. +
  97784. +static void bcm2835_alsa_device_exit(void)
  97785. +{
  97786. + platform_driver_unregister(&bcm2835_alsa0_driver);
  97787. + platform_driver_unregister(&bcm2835_alsa1_driver);
  97788. + platform_driver_unregister(&bcm2835_alsa2_driver);
  97789. + platform_driver_unregister(&bcm2835_alsa3_driver);
  97790. + platform_driver_unregister(&bcm2835_alsa4_driver);
  97791. + platform_driver_unregister(&bcm2835_alsa5_driver);
  97792. + platform_driver_unregister(&bcm2835_alsa6_driver);
  97793. + platform_driver_unregister(&bcm2835_alsa7_driver);
  97794. +}
  97795. +
  97796. +late_initcall(bcm2835_alsa_device_init);
  97797. +module_exit(bcm2835_alsa_device_exit);
  97798. +
  97799. +MODULE_AUTHOR("Dom Cobley");
  97800. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  97801. +MODULE_LICENSE("GPL");
  97802. +MODULE_ALIAS("platform:bcm2835_alsa");
  97803. diff -Nur linux-3.10.33/sound/arm/bcm2835-ctl.c linux-raspberry-pi/sound/arm/bcm2835-ctl.c
  97804. --- linux-3.10.33/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  97805. +++ linux-raspberry-pi/sound/arm/bcm2835-ctl.c 2014-03-13 12:46:44.052107092 +0100
  97806. @@ -0,0 +1,200 @@
  97807. +/*****************************************************************************
  97808. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97809. +*
  97810. +* Unless you and Broadcom execute a separate written software license
  97811. +* agreement governing use of this software, this software is licensed to you
  97812. +* under the terms of the GNU General Public License version 2, available at
  97813. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97814. +*
  97815. +* Notwithstanding the above, under no circumstances may you combine this
  97816. +* software in any way with any other Broadcom software provided under a
  97817. +* license other than the GPL, without Broadcom's express prior written
  97818. +* consent.
  97819. +*****************************************************************************/
  97820. +
  97821. +#include <linux/platform_device.h>
  97822. +#include <linux/init.h>
  97823. +#include <linux/io.h>
  97824. +#include <linux/jiffies.h>
  97825. +#include <linux/slab.h>
  97826. +#include <linux/time.h>
  97827. +#include <linux/wait.h>
  97828. +#include <linux/delay.h>
  97829. +#include <linux/moduleparam.h>
  97830. +#include <linux/sched.h>
  97831. +
  97832. +#include <sound/core.h>
  97833. +#include <sound/control.h>
  97834. +#include <sound/pcm.h>
  97835. +#include <sound/pcm_params.h>
  97836. +#include <sound/rawmidi.h>
  97837. +#include <sound/initval.h>
  97838. +#include <sound/tlv.h>
  97839. +
  97840. +#include "bcm2835.h"
  97841. +
  97842. +/* volume maximum and minimum in terms of 0.01dB */
  97843. +#define CTRL_VOL_MAX 400
  97844. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  97845. +
  97846. +
  97847. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  97848. + struct snd_ctl_elem_info *uinfo)
  97849. +{
  97850. + audio_info(" ... IN\n");
  97851. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  97852. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  97853. + uinfo->count = 1;
  97854. + uinfo->value.integer.min = CTRL_VOL_MIN;
  97855. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  97856. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  97857. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  97858. + uinfo->count = 1;
  97859. + uinfo->value.integer.min = 0;
  97860. + uinfo->value.integer.max = 1;
  97861. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  97862. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  97863. + uinfo->count = 1;
  97864. + uinfo->value.integer.min = 0;
  97865. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  97866. + }
  97867. + audio_info(" ... OUT\n");
  97868. + return 0;
  97869. +}
  97870. +
  97871. +/* toggles mute on or off depending on the value of nmute, and returns
  97872. + * 1 if the mute value was changed, otherwise 0
  97873. + */
  97874. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  97875. +{
  97876. + /* if settings are ok, just return 0 */
  97877. + if(chip->mute == nmute)
  97878. + return 0;
  97879. +
  97880. + /* if the sound is muted then we need to unmute */
  97881. + if(chip->mute == CTRL_VOL_MUTE)
  97882. + {
  97883. + chip->volume = chip->old_volume; /* copy the old volume back */
  97884. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  97885. + }
  97886. + else /* otherwise we mute */
  97887. + {
  97888. + chip->old_volume = chip->volume;
  97889. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  97890. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  97891. + }
  97892. +
  97893. + chip->mute = nmute;
  97894. + return 1;
  97895. +}
  97896. +
  97897. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  97898. + struct snd_ctl_elem_value *ucontrol)
  97899. +{
  97900. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  97901. +
  97902. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  97903. +
  97904. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  97905. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  97906. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  97907. + ucontrol->value.integer.value[0] = chip->mute;
  97908. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  97909. + ucontrol->value.integer.value[0] = chip->dest;
  97910. +
  97911. + return 0;
  97912. +}
  97913. +
  97914. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  97915. + struct snd_ctl_elem_value *ucontrol)
  97916. +{
  97917. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  97918. + int changed = 0;
  97919. +
  97920. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  97921. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  97922. + if (chip->mute == CTRL_VOL_MUTE) {
  97923. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  97924. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  97925. + }
  97926. + if (changed
  97927. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  97928. +
  97929. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  97930. + changed = 1;
  97931. + }
  97932. +
  97933. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  97934. + /* Now implemented */
  97935. + audio_info(" Mute attempted\n");
  97936. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  97937. +
  97938. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  97939. + if (ucontrol->value.integer.value[0] != chip->dest) {
  97940. + chip->dest = ucontrol->value.integer.value[0];
  97941. + changed = 1;
  97942. + }
  97943. + }
  97944. +
  97945. + if (changed) {
  97946. + if (bcm2835_audio_set_ctls(chip))
  97947. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  97948. + }
  97949. +
  97950. + return changed;
  97951. +}
  97952. +
  97953. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  97954. +
  97955. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  97956. + {
  97957. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97958. + .name = "PCM Playback Volume",
  97959. + .index = 0,
  97960. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  97961. + .private_value = PCM_PLAYBACK_VOLUME,
  97962. + .info = snd_bcm2835_ctl_info,
  97963. + .get = snd_bcm2835_ctl_get,
  97964. + .put = snd_bcm2835_ctl_put,
  97965. + .count = 1,
  97966. + .tlv = {.p = snd_bcm2835_db_scale}
  97967. + },
  97968. + {
  97969. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97970. + .name = "PCM Playback Switch",
  97971. + .index = 0,
  97972. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  97973. + .private_value = PCM_PLAYBACK_MUTE,
  97974. + .info = snd_bcm2835_ctl_info,
  97975. + .get = snd_bcm2835_ctl_get,
  97976. + .put = snd_bcm2835_ctl_put,
  97977. + .count = 1,
  97978. + },
  97979. + {
  97980. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97981. + .name = "PCM Playback Route",
  97982. + .index = 0,
  97983. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  97984. + .private_value = PCM_PLAYBACK_DEVICE,
  97985. + .info = snd_bcm2835_ctl_info,
  97986. + .get = snd_bcm2835_ctl_get,
  97987. + .put = snd_bcm2835_ctl_put,
  97988. + .count = 1,
  97989. + },
  97990. +};
  97991. +
  97992. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  97993. +{
  97994. + int err;
  97995. + unsigned int idx;
  97996. +
  97997. + strcpy(chip->card->mixername, "Broadcom Mixer");
  97998. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  97999. + err =
  98000. + snd_ctl_add(chip->card,
  98001. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  98002. + if (err < 0)
  98003. + return err;
  98004. + }
  98005. + return 0;
  98006. +}
  98007. diff -Nur linux-3.10.33/sound/arm/bcm2835.h linux-raspberry-pi/sound/arm/bcm2835.h
  98008. --- linux-3.10.33/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  98009. +++ linux-raspberry-pi/sound/arm/bcm2835.h 2014-03-13 12:46:44.060107108 +0100
  98010. @@ -0,0 +1,157 @@
  98011. +/*****************************************************************************
  98012. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  98013. +*
  98014. +* Unless you and Broadcom execute a separate written software license
  98015. +* agreement governing use of this software, this software is licensed to you
  98016. +* under the terms of the GNU General Public License version 2, available at
  98017. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98018. +*
  98019. +* Notwithstanding the above, under no circumstances may you combine this
  98020. +* software in any way with any other Broadcom software provided under a
  98021. +* license other than the GPL, without Broadcom's express prior written
  98022. +* consent.
  98023. +*****************************************************************************/
  98024. +
  98025. +#ifndef __SOUND_ARM_BCM2835_H
  98026. +#define __SOUND_ARM_BCM2835_H
  98027. +
  98028. +#include <linux/device.h>
  98029. +#include <linux/list.h>
  98030. +#include <linux/interrupt.h>
  98031. +#include <linux/wait.h>
  98032. +#include <sound/core.h>
  98033. +#include <sound/initval.h>
  98034. +#include <sound/pcm.h>
  98035. +#include <sound/pcm_params.h>
  98036. +#include <sound/pcm-indirect.h>
  98037. +#include <linux/workqueue.h>
  98038. +
  98039. +/*
  98040. +#define AUDIO_DEBUG_ENABLE
  98041. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  98042. +*/
  98043. +
  98044. +/* Debug macros */
  98045. +
  98046. +#ifdef AUDIO_DEBUG_ENABLE
  98047. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  98048. +
  98049. +#define audio_debug(fmt, arg...) \
  98050. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  98051. +
  98052. +#define audio_info(fmt, arg...) \
  98053. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  98054. +
  98055. +#else
  98056. +
  98057. +#define audio_debug(fmt, arg...)
  98058. +
  98059. +#define audio_info(fmt, arg...)
  98060. +
  98061. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  98062. +
  98063. +#else
  98064. +
  98065. +#define audio_debug(fmt, arg...)
  98066. +
  98067. +#define audio_info(fmt, arg...)
  98068. +
  98069. +#endif /* AUDIO_DEBUG_ENABLE */
  98070. +
  98071. +#define audio_error(fmt, arg...) \
  98072. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  98073. +
  98074. +#define audio_warning(fmt, arg...) \
  98075. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  98076. +
  98077. +#define audio_alert(fmt, arg...) \
  98078. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  98079. +
  98080. +#define MAX_SUBSTREAMS (8)
  98081. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  98082. +enum {
  98083. + CTRL_VOL_MUTE,
  98084. + CTRL_VOL_UNMUTE
  98085. +};
  98086. +
  98087. +/* macros for alsa2chip and chip2alsa, instead of functions */
  98088. +
  98089. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  98090. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  98091. +
  98092. +/* Some constants for values .. */
  98093. +typedef enum {
  98094. + AUDIO_DEST_AUTO = 0,
  98095. + AUDIO_DEST_HEADPHONES = 1,
  98096. + AUDIO_DEST_HDMI = 2,
  98097. + AUDIO_DEST_MAX,
  98098. +} SND_BCM2835_ROUTE_T;
  98099. +
  98100. +typedef enum {
  98101. + PCM_PLAYBACK_VOLUME,
  98102. + PCM_PLAYBACK_MUTE,
  98103. + PCM_PLAYBACK_DEVICE,
  98104. +} SND_BCM2835_CTRL_T;
  98105. +
  98106. +/* definition of the chip-specific record */
  98107. +typedef struct bcm2835_chip {
  98108. + struct snd_card *card;
  98109. + struct snd_pcm *pcm;
  98110. + /* Bitmat for valid reg_base and irq numbers */
  98111. + uint32_t avail_substreams;
  98112. + struct platform_device *pdev[MAX_SUBSTREAMS];
  98113. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  98114. +
  98115. + int volume;
  98116. + int old_volume; /* stores the volume value whist muted */
  98117. + int dest;
  98118. + int mute;
  98119. +} bcm2835_chip_t;
  98120. +
  98121. +typedef struct bcm2835_alsa_stream {
  98122. + bcm2835_chip_t *chip;
  98123. + struct snd_pcm_substream *substream;
  98124. + struct snd_pcm_indirect pcm_indirect;
  98125. +
  98126. + struct semaphore buffers_update_sem;
  98127. + struct semaphore control_sem;
  98128. + spinlock_t lock;
  98129. + volatile uint32_t control;
  98130. + volatile uint32_t status;
  98131. +
  98132. + int open;
  98133. + int running;
  98134. + int draining;
  98135. +
  98136. + unsigned int pos;
  98137. + unsigned int buffer_size;
  98138. + unsigned int period_size;
  98139. +
  98140. + uint32_t enable_fifo_irq;
  98141. + irq_handler_t fifo_irq_handler;
  98142. +
  98143. + atomic_t retrieved;
  98144. + struct opaque_AUDIO_INSTANCE_T *instance;
  98145. + struct workqueue_struct *my_wq;
  98146. + int idx;
  98147. +} bcm2835_alsa_stream_t;
  98148. +
  98149. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  98150. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  98151. +
  98152. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  98153. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  98154. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  98155. + uint32_t channels, uint32_t samplerate,
  98156. + uint32_t bps);
  98157. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  98158. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  98159. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  98160. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  98161. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  98162. + void *src);
  98163. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  98164. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  98165. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  98166. +
  98167. +#endif /* __SOUND_ARM_BCM2835_H */
  98168. diff -Nur linux-3.10.33/sound/arm/bcm2835-pcm.c linux-raspberry-pi/sound/arm/bcm2835-pcm.c
  98169. --- linux-3.10.33/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  98170. +++ linux-raspberry-pi/sound/arm/bcm2835-pcm.c 2014-03-13 12:46:44.052107092 +0100
  98171. @@ -0,0 +1,426 @@
  98172. +/*****************************************************************************
  98173. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  98174. +*
  98175. +* Unless you and Broadcom execute a separate written software license
  98176. +* agreement governing use of this software, this software is licensed to you
  98177. +* under the terms of the GNU General Public License version 2, available at
  98178. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98179. +*
  98180. +* Notwithstanding the above, under no circumstances may you combine this
  98181. +* software in any way with any other Broadcom software provided under a
  98182. +* license other than the GPL, without Broadcom's express prior written
  98183. +* consent.
  98184. +*****************************************************************************/
  98185. +
  98186. +#include <linux/interrupt.h>
  98187. +#include <linux/slab.h>
  98188. +
  98189. +#include "bcm2835.h"
  98190. +
  98191. +/* hardware definition */
  98192. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  98193. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  98194. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  98195. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  98196. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  98197. + .rate_min = 8000,
  98198. + .rate_max = 48000,
  98199. + .channels_min = 1,
  98200. + .channels_max = 2,
  98201. + .buffer_bytes_max = 128 * 1024,
  98202. + .period_bytes_min = 1 * 1024,
  98203. + .period_bytes_max = 128 * 1024,
  98204. + .periods_min = 1,
  98205. + .periods_max = 128,
  98206. +};
  98207. +
  98208. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  98209. +{
  98210. + audio_info("Freeing up alsa stream here ..\n");
  98211. + if (runtime->private_data)
  98212. + kfree(runtime->private_data);
  98213. + runtime->private_data = NULL;
  98214. +}
  98215. +
  98216. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  98217. +{
  98218. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  98219. + uint32_t consumed = 0;
  98220. + int new_period = 0;
  98221. +
  98222. + audio_info(" .. IN\n");
  98223. +
  98224. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  98225. + alsa_stream ? alsa_stream->substream : 0);
  98226. +
  98227. + if (alsa_stream->open)
  98228. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  98229. +
  98230. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  98231. + * each iteration are the buffers that have been played out already
  98232. + */
  98233. +
  98234. + if (alsa_stream->period_size) {
  98235. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  98236. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  98237. + new_period = 1;
  98238. + }
  98239. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  98240. + alsa_stream->pos,
  98241. + consumed,
  98242. + alsa_stream->buffer_size,
  98243. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  98244. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  98245. + new_period);
  98246. + if (alsa_stream->buffer_size) {
  98247. + alsa_stream->pos += consumed &~ (1<<30);
  98248. + alsa_stream->pos %= alsa_stream->buffer_size;
  98249. + }
  98250. +
  98251. + if (alsa_stream->substream) {
  98252. + if (new_period)
  98253. + snd_pcm_period_elapsed(alsa_stream->substream);
  98254. + } else {
  98255. + audio_warning(" unexpected NULL substream\n");
  98256. + }
  98257. + audio_info(" .. OUT\n");
  98258. +
  98259. + return IRQ_HANDLED;
  98260. +}
  98261. +
  98262. +/* open callback */
  98263. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  98264. +{
  98265. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  98266. + struct snd_pcm_runtime *runtime = substream->runtime;
  98267. + bcm2835_alsa_stream_t *alsa_stream;
  98268. + int idx;
  98269. + int err;
  98270. +
  98271. + audio_info(" .. IN (%d)\n", substream->number);
  98272. +
  98273. + audio_info("Alsa open (%d)\n", substream->number);
  98274. + idx = substream->number;
  98275. +
  98276. + if (idx > MAX_SUBSTREAMS) {
  98277. + audio_error
  98278. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  98279. + idx, MAX_SUBSTREAMS);
  98280. + err = -ENODEV;
  98281. + goto out;
  98282. + }
  98283. +
  98284. + /* Check if we are ready */
  98285. + if (!(chip->avail_substreams & (1 << idx))) {
  98286. + /* We are not ready yet */
  98287. + audio_error("substream(%d) device is not ready yet\n", idx);
  98288. + err = -EAGAIN;
  98289. + goto out;
  98290. + }
  98291. +
  98292. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  98293. + if (alsa_stream == NULL) {
  98294. + return -ENOMEM;
  98295. + }
  98296. +
  98297. + /* Initialise alsa_stream */
  98298. + alsa_stream->chip = chip;
  98299. + alsa_stream->substream = substream;
  98300. + alsa_stream->idx = idx;
  98301. +
  98302. + sema_init(&alsa_stream->buffers_update_sem, 0);
  98303. + sema_init(&alsa_stream->control_sem, 0);
  98304. + spin_lock_init(&alsa_stream->lock);
  98305. +
  98306. + /* Enabled in start trigger, called on each "fifo irq" after that */
  98307. + alsa_stream->enable_fifo_irq = 0;
  98308. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  98309. +
  98310. + runtime->private_data = alsa_stream;
  98311. + runtime->private_free = snd_bcm2835_playback_free;
  98312. + runtime->hw = snd_bcm2835_playback_hw;
  98313. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  98314. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  98315. + 16);
  98316. +
  98317. + err = bcm2835_audio_open(alsa_stream);
  98318. + if (err != 0) {
  98319. + kfree(alsa_stream);
  98320. + return err;
  98321. + }
  98322. + chip->alsa_stream[idx] = alsa_stream;
  98323. +
  98324. + alsa_stream->open = 1;
  98325. + alsa_stream->draining = 1;
  98326. +
  98327. +out:
  98328. + audio_info(" .. OUT =%d\n", err);
  98329. +
  98330. + return err;
  98331. +}
  98332. +
  98333. +/* close callback */
  98334. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  98335. +{
  98336. + /* the hardware-specific codes will be here */
  98337. +
  98338. + struct snd_pcm_runtime *runtime = substream->runtime;
  98339. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  98340. +
  98341. + audio_info(" .. IN\n");
  98342. + audio_info("Alsa close\n");
  98343. +
  98344. + /*
  98345. + * Call stop if it's still running. This happens when app
  98346. + * is force killed and we don't get a stop trigger.
  98347. + */
  98348. + if (alsa_stream->running) {
  98349. + int err;
  98350. + err = bcm2835_audio_stop(alsa_stream);
  98351. + alsa_stream->running = 0;
  98352. + if (err != 0)
  98353. + audio_error(" Failed to STOP alsa device\n");
  98354. + }
  98355. +
  98356. + alsa_stream->period_size = 0;
  98357. + alsa_stream->buffer_size = 0;
  98358. +
  98359. + if (alsa_stream->open) {
  98360. + alsa_stream->open = 0;
  98361. + bcm2835_audio_close(alsa_stream);
  98362. + }
  98363. + if (alsa_stream->chip)
  98364. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  98365. + /*
  98366. + * Do not free up alsa_stream here, it will be freed up by
  98367. + * runtime->private_free callback we registered in *_open above
  98368. + */
  98369. +
  98370. + audio_info(" .. OUT\n");
  98371. +
  98372. + return 0;
  98373. +}
  98374. +
  98375. +/* hw_params callback */
  98376. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  98377. + struct snd_pcm_hw_params *params)
  98378. +{
  98379. + int err;
  98380. + struct snd_pcm_runtime *runtime = substream->runtime;
  98381. + bcm2835_alsa_stream_t *alsa_stream =
  98382. + (bcm2835_alsa_stream_t *) runtime->private_data;
  98383. +
  98384. + audio_info(" .. IN\n");
  98385. +
  98386. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  98387. + if (err < 0) {
  98388. + audio_error
  98389. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  98390. + return err;
  98391. + }
  98392. +
  98393. + err = bcm2835_audio_set_params(alsa_stream, params_channels(params),
  98394. + params_rate(params),
  98395. + snd_pcm_format_width(params_format
  98396. + (params)));
  98397. + if (err < 0) {
  98398. + audio_error(" error setting hw params\n");
  98399. + }
  98400. +
  98401. + bcm2835_audio_setup(alsa_stream);
  98402. +
  98403. + /* in preparation of the stream, set the controls (volume level) of the stream */
  98404. + bcm2835_audio_set_ctls(alsa_stream->chip);
  98405. +
  98406. + audio_info(" .. OUT\n");
  98407. +
  98408. + return err;
  98409. +}
  98410. +
  98411. +/* hw_free callback */
  98412. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  98413. +{
  98414. + audio_info(" .. IN\n");
  98415. + return snd_pcm_lib_free_pages(substream);
  98416. +}
  98417. +
  98418. +/* prepare callback */
  98419. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  98420. +{
  98421. + struct snd_pcm_runtime *runtime = substream->runtime;
  98422. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  98423. +
  98424. + audio_info(" .. IN\n");
  98425. +
  98426. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  98427. +
  98428. + alsa_stream->pcm_indirect.hw_buffer_size =
  98429. + alsa_stream->pcm_indirect.sw_buffer_size =
  98430. + snd_pcm_lib_buffer_bytes(substream);
  98431. +
  98432. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  98433. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  98434. + alsa_stream->pos = 0;
  98435. +
  98436. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  98437. + alsa_stream->buffer_size, alsa_stream->period_size,
  98438. + alsa_stream->pos, runtime->frame_bits);
  98439. +
  98440. + audio_info(" .. OUT\n");
  98441. + return 0;
  98442. +}
  98443. +
  98444. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  98445. + struct snd_pcm_indirect *rec, size_t bytes)
  98446. +{
  98447. + struct snd_pcm_runtime *runtime = substream->runtime;
  98448. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  98449. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  98450. + int err;
  98451. +
  98452. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  98453. + if (err)
  98454. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  98455. +
  98456. +}
  98457. +
  98458. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  98459. +{
  98460. + struct snd_pcm_runtime *runtime = substream->runtime;
  98461. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  98462. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  98463. +
  98464. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  98465. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  98466. + snd_bcm2835_pcm_transfer);
  98467. + return 0;
  98468. +}
  98469. +
  98470. +/* trigger callback */
  98471. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  98472. +{
  98473. + struct snd_pcm_runtime *runtime = substream->runtime;
  98474. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  98475. + int err = 0;
  98476. +
  98477. + audio_info(" .. IN\n");
  98478. +
  98479. + switch (cmd) {
  98480. + case SNDRV_PCM_TRIGGER_START:
  98481. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  98482. + alsa_stream->running);
  98483. + if (!alsa_stream->running) {
  98484. + err = bcm2835_audio_start(alsa_stream);
  98485. + if (err == 0) {
  98486. + alsa_stream->pcm_indirect.hw_io =
  98487. + alsa_stream->pcm_indirect.hw_data =
  98488. + bytes_to_frames(runtime,
  98489. + alsa_stream->pos);
  98490. + substream->ops->ack(substream);
  98491. + alsa_stream->running = 1;
  98492. + alsa_stream->draining = 1;
  98493. + } else {
  98494. + audio_error(" Failed to START alsa device (%d)\n", err);
  98495. + }
  98496. + }
  98497. + break;
  98498. + case SNDRV_PCM_TRIGGER_STOP:
  98499. + audio_debug
  98500. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  98501. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  98502. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  98503. + audio_info("DRAINING\n");
  98504. + alsa_stream->draining = 1;
  98505. + } else {
  98506. + audio_info("DROPPING\n");
  98507. + alsa_stream->draining = 0;
  98508. + }
  98509. + if (alsa_stream->running) {
  98510. + err = bcm2835_audio_stop(alsa_stream);
  98511. + if (err != 0)
  98512. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  98513. + alsa_stream->running = 0;
  98514. + }
  98515. + break;
  98516. + default:
  98517. + err = -EINVAL;
  98518. + }
  98519. +
  98520. + audio_info(" .. OUT\n");
  98521. + return err;
  98522. +}
  98523. +
  98524. +/* pointer callback */
  98525. +static snd_pcm_uframes_t
  98526. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  98527. +{
  98528. + struct snd_pcm_runtime *runtime = substream->runtime;
  98529. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  98530. +
  98531. + audio_info(" .. IN\n");
  98532. +
  98533. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  98534. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  98535. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  98536. + alsa_stream->pos);
  98537. +
  98538. + audio_info(" .. OUT\n");
  98539. + return snd_pcm_indirect_playback_pointer(substream,
  98540. + &alsa_stream->pcm_indirect,
  98541. + alsa_stream->pos);
  98542. +}
  98543. +
  98544. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  98545. + unsigned int cmd, void *arg)
  98546. +{
  98547. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  98548. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  98549. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  98550. + return ret;
  98551. +}
  98552. +
  98553. +/* operators */
  98554. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  98555. + .open = snd_bcm2835_playback_open,
  98556. + .close = snd_bcm2835_playback_close,
  98557. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  98558. + .hw_params = snd_bcm2835_pcm_hw_params,
  98559. + .hw_free = snd_bcm2835_pcm_hw_free,
  98560. + .prepare = snd_bcm2835_pcm_prepare,
  98561. + .trigger = snd_bcm2835_pcm_trigger,
  98562. + .pointer = snd_bcm2835_pcm_pointer,
  98563. + .ack = snd_bcm2835_pcm_ack,
  98564. +};
  98565. +
  98566. +/* create a pcm device */
  98567. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  98568. +{
  98569. + struct snd_pcm *pcm;
  98570. + int err;
  98571. +
  98572. + audio_info(" .. IN\n");
  98573. + err =
  98574. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  98575. + if (err < 0)
  98576. + return err;
  98577. + pcm->private_data = chip;
  98578. + strcpy(pcm->name, "bcm2835 ALSA");
  98579. + chip->pcm = pcm;
  98580. + chip->dest = AUDIO_DEST_AUTO;
  98581. + chip->volume = alsa2chip(0);
  98582. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  98583. + /* set operators */
  98584. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  98585. + &snd_bcm2835_playback_ops);
  98586. +
  98587. + /* pre-allocation of buffers */
  98588. + /* NOTE: this may fail */
  98589. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  98590. + snd_dma_continuous_data
  98591. + (GFP_KERNEL), 64 * 1024,
  98592. + 64 * 1024);
  98593. +
  98594. + audio_info(" .. OUT\n");
  98595. +
  98596. + return 0;
  98597. +}
  98598. diff -Nur linux-3.10.33/sound/arm/bcm2835-vchiq.c linux-raspberry-pi/sound/arm/bcm2835-vchiq.c
  98599. --- linux-3.10.33/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  98600. +++ linux-raspberry-pi/sound/arm/bcm2835-vchiq.c 2014-03-13 12:46:44.060107108 +0100
  98601. @@ -0,0 +1,879 @@
  98602. +/*****************************************************************************
  98603. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  98604. +*
  98605. +* Unless you and Broadcom execute a separate written software license
  98606. +* agreement governing use of this software, this software is licensed to you
  98607. +* under the terms of the GNU General Public License version 2, available at
  98608. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98609. +*
  98610. +* Notwithstanding the above, under no circumstances may you combine this
  98611. +* software in any way with any other Broadcom software provided under a
  98612. +* license other than the GPL, without Broadcom's express prior written
  98613. +* consent.
  98614. +*****************************************************************************/
  98615. +
  98616. +#include <linux/device.h>
  98617. +#include <sound/core.h>
  98618. +#include <sound/initval.h>
  98619. +#include <sound/pcm.h>
  98620. +#include <linux/io.h>
  98621. +#include <linux/interrupt.h>
  98622. +#include <linux/fs.h>
  98623. +#include <linux/file.h>
  98624. +#include <linux/mm.h>
  98625. +#include <linux/syscalls.h>
  98626. +#include <asm/uaccess.h>
  98627. +#include <linux/slab.h>
  98628. +#include <linux/delay.h>
  98629. +#include <linux/atomic.h>
  98630. +#include <linux/module.h>
  98631. +#include <linux/completion.h>
  98632. +
  98633. +#include "bcm2835.h"
  98634. +
  98635. +/* ---- Include Files -------------------------------------------------------- */
  98636. +
  98637. +#include "interface/vchi/vchi.h"
  98638. +#include "vc_vchi_audioserv_defs.h"
  98639. +
  98640. +/* ---- Private Constants and Types ------------------------------------------ */
  98641. +
  98642. +#define BCM2835_AUDIO_STOP 0
  98643. +#define BCM2835_AUDIO_START 1
  98644. +#define BCM2835_AUDIO_WRITE 2
  98645. +
  98646. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  98647. +#ifdef AUDIO_DEBUG_ENABLE
  98648. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  98649. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  98650. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  98651. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  98652. +#else
  98653. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  98654. + #define LOG_WARN( fmt, arg... )
  98655. + #define LOG_INFO( fmt, arg... )
  98656. + #define LOG_DBG( fmt, arg... )
  98657. +#endif
  98658. +
  98659. +typedef struct opaque_AUDIO_INSTANCE_T {
  98660. + uint32_t num_connections;
  98661. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  98662. + struct completion msg_avail_comp;
  98663. + struct mutex vchi_mutex;
  98664. + bcm2835_alsa_stream_t *alsa_stream;
  98665. + int32_t result;
  98666. + short peer_version;
  98667. +} AUDIO_INSTANCE_T;
  98668. +
  98669. +bool force_bulk = false;
  98670. +
  98671. +/* ---- Private Variables ---------------------------------------------------- */
  98672. +
  98673. +/* ---- Private Function Prototypes ------------------------------------------ */
  98674. +
  98675. +/* ---- Private Functions ---------------------------------------------------- */
  98676. +
  98677. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  98678. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  98679. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  98680. + uint32_t count, void *src);
  98681. +
  98682. +typedef struct {
  98683. + struct work_struct my_work;
  98684. + bcm2835_alsa_stream_t *alsa_stream;
  98685. + int cmd;
  98686. + void *src;
  98687. + uint32_t count;
  98688. +} my_work_t;
  98689. +
  98690. +static void my_wq_function(struct work_struct *work)
  98691. +{
  98692. + my_work_t *w = (my_work_t *) work;
  98693. + int ret = -9;
  98694. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  98695. + switch (w->cmd) {
  98696. + case BCM2835_AUDIO_START:
  98697. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  98698. + break;
  98699. + case BCM2835_AUDIO_STOP:
  98700. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  98701. + break;
  98702. + case BCM2835_AUDIO_WRITE:
  98703. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  98704. + w->src);
  98705. + break;
  98706. + default:
  98707. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  98708. + break;
  98709. + }
  98710. + kfree((void *)work);
  98711. + LOG_DBG(" .. OUT %d\n", ret);
  98712. +}
  98713. +
  98714. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  98715. +{
  98716. + int ret = -1;
  98717. + LOG_DBG(" .. IN\n");
  98718. + if (alsa_stream->my_wq) {
  98719. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  98720. + /*--- Queue some work (item 1) ---*/
  98721. + if (work) {
  98722. + INIT_WORK((struct work_struct *)work, my_wq_function);
  98723. + work->alsa_stream = alsa_stream;
  98724. + work->cmd = BCM2835_AUDIO_START;
  98725. + if (queue_work
  98726. + (alsa_stream->my_wq, (struct work_struct *)work))
  98727. + ret = 0;
  98728. + } else
  98729. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  98730. + }
  98731. + LOG_DBG(" .. OUT %d\n", ret);
  98732. + return ret;
  98733. +}
  98734. +
  98735. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  98736. +{
  98737. + int ret = -1;
  98738. + LOG_DBG(" .. IN\n");
  98739. + if (alsa_stream->my_wq) {
  98740. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  98741. + /*--- Queue some work (item 1) ---*/
  98742. + if (work) {
  98743. + INIT_WORK((struct work_struct *)work, my_wq_function);
  98744. + work->alsa_stream = alsa_stream;
  98745. + work->cmd = BCM2835_AUDIO_STOP;
  98746. + if (queue_work
  98747. + (alsa_stream->my_wq, (struct work_struct *)work))
  98748. + ret = 0;
  98749. + } else
  98750. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  98751. + }
  98752. + LOG_DBG(" .. OUT %d\n", ret);
  98753. + return ret;
  98754. +}
  98755. +
  98756. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  98757. + uint32_t count, void *src)
  98758. +{
  98759. + int ret = -1;
  98760. + LOG_DBG(" .. IN\n");
  98761. + if (alsa_stream->my_wq) {
  98762. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  98763. + /*--- Queue some work (item 1) ---*/
  98764. + if (work) {
  98765. + INIT_WORK((struct work_struct *)work, my_wq_function);
  98766. + work->alsa_stream = alsa_stream;
  98767. + work->cmd = BCM2835_AUDIO_WRITE;
  98768. + work->src = src;
  98769. + work->count = count;
  98770. + if (queue_work
  98771. + (alsa_stream->my_wq, (struct work_struct *)work))
  98772. + ret = 0;
  98773. + } else
  98774. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  98775. + }
  98776. + LOG_DBG(" .. OUT %d\n", ret);
  98777. + return ret;
  98778. +}
  98779. +
  98780. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  98781. +{
  98782. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  98783. + return;
  98784. +}
  98785. +
  98786. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  98787. +{
  98788. + if (alsa_stream->my_wq) {
  98789. + flush_workqueue(alsa_stream->my_wq);
  98790. + destroy_workqueue(alsa_stream->my_wq);
  98791. + alsa_stream->my_wq = NULL;
  98792. + }
  98793. + return;
  98794. +}
  98795. +
  98796. +static void audio_vchi_callback(void *param,
  98797. + const VCHI_CALLBACK_REASON_T reason,
  98798. + void *msg_handle)
  98799. +{
  98800. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  98801. + int32_t status;
  98802. + int32_t msg_len;
  98803. + VC_AUDIO_MSG_T m;
  98804. + bcm2835_alsa_stream_t *alsa_stream = 0;
  98805. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  98806. + instance, param, reason, msg_handle);
  98807. +
  98808. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  98809. + return;
  98810. + }
  98811. + alsa_stream = instance->alsa_stream;
  98812. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  98813. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  98814. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  98815. + LOG_DBG
  98816. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  98817. + instance, m.u.result.success);
  98818. + instance->result = m.u.result.success;
  98819. + complete(&instance->msg_avail_comp);
  98820. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  98821. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  98822. + LOG_DBG
  98823. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  98824. + instance, m.u.complete.count);
  98825. + if (alsa_stream && callback) {
  98826. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  98827. + callback(0, alsa_stream);
  98828. + } else {
  98829. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  98830. + alsa_stream, callback);
  98831. + }
  98832. + } else {
  98833. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  98834. + }
  98835. + LOG_DBG(" .. OUT\n");
  98836. +}
  98837. +
  98838. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  98839. + VCHI_CONNECTION_T **
  98840. + vchi_connections,
  98841. + uint32_t num_connections)
  98842. +{
  98843. + uint32_t i;
  98844. + AUDIO_INSTANCE_T *instance;
  98845. + int status;
  98846. +
  98847. + LOG_DBG("%s: start", __func__);
  98848. +
  98849. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  98850. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  98851. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  98852. +
  98853. + return NULL;
  98854. + }
  98855. + /* Allocate memory for this instance */
  98856. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  98857. +
  98858. + memset(instance, 0, sizeof(*instance));
  98859. + instance->num_connections = num_connections;
  98860. +
  98861. + /* Create a lock for exclusive, serialized VCHI connection access */
  98862. + mutex_init(&instance->vchi_mutex);
  98863. + /* Open the VCHI service connections */
  98864. + for (i = 0; i < num_connections; i++) {
  98865. + SERVICE_CREATION_T params = {
  98866. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  98867. + VC_AUDIO_SERVER_NAME, // 4cc service code
  98868. + vchi_connections[i], // passed in fn pointers
  98869. + 0, // rx fifo size (unused)
  98870. + 0, // tx fifo size (unused)
  98871. + audio_vchi_callback, // service callback
  98872. + instance, // service callback parameter
  98873. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  98874. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  98875. + 0 // want crc check on bulk transfers
  98876. + };
  98877. +
  98878. + status = vchi_service_open(vchi_instance, &params,
  98879. + &instance->vchi_handle[i]);
  98880. + if (status) {
  98881. + LOG_ERR
  98882. + ("%s: failed to open VCHI service connection (status=%d)\n",
  98883. + __func__, status);
  98884. +
  98885. + goto err_close_services;
  98886. + }
  98887. + /* Finished with the service for now */
  98888. + vchi_service_release(instance->vchi_handle[i]);
  98889. + }
  98890. +
  98891. + return instance;
  98892. +
  98893. +err_close_services:
  98894. + for (i = 0; i < instance->num_connections; i++) {
  98895. + vchi_service_close(instance->vchi_handle[i]);
  98896. + }
  98897. +
  98898. + kfree(instance);
  98899. +
  98900. + return NULL;
  98901. +}
  98902. +
  98903. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  98904. +{
  98905. + uint32_t i;
  98906. +
  98907. + LOG_DBG(" .. IN\n");
  98908. +
  98909. + if (instance == NULL) {
  98910. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  98911. +
  98912. + return -1;
  98913. + }
  98914. +
  98915. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  98916. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98917. + {
  98918. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98919. + return -EINTR;
  98920. + }
  98921. +
  98922. + /* Close all VCHI service connections */
  98923. + for (i = 0; i < instance->num_connections; i++) {
  98924. + int32_t success;
  98925. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  98926. + vchi_service_use(instance->vchi_handle[i]);
  98927. +
  98928. + success = vchi_service_close(instance->vchi_handle[i]);
  98929. + if (success != 0) {
  98930. + LOG_ERR
  98931. + ("%s: failed to close VCHI service connection (status=%d)\n",
  98932. + __func__, success);
  98933. + }
  98934. + }
  98935. +
  98936. + mutex_unlock(&instance->vchi_mutex);
  98937. +
  98938. + kfree(instance);
  98939. +
  98940. + LOG_DBG(" .. OUT\n");
  98941. +
  98942. + return 0;
  98943. +}
  98944. +
  98945. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  98946. +{
  98947. + static VCHI_INSTANCE_T vchi_instance;
  98948. + static VCHI_CONNECTION_T *vchi_connection;
  98949. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98950. + int ret;
  98951. + LOG_DBG(" .. IN\n");
  98952. +
  98953. + LOG_INFO("%s: start", __func__);
  98954. + //BUG_ON(instance);
  98955. + if (instance) {
  98956. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  98957. + __func__, instance);
  98958. + instance->alsa_stream = alsa_stream;
  98959. + alsa_stream->instance = instance;
  98960. + ret = 0; // xxx todo -1;
  98961. + goto err_free_mem;
  98962. + }
  98963. +
  98964. + /* Initialize and create a VCHI connection */
  98965. + ret = vchi_initialise(&vchi_instance);
  98966. + if (ret != 0) {
  98967. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  98968. + __func__, ret);
  98969. +
  98970. + ret = -EIO;
  98971. + goto err_free_mem;
  98972. + }
  98973. + ret = vchi_connect(NULL, 0, vchi_instance);
  98974. + if (ret != 0) {
  98975. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  98976. + __func__, ret);
  98977. +
  98978. + ret = -EIO;
  98979. + goto err_free_mem;
  98980. + }
  98981. +
  98982. + /* Initialize an instance of the audio service */
  98983. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  98984. +
  98985. + if (instance == NULL /*|| audio_handle != instance */ ) {
  98986. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  98987. +
  98988. + ret = -EPERM;
  98989. + goto err_free_mem;
  98990. + }
  98991. +
  98992. + instance->alsa_stream = alsa_stream;
  98993. + alsa_stream->instance = instance;
  98994. +
  98995. + LOG_DBG(" success !\n");
  98996. +err_free_mem:
  98997. + LOG_DBG(" .. OUT\n");
  98998. +
  98999. + return ret;
  99000. +}
  99001. +
  99002. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  99003. +{
  99004. + AUDIO_INSTANCE_T *instance;
  99005. + VC_AUDIO_MSG_T m;
  99006. + int32_t success;
  99007. + int ret;
  99008. + LOG_DBG(" .. IN\n");
  99009. +
  99010. + my_workqueue_init(alsa_stream);
  99011. +
  99012. + ret = bcm2835_audio_open_connection(alsa_stream);
  99013. + if (ret != 0) {
  99014. + ret = -1;
  99015. + goto exit;
  99016. + }
  99017. + instance = alsa_stream->instance;
  99018. +
  99019. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99020. + {
  99021. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99022. + return -EINTR;
  99023. + }
  99024. + vchi_service_use(instance->vchi_handle[0]);
  99025. +
  99026. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  99027. +
  99028. + /* Send the message to the videocore */
  99029. + success = vchi_msg_queue(instance->vchi_handle[0],
  99030. + &m, sizeof m,
  99031. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99032. +
  99033. + if (success != 0) {
  99034. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  99035. + __func__, success);
  99036. +
  99037. + ret = -1;
  99038. + goto unlock;
  99039. + }
  99040. +
  99041. + ret = 0;
  99042. +
  99043. +unlock:
  99044. + vchi_service_release(instance->vchi_handle[0]);
  99045. + mutex_unlock(&instance->vchi_mutex);
  99046. +exit:
  99047. + LOG_DBG(" .. OUT\n");
  99048. + return ret;
  99049. +}
  99050. +
  99051. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  99052. + bcm2835_chip_t * chip)
  99053. +{
  99054. + VC_AUDIO_MSG_T m;
  99055. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  99056. + int32_t success;
  99057. + int ret;
  99058. + LOG_DBG(" .. IN\n");
  99059. +
  99060. + LOG_INFO
  99061. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  99062. +
  99063. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99064. + {
  99065. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99066. + return -EINTR;
  99067. + }
  99068. + vchi_service_use(instance->vchi_handle[0]);
  99069. +
  99070. + instance->result = -1;
  99071. +
  99072. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  99073. + m.u.control.dest = chip->dest;
  99074. + m.u.control.volume = chip->volume;
  99075. +
  99076. + /* Create the message available completion */
  99077. + init_completion(&instance->msg_avail_comp);
  99078. +
  99079. + /* Send the message to the videocore */
  99080. + success = vchi_msg_queue(instance->vchi_handle[0],
  99081. + &m, sizeof m,
  99082. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99083. +
  99084. + if (success != 0) {
  99085. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  99086. + __func__, success);
  99087. +
  99088. + ret = -1;
  99089. + goto unlock;
  99090. + }
  99091. +
  99092. + /* We are expecting a reply from the videocore */
  99093. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  99094. + if (ret) {
  99095. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  99096. + __func__, success);
  99097. + goto unlock;
  99098. + }
  99099. +
  99100. + if (instance->result != 0) {
  99101. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  99102. +
  99103. + ret = -1;
  99104. + goto unlock;
  99105. + }
  99106. +
  99107. + ret = 0;
  99108. +
  99109. +unlock:
  99110. + vchi_service_release(instance->vchi_handle[0]);
  99111. + mutex_unlock(&instance->vchi_mutex);
  99112. +
  99113. + LOG_DBG(" .. OUT\n");
  99114. + return ret;
  99115. +}
  99116. +
  99117. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  99118. +{
  99119. + int i;
  99120. + int ret = 0;
  99121. + LOG_DBG(" .. IN\n");
  99122. +
  99123. + /* change ctls for all substreams */
  99124. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  99125. + if (chip->avail_substreams & (1 << i)) {
  99126. + if (!chip->alsa_stream[i])
  99127. + {
  99128. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  99129. + ret = 0;
  99130. + }
  99131. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  99132. + (chip->alsa_stream[i], chip) != 0)
  99133. + {
  99134. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  99135. + ret = -1;
  99136. + }
  99137. + else LOG_DBG(" Controls set for stream %d\n", i);
  99138. + }
  99139. + }
  99140. + LOG_DBG(" .. OUT ret=%d\n", ret);
  99141. + return ret;
  99142. +}
  99143. +
  99144. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  99145. + uint32_t channels, uint32_t samplerate,
  99146. + uint32_t bps)
  99147. +{
  99148. + VC_AUDIO_MSG_T m;
  99149. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  99150. + int32_t success;
  99151. + int ret;
  99152. + LOG_DBG(" .. IN\n");
  99153. +
  99154. + LOG_INFO
  99155. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  99156. + channels, samplerate, bps);
  99157. +
  99158. + /* resend ctls - alsa_stream may not have been open when first send */
  99159. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  99160. + if (ret != 0) {
  99161. + LOG_ERR(" Alsa controls not supported\n");
  99162. + return -EINVAL;
  99163. + }
  99164. +
  99165. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99166. + {
  99167. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99168. + return -EINTR;
  99169. + }
  99170. + vchi_service_use(instance->vchi_handle[0]);
  99171. +
  99172. + instance->result = -1;
  99173. +
  99174. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  99175. + m.u.config.channels = channels;
  99176. + m.u.config.samplerate = samplerate;
  99177. + m.u.config.bps = bps;
  99178. +
  99179. + /* Create the message available completion */
  99180. + init_completion(&instance->msg_avail_comp);
  99181. +
  99182. + /* Send the message to the videocore */
  99183. + success = vchi_msg_queue(instance->vchi_handle[0],
  99184. + &m, sizeof m,
  99185. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99186. +
  99187. + if (success != 0) {
  99188. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  99189. + __func__, success);
  99190. +
  99191. + ret = -1;
  99192. + goto unlock;
  99193. + }
  99194. +
  99195. + /* We are expecting a reply from the videocore */
  99196. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  99197. + if (ret) {
  99198. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  99199. + __func__, success);
  99200. + goto unlock;
  99201. + }
  99202. +
  99203. + if (instance->result != 0) {
  99204. + LOG_ERR("%s: result=%d", __func__, instance->result);
  99205. +
  99206. + ret = -1;
  99207. + goto unlock;
  99208. + }
  99209. +
  99210. + ret = 0;
  99211. +
  99212. +unlock:
  99213. + vchi_service_release(instance->vchi_handle[0]);
  99214. + mutex_unlock(&instance->vchi_mutex);
  99215. +
  99216. + LOG_DBG(" .. OUT\n");
  99217. + return ret;
  99218. +}
  99219. +
  99220. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  99221. +{
  99222. + LOG_DBG(" .. IN\n");
  99223. +
  99224. + LOG_DBG(" .. OUT\n");
  99225. +
  99226. + return 0;
  99227. +}
  99228. +
  99229. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  99230. +{
  99231. + VC_AUDIO_MSG_T m;
  99232. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  99233. + int32_t success;
  99234. + int ret;
  99235. + LOG_DBG(" .. IN\n");
  99236. +
  99237. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99238. + {
  99239. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99240. + return -EINTR;
  99241. + }
  99242. + vchi_service_use(instance->vchi_handle[0]);
  99243. +
  99244. + m.type = VC_AUDIO_MSG_TYPE_START;
  99245. +
  99246. + /* Send the message to the videocore */
  99247. + success = vchi_msg_queue(instance->vchi_handle[0],
  99248. + &m, sizeof m,
  99249. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99250. +
  99251. + if (success != 0) {
  99252. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  99253. + __func__, success);
  99254. +
  99255. + ret = -1;
  99256. + goto unlock;
  99257. + }
  99258. +
  99259. + ret = 0;
  99260. +
  99261. +unlock:
  99262. + vchi_service_release(instance->vchi_handle[0]);
  99263. + mutex_unlock(&instance->vchi_mutex);
  99264. + LOG_DBG(" .. OUT\n");
  99265. + return ret;
  99266. +}
  99267. +
  99268. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  99269. +{
  99270. + VC_AUDIO_MSG_T m;
  99271. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  99272. + int32_t success;
  99273. + int ret;
  99274. + LOG_DBG(" .. IN\n");
  99275. +
  99276. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99277. + {
  99278. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99279. + return -EINTR;
  99280. + }
  99281. + vchi_service_use(instance->vchi_handle[0]);
  99282. +
  99283. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  99284. + m.u.stop.draining = alsa_stream->draining;
  99285. +
  99286. + /* Send the message to the videocore */
  99287. + success = vchi_msg_queue(instance->vchi_handle[0],
  99288. + &m, sizeof m,
  99289. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99290. +
  99291. + if (success != 0) {
  99292. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  99293. + __func__, success);
  99294. +
  99295. + ret = -1;
  99296. + goto unlock;
  99297. + }
  99298. +
  99299. + ret = 0;
  99300. +
  99301. +unlock:
  99302. + vchi_service_release(instance->vchi_handle[0]);
  99303. + mutex_unlock(&instance->vchi_mutex);
  99304. + LOG_DBG(" .. OUT\n");
  99305. + return ret;
  99306. +}
  99307. +
  99308. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  99309. +{
  99310. + VC_AUDIO_MSG_T m;
  99311. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  99312. + int32_t success;
  99313. + int ret;
  99314. + LOG_DBG(" .. IN\n");
  99315. +
  99316. + my_workqueue_quit(alsa_stream);
  99317. +
  99318. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99319. + {
  99320. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99321. + return -EINTR;
  99322. + }
  99323. + vchi_service_use(instance->vchi_handle[0]);
  99324. +
  99325. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  99326. +
  99327. + /* Create the message available completion */
  99328. + init_completion(&instance->msg_avail_comp);
  99329. +
  99330. + /* Send the message to the videocore */
  99331. + success = vchi_msg_queue(instance->vchi_handle[0],
  99332. + &m, sizeof m,
  99333. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99334. +
  99335. + if (success != 0) {
  99336. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  99337. + __func__, success);
  99338. + ret = -1;
  99339. + goto unlock;
  99340. + }
  99341. +
  99342. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  99343. + if (ret) {
  99344. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  99345. + __func__, success);
  99346. + goto unlock;
  99347. + }
  99348. + if (instance->result != 0) {
  99349. + LOG_ERR("%s: failed result (status=%d)",
  99350. + __func__, instance->result);
  99351. +
  99352. + ret = -1;
  99353. + goto unlock;
  99354. + }
  99355. +
  99356. + ret = 0;
  99357. +
  99358. +unlock:
  99359. + vchi_service_release(instance->vchi_handle[0]);
  99360. + mutex_unlock(&instance->vchi_mutex);
  99361. +
  99362. + /* Stop the audio service */
  99363. + if (instance) {
  99364. + vc_vchi_audio_deinit(instance);
  99365. + alsa_stream->instance = NULL;
  99366. + }
  99367. + LOG_DBG(" .. OUT\n");
  99368. + return ret;
  99369. +}
  99370. +
  99371. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  99372. + uint32_t count, void *src)
  99373. +{
  99374. + VC_AUDIO_MSG_T m;
  99375. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  99376. + int32_t success;
  99377. + int ret;
  99378. +
  99379. + LOG_DBG(" .. IN\n");
  99380. +
  99381. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  99382. +
  99383. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  99384. + {
  99385. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  99386. + return -EINTR;
  99387. + }
  99388. + vchi_service_use(instance->vchi_handle[0]);
  99389. +
  99390. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  99391. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  99392. + }
  99393. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  99394. + m.u.write.count = count;
  99395. + // old version uses bulk, new version uses control
  99396. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  99397. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  99398. + m.u.write.cookie = alsa_stream;
  99399. + m.u.write.silence = src == NULL;
  99400. +
  99401. + /* Send the message to the videocore */
  99402. + success = vchi_msg_queue(instance->vchi_handle[0],
  99403. + &m, sizeof m,
  99404. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99405. +
  99406. + if (success != 0) {
  99407. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  99408. + __func__, success);
  99409. +
  99410. + ret = -1;
  99411. + goto unlock;
  99412. + }
  99413. + if (!m.u.write.silence) {
  99414. + if (m.u.write.max_packet == 0) {
  99415. + /* Send the message to the videocore */
  99416. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  99417. + src, count,
  99418. + 0 *
  99419. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  99420. + +
  99421. + 1 *
  99422. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  99423. + NULL);
  99424. + } else {
  99425. + while (count > 0) {
  99426. + int bytes = min((int)m.u.write.max_packet, (int)count);
  99427. + success = vchi_msg_queue(instance->vchi_handle[0],
  99428. + src, bytes,
  99429. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  99430. + src = (char *)src + bytes;
  99431. + count -= bytes;
  99432. + }
  99433. + }
  99434. + if (success != 0) {
  99435. + LOG_ERR
  99436. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  99437. + __func__, success);
  99438. +
  99439. + ret = -1;
  99440. + goto unlock;
  99441. + }
  99442. + }
  99443. + ret = 0;
  99444. +
  99445. +unlock:
  99446. + vchi_service_release(instance->vchi_handle[0]);
  99447. + mutex_unlock(&instance->vchi_mutex);
  99448. + LOG_DBG(" .. OUT\n");
  99449. + return ret;
  99450. +}
  99451. +
  99452. +/**
  99453. + * Returns all buffers from arm->vc
  99454. + */
  99455. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  99456. +{
  99457. + LOG_DBG(" .. IN\n");
  99458. + LOG_DBG(" .. OUT\n");
  99459. + return;
  99460. +}
  99461. +
  99462. +/**
  99463. + * Forces VC to flush(drop) its filled playback buffers and
  99464. + * return them the us. (VC->ARM)
  99465. + */
  99466. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  99467. +{
  99468. + LOG_DBG(" .. IN\n");
  99469. + LOG_DBG(" .. OUT\n");
  99470. +}
  99471. +
  99472. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  99473. +{
  99474. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  99475. + atomic_sub(count, &alsa_stream->retrieved);
  99476. + return count;
  99477. +}
  99478. +
  99479. +module_param(force_bulk, bool, 0444);
  99480. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  99481. diff -Nur linux-3.10.33/sound/arm/Kconfig linux-raspberry-pi/sound/arm/Kconfig
  99482. --- linux-3.10.33/sound/arm/Kconfig 2014-03-07 06:58:45.000000000 +0100
  99483. +++ linux-raspberry-pi/sound/arm/Kconfig 2014-03-13 12:46:44.052107092 +0100
  99484. @@ -39,5 +39,12 @@
  99485. Say Y or M if you want to support any AC97 codec attached to
  99486. the PXA2xx AC97 interface.
  99487. +config SND_BCM2835
  99488. + tristate "BCM2835 ALSA driver"
  99489. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  99490. + select SND_PCM
  99491. + help
  99492. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  99493. +
  99494. endif # SND_ARM
  99495. diff -Nur linux-3.10.33/sound/arm/Makefile linux-raspberry-pi/sound/arm/Makefile
  99496. --- linux-3.10.33/sound/arm/Makefile 2014-03-07 06:58:45.000000000 +0100
  99497. +++ linux-raspberry-pi/sound/arm/Makefile 2014-03-13 12:46:44.052107092 +0100
  99498. @@ -14,3 +14,9 @@
  99499. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  99500. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  99501. +
  99502. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  99503. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  99504. +
  99505. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  99506. +
  99507. diff -Nur linux-3.10.33/sound/arm/vc_vchi_audioserv_defs.h linux-raspberry-pi/sound/arm/vc_vchi_audioserv_defs.h
  99508. --- linux-3.10.33/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  99509. +++ linux-raspberry-pi/sound/arm/vc_vchi_audioserv_defs.h 2014-03-13 12:46:44.060107108 +0100
  99510. @@ -0,0 +1,116 @@
  99511. +/*****************************************************************************
  99512. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99513. +*
  99514. +* Unless you and Broadcom execute a separate written software license
  99515. +* agreement governing use of this software, this software is licensed to you
  99516. +* under the terms of the GNU General Public License version 2, available at
  99517. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99518. +*
  99519. +* Notwithstanding the above, under no circumstances may you combine this
  99520. +* software in any way with any other Broadcom software provided under a
  99521. +* license other than the GPL, without Broadcom's express prior written
  99522. +* consent.
  99523. +*****************************************************************************/
  99524. +
  99525. +#ifndef _VC_AUDIO_DEFS_H_
  99526. +#define _VC_AUDIO_DEFS_H_
  99527. +
  99528. +#define VC_AUDIOSERV_MIN_VER 1
  99529. +#define VC_AUDIOSERV_VER 2
  99530. +
  99531. +// FourCC code used for VCHI connection
  99532. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  99533. +
  99534. +// Maximum message length
  99535. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  99536. +
  99537. +// List of screens that are currently supported
  99538. +// All message types supported for HOST->VC direction
  99539. +typedef enum {
  99540. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  99541. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  99542. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  99543. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  99544. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  99545. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  99546. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  99547. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  99548. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  99549. + VC_AUDIO_MSG_TYPE_MAX
  99550. +} VC_AUDIO_MSG_TYPE;
  99551. +
  99552. +// configure the audio
  99553. +typedef struct {
  99554. + uint32_t channels;
  99555. + uint32_t samplerate;
  99556. + uint32_t bps;
  99557. +
  99558. +} VC_AUDIO_CONFIG_T;
  99559. +
  99560. +typedef struct {
  99561. + uint32_t volume;
  99562. + uint32_t dest;
  99563. +
  99564. +} VC_AUDIO_CONTROL_T;
  99565. +
  99566. +// audio
  99567. +typedef struct {
  99568. + uint32_t dummy;
  99569. +
  99570. +} VC_AUDIO_OPEN_T;
  99571. +
  99572. +// audio
  99573. +typedef struct {
  99574. + uint32_t dummy;
  99575. +
  99576. +} VC_AUDIO_CLOSE_T;
  99577. +// audio
  99578. +typedef struct {
  99579. + uint32_t dummy;
  99580. +
  99581. +} VC_AUDIO_START_T;
  99582. +// audio
  99583. +typedef struct {
  99584. + uint32_t draining;
  99585. +
  99586. +} VC_AUDIO_STOP_T;
  99587. +
  99588. +// configure the write audio samples
  99589. +typedef struct {
  99590. + uint32_t count; // in bytes
  99591. + void *callback;
  99592. + void *cookie;
  99593. + uint16_t silence;
  99594. + uint16_t max_packet;
  99595. +} VC_AUDIO_WRITE_T;
  99596. +
  99597. +// Generic result for a request (VC->HOST)
  99598. +typedef struct {
  99599. + int32_t success; // Success value
  99600. +
  99601. +} VC_AUDIO_RESULT_T;
  99602. +
  99603. +// Generic result for a request (VC->HOST)
  99604. +typedef struct {
  99605. + int32_t count; // Success value
  99606. + void *callback;
  99607. + void *cookie;
  99608. +} VC_AUDIO_COMPLETE_T;
  99609. +
  99610. +// Message header for all messages in HOST->VC direction
  99611. +typedef struct {
  99612. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  99613. + union {
  99614. + VC_AUDIO_CONFIG_T config;
  99615. + VC_AUDIO_CONTROL_T control;
  99616. + VC_AUDIO_OPEN_T open;
  99617. + VC_AUDIO_CLOSE_T close;
  99618. + VC_AUDIO_START_T start;
  99619. + VC_AUDIO_STOP_T stop;
  99620. + VC_AUDIO_WRITE_T write;
  99621. + VC_AUDIO_RESULT_T result;
  99622. + VC_AUDIO_COMPLETE_T complete;
  99623. + } u;
  99624. +} VC_AUDIO_MSG_T;
  99625. +
  99626. +#endif // _VC_AUDIO_DEFS_H_
  99627. diff -Nur linux-3.10.33/sound/soc/bcm/bcm2708-i2s.c linux-raspberry-pi/sound/soc/bcm/bcm2708-i2s.c
  99628. --- linux-3.10.33/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  99629. +++ linux-raspberry-pi/sound/soc/bcm/bcm2708-i2s.c 2014-03-13 12:46:44.480107952 +0100
  99630. @@ -0,0 +1,945 @@
  99631. +/*
  99632. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  99633. + *
  99634. + * Author: Florian Meier <florian.meier@koalo.de>
  99635. + * Copyright 2013
  99636. + *
  99637. + * Based on
  99638. + * Raspberry Pi PCM I2S ALSA Driver
  99639. + * Copyright (c) by Phil Poole 2013
  99640. + *
  99641. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  99642. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  99643. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  99644. + *
  99645. + * OMAP ALSA SoC DAI driver using McBSP port
  99646. + * Copyright (C) 2008 Nokia Corporation
  99647. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  99648. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  99649. + *
  99650. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  99651. + * Author: Timur Tabi <timur@freescale.com>
  99652. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  99653. + *
  99654. + * This program is free software; you can redistribute it and/or
  99655. + * modify it under the terms of the GNU General Public License
  99656. + * version 2 as published by the Free Software Foundation.
  99657. + *
  99658. + * This program is distributed in the hope that it will be useful, but
  99659. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  99660. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  99661. + * General Public License for more details.
  99662. + */
  99663. +
  99664. +#include <linux/init.h>
  99665. +#include <linux/module.h>
  99666. +#include <linux/device.h>
  99667. +#include <linux/slab.h>
  99668. +#include <linux/delay.h>
  99669. +#include <linux/io.h>
  99670. +#include <linux/clk.h>
  99671. +
  99672. +#include <sound/core.h>
  99673. +#include <sound/pcm.h>
  99674. +#include <sound/pcm_params.h>
  99675. +#include <sound/initval.h>
  99676. +#include <sound/soc.h>
  99677. +#include <sound/dmaengine_pcm.h>
  99678. +
  99679. +/* Clock registers */
  99680. +#define BCM2708_CLK_PCMCTL_REG 0x00
  99681. +#define BCM2708_CLK_PCMDIV_REG 0x04
  99682. +
  99683. +/* Clock register settings */
  99684. +#define BCM2708_CLK_PASSWD (0x5a000000)
  99685. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  99686. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  99687. +#define BCM2708_CLK_FLIP BIT(8)
  99688. +#define BCM2708_CLK_BUSY BIT(7)
  99689. +#define BCM2708_CLK_KILL BIT(5)
  99690. +#define BCM2708_CLK_ENAB BIT(4)
  99691. +#define BCM2708_CLK_SRC(v) (v)
  99692. +
  99693. +#define BCM2708_CLK_SHIFT (12)
  99694. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  99695. +#define BCM2708_CLK_DIVF(v) (v)
  99696. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  99697. +
  99698. +enum {
  99699. + BCM2708_CLK_MASH_0 = 0,
  99700. + BCM2708_CLK_MASH_1,
  99701. + BCM2708_CLK_MASH_2,
  99702. + BCM2708_CLK_MASH_3,
  99703. +};
  99704. +
  99705. +enum {
  99706. + BCM2708_CLK_SRC_GND = 0,
  99707. + BCM2708_CLK_SRC_OSC,
  99708. + BCM2708_CLK_SRC_DBG0,
  99709. + BCM2708_CLK_SRC_DBG1,
  99710. + BCM2708_CLK_SRC_PLLA,
  99711. + BCM2708_CLK_SRC_PLLC,
  99712. + BCM2708_CLK_SRC_PLLD,
  99713. + BCM2708_CLK_SRC_HDMI,
  99714. +};
  99715. +
  99716. +/* Most clocks are not useable (freq = 0) */
  99717. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  99718. + [BCM2708_CLK_SRC_GND] = 0,
  99719. + [BCM2708_CLK_SRC_OSC] = 19200000,
  99720. + [BCM2708_CLK_SRC_DBG0] = 0,
  99721. + [BCM2708_CLK_SRC_DBG1] = 0,
  99722. + [BCM2708_CLK_SRC_PLLA] = 0,
  99723. + [BCM2708_CLK_SRC_PLLC] = 0,
  99724. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  99725. + [BCM2708_CLK_SRC_HDMI] = 0,
  99726. +};
  99727. +
  99728. +/* I2S registers */
  99729. +#define BCM2708_I2S_CS_A_REG 0x00
  99730. +#define BCM2708_I2S_FIFO_A_REG 0x04
  99731. +#define BCM2708_I2S_MODE_A_REG 0x08
  99732. +#define BCM2708_I2S_RXC_A_REG 0x0c
  99733. +#define BCM2708_I2S_TXC_A_REG 0x10
  99734. +#define BCM2708_I2S_DREQ_A_REG 0x14
  99735. +#define BCM2708_I2S_INTEN_A_REG 0x18
  99736. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  99737. +#define BCM2708_I2S_GRAY_REG 0x20
  99738. +
  99739. +/* I2S register settings */
  99740. +#define BCM2708_I2S_STBY BIT(25)
  99741. +#define BCM2708_I2S_SYNC BIT(24)
  99742. +#define BCM2708_I2S_RXSEX BIT(23)
  99743. +#define BCM2708_I2S_RXF BIT(22)
  99744. +#define BCM2708_I2S_TXE BIT(21)
  99745. +#define BCM2708_I2S_RXD BIT(20)
  99746. +#define BCM2708_I2S_TXD BIT(19)
  99747. +#define BCM2708_I2S_RXR BIT(18)
  99748. +#define BCM2708_I2S_TXW BIT(17)
  99749. +#define BCM2708_I2S_CS_RXERR BIT(16)
  99750. +#define BCM2708_I2S_CS_TXERR BIT(15)
  99751. +#define BCM2708_I2S_RXSYNC BIT(14)
  99752. +#define BCM2708_I2S_TXSYNC BIT(13)
  99753. +#define BCM2708_I2S_DMAEN BIT(9)
  99754. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  99755. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  99756. +#define BCM2708_I2S_RXCLR BIT(4)
  99757. +#define BCM2708_I2S_TXCLR BIT(3)
  99758. +#define BCM2708_I2S_TXON BIT(2)
  99759. +#define BCM2708_I2S_RXON BIT(1)
  99760. +#define BCM2708_I2S_EN (1)
  99761. +
  99762. +#define BCM2708_I2S_CLKDIS BIT(28)
  99763. +#define BCM2708_I2S_PDMN BIT(27)
  99764. +#define BCM2708_I2S_PDME BIT(26)
  99765. +#define BCM2708_I2S_FRXP BIT(25)
  99766. +#define BCM2708_I2S_FTXP BIT(24)
  99767. +#define BCM2708_I2S_CLKM BIT(23)
  99768. +#define BCM2708_I2S_CLKI BIT(22)
  99769. +#define BCM2708_I2S_FSM BIT(21)
  99770. +#define BCM2708_I2S_FSI BIT(20)
  99771. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  99772. +#define BCM2708_I2S_FSLEN(v) (v)
  99773. +
  99774. +#define BCM2708_I2S_CHWEX BIT(15)
  99775. +#define BCM2708_I2S_CHEN BIT(14)
  99776. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  99777. +#define BCM2708_I2S_CHWID(v) (v)
  99778. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  99779. +#define BCM2708_I2S_CH2(v) (v)
  99780. +
  99781. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  99782. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  99783. +#define BCM2708_I2S_TX(v) ((v) << 8)
  99784. +#define BCM2708_I2S_RX(v) (v)
  99785. +
  99786. +#define BCM2708_I2S_INT_RXERR BIT(3)
  99787. +#define BCM2708_I2S_INT_TXERR BIT(2)
  99788. +#define BCM2708_I2S_INT_RXR BIT(1)
  99789. +#define BCM2708_I2S_INT_TXW BIT(0)
  99790. +
  99791. +/* I2S DMA interface */
  99792. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  99793. +#define BCM2708_DMA_DREQ_PCM_TX 2
  99794. +#define BCM2708_DMA_DREQ_PCM_RX 3
  99795. +
  99796. +/* General device struct */
  99797. +struct bcm2708_i2s_dev {
  99798. + struct device *dev;
  99799. + struct snd_dmaengine_dai_dma_data dma_data[2];
  99800. + unsigned int fmt;
  99801. + unsigned int bclk_ratio;
  99802. +
  99803. + struct regmap *i2s_regmap;
  99804. + struct regmap *clk_regmap;
  99805. +};
  99806. +
  99807. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  99808. +{
  99809. + /* Start the clock if in master mode */
  99810. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  99811. +
  99812. + switch (master) {
  99813. + case SND_SOC_DAIFMT_CBS_CFS:
  99814. + case SND_SOC_DAIFMT_CBS_CFM:
  99815. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99816. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  99817. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  99818. + break;
  99819. + default:
  99820. + break;
  99821. + }
  99822. +}
  99823. +
  99824. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  99825. +{
  99826. + uint32_t clkreg;
  99827. + int timeout = 1000;
  99828. +
  99829. + /* Stop clock */
  99830. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99831. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  99832. + BCM2708_CLK_PASSWD);
  99833. +
  99834. + /* Wait for the BUSY flag going down */
  99835. + while (--timeout) {
  99836. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  99837. + if (!(clkreg & BCM2708_CLK_BUSY))
  99838. + break;
  99839. + }
  99840. +
  99841. + if (!timeout) {
  99842. + /* KILL the clock */
  99843. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  99844. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99845. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  99846. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  99847. + }
  99848. +}
  99849. +
  99850. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  99851. + bool tx, bool rx)
  99852. +{
  99853. + int timeout = 1000;
  99854. + uint32_t syncval;
  99855. + uint32_t csreg;
  99856. + uint32_t i2s_active_state;
  99857. + uint32_t clkreg;
  99858. + uint32_t clk_active_state;
  99859. + uint32_t off;
  99860. + uint32_t clr;
  99861. +
  99862. + off = tx ? BCM2708_I2S_TXON : 0;
  99863. + off |= rx ? BCM2708_I2S_RXON : 0;
  99864. +
  99865. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  99866. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  99867. +
  99868. + /* Backup the current state */
  99869. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  99870. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  99871. +
  99872. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  99873. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  99874. +
  99875. + /* Start clock if not running */
  99876. + if (!clk_active_state) {
  99877. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99878. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  99879. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  99880. + }
  99881. +
  99882. + /* Stop I2S module */
  99883. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  99884. +
  99885. + /*
  99886. + * Clear the FIFOs
  99887. + * Requires at least 2 PCM clock cycles to take effect
  99888. + */
  99889. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  99890. +
  99891. + /* Wait for 2 PCM clock cycles */
  99892. +
  99893. + /*
  99894. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  99895. + * FIXME: This does not seem to work for slave mode!
  99896. + */
  99897. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  99898. + syncval &= BCM2708_I2S_SYNC;
  99899. +
  99900. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99901. + BCM2708_I2S_SYNC, ~syncval);
  99902. +
  99903. + /* Wait for the SYNC flag changing it's state */
  99904. + while (--timeout) {
  99905. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  99906. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  99907. + break;
  99908. + }
  99909. +
  99910. + if (!timeout)
  99911. + dev_err(dev->dev, "I2S SYNC error!\n");
  99912. +
  99913. + /* Stop clock if it was not running before */
  99914. + if (!clk_active_state)
  99915. + bcm2708_i2s_stop_clock(dev);
  99916. +
  99917. + /* Restore I2S state */
  99918. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99919. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  99920. +}
  99921. +
  99922. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  99923. + unsigned int fmt)
  99924. +{
  99925. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99926. + dev->fmt = fmt;
  99927. + return 0;
  99928. +}
  99929. +
  99930. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  99931. + unsigned int ratio)
  99932. +{
  99933. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99934. + dev->bclk_ratio = ratio;
  99935. + return 0;
  99936. +}
  99937. +
  99938. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  99939. + struct snd_pcm_hw_params *params,
  99940. + struct snd_soc_dai *dai)
  99941. +{
  99942. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99943. +
  99944. + unsigned int sampling_rate = params_rate(params);
  99945. + unsigned int data_length, data_delay, bclk_ratio;
  99946. + unsigned int ch1pos, ch2pos, mode, format;
  99947. + unsigned int mash = BCM2708_CLK_MASH_1;
  99948. + unsigned int divi, divf, target_frequency;
  99949. + int clk_src = -1;
  99950. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  99951. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  99952. + || master == SND_SOC_DAIFMT_CBS_CFM);
  99953. +
  99954. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  99955. + || master == SND_SOC_DAIFMT_CBM_CFS);
  99956. + uint32_t csreg;
  99957. +
  99958. + /*
  99959. + * If a stream is already enabled,
  99960. + * the registers are already set properly.
  99961. + */
  99962. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  99963. +
  99964. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  99965. + return 0;
  99966. +
  99967. + /*
  99968. + * Adjust the data length according to the format.
  99969. + * We prefill the half frame length with an integer
  99970. + * divider of 2400 as explained at the clock settings.
  99971. + * Maybe it is overwritten there, if the Integer mode
  99972. + * does not apply.
  99973. + */
  99974. + switch (params_format(params)) {
  99975. + case SNDRV_PCM_FORMAT_S16_LE:
  99976. + data_length = 16;
  99977. + bclk_ratio = 40;
  99978. + break;
  99979. + case SNDRV_PCM_FORMAT_S24_LE:
  99980. + data_length = 24;
  99981. + bclk_ratio = 40;
  99982. + break;
  99983. + case SNDRV_PCM_FORMAT_S32_LE:
  99984. + data_length = 32;
  99985. + bclk_ratio = 80;
  99986. + break;
  99987. + default:
  99988. + return -EINVAL;
  99989. + }
  99990. +
  99991. + /* If bclk_ratio already set, use that one. */
  99992. + if (dev->bclk_ratio)
  99993. + bclk_ratio = dev->bclk_ratio;
  99994. +
  99995. + /*
  99996. + * Clock Settings
  99997. + *
  99998. + * The target frequency of the bit clock is
  99999. + * sampling rate * frame length
  100000. + *
  100001. + * Integer mode:
  100002. + * Sampling rates that are multiples of 8000 kHz
  100003. + * can be driven by the oscillator of 19.2 MHz
  100004. + * with an integer divider as long as the frame length
  100005. + * is an integer divider of 19200000/8000=2400 as set up above.
  100006. + * This is no longer possible if the sampling rate
  100007. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  100008. + *
  100009. + * MASH mode:
  100010. + * For all other sampling rates, it is not possible to
  100011. + * have an integer divider. Approximate the clock
  100012. + * with the MASH module that induces a slight frequency
  100013. + * variance. To minimize that it is best to have the fastest
  100014. + * clock here. That is PLLD with 500 MHz.
  100015. + */
  100016. + target_frequency = sampling_rate * bclk_ratio;
  100017. + clk_src = BCM2708_CLK_SRC_OSC;
  100018. + mash = BCM2708_CLK_MASH_0;
  100019. +
  100020. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  100021. + && bit_master && frame_master) {
  100022. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  100023. + divf = 0;
  100024. + } else {
  100025. + uint64_t dividend;
  100026. +
  100027. + if (!dev->bclk_ratio) {
  100028. + /*
  100029. + * Overwrite bclk_ratio, because the
  100030. + * above trick is not needed or can
  100031. + * not be used.
  100032. + */
  100033. + bclk_ratio = 2 * data_length;
  100034. + }
  100035. +
  100036. + target_frequency = sampling_rate * bclk_ratio;
  100037. +
  100038. + clk_src = BCM2708_CLK_SRC_PLLD;
  100039. + mash = BCM2708_CLK_MASH_1;
  100040. +
  100041. + dividend = bcm2708_clk_freq[clk_src];
  100042. + dividend <<= BCM2708_CLK_SHIFT;
  100043. + do_div(dividend, target_frequency);
  100044. + divi = dividend >> BCM2708_CLK_SHIFT;
  100045. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  100046. + }
  100047. +
  100048. + /* Set clock divider */
  100049. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  100050. + | BCM2708_CLK_DIVI(divi)
  100051. + | BCM2708_CLK_DIVF(divf));
  100052. +
  100053. + /* Setup clock, but don't start it yet */
  100054. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  100055. + | BCM2708_CLK_MASH(mash)
  100056. + | BCM2708_CLK_SRC(clk_src));
  100057. +
  100058. + /* Setup the frame format */
  100059. + format = BCM2708_I2S_CHEN;
  100060. +
  100061. + if (data_length >= 24)
  100062. + format |= BCM2708_I2S_CHWEX;
  100063. +
  100064. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  100065. +
  100066. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  100067. + case SND_SOC_DAIFMT_I2S:
  100068. + data_delay = 1;
  100069. + break;
  100070. + default:
  100071. + /*
  100072. + * TODO
  100073. + * Others are possible but are not implemented at the moment.
  100074. + */
  100075. + dev_err(dev->dev, "%s:bad format\n", __func__);
  100076. + return -EINVAL;
  100077. + }
  100078. +
  100079. + ch1pos = data_delay;
  100080. + ch2pos = bclk_ratio / 2 + data_delay;
  100081. +
  100082. + switch (params_channels(params)) {
  100083. + case 2:
  100084. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  100085. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  100086. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  100087. + break;
  100088. + default:
  100089. + return -EINVAL;
  100090. + }
  100091. +
  100092. + /*
  100093. + * Set format for both streams.
  100094. + * We cannot set another frame length
  100095. + * (and therefore word length) anyway,
  100096. + * so the format will be the same.
  100097. + */
  100098. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  100099. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  100100. +
  100101. + /* Setup the I2S mode */
  100102. + mode = 0;
  100103. +
  100104. + if (data_length <= 16) {
  100105. + /*
  100106. + * Use frame packed mode (2 channels per 32 bit word)
  100107. + * We cannot set another frame length in the second stream
  100108. + * (and therefore word length) anyway,
  100109. + * so the format will be the same.
  100110. + */
  100111. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  100112. + }
  100113. +
  100114. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  100115. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  100116. +
  100117. + /* Master or slave? */
  100118. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  100119. + case SND_SOC_DAIFMT_CBS_CFS:
  100120. + /* CPU is master */
  100121. + break;
  100122. + case SND_SOC_DAIFMT_CBM_CFS:
  100123. + /*
  100124. + * CODEC is bit clock master
  100125. + * CPU is frame master
  100126. + */
  100127. + mode |= BCM2708_I2S_CLKM;
  100128. + break;
  100129. + case SND_SOC_DAIFMT_CBS_CFM:
  100130. + /*
  100131. + * CODEC is frame master
  100132. + * CPU is bit clock master
  100133. + */
  100134. + mode |= BCM2708_I2S_FSM;
  100135. + break;
  100136. + case SND_SOC_DAIFMT_CBM_CFM:
  100137. + /* CODEC is master */
  100138. + mode |= BCM2708_I2S_CLKM;
  100139. + mode |= BCM2708_I2S_FSM;
  100140. + break;
  100141. + default:
  100142. + dev_err(dev->dev, "%s:bad master\n", __func__);
  100143. + return -EINVAL;
  100144. + }
  100145. +
  100146. + /*
  100147. + * Invert clocks?
  100148. + *
  100149. + * The BCM approach seems to be inverted to the classical I2S approach.
  100150. + */
  100151. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  100152. + case SND_SOC_DAIFMT_NB_NF:
  100153. + /* None. Therefore, both for BCM */
  100154. + mode |= BCM2708_I2S_CLKI;
  100155. + mode |= BCM2708_I2S_FSI;
  100156. + break;
  100157. + case SND_SOC_DAIFMT_IB_IF:
  100158. + /* Both. Therefore, none for BCM */
  100159. + break;
  100160. + case SND_SOC_DAIFMT_NB_IF:
  100161. + /*
  100162. + * Invert only frame sync. Therefore,
  100163. + * invert only bit clock for BCM
  100164. + */
  100165. + mode |= BCM2708_I2S_CLKI;
  100166. + break;
  100167. + case SND_SOC_DAIFMT_IB_NF:
  100168. + /*
  100169. + * Invert only bit clock. Therefore,
  100170. + * invert only frame sync for BCM
  100171. + */
  100172. + mode |= BCM2708_I2S_FSI;
  100173. + break;
  100174. + default:
  100175. + return -EINVAL;
  100176. + }
  100177. +
  100178. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  100179. +
  100180. + /* Setup the DMA parameters */
  100181. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  100182. + BCM2708_I2S_RXTHR(1)
  100183. + | BCM2708_I2S_TXTHR(1)
  100184. + | BCM2708_I2S_DMAEN, 0xffffffff);
  100185. +
  100186. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  100187. + BCM2708_I2S_TX_PANIC(0x10)
  100188. + | BCM2708_I2S_RX_PANIC(0x30)
  100189. + | BCM2708_I2S_TX(0x30)
  100190. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  100191. +
  100192. + /* Clear FIFOs */
  100193. + bcm2708_i2s_clear_fifos(dev, true, true);
  100194. +
  100195. + return 0;
  100196. +}
  100197. +
  100198. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  100199. + struct snd_soc_dai *dai)
  100200. +{
  100201. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  100202. + uint32_t cs_reg;
  100203. +
  100204. + bcm2708_i2s_start_clock(dev);
  100205. +
  100206. + /*
  100207. + * Clear both FIFOs if the one that should be started
  100208. + * is not empty at the moment. This should only happen
  100209. + * after overrun. Otherwise, hw_params would have cleared
  100210. + * the FIFO.
  100211. + */
  100212. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  100213. +
  100214. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  100215. + && !(cs_reg & BCM2708_I2S_TXE))
  100216. + bcm2708_i2s_clear_fifos(dev, true, false);
  100217. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  100218. + && (cs_reg & BCM2708_I2S_RXD))
  100219. + bcm2708_i2s_clear_fifos(dev, false, true);
  100220. +
  100221. + return 0;
  100222. +}
  100223. +
  100224. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  100225. + struct snd_pcm_substream *substream,
  100226. + struct snd_soc_dai *dai)
  100227. +{
  100228. + uint32_t mask;
  100229. +
  100230. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  100231. + mask = BCM2708_I2S_RXON;
  100232. + else
  100233. + mask = BCM2708_I2S_TXON;
  100234. +
  100235. + regmap_update_bits(dev->i2s_regmap,
  100236. + BCM2708_I2S_CS_A_REG, mask, 0);
  100237. +
  100238. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  100239. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  100240. + bcm2708_i2s_stop_clock(dev);
  100241. +}
  100242. +
  100243. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  100244. + struct snd_soc_dai *dai)
  100245. +{
  100246. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  100247. + uint32_t mask;
  100248. +
  100249. + switch (cmd) {
  100250. + case SNDRV_PCM_TRIGGER_START:
  100251. + case SNDRV_PCM_TRIGGER_RESUME:
  100252. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  100253. + bcm2708_i2s_start_clock(dev);
  100254. +
  100255. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  100256. + mask = BCM2708_I2S_RXON;
  100257. + else
  100258. + mask = BCM2708_I2S_TXON;
  100259. +
  100260. + regmap_update_bits(dev->i2s_regmap,
  100261. + BCM2708_I2S_CS_A_REG, mask, mask);
  100262. + break;
  100263. +
  100264. + case SNDRV_PCM_TRIGGER_STOP:
  100265. + case SNDRV_PCM_TRIGGER_SUSPEND:
  100266. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  100267. + bcm2708_i2s_stop(dev, substream, dai);
  100268. + break;
  100269. + default:
  100270. + return -EINVAL;
  100271. + }
  100272. +
  100273. + return 0;
  100274. +}
  100275. +
  100276. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  100277. + struct snd_soc_dai *dai)
  100278. +{
  100279. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  100280. +
  100281. + if (dai->active)
  100282. + return 0;
  100283. +
  100284. + /* Should this still be running stop it */
  100285. + bcm2708_i2s_stop_clock(dev);
  100286. +
  100287. + /* Enable PCM block */
  100288. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  100289. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  100290. +
  100291. + /*
  100292. + * Disable STBY.
  100293. + * Requires at least 4 PCM clock cycles to take effect.
  100294. + */
  100295. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  100296. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  100297. +
  100298. + return 0;
  100299. +}
  100300. +
  100301. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  100302. + struct snd_soc_dai *dai)
  100303. +{
  100304. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  100305. +
  100306. + bcm2708_i2s_stop(dev, substream, dai);
  100307. +
  100308. + /* If both streams are stopped, disable module and clock */
  100309. + if (dai->active)
  100310. + return;
  100311. +
  100312. + /* Disable the module */
  100313. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  100314. + BCM2708_I2S_EN, 0);
  100315. +
  100316. + /*
  100317. + * Stopping clock is necessary, because stop does
  100318. + * not stop the clock when SND_SOC_DAIFMT_CONT
  100319. + */
  100320. + bcm2708_i2s_stop_clock(dev);
  100321. +}
  100322. +
  100323. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  100324. + .startup = bcm2708_i2s_startup,
  100325. + .shutdown = bcm2708_i2s_shutdown,
  100326. + .prepare = bcm2708_i2s_prepare,
  100327. + .trigger = bcm2708_i2s_trigger,
  100328. + .hw_params = bcm2708_i2s_hw_params,
  100329. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  100330. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  100331. +};
  100332. +
  100333. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  100334. +{
  100335. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  100336. +
  100337. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  100338. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  100339. +
  100340. + return 0;
  100341. +}
  100342. +
  100343. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  100344. + .name = "bcm2708-i2s",
  100345. + .probe = bcm2708_i2s_dai_probe,
  100346. + .playback = {
  100347. + .channels_min = 2,
  100348. + .channels_max = 2,
  100349. + .rates = SNDRV_PCM_RATE_8000_192000,
  100350. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  100351. + | SNDRV_PCM_FMTBIT_S24_LE
  100352. + | SNDRV_PCM_FMTBIT_S32_LE
  100353. + },
  100354. + .capture = {
  100355. + .channels_min = 2,
  100356. + .channels_max = 2,
  100357. + .rates = SNDRV_PCM_RATE_8000_192000,
  100358. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  100359. + | SNDRV_PCM_FMTBIT_S24_LE
  100360. + | SNDRV_PCM_FMTBIT_S32_LE
  100361. + },
  100362. + .ops = &bcm2708_i2s_dai_ops,
  100363. + .symmetric_rates = 1
  100364. +};
  100365. +
  100366. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  100367. +{
  100368. + switch (reg) {
  100369. + case BCM2708_I2S_CS_A_REG:
  100370. + case BCM2708_I2S_FIFO_A_REG:
  100371. + case BCM2708_I2S_INTSTC_A_REG:
  100372. + case BCM2708_I2S_GRAY_REG:
  100373. + return true;
  100374. + default:
  100375. + return false;
  100376. + };
  100377. +}
  100378. +
  100379. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  100380. +{
  100381. + switch (reg) {
  100382. + case BCM2708_I2S_FIFO_A_REG:
  100383. + return true;
  100384. + default:
  100385. + return false;
  100386. + };
  100387. +}
  100388. +
  100389. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  100390. +{
  100391. + switch (reg) {
  100392. + case BCM2708_CLK_PCMCTL_REG:
  100393. + return true;
  100394. + default:
  100395. + return false;
  100396. + };
  100397. +}
  100398. +
  100399. +static const struct regmap_config bcm2708_regmap_config[] = {
  100400. + {
  100401. + .reg_bits = 32,
  100402. + .reg_stride = 4,
  100403. + .val_bits = 32,
  100404. + .max_register = BCM2708_I2S_GRAY_REG,
  100405. + .precious_reg = bcm2708_i2s_precious_reg,
  100406. + .volatile_reg = bcm2708_i2s_volatile_reg,
  100407. + .cache_type = REGCACHE_RBTREE,
  100408. + },
  100409. + {
  100410. + .reg_bits = 32,
  100411. + .reg_stride = 4,
  100412. + .val_bits = 32,
  100413. + .max_register = BCM2708_CLK_PCMDIV_REG,
  100414. + .volatile_reg = bcm2708_clk_volatile_reg,
  100415. + .cache_type = REGCACHE_RBTREE,
  100416. + },
  100417. +};
  100418. +
  100419. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  100420. + .name = "bcm2708-i2s-comp",
  100421. +};
  100422. +
  100423. +
  100424. +static void bcm2708_i2s_setup_gpio(void)
  100425. +{
  100426. + /*
  100427. + * This is the common way to handle the GPIO pins for
  100428. + * the Raspberry Pi.
  100429. + * TODO Better way would be to handle
  100430. + * this in the device tree!
  100431. + */
  100432. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  100433. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  100434. +
  100435. + unsigned int *gpio;
  100436. + int pin;
  100437. + gpio = ioremap(GPIO_BASE, SZ_16K);
  100438. +
  100439. + /* SPI is on GPIO 7..11 */
  100440. + for (pin = 28; pin <= 31; pin++) {
  100441. + INP_GPIO(pin); /* set mode to GPIO input first */
  100442. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  100443. + }
  100444. +#undef INP_GPIO
  100445. +#undef SET_GPIO_ALT
  100446. +}
  100447. +
  100448. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  100449. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  100450. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  100451. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  100452. + SNDRV_PCM_FMTBIT_S24_LE |
  100453. + SNDRV_PCM_FMTBIT_S32_LE,
  100454. + .period_bytes_min = 32,
  100455. + .period_bytes_max = 64 * PAGE_SIZE,
  100456. + .periods_min = 2,
  100457. + .periods_max = 255,
  100458. + .buffer_bytes_max = 128 * PAGE_SIZE,
  100459. +};
  100460. +
  100461. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  100462. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  100463. + .pcm_hardware = &bcm2708_pcm_hardware,
  100464. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  100465. +};
  100466. +
  100467. +
  100468. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  100469. +{
  100470. + struct bcm2708_i2s_dev *dev;
  100471. + int i;
  100472. + int ret;
  100473. + struct regmap *regmap[2];
  100474. + struct resource *mem[2];
  100475. +
  100476. + /* Request both ioareas */
  100477. + for (i = 0; i <= 1; i++) {
  100478. + void __iomem *base;
  100479. +
  100480. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  100481. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  100482. + if (IS_ERR(base))
  100483. + return PTR_ERR(base);
  100484. +
  100485. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  100486. + &bcm2708_regmap_config[i]);
  100487. + if (IS_ERR(regmap[i])) {
  100488. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  100489. + return PTR_ERR(regmap[i]);
  100490. + }
  100491. + }
  100492. +
  100493. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  100494. + GFP_KERNEL);
  100495. + if (IS_ERR(dev))
  100496. + return PTR_ERR(dev);
  100497. +
  100498. + bcm2708_i2s_setup_gpio();
  100499. +
  100500. + dev->i2s_regmap = regmap[0];
  100501. + dev->clk_regmap = regmap[1];
  100502. +
  100503. + /* Set the DMA address */
  100504. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  100505. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  100506. +
  100507. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  100508. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  100509. +
  100510. + /* Set the DREQ */
  100511. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  100512. + BCM2708_DMA_DREQ_PCM_TX;
  100513. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  100514. + BCM2708_DMA_DREQ_PCM_RX;
  100515. +
  100516. + /* Set the bus width */
  100517. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  100518. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  100519. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  100520. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  100521. +
  100522. + /* Set burst */
  100523. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  100524. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  100525. +
  100526. + /* BCLK ratio - use default */
  100527. + dev->bclk_ratio = 0;
  100528. +
  100529. + /* Store the pdev */
  100530. + dev->dev = &pdev->dev;
  100531. + dev_set_drvdata(&pdev->dev, dev);
  100532. +
  100533. + ret = snd_soc_register_component(&pdev->dev,
  100534. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  100535. +
  100536. + if (ret) {
  100537. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  100538. + ret = -ENOMEM;
  100539. + return ret;
  100540. + }
  100541. +
  100542. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  100543. + &bcm2708_dmaengine_pcm_config,
  100544. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  100545. + if (ret) {
  100546. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  100547. + snd_soc_unregister_component(&pdev->dev);
  100548. + return ret;
  100549. + }
  100550. +
  100551. + return 0;
  100552. +}
  100553. +
  100554. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  100555. +{
  100556. + snd_dmaengine_pcm_unregister(&pdev->dev);
  100557. + snd_soc_unregister_component(&pdev->dev);
  100558. + return 0;
  100559. +}
  100560. +
  100561. +static struct platform_driver bcm2708_i2s_driver = {
  100562. + .probe = bcm2708_i2s_probe,
  100563. + .remove = bcm2708_i2s_remove,
  100564. + .driver = {
  100565. + .name = "bcm2708-i2s",
  100566. + .owner = THIS_MODULE,
  100567. + },
  100568. +};
  100569. +
  100570. +module_platform_driver(bcm2708_i2s_driver);
  100571. +
  100572. +MODULE_ALIAS("platform:bcm2708-i2s");
  100573. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  100574. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100575. +MODULE_LICENSE("GPL v2");
  100576. diff -Nur linux-3.10.33/sound/soc/bcm/hifiberry_dac.c linux-raspberry-pi/sound/soc/bcm/hifiberry_dac.c
  100577. --- linux-3.10.33/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  100578. +++ linux-raspberry-pi/sound/soc/bcm/hifiberry_dac.c 2014-03-13 12:46:44.480107952 +0100
  100579. @@ -0,0 +1,100 @@
  100580. +/*
  100581. + * ASoC Driver for HifiBerry DAC
  100582. + *
  100583. + * Author: Florian Meier <florian.meier@koalo.de>
  100584. + * Copyright 2013
  100585. + *
  100586. + * This program is free software; you can redistribute it and/or
  100587. + * modify it under the terms of the GNU General Public License
  100588. + * version 2 as published by the Free Software Foundation.
  100589. + *
  100590. + * This program is distributed in the hope that it will be useful, but
  100591. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100592. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100593. + * General Public License for more details.
  100594. + */
  100595. +
  100596. +#include <linux/module.h>
  100597. +#include <linux/platform_device.h>
  100598. +
  100599. +#include <sound/core.h>
  100600. +#include <sound/pcm.h>
  100601. +#include <sound/pcm_params.h>
  100602. +#include <sound/soc.h>
  100603. +#include <sound/jack.h>
  100604. +
  100605. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  100606. +{
  100607. + return 0;
  100608. +}
  100609. +
  100610. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  100611. + struct snd_pcm_hw_params *params)
  100612. +{
  100613. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  100614. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  100615. +
  100616. + unsigned int sample_bits =
  100617. + snd_pcm_format_physical_width(params_format(params));
  100618. +
  100619. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  100620. +}
  100621. +
  100622. +/* machine stream operations */
  100623. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  100624. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  100625. +};
  100626. +
  100627. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  100628. +{
  100629. + .name = "HifiBerry DAC",
  100630. + .stream_name = "HifiBerry DAC HiFi",
  100631. + .cpu_dai_name = "bcm2708-i2s.0",
  100632. + .codec_dai_name = "pcm5102a-hifi",
  100633. + .platform_name = "bcm2708-i2s.0",
  100634. + .codec_name = "pcm5102a-codec",
  100635. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  100636. + SND_SOC_DAIFMT_CBS_CFS,
  100637. + .ops = &snd_rpi_hifiberry_dac_ops,
  100638. + .init = snd_rpi_hifiberry_dac_init,
  100639. +},
  100640. +};
  100641. +
  100642. +/* audio machine driver */
  100643. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  100644. + .name = "snd_rpi_hifiberry_dac",
  100645. + .dai_link = snd_rpi_hifiberry_dac_dai,
  100646. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  100647. +};
  100648. +
  100649. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  100650. +{
  100651. + int ret = 0;
  100652. +
  100653. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  100654. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  100655. + if (ret)
  100656. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  100657. +
  100658. + return ret;
  100659. +}
  100660. +
  100661. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  100662. +{
  100663. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  100664. +}
  100665. +
  100666. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  100667. + .driver = {
  100668. + .name = "snd-hifiberry-dac",
  100669. + .owner = THIS_MODULE,
  100670. + },
  100671. + .probe = snd_rpi_hifiberry_dac_probe,
  100672. + .remove = snd_rpi_hifiberry_dac_remove,
  100673. +};
  100674. +
  100675. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  100676. +
  100677. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100678. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  100679. +MODULE_LICENSE("GPL v2");
  100680. diff -Nur linux-3.10.33/sound/soc/bcm/hifiberry_digi.c linux-raspberry-pi/sound/soc/bcm/hifiberry_digi.c
  100681. --- linux-3.10.33/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  100682. +++ linux-raspberry-pi/sound/soc/bcm/hifiberry_digi.c 2014-03-13 12:46:44.480107952 +0100
  100683. @@ -0,0 +1,153 @@
  100684. +/*
  100685. + * ASoC Driver for HifiBerry Digi
  100686. + *
  100687. + * Author: Daniel Matuschek <info@crazy-audio.com>
  100688. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  100689. + * Copyright 2013
  100690. + *
  100691. + * This program is free software; you can redistribute it and/or
  100692. + * modify it under the terms of the GNU General Public License
  100693. + * version 2 as published by the Free Software Foundation.
  100694. + *
  100695. + * This program is distributed in the hope that it will be useful, but
  100696. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100697. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100698. + * General Public License for more details.
  100699. + */
  100700. +
  100701. +#include <linux/module.h>
  100702. +#include <linux/platform_device.h>
  100703. +
  100704. +#include <sound/core.h>
  100705. +#include <sound/pcm.h>
  100706. +#include <sound/pcm_params.h>
  100707. +#include <sound/soc.h>
  100708. +#include <sound/jack.h>
  100709. +
  100710. +#include "../codecs/wm8804.h"
  100711. +
  100712. +static int samplerate=44100;
  100713. +
  100714. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  100715. +{
  100716. + struct snd_soc_codec *codec = rtd->codec;
  100717. +
  100718. + /* enable TX output */
  100719. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  100720. +
  100721. + return 0;
  100722. +}
  100723. +
  100724. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  100725. + struct snd_pcm_hw_params *params)
  100726. +{
  100727. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  100728. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  100729. + struct snd_soc_codec *codec = rtd->codec;
  100730. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  100731. +
  100732. + int sysclk = 27000000; /* This is fixed on this board */
  100733. +
  100734. + long mclk_freq=0;
  100735. + int mclk_div=1;
  100736. +
  100737. + int ret;
  100738. +
  100739. + samplerate = params_rate(params);
  100740. +
  100741. + switch (samplerate) {
  100742. + case 44100:
  100743. + case 48000:
  100744. + case 88200:
  100745. + case 96000:
  100746. + mclk_freq=samplerate*256;
  100747. + mclk_div=WM8804_MCLKDIV_256FS;
  100748. + break;
  100749. + case 176400:
  100750. + case 192000:
  100751. + mclk_freq=samplerate*128;
  100752. + mclk_div=WM8804_MCLKDIV_128FS;
  100753. + break;
  100754. + default:
  100755. + dev_err(substream->pcm->dev,
  100756. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  100757. + }
  100758. +
  100759. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  100760. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  100761. +
  100762. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  100763. + sysclk, SND_SOC_CLOCK_OUT);
  100764. + if (ret < 0) {
  100765. + dev_err(substream->pcm->dev,
  100766. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  100767. + return ret;
  100768. + }
  100769. +
  100770. + /* Enable TX output */
  100771. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  100772. +
  100773. + /* Power on */
  100774. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  100775. +
  100776. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  100777. +}
  100778. +
  100779. +/* machine stream operations */
  100780. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  100781. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  100782. +};
  100783. +
  100784. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  100785. +{
  100786. + .name = "HifiBerry Digi",
  100787. + .stream_name = "HifiBerry Digi HiFi",
  100788. + .cpu_dai_name = "bcm2708-i2s.0",
  100789. + .codec_dai_name = "wm8804-spdif",
  100790. + .platform_name = "bcm2708-i2s.0",
  100791. + .codec_name = "wm8804.1-003b",
  100792. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  100793. + SND_SOC_DAIFMT_CBM_CFM,
  100794. + .ops = &snd_rpi_hifiberry_digi_ops,
  100795. + .init = snd_rpi_hifiberry_digi_init,
  100796. +},
  100797. +};
  100798. +
  100799. +/* audio machine driver */
  100800. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  100801. + .name = "snd_rpi_hifiberry_digi",
  100802. + .dai_link = snd_rpi_hifiberry_digi_dai,
  100803. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  100804. +};
  100805. +
  100806. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  100807. +{
  100808. + int ret = 0;
  100809. +
  100810. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  100811. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  100812. + if (ret)
  100813. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  100814. +
  100815. + return ret;
  100816. +}
  100817. +
  100818. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  100819. +{
  100820. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  100821. +}
  100822. +
  100823. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  100824. + .driver = {
  100825. + .name = "snd-hifiberry-digi",
  100826. + .owner = THIS_MODULE,
  100827. + },
  100828. + .probe = snd_rpi_hifiberry_digi_probe,
  100829. + .remove = snd_rpi_hifiberry_digi_remove,
  100830. +};
  100831. +
  100832. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  100833. +
  100834. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  100835. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  100836. +MODULE_LICENSE("GPL v2");
  100837. diff -Nur linux-3.10.33/sound/soc/bcm/Kconfig linux-raspberry-pi/sound/soc/bcm/Kconfig
  100838. --- linux-3.10.33/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  100839. +++ linux-raspberry-pi/sound/soc/bcm/Kconfig 2014-03-13 12:46:44.480107952 +0100
  100840. @@ -0,0 +1,31 @@
  100841. +config SND_BCM2708_SOC_I2S
  100842. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  100843. + depends on MACH_BCM2708
  100844. + select REGMAP_MMIO
  100845. + select SND_SOC_DMAENGINE_PCM
  100846. + select SND_SOC_GENERIC_DMAENGINE_PCM
  100847. + help
  100848. + Say Y or M if you want to add support for codecs attached to
  100849. + the BCM2708 I2S interface. You will also need
  100850. + to select the audio interfaces to support below.
  100851. +
  100852. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  100853. + tristate "Support for HifiBerry DAC"
  100854. + depends on SND_BCM2708_SOC_I2S
  100855. + select SND_SOC_PCM5102A
  100856. + help
  100857. + Say Y or M if you want to add support for HifiBerry DAC.
  100858. +
  100859. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  100860. + tristate "Support for HifiBerry Digi"
  100861. + depends on SND_BCM2708_SOC_I2S
  100862. + select SND_SOC_WM8804
  100863. + help
  100864. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  100865. +
  100866. +config SND_BCM2708_SOC_RPI_DAC
  100867. + tristate "Support for RPi-DAC"
  100868. + depends on SND_BCM2708_SOC_I2S
  100869. + select SND_SOC_PCM1794A
  100870. + help
  100871. + Say Y or M if you want to add support for RPi-DAC.
  100872. diff -Nur linux-3.10.33/sound/soc/bcm/Makefile linux-raspberry-pi/sound/soc/bcm/Makefile
  100873. --- linux-3.10.33/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  100874. +++ linux-raspberry-pi/sound/soc/bcm/Makefile 2014-03-13 12:46:44.480107952 +0100
  100875. @@ -0,0 +1,13 @@
  100876. +# BCM2708 Platform Support
  100877. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  100878. +
  100879. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  100880. +
  100881. +# BCM2708 Machine Support
  100882. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  100883. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  100884. +snd-soc-rpi-dac-objs := rpi-dac.o
  100885. +
  100886. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  100887. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  100888. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  100889. diff -Nur linux-3.10.33/sound/soc/bcm/rpi-dac.c linux-raspberry-pi/sound/soc/bcm/rpi-dac.c
  100890. --- linux-3.10.33/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  100891. +++ linux-raspberry-pi/sound/soc/bcm/rpi-dac.c 2014-03-13 12:46:44.480107952 +0100
  100892. @@ -0,0 +1,97 @@
  100893. +/*
  100894. + * ASoC Driver for RPi-DAC.
  100895. + *
  100896. + * Author: Florian Meier <florian.meier@koalo.de>
  100897. + * Copyright 2013
  100898. + *
  100899. + * This program is free software; you can redistribute it and/or
  100900. + * modify it under the terms of the GNU General Public License
  100901. + * version 2 as published by the Free Software Foundation.
  100902. + *
  100903. + * This program is distributed in the hope that it will be useful, but
  100904. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100905. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100906. + * General Public License for more details.
  100907. + */
  100908. +
  100909. +#include <linux/module.h>
  100910. +#include <linux/platform_device.h>
  100911. +
  100912. +#include <sound/core.h>
  100913. +#include <sound/pcm.h>
  100914. +#include <sound/pcm_params.h>
  100915. +#include <sound/soc.h>
  100916. +#include <sound/jack.h>
  100917. +
  100918. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  100919. +{
  100920. + return 0;
  100921. +}
  100922. +
  100923. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  100924. + struct snd_pcm_hw_params *params)
  100925. +{
  100926. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  100927. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  100928. +
  100929. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  100930. +}
  100931. +
  100932. +/* machine stream operations */
  100933. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  100934. + .hw_params = snd_rpi_rpi_dac_hw_params,
  100935. +};
  100936. +
  100937. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  100938. +{
  100939. + .name = "HifiBerry Mini",
  100940. + .stream_name = "HifiBerry Mini HiFi",
  100941. + .cpu_dai_name = "bcm2708-i2s.0",
  100942. + .codec_dai_name = "pcm1794a-hifi",
  100943. + .platform_name = "bcm2708-i2s.0",
  100944. + .codec_name = "pcm1794a-codec",
  100945. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  100946. + SND_SOC_DAIFMT_CBS_CFS,
  100947. + .ops = &snd_rpi_rpi_dac_ops,
  100948. + .init = snd_rpi_rpi_dac_init,
  100949. +},
  100950. +};
  100951. +
  100952. +/* audio machine driver */
  100953. +static struct snd_soc_card snd_rpi_rpi_dac = {
  100954. + .name = "snd_rpi_rpi_dac",
  100955. + .dai_link = snd_rpi_rpi_dac_dai,
  100956. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  100957. +};
  100958. +
  100959. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  100960. +{
  100961. + int ret = 0;
  100962. +
  100963. + snd_rpi_rpi_dac.dev = &pdev->dev;
  100964. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  100965. + if (ret)
  100966. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  100967. +
  100968. + return ret;
  100969. +}
  100970. +
  100971. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  100972. +{
  100973. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  100974. +}
  100975. +
  100976. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  100977. + .driver = {
  100978. + .name = "snd-rpi-dac",
  100979. + .owner = THIS_MODULE,
  100980. + },
  100981. + .probe = snd_rpi_rpi_dac_probe,
  100982. + .remove = snd_rpi_rpi_dac_remove,
  100983. +};
  100984. +
  100985. +module_platform_driver(snd_rpi_rpi_dac_driver);
  100986. +
  100987. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100988. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  100989. +MODULE_LICENSE("GPL v2");
  100990. diff -Nur linux-3.10.33/sound/soc/codecs/Kconfig linux-raspberry-pi/sound/soc/codecs/Kconfig
  100991. --- linux-3.10.33/sound/soc/codecs/Kconfig 2014-03-07 06:58:45.000000000 +0100
  100992. +++ linux-raspberry-pi/sound/soc/codecs/Kconfig 2014-03-13 12:46:44.524108040 +0100
  100993. @@ -55,6 +55,8 @@
  100994. select SND_SOC_ML26124 if I2C
  100995. select SND_SOC_OMAP_HDMI_CODEC if OMAP4_DSS_HDMI
  100996. select SND_SOC_PCM3008
  100997. + select SND_SOC_PCM1794A
  100998. + select SND_SOC_PCM5102A
  100999. select SND_SOC_RT5631 if I2C
  101000. select SND_SOC_SGTL5000 if I2C
  101001. select SND_SOC_SI476X if MFD_SI476X_CORE
  101002. @@ -293,6 +295,12 @@
  101003. config SND_SOC_PCM3008
  101004. tristate
  101005. +config SND_SOC_PCM1794A
  101006. + tristate
  101007. +
  101008. +config SND_SOC_PCM5102A
  101009. + tristate
  101010. +
  101011. config SND_SOC_RT5631
  101012. tristate
  101013. diff -Nur linux-3.10.33/sound/soc/codecs/Makefile linux-raspberry-pi/sound/soc/codecs/Makefile
  101014. --- linux-3.10.33/sound/soc/codecs/Makefile 2014-03-07 06:58:45.000000000 +0100
  101015. +++ linux-raspberry-pi/sound/soc/codecs/Makefile 2014-03-13 12:46:44.524108040 +0100
  101016. @@ -43,6 +43,8 @@
  101017. snd-soc-ml26124-objs := ml26124.o
  101018. snd-soc-omap-hdmi-codec-objs := omap-hdmi.o
  101019. snd-soc-pcm3008-objs := pcm3008.o
  101020. +snd-soc-pcm1794a-objs := pcm1794a.o
  101021. +snd-soc-pcm5102a-objs := pcm5102a.o
  101022. snd-soc-rt5631-objs := rt5631.o
  101023. snd-soc-sgtl5000-objs := sgtl5000.o
  101024. snd-soc-alc5623-objs := alc5623.o
  101025. @@ -170,6 +172,8 @@
  101026. obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o
  101027. obj-$(CONFIG_SND_SOC_OMAP_HDMI_CODEC) += snd-soc-omap-hdmi-codec.o
  101028. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  101029. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  101030. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  101031. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  101032. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  101033. obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o
  101034. diff -Nur linux-3.10.33/sound/soc/codecs/pcm1794a.c linux-raspberry-pi/sound/soc/codecs/pcm1794a.c
  101035. --- linux-3.10.33/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  101036. +++ linux-raspberry-pi/sound/soc/codecs/pcm1794a.c 2014-03-13 12:46:44.540108072 +0100
  101037. @@ -0,0 +1,62 @@
  101038. +/*
  101039. + * Driver for the PCM1794A codec
  101040. + *
  101041. + * Author: Florian Meier <florian.meier@koalo.de>
  101042. + * Copyright 2013
  101043. + *
  101044. + * This program is free software; you can redistribute it and/or
  101045. + * modify it under the terms of the GNU General Public License
  101046. + * version 2 as published by the Free Software Foundation.
  101047. + *
  101048. + * This program is distributed in the hope that it will be useful, but
  101049. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  101050. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  101051. + * General Public License for more details.
  101052. + */
  101053. +
  101054. +
  101055. +#include <linux/init.h>
  101056. +#include <linux/module.h>
  101057. +#include <linux/platform_device.h>
  101058. +
  101059. +#include <sound/soc.h>
  101060. +
  101061. +static struct snd_soc_dai_driver pcm1794a_dai = {
  101062. + .name = "pcm1794a-hifi",
  101063. + .playback = {
  101064. + .channels_min = 2,
  101065. + .channels_max = 2,
  101066. + .rates = SNDRV_PCM_RATE_8000_192000,
  101067. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  101068. + SNDRV_PCM_FMTBIT_S24_LE
  101069. + },
  101070. +};
  101071. +
  101072. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  101073. +
  101074. +static int pcm1794a_probe(struct platform_device *pdev)
  101075. +{
  101076. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  101077. + &pcm1794a_dai, 1);
  101078. +}
  101079. +
  101080. +static int pcm1794a_remove(struct platform_device *pdev)
  101081. +{
  101082. + snd_soc_unregister_codec(&pdev->dev);
  101083. + return 0;
  101084. +}
  101085. +
  101086. +static struct platform_driver pcm1794a_codec_driver = {
  101087. + .probe = pcm1794a_probe,
  101088. + .remove = pcm1794a_remove,
  101089. + .driver = {
  101090. + .name = "pcm1794a-codec",
  101091. + .owner = THIS_MODULE,
  101092. + },
  101093. +};
  101094. +
  101095. +module_platform_driver(pcm1794a_codec_driver);
  101096. +
  101097. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  101098. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  101099. +MODULE_LICENSE("GPL v2");
  101100. diff -Nur linux-3.10.33/sound/soc/codecs/pcm5102a.c linux-raspberry-pi/sound/soc/codecs/pcm5102a.c
  101101. --- linux-3.10.33/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  101102. +++ linux-raspberry-pi/sound/soc/codecs/pcm5102a.c 2014-03-13 12:46:44.540108072 +0100
  101103. @@ -0,0 +1,63 @@
  101104. +/*
  101105. + * Driver for the PCM5102A codec
  101106. + *
  101107. + * Author: Florian Meier <florian.meier@koalo.de>
  101108. + * Copyright 2013
  101109. + *
  101110. + * This program is free software; you can redistribute it and/or
  101111. + * modify it under the terms of the GNU General Public License
  101112. + * version 2 as published by the Free Software Foundation.
  101113. + *
  101114. + * This program is distributed in the hope that it will be useful, but
  101115. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  101116. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  101117. + * General Public License for more details.
  101118. + */
  101119. +
  101120. +
  101121. +#include <linux/init.h>
  101122. +#include <linux/module.h>
  101123. +#include <linux/platform_device.h>
  101124. +
  101125. +#include <sound/soc.h>
  101126. +
  101127. +static struct snd_soc_dai_driver pcm5102a_dai = {
  101128. + .name = "pcm5102a-hifi",
  101129. + .playback = {
  101130. + .channels_min = 2,
  101131. + .channels_max = 2,
  101132. + .rates = SNDRV_PCM_RATE_8000_192000,
  101133. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  101134. + // SNDRV_PCM_FMTBIT_S24_LE | : disable for now, it causes white noise with xbmc
  101135. + SNDRV_PCM_FMTBIT_S32_LE
  101136. + },
  101137. +};
  101138. +
  101139. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  101140. +
  101141. +static int pcm5102a_probe(struct platform_device *pdev)
  101142. +{
  101143. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  101144. + &pcm5102a_dai, 1);
  101145. +}
  101146. +
  101147. +static int pcm5102a_remove(struct platform_device *pdev)
  101148. +{
  101149. + snd_soc_unregister_codec(&pdev->dev);
  101150. + return 0;
  101151. +}
  101152. +
  101153. +static struct platform_driver pcm5102a_codec_driver = {
  101154. + .probe = pcm5102a_probe,
  101155. + .remove = pcm5102a_remove,
  101156. + .driver = {
  101157. + .name = "pcm5102a-codec",
  101158. + .owner = THIS_MODULE,
  101159. + },
  101160. +};
  101161. +
  101162. +module_platform_driver(pcm5102a_codec_driver);
  101163. +
  101164. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  101165. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  101166. +MODULE_LICENSE("GPL v2");
  101167. diff -Nur linux-3.10.33/sound/soc/codecs/wm8804.c linux-raspberry-pi/sound/soc/codecs/wm8804.c
  101168. --- linux-3.10.33/sound/soc/codecs/wm8804.c 2014-03-07 06:58:45.000000000 +0100
  101169. +++ linux-raspberry-pi/sound/soc/codecs/wm8804.c 2014-03-13 12:46:44.660108313 +0100
  101170. @@ -63,6 +63,7 @@
  101171. struct regmap *regmap;
  101172. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  101173. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  101174. + int mclk_div;
  101175. };
  101176. static int txsrc_get(struct snd_kcontrol *kcontrol,
  101177. @@ -277,6 +278,7 @@
  101178. blen = 0x1;
  101179. break;
  101180. case SNDRV_PCM_FORMAT_S24_LE:
  101181. + case SNDRV_PCM_FORMAT_S32_LE:
  101182. blen = 0x2;
  101183. break;
  101184. default:
  101185. @@ -318,7 +320,7 @@
  101186. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  101187. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  101188. - unsigned int source)
  101189. + unsigned int source, unsigned int mclk_div)
  101190. {
  101191. u64 Kpart;
  101192. unsigned long int K, Ndiv, Nmod, tmp;
  101193. @@ -330,7 +332,8 @@
  101194. */
  101195. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  101196. tmp = target * post_table[i].div;
  101197. - if (tmp >= 90000000 && tmp <= 100000000) {
  101198. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  101199. + (mclk_div == post_table[i].mclkdiv)) {
  101200. pll_div->freqmode = post_table[i].freqmode;
  101201. pll_div->mclkdiv = post_table[i].mclkdiv;
  101202. target *= post_table[i].div;
  101203. @@ -387,8 +390,11 @@
  101204. } else {
  101205. int ret;
  101206. struct pll_div pll_div;
  101207. + struct wm8804_priv *wm8804;
  101208. - ret = pll_factors(&pll_div, freq_out, freq_in);
  101209. + wm8804 = snd_soc_codec_get_drvdata(codec);
  101210. +
  101211. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  101212. if (ret)
  101213. return ret;
  101214. @@ -452,6 +458,7 @@
  101215. int div_id, int div)
  101216. {
  101217. struct snd_soc_codec *codec;
  101218. + struct wm8804_priv *wm8804;
  101219. codec = dai->codec;
  101220. switch (div_id) {
  101221. @@ -459,6 +466,10 @@
  101222. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  101223. (div & 0x3) << 4);
  101224. break;
  101225. + case WM8804_MCLK_DIV:
  101226. + wm8804 = snd_soc_codec_get_drvdata(codec);
  101227. + wm8804->mclk_div = div;
  101228. + break;
  101229. default:
  101230. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  101231. return -EINVAL;
  101232. @@ -641,7 +652,7 @@
  101233. };
  101234. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  101235. - SNDRV_PCM_FMTBIT_S24_LE)
  101236. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  101237. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  101238. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  101239. @@ -674,7 +685,7 @@
  101240. .suspend = wm8804_suspend,
  101241. .resume = wm8804_resume,
  101242. .set_bias_level = wm8804_set_bias_level,
  101243. - .idle_bias_off = true,
  101244. + .idle_bias_off = false,
  101245. .controls = wm8804_snd_controls,
  101246. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  101247. diff -Nur linux-3.10.33/sound/soc/codecs/wm8804.h linux-raspberry-pi/sound/soc/codecs/wm8804.h
  101248. --- linux-3.10.33/sound/soc/codecs/wm8804.h 2014-03-07 06:58:45.000000000 +0100
  101249. +++ linux-raspberry-pi/sound/soc/codecs/wm8804.h 2014-03-13 12:46:44.660108313 +0100
  101250. @@ -57,5 +57,9 @@
  101251. #define WM8804_CLKOUT_SRC_OSCCLK 4
  101252. #define WM8804_CLKOUT_DIV 1
  101253. +#define WM8804_MCLK_DIV 2
  101254. +
  101255. +#define WM8804_MCLKDIV_256FS 0
  101256. +#define WM8804_MCLKDIV_128FS 1
  101257. #endif /* _WM8804_H */
  101258. diff -Nur linux-3.10.33/sound/soc/Kconfig linux-raspberry-pi/sound/soc/Kconfig
  101259. --- linux-3.10.33/sound/soc/Kconfig 2014-03-07 06:58:45.000000000 +0100
  101260. +++ linux-raspberry-pi/sound/soc/Kconfig 2014-03-13 12:46:44.420107831 +0100
  101261. @@ -36,6 +36,7 @@
  101262. # All the supported SoCs
  101263. source "sound/soc/atmel/Kconfig"
  101264. source "sound/soc/au1x/Kconfig"
  101265. +source "sound/soc/bcm/Kconfig"
  101266. source "sound/soc/blackfin/Kconfig"
  101267. source "sound/soc/cirrus/Kconfig"
  101268. source "sound/soc/davinci/Kconfig"
  101269. diff -Nur linux-3.10.33/sound/soc/Makefile linux-raspberry-pi/sound/soc/Makefile
  101270. --- linux-3.10.33/sound/soc/Makefile 2014-03-07 06:58:45.000000000 +0100
  101271. +++ linux-raspberry-pi/sound/soc/Makefile 2014-03-13 12:46:44.420107831 +0100
  101272. @@ -14,6 +14,7 @@
  101273. obj-$(CONFIG_SND_SOC) += generic/
  101274. obj-$(CONFIG_SND_SOC) += atmel/
  101275. obj-$(CONFIG_SND_SOC) += au1x/
  101276. +obj-$(CONFIG_SND_SOC) += bcm/
  101277. obj-$(CONFIG_SND_SOC) += blackfin/
  101278. obj-$(CONFIG_SND_SOC) += cirrus/
  101279. obj-$(CONFIG_SND_SOC) += davinci/
  101280. diff -Nur linux-3.10.33/sound/soc/soc-core.c linux-raspberry-pi/sound/soc/soc-core.c
  101281. --- linux-3.10.33/sound/soc/soc-core.c 2014-03-07 06:58:45.000000000 +0100
  101282. +++ linux-raspberry-pi/sound/soc/soc-core.c 2014-03-13 12:46:44.888108771 +0100
  101283. @@ -3463,6 +3463,22 @@
  101284. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  101285. /**
  101286. + * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
  101287. + * @dai: DAI
  101288. + * @ratio Ratio of BCLK to Sample rate.
  101289. + *
  101290. + * Configures the DAI for a preset BCLK to sample rate ratio.
  101291. + */
  101292. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  101293. +{
  101294. + if (dai->driver && dai->driver->ops->set_bclk_ratio)
  101295. + return dai->driver->ops->set_bclk_ratio(dai, ratio);
  101296. + else
  101297. + return -EINVAL;
  101298. +}
  101299. +EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
  101300. +
  101301. +/**
  101302. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  101303. * @dai: DAI
  101304. * @fmt: SND_SOC_DAIFMT_ format value.